2 * Copyright (C) 2016 Rob Clark <robclark@freedesktop.org>
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
25 #include <arpa/inet.h>
35 #include <sys/types.h>
41 #include <libconfig.h>
44 #include "drm/freedreno_drmif.h"
45 #include "drm/freedreno_ringbuffer.h"
47 #include "freedreno_perfcntr.h"
49 #define MAX_CNTR_PER_GROUP 24
51 /* NOTE first counter group should always be CP, since we unconditionally
52 * use CP counter to measure the gpu freq.
55 struct counter_group
{
56 const struct fd_perfcntr_group
*group
;
59 const struct fd_perfcntr_counter
*counter
;
61 volatile uint32_t *val_hi
;
62 volatile uint32_t *val_lo
;
63 } counter
[MAX_CNTR_PER_GROUP
];
65 /* last sample time: */
66 uint32_t stime
[MAX_CNTR_PER_GROUP
];
67 /* for now just care about the low 32b value.. at least then we don't
68 * have to really care that we can't sample both hi and lo regs at the
71 uint32_t last
[MAX_CNTR_PER_GROUP
];
72 /* current value, ie. by how many did the counter increase in last
73 * sampling period divided by the sampling period:
75 float current
[MAX_CNTR_PER_GROUP
];
76 /* name of currently selected counters (for UI): */
77 const char *label
[MAX_CNTR_PER_GROUP
];
82 int address_cells
, size_cells
;
89 /* per-generation table of counters: */
91 struct counter_group
*groups
;
92 /* drm device (for writing select regs via ring): */
93 struct fd_device
*dev
;
95 struct fd_submit
*submit
;
96 struct fd_ringbuffer
*ring
;
99 static void config_save(void);
100 static void config_restore(void);
101 static void restore_counter_groups(void);
110 readfile(const char *path
, int *sz
)
115 fd
= open(path
, O_RDONLY
);
120 buf
= realloc(buf
, n
+ CHUNKSIZE
);
121 ret
= read(fd
, buf
+ n
, CHUNKSIZE
);
126 } else if (ret
< CHUNKSIZE
) {
140 clock_gettime(CLOCK_MONOTONIC
, &ts
);
141 return (ts
.tv_sec
* 1000000) + (ts
.tv_nsec
/ 1000);
145 delta(uint32_t a
, uint32_t b
)
147 /* deal with rollover: */
149 return 0xffffffff - a
+ b
;
155 * TODO de-duplicate OUT_RING() and friends
158 #define CP_WAIT_FOR_IDLE 38
159 #define CP_TYPE0_PKT 0x00000000
160 #define CP_TYPE3_PKT 0xc0000000
161 #define CP_TYPE4_PKT 0x40000000
162 #define CP_TYPE7_PKT 0x70000000
165 OUT_RING(struct fd_ringbuffer
*ring
, uint32_t data
)
167 *(ring
->cur
++) = data
;
171 OUT_PKT0(struct fd_ringbuffer
*ring
, uint16_t regindx
, uint16_t cnt
)
173 OUT_RING(ring
, CP_TYPE0_PKT
| ((cnt
-1) << 16) | (regindx
& 0x7FFF));
177 OUT_PKT3(struct fd_ringbuffer
*ring
, uint8_t opcode
, uint16_t cnt
)
179 OUT_RING(ring
, CP_TYPE3_PKT
| ((cnt
-1) << 16) | ((opcode
& 0xFF) << 8));
184 * Starting with a5xx, pkt4/pkt7 are used instead of pkt0/pkt3
187 static inline unsigned
188 _odd_parity_bit(unsigned val
)
190 /* See: http://graphics.stanford.edu/~seander/bithacks.html#ParityParallel
191 * note that we want odd parity so 0x6996 is inverted.
197 return (~0x6996 >> val
) & 1;
201 OUT_PKT4(struct fd_ringbuffer
*ring
, uint16_t regindx
, uint16_t cnt
)
203 OUT_RING(ring
, CP_TYPE4_PKT
| cnt
|
204 (_odd_parity_bit(cnt
) << 7) |
205 ((regindx
& 0x3ffff) << 8) |
206 ((_odd_parity_bit(regindx
) << 27)));
210 OUT_PKT7(struct fd_ringbuffer
*ring
, uint8_t opcode
, uint16_t cnt
)
212 OUT_RING(ring
, CP_TYPE7_PKT
| cnt
|
213 (_odd_parity_bit(cnt
) << 15) |
214 ((opcode
& 0x7f) << 16) |
215 ((_odd_parity_bit(opcode
) << 23)));
219 * code to find stuff in /proc/device-tree:
221 * NOTE: if we sampled the counters from the cmdstream, we could avoid needing
222 * /dev/mem and /proc/device-tree crawling. OTOH when the GPU is heavily loaded
223 * we would be competing with whatever else is using the GPU.
227 readdt(const char *node
)
233 asprintf(&path
, "%s/%s", dev
.dtnode
, node
);
234 buf
= readfile(path
, &sz
);
241 find_freqs_fn(const char *fpath
, const struct stat
*sb
, int typeflag
, struct FTW
*ftwbuf
)
243 const char *fname
= fpath
+ ftwbuf
->base
;
246 if (strcmp(fname
, "qcom,gpu-freq") == 0) {
247 uint32_t *buf
= readfile(fpath
, &sz
);
248 uint32_t freq
= ntohl(buf
[0]);
250 dev
.max_freq
= MAX2(dev
.max_freq
, freq
);
251 dev
.min_freq
= MIN2(dev
.min_freq
, freq
);
266 asprintf(&path
, "%s/%s", dev
.dtnode
, "qcom,gpu-pwrlevels");
268 ret
= nftw(path
, find_freqs_fn
, 64, 0);
270 err(1, "could not find power levels");
276 find_device_fn(const char *fpath
, const struct stat
*sb
, int typeflag
, struct FTW
*ftwbuf
)
278 const char *fname
= fpath
+ ftwbuf
->base
;
281 if (strcmp(fname
, "compatible") == 0) {
282 char *str
= readfile(fpath
, &sz
);
283 if ((strcmp(str
, "qcom,adreno-3xx") == 0) ||
284 (strcmp(str
, "qcom,kgsl-3d0") == 0) ||
285 (strstr(str
, "qcom,adreno") == str
)) {
286 int dlen
= strlen(fpath
) - strlen("/compatible");
287 dev
.dtnode
= malloc(dlen
+ 1);
288 memcpy(dev
.dtnode
, fpath
, dlen
);
289 printf("found dt node: %s\n", dev
.dtnode
);
291 char buf
[dlen
+ sizeof("/../#address-cells") + 1];
294 sprintf(buf
, "%s/../#address-cells", dev
.dtnode
);
295 val
= readfile(buf
, &sz
);
296 dev
.address_cells
= ntohl(*val
);
299 sprintf(buf
, "%s/../#size-cells", dev
.dtnode
);
300 val
= readfile(buf
, &sz
);
301 dev
.size_cells
= ntohl(*val
);
304 printf("#address-cells=%d, #size-cells=%d\n",
305 dev
.address_cells
, dev
.size_cells
);
322 ret
= nftw("/proc/device-tree/", find_device_fn
, 64, 0);
324 err(1, "could not find adreno gpu");
327 errx(1, "could not find qcom,adreno-3xx node");
329 fd
= open("/dev/dri/card0", O_RDWR
);
331 err(1, "could not open drm device");
333 dev
.dev
= fd_device_new(fd
);
334 dev
.pipe
= fd_pipe_new(dev
.dev
, FD_PIPE_3D
);
337 ret
= fd_pipe_get_param(dev
.pipe
, FD_CHIP_ID
, &val
);
339 err(1, "could not get gpu-id");
343 #define CHIP_FMT "d%d%d.%d"
344 #define CHIP_ARGS(chipid) \
345 ((chipid) >> 24) & 0xff, \
346 ((chipid) >> 16) & 0xff, \
347 ((chipid) >> 8) & 0xff, \
348 ((chipid) >> 0) & 0xff
349 printf("device: a%"CHIP_FMT
"\n", CHIP_ARGS(dev
.chipid
));
351 b
= buf
= readdt("reg");
353 if (dev
.address_cells
== 2) {
354 uint32_t u
[2] = { ntohl(buf
[0]), ntohl(buf
[1]) };
355 dev
.base
= (((uint64_t)u
[0]) << 32) | u
[1];
358 dev
.base
= ntohl(buf
[0]);
362 if (dev
.size_cells
== 2) {
363 uint32_t u
[2] = { ntohl(buf
[0]), ntohl(buf
[1]) };
364 dev
.size
= (((uint64_t)u
[0]) << 32) | u
[1];
367 dev
.size
= ntohl(buf
[0]);
373 printf("i/o region at %08"PRIu64
" (size: %x)\n", dev
.base
, dev
.size
);
375 /* try MAX_FREQ first as that will work regardless of old dt
376 * dt bindings vs upstream bindings:
378 ret
= fd_pipe_get_param(dev
.pipe
, FD_MAX_FREQ
, &val
);
380 printf("falling back to parsing DT bindings for freq\n");
387 printf("min_freq=%u, max_freq=%u\n", dev
.min_freq
, dev
.max_freq
);
389 fd
= open("/dev/mem", O_RDWR
| O_SYNC
);
391 err(1, "could not open /dev/mem");
393 dev
.io
= mmap(0, dev
.size
, PROT_READ
| PROT_WRITE
, MAP_SHARED
, fd
, dev
.base
);
395 err(1, "could not map device");
410 ret
= fd_submit_flush(dev
.submit
, -1, NULL
, NULL
);
412 errx(1, "submit failed: %d", ret
);
413 fd_ringbuffer_del(dev
.ring
);
414 fd_submit_del(dev
.submit
);
421 select_counter(struct counter_group
*group
, int ctr
, int n
)
423 assert(n
< group
->group
->num_countables
);
424 assert(ctr
< group
->group
->num_counters
);
426 group
->label
[ctr
] = group
->group
->countables
[n
].name
;
427 group
->counter
[ctr
].select_val
= n
;
430 dev
.submit
= fd_submit_new(dev
.pipe
);
431 dev
.ring
= fd_submit_new_ringbuffer(dev
.submit
, 0x1000,
432 FD_RINGBUFFER_PRIMARY
| FD_RINGBUFFER_GROWABLE
);
435 /* bashing select register directly while gpu is active will end
436 * in tears.. so we need to write it via the ring:
438 * TODO it would help startup time, if gpu is loaded, to batch
439 * all the initial writes and do a single flush.. although that
440 * makes things more complicated for capturing inital sample value
442 struct fd_ringbuffer
*ring
= dev
.ring
;
443 switch (dev
.chipid
>> 24) {
446 OUT_PKT3(ring
, CP_WAIT_FOR_IDLE
, 1);
447 OUT_RING(ring
, 0x00000000);
449 if (group
->group
->counters
[ctr
].enable
) {
450 OUT_PKT0(ring
, group
->group
->counters
[ctr
].enable
, 1);
454 if (group
->group
->counters
[ctr
].clear
) {
455 OUT_PKT0(ring
, group
->group
->counters
[ctr
].clear
, 1);
458 OUT_PKT0(ring
, group
->group
->counters
[ctr
].clear
, 1);
462 OUT_PKT0(ring
, group
->group
->counters
[ctr
].select_reg
, 1);
465 if (group
->group
->counters
[ctr
].enable
) {
466 OUT_PKT0(ring
, group
->group
->counters
[ctr
].enable
, 1);
473 OUT_PKT7(ring
, CP_WAIT_FOR_IDLE
, 0);
475 if (group
->group
->counters
[ctr
].enable
) {
476 OUT_PKT4(ring
, group
->group
->counters
[ctr
].enable
, 1);
480 if (group
->group
->counters
[ctr
].clear
) {
481 OUT_PKT4(ring
, group
->group
->counters
[ctr
].clear
, 1);
484 OUT_PKT4(ring
, group
->group
->counters
[ctr
].clear
, 1);
488 OUT_PKT4(ring
, group
->group
->counters
[ctr
].select_reg
, 1);
491 if (group
->group
->counters
[ctr
].enable
) {
492 OUT_PKT4(ring
, group
->group
->counters
[ctr
].enable
, 1);
499 group
->last
[ctr
] = *group
->counter
[ctr
].val_lo
;
500 group
->stime
[ctr
] = gettime_us();
504 resample_counter(struct counter_group
*group
, int ctr
)
506 uint32_t val
= *group
->counter
[ctr
].val_lo
;
507 uint32_t t
= gettime_us();
508 uint32_t dt
= delta(group
->stime
[ctr
], t
);
509 uint32_t dval
= delta(group
->last
[ctr
], val
);
510 group
->current
[ctr
] = (float)dval
* 1000000.0 / (float)dt
;
511 group
->last
[ctr
] = val
;
512 group
->stime
[ctr
] = t
;
515 #define REFRESH_MS 500
517 /* sample all the counters: */
521 static uint64_t last_time
;
522 uint64_t current_time
= gettime_us();
524 if ((current_time
- last_time
) < (REFRESH_MS
* 1000 / 2))
527 last_time
= current_time
;
529 for (unsigned i
= 0; i
< dev
.ngroups
; i
++) {
530 struct counter_group
*group
= &dev
.groups
[i
];
531 for (unsigned j
= 0; j
< group
->group
->num_counters
; j
++) {
532 resample_counter(group
, j
);
541 #define COLOR_GROUP_HEADER 1
542 #define COLOR_FOOTER 2
543 #define COLOR_INVERSE 3
546 static int ctr_width
;
547 static int max_rows
, current_cntr
= 1;
550 redraw_footer(WINDOW
*win
)
555 n
= asprintf(&footer
, " fdperf: a%"CHIP_FMT
" (%.2fMHz..%.2fMHz)",
556 CHIP_ARGS(dev
.chipid
),
557 ((float)dev
.min_freq
) / 1000000.0,
558 ((float)dev
.max_freq
) / 1000000.0);
560 wmove(win
, h
- 1, 0);
561 wattron(win
, COLOR_PAIR(COLOR_FOOTER
));
562 waddstr(win
, footer
);
563 whline(win
, ' ', w
- n
);
564 wattroff(win
, COLOR_PAIR(COLOR_FOOTER
));
570 redraw_group_header(WINDOW
*win
, int row
, const char *name
)
573 wattron(win
, A_BOLD
);
574 wattron(win
, COLOR_PAIR(COLOR_GROUP_HEADER
));
576 whline(win
, ' ', w
- strlen(name
));
577 wattroff(win
, COLOR_PAIR(COLOR_GROUP_HEADER
));
578 wattroff(win
, A_BOLD
);
582 redraw_counter_label(WINDOW
*win
, int row
, const char *name
, bool selected
)
584 int n
= strlen(name
);
585 assert(n
<= ctr_width
);
587 whline(win
, ' ', ctr_width
- n
);
588 wmove(win
, row
, ctr_width
- n
);
590 wattron(win
, COLOR_PAIR(COLOR_INVERSE
));
593 wattroff(win
, COLOR_PAIR(COLOR_INVERSE
));
598 redraw_counter_value_cycles(WINDOW
*win
, float val
)
601 int x
= getcurx(win
);
602 int valwidth
= w
- x
;
605 /* convert to fraction of max freq: */
606 val
= val
/ (float)dev
.max_freq
;
608 /* figure out percentage-bar width: */
609 barwidth
= (int)(val
* valwidth
);
611 /* sometimes things go over 100%.. idk why, could be
612 * things running faster than base clock, or counter
613 * summing up cycles in multiple cores?
615 barwidth
= MIN2(barwidth
, valwidth
- 1);
617 n
= asprintf(&str
, "%.2f%%", 100.0 * val
);
618 wattron(win
, COLOR_PAIR(COLOR_INVERSE
));
619 waddnstr(win
, str
, barwidth
);
621 whline(win
, ' ', barwidth
- n
);
622 wmove(win
, getcury(win
), x
+ barwidth
);
624 wattroff(win
, COLOR_PAIR(COLOR_INVERSE
));
626 waddstr(win
, str
+ barwidth
);
627 whline(win
, ' ', w
- getcurx(win
));
633 redraw_counter_value_raw(WINDOW
*win
, float val
)
636 asprintf(&str
, "%'.2f", val
);
638 whline(win
, ' ', w
- getcurx(win
));
643 redraw_counter(WINDOW
*win
, int row
, struct counter_group
*group
,
644 int ctr
, bool selected
)
646 redraw_counter_label(win
, row
, group
->label
[ctr
], selected
);
648 /* quick hack, if the label has "CYCLE" in the name, it is
649 * probably a cycle counter ;-)
650 * Perhaps add more info in rnndb schema to know how to
651 * treat individual counters (ie. which are cycles, and
652 * for those we want to present as a percentage do we
653 * need to scale the result.. ie. is it running at some
654 * multiple or divisor of core clk, etc)
656 * TODO it would be much more clever to get this from xml
657 * Also.. in some cases I think we want to know how many
658 * units the counter is counting for, ie. if a320 has 2x
659 * shader as a306 we might need to scale the result..
661 if (strstr(group
->label
[ctr
], "CYCLE") ||
662 strstr(group
->label
[ctr
], "BUSY") ||
663 strstr(group
->label
[ctr
], "IDLE"))
664 redraw_counter_value_cycles(win
, group
->current
[ctr
]);
666 redraw_counter_value_raw(win
, group
->current
[ctr
]);
672 static int scroll
= 0;
680 if ((current_cntr
- scroll
) > (max
- 1)) {
681 scroll
= current_cntr
- (max
- 1);
682 } else if ((current_cntr
- 1) < scroll
) {
683 scroll
= current_cntr
- 1;
686 for (unsigned i
= 0; i
< dev
.ngroups
; i
++) {
687 struct counter_group
*group
= &dev
.groups
[i
];
690 /* NOTE skip CP the first CP counter */
694 if (j
< group
->group
->num_counters
) {
695 if ((scroll
<= row
) && ((row
- scroll
) < max
))
696 redraw_group_header(win
, row
- scroll
, group
->group
->name
);
700 for (; j
< group
->group
->num_counters
; j
++) {
701 if ((scroll
<= row
) && ((row
- scroll
) < max
))
702 redraw_counter(win
, row
- scroll
, group
, j
, row
== current_cntr
);
707 /* convert back to physical (unscrolled) offset: */
710 redraw_group_header(win
, row
, "Status");
713 /* Draw GPU freq row: */
714 redraw_counter_label(win
, row
, "Freq (MHz)", false);
715 redraw_counter_value_raw(win
, dev
.groups
[0].current
[0] / 1000000.0);
723 static struct counter_group
*
724 current_counter(int *ctr
)
728 for (unsigned i
= 0; i
< dev
.ngroups
; i
++) {
729 struct counter_group
*group
= &dev
.groups
[i
];
732 /* NOTE skip the first CP counter (CP_ALWAYS_COUNT) */
736 /* account for group header: */
737 if (j
< group
->group
->num_counters
) {
738 /* cannot select group header.. return null to indicate this
741 if (n
== current_cntr
)
747 for (; j
< group
->group
->num_counters
; j
++) {
748 if (n
== current_cntr
) {
765 struct counter_group
*group
;
766 int cnt
, current
= 0, scroll
;
768 /* figure out dialog size: */
770 int dw
= ctr_width
+ 2;
772 group
= current_counter(&cnt
);
774 /* find currently selected idx (note there can be discontinuities
775 * so the selected value does not map 1:1 to current idx)
777 uint32_t selected
= group
->counter
[cnt
].select_val
;
778 for (int i
= 0; i
< group
->group
->num_countables
; i
++) {
779 if (group
->group
->countables
[i
].selector
== selected
) {
785 /* scrolling offset, if dialog is too small for all the choices: */
788 dialog
= newwin(dh
, dw
, (h
-dh
)/2, (w
-dw
)/2);
791 keypad(dialog
, TRUE
);
794 int max
= MIN2(dh
- 2, group
->group
->num_countables
);
797 if ((current
- scroll
) >= (dh
- 3)) {
798 scroll
= current
- (dh
- 3);
799 } else if (current
< scroll
) {
803 for (int i
= 0; i
< max
; i
++) {
805 wmove(dialog
, i
+1, 1);
807 assert (n
< group
->group
->num_countables
);
808 selector
= group
->group
->countables
[n
].selector
;
809 wattron(dialog
, COLOR_PAIR(COLOR_INVERSE
));
811 if (n
< group
->group
->num_countables
)
812 waddstr(dialog
, group
->group
->countables
[n
].name
);
813 whline(dialog
, ' ', dw
- getcurx(dialog
) - 1);
815 wattroff(dialog
, COLOR_PAIR(COLOR_INVERSE
));
818 assert (selector
>= 0);
820 switch (wgetch(dialog
)) {
822 current
= MAX2(0, current
- 1);
825 current
= MIN2(group
->group
->num_countables
- 1, current
+ 1);
829 /* select new sampler */
830 select_counter(group
, cnt
, selector
);
845 wborder(dialog
, ' ', ' ', ' ',' ',' ',' ',' ',' ');
850 scroll_cntr(int amount
)
853 current_cntr
= MAX2(1, current_cntr
+ amount
);
854 if (current_counter(NULL
) == NULL
) {
855 current_cntr
= MAX2(1, current_cntr
- 1);
858 current_cntr
= MIN2(max_rows
- 1, current_cntr
+ amount
);
859 if (current_counter(NULL
) == NULL
)
860 current_cntr
= MIN2(max_rows
- 1, current_cntr
+ 1);
868 uint32_t last_time
= gettime_us();
876 wtimeout(mainwin
, REFRESH_MS
);
878 keypad(mainwin
, TRUE
);
881 init_pair(COLOR_GROUP_HEADER
, COLOR_WHITE
, COLOR_GREEN
);
882 init_pair(COLOR_FOOTER
, COLOR_WHITE
, COLOR_BLUE
);
883 init_pair(COLOR_INVERSE
, COLOR_BLACK
, COLOR_WHITE
);
886 switch (wgetch(mainwin
)) {
893 case KEY_NPAGE
: /* page-down */
894 /* TODO figure out # of rows visible? */
897 case KEY_PPAGE
: /* page-up */
898 /* TODO figure out # of rows visible? */
914 /* restore the counters every 0.5s in case the GPU has suspended,
915 * in which case the current selected countables will have reset:
917 uint32_t t
= gettime_us();
918 if (delta(last_time
, t
) > 500000) {
919 restore_counter_groups();
925 /* restore settings.. maybe we need an atexit()??*/
933 restore_counter_groups(void)
935 for (unsigned i
= 0; i
< dev
.ngroups
; i
++) {
936 struct counter_group
*group
= &dev
.groups
[i
];
939 /* NOTE skip CP the first CP counter */
943 for (; j
< group
->group
->num_counters
; j
++) {
944 select_counter(group
, j
, group
->counter
[j
].select_val
);
950 setup_counter_groups(const struct fd_perfcntr_group
*groups
)
952 for (unsigned i
= 0; i
< dev
.ngroups
; i
++) {
953 struct counter_group
*group
= &dev
.groups
[i
];
955 group
->group
= &groups
[i
];
957 max_rows
+= group
->group
->num_counters
+ 1;
959 /* the first CP counter is hidden: */
962 if (group
->group
->num_counters
<= 1)
966 for (unsigned j
= 0; j
< group
->group
->num_counters
; j
++) {
967 group
->counter
[j
].counter
= &group
->group
->counters
[j
];
969 group
->counter
[j
].val_hi
= dev
.io
+ (group
->counter
[j
].counter
->counter_reg_hi
* 4);
970 group
->counter
[j
].val_lo
= dev
.io
+ (group
->counter
[j
].counter
->counter_reg_lo
* 4);
972 group
->counter
[j
].select_val
= j
;
975 for (unsigned j
= 0; j
< group
->group
->num_countables
; j
++) {
976 ctr_width
= MAX2(ctr_width
, strlen(group
->group
->countables
[j
].name
) + 1);
982 * configuration / persistence
986 static config_setting_t
*setting
;
991 for (unsigned i
= 0; i
< dev
.ngroups
; i
++) {
992 struct counter_group
*group
= &dev
.groups
[i
];
995 /* NOTE skip CP the first CP counter */
999 config_setting_t
*sect
=
1000 config_setting_get_member(setting
, group
->group
->name
);
1002 for (; j
< group
->group
->num_counters
; j
++) {
1003 char name
[] = "counter0000";
1004 sprintf(name
, "counter%d", j
);
1005 config_setting_t
*s
=
1006 config_setting_lookup(sect
, name
);
1007 config_setting_set_int(s
, group
->counter
[j
].select_val
);
1011 config_write_file(&cfg
, "fdperf.cfg");
1015 config_restore(void)
1021 /* Read the file. If there is an error, report it and exit. */
1022 if(!config_read_file(&cfg
, "fdperf.cfg")) {
1023 warn("could not restore settings");
1026 config_setting_t
*root
= config_root_setting(&cfg
);
1028 /* per device settings: */
1029 asprintf(&str
, "a%dxx", dev
.chipid
>> 24);
1030 setting
= config_setting_get_member(root
, str
);
1032 setting
= config_setting_add(root
, str
, CONFIG_TYPE_GROUP
);
1035 for (unsigned i
= 0; i
< dev
.ngroups
; i
++) {
1036 struct counter_group
*group
= &dev
.groups
[i
];
1039 /* NOTE skip CP the first CP counter */
1043 config_setting_t
*sect
=
1044 config_setting_get_member(setting
, group
->group
->name
);
1047 sect
= config_setting_add(setting
, group
->group
->name
,
1051 for (; j
< group
->group
->num_counters
; j
++) {
1052 char name
[] = "counter0000";
1053 sprintf(name
, "counter%d", j
);
1054 config_setting_t
*s
= config_setting_lookup(sect
, name
);
1056 config_setting_add(sect
, name
, CONFIG_TYPE_INT
);
1059 select_counter(group
, j
, config_setting_get_int(s
));
1069 main(int argc
, char **argv
)
1073 const struct fd_perfcntr_group
*groups
;
1074 groups
= fd_perfcntrs((dev
.chipid
>> 24) * 100, &dev
.ngroups
);
1076 errx(1, "no perfcntr support");
1079 dev
.groups
= calloc(dev
.ngroups
, sizeof(struct counter_group
));
1081 setup_counter_groups(groups
);
1082 restore_counter_groups();