1 // SPDX-License-Identifier: GPL-2.0
3 * This is rewrite of original c2c tool introduced in here:
4 * http://lwn.net/Articles/588866/
6 * The original tool was changed to fit in current perf state.
9 * Don Zickus <dzickus@redhat.com>
10 * Dick Fowles <fowles@inreach.com>
11 * Joe Mario <jmario@redhat.com>
15 #include <linux/compiler.h>
16 #include <linux/kernel.h>
17 #include <linux/stringify.h>
19 #include <sys/param.h>
23 #include <subcmd/parse-options.h>
24 #include "mem-events.h"
33 #include "ui/browsers/hists.h"
40 struct perf_hpp_list list
;
41 struct c2c_stats stats
;
44 struct compute_stats
{
45 struct stats lcl_hitm
;
46 struct stats rmt_hitm
;
50 struct c2c_hist_entry
{
51 struct c2c_hists
*hists
;
52 struct c2c_stats stats
;
53 unsigned long *cpuset
;
54 unsigned long *nodeset
;
55 struct c2c_stats
*node_stats
;
56 unsigned int cacheline_idx
;
58 struct compute_stats cstats
;
61 unsigned long paddr_cnt
;
67 * because of its callchain dynamic entry
72 static char const *coalesce_default
= "iaddr";
75 struct perf_tool tool
;
76 struct c2c_hists hists
;
77 struct mem2node mem2node
;
79 unsigned long **nodes
;
91 /* HITM shared clines stats */
92 struct c2c_stats hitm_stats
;
110 static const char *display_str
[DISPLAY_MAX
] = {
111 [DISPLAY_LCL
] = "Local",
112 [DISPLAY_RMT
] = "Remote",
113 [DISPLAY_TOT
] = "Total",
116 static const struct option c2c_options
[] = {
117 OPT_INCR('v', "verbose", &verbose
, "be more verbose (show counter open errors, etc)"),
121 static struct perf_c2c c2c
;
123 static void *c2c_he_zalloc(size_t size
)
125 struct c2c_hist_entry
*c2c_he
;
127 c2c_he
= zalloc(size
+ sizeof(*c2c_he
));
131 c2c_he
->cpuset
= bitmap_alloc(c2c
.cpus_cnt
);
135 c2c_he
->nodeset
= bitmap_alloc(c2c
.nodes_cnt
);
136 if (!c2c_he
->nodeset
)
139 c2c_he
->node_stats
= zalloc(c2c
.nodes_cnt
* sizeof(*c2c_he
->node_stats
));
140 if (!c2c_he
->node_stats
)
143 init_stats(&c2c_he
->cstats
.lcl_hitm
);
144 init_stats(&c2c_he
->cstats
.rmt_hitm
);
145 init_stats(&c2c_he
->cstats
.load
);
150 static void c2c_he_free(void *he
)
152 struct c2c_hist_entry
*c2c_he
;
154 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
156 hists__delete_entries(&c2c_he
->hists
->hists
);
160 free(c2c_he
->cpuset
);
161 free(c2c_he
->nodeset
);
162 free(c2c_he
->nodestr
);
163 free(c2c_he
->node_stats
);
167 static struct hist_entry_ops c2c_entry_ops
= {
168 .new = c2c_he_zalloc
,
172 static int c2c_hists__init(struct c2c_hists
*hists
,
174 int nr_header_lines
);
176 static struct c2c_hists
*
177 he__get_c2c_hists(struct hist_entry
*he
,
181 struct c2c_hist_entry
*c2c_he
;
182 struct c2c_hists
*hists
;
185 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
187 return c2c_he
->hists
;
189 hists
= c2c_he
->hists
= zalloc(sizeof(*hists
));
193 ret
= c2c_hists__init(hists
, sort
, nr_header_lines
);
202 static void c2c_he__set_cpu(struct c2c_hist_entry
*c2c_he
,
203 struct perf_sample
*sample
)
205 if (WARN_ONCE(sample
->cpu
== (unsigned int) -1,
206 "WARNING: no sample cpu value"))
209 set_bit(sample
->cpu
, c2c_he
->cpuset
);
212 static void c2c_he__set_node(struct c2c_hist_entry
*c2c_he
,
213 struct perf_sample
*sample
)
217 if (!sample
->phys_addr
) {
218 c2c_he
->paddr_zero
= true;
222 node
= mem2node__node(&c2c
.mem2node
, sample
->phys_addr
);
223 if (WARN_ONCE(node
< 0, "WARNING: failed to find node\n"))
226 set_bit(node
, c2c_he
->nodeset
);
228 if (c2c_he
->paddr
!= sample
->phys_addr
) {
230 c2c_he
->paddr
= sample
->phys_addr
;
234 static void compute_stats(struct c2c_hist_entry
*c2c_he
,
235 struct c2c_stats
*stats
,
238 struct compute_stats
*cstats
= &c2c_he
->cstats
;
241 update_stats(&cstats
->rmt_hitm
, weight
);
242 else if (stats
->lcl_hitm
)
243 update_stats(&cstats
->lcl_hitm
, weight
);
244 else if (stats
->load
)
245 update_stats(&cstats
->load
, weight
);
248 static int process_sample_event(struct perf_tool
*tool __maybe_unused
,
249 union perf_event
*event
,
250 struct perf_sample
*sample
,
251 struct perf_evsel
*evsel
,
252 struct machine
*machine
)
254 struct c2c_hists
*c2c_hists
= &c2c
.hists
;
255 struct c2c_hist_entry
*c2c_he
;
256 struct c2c_stats stats
= { .nr_entries
= 0, };
257 struct hist_entry
*he
;
258 struct addr_location al
;
259 struct mem_info
*mi
, *mi_dup
;
262 if (machine__resolve(machine
, &al
, sample
) < 0) {
263 pr_debug("problem processing %d event, skipping it.\n",
268 ret
= sample__resolve_callchain(sample
, &callchain_cursor
, NULL
,
269 evsel
, &al
, sysctl_perf_event_max_stack
);
273 mi
= sample__resolve_mem(sample
, &al
);
278 * The mi object is released in hists__add_entry_ops,
279 * if it gets sorted out into existing data, so we need
280 * to take the copy now.
282 mi_dup
= mem_info__get(mi
);
284 c2c_decode_stats(&stats
, mi
);
286 he
= hists__add_entry_ops(&c2c_hists
->hists
, &c2c_entry_ops
,
292 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
293 c2c_add_stats(&c2c_he
->stats
, &stats
);
294 c2c_add_stats(&c2c_hists
->stats
, &stats
);
296 c2c_he__set_cpu(c2c_he
, sample
);
297 c2c_he__set_node(c2c_he
, sample
);
299 hists__inc_nr_samples(&c2c_hists
->hists
, he
->filtered
);
300 ret
= hist_entry__append_callchain(he
, sample
);
304 * There's already been warning about missing
305 * sample's cpu value. Let's account all to
306 * node 0 in this case, without any further
309 * Doing node stats only for single callchain data.
311 int cpu
= sample
->cpu
== (unsigned int) -1 ? 0 : sample
->cpu
;
312 int node
= c2c
.cpu2node
[cpu
];
316 c2c_hists
= he__get_c2c_hists(he
, c2c
.cl_sort
, 2);
320 he
= hists__add_entry_ops(&c2c_hists
->hists
, &c2c_entry_ops
,
326 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
327 c2c_add_stats(&c2c_he
->stats
, &stats
);
328 c2c_add_stats(&c2c_hists
->stats
, &stats
);
329 c2c_add_stats(&c2c_he
->node_stats
[node
], &stats
);
331 compute_stats(c2c_he
, &stats
, sample
->weight
);
333 c2c_he__set_cpu(c2c_he
, sample
);
334 c2c_he__set_node(c2c_he
, sample
);
336 hists__inc_nr_samples(&c2c_hists
->hists
, he
->filtered
);
337 ret
= hist_entry__append_callchain(he
, sample
);
341 addr_location__put(&al
);
345 mem_info__put(mi_dup
);
351 static struct perf_c2c c2c
= {
353 .sample
= process_sample_event
,
354 .mmap
= perf_event__process_mmap
,
355 .mmap2
= perf_event__process_mmap2
,
356 .comm
= perf_event__process_comm
,
357 .exit
= perf_event__process_exit
,
358 .fork
= perf_event__process_fork
,
359 .lost
= perf_event__process_lost
,
360 .ordered_events
= true,
361 .ordering_requires_timestamps
= true,
365 static const char * const c2c_usage
[] = {
366 "perf c2c {record|report}",
370 static const char * const __usage_report
[] = {
375 static const char * const *report_c2c_usage
= __usage_report
;
377 #define C2C_HEADER_MAX 2
383 } line
[C2C_HEADER_MAX
];
386 struct c2c_dimension
{
387 struct c2c_header header
;
390 struct sort_entry
*se
;
392 int64_t (*cmp
)(struct perf_hpp_fmt
*fmt
,
393 struct hist_entry
*, struct hist_entry
*);
394 int (*entry
)(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
395 struct hist_entry
*he
);
396 int (*color
)(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
397 struct hist_entry
*he
);
401 struct perf_hpp_fmt fmt
;
402 struct c2c_dimension
*dim
;
405 #define SYMBOL_WIDTH 30
407 static struct c2c_dimension dim_symbol
;
408 static struct c2c_dimension dim_srcline
;
410 static int symbol_width(struct hists
*hists
, struct sort_entry
*se
)
412 int width
= hists__col_len(hists
, se
->se_width_idx
);
414 if (!c2c
.symbol_full
)
415 width
= MIN(width
, SYMBOL_WIDTH
);
420 static int c2c_width(struct perf_hpp_fmt
*fmt
,
421 struct perf_hpp
*hpp __maybe_unused
,
424 struct c2c_fmt
*c2c_fmt
;
425 struct c2c_dimension
*dim
;
427 c2c_fmt
= container_of(fmt
, struct c2c_fmt
, fmt
);
430 if (dim
== &dim_symbol
|| dim
== &dim_srcline
)
431 return symbol_width(hists
, dim
->se
);
433 return dim
->se
? hists__col_len(hists
, dim
->se
->se_width_idx
) :
437 static int c2c_header(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
438 struct hists
*hists
, int line
, int *span
)
440 struct perf_hpp_list
*hpp_list
= hists
->hpp_list
;
441 struct c2c_fmt
*c2c_fmt
;
442 struct c2c_dimension
*dim
;
443 const char *text
= NULL
;
444 int width
= c2c_width(fmt
, hpp
, hists
);
446 c2c_fmt
= container_of(fmt
, struct c2c_fmt
, fmt
);
450 text
= dim
->header
.line
[line
].text
;
451 /* Use the last line from sort_entry if not defined. */
452 if (!text
&& (line
== hpp_list
->nr_header_lines
- 1))
453 text
= dim
->se
->se_header
;
455 text
= dim
->header
.line
[line
].text
;
461 *span
= dim
->header
.line
[line
].span
;
468 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, text
);
471 #define HEX_STR(__s, __v) \
473 scnprintf(__s, sizeof(__s), "0x%" PRIx64, __v); \
478 dcacheline_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
479 struct hist_entry
*left
, struct hist_entry
*right
)
481 return sort__dcacheline_cmp(left
, right
);
484 static int dcacheline_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
485 struct hist_entry
*he
)
488 int width
= c2c_width(fmt
, hpp
, he
->hists
);
492 addr
= cl_address(he
->mem_info
->daddr
.addr
);
494 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, HEX_STR(buf
, addr
));
498 dcacheline_node_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
499 struct hist_entry
*he
)
501 struct c2c_hist_entry
*c2c_he
;
502 int width
= c2c_width(fmt
, hpp
, he
->hists
);
504 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
505 if (WARN_ON_ONCE(!c2c_he
->nodestr
))
508 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, c2c_he
->nodestr
);
512 dcacheline_node_count(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
513 struct hist_entry
*he
)
515 struct c2c_hist_entry
*c2c_he
;
516 int width
= c2c_width(fmt
, hpp
, he
->hists
);
518 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
519 return scnprintf(hpp
->buf
, hpp
->size
, "%*lu", width
, c2c_he
->paddr_cnt
);
522 static int offset_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
523 struct hist_entry
*he
)
526 int width
= c2c_width(fmt
, hpp
, he
->hists
);
530 addr
= cl_offset(he
->mem_info
->daddr
.al_addr
);
532 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, HEX_STR(buf
, addr
));
536 offset_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
537 struct hist_entry
*left
, struct hist_entry
*right
)
539 uint64_t l
= 0, r
= 0;
542 l
= cl_offset(left
->mem_info
->daddr
.addr
);
544 r
= cl_offset(right
->mem_info
->daddr
.addr
);
546 return (int64_t)(r
- l
);
550 iaddr_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
551 struct hist_entry
*he
)
554 int width
= c2c_width(fmt
, hpp
, he
->hists
);
558 addr
= he
->mem_info
->iaddr
.addr
;
560 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, HEX_STR(buf
, addr
));
564 iaddr_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
565 struct hist_entry
*left
, struct hist_entry
*right
)
567 return sort__iaddr_cmp(left
, right
);
571 tot_hitm_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
572 struct hist_entry
*he
)
574 struct c2c_hist_entry
*c2c_he
;
575 int width
= c2c_width(fmt
, hpp
, he
->hists
);
576 unsigned int tot_hitm
;
578 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
579 tot_hitm
= c2c_he
->stats
.lcl_hitm
+ c2c_he
->stats
.rmt_hitm
;
581 return scnprintf(hpp
->buf
, hpp
->size
, "%*u", width
, tot_hitm
);
585 tot_hitm_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
586 struct hist_entry
*left
, struct hist_entry
*right
)
588 struct c2c_hist_entry
*c2c_left
;
589 struct c2c_hist_entry
*c2c_right
;
590 unsigned int tot_hitm_left
;
591 unsigned int tot_hitm_right
;
593 c2c_left
= container_of(left
, struct c2c_hist_entry
, he
);
594 c2c_right
= container_of(right
, struct c2c_hist_entry
, he
);
596 tot_hitm_left
= c2c_left
->stats
.lcl_hitm
+ c2c_left
->stats
.rmt_hitm
;
597 tot_hitm_right
= c2c_right
->stats
.lcl_hitm
+ c2c_right
->stats
.rmt_hitm
;
599 return tot_hitm_left
- tot_hitm_right
;
602 #define STAT_FN_ENTRY(__f) \
604 __f ## _entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, \
605 struct hist_entry *he) \
607 struct c2c_hist_entry *c2c_he; \
608 int width = c2c_width(fmt, hpp, he->hists); \
610 c2c_he = container_of(he, struct c2c_hist_entry, he); \
611 return scnprintf(hpp->buf, hpp->size, "%*u", width, \
612 c2c_he->stats.__f); \
615 #define STAT_FN_CMP(__f) \
617 __f ## _cmp(struct perf_hpp_fmt *fmt __maybe_unused, \
618 struct hist_entry *left, struct hist_entry *right) \
620 struct c2c_hist_entry *c2c_left, *c2c_right; \
622 c2c_left = container_of(left, struct c2c_hist_entry, he); \
623 c2c_right = container_of(right, struct c2c_hist_entry, he); \
624 return c2c_left->stats.__f - c2c_right->stats.__f; \
627 #define STAT_FN(__f) \
642 static uint64_t llc_miss(struct c2c_stats
*stats
)
646 llcmiss
= stats
->lcl_dram
+
655 ld_llcmiss_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
656 struct hist_entry
*he
)
658 struct c2c_hist_entry
*c2c_he
;
659 int width
= c2c_width(fmt
, hpp
, he
->hists
);
661 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
663 return scnprintf(hpp
->buf
, hpp
->size
, "%*lu", width
,
664 llc_miss(&c2c_he
->stats
));
668 ld_llcmiss_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
669 struct hist_entry
*left
, struct hist_entry
*right
)
671 struct c2c_hist_entry
*c2c_left
;
672 struct c2c_hist_entry
*c2c_right
;
674 c2c_left
= container_of(left
, struct c2c_hist_entry
, he
);
675 c2c_right
= container_of(right
, struct c2c_hist_entry
, he
);
677 return llc_miss(&c2c_left
->stats
) - llc_miss(&c2c_right
->stats
);
680 static uint64_t total_records(struct c2c_stats
*stats
)
682 uint64_t lclmiss
, ldcnt
, total
;
684 lclmiss
= stats
->lcl_dram
+
704 tot_recs_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
705 struct hist_entry
*he
)
707 struct c2c_hist_entry
*c2c_he
;
708 int width
= c2c_width(fmt
, hpp
, he
->hists
);
711 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
712 tot_recs
= total_records(&c2c_he
->stats
);
714 return scnprintf(hpp
->buf
, hpp
->size
, "%*" PRIu64
, width
, tot_recs
);
718 tot_recs_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
719 struct hist_entry
*left
, struct hist_entry
*right
)
721 struct c2c_hist_entry
*c2c_left
;
722 struct c2c_hist_entry
*c2c_right
;
723 uint64_t tot_recs_left
;
724 uint64_t tot_recs_right
;
726 c2c_left
= container_of(left
, struct c2c_hist_entry
, he
);
727 c2c_right
= container_of(right
, struct c2c_hist_entry
, he
);
729 tot_recs_left
= total_records(&c2c_left
->stats
);
730 tot_recs_right
= total_records(&c2c_right
->stats
);
732 return tot_recs_left
- tot_recs_right
;
735 static uint64_t total_loads(struct c2c_stats
*stats
)
737 uint64_t lclmiss
, ldcnt
;
739 lclmiss
= stats
->lcl_dram
+
755 tot_loads_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
756 struct hist_entry
*he
)
758 struct c2c_hist_entry
*c2c_he
;
759 int width
= c2c_width(fmt
, hpp
, he
->hists
);
762 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
763 tot_recs
= total_loads(&c2c_he
->stats
);
765 return scnprintf(hpp
->buf
, hpp
->size
, "%*" PRIu64
, width
, tot_recs
);
769 tot_loads_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
770 struct hist_entry
*left
, struct hist_entry
*right
)
772 struct c2c_hist_entry
*c2c_left
;
773 struct c2c_hist_entry
*c2c_right
;
774 uint64_t tot_recs_left
;
775 uint64_t tot_recs_right
;
777 c2c_left
= container_of(left
, struct c2c_hist_entry
, he
);
778 c2c_right
= container_of(right
, struct c2c_hist_entry
, he
);
780 tot_recs_left
= total_loads(&c2c_left
->stats
);
781 tot_recs_right
= total_loads(&c2c_right
->stats
);
783 return tot_recs_left
- tot_recs_right
;
786 typedef double (get_percent_cb
)(struct c2c_hist_entry
*);
789 percent_color(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
790 struct hist_entry
*he
, get_percent_cb get_percent
)
792 struct c2c_hist_entry
*c2c_he
;
793 int width
= c2c_width(fmt
, hpp
, he
->hists
);
796 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
797 per
= get_percent(c2c_he
);
799 #ifdef HAVE_SLANG_SUPPORT
801 return __hpp__slsmg_color_printf(hpp
, "%*.2f%%", width
- 1, per
);
803 return hpp_color_scnprintf(hpp
, "%*.2f%%", width
- 1, per
);
806 static double percent_hitm(struct c2c_hist_entry
*c2c_he
)
808 struct c2c_hists
*hists
;
809 struct c2c_stats
*stats
;
810 struct c2c_stats
*total
;
814 hists
= container_of(c2c_he
->he
.hists
, struct c2c_hists
, hists
);
815 stats
= &c2c_he
->stats
;
816 total
= &hists
->stats
;
818 switch (c2c
.display
) {
820 st
= stats
->rmt_hitm
;
821 tot
= total
->rmt_hitm
;
824 st
= stats
->lcl_hitm
;
825 tot
= total
->lcl_hitm
;
828 st
= stats
->tot_hitm
;
829 tot
= total
->tot_hitm
;
834 p
= tot
? (double) st
/ tot
: 0;
839 #define PERC_STR(__s, __v) \
841 scnprintf(__s, sizeof(__s), "%.2F%%", __v); \
846 percent_hitm_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
847 struct hist_entry
*he
)
849 struct c2c_hist_entry
*c2c_he
;
850 int width
= c2c_width(fmt
, hpp
, he
->hists
);
854 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
855 per
= percent_hitm(c2c_he
);
856 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, PERC_STR(buf
, per
));
860 percent_hitm_color(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
861 struct hist_entry
*he
)
863 return percent_color(fmt
, hpp
, he
, percent_hitm
);
867 percent_hitm_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
868 struct hist_entry
*left
, struct hist_entry
*right
)
870 struct c2c_hist_entry
*c2c_left
;
871 struct c2c_hist_entry
*c2c_right
;
875 c2c_left
= container_of(left
, struct c2c_hist_entry
, he
);
876 c2c_right
= container_of(right
, struct c2c_hist_entry
, he
);
878 per_left
= percent_hitm(c2c_left
);
879 per_right
= percent_hitm(c2c_right
);
881 return per_left
- per_right
;
884 static struct c2c_stats
*he_stats(struct hist_entry
*he
)
886 struct c2c_hist_entry
*c2c_he
;
888 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
889 return &c2c_he
->stats
;
892 static struct c2c_stats
*total_stats(struct hist_entry
*he
)
894 struct c2c_hists
*hists
;
896 hists
= container_of(he
->hists
, struct c2c_hists
, hists
);
897 return &hists
->stats
;
900 static double percent(int st
, int tot
)
902 return tot
? 100. * (double) st
/ (double) tot
: 0;
905 #define PERCENT(__h, __f) percent(he_stats(__h)->__f, total_stats(__h)->__f)
907 #define PERCENT_FN(__f) \
908 static double percent_ ## __f(struct c2c_hist_entry *c2c_he) \
910 struct c2c_hists *hists; \
912 hists = container_of(c2c_he->he.hists, struct c2c_hists, hists); \
913 return percent(c2c_he->stats.__f, hists->stats.__f); \
919 PERCENT_FN(st_l1miss
)
922 percent_rmt_hitm_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
923 struct hist_entry
*he
)
925 int width
= c2c_width(fmt
, hpp
, he
->hists
);
926 double per
= PERCENT(he
, rmt_hitm
);
929 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, PERC_STR(buf
, per
));
933 percent_rmt_hitm_color(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
934 struct hist_entry
*he
)
936 return percent_color(fmt
, hpp
, he
, percent_rmt_hitm
);
940 percent_rmt_hitm_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
941 struct hist_entry
*left
, struct hist_entry
*right
)
946 per_left
= PERCENT(left
, lcl_hitm
);
947 per_right
= PERCENT(right
, lcl_hitm
);
949 return per_left
- per_right
;
953 percent_lcl_hitm_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
954 struct hist_entry
*he
)
956 int width
= c2c_width(fmt
, hpp
, he
->hists
);
957 double per
= PERCENT(he
, lcl_hitm
);
960 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, PERC_STR(buf
, per
));
964 percent_lcl_hitm_color(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
965 struct hist_entry
*he
)
967 return percent_color(fmt
, hpp
, he
, percent_lcl_hitm
);
971 percent_lcl_hitm_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
972 struct hist_entry
*left
, struct hist_entry
*right
)
977 per_left
= PERCENT(left
, lcl_hitm
);
978 per_right
= PERCENT(right
, lcl_hitm
);
980 return per_left
- per_right
;
984 percent_stores_l1hit_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
985 struct hist_entry
*he
)
987 int width
= c2c_width(fmt
, hpp
, he
->hists
);
988 double per
= PERCENT(he
, st_l1hit
);
991 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, PERC_STR(buf
, per
));
995 percent_stores_l1hit_color(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
996 struct hist_entry
*he
)
998 return percent_color(fmt
, hpp
, he
, percent_st_l1hit
);
1002 percent_stores_l1hit_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
1003 struct hist_entry
*left
, struct hist_entry
*right
)
1008 per_left
= PERCENT(left
, st_l1hit
);
1009 per_right
= PERCENT(right
, st_l1hit
);
1011 return per_left
- per_right
;
1015 percent_stores_l1miss_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
1016 struct hist_entry
*he
)
1018 int width
= c2c_width(fmt
, hpp
, he
->hists
);
1019 double per
= PERCENT(he
, st_l1miss
);
1022 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, PERC_STR(buf
, per
));
1026 percent_stores_l1miss_color(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
1027 struct hist_entry
*he
)
1029 return percent_color(fmt
, hpp
, he
, percent_st_l1miss
);
1033 percent_stores_l1miss_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
1034 struct hist_entry
*left
, struct hist_entry
*right
)
1039 per_left
= PERCENT(left
, st_l1miss
);
1040 per_right
= PERCENT(right
, st_l1miss
);
1042 return per_left
- per_right
;
1049 pid_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
1050 struct hist_entry
*he
)
1052 int width
= c2c_width(fmt
, hpp
, he
->hists
);
1054 return scnprintf(hpp
->buf
, hpp
->size
, "%*d", width
, he
->thread
->pid_
);
1058 pid_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
1059 struct hist_entry
*left
, struct hist_entry
*right
)
1061 return left
->thread
->pid_
- right
->thread
->pid_
;
1065 empty_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
1066 struct hist_entry
*left __maybe_unused
,
1067 struct hist_entry
*right __maybe_unused
)
1073 node_entry(struct perf_hpp_fmt
*fmt __maybe_unused
, struct perf_hpp
*hpp
,
1074 struct hist_entry
*he
)
1076 struct c2c_hist_entry
*c2c_he
;
1081 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
1083 for (node
= 0; node
< c2c
.nodes_cnt
; node
++) {
1084 DECLARE_BITMAP(set
, c2c
.cpus_cnt
);
1086 bitmap_zero(set
, c2c
.cpus_cnt
);
1087 bitmap_and(set
, c2c_he
->cpuset
, c2c
.nodes
[node
], c2c
.cpus_cnt
);
1089 if (!bitmap_weight(set
, c2c
.cpus_cnt
)) {
1090 if (c2c
.node_info
== 1) {
1091 ret
= scnprintf(hpp
->buf
, hpp
->size
, "%21s", " ");
1092 advance_hpp(hpp
, ret
);
1098 ret
= scnprintf(hpp
->buf
, hpp
->size
, " ");
1099 advance_hpp(hpp
, ret
);
1102 switch (c2c
.node_info
) {
1104 ret
= scnprintf(hpp
->buf
, hpp
->size
, "%2d", node
);
1105 advance_hpp(hpp
, ret
);
1109 int num
= bitmap_weight(c2c_he
->cpuset
, c2c
.cpus_cnt
);
1110 struct c2c_stats
*stats
= &c2c_he
->node_stats
[node
];
1112 ret
= scnprintf(hpp
->buf
, hpp
->size
, "%2d{%2d ", node
, num
);
1113 advance_hpp(hpp
, ret
);
1115 #define DISPLAY_HITM(__h) \
1116 if (c2c_he->stats.__h> 0) { \
1117 ret = scnprintf(hpp->buf, hpp->size, "%5.1f%% ", \
1118 percent(stats->__h, c2c_he->stats.__h));\
1120 ret = scnprintf(hpp->buf, hpp->size, "%6s ", "n/a"); \
1123 switch (c2c
.display
) {
1125 DISPLAY_HITM(rmt_hitm
);
1128 DISPLAY_HITM(lcl_hitm
);
1131 DISPLAY_HITM(tot_hitm
);
1138 advance_hpp(hpp
, ret
);
1140 if (c2c_he
->stats
.store
> 0) {
1141 ret
= scnprintf(hpp
->buf
, hpp
->size
, "%5.1f%%}",
1142 percent(stats
->store
, c2c_he
->stats
.store
));
1144 ret
= scnprintf(hpp
->buf
, hpp
->size
, "%6s}", "n/a");
1147 advance_hpp(hpp
, ret
);
1151 ret
= scnprintf(hpp
->buf
, hpp
->size
, "%2d{", node
);
1152 advance_hpp(hpp
, ret
);
1154 ret
= bitmap_scnprintf(set
, c2c
.cpus_cnt
, hpp
->buf
, hpp
->size
);
1155 advance_hpp(hpp
, ret
);
1157 ret
= scnprintf(hpp
->buf
, hpp
->size
, "}");
1158 advance_hpp(hpp
, ret
);
1171 mean_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
1172 struct hist_entry
*he
, double mean
)
1174 int width
= c2c_width(fmt
, hpp
, he
->hists
);
1177 scnprintf(buf
, 10, "%6.0f", mean
);
1178 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, buf
);
1181 #define MEAN_ENTRY(__func, __val) \
1183 __func(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, struct hist_entry *he) \
1185 struct c2c_hist_entry *c2c_he; \
1186 c2c_he = container_of(he, struct c2c_hist_entry, he); \
1187 return mean_entry(fmt, hpp, he, avg_stats(&c2c_he->cstats.__val)); \
1190 MEAN_ENTRY(mean_rmt_entry
, rmt_hitm
);
1191 MEAN_ENTRY(mean_lcl_entry
, lcl_hitm
);
1192 MEAN_ENTRY(mean_load_entry
, load
);
1195 cpucnt_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
1196 struct hist_entry
*he
)
1198 struct c2c_hist_entry
*c2c_he
;
1199 int width
= c2c_width(fmt
, hpp
, he
->hists
);
1202 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
1204 scnprintf(buf
, 10, "%d", bitmap_weight(c2c_he
->cpuset
, c2c
.cpus_cnt
));
1205 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, buf
);
1209 cl_idx_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
1210 struct hist_entry
*he
)
1212 struct c2c_hist_entry
*c2c_he
;
1213 int width
= c2c_width(fmt
, hpp
, he
->hists
);
1216 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
1218 scnprintf(buf
, 10, "%u", c2c_he
->cacheline_idx
);
1219 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, buf
);
1223 cl_idx_empty_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
1224 struct hist_entry
*he
)
1226 int width
= c2c_width(fmt
, hpp
, he
->hists
);
1228 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, "");
1231 #define HEADER_LOW(__h) \
1238 #define HEADER_BOTH(__h0, __h1) \
1248 #define HEADER_SPAN(__h0, __h1, __s) \
1259 #define HEADER_SPAN_LOW(__h) \
1266 static struct c2c_dimension dim_dcacheline
= {
1267 .header
= HEADER_SPAN("--- Cacheline ----", "Address", 2),
1268 .name
= "dcacheline",
1269 .cmp
= dcacheline_cmp
,
1270 .entry
= dcacheline_entry
,
1274 static struct c2c_dimension dim_dcacheline_node
= {
1275 .header
= HEADER_LOW("Node"),
1276 .name
= "dcacheline_node",
1278 .entry
= dcacheline_node_entry
,
1282 static struct c2c_dimension dim_dcacheline_count
= {
1283 .header
= HEADER_LOW("PA cnt"),
1284 .name
= "dcacheline_count",
1286 .entry
= dcacheline_node_count
,
1290 static struct c2c_header header_offset_tui
= HEADER_SPAN("-----", "Off", 2);
1292 static struct c2c_dimension dim_offset
= {
1293 .header
= HEADER_SPAN("--- Data address -", "Offset", 2),
1296 .entry
= offset_entry
,
1300 static struct c2c_dimension dim_offset_node
= {
1301 .header
= HEADER_LOW("Node"),
1302 .name
= "offset_node",
1304 .entry
= dcacheline_node_entry
,
1308 static struct c2c_dimension dim_iaddr
= {
1309 .header
= HEADER_LOW("Code address"),
1312 .entry
= iaddr_entry
,
1316 static struct c2c_dimension dim_tot_hitm
= {
1317 .header
= HEADER_SPAN("----- LLC Load Hitm -----", "Total", 2),
1319 .cmp
= tot_hitm_cmp
,
1320 .entry
= tot_hitm_entry
,
1324 static struct c2c_dimension dim_lcl_hitm
= {
1325 .header
= HEADER_SPAN_LOW("Lcl"),
1327 .cmp
= lcl_hitm_cmp
,
1328 .entry
= lcl_hitm_entry
,
1332 static struct c2c_dimension dim_rmt_hitm
= {
1333 .header
= HEADER_SPAN_LOW("Rmt"),
1335 .cmp
= rmt_hitm_cmp
,
1336 .entry
= rmt_hitm_entry
,
1340 static struct c2c_dimension dim_cl_rmt_hitm
= {
1341 .header
= HEADER_SPAN("----- HITM -----", "Rmt", 1),
1342 .name
= "cl_rmt_hitm",
1343 .cmp
= rmt_hitm_cmp
,
1344 .entry
= rmt_hitm_entry
,
1348 static struct c2c_dimension dim_cl_lcl_hitm
= {
1349 .header
= HEADER_SPAN_LOW("Lcl"),
1350 .name
= "cl_lcl_hitm",
1351 .cmp
= lcl_hitm_cmp
,
1352 .entry
= lcl_hitm_entry
,
1356 static struct c2c_dimension dim_stores
= {
1357 .header
= HEADER_SPAN("---- Store Reference ----", "Total", 2),
1360 .entry
= store_entry
,
1364 static struct c2c_dimension dim_stores_l1hit
= {
1365 .header
= HEADER_SPAN_LOW("L1Hit"),
1366 .name
= "stores_l1hit",
1367 .cmp
= st_l1hit_cmp
,
1368 .entry
= st_l1hit_entry
,
1372 static struct c2c_dimension dim_stores_l1miss
= {
1373 .header
= HEADER_SPAN_LOW("L1Miss"),
1374 .name
= "stores_l1miss",
1375 .cmp
= st_l1miss_cmp
,
1376 .entry
= st_l1miss_entry
,
1380 static struct c2c_dimension dim_cl_stores_l1hit
= {
1381 .header
= HEADER_SPAN("-- Store Refs --", "L1 Hit", 1),
1382 .name
= "cl_stores_l1hit",
1383 .cmp
= st_l1hit_cmp
,
1384 .entry
= st_l1hit_entry
,
1388 static struct c2c_dimension dim_cl_stores_l1miss
= {
1389 .header
= HEADER_SPAN_LOW("L1 Miss"),
1390 .name
= "cl_stores_l1miss",
1391 .cmp
= st_l1miss_cmp
,
1392 .entry
= st_l1miss_entry
,
1396 static struct c2c_dimension dim_ld_fbhit
= {
1397 .header
= HEADER_SPAN("----- Core Load Hit -----", "FB", 2),
1399 .cmp
= ld_fbhit_cmp
,
1400 .entry
= ld_fbhit_entry
,
1404 static struct c2c_dimension dim_ld_l1hit
= {
1405 .header
= HEADER_SPAN_LOW("L1"),
1407 .cmp
= ld_l1hit_cmp
,
1408 .entry
= ld_l1hit_entry
,
1412 static struct c2c_dimension dim_ld_l2hit
= {
1413 .header
= HEADER_SPAN_LOW("L2"),
1415 .cmp
= ld_l2hit_cmp
,
1416 .entry
= ld_l2hit_entry
,
1420 static struct c2c_dimension dim_ld_llchit
= {
1421 .header
= HEADER_SPAN("-- LLC Load Hit --", "Llc", 1),
1422 .name
= "ld_lclhit",
1423 .cmp
= ld_llchit_cmp
,
1424 .entry
= ld_llchit_entry
,
1428 static struct c2c_dimension dim_ld_rmthit
= {
1429 .header
= HEADER_SPAN_LOW("Rmt"),
1430 .name
= "ld_rmthit",
1432 .entry
= rmt_hit_entry
,
1436 static struct c2c_dimension dim_ld_llcmiss
= {
1437 .header
= HEADER_BOTH("LLC", "Ld Miss"),
1438 .name
= "ld_llcmiss",
1439 .cmp
= ld_llcmiss_cmp
,
1440 .entry
= ld_llcmiss_entry
,
1444 static struct c2c_dimension dim_tot_recs
= {
1445 .header
= HEADER_BOTH("Total", "records"),
1447 .cmp
= tot_recs_cmp
,
1448 .entry
= tot_recs_entry
,
1452 static struct c2c_dimension dim_tot_loads
= {
1453 .header
= HEADER_BOTH("Total", "Loads"),
1454 .name
= "tot_loads",
1455 .cmp
= tot_loads_cmp
,
1456 .entry
= tot_loads_entry
,
1460 static struct c2c_header percent_hitm_header
[] = {
1461 [DISPLAY_LCL
] = HEADER_BOTH("Lcl", "Hitm"),
1462 [DISPLAY_RMT
] = HEADER_BOTH("Rmt", "Hitm"),
1463 [DISPLAY_TOT
] = HEADER_BOTH("Tot", "Hitm"),
1466 static struct c2c_dimension dim_percent_hitm
= {
1467 .name
= "percent_hitm",
1468 .cmp
= percent_hitm_cmp
,
1469 .entry
= percent_hitm_entry
,
1470 .color
= percent_hitm_color
,
1474 static struct c2c_dimension dim_percent_rmt_hitm
= {
1475 .header
= HEADER_SPAN("----- HITM -----", "Rmt", 1),
1476 .name
= "percent_rmt_hitm",
1477 .cmp
= percent_rmt_hitm_cmp
,
1478 .entry
= percent_rmt_hitm_entry
,
1479 .color
= percent_rmt_hitm_color
,
1483 static struct c2c_dimension dim_percent_lcl_hitm
= {
1484 .header
= HEADER_SPAN_LOW("Lcl"),
1485 .name
= "percent_lcl_hitm",
1486 .cmp
= percent_lcl_hitm_cmp
,
1487 .entry
= percent_lcl_hitm_entry
,
1488 .color
= percent_lcl_hitm_color
,
1492 static struct c2c_dimension dim_percent_stores_l1hit
= {
1493 .header
= HEADER_SPAN("-- Store Refs --", "L1 Hit", 1),
1494 .name
= "percent_stores_l1hit",
1495 .cmp
= percent_stores_l1hit_cmp
,
1496 .entry
= percent_stores_l1hit_entry
,
1497 .color
= percent_stores_l1hit_color
,
1501 static struct c2c_dimension dim_percent_stores_l1miss
= {
1502 .header
= HEADER_SPAN_LOW("L1 Miss"),
1503 .name
= "percent_stores_l1miss",
1504 .cmp
= percent_stores_l1miss_cmp
,
1505 .entry
= percent_stores_l1miss_entry
,
1506 .color
= percent_stores_l1miss_color
,
1510 static struct c2c_dimension dim_dram_lcl
= {
1511 .header
= HEADER_SPAN("--- Load Dram ----", "Lcl", 1),
1513 .cmp
= lcl_dram_cmp
,
1514 .entry
= lcl_dram_entry
,
1518 static struct c2c_dimension dim_dram_rmt
= {
1519 .header
= HEADER_SPAN_LOW("Rmt"),
1521 .cmp
= rmt_dram_cmp
,
1522 .entry
= rmt_dram_entry
,
1526 static struct c2c_dimension dim_pid
= {
1527 .header
= HEADER_LOW("Pid"),
1534 static struct c2c_dimension dim_tid
= {
1535 .header
= HEADER_LOW("Tid"),
1540 static struct c2c_dimension dim_symbol
= {
1545 static struct c2c_dimension dim_dso
= {
1546 .header
= HEADER_BOTH("Shared", "Object"),
1551 static struct c2c_header header_node
[3] = {
1553 HEADER_LOW("Node{cpus %hitms %stores}"),
1554 HEADER_LOW("Node{cpu list}"),
1557 static struct c2c_dimension dim_node
= {
1560 .entry
= node_entry
,
1564 static struct c2c_dimension dim_mean_rmt
= {
1565 .header
= HEADER_SPAN("---------- cycles ----------", "rmt hitm", 2),
1568 .entry
= mean_rmt_entry
,
1572 static struct c2c_dimension dim_mean_lcl
= {
1573 .header
= HEADER_SPAN_LOW("lcl hitm"),
1576 .entry
= mean_lcl_entry
,
1580 static struct c2c_dimension dim_mean_load
= {
1581 .header
= HEADER_SPAN_LOW("load"),
1582 .name
= "mean_load",
1584 .entry
= mean_load_entry
,
1588 static struct c2c_dimension dim_cpucnt
= {
1589 .header
= HEADER_BOTH("cpu", "cnt"),
1592 .entry
= cpucnt_entry
,
1596 static struct c2c_dimension dim_srcline
= {
1597 .name
= "cl_srcline",
1598 .se
= &sort_srcline
,
1601 static struct c2c_dimension dim_dcacheline_idx
= {
1602 .header
= HEADER_LOW("Index"),
1605 .entry
= cl_idx_entry
,
1609 static struct c2c_dimension dim_dcacheline_num
= {
1610 .header
= HEADER_LOW("Num"),
1613 .entry
= cl_idx_entry
,
1617 static struct c2c_dimension dim_dcacheline_num_empty
= {
1618 .header
= HEADER_LOW("Num"),
1619 .name
= "cl_num_empty",
1621 .entry
= cl_idx_empty_entry
,
1625 static struct c2c_dimension
*dimensions
[] = {
1627 &dim_dcacheline_node
,
1628 &dim_dcacheline_count
,
1640 &dim_cl_stores_l1hit
,
1641 &dim_cl_stores_l1miss
,
1651 &dim_percent_rmt_hitm
,
1652 &dim_percent_lcl_hitm
,
1653 &dim_percent_stores_l1hit
,
1654 &dim_percent_stores_l1miss
,
1667 &dim_dcacheline_idx
,
1668 &dim_dcacheline_num
,
1669 &dim_dcacheline_num_empty
,
1673 static void fmt_free(struct perf_hpp_fmt
*fmt
)
1675 struct c2c_fmt
*c2c_fmt
;
1677 c2c_fmt
= container_of(fmt
, struct c2c_fmt
, fmt
);
1681 static bool fmt_equal(struct perf_hpp_fmt
*a
, struct perf_hpp_fmt
*b
)
1683 struct c2c_fmt
*c2c_a
= container_of(a
, struct c2c_fmt
, fmt
);
1684 struct c2c_fmt
*c2c_b
= container_of(b
, struct c2c_fmt
, fmt
);
1686 return c2c_a
->dim
== c2c_b
->dim
;
1689 static struct c2c_dimension
*get_dimension(const char *name
)
1693 for (i
= 0; dimensions
[i
]; i
++) {
1694 struct c2c_dimension
*dim
= dimensions
[i
];
1696 if (!strcmp(dim
->name
, name
))
1703 static int c2c_se_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
1704 struct hist_entry
*he
)
1706 struct c2c_fmt
*c2c_fmt
= container_of(fmt
, struct c2c_fmt
, fmt
);
1707 struct c2c_dimension
*dim
= c2c_fmt
->dim
;
1708 size_t len
= fmt
->user_len
;
1711 len
= hists__col_len(he
->hists
, dim
->se
->se_width_idx
);
1713 if (dim
== &dim_symbol
|| dim
== &dim_srcline
)
1714 len
= symbol_width(he
->hists
, dim
->se
);
1717 return dim
->se
->se_snprintf(he
, hpp
->buf
, hpp
->size
, len
);
1720 static int64_t c2c_se_cmp(struct perf_hpp_fmt
*fmt
,
1721 struct hist_entry
*a
, struct hist_entry
*b
)
1723 struct c2c_fmt
*c2c_fmt
= container_of(fmt
, struct c2c_fmt
, fmt
);
1724 struct c2c_dimension
*dim
= c2c_fmt
->dim
;
1726 return dim
->se
->se_cmp(a
, b
);
1729 static int64_t c2c_se_collapse(struct perf_hpp_fmt
*fmt
,
1730 struct hist_entry
*a
, struct hist_entry
*b
)
1732 struct c2c_fmt
*c2c_fmt
= container_of(fmt
, struct c2c_fmt
, fmt
);
1733 struct c2c_dimension
*dim
= c2c_fmt
->dim
;
1734 int64_t (*collapse_fn
)(struct hist_entry
*, struct hist_entry
*);
1736 collapse_fn
= dim
->se
->se_collapse
?: dim
->se
->se_cmp
;
1737 return collapse_fn(a
, b
);
1740 static struct c2c_fmt
*get_format(const char *name
)
1742 struct c2c_dimension
*dim
= get_dimension(name
);
1743 struct c2c_fmt
*c2c_fmt
;
1744 struct perf_hpp_fmt
*fmt
;
1749 c2c_fmt
= zalloc(sizeof(*c2c_fmt
));
1755 fmt
= &c2c_fmt
->fmt
;
1756 INIT_LIST_HEAD(&fmt
->list
);
1757 INIT_LIST_HEAD(&fmt
->sort_list
);
1759 fmt
->cmp
= dim
->se
? c2c_se_cmp
: dim
->cmp
;
1760 fmt
->sort
= dim
->se
? c2c_se_cmp
: dim
->cmp
;
1761 fmt
->color
= dim
->se
? NULL
: dim
->color
;
1762 fmt
->entry
= dim
->se
? c2c_se_entry
: dim
->entry
;
1763 fmt
->header
= c2c_header
;
1764 fmt
->width
= c2c_width
;
1765 fmt
->collapse
= dim
->se
? c2c_se_collapse
: dim
->cmp
;
1766 fmt
->equal
= fmt_equal
;
1767 fmt
->free
= fmt_free
;
1772 static int c2c_hists__init_output(struct perf_hpp_list
*hpp_list
, char *name
)
1774 struct c2c_fmt
*c2c_fmt
= get_format(name
);
1778 return output_field_add(hpp_list
, name
);
1781 perf_hpp_list__column_register(hpp_list
, &c2c_fmt
->fmt
);
1785 static int c2c_hists__init_sort(struct perf_hpp_list
*hpp_list
, char *name
)
1787 struct c2c_fmt
*c2c_fmt
= get_format(name
);
1788 struct c2c_dimension
*dim
;
1792 return sort_dimension__add(hpp_list
, name
, NULL
, 0);
1796 if (dim
== &dim_dso
)
1799 perf_hpp_list__register_sort_field(hpp_list
, &c2c_fmt
->fmt
);
1803 #define PARSE_LIST(_list, _fn) \
1811 for (tok = strtok_r((char *)_list, ", ", &tmp); \
1812 tok; tok = strtok_r(NULL, ", ", &tmp)) { \
1813 ret = _fn(hpp_list, tok); \
1814 if (ret == -EINVAL) { \
1815 pr_err("Invalid --fields key: `%s'", tok); \
1817 } else if (ret == -ESRCH) { \
1818 pr_err("Unknown --fields key: `%s'", tok); \
1824 static int hpp_list__parse(struct perf_hpp_list
*hpp_list
,
1825 const char *output_
,
1828 char *output
= output_
? strdup(output_
) : NULL
;
1829 char *sort
= sort_
? strdup(sort_
) : NULL
;
1832 PARSE_LIST(output
, c2c_hists__init_output
);
1833 PARSE_LIST(sort
, c2c_hists__init_sort
);
1835 /* copy sort keys to output fields */
1836 perf_hpp__setup_output_field(hpp_list
);
1839 * We dont need other sorting keys other than those
1840 * we already specified. It also really slows down
1841 * the processing a lot with big number of output
1842 * fields, so switching this off for c2c.
1846 /* and then copy output fields to sort keys */
1847 perf_hpp__append_sort_keys(&hists
->list
);
1855 static int c2c_hists__init(struct c2c_hists
*hists
,
1857 int nr_header_lines
)
1859 __hists__init(&hists
->hists
, &hists
->list
);
1862 * Initialize only with sort fields, we need to resort
1863 * later anyway, and that's where we add output fields
1866 perf_hpp_list__init(&hists
->list
);
1868 /* Overload number of header lines.*/
1869 hists
->list
.nr_header_lines
= nr_header_lines
;
1871 return hpp_list__parse(&hists
->list
, NULL
, sort
);
1874 static int c2c_hists__reinit(struct c2c_hists
*c2c_hists
,
1878 perf_hpp__reset_output_field(&c2c_hists
->list
);
1879 return hpp_list__parse(&c2c_hists
->list
, output
, sort
);
1882 #define DISPLAY_LINE_LIMIT 0.001
1884 static bool he__display(struct hist_entry
*he
, struct c2c_stats
*stats
)
1886 struct c2c_hist_entry
*c2c_he
;
1892 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
1894 #define FILTER_HITM(__h) \
1896 ld_dist = ((double)c2c_he->stats.__h / stats->__h); \
1897 if (ld_dist < DISPLAY_LINE_LIMIT) \
1898 he->filtered = HIST_FILTER__C2C; \
1900 he->filtered = HIST_FILTER__C2C; \
1903 switch (c2c
.display
) {
1905 FILTER_HITM(lcl_hitm
);
1908 FILTER_HITM(rmt_hitm
);
1911 FILTER_HITM(tot_hitm
);
1918 return he
->filtered
== 0;
1921 static inline int valid_hitm_or_store(struct hist_entry
*he
)
1923 struct c2c_hist_entry
*c2c_he
;
1926 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
1927 has_hitm
= c2c
.display
== DISPLAY_TOT
? c2c_he
->stats
.tot_hitm
:
1928 c2c
.display
== DISPLAY_LCL
? c2c_he
->stats
.lcl_hitm
:
1929 c2c_he
->stats
.rmt_hitm
;
1930 return has_hitm
|| c2c_he
->stats
.store
;
1933 static void set_node_width(struct c2c_hist_entry
*c2c_he
, int len
)
1935 struct c2c_dimension
*dim
;
1937 dim
= &c2c
.hists
== c2c_he
->hists
?
1938 &dim_dcacheline_node
: &dim_offset_node
;
1940 if (len
> dim
->width
)
1944 static int set_nodestr(struct c2c_hist_entry
*c2c_he
)
1949 if (c2c_he
->nodestr
)
1952 if (bitmap_weight(c2c_he
->nodeset
, c2c
.nodes_cnt
)) {
1953 len
= bitmap_scnprintf(c2c_he
->nodeset
, c2c
.nodes_cnt
,
1956 len
= scnprintf(buf
, sizeof(buf
), "N/A");
1959 set_node_width(c2c_he
, len
);
1960 c2c_he
->nodestr
= strdup(buf
);
1961 return c2c_he
->nodestr
? 0 : -ENOMEM
;
1964 static void calc_width(struct c2c_hist_entry
*c2c_he
)
1966 struct c2c_hists
*c2c_hists
;
1968 c2c_hists
= container_of(c2c_he
->he
.hists
, struct c2c_hists
, hists
);
1969 hists__calc_col_len(&c2c_hists
->hists
, &c2c_he
->he
);
1970 set_nodestr(c2c_he
);
1973 static int filter_cb(struct hist_entry
*he
, void *arg __maybe_unused
)
1975 struct c2c_hist_entry
*c2c_he
;
1977 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
1979 if (c2c
.show_src
&& !he
->srcline
)
1980 he
->srcline
= hist_entry__srcline(he
);
1984 if (!valid_hitm_or_store(he
))
1985 he
->filtered
= HIST_FILTER__C2C
;
1990 static int resort_cl_cb(struct hist_entry
*he
, void *arg __maybe_unused
)
1992 struct c2c_hist_entry
*c2c_he
;
1993 struct c2c_hists
*c2c_hists
;
1994 bool display
= he__display(he
, &c2c
.hitm_stats
);
1996 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
1997 c2c_hists
= c2c_he
->hists
;
1999 if (display
&& c2c_hists
) {
2000 static unsigned int idx
;
2002 c2c_he
->cacheline_idx
= idx
++;
2005 c2c_hists__reinit(c2c_hists
, c2c
.cl_output
, c2c
.cl_resort
);
2007 hists__collapse_resort(&c2c_hists
->hists
, NULL
);
2008 hists__output_resort_cb(&c2c_hists
->hists
, NULL
, filter_cb
);
2014 static void setup_nodes_header(void)
2016 dim_node
.header
= header_node
[c2c
.node_info
];
2019 static int setup_nodes(struct perf_session
*session
)
2021 struct numa_node
*n
;
2022 unsigned long **nodes
;
2026 if (c2c
.node_info
> 2)
2029 c2c
.nodes_cnt
= session
->header
.env
.nr_numa_nodes
;
2030 c2c
.cpus_cnt
= session
->header
.env
.nr_cpus_online
;
2032 n
= session
->header
.env
.numa_nodes
;
2036 nodes
= zalloc(sizeof(unsigned long *) * c2c
.nodes_cnt
);
2042 cpu2node
= zalloc(sizeof(int) * c2c
.cpus_cnt
);
2046 for (cpu
= 0; cpu
< c2c
.cpus_cnt
; cpu
++)
2049 c2c
.cpu2node
= cpu2node
;
2051 for (node
= 0; node
< c2c
.nodes_cnt
; node
++) {
2052 struct cpu_map
*map
= n
[node
].map
;
2055 set
= bitmap_alloc(c2c
.cpus_cnt
);
2061 /* empty node, skip */
2062 if (cpu_map__empty(map
))
2065 for (cpu
= 0; cpu
< map
->nr
; cpu
++) {
2066 set_bit(map
->map
[cpu
], set
);
2068 if (WARN_ONCE(cpu2node
[map
->map
[cpu
]] != -1, "node/cpu topology bug"))
2071 cpu2node
[map
->map
[cpu
]] = node
;
2075 setup_nodes_header();
2079 #define HAS_HITMS(__h) ((__h)->stats.lcl_hitm || (__h)->stats.rmt_hitm)
2081 static int resort_hitm_cb(struct hist_entry
*he
, void *arg __maybe_unused
)
2083 struct c2c_hist_entry
*c2c_he
;
2084 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
2086 if (HAS_HITMS(c2c_he
)) {
2087 c2c
.shared_clines
++;
2088 c2c_add_stats(&c2c
.hitm_stats
, &c2c_he
->stats
);
2094 static int hists__iterate_cb(struct hists
*hists
, hists__resort_cb_t cb
)
2096 struct rb_node
*next
= rb_first_cached(&hists
->entries
);
2100 struct hist_entry
*he
;
2102 he
= rb_entry(next
, struct hist_entry
, rb_node
);
2106 next
= rb_next(&he
->rb_node
);
2112 static void print_c2c__display_stats(FILE *out
)
2115 struct c2c_stats
*stats
= &c2c
.hists
.stats
;
2117 llc_misses
= stats
->lcl_dram
+
2122 fprintf(out
, "=================================================\n");
2123 fprintf(out
, " Trace Event Information \n");
2124 fprintf(out
, "=================================================\n");
2125 fprintf(out
, " Total records : %10d\n", stats
->nr_entries
);
2126 fprintf(out
, " Locked Load/Store Operations : %10d\n", stats
->locks
);
2127 fprintf(out
, " Load Operations : %10d\n", stats
->load
);
2128 fprintf(out
, " Loads - uncacheable : %10d\n", stats
->ld_uncache
);
2129 fprintf(out
, " Loads - IO : %10d\n", stats
->ld_io
);
2130 fprintf(out
, " Loads - Miss : %10d\n", stats
->ld_miss
);
2131 fprintf(out
, " Loads - no mapping : %10d\n", stats
->ld_noadrs
);
2132 fprintf(out
, " Load Fill Buffer Hit : %10d\n", stats
->ld_fbhit
);
2133 fprintf(out
, " Load L1D hit : %10d\n", stats
->ld_l1hit
);
2134 fprintf(out
, " Load L2D hit : %10d\n", stats
->ld_l2hit
);
2135 fprintf(out
, " Load LLC hit : %10d\n", stats
->ld_llchit
+ stats
->lcl_hitm
);
2136 fprintf(out
, " Load Local HITM : %10d\n", stats
->lcl_hitm
);
2137 fprintf(out
, " Load Remote HITM : %10d\n", stats
->rmt_hitm
);
2138 fprintf(out
, " Load Remote HIT : %10d\n", stats
->rmt_hit
);
2139 fprintf(out
, " Load Local DRAM : %10d\n", stats
->lcl_dram
);
2140 fprintf(out
, " Load Remote DRAM : %10d\n", stats
->rmt_dram
);
2141 fprintf(out
, " Load MESI State Exclusive : %10d\n", stats
->ld_excl
);
2142 fprintf(out
, " Load MESI State Shared : %10d\n", stats
->ld_shared
);
2143 fprintf(out
, " Load LLC Misses : %10d\n", llc_misses
);
2144 fprintf(out
, " LLC Misses to Local DRAM : %10.1f%%\n", ((double)stats
->lcl_dram
/(double)llc_misses
) * 100.);
2145 fprintf(out
, " LLC Misses to Remote DRAM : %10.1f%%\n", ((double)stats
->rmt_dram
/(double)llc_misses
) * 100.);
2146 fprintf(out
, " LLC Misses to Remote cache (HIT) : %10.1f%%\n", ((double)stats
->rmt_hit
/(double)llc_misses
) * 100.);
2147 fprintf(out
, " LLC Misses to Remote cache (HITM) : %10.1f%%\n", ((double)stats
->rmt_hitm
/(double)llc_misses
) * 100.);
2148 fprintf(out
, " Store Operations : %10d\n", stats
->store
);
2149 fprintf(out
, " Store - uncacheable : %10d\n", stats
->st_uncache
);
2150 fprintf(out
, " Store - no mapping : %10d\n", stats
->st_noadrs
);
2151 fprintf(out
, " Store L1D Hit : %10d\n", stats
->st_l1hit
);
2152 fprintf(out
, " Store L1D Miss : %10d\n", stats
->st_l1miss
);
2153 fprintf(out
, " No Page Map Rejects : %10d\n", stats
->nomap
);
2154 fprintf(out
, " Unable to parse data source : %10d\n", stats
->noparse
);
2157 static void print_shared_cacheline_info(FILE *out
)
2159 struct c2c_stats
*stats
= &c2c
.hitm_stats
;
2160 int hitm_cnt
= stats
->lcl_hitm
+ stats
->rmt_hitm
;
2162 fprintf(out
, "=================================================\n");
2163 fprintf(out
, " Global Shared Cache Line Event Information \n");
2164 fprintf(out
, "=================================================\n");
2165 fprintf(out
, " Total Shared Cache Lines : %10d\n", c2c
.shared_clines
);
2166 fprintf(out
, " Load HITs on shared lines : %10d\n", stats
->load
);
2167 fprintf(out
, " Fill Buffer Hits on shared lines : %10d\n", stats
->ld_fbhit
);
2168 fprintf(out
, " L1D hits on shared lines : %10d\n", stats
->ld_l1hit
);
2169 fprintf(out
, " L2D hits on shared lines : %10d\n", stats
->ld_l2hit
);
2170 fprintf(out
, " LLC hits on shared lines : %10d\n", stats
->ld_llchit
+ stats
->lcl_hitm
);
2171 fprintf(out
, " Locked Access on shared lines : %10d\n", stats
->locks
);
2172 fprintf(out
, " Store HITs on shared lines : %10d\n", stats
->store
);
2173 fprintf(out
, " Store L1D hits on shared lines : %10d\n", stats
->st_l1hit
);
2174 fprintf(out
, " Total Merged records : %10d\n", hitm_cnt
+ stats
->store
);
2177 static void print_cacheline(struct c2c_hists
*c2c_hists
,
2178 struct hist_entry
*he_cl
,
2179 struct perf_hpp_list
*hpp_list
,
2183 struct perf_hpp hpp
= {
2190 hists__fprintf_headers(&c2c_hists
->hists
, out
);
2196 fprintf(out
, " -------------------------------------------------------------\n");
2197 __hist_entry__snprintf(he_cl
, &hpp
, hpp_list
);
2198 fprintf(out
, "%s\n", bf
);
2199 fprintf(out
, " -------------------------------------------------------------\n");
2201 hists__fprintf(&c2c_hists
->hists
, false, 0, 0, 0, out
, false);
2204 static void print_pareto(FILE *out
)
2206 struct perf_hpp_list hpp_list
;
2210 perf_hpp_list__init(&hpp_list
);
2211 ret
= hpp_list__parse(&hpp_list
,
2220 if (WARN_ONCE(ret
, "failed to setup sort entries\n"))
2223 nd
= rb_first_cached(&c2c
.hists
.hists
.entries
);
2225 for (; nd
; nd
= rb_next(nd
)) {
2226 struct hist_entry
*he
= rb_entry(nd
, struct hist_entry
, rb_node
);
2227 struct c2c_hist_entry
*c2c_he
;
2232 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
2233 print_cacheline(c2c_he
->hists
, he
, &hpp_list
, out
);
2237 static void print_c2c_info(FILE *out
, struct perf_session
*session
)
2239 struct perf_evlist
*evlist
= session
->evlist
;
2240 struct perf_evsel
*evsel
;
2243 fprintf(out
, "=================================================\n");
2244 fprintf(out
, " c2c details \n");
2245 fprintf(out
, "=================================================\n");
2247 evlist__for_each_entry(evlist
, evsel
) {
2248 fprintf(out
, "%-36s: %s\n", first
? " Events" : "",
2249 perf_evsel__name(evsel
));
2252 fprintf(out
, " Cachelines sort on : %s HITMs\n",
2253 display_str
[c2c
.display
]);
2254 fprintf(out
, " Cacheline data grouping : %s\n", c2c
.cl_sort
);
2257 static void perf_c2c__hists_fprintf(FILE *out
, struct perf_session
*session
)
2261 print_c2c__display_stats(out
);
2263 print_shared_cacheline_info(out
);
2265 print_c2c_info(out
, session
);
2271 fprintf(out
, "=================================================\n");
2272 fprintf(out
, " Shared Data Cache Line Table \n");
2273 fprintf(out
, "=================================================\n");
2274 fprintf(out
, "#\n");
2276 hists__fprintf(&c2c
.hists
.hists
, true, 0, 0, 0, stdout
, true);
2279 fprintf(out
, "=================================================\n");
2280 fprintf(out
, " Shared Cache Line Distribution Pareto \n");
2281 fprintf(out
, "=================================================\n");
2282 fprintf(out
, "#\n");
2287 #ifdef HAVE_SLANG_SUPPORT
2288 static void c2c_browser__update_nr_entries(struct hist_browser
*hb
)
2291 struct rb_node
*nd
= rb_first_cached(&hb
->hists
->entries
);
2294 struct hist_entry
*he
= rb_entry(nd
, struct hist_entry
, rb_node
);
2302 hb
->nr_non_filtered_entries
= nr_entries
;
2305 struct c2c_cacheline_browser
{
2306 struct hist_browser hb
;
2307 struct hist_entry
*he
;
2311 perf_c2c_cacheline_browser__title(struct hist_browser
*browser
,
2312 char *bf
, size_t size
)
2314 struct c2c_cacheline_browser
*cl_browser
;
2315 struct hist_entry
*he
;
2318 cl_browser
= container_of(browser
, struct c2c_cacheline_browser
, hb
);
2319 he
= cl_browser
->he
;
2322 addr
= cl_address(he
->mem_info
->daddr
.addr
);
2324 scnprintf(bf
, size
, "Cacheline 0x%lx", addr
);
2328 static struct c2c_cacheline_browser
*
2329 c2c_cacheline_browser__new(struct hists
*hists
, struct hist_entry
*he
)
2331 struct c2c_cacheline_browser
*browser
;
2333 browser
= zalloc(sizeof(*browser
));
2335 hist_browser__init(&browser
->hb
, hists
);
2336 browser
->hb
.c2c_filter
= true;
2337 browser
->hb
.title
= perf_c2c_cacheline_browser__title
;
2344 static int perf_c2c__browse_cacheline(struct hist_entry
*he
)
2346 struct c2c_hist_entry
*c2c_he
;
2347 struct c2c_hists
*c2c_hists
;
2348 struct c2c_cacheline_browser
*cl_browser
;
2349 struct hist_browser
*browser
;
2351 static const char help
[] =
2352 " ENTER Toggle callchains (if present) \n"
2353 " n Toggle Node details info \n"
2354 " s Toggle full length of symbol and source line columns \n"
2355 " q Return back to cacheline list \n";
2360 /* Display compact version first. */
2361 c2c
.symbol_full
= false;
2363 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
2364 c2c_hists
= c2c_he
->hists
;
2366 cl_browser
= c2c_cacheline_browser__new(&c2c_hists
->hists
, he
);
2367 if (cl_browser
== NULL
)
2370 browser
= &cl_browser
->hb
;
2372 /* reset abort key so that it can get Ctrl-C as a key */
2374 SLang_init_tty(0, 0, 0);
2376 c2c_browser__update_nr_entries(browser
);
2379 key
= hist_browser__run(browser
, "? - help", true);
2383 c2c
.symbol_full
= !c2c
.symbol_full
;
2386 c2c
.node_info
= (c2c
.node_info
+ 1) % 3;
2387 setup_nodes_header();
2392 ui_browser__help_window(&browser
->b
, help
);
2404 static int perf_c2c_browser__title(struct hist_browser
*browser
,
2405 char *bf
, size_t size
)
2408 "Shared Data Cache Line Table "
2409 "(%lu entries, sorted on %s HITMs)",
2410 browser
->nr_non_filtered_entries
,
2411 display_str
[c2c
.display
]);
2415 static struct hist_browser
*
2416 perf_c2c_browser__new(struct hists
*hists
)
2418 struct hist_browser
*browser
= hist_browser__new(hists
);
2421 browser
->title
= perf_c2c_browser__title
;
2422 browser
->c2c_filter
= true;
2428 static int perf_c2c__hists_browse(struct hists
*hists
)
2430 struct hist_browser
*browser
;
2432 static const char help
[] =
2433 " d Display cacheline details \n"
2434 " ENTER Toggle callchains (if present) \n"
2437 browser
= perf_c2c_browser__new(hists
);
2438 if (browser
== NULL
)
2441 /* reset abort key so that it can get Ctrl-C as a key */
2443 SLang_init_tty(0, 0, 0);
2445 c2c_browser__update_nr_entries(browser
);
2448 key
= hist_browser__run(browser
, "? - help", true);
2454 perf_c2c__browse_cacheline(browser
->he_selection
);
2457 ui_browser__help_window(&browser
->b
, help
);
2465 hist_browser__delete(browser
);
2469 static void perf_c2c_display(struct perf_session
*session
)
2471 if (use_browser
== 0)
2472 perf_c2c__hists_fprintf(stdout
, session
);
2474 perf_c2c__hists_browse(&c2c
.hists
.hists
);
2477 static void perf_c2c_display(struct perf_session
*session
)
2480 perf_c2c__hists_fprintf(stdout
, session
);
2482 #endif /* HAVE_SLANG_SUPPORT */
2484 static char *fill_line(const char *orig
, int len
)
2486 int i
, j
, olen
= strlen(orig
);
2489 buf
= zalloc(len
+ 1);
2493 j
= len
/ 2 - olen
/ 2;
2495 for (i
= 0; i
< j
- 1; i
++)
2500 strcpy(buf
+ i
, orig
);
2506 for (; i
< len
; i
++)
2512 static int ui_quirks(void)
2514 const char *nodestr
= "Data address";
2517 if (!c2c
.use_stdio
) {
2518 dim_offset
.width
= 5;
2519 dim_offset
.header
= header_offset_tui
;
2523 dim_percent_hitm
.header
= percent_hitm_header
[c2c
.display
];
2525 /* Fix the zero line for dcacheline column. */
2526 buf
= fill_line("Cacheline", dim_dcacheline
.width
+
2527 dim_dcacheline_node
.width
+
2528 dim_dcacheline_count
.width
+ 4);
2532 dim_dcacheline
.header
.line
[0].text
= buf
;
2534 /* Fix the zero line for offset column. */
2535 buf
= fill_line(nodestr
, dim_offset
.width
+
2536 dim_offset_node
.width
+
2537 dim_dcacheline_count
.width
+ 4);
2541 dim_offset
.header
.line
[0].text
= buf
;
2546 #define CALLCHAIN_DEFAULT_OPT "graph,0.5,caller,function,percent"
2548 const char callchain_help
[] = "Display call graph (stack chain/backtrace):\n\n"
2549 CALLCHAIN_REPORT_HELP
2550 "\n\t\t\t\tDefault: " CALLCHAIN_DEFAULT_OPT
;
2553 parse_callchain_opt(const struct option
*opt
, const char *arg
, int unset
)
2555 struct callchain_param
*callchain
= opt
->value
;
2557 callchain
->enabled
= !unset
;
2562 symbol_conf
.use_callchain
= false;
2563 callchain
->mode
= CHAIN_NONE
;
2567 return parse_callchain_report_opt(arg
);
2570 static int setup_callchain(struct perf_evlist
*evlist
)
2572 u64 sample_type
= perf_evlist__combined_sample_type(evlist
);
2573 enum perf_call_graph_mode mode
= CALLCHAIN_NONE
;
2575 if ((sample_type
& PERF_SAMPLE_REGS_USER
) &&
2576 (sample_type
& PERF_SAMPLE_STACK_USER
)) {
2577 mode
= CALLCHAIN_DWARF
;
2578 dwarf_callchain_users
= true;
2579 } else if (sample_type
& PERF_SAMPLE_BRANCH_STACK
)
2580 mode
= CALLCHAIN_LBR
;
2581 else if (sample_type
& PERF_SAMPLE_CALLCHAIN
)
2582 mode
= CALLCHAIN_FP
;
2584 if (!callchain_param
.enabled
&&
2585 callchain_param
.mode
!= CHAIN_NONE
&&
2586 mode
!= CALLCHAIN_NONE
) {
2587 symbol_conf
.use_callchain
= true;
2588 if (callchain_register_param(&callchain_param
) < 0) {
2589 ui__error("Can't register callchain params.\n");
2594 callchain_param
.record_mode
= mode
;
2595 callchain_param
.min_percent
= 0;
2599 static int setup_display(const char *str
)
2601 const char *display
= str
?: "tot";
2603 if (!strcmp(display
, "tot"))
2604 c2c
.display
= DISPLAY_TOT
;
2605 else if (!strcmp(display
, "rmt"))
2606 c2c
.display
= DISPLAY_RMT
;
2607 else if (!strcmp(display
, "lcl"))
2608 c2c
.display
= DISPLAY_LCL
;
2610 pr_err("failed: unknown display type: %s\n", str
);
2617 #define for_each_token(__tok, __buf, __sep, __tmp) \
2618 for (__tok = strtok_r(__buf, __sep, &__tmp); __tok; \
2619 __tok = strtok_r(NULL, __sep, &__tmp))
2621 static int build_cl_output(char *cl_sort
, bool no_source
)
2623 char *tok
, *tmp
, *buf
= strdup(cl_sort
);
2624 bool add_pid
= false;
2625 bool add_tid
= false;
2626 bool add_iaddr
= false;
2627 bool add_sym
= false;
2628 bool add_dso
= false;
2629 bool add_src
= false;
2634 for_each_token(tok
, buf
, ",", tmp
) {
2635 if (!strcmp(tok
, "tid")) {
2637 } else if (!strcmp(tok
, "pid")) {
2639 } else if (!strcmp(tok
, "iaddr")) {
2643 add_src
= no_source
? false : true;
2644 } else if (!strcmp(tok
, "dso")) {
2646 } else if (strcmp(tok
, "offset")) {
2647 pr_err("unrecognized sort token: %s\n", tok
);
2652 if (asprintf(&c2c
.cl_output
,
2653 "%s%s%s%s%s%s%s%s%s%s",
2654 c2c
.use_stdio
? "cl_num_empty," : "",
2657 "percent_stores_l1hit,"
2658 "percent_stores_l1miss,"
2659 "offset,offset_node,dcacheline_count,",
2660 add_pid
? "pid," : "",
2661 add_tid
? "tid," : "",
2662 add_iaddr
? "iaddr," : "",
2668 add_sym
? "symbol," : "",
2669 add_dso
? "dso," : "",
2670 add_src
? "cl_srcline," : "",
2674 c2c
.show_src
= add_src
;
2680 static int setup_coalesce(const char *coalesce
, bool no_source
)
2682 const char *c
= coalesce
?: coalesce_default
;
2684 if (asprintf(&c2c
.cl_sort
, "offset,%s", c
) < 0)
2687 if (build_cl_output(c2c
.cl_sort
, no_source
))
2690 if (asprintf(&c2c
.cl_resort
, "offset,%s",
2691 c2c
.display
== DISPLAY_TOT
?
2693 c2c
.display
== DISPLAY_RMT
?
2694 "rmt_hitm,lcl_hitm" :
2695 "lcl_hitm,rmt_hitm") < 0)
2698 pr_debug("coalesce sort fields: %s\n", c2c
.cl_sort
);
2699 pr_debug("coalesce resort fields: %s\n", c2c
.cl_resort
);
2700 pr_debug("coalesce output fields: %s\n", c2c
.cl_output
);
2704 static int perf_c2c__report(int argc
, const char **argv
)
2706 struct perf_session
*session
;
2707 struct ui_progress prog
;
2708 struct perf_data data
= {
2709 .mode
= PERF_DATA_MODE_READ
,
2711 char callchain_default_opt
[] = CALLCHAIN_DEFAULT_OPT
;
2712 const char *display
= NULL
;
2713 const char *coalesce
= NULL
;
2714 bool no_source
= false;
2715 const struct option options
[] = {
2716 OPT_STRING('k', "vmlinux", &symbol_conf
.vmlinux_name
,
2717 "file", "vmlinux pathname"),
2718 OPT_STRING('i', "input", &input_name
, "file",
2719 "the input file to process"),
2720 OPT_INCR('N', "node-info", &c2c
.node_info
,
2721 "show extra node info in report (repeat for more info)"),
2722 #ifdef HAVE_SLANG_SUPPORT
2723 OPT_BOOLEAN(0, "stdio", &c2c
.use_stdio
, "Use the stdio interface"),
2725 OPT_BOOLEAN(0, "stats", &c2c
.stats_only
,
2726 "Display only statistic tables (implies --stdio)"),
2727 OPT_BOOLEAN(0, "full-symbols", &c2c
.symbol_full
,
2728 "Display full length of symbols"),
2729 OPT_BOOLEAN(0, "no-source", &no_source
,
2730 "Do not display Source Line column"),
2731 OPT_BOOLEAN(0, "show-all", &c2c
.show_all
,
2732 "Show all captured HITM lines."),
2733 OPT_CALLBACK_DEFAULT('g', "call-graph", &callchain_param
,
2734 "print_type,threshold[,print_limit],order,sort_key[,branch],value",
2735 callchain_help
, &parse_callchain_opt
,
2736 callchain_default_opt
),
2737 OPT_STRING('d', "display", &display
, "Switch HITM output type", "lcl,rmt"),
2738 OPT_STRING('c', "coalesce", &coalesce
, "coalesce fields",
2739 "coalesce fields: pid,tid,iaddr,dso"),
2740 OPT_BOOLEAN('f', "force", &symbol_conf
.force
, "don't complain, do it"),
2741 OPT_PARENT(c2c_options
),
2746 argc
= parse_options(argc
, argv
, options
, report_c2c_usage
,
2747 PARSE_OPT_STOP_AT_NON_OPTION
);
2749 usage_with_options(report_c2c_usage
, options
);
2752 c2c
.use_stdio
= true;
2754 if (!input_name
|| !strlen(input_name
))
2755 input_name
= "perf.data";
2757 data
.path
= input_name
;
2758 data
.force
= symbol_conf
.force
;
2760 err
= setup_display(display
);
2764 err
= setup_coalesce(coalesce
, no_source
);
2766 pr_debug("Failed to initialize hists\n");
2770 err
= c2c_hists__init(&c2c
.hists
, "dcacheline", 2);
2772 pr_debug("Failed to initialize hists\n");
2776 session
= perf_session__new(&data
, 0, &c2c
.tool
);
2777 if (session
== NULL
) {
2778 pr_debug("No memory for session\n");
2782 err
= setup_nodes(session
);
2784 pr_err("Failed setup nodes\n");
2788 err
= mem2node__init(&c2c
.mem2node
, &session
->header
.env
);
2792 err
= setup_callchain(session
->evlist
);
2796 if (symbol__init(&session
->header
.env
) < 0)
2799 /* No pipe support at the moment. */
2800 if (perf_data__is_pipe(session
->data
)) {
2801 pr_debug("No pipe support at the moment.\n");
2810 setup_browser(false);
2812 err
= perf_session__process_events(session
);
2814 pr_err("failed to process sample\n");
2818 c2c_hists__reinit(&c2c
.hists
,
2825 "tot_hitm,lcl_hitm,rmt_hitm,"
2826 "stores,stores_l1hit,stores_l1miss,"
2827 "dram_lcl,dram_rmt,"
2830 "ld_fbhit,ld_l1hit,ld_l2hit,"
2831 "ld_lclhit,ld_rmthit",
2832 c2c
.display
== DISPLAY_TOT
? "tot_hitm" :
2833 c2c
.display
== DISPLAY_LCL
? "lcl_hitm" : "rmt_hitm"
2836 ui_progress__init(&prog
, c2c
.hists
.hists
.nr_entries
, "Sorting...");
2838 hists__collapse_resort(&c2c
.hists
.hists
, NULL
);
2839 hists__output_resort_cb(&c2c
.hists
.hists
, &prog
, resort_hitm_cb
);
2840 hists__iterate_cb(&c2c
.hists
.hists
, resort_cl_cb
);
2842 ui_progress__finish();
2845 pr_err("failed to setup UI\n");
2849 perf_c2c_display(session
);
2852 mem2node__exit(&c2c
.mem2node
);
2854 perf_session__delete(session
);
2859 static int parse_record_events(const struct option
*opt
,
2860 const char *str
, int unset __maybe_unused
)
2862 bool *event_set
= (bool *) opt
->value
;
2865 return perf_mem_events__parse(str
);
2869 static const char * const __usage_record
[] = {
2870 "perf c2c record [<options>] [<command>]",
2871 "perf c2c record [<options>] -- <command> [<options>]",
2875 static const char * const *record_mem_usage
= __usage_record
;
2877 static int perf_c2c__record(int argc
, const char **argv
)
2879 int rec_argc
, i
= 0, j
;
2880 const char **rec_argv
;
2882 bool all_user
= false, all_kernel
= false;
2883 bool event_set
= false;
2884 struct option options
[] = {
2885 OPT_CALLBACK('e', "event", &event_set
, "event",
2886 "event selector. Use 'perf mem record -e list' to list available events",
2887 parse_record_events
),
2888 OPT_BOOLEAN('u', "all-user", &all_user
, "collect only user level data"),
2889 OPT_BOOLEAN('k', "all-kernel", &all_kernel
, "collect only kernel level data"),
2890 OPT_UINTEGER('l', "ldlat", &perf_mem_events__loads_ldlat
, "setup mem-loads latency"),
2891 OPT_PARENT(c2c_options
),
2895 if (perf_mem_events__init()) {
2896 pr_err("failed: memory events not supported\n");
2900 argc
= parse_options(argc
, argv
, options
, record_mem_usage
,
2901 PARSE_OPT_KEEP_UNKNOWN
);
2903 rec_argc
= argc
+ 11; /* max number of arguments */
2904 rec_argv
= calloc(rec_argc
+ 1, sizeof(char *));
2908 rec_argv
[i
++] = "record";
2911 perf_mem_events
[PERF_MEM_EVENTS__LOAD
].record
= true;
2912 perf_mem_events
[PERF_MEM_EVENTS__STORE
].record
= true;
2915 if (perf_mem_events
[PERF_MEM_EVENTS__LOAD
].record
)
2916 rec_argv
[i
++] = "-W";
2918 rec_argv
[i
++] = "-d";
2919 rec_argv
[i
++] = "--phys-data";
2920 rec_argv
[i
++] = "--sample-cpu";
2922 for (j
= 0; j
< PERF_MEM_EVENTS__MAX
; j
++) {
2923 if (!perf_mem_events
[j
].record
)
2926 if (!perf_mem_events
[j
].supported
) {
2927 pr_err("failed: event '%s' not supported\n",
2928 perf_mem_events
[j
].name
);
2933 rec_argv
[i
++] = "-e";
2934 rec_argv
[i
++] = perf_mem_events__name(j
);
2938 rec_argv
[i
++] = "--all-user";
2941 rec_argv
[i
++] = "--all-kernel";
2943 for (j
= 0; j
< argc
; j
++, i
++)
2944 rec_argv
[i
] = argv
[j
];
2947 pr_debug("calling: ");
2951 while (rec_argv
[j
]) {
2952 pr_debug("%s ", rec_argv
[j
]);
2958 ret
= cmd_record(i
, rec_argv
);
2963 int cmd_c2c(int argc
, const char **argv
)
2965 argc
= parse_options(argc
, argv
, c2c_options
, c2c_usage
,
2966 PARSE_OPT_STOP_AT_NON_OPTION
);
2969 usage_with_options(c2c_usage
, c2c_options
);
2971 if (!strncmp(argv
[0], "rec", 3)) {
2972 return perf_c2c__record(argc
, argv
);
2973 } else if (!strncmp(argv
[0], "rep", 3)) {
2974 return perf_c2c__report(argc
, argv
);
2976 usage_with_options(c2c_usage
, c2c_options
);