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"
39 struct perf_hpp_list list
;
40 struct c2c_stats stats
;
43 struct compute_stats
{
44 struct stats lcl_hitm
;
45 struct stats rmt_hitm
;
49 struct c2c_hist_entry
{
50 struct c2c_hists
*hists
;
51 struct c2c_stats stats
;
52 unsigned long *cpuset
;
53 unsigned long *nodeset
;
54 struct c2c_stats
*node_stats
;
55 unsigned int cacheline_idx
;
57 struct compute_stats cstats
;
60 unsigned long paddr_cnt
;
66 * because of its callchain dynamic entry
71 static char const *coalesce_default
= "pid,iaddr";
74 struct perf_tool tool
;
75 struct c2c_hists hists
;
76 struct mem2node mem2node
;
78 unsigned long **nodes
;
90 /* HITM shared clines stats */
91 struct c2c_stats hitm_stats
;
109 static const char *display_str
[DISPLAY_MAX
] = {
110 [DISPLAY_LCL
] = "Local",
111 [DISPLAY_RMT
] = "Remote",
112 [DISPLAY_TOT
] = "Total",
115 static const struct option c2c_options
[] = {
116 OPT_INCR('v', "verbose", &verbose
, "be more verbose (show counter open errors, etc)"),
120 static struct perf_c2c c2c
;
122 static void *c2c_he_zalloc(size_t size
)
124 struct c2c_hist_entry
*c2c_he
;
126 c2c_he
= zalloc(size
+ sizeof(*c2c_he
));
130 c2c_he
->cpuset
= bitmap_alloc(c2c
.cpus_cnt
);
134 c2c_he
->nodeset
= bitmap_alloc(c2c
.nodes_cnt
);
135 if (!c2c_he
->nodeset
)
138 c2c_he
->node_stats
= zalloc(c2c
.nodes_cnt
* sizeof(*c2c_he
->node_stats
));
139 if (!c2c_he
->node_stats
)
142 init_stats(&c2c_he
->cstats
.lcl_hitm
);
143 init_stats(&c2c_he
->cstats
.rmt_hitm
);
144 init_stats(&c2c_he
->cstats
.load
);
149 static void c2c_he_free(void *he
)
151 struct c2c_hist_entry
*c2c_he
;
153 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
155 hists__delete_entries(&c2c_he
->hists
->hists
);
159 free(c2c_he
->cpuset
);
160 free(c2c_he
->nodeset
);
161 free(c2c_he
->nodestr
);
162 free(c2c_he
->node_stats
);
166 static struct hist_entry_ops c2c_entry_ops
= {
167 .new = c2c_he_zalloc
,
171 static int c2c_hists__init(struct c2c_hists
*hists
,
173 int nr_header_lines
);
175 static struct c2c_hists
*
176 he__get_c2c_hists(struct hist_entry
*he
,
180 struct c2c_hist_entry
*c2c_he
;
181 struct c2c_hists
*hists
;
184 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
186 return c2c_he
->hists
;
188 hists
= c2c_he
->hists
= zalloc(sizeof(*hists
));
192 ret
= c2c_hists__init(hists
, sort
, nr_header_lines
);
201 static void c2c_he__set_cpu(struct c2c_hist_entry
*c2c_he
,
202 struct perf_sample
*sample
)
204 if (WARN_ONCE(sample
->cpu
== (unsigned int) -1,
205 "WARNING: no sample cpu value"))
208 set_bit(sample
->cpu
, c2c_he
->cpuset
);
211 static void c2c_he__set_node(struct c2c_hist_entry
*c2c_he
,
212 struct perf_sample
*sample
)
216 if (!sample
->phys_addr
) {
217 c2c_he
->paddr_zero
= true;
221 node
= mem2node__node(&c2c
.mem2node
, sample
->phys_addr
);
222 if (WARN_ONCE(node
< 0, "WARNING: failed to find node\n"))
225 set_bit(node
, c2c_he
->nodeset
);
227 if (c2c_he
->paddr
!= sample
->phys_addr
) {
229 c2c_he
->paddr
= sample
->phys_addr
;
233 static void compute_stats(struct c2c_hist_entry
*c2c_he
,
234 struct c2c_stats
*stats
,
237 struct compute_stats
*cstats
= &c2c_he
->cstats
;
240 update_stats(&cstats
->rmt_hitm
, weight
);
241 else if (stats
->lcl_hitm
)
242 update_stats(&cstats
->lcl_hitm
, weight
);
243 else if (stats
->load
)
244 update_stats(&cstats
->load
, weight
);
247 static int process_sample_event(struct perf_tool
*tool __maybe_unused
,
248 union perf_event
*event
,
249 struct perf_sample
*sample
,
250 struct perf_evsel
*evsel
,
251 struct machine
*machine
)
253 struct c2c_hists
*c2c_hists
= &c2c
.hists
;
254 struct c2c_hist_entry
*c2c_he
;
255 struct c2c_stats stats
= { .nr_entries
= 0, };
256 struct hist_entry
*he
;
257 struct addr_location al
;
258 struct mem_info
*mi
, *mi_dup
;
261 if (machine__resolve(machine
, &al
, sample
) < 0) {
262 pr_debug("problem processing %d event, skipping it.\n",
267 ret
= sample__resolve_callchain(sample
, &callchain_cursor
, NULL
,
268 evsel
, &al
, sysctl_perf_event_max_stack
);
272 mi
= sample__resolve_mem(sample
, &al
);
277 * The mi object is released in hists__add_entry_ops,
278 * if it gets sorted out into existing data, so we need
279 * to take the copy now.
281 mi_dup
= mem_info__get(mi
);
283 c2c_decode_stats(&stats
, mi
);
285 he
= hists__add_entry_ops(&c2c_hists
->hists
, &c2c_entry_ops
,
291 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
292 c2c_add_stats(&c2c_he
->stats
, &stats
);
293 c2c_add_stats(&c2c_hists
->stats
, &stats
);
295 c2c_he__set_cpu(c2c_he
, sample
);
296 c2c_he__set_node(c2c_he
, sample
);
298 hists__inc_nr_samples(&c2c_hists
->hists
, he
->filtered
);
299 ret
= hist_entry__append_callchain(he
, sample
);
303 * There's already been warning about missing
304 * sample's cpu value. Let's account all to
305 * node 0 in this case, without any further
308 * Doing node stats only for single callchain data.
310 int cpu
= sample
->cpu
== (unsigned int) -1 ? 0 : sample
->cpu
;
311 int node
= c2c
.cpu2node
[cpu
];
315 c2c_hists
= he__get_c2c_hists(he
, c2c
.cl_sort
, 2);
319 he
= hists__add_entry_ops(&c2c_hists
->hists
, &c2c_entry_ops
,
325 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
326 c2c_add_stats(&c2c_he
->stats
, &stats
);
327 c2c_add_stats(&c2c_hists
->stats
, &stats
);
328 c2c_add_stats(&c2c_he
->node_stats
[node
], &stats
);
330 compute_stats(c2c_he
, &stats
, sample
->weight
);
332 c2c_he__set_cpu(c2c_he
, sample
);
333 c2c_he__set_node(c2c_he
, sample
);
335 hists__inc_nr_samples(&c2c_hists
->hists
, he
->filtered
);
336 ret
= hist_entry__append_callchain(he
, sample
);
340 addr_location__put(&al
);
344 mem_info__put(mi_dup
);
350 static struct perf_c2c c2c
= {
352 .sample
= process_sample_event
,
353 .mmap
= perf_event__process_mmap
,
354 .mmap2
= perf_event__process_mmap2
,
355 .comm
= perf_event__process_comm
,
356 .exit
= perf_event__process_exit
,
357 .fork
= perf_event__process_fork
,
358 .lost
= perf_event__process_lost
,
359 .ordered_events
= true,
360 .ordering_requires_timestamps
= true,
364 static const char * const c2c_usage
[] = {
365 "perf c2c {record|report}",
369 static const char * const __usage_report
[] = {
374 static const char * const *report_c2c_usage
= __usage_report
;
376 #define C2C_HEADER_MAX 2
382 } line
[C2C_HEADER_MAX
];
385 struct c2c_dimension
{
386 struct c2c_header header
;
389 struct sort_entry
*se
;
391 int64_t (*cmp
)(struct perf_hpp_fmt
*fmt
,
392 struct hist_entry
*, struct hist_entry
*);
393 int (*entry
)(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
394 struct hist_entry
*he
);
395 int (*color
)(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
396 struct hist_entry
*he
);
400 struct perf_hpp_fmt fmt
;
401 struct c2c_dimension
*dim
;
404 #define SYMBOL_WIDTH 30
406 static struct c2c_dimension dim_symbol
;
407 static struct c2c_dimension dim_srcline
;
409 static int symbol_width(struct hists
*hists
, struct sort_entry
*se
)
411 int width
= hists__col_len(hists
, se
->se_width_idx
);
413 if (!c2c
.symbol_full
)
414 width
= MIN(width
, SYMBOL_WIDTH
);
419 static int c2c_width(struct perf_hpp_fmt
*fmt
,
420 struct perf_hpp
*hpp __maybe_unused
,
423 struct c2c_fmt
*c2c_fmt
;
424 struct c2c_dimension
*dim
;
426 c2c_fmt
= container_of(fmt
, struct c2c_fmt
, fmt
);
429 if (dim
== &dim_symbol
|| dim
== &dim_srcline
)
430 return symbol_width(hists
, dim
->se
);
432 return dim
->se
? hists__col_len(hists
, dim
->se
->se_width_idx
) :
436 static int c2c_header(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
437 struct hists
*hists
, int line
, int *span
)
439 struct perf_hpp_list
*hpp_list
= hists
->hpp_list
;
440 struct c2c_fmt
*c2c_fmt
;
441 struct c2c_dimension
*dim
;
442 const char *text
= NULL
;
443 int width
= c2c_width(fmt
, hpp
, hists
);
445 c2c_fmt
= container_of(fmt
, struct c2c_fmt
, fmt
);
449 text
= dim
->header
.line
[line
].text
;
450 /* Use the last line from sort_entry if not defined. */
451 if (!text
&& (line
== hpp_list
->nr_header_lines
- 1))
452 text
= dim
->se
->se_header
;
454 text
= dim
->header
.line
[line
].text
;
460 *span
= dim
->header
.line
[line
].span
;
467 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, text
);
470 #define HEX_STR(__s, __v) \
472 scnprintf(__s, sizeof(__s), "0x%" PRIx64, __v); \
477 dcacheline_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
478 struct hist_entry
*left
, struct hist_entry
*right
)
480 return sort__dcacheline_cmp(left
, right
);
483 static int dcacheline_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
484 struct hist_entry
*he
)
487 int width
= c2c_width(fmt
, hpp
, he
->hists
);
491 addr
= cl_address(he
->mem_info
->daddr
.addr
);
493 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, HEX_STR(buf
, addr
));
497 dcacheline_node_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
498 struct hist_entry
*he
)
500 struct c2c_hist_entry
*c2c_he
;
501 int width
= c2c_width(fmt
, hpp
, he
->hists
);
503 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
504 if (WARN_ON_ONCE(!c2c_he
->nodestr
))
507 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, c2c_he
->nodestr
);
511 dcacheline_node_count(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
512 struct hist_entry
*he
)
514 struct c2c_hist_entry
*c2c_he
;
515 int width
= c2c_width(fmt
, hpp
, he
->hists
);
517 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
518 return scnprintf(hpp
->buf
, hpp
->size
, "%*lu", width
, c2c_he
->paddr_cnt
);
521 static int offset_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
522 struct hist_entry
*he
)
525 int width
= c2c_width(fmt
, hpp
, he
->hists
);
529 addr
= cl_offset(he
->mem_info
->daddr
.al_addr
);
531 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, HEX_STR(buf
, addr
));
535 offset_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
536 struct hist_entry
*left
, struct hist_entry
*right
)
538 uint64_t l
= 0, r
= 0;
541 l
= cl_offset(left
->mem_info
->daddr
.addr
);
543 r
= cl_offset(right
->mem_info
->daddr
.addr
);
545 return (int64_t)(r
- l
);
549 iaddr_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
550 struct hist_entry
*he
)
553 int width
= c2c_width(fmt
, hpp
, he
->hists
);
557 addr
= he
->mem_info
->iaddr
.addr
;
559 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, HEX_STR(buf
, addr
));
563 iaddr_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
564 struct hist_entry
*left
, struct hist_entry
*right
)
566 return sort__iaddr_cmp(left
, right
);
570 tot_hitm_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
571 struct hist_entry
*he
)
573 struct c2c_hist_entry
*c2c_he
;
574 int width
= c2c_width(fmt
, hpp
, he
->hists
);
575 unsigned int tot_hitm
;
577 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
578 tot_hitm
= c2c_he
->stats
.lcl_hitm
+ c2c_he
->stats
.rmt_hitm
;
580 return scnprintf(hpp
->buf
, hpp
->size
, "%*u", width
, tot_hitm
);
584 tot_hitm_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
585 struct hist_entry
*left
, struct hist_entry
*right
)
587 struct c2c_hist_entry
*c2c_left
;
588 struct c2c_hist_entry
*c2c_right
;
589 uint64_t tot_hitm_left
;
590 uint64_t tot_hitm_right
;
592 c2c_left
= container_of(left
, struct c2c_hist_entry
, he
);
593 c2c_right
= container_of(right
, struct c2c_hist_entry
, he
);
595 tot_hitm_left
= c2c_left
->stats
.lcl_hitm
+ c2c_left
->stats
.rmt_hitm
;
596 tot_hitm_right
= c2c_right
->stats
.lcl_hitm
+ c2c_right
->stats
.rmt_hitm
;
598 return tot_hitm_left
- tot_hitm_right
;
601 #define STAT_FN_ENTRY(__f) \
603 __f ## _entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, \
604 struct hist_entry *he) \
606 struct c2c_hist_entry *c2c_he; \
607 int width = c2c_width(fmt, hpp, he->hists); \
609 c2c_he = container_of(he, struct c2c_hist_entry, he); \
610 return scnprintf(hpp->buf, hpp->size, "%*u", width, \
611 c2c_he->stats.__f); \
614 #define STAT_FN_CMP(__f) \
616 __f ## _cmp(struct perf_hpp_fmt *fmt __maybe_unused, \
617 struct hist_entry *left, struct hist_entry *right) \
619 struct c2c_hist_entry *c2c_left, *c2c_right; \
621 c2c_left = container_of(left, struct c2c_hist_entry, he); \
622 c2c_right = container_of(right, struct c2c_hist_entry, he); \
623 return (uint64_t) c2c_left->stats.__f - \
624 (uint64_t) 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 (uint64_t) llc_miss(&c2c_left
->stats
) -
678 (uint64_t) llc_miss(&c2c_right
->stats
);
681 static uint64_t total_records(struct c2c_stats
*stats
)
683 uint64_t lclmiss
, ldcnt
, total
;
685 lclmiss
= stats
->lcl_dram
+
705 tot_recs_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
706 struct hist_entry
*he
)
708 struct c2c_hist_entry
*c2c_he
;
709 int width
= c2c_width(fmt
, hpp
, he
->hists
);
712 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
713 tot_recs
= total_records(&c2c_he
->stats
);
715 return scnprintf(hpp
->buf
, hpp
->size
, "%*" PRIu64
, width
, tot_recs
);
719 tot_recs_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
720 struct hist_entry
*left
, struct hist_entry
*right
)
722 struct c2c_hist_entry
*c2c_left
;
723 struct c2c_hist_entry
*c2c_right
;
724 uint64_t tot_recs_left
;
725 uint64_t tot_recs_right
;
727 c2c_left
= container_of(left
, struct c2c_hist_entry
, he
);
728 c2c_right
= container_of(right
, struct c2c_hist_entry
, he
);
730 tot_recs_left
= total_records(&c2c_left
->stats
);
731 tot_recs_right
= total_records(&c2c_right
->stats
);
733 return tot_recs_left
- tot_recs_right
;
736 static uint64_t total_loads(struct c2c_stats
*stats
)
738 uint64_t lclmiss
, ldcnt
;
740 lclmiss
= stats
->lcl_dram
+
756 tot_loads_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
757 struct hist_entry
*he
)
759 struct c2c_hist_entry
*c2c_he
;
760 int width
= c2c_width(fmt
, hpp
, he
->hists
);
763 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
764 tot_recs
= total_loads(&c2c_he
->stats
);
766 return scnprintf(hpp
->buf
, hpp
->size
, "%*" PRIu64
, width
, tot_recs
);
770 tot_loads_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
771 struct hist_entry
*left
, struct hist_entry
*right
)
773 struct c2c_hist_entry
*c2c_left
;
774 struct c2c_hist_entry
*c2c_right
;
775 uint64_t tot_recs_left
;
776 uint64_t tot_recs_right
;
778 c2c_left
= container_of(left
, struct c2c_hist_entry
, he
);
779 c2c_right
= container_of(right
, struct c2c_hist_entry
, he
);
781 tot_recs_left
= total_loads(&c2c_left
->stats
);
782 tot_recs_right
= total_loads(&c2c_right
->stats
);
784 return tot_recs_left
- tot_recs_right
;
787 typedef double (get_percent_cb
)(struct c2c_hist_entry
*);
790 percent_color(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
791 struct hist_entry
*he
, get_percent_cb get_percent
)
793 struct c2c_hist_entry
*c2c_he
;
794 int width
= c2c_width(fmt
, hpp
, he
->hists
);
797 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
798 per
= get_percent(c2c_he
);
800 #ifdef HAVE_SLANG_SUPPORT
802 return __hpp__slsmg_color_printf(hpp
, "%*.2f%%", width
- 1, per
);
804 return hpp_color_scnprintf(hpp
, "%*.2f%%", width
- 1, per
);
807 static double percent_hitm(struct c2c_hist_entry
*c2c_he
)
809 struct c2c_hists
*hists
;
810 struct c2c_stats
*stats
;
811 struct c2c_stats
*total
;
815 hists
= container_of(c2c_he
->he
.hists
, struct c2c_hists
, hists
);
816 stats
= &c2c_he
->stats
;
817 total
= &hists
->stats
;
819 switch (c2c
.display
) {
821 st
= stats
->rmt_hitm
;
822 tot
= total
->rmt_hitm
;
825 st
= stats
->lcl_hitm
;
826 tot
= total
->lcl_hitm
;
829 st
= stats
->tot_hitm
;
830 tot
= total
->tot_hitm
;
835 p
= tot
? (double) st
/ tot
: 0;
840 #define PERC_STR(__s, __v) \
842 scnprintf(__s, sizeof(__s), "%.2F%%", __v); \
847 percent_hitm_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
848 struct hist_entry
*he
)
850 struct c2c_hist_entry
*c2c_he
;
851 int width
= c2c_width(fmt
, hpp
, he
->hists
);
855 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
856 per
= percent_hitm(c2c_he
);
857 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, PERC_STR(buf
, per
));
861 percent_hitm_color(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
862 struct hist_entry
*he
)
864 return percent_color(fmt
, hpp
, he
, percent_hitm
);
868 percent_hitm_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
869 struct hist_entry
*left
, struct hist_entry
*right
)
871 struct c2c_hist_entry
*c2c_left
;
872 struct c2c_hist_entry
*c2c_right
;
876 c2c_left
= container_of(left
, struct c2c_hist_entry
, he
);
877 c2c_right
= container_of(right
, struct c2c_hist_entry
, he
);
879 per_left
= percent_hitm(c2c_left
);
880 per_right
= percent_hitm(c2c_right
);
882 return per_left
- per_right
;
885 static struct c2c_stats
*he_stats(struct hist_entry
*he
)
887 struct c2c_hist_entry
*c2c_he
;
889 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
890 return &c2c_he
->stats
;
893 static struct c2c_stats
*total_stats(struct hist_entry
*he
)
895 struct c2c_hists
*hists
;
897 hists
= container_of(he
->hists
, struct c2c_hists
, hists
);
898 return &hists
->stats
;
901 static double percent(int st
, int tot
)
903 return tot
? 100. * (double) st
/ (double) tot
: 0;
906 #define PERCENT(__h, __f) percent(he_stats(__h)->__f, total_stats(__h)->__f)
908 #define PERCENT_FN(__f) \
909 static double percent_ ## __f(struct c2c_hist_entry *c2c_he) \
911 struct c2c_hists *hists; \
913 hists = container_of(c2c_he->he.hists, struct c2c_hists, hists); \
914 return percent(c2c_he->stats.__f, hists->stats.__f); \
920 PERCENT_FN(st_l1miss
)
923 percent_rmt_hitm_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
924 struct hist_entry
*he
)
926 int width
= c2c_width(fmt
, hpp
, he
->hists
);
927 double per
= PERCENT(he
, rmt_hitm
);
930 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, PERC_STR(buf
, per
));
934 percent_rmt_hitm_color(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
935 struct hist_entry
*he
)
937 return percent_color(fmt
, hpp
, he
, percent_rmt_hitm
);
941 percent_rmt_hitm_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
942 struct hist_entry
*left
, struct hist_entry
*right
)
947 per_left
= PERCENT(left
, lcl_hitm
);
948 per_right
= PERCENT(right
, lcl_hitm
);
950 return per_left
- per_right
;
954 percent_lcl_hitm_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
955 struct hist_entry
*he
)
957 int width
= c2c_width(fmt
, hpp
, he
->hists
);
958 double per
= PERCENT(he
, lcl_hitm
);
961 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, PERC_STR(buf
, per
));
965 percent_lcl_hitm_color(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
966 struct hist_entry
*he
)
968 return percent_color(fmt
, hpp
, he
, percent_lcl_hitm
);
972 percent_lcl_hitm_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
973 struct hist_entry
*left
, struct hist_entry
*right
)
978 per_left
= PERCENT(left
, lcl_hitm
);
979 per_right
= PERCENT(right
, lcl_hitm
);
981 return per_left
- per_right
;
985 percent_stores_l1hit_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
986 struct hist_entry
*he
)
988 int width
= c2c_width(fmt
, hpp
, he
->hists
);
989 double per
= PERCENT(he
, st_l1hit
);
992 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, PERC_STR(buf
, per
));
996 percent_stores_l1hit_color(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
997 struct hist_entry
*he
)
999 return percent_color(fmt
, hpp
, he
, percent_st_l1hit
);
1003 percent_stores_l1hit_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
1004 struct hist_entry
*left
, struct hist_entry
*right
)
1009 per_left
= PERCENT(left
, st_l1hit
);
1010 per_right
= PERCENT(right
, st_l1hit
);
1012 return per_left
- per_right
;
1016 percent_stores_l1miss_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
1017 struct hist_entry
*he
)
1019 int width
= c2c_width(fmt
, hpp
, he
->hists
);
1020 double per
= PERCENT(he
, st_l1miss
);
1023 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, PERC_STR(buf
, per
));
1027 percent_stores_l1miss_color(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
1028 struct hist_entry
*he
)
1030 return percent_color(fmt
, hpp
, he
, percent_st_l1miss
);
1034 percent_stores_l1miss_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
1035 struct hist_entry
*left
, struct hist_entry
*right
)
1040 per_left
= PERCENT(left
, st_l1miss
);
1041 per_right
= PERCENT(right
, st_l1miss
);
1043 return per_left
- per_right
;
1050 pid_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
1051 struct hist_entry
*he
)
1053 int width
= c2c_width(fmt
, hpp
, he
->hists
);
1055 return scnprintf(hpp
->buf
, hpp
->size
, "%*d", width
, he
->thread
->pid_
);
1059 pid_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
1060 struct hist_entry
*left
, struct hist_entry
*right
)
1062 return left
->thread
->pid_
- right
->thread
->pid_
;
1066 empty_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
1067 struct hist_entry
*left __maybe_unused
,
1068 struct hist_entry
*right __maybe_unused
)
1074 node_entry(struct perf_hpp_fmt
*fmt __maybe_unused
, struct perf_hpp
*hpp
,
1075 struct hist_entry
*he
)
1077 struct c2c_hist_entry
*c2c_he
;
1082 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
1084 for (node
= 0; node
< c2c
.nodes_cnt
; node
++) {
1085 DECLARE_BITMAP(set
, c2c
.cpus_cnt
);
1087 bitmap_zero(set
, c2c
.cpus_cnt
);
1088 bitmap_and(set
, c2c_he
->cpuset
, c2c
.nodes
[node
], c2c
.cpus_cnt
);
1090 if (!bitmap_weight(set
, c2c
.cpus_cnt
)) {
1091 if (c2c
.node_info
== 1) {
1092 ret
= scnprintf(hpp
->buf
, hpp
->size
, "%21s", " ");
1093 advance_hpp(hpp
, ret
);
1099 ret
= scnprintf(hpp
->buf
, hpp
->size
, " ");
1100 advance_hpp(hpp
, ret
);
1103 switch (c2c
.node_info
) {
1105 ret
= scnprintf(hpp
->buf
, hpp
->size
, "%2d", node
);
1106 advance_hpp(hpp
, ret
);
1110 int num
= bitmap_weight(c2c_he
->cpuset
, c2c
.cpus_cnt
);
1111 struct c2c_stats
*stats
= &c2c_he
->node_stats
[node
];
1113 ret
= scnprintf(hpp
->buf
, hpp
->size
, "%2d{%2d ", node
, num
);
1114 advance_hpp(hpp
, ret
);
1116 #define DISPLAY_HITM(__h) \
1117 if (c2c_he->stats.__h> 0) { \
1118 ret = scnprintf(hpp->buf, hpp->size, "%5.1f%% ", \
1119 percent(stats->__h, c2c_he->stats.__h));\
1121 ret = scnprintf(hpp->buf, hpp->size, "%6s ", "n/a"); \
1124 switch (c2c
.display
) {
1126 DISPLAY_HITM(rmt_hitm
);
1129 DISPLAY_HITM(lcl_hitm
);
1132 DISPLAY_HITM(tot_hitm
);
1139 advance_hpp(hpp
, ret
);
1141 if (c2c_he
->stats
.store
> 0) {
1142 ret
= scnprintf(hpp
->buf
, hpp
->size
, "%5.1f%%}",
1143 percent(stats
->store
, c2c_he
->stats
.store
));
1145 ret
= scnprintf(hpp
->buf
, hpp
->size
, "%6s}", "n/a");
1148 advance_hpp(hpp
, ret
);
1152 ret
= scnprintf(hpp
->buf
, hpp
->size
, "%2d{", node
);
1153 advance_hpp(hpp
, ret
);
1155 ret
= bitmap_scnprintf(set
, c2c
.cpus_cnt
, hpp
->buf
, hpp
->size
);
1156 advance_hpp(hpp
, ret
);
1158 ret
= scnprintf(hpp
->buf
, hpp
->size
, "}");
1159 advance_hpp(hpp
, ret
);
1172 mean_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
1173 struct hist_entry
*he
, double mean
)
1175 int width
= c2c_width(fmt
, hpp
, he
->hists
);
1178 scnprintf(buf
, 10, "%6.0f", mean
);
1179 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, buf
);
1182 #define MEAN_ENTRY(__func, __val) \
1184 __func(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, struct hist_entry *he) \
1186 struct c2c_hist_entry *c2c_he; \
1187 c2c_he = container_of(he, struct c2c_hist_entry, he); \
1188 return mean_entry(fmt, hpp, he, avg_stats(&c2c_he->cstats.__val)); \
1191 MEAN_ENTRY(mean_rmt_entry
, rmt_hitm
);
1192 MEAN_ENTRY(mean_lcl_entry
, lcl_hitm
);
1193 MEAN_ENTRY(mean_load_entry
, load
);
1196 cpucnt_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
1197 struct hist_entry
*he
)
1199 struct c2c_hist_entry
*c2c_he
;
1200 int width
= c2c_width(fmt
, hpp
, he
->hists
);
1203 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
1205 scnprintf(buf
, 10, "%d", bitmap_weight(c2c_he
->cpuset
, c2c
.cpus_cnt
));
1206 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, buf
);
1210 cl_idx_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
1211 struct hist_entry
*he
)
1213 struct c2c_hist_entry
*c2c_he
;
1214 int width
= c2c_width(fmt
, hpp
, he
->hists
);
1217 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
1219 scnprintf(buf
, 10, "%u", c2c_he
->cacheline_idx
);
1220 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, buf
);
1224 cl_idx_empty_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
1225 struct hist_entry
*he
)
1227 int width
= c2c_width(fmt
, hpp
, he
->hists
);
1229 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, "");
1232 #define HEADER_LOW(__h) \
1239 #define HEADER_BOTH(__h0, __h1) \
1249 #define HEADER_SPAN(__h0, __h1, __s) \
1260 #define HEADER_SPAN_LOW(__h) \
1267 static struct c2c_dimension dim_dcacheline
= {
1268 .header
= HEADER_SPAN("--- Cacheline ----", "Address", 2),
1269 .name
= "dcacheline",
1270 .cmp
= dcacheline_cmp
,
1271 .entry
= dcacheline_entry
,
1275 static struct c2c_dimension dim_dcacheline_node
= {
1276 .header
= HEADER_LOW("Node"),
1277 .name
= "dcacheline_node",
1279 .entry
= dcacheline_node_entry
,
1283 static struct c2c_dimension dim_dcacheline_count
= {
1284 .header
= HEADER_LOW("PA cnt"),
1285 .name
= "dcacheline_count",
1287 .entry
= dcacheline_node_count
,
1291 static struct c2c_header header_offset_tui
= HEADER_SPAN("-----", "Off", 2);
1293 static struct c2c_dimension dim_offset
= {
1294 .header
= HEADER_SPAN("--- Data address -", "Offset", 2),
1297 .entry
= offset_entry
,
1301 static struct c2c_dimension dim_offset_node
= {
1302 .header
= HEADER_LOW("Node"),
1303 .name
= "offset_node",
1305 .entry
= dcacheline_node_entry
,
1309 static struct c2c_dimension dim_iaddr
= {
1310 .header
= HEADER_LOW("Code address"),
1313 .entry
= iaddr_entry
,
1317 static struct c2c_dimension dim_tot_hitm
= {
1318 .header
= HEADER_SPAN("----- LLC Load Hitm -----", "Total", 2),
1320 .cmp
= tot_hitm_cmp
,
1321 .entry
= tot_hitm_entry
,
1325 static struct c2c_dimension dim_lcl_hitm
= {
1326 .header
= HEADER_SPAN_LOW("Lcl"),
1328 .cmp
= lcl_hitm_cmp
,
1329 .entry
= lcl_hitm_entry
,
1333 static struct c2c_dimension dim_rmt_hitm
= {
1334 .header
= HEADER_SPAN_LOW("Rmt"),
1336 .cmp
= rmt_hitm_cmp
,
1337 .entry
= rmt_hitm_entry
,
1341 static struct c2c_dimension dim_cl_rmt_hitm
= {
1342 .header
= HEADER_SPAN("----- HITM -----", "Rmt", 1),
1343 .name
= "cl_rmt_hitm",
1344 .cmp
= rmt_hitm_cmp
,
1345 .entry
= rmt_hitm_entry
,
1349 static struct c2c_dimension dim_cl_lcl_hitm
= {
1350 .header
= HEADER_SPAN_LOW("Lcl"),
1351 .name
= "cl_lcl_hitm",
1352 .cmp
= lcl_hitm_cmp
,
1353 .entry
= lcl_hitm_entry
,
1357 static struct c2c_dimension dim_stores
= {
1358 .header
= HEADER_SPAN("---- Store Reference ----", "Total", 2),
1361 .entry
= store_entry
,
1365 static struct c2c_dimension dim_stores_l1hit
= {
1366 .header
= HEADER_SPAN_LOW("L1Hit"),
1367 .name
= "stores_l1hit",
1368 .cmp
= st_l1hit_cmp
,
1369 .entry
= st_l1hit_entry
,
1373 static struct c2c_dimension dim_stores_l1miss
= {
1374 .header
= HEADER_SPAN_LOW("L1Miss"),
1375 .name
= "stores_l1miss",
1376 .cmp
= st_l1miss_cmp
,
1377 .entry
= st_l1miss_entry
,
1381 static struct c2c_dimension dim_cl_stores_l1hit
= {
1382 .header
= HEADER_SPAN("-- Store Refs --", "L1 Hit", 1),
1383 .name
= "cl_stores_l1hit",
1384 .cmp
= st_l1hit_cmp
,
1385 .entry
= st_l1hit_entry
,
1389 static struct c2c_dimension dim_cl_stores_l1miss
= {
1390 .header
= HEADER_SPAN_LOW("L1 Miss"),
1391 .name
= "cl_stores_l1miss",
1392 .cmp
= st_l1miss_cmp
,
1393 .entry
= st_l1miss_entry
,
1397 static struct c2c_dimension dim_ld_fbhit
= {
1398 .header
= HEADER_SPAN("----- Core Load Hit -----", "FB", 2),
1400 .cmp
= ld_fbhit_cmp
,
1401 .entry
= ld_fbhit_entry
,
1405 static struct c2c_dimension dim_ld_l1hit
= {
1406 .header
= HEADER_SPAN_LOW("L1"),
1408 .cmp
= ld_l1hit_cmp
,
1409 .entry
= ld_l1hit_entry
,
1413 static struct c2c_dimension dim_ld_l2hit
= {
1414 .header
= HEADER_SPAN_LOW("L2"),
1416 .cmp
= ld_l2hit_cmp
,
1417 .entry
= ld_l2hit_entry
,
1421 static struct c2c_dimension dim_ld_llchit
= {
1422 .header
= HEADER_SPAN("-- LLC Load Hit --", "Llc", 1),
1423 .name
= "ld_lclhit",
1424 .cmp
= ld_llchit_cmp
,
1425 .entry
= ld_llchit_entry
,
1429 static struct c2c_dimension dim_ld_rmthit
= {
1430 .header
= HEADER_SPAN_LOW("Rmt"),
1431 .name
= "ld_rmthit",
1433 .entry
= rmt_hit_entry
,
1437 static struct c2c_dimension dim_ld_llcmiss
= {
1438 .header
= HEADER_BOTH("LLC", "Ld Miss"),
1439 .name
= "ld_llcmiss",
1440 .cmp
= ld_llcmiss_cmp
,
1441 .entry
= ld_llcmiss_entry
,
1445 static struct c2c_dimension dim_tot_recs
= {
1446 .header
= HEADER_BOTH("Total", "records"),
1448 .cmp
= tot_recs_cmp
,
1449 .entry
= tot_recs_entry
,
1453 static struct c2c_dimension dim_tot_loads
= {
1454 .header
= HEADER_BOTH("Total", "Loads"),
1455 .name
= "tot_loads",
1456 .cmp
= tot_loads_cmp
,
1457 .entry
= tot_loads_entry
,
1461 static struct c2c_header percent_hitm_header
[] = {
1462 [DISPLAY_LCL
] = HEADER_BOTH("Lcl", "Hitm"),
1463 [DISPLAY_RMT
] = HEADER_BOTH("Rmt", "Hitm"),
1464 [DISPLAY_TOT
] = HEADER_BOTH("Tot", "Hitm"),
1467 static struct c2c_dimension dim_percent_hitm
= {
1468 .name
= "percent_hitm",
1469 .cmp
= percent_hitm_cmp
,
1470 .entry
= percent_hitm_entry
,
1471 .color
= percent_hitm_color
,
1475 static struct c2c_dimension dim_percent_rmt_hitm
= {
1476 .header
= HEADER_SPAN("----- HITM -----", "Rmt", 1),
1477 .name
= "percent_rmt_hitm",
1478 .cmp
= percent_rmt_hitm_cmp
,
1479 .entry
= percent_rmt_hitm_entry
,
1480 .color
= percent_rmt_hitm_color
,
1484 static struct c2c_dimension dim_percent_lcl_hitm
= {
1485 .header
= HEADER_SPAN_LOW("Lcl"),
1486 .name
= "percent_lcl_hitm",
1487 .cmp
= percent_lcl_hitm_cmp
,
1488 .entry
= percent_lcl_hitm_entry
,
1489 .color
= percent_lcl_hitm_color
,
1493 static struct c2c_dimension dim_percent_stores_l1hit
= {
1494 .header
= HEADER_SPAN("-- Store Refs --", "L1 Hit", 1),
1495 .name
= "percent_stores_l1hit",
1496 .cmp
= percent_stores_l1hit_cmp
,
1497 .entry
= percent_stores_l1hit_entry
,
1498 .color
= percent_stores_l1hit_color
,
1502 static struct c2c_dimension dim_percent_stores_l1miss
= {
1503 .header
= HEADER_SPAN_LOW("L1 Miss"),
1504 .name
= "percent_stores_l1miss",
1505 .cmp
= percent_stores_l1miss_cmp
,
1506 .entry
= percent_stores_l1miss_entry
,
1507 .color
= percent_stores_l1miss_color
,
1511 static struct c2c_dimension dim_dram_lcl
= {
1512 .header
= HEADER_SPAN("--- Load Dram ----", "Lcl", 1),
1514 .cmp
= lcl_dram_cmp
,
1515 .entry
= lcl_dram_entry
,
1519 static struct c2c_dimension dim_dram_rmt
= {
1520 .header
= HEADER_SPAN_LOW("Rmt"),
1522 .cmp
= rmt_dram_cmp
,
1523 .entry
= rmt_dram_entry
,
1527 static struct c2c_dimension dim_pid
= {
1528 .header
= HEADER_LOW("Pid"),
1535 static struct c2c_dimension dim_tid
= {
1536 .header
= HEADER_LOW("Tid"),
1541 static struct c2c_dimension dim_symbol
= {
1546 static struct c2c_dimension dim_dso
= {
1547 .header
= HEADER_BOTH("Shared", "Object"),
1552 static struct c2c_header header_node
[3] = {
1554 HEADER_LOW("Node{cpus %hitms %stores}"),
1555 HEADER_LOW("Node{cpu list}"),
1558 static struct c2c_dimension dim_node
= {
1561 .entry
= node_entry
,
1565 static struct c2c_dimension dim_mean_rmt
= {
1566 .header
= HEADER_SPAN("---------- cycles ----------", "rmt hitm", 2),
1569 .entry
= mean_rmt_entry
,
1573 static struct c2c_dimension dim_mean_lcl
= {
1574 .header
= HEADER_SPAN_LOW("lcl hitm"),
1577 .entry
= mean_lcl_entry
,
1581 static struct c2c_dimension dim_mean_load
= {
1582 .header
= HEADER_SPAN_LOW("load"),
1583 .name
= "mean_load",
1585 .entry
= mean_load_entry
,
1589 static struct c2c_dimension dim_cpucnt
= {
1590 .header
= HEADER_BOTH("cpu", "cnt"),
1593 .entry
= cpucnt_entry
,
1597 static struct c2c_dimension dim_srcline
= {
1598 .name
= "cl_srcline",
1599 .se
= &sort_srcline
,
1602 static struct c2c_dimension dim_dcacheline_idx
= {
1603 .header
= HEADER_LOW("Index"),
1606 .entry
= cl_idx_entry
,
1610 static struct c2c_dimension dim_dcacheline_num
= {
1611 .header
= HEADER_LOW("Num"),
1614 .entry
= cl_idx_entry
,
1618 static struct c2c_dimension dim_dcacheline_num_empty
= {
1619 .header
= HEADER_LOW("Num"),
1620 .name
= "cl_num_empty",
1622 .entry
= cl_idx_empty_entry
,
1626 static struct c2c_dimension
*dimensions
[] = {
1628 &dim_dcacheline_node
,
1629 &dim_dcacheline_count
,
1641 &dim_cl_stores_l1hit
,
1642 &dim_cl_stores_l1miss
,
1652 &dim_percent_rmt_hitm
,
1653 &dim_percent_lcl_hitm
,
1654 &dim_percent_stores_l1hit
,
1655 &dim_percent_stores_l1miss
,
1668 &dim_dcacheline_idx
,
1669 &dim_dcacheline_num
,
1670 &dim_dcacheline_num_empty
,
1674 static void fmt_free(struct perf_hpp_fmt
*fmt
)
1676 struct c2c_fmt
*c2c_fmt
;
1678 c2c_fmt
= container_of(fmt
, struct c2c_fmt
, fmt
);
1682 static bool fmt_equal(struct perf_hpp_fmt
*a
, struct perf_hpp_fmt
*b
)
1684 struct c2c_fmt
*c2c_a
= container_of(a
, struct c2c_fmt
, fmt
);
1685 struct c2c_fmt
*c2c_b
= container_of(b
, struct c2c_fmt
, fmt
);
1687 return c2c_a
->dim
== c2c_b
->dim
;
1690 static struct c2c_dimension
*get_dimension(const char *name
)
1694 for (i
= 0; dimensions
[i
]; i
++) {
1695 struct c2c_dimension
*dim
= dimensions
[i
];
1697 if (!strcmp(dim
->name
, name
))
1704 static int c2c_se_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
1705 struct hist_entry
*he
)
1707 struct c2c_fmt
*c2c_fmt
= container_of(fmt
, struct c2c_fmt
, fmt
);
1708 struct c2c_dimension
*dim
= c2c_fmt
->dim
;
1709 size_t len
= fmt
->user_len
;
1712 len
= hists__col_len(he
->hists
, dim
->se
->se_width_idx
);
1714 if (dim
== &dim_symbol
|| dim
== &dim_srcline
)
1715 len
= symbol_width(he
->hists
, dim
->se
);
1718 return dim
->se
->se_snprintf(he
, hpp
->buf
, hpp
->size
, len
);
1721 static int64_t c2c_se_cmp(struct perf_hpp_fmt
*fmt
,
1722 struct hist_entry
*a
, struct hist_entry
*b
)
1724 struct c2c_fmt
*c2c_fmt
= container_of(fmt
, struct c2c_fmt
, fmt
);
1725 struct c2c_dimension
*dim
= c2c_fmt
->dim
;
1727 return dim
->se
->se_cmp(a
, b
);
1730 static int64_t c2c_se_collapse(struct perf_hpp_fmt
*fmt
,
1731 struct hist_entry
*a
, struct hist_entry
*b
)
1733 struct c2c_fmt
*c2c_fmt
= container_of(fmt
, struct c2c_fmt
, fmt
);
1734 struct c2c_dimension
*dim
= c2c_fmt
->dim
;
1735 int64_t (*collapse_fn
)(struct hist_entry
*, struct hist_entry
*);
1737 collapse_fn
= dim
->se
->se_collapse
?: dim
->se
->se_cmp
;
1738 return collapse_fn(a
, b
);
1741 static struct c2c_fmt
*get_format(const char *name
)
1743 struct c2c_dimension
*dim
= get_dimension(name
);
1744 struct c2c_fmt
*c2c_fmt
;
1745 struct perf_hpp_fmt
*fmt
;
1750 c2c_fmt
= zalloc(sizeof(*c2c_fmt
));
1756 fmt
= &c2c_fmt
->fmt
;
1757 INIT_LIST_HEAD(&fmt
->list
);
1758 INIT_LIST_HEAD(&fmt
->sort_list
);
1760 fmt
->cmp
= dim
->se
? c2c_se_cmp
: dim
->cmp
;
1761 fmt
->sort
= dim
->se
? c2c_se_cmp
: dim
->cmp
;
1762 fmt
->color
= dim
->se
? NULL
: dim
->color
;
1763 fmt
->entry
= dim
->se
? c2c_se_entry
: dim
->entry
;
1764 fmt
->header
= c2c_header
;
1765 fmt
->width
= c2c_width
;
1766 fmt
->collapse
= dim
->se
? c2c_se_collapse
: dim
->cmp
;
1767 fmt
->equal
= fmt_equal
;
1768 fmt
->free
= fmt_free
;
1773 static int c2c_hists__init_output(struct perf_hpp_list
*hpp_list
, char *name
)
1775 struct c2c_fmt
*c2c_fmt
= get_format(name
);
1779 return output_field_add(hpp_list
, name
);
1782 perf_hpp_list__column_register(hpp_list
, &c2c_fmt
->fmt
);
1786 static int c2c_hists__init_sort(struct perf_hpp_list
*hpp_list
, char *name
)
1788 struct c2c_fmt
*c2c_fmt
= get_format(name
);
1789 struct c2c_dimension
*dim
;
1793 return sort_dimension__add(hpp_list
, name
, NULL
, 0);
1797 if (dim
== &dim_dso
)
1800 perf_hpp_list__register_sort_field(hpp_list
, &c2c_fmt
->fmt
);
1804 #define PARSE_LIST(_list, _fn) \
1812 for (tok = strtok_r((char *)_list, ", ", &tmp); \
1813 tok; tok = strtok_r(NULL, ", ", &tmp)) { \
1814 ret = _fn(hpp_list, tok); \
1815 if (ret == -EINVAL) { \
1816 pr_err("Invalid --fields key: `%s'", tok); \
1818 } else if (ret == -ESRCH) { \
1819 pr_err("Unknown --fields key: `%s'", tok); \
1825 static int hpp_list__parse(struct perf_hpp_list
*hpp_list
,
1826 const char *output_
,
1829 char *output
= output_
? strdup(output_
) : NULL
;
1830 char *sort
= sort_
? strdup(sort_
) : NULL
;
1833 PARSE_LIST(output
, c2c_hists__init_output
);
1834 PARSE_LIST(sort
, c2c_hists__init_sort
);
1836 /* copy sort keys to output fields */
1837 perf_hpp__setup_output_field(hpp_list
);
1840 * We dont need other sorting keys other than those
1841 * we already specified. It also really slows down
1842 * the processing a lot with big number of output
1843 * fields, so switching this off for c2c.
1847 /* and then copy output fields to sort keys */
1848 perf_hpp__append_sort_keys(&hists
->list
);
1856 static int c2c_hists__init(struct c2c_hists
*hists
,
1858 int nr_header_lines
)
1860 __hists__init(&hists
->hists
, &hists
->list
);
1863 * Initialize only with sort fields, we need to resort
1864 * later anyway, and that's where we add output fields
1867 perf_hpp_list__init(&hists
->list
);
1869 /* Overload number of header lines.*/
1870 hists
->list
.nr_header_lines
= nr_header_lines
;
1872 return hpp_list__parse(&hists
->list
, NULL
, sort
);
1875 static int c2c_hists__reinit(struct c2c_hists
*c2c_hists
,
1879 perf_hpp__reset_output_field(&c2c_hists
->list
);
1880 return hpp_list__parse(&c2c_hists
->list
, output
, sort
);
1883 #define DISPLAY_LINE_LIMIT 0.0005
1885 static bool he__display(struct hist_entry
*he
, struct c2c_stats
*stats
)
1887 struct c2c_hist_entry
*c2c_he
;
1893 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
1895 #define FILTER_HITM(__h) \
1897 ld_dist = ((double)c2c_he->stats.__h / stats->__h); \
1898 if (ld_dist < DISPLAY_LINE_LIMIT) \
1899 he->filtered = HIST_FILTER__C2C; \
1901 he->filtered = HIST_FILTER__C2C; \
1904 switch (c2c
.display
) {
1906 FILTER_HITM(lcl_hitm
);
1909 FILTER_HITM(rmt_hitm
);
1912 FILTER_HITM(tot_hitm
);
1919 return he
->filtered
== 0;
1922 static inline int valid_hitm_or_store(struct hist_entry
*he
)
1924 struct c2c_hist_entry
*c2c_he
;
1927 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
1928 has_hitm
= c2c
.display
== DISPLAY_TOT
? c2c_he
->stats
.tot_hitm
:
1929 c2c
.display
== DISPLAY_LCL
? c2c_he
->stats
.lcl_hitm
:
1930 c2c_he
->stats
.rmt_hitm
;
1931 return has_hitm
|| c2c_he
->stats
.store
;
1934 static void set_node_width(struct c2c_hist_entry
*c2c_he
, int len
)
1936 struct c2c_dimension
*dim
;
1938 dim
= &c2c
.hists
== c2c_he
->hists
?
1939 &dim_dcacheline_node
: &dim_offset_node
;
1941 if (len
> dim
->width
)
1945 static int set_nodestr(struct c2c_hist_entry
*c2c_he
)
1950 if (c2c_he
->nodestr
)
1953 if (bitmap_weight(c2c_he
->nodeset
, c2c
.nodes_cnt
)) {
1954 len
= bitmap_scnprintf(c2c_he
->nodeset
, c2c
.nodes_cnt
,
1957 len
= scnprintf(buf
, sizeof(buf
), "N/A");
1960 set_node_width(c2c_he
, len
);
1961 c2c_he
->nodestr
= strdup(buf
);
1962 return c2c_he
->nodestr
? 0 : -ENOMEM
;
1965 static void calc_width(struct c2c_hist_entry
*c2c_he
)
1967 struct c2c_hists
*c2c_hists
;
1969 c2c_hists
= container_of(c2c_he
->he
.hists
, struct c2c_hists
, hists
);
1970 hists__calc_col_len(&c2c_hists
->hists
, &c2c_he
->he
);
1971 set_nodestr(c2c_he
);
1974 static int filter_cb(struct hist_entry
*he
)
1976 struct c2c_hist_entry
*c2c_he
;
1978 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
1980 if (c2c
.show_src
&& !he
->srcline
)
1981 he
->srcline
= hist_entry__srcline(he
);
1985 if (!valid_hitm_or_store(he
))
1986 he
->filtered
= HIST_FILTER__C2C
;
1991 static int resort_cl_cb(struct hist_entry
*he
)
1993 struct c2c_hist_entry
*c2c_he
;
1994 struct c2c_hists
*c2c_hists
;
1995 bool display
= he__display(he
, &c2c
.hitm_stats
);
1997 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
1998 c2c_hists
= c2c_he
->hists
;
2000 if (display
&& c2c_hists
) {
2001 static unsigned int idx
;
2003 c2c_he
->cacheline_idx
= idx
++;
2006 c2c_hists__reinit(c2c_hists
, c2c
.cl_output
, c2c
.cl_resort
);
2008 hists__collapse_resort(&c2c_hists
->hists
, NULL
);
2009 hists__output_resort_cb(&c2c_hists
->hists
, NULL
, filter_cb
);
2015 static void setup_nodes_header(void)
2017 dim_node
.header
= header_node
[c2c
.node_info
];
2020 static int setup_nodes(struct perf_session
*session
)
2022 struct numa_node
*n
;
2023 unsigned long **nodes
;
2027 if (c2c
.node_info
> 2)
2030 c2c
.nodes_cnt
= session
->header
.env
.nr_numa_nodes
;
2031 c2c
.cpus_cnt
= session
->header
.env
.nr_cpus_online
;
2033 n
= session
->header
.env
.numa_nodes
;
2037 nodes
= zalloc(sizeof(unsigned long *) * c2c
.nodes_cnt
);
2043 cpu2node
= zalloc(sizeof(int) * c2c
.cpus_cnt
);
2047 for (cpu
= 0; cpu
< c2c
.cpus_cnt
; cpu
++)
2050 c2c
.cpu2node
= cpu2node
;
2052 for (node
= 0; node
< c2c
.nodes_cnt
; node
++) {
2053 struct cpu_map
*map
= n
[node
].map
;
2056 set
= bitmap_alloc(c2c
.cpus_cnt
);
2062 /* empty node, skip */
2063 if (cpu_map__empty(map
))
2066 for (cpu
= 0; cpu
< map
->nr
; cpu
++) {
2067 set_bit(map
->map
[cpu
], set
);
2069 if (WARN_ONCE(cpu2node
[map
->map
[cpu
]] != -1, "node/cpu topology bug"))
2072 cpu2node
[map
->map
[cpu
]] = node
;
2076 setup_nodes_header();
2080 #define HAS_HITMS(__h) ((__h)->stats.lcl_hitm || (__h)->stats.rmt_hitm)
2082 static int resort_hitm_cb(struct hist_entry
*he
)
2084 struct c2c_hist_entry
*c2c_he
;
2085 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
2087 if (HAS_HITMS(c2c_he
)) {
2088 c2c
.shared_clines
++;
2089 c2c_add_stats(&c2c
.hitm_stats
, &c2c_he
->stats
);
2095 static int hists__iterate_cb(struct hists
*hists
, hists__resort_cb_t cb
)
2097 struct rb_node
*next
= rb_first(&hists
->entries
);
2101 struct hist_entry
*he
;
2103 he
= rb_entry(next
, struct hist_entry
, rb_node
);
2107 next
= rb_next(&he
->rb_node
);
2113 static void print_c2c__display_stats(FILE *out
)
2116 struct c2c_stats
*stats
= &c2c
.hists
.stats
;
2118 llc_misses
= stats
->lcl_dram
+
2123 fprintf(out
, "=================================================\n");
2124 fprintf(out
, " Trace Event Information \n");
2125 fprintf(out
, "=================================================\n");
2126 fprintf(out
, " Total records : %10d\n", stats
->nr_entries
);
2127 fprintf(out
, " Locked Load/Store Operations : %10d\n", stats
->locks
);
2128 fprintf(out
, " Load Operations : %10d\n", stats
->load
);
2129 fprintf(out
, " Loads - uncacheable : %10d\n", stats
->ld_uncache
);
2130 fprintf(out
, " Loads - IO : %10d\n", stats
->ld_io
);
2131 fprintf(out
, " Loads - Miss : %10d\n", stats
->ld_miss
);
2132 fprintf(out
, " Loads - no mapping : %10d\n", stats
->ld_noadrs
);
2133 fprintf(out
, " Load Fill Buffer Hit : %10d\n", stats
->ld_fbhit
);
2134 fprintf(out
, " Load L1D hit : %10d\n", stats
->ld_l1hit
);
2135 fprintf(out
, " Load L2D hit : %10d\n", stats
->ld_l2hit
);
2136 fprintf(out
, " Load LLC hit : %10d\n", stats
->ld_llchit
+ stats
->lcl_hitm
);
2137 fprintf(out
, " Load Local HITM : %10d\n", stats
->lcl_hitm
);
2138 fprintf(out
, " Load Remote HITM : %10d\n", stats
->rmt_hitm
);
2139 fprintf(out
, " Load Remote HIT : %10d\n", stats
->rmt_hit
);
2140 fprintf(out
, " Load Local DRAM : %10d\n", stats
->lcl_dram
);
2141 fprintf(out
, " Load Remote DRAM : %10d\n", stats
->rmt_dram
);
2142 fprintf(out
, " Load MESI State Exclusive : %10d\n", stats
->ld_excl
);
2143 fprintf(out
, " Load MESI State Shared : %10d\n", stats
->ld_shared
);
2144 fprintf(out
, " Load LLC Misses : %10d\n", llc_misses
);
2145 fprintf(out
, " LLC Misses to Local DRAM : %10.1f%%\n", ((double)stats
->lcl_dram
/(double)llc_misses
) * 100.);
2146 fprintf(out
, " LLC Misses to Remote DRAM : %10.1f%%\n", ((double)stats
->rmt_dram
/(double)llc_misses
) * 100.);
2147 fprintf(out
, " LLC Misses to Remote cache (HIT) : %10.1f%%\n", ((double)stats
->rmt_hit
/(double)llc_misses
) * 100.);
2148 fprintf(out
, " LLC Misses to Remote cache (HITM) : %10.1f%%\n", ((double)stats
->rmt_hitm
/(double)llc_misses
) * 100.);
2149 fprintf(out
, " Store Operations : %10d\n", stats
->store
);
2150 fprintf(out
, " Store - uncacheable : %10d\n", stats
->st_uncache
);
2151 fprintf(out
, " Store - no mapping : %10d\n", stats
->st_noadrs
);
2152 fprintf(out
, " Store L1D Hit : %10d\n", stats
->st_l1hit
);
2153 fprintf(out
, " Store L1D Miss : %10d\n", stats
->st_l1miss
);
2154 fprintf(out
, " No Page Map Rejects : %10d\n", stats
->nomap
);
2155 fprintf(out
, " Unable to parse data source : %10d\n", stats
->noparse
);
2158 static void print_shared_cacheline_info(FILE *out
)
2160 struct c2c_stats
*stats
= &c2c
.hitm_stats
;
2161 int hitm_cnt
= stats
->lcl_hitm
+ stats
->rmt_hitm
;
2163 fprintf(out
, "=================================================\n");
2164 fprintf(out
, " Global Shared Cache Line Event Information \n");
2165 fprintf(out
, "=================================================\n");
2166 fprintf(out
, " Total Shared Cache Lines : %10d\n", c2c
.shared_clines
);
2167 fprintf(out
, " Load HITs on shared lines : %10d\n", stats
->load
);
2168 fprintf(out
, " Fill Buffer Hits on shared lines : %10d\n", stats
->ld_fbhit
);
2169 fprintf(out
, " L1D hits on shared lines : %10d\n", stats
->ld_l1hit
);
2170 fprintf(out
, " L2D hits on shared lines : %10d\n", stats
->ld_l2hit
);
2171 fprintf(out
, " LLC hits on shared lines : %10d\n", stats
->ld_llchit
+ stats
->lcl_hitm
);
2172 fprintf(out
, " Locked Access on shared lines : %10d\n", stats
->locks
);
2173 fprintf(out
, " Store HITs on shared lines : %10d\n", stats
->store
);
2174 fprintf(out
, " Store L1D hits on shared lines : %10d\n", stats
->st_l1hit
);
2175 fprintf(out
, " Total Merged records : %10d\n", hitm_cnt
+ stats
->store
);
2178 static void print_cacheline(struct c2c_hists
*c2c_hists
,
2179 struct hist_entry
*he_cl
,
2180 struct perf_hpp_list
*hpp_list
,
2184 struct perf_hpp hpp
= {
2191 hists__fprintf_headers(&c2c_hists
->hists
, out
);
2197 fprintf(out
, " -------------------------------------------------------------\n");
2198 __hist_entry__snprintf(he_cl
, &hpp
, hpp_list
);
2199 fprintf(out
, "%s\n", bf
);
2200 fprintf(out
, " -------------------------------------------------------------\n");
2202 hists__fprintf(&c2c_hists
->hists
, false, 0, 0, 0, out
, false);
2205 static void print_pareto(FILE *out
)
2207 struct perf_hpp_list hpp_list
;
2211 perf_hpp_list__init(&hpp_list
);
2212 ret
= hpp_list__parse(&hpp_list
,
2221 if (WARN_ONCE(ret
, "failed to setup sort entries\n"))
2224 nd
= rb_first(&c2c
.hists
.hists
.entries
);
2226 for (; nd
; nd
= rb_next(nd
)) {
2227 struct hist_entry
*he
= rb_entry(nd
, struct hist_entry
, rb_node
);
2228 struct c2c_hist_entry
*c2c_he
;
2233 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
2234 print_cacheline(c2c_he
->hists
, he
, &hpp_list
, out
);
2238 static void print_c2c_info(FILE *out
, struct perf_session
*session
)
2240 struct perf_evlist
*evlist
= session
->evlist
;
2241 struct perf_evsel
*evsel
;
2244 fprintf(out
, "=================================================\n");
2245 fprintf(out
, " c2c details \n");
2246 fprintf(out
, "=================================================\n");
2248 evlist__for_each_entry(evlist
, evsel
) {
2249 fprintf(out
, "%-36s: %s\n", first
? " Events" : "",
2250 perf_evsel__name(evsel
));
2253 fprintf(out
, " Cachelines sort on : %s HITMs\n",
2254 display_str
[c2c
.display
]);
2255 fprintf(out
, " Cacheline data grouping : %s\n", c2c
.cl_sort
);
2258 static void perf_c2c__hists_fprintf(FILE *out
, struct perf_session
*session
)
2262 print_c2c__display_stats(out
);
2264 print_shared_cacheline_info(out
);
2266 print_c2c_info(out
, session
);
2272 fprintf(out
, "=================================================\n");
2273 fprintf(out
, " Shared Data Cache Line Table \n");
2274 fprintf(out
, "=================================================\n");
2275 fprintf(out
, "#\n");
2277 hists__fprintf(&c2c
.hists
.hists
, true, 0, 0, 0, stdout
, true);
2280 fprintf(out
, "=================================================\n");
2281 fprintf(out
, " Shared Cache Line Distribution Pareto \n");
2282 fprintf(out
, "=================================================\n");
2283 fprintf(out
, "#\n");
2288 #ifdef HAVE_SLANG_SUPPORT
2289 static void c2c_browser__update_nr_entries(struct hist_browser
*hb
)
2292 struct rb_node
*nd
= rb_first(&hb
->hists
->entries
);
2295 struct hist_entry
*he
= rb_entry(nd
, struct hist_entry
, rb_node
);
2303 hb
->nr_non_filtered_entries
= nr_entries
;
2306 struct c2c_cacheline_browser
{
2307 struct hist_browser hb
;
2308 struct hist_entry
*he
;
2312 perf_c2c_cacheline_browser__title(struct hist_browser
*browser
,
2313 char *bf
, size_t size
)
2315 struct c2c_cacheline_browser
*cl_browser
;
2316 struct hist_entry
*he
;
2319 cl_browser
= container_of(browser
, struct c2c_cacheline_browser
, hb
);
2320 he
= cl_browser
->he
;
2323 addr
= cl_address(he
->mem_info
->daddr
.addr
);
2325 scnprintf(bf
, size
, "Cacheline 0x%lx", addr
);
2329 static struct c2c_cacheline_browser
*
2330 c2c_cacheline_browser__new(struct hists
*hists
, struct hist_entry
*he
)
2332 struct c2c_cacheline_browser
*browser
;
2334 browser
= zalloc(sizeof(*browser
));
2336 hist_browser__init(&browser
->hb
, hists
);
2337 browser
->hb
.c2c_filter
= true;
2338 browser
->hb
.title
= perf_c2c_cacheline_browser__title
;
2345 static int perf_c2c__browse_cacheline(struct hist_entry
*he
)
2347 struct c2c_hist_entry
*c2c_he
;
2348 struct c2c_hists
*c2c_hists
;
2349 struct c2c_cacheline_browser
*cl_browser
;
2350 struct hist_browser
*browser
;
2353 " ENTER Toggle callchains (if present) \n"
2354 " n Toggle Node details info \n"
2355 " s Toggle full length of symbol and source line columns \n"
2356 " q Return back to cacheline list \n";
2361 /* Display compact version first. */
2362 c2c
.symbol_full
= false;
2364 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
2365 c2c_hists
= c2c_he
->hists
;
2367 cl_browser
= c2c_cacheline_browser__new(&c2c_hists
->hists
, he
);
2368 if (cl_browser
== NULL
)
2371 browser
= &cl_browser
->hb
;
2373 /* reset abort key so that it can get Ctrl-C as a key */
2375 SLang_init_tty(0, 0, 0);
2377 c2c_browser__update_nr_entries(browser
);
2380 key
= hist_browser__run(browser
, "? - help", true);
2384 c2c
.symbol_full
= !c2c
.symbol_full
;
2387 c2c
.node_info
= (c2c
.node_info
+ 1) % 3;
2388 setup_nodes_header();
2393 ui_browser__help_window(&browser
->b
, help
);
2405 static int perf_c2c_browser__title(struct hist_browser
*browser
,
2406 char *bf
, size_t size
)
2409 "Shared Data Cache Line Table "
2410 "(%lu entries, sorted on %s HITMs)",
2411 browser
->nr_non_filtered_entries
,
2412 display_str
[c2c
.display
]);
2416 static struct hist_browser
*
2417 perf_c2c_browser__new(struct hists
*hists
)
2419 struct hist_browser
*browser
= hist_browser__new(hists
);
2422 browser
->title
= perf_c2c_browser__title
;
2423 browser
->c2c_filter
= true;
2429 static int perf_c2c__hists_browse(struct hists
*hists
)
2431 struct hist_browser
*browser
;
2434 " d Display cacheline details \n"
2435 " ENTER Toggle callchains (if present) \n"
2438 browser
= perf_c2c_browser__new(hists
);
2439 if (browser
== NULL
)
2442 /* reset abort key so that it can get Ctrl-C as a key */
2444 SLang_init_tty(0, 0, 0);
2446 c2c_browser__update_nr_entries(browser
);
2449 key
= hist_browser__run(browser
, "? - help", true);
2455 perf_c2c__browse_cacheline(browser
->he_selection
);
2458 ui_browser__help_window(&browser
->b
, help
);
2466 hist_browser__delete(browser
);
2470 static void perf_c2c_display(struct perf_session
*session
)
2472 if (use_browser
== 0)
2473 perf_c2c__hists_fprintf(stdout
, session
);
2475 perf_c2c__hists_browse(&c2c
.hists
.hists
);
2478 static void perf_c2c_display(struct perf_session
*session
)
2481 perf_c2c__hists_fprintf(stdout
, session
);
2483 #endif /* HAVE_SLANG_SUPPORT */
2485 static char *fill_line(const char *orig
, int len
)
2487 int i
, j
, olen
= strlen(orig
);
2490 buf
= zalloc(len
+ 1);
2494 j
= len
/ 2 - olen
/ 2;
2496 for (i
= 0; i
< j
- 1; i
++)
2501 strcpy(buf
+ i
, orig
);
2507 for (; i
< len
; i
++)
2513 static int ui_quirks(void)
2515 const char *nodestr
= "Data address";
2518 if (!c2c
.use_stdio
) {
2519 dim_offset
.width
= 5;
2520 dim_offset
.header
= header_offset_tui
;
2524 dim_percent_hitm
.header
= percent_hitm_header
[c2c
.display
];
2526 /* Fix the zero line for dcacheline column. */
2527 buf
= fill_line("Cacheline", dim_dcacheline
.width
+
2528 dim_dcacheline_node
.width
+
2529 dim_dcacheline_count
.width
+ 4);
2533 dim_dcacheline
.header
.line
[0].text
= buf
;
2535 /* Fix the zero line for offset column. */
2536 buf
= fill_line(nodestr
, dim_offset
.width
+
2537 dim_offset_node
.width
+
2538 dim_dcacheline_count
.width
+ 4);
2542 dim_offset
.header
.line
[0].text
= buf
;
2547 #define CALLCHAIN_DEFAULT_OPT "graph,0.5,caller,function,percent"
2549 const char callchain_help
[] = "Display call graph (stack chain/backtrace):\n\n"
2550 CALLCHAIN_REPORT_HELP
2551 "\n\t\t\t\tDefault: " CALLCHAIN_DEFAULT_OPT
;
2554 parse_callchain_opt(const struct option
*opt
, const char *arg
, int unset
)
2556 struct callchain_param
*callchain
= opt
->value
;
2558 callchain
->enabled
= !unset
;
2563 symbol_conf
.use_callchain
= false;
2564 callchain
->mode
= CHAIN_NONE
;
2568 return parse_callchain_report_opt(arg
);
2571 static int setup_callchain(struct perf_evlist
*evlist
)
2573 u64 sample_type
= perf_evlist__combined_sample_type(evlist
);
2574 enum perf_call_graph_mode mode
= CALLCHAIN_NONE
;
2576 if ((sample_type
& PERF_SAMPLE_REGS_USER
) &&
2577 (sample_type
& PERF_SAMPLE_STACK_USER
)) {
2578 mode
= CALLCHAIN_DWARF
;
2579 dwarf_callchain_users
= true;
2580 } else if (sample_type
& PERF_SAMPLE_BRANCH_STACK
)
2581 mode
= CALLCHAIN_LBR
;
2582 else if (sample_type
& PERF_SAMPLE_CALLCHAIN
)
2583 mode
= CALLCHAIN_FP
;
2585 if (!callchain_param
.enabled
&&
2586 callchain_param
.mode
!= CHAIN_NONE
&&
2587 mode
!= CALLCHAIN_NONE
) {
2588 symbol_conf
.use_callchain
= true;
2589 if (callchain_register_param(&callchain_param
) < 0) {
2590 ui__error("Can't register callchain params.\n");
2595 callchain_param
.record_mode
= mode
;
2596 callchain_param
.min_percent
= 0;
2600 static int setup_display(const char *str
)
2602 const char *display
= str
?: "tot";
2604 if (!strcmp(display
, "tot"))
2605 c2c
.display
= DISPLAY_TOT
;
2606 else if (!strcmp(display
, "rmt"))
2607 c2c
.display
= DISPLAY_RMT
;
2608 else if (!strcmp(display
, "lcl"))
2609 c2c
.display
= DISPLAY_LCL
;
2611 pr_err("failed: unknown display type: %s\n", str
);
2618 #define for_each_token(__tok, __buf, __sep, __tmp) \
2619 for (__tok = strtok_r(__buf, __sep, &__tmp); __tok; \
2620 __tok = strtok_r(NULL, __sep, &__tmp))
2622 static int build_cl_output(char *cl_sort
, bool no_source
)
2624 char *tok
, *tmp
, *buf
= strdup(cl_sort
);
2625 bool add_pid
= false;
2626 bool add_tid
= false;
2627 bool add_iaddr
= false;
2628 bool add_sym
= false;
2629 bool add_dso
= false;
2630 bool add_src
= false;
2636 for_each_token(tok
, buf
, ",", tmp
) {
2637 if (!strcmp(tok
, "tid")) {
2639 } else if (!strcmp(tok
, "pid")) {
2641 } else if (!strcmp(tok
, "iaddr")) {
2645 add_src
= no_source
? false : true;
2646 } else if (!strcmp(tok
, "dso")) {
2648 } else if (strcmp(tok
, "offset")) {
2649 pr_err("unrecognized sort token: %s\n", tok
);
2655 if (asprintf(&c2c
.cl_output
,
2656 "%s%s%s%s%s%s%s%s%s%s",
2657 c2c
.use_stdio
? "cl_num_empty," : "",
2660 "percent_stores_l1hit,"
2661 "percent_stores_l1miss,"
2662 "offset,offset_node,dcacheline_count,",
2663 add_pid
? "pid," : "",
2664 add_tid
? "tid," : "",
2665 add_iaddr
? "iaddr," : "",
2671 add_sym
? "symbol," : "",
2672 add_dso
? "dso," : "",
2673 add_src
? "cl_srcline," : "",
2679 c2c
.show_src
= add_src
;
2685 static int setup_coalesce(const char *coalesce
, bool no_source
)
2687 const char *c
= coalesce
?: coalesce_default
;
2689 if (asprintf(&c2c
.cl_sort
, "offset,%s", c
) < 0)
2692 if (build_cl_output(c2c
.cl_sort
, no_source
))
2695 if (asprintf(&c2c
.cl_resort
, "offset,%s",
2696 c2c
.display
== DISPLAY_TOT
?
2698 c2c
.display
== DISPLAY_RMT
?
2699 "rmt_hitm,lcl_hitm" :
2700 "lcl_hitm,rmt_hitm") < 0)
2703 pr_debug("coalesce sort fields: %s\n", c2c
.cl_sort
);
2704 pr_debug("coalesce resort fields: %s\n", c2c
.cl_resort
);
2705 pr_debug("coalesce output fields: %s\n", c2c
.cl_output
);
2709 static int perf_c2c__report(int argc
, const char **argv
)
2711 struct perf_session
*session
;
2712 struct ui_progress prog
;
2713 struct perf_data data
= {
2714 .mode
= PERF_DATA_MODE_READ
,
2716 char callchain_default_opt
[] = CALLCHAIN_DEFAULT_OPT
;
2717 const char *display
= NULL
;
2718 const char *coalesce
= NULL
;
2719 bool no_source
= false;
2720 const struct option options
[] = {
2721 OPT_STRING('k', "vmlinux", &symbol_conf
.vmlinux_name
,
2722 "file", "vmlinux pathname"),
2723 OPT_STRING('i', "input", &input_name
, "file",
2724 "the input file to process"),
2725 OPT_INCR('N', "node-info", &c2c
.node_info
,
2726 "show extra node info in report (repeat for more info)"),
2727 #ifdef HAVE_SLANG_SUPPORT
2728 OPT_BOOLEAN(0, "stdio", &c2c
.use_stdio
, "Use the stdio interface"),
2730 OPT_BOOLEAN(0, "stats", &c2c
.stats_only
,
2731 "Display only statistic tables (implies --stdio)"),
2732 OPT_BOOLEAN(0, "full-symbols", &c2c
.symbol_full
,
2733 "Display full length of symbols"),
2734 OPT_BOOLEAN(0, "no-source", &no_source
,
2735 "Do not display Source Line column"),
2736 OPT_BOOLEAN(0, "show-all", &c2c
.show_all
,
2737 "Show all captured HITM lines."),
2738 OPT_CALLBACK_DEFAULT('g', "call-graph", &callchain_param
,
2739 "print_type,threshold[,print_limit],order,sort_key[,branch],value",
2740 callchain_help
, &parse_callchain_opt
,
2741 callchain_default_opt
),
2742 OPT_STRING('d', "display", &display
, "Switch HITM output type", "lcl,rmt"),
2743 OPT_STRING('c', "coalesce", &coalesce
, "coalesce fields",
2744 "coalesce fields: pid,tid,iaddr,dso"),
2745 OPT_BOOLEAN('f', "force", &symbol_conf
.force
, "don't complain, do it"),
2746 OPT_PARENT(c2c_options
),
2751 argc
= parse_options(argc
, argv
, options
, report_c2c_usage
,
2752 PARSE_OPT_STOP_AT_NON_OPTION
);
2754 usage_with_options(report_c2c_usage
, options
);
2757 c2c
.use_stdio
= true;
2759 if (!input_name
|| !strlen(input_name
))
2760 input_name
= "perf.data";
2762 data
.file
.path
= input_name
;
2763 data
.force
= symbol_conf
.force
;
2765 err
= setup_display(display
);
2769 err
= setup_coalesce(coalesce
, no_source
);
2771 pr_debug("Failed to initialize hists\n");
2775 err
= c2c_hists__init(&c2c
.hists
, "dcacheline", 2);
2777 pr_debug("Failed to initialize hists\n");
2781 session
= perf_session__new(&data
, 0, &c2c
.tool
);
2782 if (session
== NULL
) {
2783 pr_debug("No memory for session\n");
2787 err
= setup_nodes(session
);
2789 pr_err("Failed setup nodes\n");
2793 err
= mem2node__init(&c2c
.mem2node
, &session
->header
.env
);
2797 err
= setup_callchain(session
->evlist
);
2801 if (symbol__init(&session
->header
.env
) < 0)
2804 /* No pipe support at the moment. */
2805 if (perf_data__is_pipe(session
->data
)) {
2806 pr_debug("No pipe support at the moment.\n");
2815 setup_browser(false);
2817 err
= perf_session__process_events(session
);
2819 pr_err("failed to process sample\n");
2823 c2c_hists__reinit(&c2c
.hists
,
2830 "tot_hitm,lcl_hitm,rmt_hitm,"
2831 "stores,stores_l1hit,stores_l1miss,"
2832 "dram_lcl,dram_rmt,"
2835 "ld_fbhit,ld_l1hit,ld_l2hit,"
2836 "ld_lclhit,ld_rmthit",
2837 c2c
.display
== DISPLAY_TOT
? "tot_hitm" :
2838 c2c
.display
== DISPLAY_LCL
? "lcl_hitm" : "rmt_hitm"
2841 ui_progress__init(&prog
, c2c
.hists
.hists
.nr_entries
, "Sorting...");
2843 hists__collapse_resort(&c2c
.hists
.hists
, NULL
);
2844 hists__output_resort_cb(&c2c
.hists
.hists
, &prog
, resort_hitm_cb
);
2845 hists__iterate_cb(&c2c
.hists
.hists
, resort_cl_cb
);
2847 ui_progress__finish();
2850 pr_err("failed to setup UI\n");
2854 perf_c2c_display(session
);
2857 mem2node__exit(&c2c
.mem2node
);
2859 perf_session__delete(session
);
2864 static int parse_record_events(const struct option
*opt
,
2865 const char *str
, int unset __maybe_unused
)
2867 bool *event_set
= (bool *) opt
->value
;
2870 return perf_mem_events__parse(str
);
2874 static const char * const __usage_record
[] = {
2875 "perf c2c record [<options>] [<command>]",
2876 "perf c2c record [<options>] -- <command> [<options>]",
2880 static const char * const *record_mem_usage
= __usage_record
;
2882 static int perf_c2c__record(int argc
, const char **argv
)
2884 int rec_argc
, i
= 0, j
;
2885 const char **rec_argv
;
2887 bool all_user
= false, all_kernel
= false;
2888 bool event_set
= false;
2889 struct option options
[] = {
2890 OPT_CALLBACK('e', "event", &event_set
, "event",
2891 "event selector. Use 'perf mem record -e list' to list available events",
2892 parse_record_events
),
2893 OPT_BOOLEAN('u', "all-user", &all_user
, "collect only user level data"),
2894 OPT_BOOLEAN('k', "all-kernel", &all_kernel
, "collect only kernel level data"),
2895 OPT_UINTEGER('l', "ldlat", &perf_mem_events__loads_ldlat
, "setup mem-loads latency"),
2896 OPT_PARENT(c2c_options
),
2900 if (perf_mem_events__init()) {
2901 pr_err("failed: memory events not supported\n");
2905 argc
= parse_options(argc
, argv
, options
, record_mem_usage
,
2906 PARSE_OPT_KEEP_UNKNOWN
);
2908 rec_argc
= argc
+ 11; /* max number of arguments */
2909 rec_argv
= calloc(rec_argc
+ 1, sizeof(char *));
2913 rec_argv
[i
++] = "record";
2916 perf_mem_events
[PERF_MEM_EVENTS__LOAD
].record
= true;
2917 perf_mem_events
[PERF_MEM_EVENTS__STORE
].record
= true;
2920 if (perf_mem_events
[PERF_MEM_EVENTS__LOAD
].record
)
2921 rec_argv
[i
++] = "-W";
2923 rec_argv
[i
++] = "-d";
2924 rec_argv
[i
++] = "--phys-data";
2925 rec_argv
[i
++] = "--sample-cpu";
2927 for (j
= 0; j
< PERF_MEM_EVENTS__MAX
; j
++) {
2928 if (!perf_mem_events
[j
].record
)
2931 if (!perf_mem_events
[j
].supported
) {
2932 pr_err("failed: event '%s' not supported\n",
2933 perf_mem_events
[j
].name
);
2938 rec_argv
[i
++] = "-e";
2939 rec_argv
[i
++] = perf_mem_events__name(j
);
2943 rec_argv
[i
++] = "--all-user";
2946 rec_argv
[i
++] = "--all-kernel";
2948 for (j
= 0; j
< argc
; j
++, i
++)
2949 rec_argv
[i
] = argv
[j
];
2952 pr_debug("calling: ");
2956 while (rec_argv
[j
]) {
2957 pr_debug("%s ", rec_argv
[j
]);
2963 ret
= cmd_record(i
, rec_argv
);
2968 int cmd_c2c(int argc
, const char **argv
)
2970 argc
= parse_options(argc
, argv
, c2c_options
, c2c_usage
,
2971 PARSE_OPT_STOP_AT_NON_OPTION
);
2974 usage_with_options(c2c_usage
, c2c_options
);
2976 if (!strncmp(argv
[0], "rec", 3)) {
2977 return perf_c2c__record(argc
, argv
);
2978 } else if (!strncmp(argv
[0], "rep", 3)) {
2979 return perf_c2c__report(argc
, argv
);
2981 usage_with_options(c2c_usage
, c2c_options
);