freedreno/perfcntrs: Re-indent

Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10293>
This commit is contained in:
Rob Clark 2021-04-16 11:59:30 -07:00 committed by Marge Bot
parent d26a224ca9
commit 6050976232
8 changed files with 2850 additions and 2859 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -22,18 +22,18 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include <arpa/inet.h>
#include <fcntl.h>
#include <ftw.h>
#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <unistd.h>
#include <inttypes.h>
#include <arpa/inet.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#include "util/macros.h"
#include "util/os_file.h"
@ -41,15 +41,14 @@
#include "freedreno_dt.h"
static struct {
char *dtnode;
int address_cells, size_cells;
uint64_t base;
uint32_t size;
uint32_t min_freq;
uint32_t max_freq;
char *dtnode;
int address_cells, size_cells;
uint64_t base;
uint32_t size;
uint32_t min_freq;
uint32_t max_freq;
} dev;
/*
* code to find stuff in /proc/device-tree:
*
@ -61,54 +60,55 @@ static struct {
static void *
readdt(const char *node)
{
char *path;
void *buf;
size_t sz;
char *path;
void *buf;
size_t sz;
(void) asprintf(&path, "%s/%s", dev.dtnode, node);
buf = os_read_file(path, &sz);
free(path);
(void)asprintf(&path, "%s/%s", dev.dtnode, node);
buf = os_read_file(path, &sz);
free(path);
return buf;
return buf;
}
static int
find_freqs_fn(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf)
find_freqs_fn(const char *fpath, const struct stat *sb, int typeflag,
struct FTW *ftwbuf)
{
const char *fname = fpath + ftwbuf->base;
size_t sz;
const char *fname = fpath + ftwbuf->base;
size_t sz;
if (strcmp(fname, "qcom,gpu-freq") == 0) {
uint32_t *buf = (uint32_t *)os_read_file(fpath, &sz);
uint32_t freq = ntohl(buf[0]);
free(buf);
dev.max_freq = MAX2(dev.max_freq, freq);
dev.min_freq = MIN2(dev.min_freq, freq);
}
if (strcmp(fname, "qcom,gpu-freq") == 0) {
uint32_t *buf = (uint32_t *)os_read_file(fpath, &sz);
uint32_t freq = ntohl(buf[0]);
free(buf);
dev.max_freq = MAX2(dev.max_freq, freq);
dev.min_freq = MIN2(dev.min_freq, freq);
}
return 0;
return 0;
}
static void
find_freqs(void)
{
char *path;
char *path;
dev.min_freq = ~0;
dev.max_freq = 0;
dev.min_freq = ~0;
dev.max_freq = 0;
(void) asprintf(&path, "%s/%s", dev.dtnode, "qcom,gpu-pwrlevels");
(void)asprintf(&path, "%s/%s", dev.dtnode, "qcom,gpu-pwrlevels");
nftw(path, find_freqs_fn, 64, 0);
nftw(path, find_freqs_fn, 64, 0);
free(path);
free(path);
}
static const char * compatibles[] = {
"qcom,adreno-3xx",
"qcom,kgsl-3d0",
"amd,imageon",
"qcom,adreno",
static const char *compatibles[] = {
"qcom,adreno-3xx",
"qcom,kgsl-3d0",
"amd,imageon",
"qcom,adreno",
};
/**
@ -118,137 +118,140 @@ static const char * compatibles[] = {
*
* would result in "qcom,adreno-630.2\0qcom,adreno\0"
*/
static bool match_compatible(char *compatstrs, int sz)
static bool
match_compatible(char *compatstrs, int sz)
{
while (sz > 0) {
char *compatible = compatstrs;
while (sz > 0) {
char *compatible = compatstrs;
for (unsigned i = 0; i < ARRAY_SIZE(compatibles); i++) {
if (strcmp(compatible, compatibles[i]) == 0) {
return true;
}
}
for (unsigned i = 0; i < ARRAY_SIZE(compatibles); i++) {
if (strcmp(compatible, compatibles[i]) == 0) {
return true;
}
}
compatstrs += strlen(compatible) + 1;
sz -= strlen(compatible) + 1;
}
return false;
compatstrs += strlen(compatible) + 1;
sz -= strlen(compatible) + 1;
}
return false;
}
static int
find_device_fn(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf)
find_device_fn(const char *fpath, const struct stat *sb, int typeflag,
struct FTW *ftwbuf)
{
const char *fname = fpath + ftwbuf->base;
size_t sz;
const char *fname = fpath + ftwbuf->base;
size_t sz;
if (strcmp(fname, "compatible") == 0) {
char *str = os_read_file(fpath, &sz);
if (match_compatible(str, sz)) {
int dlen = strlen(fpath) - strlen("/compatible");
dev.dtnode = malloc(dlen + 1);
memcpy(dev.dtnode, fpath, dlen);
dev.dtnode[dlen] = '\0';
printf("found dt node: %s\n", dev.dtnode);
if (strcmp(fname, "compatible") == 0) {
char *str = os_read_file(fpath, &sz);
if (match_compatible(str, sz)) {
int dlen = strlen(fpath) - strlen("/compatible");
dev.dtnode = malloc(dlen + 1);
memcpy(dev.dtnode, fpath, dlen);
dev.dtnode[dlen] = '\0';
printf("found dt node: %s\n", dev.dtnode);
char buf[dlen + sizeof("/../#address-cells") + 1];
size_t sz;
int *val;
char buf[dlen + sizeof("/../#address-cells") + 1];
size_t sz;
int *val;
sprintf(buf, "%s/../#address-cells", dev.dtnode);
val = (int *)os_read_file(buf, &sz);
dev.address_cells = ntohl(*val);
free(val);
sprintf(buf, "%s/../#address-cells", dev.dtnode);
val = (int *)os_read_file(buf, &sz);
dev.address_cells = ntohl(*val);
free(val);
sprintf(buf, "%s/../#size-cells", dev.dtnode);
val = (int *)os_read_file(buf, &sz);
dev.size_cells = ntohl(*val);
free(val);
sprintf(buf, "%s/../#size-cells", dev.dtnode);
val = (int *)os_read_file(buf, &sz);
dev.size_cells = ntohl(*val);
free(val);
printf("#address-cells=%d, #size-cells=%d\n",
dev.address_cells, dev.size_cells);
}
free(str);
}
if (dev.dtnode) {
/* we found it! */
return 1;
}
return 0;
printf("#address-cells=%d, #size-cells=%d\n", dev.address_cells,
dev.size_cells);
}
free(str);
}
if (dev.dtnode) {
/* we found it! */
return 1;
}
return 0;
}
static bool
find_device(void)
{
int ret;
uint32_t *buf, *b;
int ret;
uint32_t *buf, *b;
if (dev.dtnode)
return true;
if (dev.dtnode)
return true;
ret = nftw("/proc/device-tree/", find_device_fn, 64, 0);
if (ret < 0)
return false;
ret = nftw("/proc/device-tree/", find_device_fn, 64, 0);
if (ret < 0)
return false;
if (!dev.dtnode)
return false;
if (!dev.dtnode)
return false;
b = buf = readdt("reg");
b = buf = readdt("reg");
if (dev.address_cells == 2) {
uint32_t u[2] = { ntohl(buf[0]), ntohl(buf[1]) };
dev.base = (((uint64_t)u[0]) << 32) | u[1];
buf += 2;
} else {
dev.base = ntohl(buf[0]);
buf += 1;
}
if (dev.address_cells == 2) {
uint32_t u[2] = {ntohl(buf[0]), ntohl(buf[1])};
dev.base = (((uint64_t)u[0]) << 32) | u[1];
buf += 2;
} else {
dev.base = ntohl(buf[0]);
buf += 1;
}
if (dev.size_cells == 2) {
uint32_t u[2] = { ntohl(buf[0]), ntohl(buf[1]) };
dev.size = (((uint64_t)u[0]) << 32) | u[1];
buf += 2;
} else {
dev.size = ntohl(buf[0]);
buf += 1;
}
if (dev.size_cells == 2) {
uint32_t u[2] = {ntohl(buf[0]), ntohl(buf[1])};
dev.size = (((uint64_t)u[0]) << 32) | u[1];
buf += 2;
} else {
dev.size = ntohl(buf[0]);
buf += 1;
}
free(b);
free(b);
printf("i/o region at %08"PRIx64" (size: %x)\n", dev.base, dev.size);
printf("i/o region at %08" PRIx64 " (size: %x)\n", dev.base, dev.size);
find_freqs();
find_freqs();
printf("min_freq=%u, max_freq=%u\n", dev.min_freq, dev.max_freq);
printf("min_freq=%u, max_freq=%u\n", dev.min_freq, dev.max_freq);
return true;
return true;
}
bool
fd_dt_find_freqs(uint32_t *min_freq, uint32_t *max_freq)
{
if (!find_device())
return false;
if (!find_device())
return false;
*min_freq = dev.min_freq;
*max_freq = dev.max_freq;
*min_freq = dev.min_freq;
*max_freq = dev.max_freq;
return true;
return true;
}
void *
fd_dt_find_io(void)
{
if (!find_device())
return NULL;
if (!find_device())
return NULL;
int fd = open("/dev/mem", O_RDWR | O_SYNC);
if (fd < 0)
return NULL;
int fd = open("/dev/mem", O_RDWR | O_SYNC);
if (fd < 0)
return NULL;
void *io = mmap(0, dev.size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, dev.base);
close(fd);
if (io == MAP_FAILED)
return NULL;
void *io =
mmap(0, dev.size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, dev.base);
close(fd);
if (io == MAP_FAILED)
return NULL;
return io;
return io;
}

View File

@ -39,7 +39,7 @@ extern "C" {
*/
bool fd_dt_find_freqs(uint32_t *min_freq, uint32_t *max_freq);
void * fd_dt_find_io(void);
void *fd_dt_find_io(void);
#ifdef __cplusplus
} /* end of extern "C" */

View File

@ -40,18 +40,18 @@ extern const unsigned a6xx_num_perfcntr_groups;
const struct fd_perfcntr_group *
fd_perfcntrs(unsigned gpu_id, unsigned *count)
{
switch (gpu_id) {
case 200 ... 299:
*count = a2xx_num_perfcntr_groups;
return a2xx_perfcntr_groups;
case 500 ... 599:
*count = a5xx_num_perfcntr_groups;
return a5xx_perfcntr_groups;
case 600 ... 699:
*count = a6xx_num_perfcntr_groups;
return a6xx_perfcntr_groups;
default:
*count = 0;
return NULL;
}
switch (gpu_id) {
case 200 ... 299:
*count = a2xx_num_perfcntr_groups;
return a2xx_perfcntr_groups;
case 500 ... 599:
*count = a5xx_num_perfcntr_groups;
return a5xx_perfcntr_groups;
case 600 ... 699:
*count = a6xx_num_perfcntr_groups;
return a6xx_perfcntr_groups;
default:
*count = 0;
return NULL;
}
}

View File

@ -42,91 +42,82 @@ extern "C" {
/* Describes a single counter: */
struct fd_perfcntr_counter {
/* offset of the select register to choose what to count: */
unsigned select_reg;
/* offset of the lo/hi 32b to read current counter value: */
unsigned counter_reg_lo;
unsigned counter_reg_hi;
/* Optional, most counters don't have enable/clear registers: */
unsigned enable;
unsigned clear;
/* offset of the select register to choose what to count: */
unsigned select_reg;
/* offset of the lo/hi 32b to read current counter value: */
unsigned counter_reg_lo;
unsigned counter_reg_hi;
/* Optional, most counters don't have enable/clear registers: */
unsigned enable;
unsigned clear;
};
enum fd_perfcntr_type {
FD_PERFCNTR_TYPE_UINT64,
FD_PERFCNTR_TYPE_UINT,
FD_PERFCNTR_TYPE_FLOAT,
FD_PERFCNTR_TYPE_PERCENTAGE,
FD_PERFCNTR_TYPE_BYTES,
FD_PERFCNTR_TYPE_MICROSECONDS,
FD_PERFCNTR_TYPE_HZ,
FD_PERFCNTR_TYPE_DBM,
FD_PERFCNTR_TYPE_TEMPERATURE,
FD_PERFCNTR_TYPE_VOLTS,
FD_PERFCNTR_TYPE_AMPS,
FD_PERFCNTR_TYPE_WATTS,
FD_PERFCNTR_TYPE_UINT64,
FD_PERFCNTR_TYPE_UINT,
FD_PERFCNTR_TYPE_FLOAT,
FD_PERFCNTR_TYPE_PERCENTAGE,
FD_PERFCNTR_TYPE_BYTES,
FD_PERFCNTR_TYPE_MICROSECONDS,
FD_PERFCNTR_TYPE_HZ,
FD_PERFCNTR_TYPE_DBM,
FD_PERFCNTR_TYPE_TEMPERATURE,
FD_PERFCNTR_TYPE_VOLTS,
FD_PERFCNTR_TYPE_AMPS,
FD_PERFCNTR_TYPE_WATTS,
};
/* Whether an average value per frame or a cumulative value should be
* displayed.
*/
enum fd_perfcntr_result_type {
FD_PERFCNTR_RESULT_TYPE_AVERAGE,
FD_PERFCNTR_RESULT_TYPE_CUMULATIVE,
FD_PERFCNTR_RESULT_TYPE_AVERAGE,
FD_PERFCNTR_RESULT_TYPE_CUMULATIVE,
};
/* Describes a single countable: */
struct fd_perfcntr_countable {
const char *name;
/* selector register enum value to select this countable: */
unsigned selector;
const char *name;
/* selector register enum value to select this countable: */
unsigned selector;
/* description of the countable: */
enum fd_perfcntr_type query_type;
enum fd_perfcntr_result_type result_type;
/* description of the countable: */
enum fd_perfcntr_type query_type;
enum fd_perfcntr_result_type result_type;
};
/* Describes an entire counter group: */
struct fd_perfcntr_group {
const char *name;
unsigned num_counters;
const struct fd_perfcntr_counter *counters;
unsigned num_countables;
const struct fd_perfcntr_countable *countables;
const char *name;
unsigned num_counters;
const struct fd_perfcntr_counter *counters;
unsigned num_countables;
const struct fd_perfcntr_countable *countables;
};
const struct fd_perfcntr_group *fd_perfcntrs(unsigned gpu_id, unsigned *count);
#define COUNTER(_sel, _lo, _hi) { \
.select_reg = REG(_sel), \
.counter_reg_lo = REG(_lo), \
.counter_reg_hi = REG(_hi), \
}
#define COUNTER(_sel, _lo, _hi) { \
.select_reg = REG(_sel), .counter_reg_lo = REG(_lo), \
.counter_reg_hi = REG(_hi), \
}
#define COUNTER2(_sel, _lo, _hi, _en, _clr) { \
.select_reg = REG(_sel), \
.counter_reg_lo = REG(_lo), \
.counter_reg_hi = REG(_hi), \
.enable = REG(_en), \
.clear = REG(_clr), \
}
#define COUNTER2(_sel, _lo, _hi, _en, _clr) { \
.select_reg = REG(_sel), .counter_reg_lo = REG(_lo), \
.counter_reg_hi = REG(_hi), .enable = REG(_en), .clear = REG(_clr), \
}
#define COUNTABLE(_selector, _query_type, _result_type) { \
.name = #_selector, \
.selector = _selector, \
.query_type = FD_PERFCNTR_TYPE_ ## _query_type, \
.result_type = FD_PERFCNTR_RESULT_TYPE_ ## _result_type, \
}
#define COUNTABLE(_selector, _query_type, _result_type) { \
.name = #_selector, .selector = _selector, \
.query_type = FD_PERFCNTR_TYPE_##_query_type, \
.result_type = FD_PERFCNTR_RESULT_TYPE_##_result_type, \
}
#define GROUP(_name, _counters, _countables) { \
.name = _name, \
.num_counters = ARRAY_SIZE(_counters), \
.counters = _counters, \
.num_countables = ARRAY_SIZE(_countables), \
.countables = _countables, \
}
#define GROUP(_name, _counters, _countables) { \
.name = _name, .num_counters = ARRAY_SIZE(_counters), \
.counters = _counters, .num_countables = ARRAY_SIZE(_countables), \
.countables = _countables, \
}
#ifdef __cplusplus
} /* end of extern "C" */