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
, "amd,imageon") == str
) ||
286 (strstr(str
, "qcom,adreno") == str
)) {
287 int dlen
= strlen(fpath
) - strlen("/compatible");
288 dev
.dtnode
= malloc(dlen
+ 1);
289 memcpy(dev
.dtnode
, fpath
, dlen
);
290 printf("found dt node: %s\n", dev
.dtnode
);
292 char buf
[dlen
+ sizeof("/../#address-cells") + 1];
295 sprintf(buf
, "%s/../#address-cells", dev
.dtnode
);
296 val
= readfile(buf
, &sz
);
297 dev
.address_cells
= ntohl(*val
);
300 sprintf(buf
, "%s/../#size-cells", dev
.dtnode
);
301 val
= readfile(buf
, &sz
);
302 dev
.size_cells
= ntohl(*val
);
305 printf("#address-cells=%d, #size-cells=%d\n",
306 dev
.address_cells
, dev
.size_cells
);
323 ret
= nftw("/proc/device-tree/", find_device_fn
, 64, 0);
325 err(1, "could not find adreno gpu");
328 errx(1, "could not find qcom,adreno-3xx node");
330 fd
= open("/dev/dri/card0", O_RDWR
);
332 err(1, "could not open drm device");
334 dev
.dev
= fd_device_new(fd
);
335 dev
.pipe
= fd_pipe_new(dev
.dev
, FD_PIPE_3D
);
338 ret
= fd_pipe_get_param(dev
.pipe
, FD_CHIP_ID
, &val
);
340 err(1, "could not get gpu-id");
344 #define CHIP_FMT "d%d%d.%d"
345 #define CHIP_ARGS(chipid) \
346 ((chipid) >> 24) & 0xff, \
347 ((chipid) >> 16) & 0xff, \
348 ((chipid) >> 8) & 0xff, \
349 ((chipid) >> 0) & 0xff
350 printf("device: a%"CHIP_FMT
"\n", CHIP_ARGS(dev
.chipid
));
352 b
= buf
= readdt("reg");
354 if (dev
.address_cells
== 2) {
355 uint32_t u
[2] = { ntohl(buf
[0]), ntohl(buf
[1]) };
356 dev
.base
= (((uint64_t)u
[0]) << 32) | u
[1];
359 dev
.base
= ntohl(buf
[0]);
363 if (dev
.size_cells
== 2) {
364 uint32_t u
[2] = { ntohl(buf
[0]), ntohl(buf
[1]) };
365 dev
.size
= (((uint64_t)u
[0]) << 32) | u
[1];
368 dev
.size
= ntohl(buf
[0]);
374 printf("i/o region at %08"PRIu64
" (size: %x)\n", dev
.base
, dev
.size
);
376 /* try MAX_FREQ first as that will work regardless of old dt
377 * dt bindings vs upstream bindings:
379 ret
= fd_pipe_get_param(dev
.pipe
, FD_MAX_FREQ
, &val
);
381 printf("falling back to parsing DT bindings for freq\n");
388 printf("min_freq=%u, max_freq=%u\n", dev
.min_freq
, dev
.max_freq
);
390 fd
= open("/dev/mem", O_RDWR
| O_SYNC
);
392 err(1, "could not open /dev/mem");
394 dev
.io
= mmap(0, dev
.size
, PROT_READ
| PROT_WRITE
, MAP_SHARED
, fd
, dev
.base
);
396 err(1, "could not map device");
411 ret
= fd_submit_flush(dev
.submit
, -1, NULL
, NULL
);
413 errx(1, "submit failed: %d", ret
);
414 fd_ringbuffer_del(dev
.ring
);
415 fd_submit_del(dev
.submit
);
422 select_counter(struct counter_group
*group
, int ctr
, int n
)
424 assert(n
< group
->group
->num_countables
);
425 assert(ctr
< group
->group
->num_counters
);
427 group
->label
[ctr
] = group
->group
->countables
[n
].name
;
428 group
->counter
[ctr
].select_val
= n
;
431 dev
.submit
= fd_submit_new(dev
.pipe
);
432 dev
.ring
= fd_submit_new_ringbuffer(dev
.submit
, 0x1000,
433 FD_RINGBUFFER_PRIMARY
| FD_RINGBUFFER_GROWABLE
);
436 /* bashing select register directly while gpu is active will end
437 * in tears.. so we need to write it via the ring:
439 * TODO it would help startup time, if gpu is loaded, to batch
440 * all the initial writes and do a single flush.. although that
441 * makes things more complicated for capturing inital sample value
443 struct fd_ringbuffer
*ring
= dev
.ring
;
444 switch (dev
.chipid
>> 24) {
448 OUT_PKT3(ring
, CP_WAIT_FOR_IDLE
, 1);
449 OUT_RING(ring
, 0x00000000);
451 if (group
->group
->counters
[ctr
].enable
) {
452 OUT_PKT0(ring
, group
->group
->counters
[ctr
].enable
, 1);
456 if (group
->group
->counters
[ctr
].clear
) {
457 OUT_PKT0(ring
, group
->group
->counters
[ctr
].clear
, 1);
460 OUT_PKT0(ring
, group
->group
->counters
[ctr
].clear
, 1);
464 OUT_PKT0(ring
, group
->group
->counters
[ctr
].select_reg
, 1);
467 if (group
->group
->counters
[ctr
].enable
) {
468 OUT_PKT0(ring
, group
->group
->counters
[ctr
].enable
, 1);
475 OUT_PKT7(ring
, CP_WAIT_FOR_IDLE
, 0);
477 if (group
->group
->counters
[ctr
].enable
) {
478 OUT_PKT4(ring
, group
->group
->counters
[ctr
].enable
, 1);
482 if (group
->group
->counters
[ctr
].clear
) {
483 OUT_PKT4(ring
, group
->group
->counters
[ctr
].clear
, 1);
486 OUT_PKT4(ring
, group
->group
->counters
[ctr
].clear
, 1);
490 OUT_PKT4(ring
, group
->group
->counters
[ctr
].select_reg
, 1);
493 if (group
->group
->counters
[ctr
].enable
) {
494 OUT_PKT4(ring
, group
->group
->counters
[ctr
].enable
, 1);
501 group
->last
[ctr
] = *group
->counter
[ctr
].val_lo
;
502 group
->stime
[ctr
] = gettime_us();
506 resample_counter(struct counter_group
*group
, int ctr
)
508 uint32_t val
= *group
->counter
[ctr
].val_lo
;
509 uint32_t t
= gettime_us();
510 uint32_t dt
= delta(group
->stime
[ctr
], t
);
511 uint32_t dval
= delta(group
->last
[ctr
], val
);
512 group
->current
[ctr
] = (float)dval
* 1000000.0 / (float)dt
;
513 group
->last
[ctr
] = val
;
514 group
->stime
[ctr
] = t
;
517 #define REFRESH_MS 500
519 /* sample all the counters: */
523 static uint64_t last_time
;
524 uint64_t current_time
= gettime_us();
526 if ((current_time
- last_time
) < (REFRESH_MS
* 1000 / 2))
529 last_time
= current_time
;
531 for (unsigned i
= 0; i
< dev
.ngroups
; i
++) {
532 struct counter_group
*group
= &dev
.groups
[i
];
533 for (unsigned j
= 0; j
< group
->group
->num_counters
; j
++) {
534 resample_counter(group
, j
);
543 #define COLOR_GROUP_HEADER 1
544 #define COLOR_FOOTER 2
545 #define COLOR_INVERSE 3
548 static int ctr_width
;
549 static int max_rows
, current_cntr
= 1;
552 redraw_footer(WINDOW
*win
)
557 n
= asprintf(&footer
, " fdperf: a%"CHIP_FMT
" (%.2fMHz..%.2fMHz)",
558 CHIP_ARGS(dev
.chipid
),
559 ((float)dev
.min_freq
) / 1000000.0,
560 ((float)dev
.max_freq
) / 1000000.0);
562 wmove(win
, h
- 1, 0);
563 wattron(win
, COLOR_PAIR(COLOR_FOOTER
));
564 waddstr(win
, footer
);
565 whline(win
, ' ', w
- n
);
566 wattroff(win
, COLOR_PAIR(COLOR_FOOTER
));
572 redraw_group_header(WINDOW
*win
, int row
, const char *name
)
575 wattron(win
, A_BOLD
);
576 wattron(win
, COLOR_PAIR(COLOR_GROUP_HEADER
));
578 whline(win
, ' ', w
- strlen(name
));
579 wattroff(win
, COLOR_PAIR(COLOR_GROUP_HEADER
));
580 wattroff(win
, A_BOLD
);
584 redraw_counter_label(WINDOW
*win
, int row
, const char *name
, bool selected
)
586 int n
= strlen(name
);
587 assert(n
<= ctr_width
);
589 whline(win
, ' ', ctr_width
- n
);
590 wmove(win
, row
, ctr_width
- n
);
592 wattron(win
, COLOR_PAIR(COLOR_INVERSE
));
595 wattroff(win
, COLOR_PAIR(COLOR_INVERSE
));
600 redraw_counter_value_cycles(WINDOW
*win
, float val
)
603 int x
= getcurx(win
);
604 int valwidth
= w
- x
;
607 /* convert to fraction of max freq: */
608 val
= val
/ (float)dev
.max_freq
;
610 /* figure out percentage-bar width: */
611 barwidth
= (int)(val
* valwidth
);
613 /* sometimes things go over 100%.. idk why, could be
614 * things running faster than base clock, or counter
615 * summing up cycles in multiple cores?
617 barwidth
= MIN2(barwidth
, valwidth
- 1);
619 n
= asprintf(&str
, "%.2f%%", 100.0 * val
);
620 wattron(win
, COLOR_PAIR(COLOR_INVERSE
));
621 waddnstr(win
, str
, barwidth
);
623 whline(win
, ' ', barwidth
- n
);
624 wmove(win
, getcury(win
), x
+ barwidth
);
626 wattroff(win
, COLOR_PAIR(COLOR_INVERSE
));
628 waddstr(win
, str
+ barwidth
);
629 whline(win
, ' ', w
- getcurx(win
));
635 redraw_counter_value_raw(WINDOW
*win
, float val
)
638 asprintf(&str
, "%'.2f", val
);
640 whline(win
, ' ', w
- getcurx(win
));
645 redraw_counter(WINDOW
*win
, int row
, struct counter_group
*group
,
646 int ctr
, bool selected
)
648 redraw_counter_label(win
, row
, group
->label
[ctr
], selected
);
650 /* quick hack, if the label has "CYCLE" in the name, it is
651 * probably a cycle counter ;-)
652 * Perhaps add more info in rnndb schema to know how to
653 * treat individual counters (ie. which are cycles, and
654 * for those we want to present as a percentage do we
655 * need to scale the result.. ie. is it running at some
656 * multiple or divisor of core clk, etc)
658 * TODO it would be much more clever to get this from xml
659 * Also.. in some cases I think we want to know how many
660 * units the counter is counting for, ie. if a320 has 2x
661 * shader as a306 we might need to scale the result..
663 if (strstr(group
->label
[ctr
], "CYCLE") ||
664 strstr(group
->label
[ctr
], "BUSY") ||
665 strstr(group
->label
[ctr
], "IDLE"))
666 redraw_counter_value_cycles(win
, group
->current
[ctr
]);
668 redraw_counter_value_raw(win
, group
->current
[ctr
]);
674 static int scroll
= 0;
682 if ((current_cntr
- scroll
) > (max
- 1)) {
683 scroll
= current_cntr
- (max
- 1);
684 } else if ((current_cntr
- 1) < scroll
) {
685 scroll
= current_cntr
- 1;
688 for (unsigned i
= 0; i
< dev
.ngroups
; i
++) {
689 struct counter_group
*group
= &dev
.groups
[i
];
692 /* NOTE skip CP the first CP counter */
696 if (j
< group
->group
->num_counters
) {
697 if ((scroll
<= row
) && ((row
- scroll
) < max
))
698 redraw_group_header(win
, row
- scroll
, group
->group
->name
);
702 for (; j
< group
->group
->num_counters
; j
++) {
703 if ((scroll
<= row
) && ((row
- scroll
) < max
))
704 redraw_counter(win
, row
- scroll
, group
, j
, row
== current_cntr
);
709 /* convert back to physical (unscrolled) offset: */
712 redraw_group_header(win
, row
, "Status");
715 /* Draw GPU freq row: */
716 redraw_counter_label(win
, row
, "Freq (MHz)", false);
717 redraw_counter_value_raw(win
, dev
.groups
[0].current
[0] / 1000000.0);
725 static struct counter_group
*
726 current_counter(int *ctr
)
730 for (unsigned i
= 0; i
< dev
.ngroups
; i
++) {
731 struct counter_group
*group
= &dev
.groups
[i
];
734 /* NOTE skip the first CP counter (CP_ALWAYS_COUNT) */
738 /* account for group header: */
739 if (j
< group
->group
->num_counters
) {
740 /* cannot select group header.. return null to indicate this
743 if (n
== current_cntr
)
749 for (; j
< group
->group
->num_counters
; j
++) {
750 if (n
== current_cntr
) {
767 struct counter_group
*group
;
768 int cnt
, current
= 0, scroll
;
770 /* figure out dialog size: */
772 int dw
= ctr_width
+ 2;
774 group
= current_counter(&cnt
);
776 /* find currently selected idx (note there can be discontinuities
777 * so the selected value does not map 1:1 to current idx)
779 uint32_t selected
= group
->counter
[cnt
].select_val
;
780 for (int i
= 0; i
< group
->group
->num_countables
; i
++) {
781 if (group
->group
->countables
[i
].selector
== selected
) {
787 /* scrolling offset, if dialog is too small for all the choices: */
790 dialog
= newwin(dh
, dw
, (h
-dh
)/2, (w
-dw
)/2);
793 keypad(dialog
, TRUE
);
796 int max
= MIN2(dh
- 2, group
->group
->num_countables
);
799 if ((current
- scroll
) >= (dh
- 3)) {
800 scroll
= current
- (dh
- 3);
801 } else if (current
< scroll
) {
805 for (int i
= 0; i
< max
; i
++) {
807 wmove(dialog
, i
+1, 1);
809 assert (n
< group
->group
->num_countables
);
810 selector
= group
->group
->countables
[n
].selector
;
811 wattron(dialog
, COLOR_PAIR(COLOR_INVERSE
));
813 if (n
< group
->group
->num_countables
)
814 waddstr(dialog
, group
->group
->countables
[n
].name
);
815 whline(dialog
, ' ', dw
- getcurx(dialog
) - 1);
817 wattroff(dialog
, COLOR_PAIR(COLOR_INVERSE
));
820 assert (selector
>= 0);
822 switch (wgetch(dialog
)) {
824 current
= MAX2(0, current
- 1);
827 current
= MIN2(group
->group
->num_countables
- 1, current
+ 1);
831 /* select new sampler */
832 select_counter(group
, cnt
, selector
);
847 wborder(dialog
, ' ', ' ', ' ',' ',' ',' ',' ',' ');
852 scroll_cntr(int amount
)
855 current_cntr
= MAX2(1, current_cntr
+ amount
);
856 if (current_counter(NULL
) == NULL
) {
857 current_cntr
= MAX2(1, current_cntr
- 1);
860 current_cntr
= MIN2(max_rows
- 1, current_cntr
+ amount
);
861 if (current_counter(NULL
) == NULL
)
862 current_cntr
= MIN2(max_rows
- 1, current_cntr
+ 1);
870 uint32_t last_time
= gettime_us();
878 wtimeout(mainwin
, REFRESH_MS
);
880 keypad(mainwin
, TRUE
);
883 init_pair(COLOR_GROUP_HEADER
, COLOR_WHITE
, COLOR_GREEN
);
884 init_pair(COLOR_FOOTER
, COLOR_WHITE
, COLOR_BLUE
);
885 init_pair(COLOR_INVERSE
, COLOR_BLACK
, COLOR_WHITE
);
888 switch (wgetch(mainwin
)) {
895 case KEY_NPAGE
: /* page-down */
896 /* TODO figure out # of rows visible? */
899 case KEY_PPAGE
: /* page-up */
900 /* TODO figure out # of rows visible? */
916 /* restore the counters every 0.5s in case the GPU has suspended,
917 * in which case the current selected countables will have reset:
919 uint32_t t
= gettime_us();
920 if (delta(last_time
, t
) > 500000) {
921 restore_counter_groups();
927 /* restore settings.. maybe we need an atexit()??*/
935 restore_counter_groups(void)
937 for (unsigned i
= 0; i
< dev
.ngroups
; i
++) {
938 struct counter_group
*group
= &dev
.groups
[i
];
941 /* NOTE skip CP the first CP counter */
945 for (; j
< group
->group
->num_counters
; j
++) {
946 select_counter(group
, j
, group
->counter
[j
].select_val
);
952 setup_counter_groups(const struct fd_perfcntr_group
*groups
)
954 for (unsigned i
= 0; i
< dev
.ngroups
; i
++) {
955 struct counter_group
*group
= &dev
.groups
[i
];
957 group
->group
= &groups
[i
];
959 max_rows
+= group
->group
->num_counters
+ 1;
961 /* the first CP counter is hidden: */
964 if (group
->group
->num_counters
<= 1)
968 for (unsigned j
= 0; j
< group
->group
->num_counters
; j
++) {
969 group
->counter
[j
].counter
= &group
->group
->counters
[j
];
971 group
->counter
[j
].val_hi
= dev
.io
+ (group
->counter
[j
].counter
->counter_reg_hi
* 4);
972 group
->counter
[j
].val_lo
= dev
.io
+ (group
->counter
[j
].counter
->counter_reg_lo
* 4);
974 group
->counter
[j
].select_val
= j
;
977 for (unsigned j
= 0; j
< group
->group
->num_countables
; j
++) {
978 ctr_width
= MAX2(ctr_width
, strlen(group
->group
->countables
[j
].name
) + 1);
984 * configuration / persistence
988 static config_setting_t
*setting
;
993 for (unsigned i
= 0; i
< dev
.ngroups
; i
++) {
994 struct counter_group
*group
= &dev
.groups
[i
];
997 /* NOTE skip CP the first CP counter */
1001 config_setting_t
*sect
=
1002 config_setting_get_member(setting
, group
->group
->name
);
1004 for (; j
< group
->group
->num_counters
; j
++) {
1005 char name
[] = "counter0000";
1006 sprintf(name
, "counter%d", j
);
1007 config_setting_t
*s
=
1008 config_setting_lookup(sect
, name
);
1009 config_setting_set_int(s
, group
->counter
[j
].select_val
);
1013 config_write_file(&cfg
, "fdperf.cfg");
1017 config_restore(void)
1023 /* Read the file. If there is an error, report it and exit. */
1024 if(!config_read_file(&cfg
, "fdperf.cfg")) {
1025 warn("could not restore settings");
1028 config_setting_t
*root
= config_root_setting(&cfg
);
1030 /* per device settings: */
1031 asprintf(&str
, "a%dxx", dev
.chipid
>> 24);
1032 setting
= config_setting_get_member(root
, str
);
1034 setting
= config_setting_add(root
, str
, CONFIG_TYPE_GROUP
);
1037 for (unsigned i
= 0; i
< dev
.ngroups
; i
++) {
1038 struct counter_group
*group
= &dev
.groups
[i
];
1041 /* NOTE skip CP the first CP counter */
1045 config_setting_t
*sect
=
1046 config_setting_get_member(setting
, group
->group
->name
);
1049 sect
= config_setting_add(setting
, group
->group
->name
,
1053 for (; j
< group
->group
->num_counters
; j
++) {
1054 char name
[] = "counter0000";
1055 sprintf(name
, "counter%d", j
);
1056 config_setting_t
*s
= config_setting_lookup(sect
, name
);
1058 config_setting_add(sect
, name
, CONFIG_TYPE_INT
);
1061 select_counter(group
, j
, config_setting_get_int(s
));
1071 main(int argc
, char **argv
)
1075 const struct fd_perfcntr_group
*groups
;
1076 groups
= fd_perfcntrs((dev
.chipid
>> 24) * 100, &dev
.ngroups
);
1078 errx(1, "no perfcntr support");
1081 dev
.groups
= calloc(dev
.ngroups
, sizeof(struct counter_group
));
1083 setup_counter_groups(groups
);
1084 restore_counter_groups();