Path: blob/21.2-virgl/src/panfrost/perf/pan_perf.c
4560 views
/*1* Copyright © 2021 Collabora, Ltd.2* Author: Antonio Caggiano <[email protected]>3*4* Permission is hereby granted, free of charge, to any person obtaining a copy5* of this software and associated documentation files (the "Software"), to deal6* in the Software without restriction, including without limitation the rights7* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell8* copies of the Software, and to permit persons to whom the Software is9* furnished to do so, subject to the following conditions:10*11* The above copyright notice and this permission notice shall be included in12* all copies or substantial portions of the Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE17* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,19* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN20* THE SOFTWARE.21*/2223#include "pan_perf.h"2425#include <pan_perf_metrics.h>26#include <lib/pan_device.h>27#include <drm-uapi/panfrost_drm.h>2829#define PAN_COUNTERS_PER_CATEGORY 6430#define PAN_SHADER_CORE_INDEX 23132uint32_t33panfrost_perf_counter_read(const struct panfrost_perf_counter *counter,34const struct panfrost_perf *perf)35{36assert(counter->offset < perf->n_counter_values);37uint32_t ret = perf->counter_values[counter->offset];3839// If counter belongs to shader core, accumulate values for all other cores40if (counter->category == &perf->cfg->categories[PAN_SHADER_CORE_INDEX]) {41for (uint32_t core = 1; core < perf->dev->core_count; ++core) {42ret += perf->counter_values[counter->offset + PAN_COUNTERS_PER_CATEGORY * core];43}44}4546return ret;47}4849static const struct panfrost_perf_config*50get_perf_config(unsigned int gpu_id)51{52switch (gpu_id) {53case 0x720:54return &panfrost_perf_config_t72x;55case 0x750:56return &panfrost_perf_config_t76x;57case 0x820:58return &panfrost_perf_config_t82x;59case 0x830:60return &panfrost_perf_config_t83x;61case 0x860:62return &panfrost_perf_config_t86x;63case 0x880:64return &panfrost_perf_config_t88x;65case 0x6221:66return &panfrost_perf_config_thex;67case 0x7093:68return &panfrost_perf_config_tdvx;69case 0x7212:70case 0x7402:71return &panfrost_perf_config_tgox;72default:73unreachable("Invalid GPU ID");74}75}7677void78panfrost_perf_init(struct panfrost_perf *perf, struct panfrost_device *dev)79{80perf->dev = dev;81perf->cfg = get_perf_config(dev->gpu_id);8283// Generally counter blocks are laid out in the following order:84// Job manager, tiler, L2 cache, and one or more shader cores.85uint32_t n_blocks = 3 + dev->core_count;86perf->n_counter_values = PAN_COUNTERS_PER_CATEGORY * n_blocks;87perf->counter_values = ralloc_array(perf, uint32_t, perf->n_counter_values);88}8990static int91panfrost_perf_query(struct panfrost_perf *perf, uint32_t enable)92{93struct drm_panfrost_perfcnt_enable perfcnt_enable = {enable, 0};94return drmIoctl(perf->dev->fd, DRM_IOCTL_PANFROST_PERFCNT_ENABLE, &perfcnt_enable);95}9697int98panfrost_perf_enable(struct panfrost_perf *perf)99{100return panfrost_perf_query(perf, 1 /* enable */);101}102103int104panfrost_perf_disable(struct panfrost_perf *perf)105{106return panfrost_perf_query(perf, 0 /* disable */);107}108109int110panfrost_perf_dump(struct panfrost_perf *perf)111{112// Dump performance counter values to the memory buffer pointed to by counter_values113struct drm_panfrost_perfcnt_dump perfcnt_dump = {(uint64_t)(uintptr_t)perf->counter_values};114return drmIoctl(perf->dev->fd, DRM_IOCTL_PANFROST_PERFCNT_DUMP, &perfcnt_dump);115}116117118