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"
35 #include "ui/browsers/hists.h"
41 struct perf_hpp_list list
;
42 struct c2c_stats stats
;
45 struct compute_stats
{
46 struct stats lcl_hitm
;
47 struct stats rmt_hitm
;
51 struct c2c_hist_entry
{
52 struct c2c_hists
*hists
;
53 struct c2c_stats stats
;
54 unsigned long *cpuset
;
55 struct c2c_stats
*node_stats
;
56 unsigned int cacheline_idx
;
58 struct compute_stats cstats
;
62 * because of its callchain dynamic entry
67 static char const *coalesce_default
= "pid,iaddr";
70 struct perf_tool tool
;
71 struct c2c_hists hists
;
73 unsigned long **nodes
;
85 /* HITM shared clines stats */
86 struct c2c_stats hitm_stats
;
104 static const char *display_str
[DISPLAY_MAX
] = {
105 [DISPLAY_LCL
] = "Local",
106 [DISPLAY_RMT
] = "Remote",
107 [DISPLAY_TOT
] = "Total",
110 static const struct option c2c_options
[] = {
111 OPT_INCR('v', "verbose", &verbose
, "be more verbose (show counter open errors, etc)"),
115 static struct perf_c2c c2c
;
117 static void *c2c_he_zalloc(size_t size
)
119 struct c2c_hist_entry
*c2c_he
;
121 c2c_he
= zalloc(size
+ sizeof(*c2c_he
));
125 c2c_he
->cpuset
= bitmap_alloc(c2c
.cpus_cnt
);
129 c2c_he
->node_stats
= zalloc(c2c
.nodes_cnt
* sizeof(*c2c_he
->node_stats
));
130 if (!c2c_he
->node_stats
)
133 init_stats(&c2c_he
->cstats
.lcl_hitm
);
134 init_stats(&c2c_he
->cstats
.rmt_hitm
);
135 init_stats(&c2c_he
->cstats
.load
);
140 static void c2c_he_free(void *he
)
142 struct c2c_hist_entry
*c2c_he
;
144 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
146 hists__delete_entries(&c2c_he
->hists
->hists
);
150 free(c2c_he
->cpuset
);
151 free(c2c_he
->node_stats
);
155 static struct hist_entry_ops c2c_entry_ops
= {
156 .new = c2c_he_zalloc
,
160 static int c2c_hists__init(struct c2c_hists
*hists
,
162 int nr_header_lines
);
164 static struct c2c_hists
*
165 he__get_c2c_hists(struct hist_entry
*he
,
169 struct c2c_hist_entry
*c2c_he
;
170 struct c2c_hists
*hists
;
173 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
175 return c2c_he
->hists
;
177 hists
= c2c_he
->hists
= zalloc(sizeof(*hists
));
181 ret
= c2c_hists__init(hists
, sort
, nr_header_lines
);
190 static void c2c_he__set_cpu(struct c2c_hist_entry
*c2c_he
,
191 struct perf_sample
*sample
)
193 if (WARN_ONCE(sample
->cpu
== (unsigned int) -1,
194 "WARNING: no sample cpu value"))
197 set_bit(sample
->cpu
, c2c_he
->cpuset
);
200 static void compute_stats(struct c2c_hist_entry
*c2c_he
,
201 struct c2c_stats
*stats
,
204 struct compute_stats
*cstats
= &c2c_he
->cstats
;
207 update_stats(&cstats
->rmt_hitm
, weight
);
208 else if (stats
->lcl_hitm
)
209 update_stats(&cstats
->lcl_hitm
, weight
);
210 else if (stats
->load
)
211 update_stats(&cstats
->load
, weight
);
214 static int process_sample_event(struct perf_tool
*tool __maybe_unused
,
215 union perf_event
*event
,
216 struct perf_sample
*sample
,
217 struct perf_evsel
*evsel
,
218 struct machine
*machine
)
220 struct c2c_hists
*c2c_hists
= &c2c
.hists
;
221 struct c2c_hist_entry
*c2c_he
;
222 struct c2c_stats stats
= { .nr_entries
= 0, };
223 struct hist_entry
*he
;
224 struct addr_location al
;
225 struct mem_info
*mi
, *mi_dup
;
228 if (machine__resolve(machine
, &al
, sample
) < 0) {
229 pr_debug("problem processing %d event, skipping it.\n",
234 ret
= sample__resolve_callchain(sample
, &callchain_cursor
, NULL
,
235 evsel
, &al
, sysctl_perf_event_max_stack
);
239 mi
= sample__resolve_mem(sample
, &al
);
243 mi_dup
= memdup(mi
, sizeof(*mi
));
247 c2c_decode_stats(&stats
, mi
);
249 he
= hists__add_entry_ops(&c2c_hists
->hists
, &c2c_entry_ops
,
255 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
256 c2c_add_stats(&c2c_he
->stats
, &stats
);
257 c2c_add_stats(&c2c_hists
->stats
, &stats
);
259 c2c_he__set_cpu(c2c_he
, sample
);
261 hists__inc_nr_samples(&c2c_hists
->hists
, he
->filtered
);
262 ret
= hist_entry__append_callchain(he
, sample
);
266 * There's already been warning about missing
267 * sample's cpu value. Let's account all to
268 * node 0 in this case, without any further
271 * Doing node stats only for single callchain data.
273 int cpu
= sample
->cpu
== (unsigned int) -1 ? 0 : sample
->cpu
;
274 int node
= c2c
.cpu2node
[cpu
];
278 mi_dup
= memdup(mi
, sizeof(*mi
));
282 c2c_hists
= he__get_c2c_hists(he
, c2c
.cl_sort
, 2);
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
);
295 c2c_add_stats(&c2c_he
->node_stats
[node
], &stats
);
297 compute_stats(c2c_he
, &stats
, sample
->weight
);
299 c2c_he__set_cpu(c2c_he
, sample
);
301 hists__inc_nr_samples(&c2c_hists
->hists
, he
->filtered
);
302 ret
= hist_entry__append_callchain(he
, sample
);
306 addr_location__put(&al
);
317 static struct perf_c2c c2c
= {
319 .sample
= process_sample_event
,
320 .mmap
= perf_event__process_mmap
,
321 .mmap2
= perf_event__process_mmap2
,
322 .comm
= perf_event__process_comm
,
323 .exit
= perf_event__process_exit
,
324 .fork
= perf_event__process_fork
,
325 .lost
= perf_event__process_lost
,
326 .ordered_events
= true,
327 .ordering_requires_timestamps
= true,
331 static const char * const c2c_usage
[] = {
332 "perf c2c {record|report}",
336 static const char * const __usage_report
[] = {
341 static const char * const *report_c2c_usage
= __usage_report
;
343 #define C2C_HEADER_MAX 2
349 } line
[C2C_HEADER_MAX
];
352 struct c2c_dimension
{
353 struct c2c_header header
;
356 struct sort_entry
*se
;
358 int64_t (*cmp
)(struct perf_hpp_fmt
*fmt
,
359 struct hist_entry
*, struct hist_entry
*);
360 int (*entry
)(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
361 struct hist_entry
*he
);
362 int (*color
)(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
363 struct hist_entry
*he
);
367 struct perf_hpp_fmt fmt
;
368 struct c2c_dimension
*dim
;
371 #define SYMBOL_WIDTH 30
373 static struct c2c_dimension dim_symbol
;
374 static struct c2c_dimension dim_srcline
;
376 static int symbol_width(struct hists
*hists
, struct sort_entry
*se
)
378 int width
= hists__col_len(hists
, se
->se_width_idx
);
380 if (!c2c
.symbol_full
)
381 width
= MIN(width
, SYMBOL_WIDTH
);
386 static int c2c_width(struct perf_hpp_fmt
*fmt
,
387 struct perf_hpp
*hpp __maybe_unused
,
390 struct c2c_fmt
*c2c_fmt
;
391 struct c2c_dimension
*dim
;
393 c2c_fmt
= container_of(fmt
, struct c2c_fmt
, fmt
);
396 if (dim
== &dim_symbol
|| dim
== &dim_srcline
)
397 return symbol_width(hists
, dim
->se
);
399 return dim
->se
? hists__col_len(hists
, dim
->se
->se_width_idx
) :
403 static int c2c_header(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
404 struct hists
*hists
, int line
, int *span
)
406 struct perf_hpp_list
*hpp_list
= hists
->hpp_list
;
407 struct c2c_fmt
*c2c_fmt
;
408 struct c2c_dimension
*dim
;
409 const char *text
= NULL
;
410 int width
= c2c_width(fmt
, hpp
, hists
);
412 c2c_fmt
= container_of(fmt
, struct c2c_fmt
, fmt
);
416 text
= dim
->header
.line
[line
].text
;
417 /* Use the last line from sort_entry if not defined. */
418 if (!text
&& (line
== hpp_list
->nr_header_lines
- 1))
419 text
= dim
->se
->se_header
;
421 text
= dim
->header
.line
[line
].text
;
427 *span
= dim
->header
.line
[line
].span
;
434 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, text
);
437 #define HEX_STR(__s, __v) \
439 scnprintf(__s, sizeof(__s), "0x%" PRIx64, __v); \
444 dcacheline_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
445 struct hist_entry
*left
, struct hist_entry
*right
)
447 return sort__dcacheline_cmp(left
, right
);
450 static int dcacheline_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
451 struct hist_entry
*he
)
454 int width
= c2c_width(fmt
, hpp
, he
->hists
);
458 addr
= cl_address(he
->mem_info
->daddr
.addr
);
460 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, HEX_STR(buf
, addr
));
463 static int offset_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
464 struct hist_entry
*he
)
467 int width
= c2c_width(fmt
, hpp
, he
->hists
);
471 addr
= cl_offset(he
->mem_info
->daddr
.al_addr
);
473 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, HEX_STR(buf
, addr
));
477 offset_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
478 struct hist_entry
*left
, struct hist_entry
*right
)
480 uint64_t l
= 0, r
= 0;
483 l
= cl_offset(left
->mem_info
->daddr
.addr
);
485 r
= cl_offset(right
->mem_info
->daddr
.addr
);
487 return (int64_t)(r
- l
);
491 iaddr_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
492 struct hist_entry
*he
)
495 int width
= c2c_width(fmt
, hpp
, he
->hists
);
499 addr
= he
->mem_info
->iaddr
.addr
;
501 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, HEX_STR(buf
, addr
));
505 iaddr_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
506 struct hist_entry
*left
, struct hist_entry
*right
)
508 return sort__iaddr_cmp(left
, right
);
512 tot_hitm_entry(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
);
517 unsigned int tot_hitm
;
519 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
520 tot_hitm
= c2c_he
->stats
.lcl_hitm
+ c2c_he
->stats
.rmt_hitm
;
522 return scnprintf(hpp
->buf
, hpp
->size
, "%*u", width
, tot_hitm
);
526 tot_hitm_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
527 struct hist_entry
*left
, struct hist_entry
*right
)
529 struct c2c_hist_entry
*c2c_left
;
530 struct c2c_hist_entry
*c2c_right
;
531 unsigned int tot_hitm_left
;
532 unsigned int tot_hitm_right
;
534 c2c_left
= container_of(left
, struct c2c_hist_entry
, he
);
535 c2c_right
= container_of(right
, struct c2c_hist_entry
, he
);
537 tot_hitm_left
= c2c_left
->stats
.lcl_hitm
+ c2c_left
->stats
.rmt_hitm
;
538 tot_hitm_right
= c2c_right
->stats
.lcl_hitm
+ c2c_right
->stats
.rmt_hitm
;
540 return tot_hitm_left
- tot_hitm_right
;
543 #define STAT_FN_ENTRY(__f) \
545 __f ## _entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, \
546 struct hist_entry *he) \
548 struct c2c_hist_entry *c2c_he; \
549 int width = c2c_width(fmt, hpp, he->hists); \
551 c2c_he = container_of(he, struct c2c_hist_entry, he); \
552 return scnprintf(hpp->buf, hpp->size, "%*u", width, \
553 c2c_he->stats.__f); \
556 #define STAT_FN_CMP(__f) \
558 __f ## _cmp(struct perf_hpp_fmt *fmt __maybe_unused, \
559 struct hist_entry *left, struct hist_entry *right) \
561 struct c2c_hist_entry *c2c_left, *c2c_right; \
563 c2c_left = container_of(left, struct c2c_hist_entry, he); \
564 c2c_right = container_of(right, struct c2c_hist_entry, he); \
565 return c2c_left->stats.__f - c2c_right->stats.__f; \
568 #define STAT_FN(__f) \
583 static uint64_t llc_miss(struct c2c_stats
*stats
)
587 llcmiss
= stats
->lcl_dram
+
596 ld_llcmiss_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
597 struct hist_entry
*he
)
599 struct c2c_hist_entry
*c2c_he
;
600 int width
= c2c_width(fmt
, hpp
, he
->hists
);
602 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
604 return scnprintf(hpp
->buf
, hpp
->size
, "%*lu", width
,
605 llc_miss(&c2c_he
->stats
));
609 ld_llcmiss_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
610 struct hist_entry
*left
, struct hist_entry
*right
)
612 struct c2c_hist_entry
*c2c_left
;
613 struct c2c_hist_entry
*c2c_right
;
615 c2c_left
= container_of(left
, struct c2c_hist_entry
, he
);
616 c2c_right
= container_of(right
, struct c2c_hist_entry
, he
);
618 return llc_miss(&c2c_left
->stats
) - llc_miss(&c2c_right
->stats
);
621 static uint64_t total_records(struct c2c_stats
*stats
)
623 uint64_t lclmiss
, ldcnt
, total
;
625 lclmiss
= stats
->lcl_dram
+
645 tot_recs_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
646 struct hist_entry
*he
)
648 struct c2c_hist_entry
*c2c_he
;
649 int width
= c2c_width(fmt
, hpp
, he
->hists
);
652 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
653 tot_recs
= total_records(&c2c_he
->stats
);
655 return scnprintf(hpp
->buf
, hpp
->size
, "%*" PRIu64
, width
, tot_recs
);
659 tot_recs_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
660 struct hist_entry
*left
, struct hist_entry
*right
)
662 struct c2c_hist_entry
*c2c_left
;
663 struct c2c_hist_entry
*c2c_right
;
664 uint64_t tot_recs_left
;
665 uint64_t tot_recs_right
;
667 c2c_left
= container_of(left
, struct c2c_hist_entry
, he
);
668 c2c_right
= container_of(right
, struct c2c_hist_entry
, he
);
670 tot_recs_left
= total_records(&c2c_left
->stats
);
671 tot_recs_right
= total_records(&c2c_right
->stats
);
673 return tot_recs_left
- tot_recs_right
;
676 static uint64_t total_loads(struct c2c_stats
*stats
)
678 uint64_t lclmiss
, ldcnt
;
680 lclmiss
= stats
->lcl_dram
+
696 tot_loads_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
697 struct hist_entry
*he
)
699 struct c2c_hist_entry
*c2c_he
;
700 int width
= c2c_width(fmt
, hpp
, he
->hists
);
703 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
704 tot_recs
= total_loads(&c2c_he
->stats
);
706 return scnprintf(hpp
->buf
, hpp
->size
, "%*" PRIu64
, width
, tot_recs
);
710 tot_loads_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
711 struct hist_entry
*left
, struct hist_entry
*right
)
713 struct c2c_hist_entry
*c2c_left
;
714 struct c2c_hist_entry
*c2c_right
;
715 uint64_t tot_recs_left
;
716 uint64_t tot_recs_right
;
718 c2c_left
= container_of(left
, struct c2c_hist_entry
, he
);
719 c2c_right
= container_of(right
, struct c2c_hist_entry
, he
);
721 tot_recs_left
= total_loads(&c2c_left
->stats
);
722 tot_recs_right
= total_loads(&c2c_right
->stats
);
724 return tot_recs_left
- tot_recs_right
;
727 typedef double (get_percent_cb
)(struct c2c_hist_entry
*);
730 percent_color(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
731 struct hist_entry
*he
, get_percent_cb get_percent
)
733 struct c2c_hist_entry
*c2c_he
;
734 int width
= c2c_width(fmt
, hpp
, he
->hists
);
737 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
738 per
= get_percent(c2c_he
);
740 #ifdef HAVE_SLANG_SUPPORT
742 return __hpp__slsmg_color_printf(hpp
, "%*.2f%%", width
- 1, per
);
744 return hpp_color_scnprintf(hpp
, "%*.2f%%", width
- 1, per
);
747 static double percent_hitm(struct c2c_hist_entry
*c2c_he
)
749 struct c2c_hists
*hists
;
750 struct c2c_stats
*stats
;
751 struct c2c_stats
*total
;
755 hists
= container_of(c2c_he
->he
.hists
, struct c2c_hists
, hists
);
756 stats
= &c2c_he
->stats
;
757 total
= &hists
->stats
;
759 switch (c2c
.display
) {
761 st
= stats
->rmt_hitm
;
762 tot
= total
->rmt_hitm
;
765 st
= stats
->lcl_hitm
;
766 tot
= total
->lcl_hitm
;
769 st
= stats
->tot_hitm
;
770 tot
= total
->tot_hitm
;
775 p
= tot
? (double) st
/ tot
: 0;
780 #define PERC_STR(__s, __v) \
782 scnprintf(__s, sizeof(__s), "%.2F%%", __v); \
787 percent_hitm_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
788 struct hist_entry
*he
)
790 struct c2c_hist_entry
*c2c_he
;
791 int width
= c2c_width(fmt
, hpp
, he
->hists
);
795 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
796 per
= percent_hitm(c2c_he
);
797 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, PERC_STR(buf
, per
));
801 percent_hitm_color(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
802 struct hist_entry
*he
)
804 return percent_color(fmt
, hpp
, he
, percent_hitm
);
808 percent_hitm_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
809 struct hist_entry
*left
, struct hist_entry
*right
)
811 struct c2c_hist_entry
*c2c_left
;
812 struct c2c_hist_entry
*c2c_right
;
816 c2c_left
= container_of(left
, struct c2c_hist_entry
, he
);
817 c2c_right
= container_of(right
, struct c2c_hist_entry
, he
);
819 per_left
= percent_hitm(c2c_left
);
820 per_right
= percent_hitm(c2c_right
);
822 return per_left
- per_right
;
825 static struct c2c_stats
*he_stats(struct hist_entry
*he
)
827 struct c2c_hist_entry
*c2c_he
;
829 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
830 return &c2c_he
->stats
;
833 static struct c2c_stats
*total_stats(struct hist_entry
*he
)
835 struct c2c_hists
*hists
;
837 hists
= container_of(he
->hists
, struct c2c_hists
, hists
);
838 return &hists
->stats
;
841 static double percent(int st
, int tot
)
843 return tot
? 100. * (double) st
/ (double) tot
: 0;
846 #define PERCENT(__h, __f) percent(he_stats(__h)->__f, total_stats(__h)->__f)
848 #define PERCENT_FN(__f) \
849 static double percent_ ## __f(struct c2c_hist_entry *c2c_he) \
851 struct c2c_hists *hists; \
853 hists = container_of(c2c_he->he.hists, struct c2c_hists, hists); \
854 return percent(c2c_he->stats.__f, hists->stats.__f); \
860 PERCENT_FN(st_l1miss
)
863 percent_rmt_hitm_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
864 struct hist_entry
*he
)
866 int width
= c2c_width(fmt
, hpp
, he
->hists
);
867 double per
= PERCENT(he
, rmt_hitm
);
870 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, PERC_STR(buf
, per
));
874 percent_rmt_hitm_color(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
875 struct hist_entry
*he
)
877 return percent_color(fmt
, hpp
, he
, percent_rmt_hitm
);
881 percent_rmt_hitm_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
882 struct hist_entry
*left
, struct hist_entry
*right
)
887 per_left
= PERCENT(left
, lcl_hitm
);
888 per_right
= PERCENT(right
, lcl_hitm
);
890 return per_left
- per_right
;
894 percent_lcl_hitm_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
895 struct hist_entry
*he
)
897 int width
= c2c_width(fmt
, hpp
, he
->hists
);
898 double per
= PERCENT(he
, lcl_hitm
);
901 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, PERC_STR(buf
, per
));
905 percent_lcl_hitm_color(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
906 struct hist_entry
*he
)
908 return percent_color(fmt
, hpp
, he
, percent_lcl_hitm
);
912 percent_lcl_hitm_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
913 struct hist_entry
*left
, struct hist_entry
*right
)
918 per_left
= PERCENT(left
, lcl_hitm
);
919 per_right
= PERCENT(right
, lcl_hitm
);
921 return per_left
- per_right
;
925 percent_stores_l1hit_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
926 struct hist_entry
*he
)
928 int width
= c2c_width(fmt
, hpp
, he
->hists
);
929 double per
= PERCENT(he
, st_l1hit
);
932 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, PERC_STR(buf
, per
));
936 percent_stores_l1hit_color(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
937 struct hist_entry
*he
)
939 return percent_color(fmt
, hpp
, he
, percent_st_l1hit
);
943 percent_stores_l1hit_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
944 struct hist_entry
*left
, struct hist_entry
*right
)
949 per_left
= PERCENT(left
, st_l1hit
);
950 per_right
= PERCENT(right
, st_l1hit
);
952 return per_left
- per_right
;
956 percent_stores_l1miss_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
957 struct hist_entry
*he
)
959 int width
= c2c_width(fmt
, hpp
, he
->hists
);
960 double per
= PERCENT(he
, st_l1miss
);
963 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, PERC_STR(buf
, per
));
967 percent_stores_l1miss_color(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
968 struct hist_entry
*he
)
970 return percent_color(fmt
, hpp
, he
, percent_st_l1miss
);
974 percent_stores_l1miss_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
975 struct hist_entry
*left
, struct hist_entry
*right
)
980 per_left
= PERCENT(left
, st_l1miss
);
981 per_right
= PERCENT(right
, st_l1miss
);
983 return per_left
- per_right
;
990 pid_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
991 struct hist_entry
*he
)
993 int width
= c2c_width(fmt
, hpp
, he
->hists
);
995 return scnprintf(hpp
->buf
, hpp
->size
, "%*d", width
, he
->thread
->pid_
);
999 pid_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
1000 struct hist_entry
*left
, struct hist_entry
*right
)
1002 return left
->thread
->pid_
- right
->thread
->pid_
;
1006 empty_cmp(struct perf_hpp_fmt
*fmt __maybe_unused
,
1007 struct hist_entry
*left __maybe_unused
,
1008 struct hist_entry
*right __maybe_unused
)
1014 node_entry(struct perf_hpp_fmt
*fmt __maybe_unused
, struct perf_hpp
*hpp
,
1015 struct hist_entry
*he
)
1017 struct c2c_hist_entry
*c2c_he
;
1022 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
1024 for (node
= 0; node
< c2c
.nodes_cnt
; node
++) {
1025 DECLARE_BITMAP(set
, c2c
.cpus_cnt
);
1027 bitmap_zero(set
, c2c
.cpus_cnt
);
1028 bitmap_and(set
, c2c_he
->cpuset
, c2c
.nodes
[node
], c2c
.cpus_cnt
);
1030 if (!bitmap_weight(set
, c2c
.cpus_cnt
)) {
1031 if (c2c
.node_info
== 1) {
1032 ret
= scnprintf(hpp
->buf
, hpp
->size
, "%21s", " ");
1033 advance_hpp(hpp
, ret
);
1039 ret
= scnprintf(hpp
->buf
, hpp
->size
, " ");
1040 advance_hpp(hpp
, ret
);
1043 switch (c2c
.node_info
) {
1045 ret
= scnprintf(hpp
->buf
, hpp
->size
, "%2d", node
);
1046 advance_hpp(hpp
, ret
);
1050 int num
= bitmap_weight(c2c_he
->cpuset
, c2c
.cpus_cnt
);
1051 struct c2c_stats
*stats
= &c2c_he
->node_stats
[node
];
1053 ret
= scnprintf(hpp
->buf
, hpp
->size
, "%2d{%2d ", node
, num
);
1054 advance_hpp(hpp
, ret
);
1056 #define DISPLAY_HITM(__h) \
1057 if (c2c_he->stats.__h> 0) { \
1058 ret = scnprintf(hpp->buf, hpp->size, "%5.1f%% ", \
1059 percent(stats->__h, c2c_he->stats.__h));\
1061 ret = scnprintf(hpp->buf, hpp->size, "%6s ", "n/a"); \
1064 switch (c2c
.display
) {
1066 DISPLAY_HITM(rmt_hitm
);
1069 DISPLAY_HITM(lcl_hitm
);
1072 DISPLAY_HITM(tot_hitm
);
1079 advance_hpp(hpp
, ret
);
1081 if (c2c_he
->stats
.store
> 0) {
1082 ret
= scnprintf(hpp
->buf
, hpp
->size
, "%5.1f%%}",
1083 percent(stats
->store
, c2c_he
->stats
.store
));
1085 ret
= scnprintf(hpp
->buf
, hpp
->size
, "%6s}", "n/a");
1088 advance_hpp(hpp
, ret
);
1092 ret
= scnprintf(hpp
->buf
, hpp
->size
, "%2d{", node
);
1093 advance_hpp(hpp
, ret
);
1095 ret
= bitmap_scnprintf(set
, c2c
.cpus_cnt
, hpp
->buf
, hpp
->size
);
1096 advance_hpp(hpp
, ret
);
1098 ret
= scnprintf(hpp
->buf
, hpp
->size
, "}");
1099 advance_hpp(hpp
, ret
);
1112 mean_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
1113 struct hist_entry
*he
, double mean
)
1115 int width
= c2c_width(fmt
, hpp
, he
->hists
);
1118 scnprintf(buf
, 10, "%6.0f", mean
);
1119 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, buf
);
1122 #define MEAN_ENTRY(__func, __val) \
1124 __func(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, struct hist_entry *he) \
1126 struct c2c_hist_entry *c2c_he; \
1127 c2c_he = container_of(he, struct c2c_hist_entry, he); \
1128 return mean_entry(fmt, hpp, he, avg_stats(&c2c_he->cstats.__val)); \
1131 MEAN_ENTRY(mean_rmt_entry
, rmt_hitm
);
1132 MEAN_ENTRY(mean_lcl_entry
, lcl_hitm
);
1133 MEAN_ENTRY(mean_load_entry
, load
);
1136 cpucnt_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
1137 struct hist_entry
*he
)
1139 struct c2c_hist_entry
*c2c_he
;
1140 int width
= c2c_width(fmt
, hpp
, he
->hists
);
1143 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
1145 scnprintf(buf
, 10, "%d", bitmap_weight(c2c_he
->cpuset
, c2c
.cpus_cnt
));
1146 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, buf
);
1150 cl_idx_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
1151 struct hist_entry
*he
)
1153 struct c2c_hist_entry
*c2c_he
;
1154 int width
= c2c_width(fmt
, hpp
, he
->hists
);
1157 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
1159 scnprintf(buf
, 10, "%u", c2c_he
->cacheline_idx
);
1160 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, buf
);
1164 cl_idx_empty_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
1165 struct hist_entry
*he
)
1167 int width
= c2c_width(fmt
, hpp
, he
->hists
);
1169 return scnprintf(hpp
->buf
, hpp
->size
, "%*s", width
, "");
1172 #define HEADER_LOW(__h) \
1179 #define HEADER_BOTH(__h0, __h1) \
1189 #define HEADER_SPAN(__h0, __h1, __s) \
1200 #define HEADER_SPAN_LOW(__h) \
1207 static struct c2c_dimension dim_dcacheline
= {
1208 .header
= HEADER_LOW("Cacheline"),
1209 .name
= "dcacheline",
1210 .cmp
= dcacheline_cmp
,
1211 .entry
= dcacheline_entry
,
1215 static struct c2c_header header_offset_tui
= HEADER_LOW("Off");
1217 static struct c2c_dimension dim_offset
= {
1218 .header
= HEADER_BOTH("Data address", "Offset"),
1221 .entry
= offset_entry
,
1225 static struct c2c_dimension dim_iaddr
= {
1226 .header
= HEADER_LOW("Code address"),
1229 .entry
= iaddr_entry
,
1233 static struct c2c_dimension dim_tot_hitm
= {
1234 .header
= HEADER_SPAN("----- LLC Load Hitm -----", "Total", 2),
1236 .cmp
= tot_hitm_cmp
,
1237 .entry
= tot_hitm_entry
,
1241 static struct c2c_dimension dim_lcl_hitm
= {
1242 .header
= HEADER_SPAN_LOW("Lcl"),
1244 .cmp
= lcl_hitm_cmp
,
1245 .entry
= lcl_hitm_entry
,
1249 static struct c2c_dimension dim_rmt_hitm
= {
1250 .header
= HEADER_SPAN_LOW("Rmt"),
1252 .cmp
= rmt_hitm_cmp
,
1253 .entry
= rmt_hitm_entry
,
1257 static struct c2c_dimension dim_cl_rmt_hitm
= {
1258 .header
= HEADER_SPAN("----- HITM -----", "Rmt", 1),
1259 .name
= "cl_rmt_hitm",
1260 .cmp
= rmt_hitm_cmp
,
1261 .entry
= rmt_hitm_entry
,
1265 static struct c2c_dimension dim_cl_lcl_hitm
= {
1266 .header
= HEADER_SPAN_LOW("Lcl"),
1267 .name
= "cl_lcl_hitm",
1268 .cmp
= lcl_hitm_cmp
,
1269 .entry
= lcl_hitm_entry
,
1273 static struct c2c_dimension dim_stores
= {
1274 .header
= HEADER_SPAN("---- Store Reference ----", "Total", 2),
1277 .entry
= store_entry
,
1281 static struct c2c_dimension dim_stores_l1hit
= {
1282 .header
= HEADER_SPAN_LOW("L1Hit"),
1283 .name
= "stores_l1hit",
1284 .cmp
= st_l1hit_cmp
,
1285 .entry
= st_l1hit_entry
,
1289 static struct c2c_dimension dim_stores_l1miss
= {
1290 .header
= HEADER_SPAN_LOW("L1Miss"),
1291 .name
= "stores_l1miss",
1292 .cmp
= st_l1miss_cmp
,
1293 .entry
= st_l1miss_entry
,
1297 static struct c2c_dimension dim_cl_stores_l1hit
= {
1298 .header
= HEADER_SPAN("-- Store Refs --", "L1 Hit", 1),
1299 .name
= "cl_stores_l1hit",
1300 .cmp
= st_l1hit_cmp
,
1301 .entry
= st_l1hit_entry
,
1305 static struct c2c_dimension dim_cl_stores_l1miss
= {
1306 .header
= HEADER_SPAN_LOW("L1 Miss"),
1307 .name
= "cl_stores_l1miss",
1308 .cmp
= st_l1miss_cmp
,
1309 .entry
= st_l1miss_entry
,
1313 static struct c2c_dimension dim_ld_fbhit
= {
1314 .header
= HEADER_SPAN("----- Core Load Hit -----", "FB", 2),
1316 .cmp
= ld_fbhit_cmp
,
1317 .entry
= ld_fbhit_entry
,
1321 static struct c2c_dimension dim_ld_l1hit
= {
1322 .header
= HEADER_SPAN_LOW("L1"),
1324 .cmp
= ld_l1hit_cmp
,
1325 .entry
= ld_l1hit_entry
,
1329 static struct c2c_dimension dim_ld_l2hit
= {
1330 .header
= HEADER_SPAN_LOW("L2"),
1332 .cmp
= ld_l2hit_cmp
,
1333 .entry
= ld_l2hit_entry
,
1337 static struct c2c_dimension dim_ld_llchit
= {
1338 .header
= HEADER_SPAN("-- LLC Load Hit --", "Llc", 1),
1339 .name
= "ld_lclhit",
1340 .cmp
= ld_llchit_cmp
,
1341 .entry
= ld_llchit_entry
,
1345 static struct c2c_dimension dim_ld_rmthit
= {
1346 .header
= HEADER_SPAN_LOW("Rmt"),
1347 .name
= "ld_rmthit",
1349 .entry
= rmt_hit_entry
,
1353 static struct c2c_dimension dim_ld_llcmiss
= {
1354 .header
= HEADER_BOTH("LLC", "Ld Miss"),
1355 .name
= "ld_llcmiss",
1356 .cmp
= ld_llcmiss_cmp
,
1357 .entry
= ld_llcmiss_entry
,
1361 static struct c2c_dimension dim_tot_recs
= {
1362 .header
= HEADER_BOTH("Total", "records"),
1364 .cmp
= tot_recs_cmp
,
1365 .entry
= tot_recs_entry
,
1369 static struct c2c_dimension dim_tot_loads
= {
1370 .header
= HEADER_BOTH("Total", "Loads"),
1371 .name
= "tot_loads",
1372 .cmp
= tot_loads_cmp
,
1373 .entry
= tot_loads_entry
,
1377 static struct c2c_header percent_hitm_header
[] = {
1378 [DISPLAY_LCL
] = HEADER_BOTH("Lcl", "Hitm"),
1379 [DISPLAY_RMT
] = HEADER_BOTH("Rmt", "Hitm"),
1380 [DISPLAY_TOT
] = HEADER_BOTH("Tot", "Hitm"),
1383 static struct c2c_dimension dim_percent_hitm
= {
1384 .name
= "percent_hitm",
1385 .cmp
= percent_hitm_cmp
,
1386 .entry
= percent_hitm_entry
,
1387 .color
= percent_hitm_color
,
1391 static struct c2c_dimension dim_percent_rmt_hitm
= {
1392 .header
= HEADER_SPAN("----- HITM -----", "Rmt", 1),
1393 .name
= "percent_rmt_hitm",
1394 .cmp
= percent_rmt_hitm_cmp
,
1395 .entry
= percent_rmt_hitm_entry
,
1396 .color
= percent_rmt_hitm_color
,
1400 static struct c2c_dimension dim_percent_lcl_hitm
= {
1401 .header
= HEADER_SPAN_LOW("Lcl"),
1402 .name
= "percent_lcl_hitm",
1403 .cmp
= percent_lcl_hitm_cmp
,
1404 .entry
= percent_lcl_hitm_entry
,
1405 .color
= percent_lcl_hitm_color
,
1409 static struct c2c_dimension dim_percent_stores_l1hit
= {
1410 .header
= HEADER_SPAN("-- Store Refs --", "L1 Hit", 1),
1411 .name
= "percent_stores_l1hit",
1412 .cmp
= percent_stores_l1hit_cmp
,
1413 .entry
= percent_stores_l1hit_entry
,
1414 .color
= percent_stores_l1hit_color
,
1418 static struct c2c_dimension dim_percent_stores_l1miss
= {
1419 .header
= HEADER_SPAN_LOW("L1 Miss"),
1420 .name
= "percent_stores_l1miss",
1421 .cmp
= percent_stores_l1miss_cmp
,
1422 .entry
= percent_stores_l1miss_entry
,
1423 .color
= percent_stores_l1miss_color
,
1427 static struct c2c_dimension dim_dram_lcl
= {
1428 .header
= HEADER_SPAN("--- Load Dram ----", "Lcl", 1),
1430 .cmp
= lcl_dram_cmp
,
1431 .entry
= lcl_dram_entry
,
1435 static struct c2c_dimension dim_dram_rmt
= {
1436 .header
= HEADER_SPAN_LOW("Rmt"),
1438 .cmp
= rmt_dram_cmp
,
1439 .entry
= rmt_dram_entry
,
1443 static struct c2c_dimension dim_pid
= {
1444 .header
= HEADER_LOW("Pid"),
1451 static struct c2c_dimension dim_tid
= {
1452 .header
= HEADER_LOW("Tid"),
1457 static struct c2c_dimension dim_symbol
= {
1462 static struct c2c_dimension dim_dso
= {
1463 .header
= HEADER_BOTH("Shared", "Object"),
1468 static struct c2c_header header_node
[3] = {
1470 HEADER_LOW("Node{cpus %hitms %stores}"),
1471 HEADER_LOW("Node{cpu list}"),
1474 static struct c2c_dimension dim_node
= {
1477 .entry
= node_entry
,
1481 static struct c2c_dimension dim_mean_rmt
= {
1482 .header
= HEADER_SPAN("---------- cycles ----------", "rmt hitm", 2),
1485 .entry
= mean_rmt_entry
,
1489 static struct c2c_dimension dim_mean_lcl
= {
1490 .header
= HEADER_SPAN_LOW("lcl hitm"),
1493 .entry
= mean_lcl_entry
,
1497 static struct c2c_dimension dim_mean_load
= {
1498 .header
= HEADER_SPAN_LOW("load"),
1499 .name
= "mean_load",
1501 .entry
= mean_load_entry
,
1505 static struct c2c_dimension dim_cpucnt
= {
1506 .header
= HEADER_BOTH("cpu", "cnt"),
1509 .entry
= cpucnt_entry
,
1513 static struct c2c_dimension dim_srcline
= {
1514 .name
= "cl_srcline",
1515 .se
= &sort_srcline
,
1518 static struct c2c_dimension dim_dcacheline_idx
= {
1519 .header
= HEADER_LOW("Index"),
1522 .entry
= cl_idx_entry
,
1526 static struct c2c_dimension dim_dcacheline_num
= {
1527 .header
= HEADER_LOW("Num"),
1530 .entry
= cl_idx_entry
,
1534 static struct c2c_dimension dim_dcacheline_num_empty
= {
1535 .header
= HEADER_LOW("Num"),
1536 .name
= "cl_num_empty",
1538 .entry
= cl_idx_empty_entry
,
1542 static struct c2c_dimension
*dimensions
[] = {
1554 &dim_cl_stores_l1hit
,
1555 &dim_cl_stores_l1miss
,
1565 &dim_percent_rmt_hitm
,
1566 &dim_percent_lcl_hitm
,
1567 &dim_percent_stores_l1hit
,
1568 &dim_percent_stores_l1miss
,
1581 &dim_dcacheline_idx
,
1582 &dim_dcacheline_num
,
1583 &dim_dcacheline_num_empty
,
1587 static void fmt_free(struct perf_hpp_fmt
*fmt
)
1589 struct c2c_fmt
*c2c_fmt
;
1591 c2c_fmt
= container_of(fmt
, struct c2c_fmt
, fmt
);
1595 static bool fmt_equal(struct perf_hpp_fmt
*a
, struct perf_hpp_fmt
*b
)
1597 struct c2c_fmt
*c2c_a
= container_of(a
, struct c2c_fmt
, fmt
);
1598 struct c2c_fmt
*c2c_b
= container_of(b
, struct c2c_fmt
, fmt
);
1600 return c2c_a
->dim
== c2c_b
->dim
;
1603 static struct c2c_dimension
*get_dimension(const char *name
)
1607 for (i
= 0; dimensions
[i
]; i
++) {
1608 struct c2c_dimension
*dim
= dimensions
[i
];
1610 if (!strcmp(dim
->name
, name
))
1617 static int c2c_se_entry(struct perf_hpp_fmt
*fmt
, struct perf_hpp
*hpp
,
1618 struct hist_entry
*he
)
1620 struct c2c_fmt
*c2c_fmt
= container_of(fmt
, struct c2c_fmt
, fmt
);
1621 struct c2c_dimension
*dim
= c2c_fmt
->dim
;
1622 size_t len
= fmt
->user_len
;
1625 len
= hists__col_len(he
->hists
, dim
->se
->se_width_idx
);
1627 if (dim
== &dim_symbol
|| dim
== &dim_srcline
)
1628 len
= symbol_width(he
->hists
, dim
->se
);
1631 return dim
->se
->se_snprintf(he
, hpp
->buf
, hpp
->size
, len
);
1634 static int64_t c2c_se_cmp(struct perf_hpp_fmt
*fmt
,
1635 struct hist_entry
*a
, struct hist_entry
*b
)
1637 struct c2c_fmt
*c2c_fmt
= container_of(fmt
, struct c2c_fmt
, fmt
);
1638 struct c2c_dimension
*dim
= c2c_fmt
->dim
;
1640 return dim
->se
->se_cmp(a
, b
);
1643 static int64_t c2c_se_collapse(struct perf_hpp_fmt
*fmt
,
1644 struct hist_entry
*a
, struct hist_entry
*b
)
1646 struct c2c_fmt
*c2c_fmt
= container_of(fmt
, struct c2c_fmt
, fmt
);
1647 struct c2c_dimension
*dim
= c2c_fmt
->dim
;
1648 int64_t (*collapse_fn
)(struct hist_entry
*, struct hist_entry
*);
1650 collapse_fn
= dim
->se
->se_collapse
?: dim
->se
->se_cmp
;
1651 return collapse_fn(a
, b
);
1654 static struct c2c_fmt
*get_format(const char *name
)
1656 struct c2c_dimension
*dim
= get_dimension(name
);
1657 struct c2c_fmt
*c2c_fmt
;
1658 struct perf_hpp_fmt
*fmt
;
1663 c2c_fmt
= zalloc(sizeof(*c2c_fmt
));
1669 fmt
= &c2c_fmt
->fmt
;
1670 INIT_LIST_HEAD(&fmt
->list
);
1671 INIT_LIST_HEAD(&fmt
->sort_list
);
1673 fmt
->cmp
= dim
->se
? c2c_se_cmp
: dim
->cmp
;
1674 fmt
->sort
= dim
->se
? c2c_se_cmp
: dim
->cmp
;
1675 fmt
->color
= dim
->se
? NULL
: dim
->color
;
1676 fmt
->entry
= dim
->se
? c2c_se_entry
: dim
->entry
;
1677 fmt
->header
= c2c_header
;
1678 fmt
->width
= c2c_width
;
1679 fmt
->collapse
= dim
->se
? c2c_se_collapse
: dim
->cmp
;
1680 fmt
->equal
= fmt_equal
;
1681 fmt
->free
= fmt_free
;
1686 static int c2c_hists__init_output(struct perf_hpp_list
*hpp_list
, char *name
)
1688 struct c2c_fmt
*c2c_fmt
= get_format(name
);
1692 return output_field_add(hpp_list
, name
);
1695 perf_hpp_list__column_register(hpp_list
, &c2c_fmt
->fmt
);
1699 static int c2c_hists__init_sort(struct perf_hpp_list
*hpp_list
, char *name
)
1701 struct c2c_fmt
*c2c_fmt
= get_format(name
);
1702 struct c2c_dimension
*dim
;
1706 return sort_dimension__add(hpp_list
, name
, NULL
, 0);
1710 if (dim
== &dim_dso
)
1713 perf_hpp_list__register_sort_field(hpp_list
, &c2c_fmt
->fmt
);
1717 #define PARSE_LIST(_list, _fn) \
1725 for (tok = strtok_r((char *)_list, ", ", &tmp); \
1726 tok; tok = strtok_r(NULL, ", ", &tmp)) { \
1727 ret = _fn(hpp_list, tok); \
1728 if (ret == -EINVAL) { \
1729 pr_err("Invalid --fields key: `%s'", tok); \
1731 } else if (ret == -ESRCH) { \
1732 pr_err("Unknown --fields key: `%s'", tok); \
1738 static int hpp_list__parse(struct perf_hpp_list
*hpp_list
,
1739 const char *output_
,
1742 char *output
= output_
? strdup(output_
) : NULL
;
1743 char *sort
= sort_
? strdup(sort_
) : NULL
;
1746 PARSE_LIST(output
, c2c_hists__init_output
);
1747 PARSE_LIST(sort
, c2c_hists__init_sort
);
1749 /* copy sort keys to output fields */
1750 perf_hpp__setup_output_field(hpp_list
);
1753 * We dont need other sorting keys other than those
1754 * we already specified. It also really slows down
1755 * the processing a lot with big number of output
1756 * fields, so switching this off for c2c.
1760 /* and then copy output fields to sort keys */
1761 perf_hpp__append_sort_keys(&hists
->list
);
1769 static int c2c_hists__init(struct c2c_hists
*hists
,
1771 int nr_header_lines
)
1773 __hists__init(&hists
->hists
, &hists
->list
);
1776 * Initialize only with sort fields, we need to resort
1777 * later anyway, and that's where we add output fields
1780 perf_hpp_list__init(&hists
->list
);
1782 /* Overload number of header lines.*/
1783 hists
->list
.nr_header_lines
= nr_header_lines
;
1785 return hpp_list__parse(&hists
->list
, NULL
, sort
);
1788 static int c2c_hists__reinit(struct c2c_hists
*c2c_hists
,
1792 perf_hpp__reset_output_field(&c2c_hists
->list
);
1793 return hpp_list__parse(&c2c_hists
->list
, output
, sort
);
1796 #define DISPLAY_LINE_LIMIT 0.0005
1798 static bool he__display(struct hist_entry
*he
, struct c2c_stats
*stats
)
1800 struct c2c_hist_entry
*c2c_he
;
1806 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
1808 #define FILTER_HITM(__h) \
1810 ld_dist = ((double)c2c_he->stats.__h / stats->__h); \
1811 if (ld_dist < DISPLAY_LINE_LIMIT) \
1812 he->filtered = HIST_FILTER__C2C; \
1814 he->filtered = HIST_FILTER__C2C; \
1817 switch (c2c
.display
) {
1819 FILTER_HITM(lcl_hitm
);
1822 FILTER_HITM(rmt_hitm
);
1825 FILTER_HITM(tot_hitm
);
1832 return he
->filtered
== 0;
1835 static inline int valid_hitm_or_store(struct hist_entry
*he
)
1837 struct c2c_hist_entry
*c2c_he
;
1840 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
1841 has_hitm
= c2c
.display
== DISPLAY_TOT
? c2c_he
->stats
.tot_hitm
:
1842 c2c
.display
== DISPLAY_LCL
? c2c_he
->stats
.lcl_hitm
:
1843 c2c_he
->stats
.rmt_hitm
;
1844 return has_hitm
|| c2c_he
->stats
.store
;
1847 static void calc_width(struct hist_entry
*he
)
1849 struct c2c_hists
*c2c_hists
;
1851 c2c_hists
= container_of(he
->hists
, struct c2c_hists
, hists
);
1852 hists__calc_col_len(&c2c_hists
->hists
, he
);
1855 static int filter_cb(struct hist_entry
*he
)
1857 if (c2c
.show_src
&& !he
->srcline
)
1858 he
->srcline
= hist_entry__get_srcline(he
);
1862 if (!valid_hitm_or_store(he
))
1863 he
->filtered
= HIST_FILTER__C2C
;
1868 static int resort_cl_cb(struct hist_entry
*he
)
1870 struct c2c_hist_entry
*c2c_he
;
1871 struct c2c_hists
*c2c_hists
;
1872 bool display
= he__display(he
, &c2c
.hitm_stats
);
1874 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
1875 c2c_hists
= c2c_he
->hists
;
1879 if (display
&& c2c_hists
) {
1880 static unsigned int idx
;
1882 c2c_he
->cacheline_idx
= idx
++;
1884 c2c_hists__reinit(c2c_hists
, c2c
.cl_output
, c2c
.cl_resort
);
1886 hists__collapse_resort(&c2c_hists
->hists
, NULL
);
1887 hists__output_resort_cb(&c2c_hists
->hists
, NULL
, filter_cb
);
1893 static void setup_nodes_header(void)
1895 dim_node
.header
= header_node
[c2c
.node_info
];
1898 static int setup_nodes(struct perf_session
*session
)
1900 struct numa_node
*n
;
1901 unsigned long **nodes
;
1905 if (c2c
.node_info
> 2)
1908 c2c
.nodes_cnt
= session
->header
.env
.nr_numa_nodes
;
1909 c2c
.cpus_cnt
= session
->header
.env
.nr_cpus_online
;
1911 n
= session
->header
.env
.numa_nodes
;
1915 nodes
= zalloc(sizeof(unsigned long *) * c2c
.nodes_cnt
);
1921 cpu2node
= zalloc(sizeof(int) * c2c
.cpus_cnt
);
1925 for (cpu
= 0; cpu
< c2c
.cpus_cnt
; cpu
++)
1928 c2c
.cpu2node
= cpu2node
;
1930 for (node
= 0; node
< c2c
.nodes_cnt
; node
++) {
1931 struct cpu_map
*map
= n
[node
].map
;
1934 set
= bitmap_alloc(c2c
.cpus_cnt
);
1938 for (cpu
= 0; cpu
< map
->nr
; cpu
++) {
1939 set_bit(map
->map
[cpu
], set
);
1941 if (WARN_ONCE(cpu2node
[map
->map
[cpu
]] != -1, "node/cpu topology bug"))
1944 cpu2node
[map
->map
[cpu
]] = node
;
1950 setup_nodes_header();
1954 #define HAS_HITMS(__h) ((__h)->stats.lcl_hitm || (__h)->stats.rmt_hitm)
1956 static int resort_hitm_cb(struct hist_entry
*he
)
1958 struct c2c_hist_entry
*c2c_he
;
1959 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
1961 if (HAS_HITMS(c2c_he
)) {
1962 c2c
.shared_clines
++;
1963 c2c_add_stats(&c2c
.hitm_stats
, &c2c_he
->stats
);
1969 static int hists__iterate_cb(struct hists
*hists
, hists__resort_cb_t cb
)
1971 struct rb_node
*next
= rb_first(&hists
->entries
);
1975 struct hist_entry
*he
;
1977 he
= rb_entry(next
, struct hist_entry
, rb_node
);
1981 next
= rb_next(&he
->rb_node
);
1987 static void print_c2c__display_stats(FILE *out
)
1990 struct c2c_stats
*stats
= &c2c
.hists
.stats
;
1992 llc_misses
= stats
->lcl_dram
+
1997 fprintf(out
, "=================================================\n");
1998 fprintf(out
, " Trace Event Information \n");
1999 fprintf(out
, "=================================================\n");
2000 fprintf(out
, " Total records : %10d\n", stats
->nr_entries
);
2001 fprintf(out
, " Locked Load/Store Operations : %10d\n", stats
->locks
);
2002 fprintf(out
, " Load Operations : %10d\n", stats
->load
);
2003 fprintf(out
, " Loads - uncacheable : %10d\n", stats
->ld_uncache
);
2004 fprintf(out
, " Loads - IO : %10d\n", stats
->ld_io
);
2005 fprintf(out
, " Loads - Miss : %10d\n", stats
->ld_miss
);
2006 fprintf(out
, " Loads - no mapping : %10d\n", stats
->ld_noadrs
);
2007 fprintf(out
, " Load Fill Buffer Hit : %10d\n", stats
->ld_fbhit
);
2008 fprintf(out
, " Load L1D hit : %10d\n", stats
->ld_l1hit
);
2009 fprintf(out
, " Load L2D hit : %10d\n", stats
->ld_l2hit
);
2010 fprintf(out
, " Load LLC hit : %10d\n", stats
->ld_llchit
+ stats
->lcl_hitm
);
2011 fprintf(out
, " Load Local HITM : %10d\n", stats
->lcl_hitm
);
2012 fprintf(out
, " Load Remote HITM : %10d\n", stats
->rmt_hitm
);
2013 fprintf(out
, " Load Remote HIT : %10d\n", stats
->rmt_hit
);
2014 fprintf(out
, " Load Local DRAM : %10d\n", stats
->lcl_dram
);
2015 fprintf(out
, " Load Remote DRAM : %10d\n", stats
->rmt_dram
);
2016 fprintf(out
, " Load MESI State Exclusive : %10d\n", stats
->ld_excl
);
2017 fprintf(out
, " Load MESI State Shared : %10d\n", stats
->ld_shared
);
2018 fprintf(out
, " Load LLC Misses : %10d\n", llc_misses
);
2019 fprintf(out
, " LLC Misses to Local DRAM : %10.1f%%\n", ((double)stats
->lcl_dram
/(double)llc_misses
) * 100.);
2020 fprintf(out
, " LLC Misses to Remote DRAM : %10.1f%%\n", ((double)stats
->rmt_dram
/(double)llc_misses
) * 100.);
2021 fprintf(out
, " LLC Misses to Remote cache (HIT) : %10.1f%%\n", ((double)stats
->rmt_hit
/(double)llc_misses
) * 100.);
2022 fprintf(out
, " LLC Misses to Remote cache (HITM) : %10.1f%%\n", ((double)stats
->rmt_hitm
/(double)llc_misses
) * 100.);
2023 fprintf(out
, " Store Operations : %10d\n", stats
->store
);
2024 fprintf(out
, " Store - uncacheable : %10d\n", stats
->st_uncache
);
2025 fprintf(out
, " Store - no mapping : %10d\n", stats
->st_noadrs
);
2026 fprintf(out
, " Store L1D Hit : %10d\n", stats
->st_l1hit
);
2027 fprintf(out
, " Store L1D Miss : %10d\n", stats
->st_l1miss
);
2028 fprintf(out
, " No Page Map Rejects : %10d\n", stats
->nomap
);
2029 fprintf(out
, " Unable to parse data source : %10d\n", stats
->noparse
);
2032 static void print_shared_cacheline_info(FILE *out
)
2034 struct c2c_stats
*stats
= &c2c
.hitm_stats
;
2035 int hitm_cnt
= stats
->lcl_hitm
+ stats
->rmt_hitm
;
2037 fprintf(out
, "=================================================\n");
2038 fprintf(out
, " Global Shared Cache Line Event Information \n");
2039 fprintf(out
, "=================================================\n");
2040 fprintf(out
, " Total Shared Cache Lines : %10d\n", c2c
.shared_clines
);
2041 fprintf(out
, " Load HITs on shared lines : %10d\n", stats
->load
);
2042 fprintf(out
, " Fill Buffer Hits on shared lines : %10d\n", stats
->ld_fbhit
);
2043 fprintf(out
, " L1D hits on shared lines : %10d\n", stats
->ld_l1hit
);
2044 fprintf(out
, " L2D hits on shared lines : %10d\n", stats
->ld_l2hit
);
2045 fprintf(out
, " LLC hits on shared lines : %10d\n", stats
->ld_llchit
+ stats
->lcl_hitm
);
2046 fprintf(out
, " Locked Access on shared lines : %10d\n", stats
->locks
);
2047 fprintf(out
, " Store HITs on shared lines : %10d\n", stats
->store
);
2048 fprintf(out
, " Store L1D hits on shared lines : %10d\n", stats
->st_l1hit
);
2049 fprintf(out
, " Total Merged records : %10d\n", hitm_cnt
+ stats
->store
);
2052 static void print_cacheline(struct c2c_hists
*c2c_hists
,
2053 struct hist_entry
*he_cl
,
2054 struct perf_hpp_list
*hpp_list
,
2058 struct perf_hpp hpp
= {
2065 hists__fprintf_headers(&c2c_hists
->hists
, out
);
2071 fprintf(out
, " -------------------------------------------------------------\n");
2072 __hist_entry__snprintf(he_cl
, &hpp
, hpp_list
);
2073 fprintf(out
, "%s\n", bf
);
2074 fprintf(out
, " -------------------------------------------------------------\n");
2076 hists__fprintf(&c2c_hists
->hists
, false, 0, 0, 0, out
, true);
2079 static void print_pareto(FILE *out
)
2081 struct perf_hpp_list hpp_list
;
2085 perf_hpp_list__init(&hpp_list
);
2086 ret
= hpp_list__parse(&hpp_list
,
2095 if (WARN_ONCE(ret
, "failed to setup sort entries\n"))
2098 nd
= rb_first(&c2c
.hists
.hists
.entries
);
2100 for (; nd
; nd
= rb_next(nd
)) {
2101 struct hist_entry
*he
= rb_entry(nd
, struct hist_entry
, rb_node
);
2102 struct c2c_hist_entry
*c2c_he
;
2107 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
2108 print_cacheline(c2c_he
->hists
, he
, &hpp_list
, out
);
2112 static void print_c2c_info(FILE *out
, struct perf_session
*session
)
2114 struct perf_evlist
*evlist
= session
->evlist
;
2115 struct perf_evsel
*evsel
;
2118 fprintf(out
, "=================================================\n");
2119 fprintf(out
, " c2c details \n");
2120 fprintf(out
, "=================================================\n");
2122 evlist__for_each_entry(evlist
, evsel
) {
2123 fprintf(out
, "%-36s: %s\n", first
? " Events" : "",
2124 perf_evsel__name(evsel
));
2127 fprintf(out
, " Cachelines sort on : %s HITMs\n",
2128 display_str
[c2c
.display
]);
2129 fprintf(out
, " Cacheline data grouping : %s\n", c2c
.cl_sort
);
2132 static void perf_c2c__hists_fprintf(FILE *out
, struct perf_session
*session
)
2136 print_c2c__display_stats(out
);
2138 print_shared_cacheline_info(out
);
2140 print_c2c_info(out
, session
);
2146 fprintf(out
, "=================================================\n");
2147 fprintf(out
, " Shared Data Cache Line Table \n");
2148 fprintf(out
, "=================================================\n");
2149 fprintf(out
, "#\n");
2151 hists__fprintf(&c2c
.hists
.hists
, true, 0, 0, 0, stdout
, false);
2154 fprintf(out
, "=================================================\n");
2155 fprintf(out
, " Shared Cache Line Distribution Pareto \n");
2156 fprintf(out
, "=================================================\n");
2157 fprintf(out
, "#\n");
2162 #ifdef HAVE_SLANG_SUPPORT
2163 static void c2c_browser__update_nr_entries(struct hist_browser
*hb
)
2166 struct rb_node
*nd
= rb_first(&hb
->hists
->entries
);
2169 struct hist_entry
*he
= rb_entry(nd
, struct hist_entry
, rb_node
);
2177 hb
->nr_non_filtered_entries
= nr_entries
;
2180 struct c2c_cacheline_browser
{
2181 struct hist_browser hb
;
2182 struct hist_entry
*he
;
2186 perf_c2c_cacheline_browser__title(struct hist_browser
*browser
,
2187 char *bf
, size_t size
)
2189 struct c2c_cacheline_browser
*cl_browser
;
2190 struct hist_entry
*he
;
2193 cl_browser
= container_of(browser
, struct c2c_cacheline_browser
, hb
);
2194 he
= cl_browser
->he
;
2197 addr
= cl_address(he
->mem_info
->daddr
.addr
);
2199 scnprintf(bf
, size
, "Cacheline 0x%lx", addr
);
2203 static struct c2c_cacheline_browser
*
2204 c2c_cacheline_browser__new(struct hists
*hists
, struct hist_entry
*he
)
2206 struct c2c_cacheline_browser
*browser
;
2208 browser
= zalloc(sizeof(*browser
));
2210 hist_browser__init(&browser
->hb
, hists
);
2211 browser
->hb
.c2c_filter
= true;
2212 browser
->hb
.title
= perf_c2c_cacheline_browser__title
;
2219 static int perf_c2c__browse_cacheline(struct hist_entry
*he
)
2221 struct c2c_hist_entry
*c2c_he
;
2222 struct c2c_hists
*c2c_hists
;
2223 struct c2c_cacheline_browser
*cl_browser
;
2224 struct hist_browser
*browser
;
2227 " ENTER Togle callchains (if present) \n"
2228 " n Togle Node details info \n"
2229 " s Togle full lenght of symbol and source line columns \n"
2230 " q Return back to cacheline list \n";
2232 /* Display compact version first. */
2233 c2c
.symbol_full
= false;
2235 c2c_he
= container_of(he
, struct c2c_hist_entry
, he
);
2236 c2c_hists
= c2c_he
->hists
;
2238 cl_browser
= c2c_cacheline_browser__new(&c2c_hists
->hists
, he
);
2239 if (cl_browser
== NULL
)
2242 browser
= &cl_browser
->hb
;
2244 /* reset abort key so that it can get Ctrl-C as a key */
2246 SLang_init_tty(0, 0, 0);
2248 c2c_browser__update_nr_entries(browser
);
2251 key
= hist_browser__run(browser
, "? - help");
2255 c2c
.symbol_full
= !c2c
.symbol_full
;
2258 c2c
.node_info
= (c2c
.node_info
+ 1) % 3;
2259 setup_nodes_header();
2264 ui_browser__help_window(&browser
->b
, help
);
2276 static int perf_c2c_browser__title(struct hist_browser
*browser
,
2277 char *bf
, size_t size
)
2280 "Shared Data Cache Line Table "
2281 "(%lu entries, sorted on %s HITMs)",
2282 browser
->nr_non_filtered_entries
,
2283 display_str
[c2c
.display
]);
2287 static struct hist_browser
*
2288 perf_c2c_browser__new(struct hists
*hists
)
2290 struct hist_browser
*browser
= hist_browser__new(hists
);
2293 browser
->title
= perf_c2c_browser__title
;
2294 browser
->c2c_filter
= true;
2300 static int perf_c2c__hists_browse(struct hists
*hists
)
2302 struct hist_browser
*browser
;
2305 " d Display cacheline details \n"
2306 " ENTER Togle callchains (if present) \n"
2309 browser
= perf_c2c_browser__new(hists
);
2310 if (browser
== NULL
)
2313 /* reset abort key so that it can get Ctrl-C as a key */
2315 SLang_init_tty(0, 0, 0);
2317 c2c_browser__update_nr_entries(browser
);
2320 key
= hist_browser__run(browser
, "? - help");
2326 perf_c2c__browse_cacheline(browser
->he_selection
);
2329 ui_browser__help_window(&browser
->b
, help
);
2337 hist_browser__delete(browser
);
2341 static void perf_c2c_display(struct perf_session
*session
)
2343 if (use_browser
== 0)
2344 perf_c2c__hists_fprintf(stdout
, session
);
2346 perf_c2c__hists_browse(&c2c
.hists
.hists
);
2349 static void perf_c2c_display(struct perf_session
*session
)
2352 perf_c2c__hists_fprintf(stdout
, session
);
2354 #endif /* HAVE_SLANG_SUPPORT */
2356 static void ui_quirks(void)
2358 if (!c2c
.use_stdio
) {
2359 dim_offset
.width
= 5;
2360 dim_offset
.header
= header_offset_tui
;
2363 dim_percent_hitm
.header
= percent_hitm_header
[c2c
.display
];
2366 #define CALLCHAIN_DEFAULT_OPT "graph,0.5,caller,function,percent"
2368 const char callchain_help
[] = "Display call graph (stack chain/backtrace):\n\n"
2369 CALLCHAIN_REPORT_HELP
2370 "\n\t\t\t\tDefault: " CALLCHAIN_DEFAULT_OPT
;
2373 parse_callchain_opt(const struct option
*opt
, const char *arg
, int unset
)
2375 struct callchain_param
*callchain
= opt
->value
;
2377 callchain
->enabled
= !unset
;
2382 symbol_conf
.use_callchain
= false;
2383 callchain
->mode
= CHAIN_NONE
;
2387 return parse_callchain_report_opt(arg
);
2390 static int setup_callchain(struct perf_evlist
*evlist
)
2392 u64 sample_type
= perf_evlist__combined_sample_type(evlist
);
2393 enum perf_call_graph_mode mode
= CALLCHAIN_NONE
;
2395 if ((sample_type
& PERF_SAMPLE_REGS_USER
) &&
2396 (sample_type
& PERF_SAMPLE_STACK_USER
))
2397 mode
= CALLCHAIN_DWARF
;
2398 else if (sample_type
& PERF_SAMPLE_BRANCH_STACK
)
2399 mode
= CALLCHAIN_LBR
;
2400 else if (sample_type
& PERF_SAMPLE_CALLCHAIN
)
2401 mode
= CALLCHAIN_FP
;
2403 if (!callchain_param
.enabled
&&
2404 callchain_param
.mode
!= CHAIN_NONE
&&
2405 mode
!= CALLCHAIN_NONE
) {
2406 symbol_conf
.use_callchain
= true;
2407 if (callchain_register_param(&callchain_param
) < 0) {
2408 ui__error("Can't register callchain params.\n");
2413 callchain_param
.record_mode
= mode
;
2414 callchain_param
.min_percent
= 0;
2418 static int setup_display(const char *str
)
2420 const char *display
= str
?: "tot";
2422 if (!strcmp(display
, "tot"))
2423 c2c
.display
= DISPLAY_TOT
;
2424 else if (!strcmp(display
, "rmt"))
2425 c2c
.display
= DISPLAY_RMT
;
2426 else if (!strcmp(display
, "lcl"))
2427 c2c
.display
= DISPLAY_LCL
;
2429 pr_err("failed: unknown display type: %s\n", str
);
2436 #define for_each_token(__tok, __buf, __sep, __tmp) \
2437 for (__tok = strtok_r(__buf, __sep, &__tmp); __tok; \
2438 __tok = strtok_r(NULL, __sep, &__tmp))
2440 static int build_cl_output(char *cl_sort
, bool no_source
)
2442 char *tok
, *tmp
, *buf
= strdup(cl_sort
);
2443 bool add_pid
= false;
2444 bool add_tid
= false;
2445 bool add_iaddr
= false;
2446 bool add_sym
= false;
2447 bool add_dso
= false;
2448 bool add_src
= false;
2453 for_each_token(tok
, buf
, ",", tmp
) {
2454 if (!strcmp(tok
, "tid")) {
2456 } else if (!strcmp(tok
, "pid")) {
2458 } else if (!strcmp(tok
, "iaddr")) {
2462 add_src
= no_source
? false : true;
2463 } else if (!strcmp(tok
, "dso")) {
2465 } else if (strcmp(tok
, "offset")) {
2466 pr_err("unrecognized sort token: %s\n", tok
);
2471 if (asprintf(&c2c
.cl_output
,
2472 "%s%s%s%s%s%s%s%s%s%s",
2473 c2c
.use_stdio
? "cl_num_empty," : "",
2476 "percent_stores_l1hit,"
2477 "percent_stores_l1miss,"
2479 add_pid
? "pid," : "",
2480 add_tid
? "tid," : "",
2481 add_iaddr
? "iaddr," : "",
2487 add_sym
? "symbol," : "",
2488 add_dso
? "dso," : "",
2489 add_src
? "cl_srcline," : "",
2493 c2c
.show_src
= add_src
;
2499 static int setup_coalesce(const char *coalesce
, bool no_source
)
2501 const char *c
= coalesce
?: coalesce_default
;
2503 if (asprintf(&c2c
.cl_sort
, "offset,%s", c
) < 0)
2506 if (build_cl_output(c2c
.cl_sort
, no_source
))
2509 if (asprintf(&c2c
.cl_resort
, "offset,%s",
2510 c2c
.display
== DISPLAY_TOT
?
2512 c2c
.display
== DISPLAY_RMT
?
2513 "rmt_hitm,lcl_hitm" :
2514 "lcl_hitm,rmt_hitm") < 0)
2517 pr_debug("coalesce sort fields: %s\n", c2c
.cl_sort
);
2518 pr_debug("coalesce resort fields: %s\n", c2c
.cl_resort
);
2519 pr_debug("coalesce output fields: %s\n", c2c
.cl_output
);
2523 static int perf_c2c__report(int argc
, const char **argv
)
2525 struct perf_session
*session
;
2526 struct ui_progress prog
;
2527 struct perf_data data
= {
2528 .mode
= PERF_DATA_MODE_READ
,
2530 char callchain_default_opt
[] = CALLCHAIN_DEFAULT_OPT
;
2531 const char *display
= NULL
;
2532 const char *coalesce
= NULL
;
2533 bool no_source
= false;
2534 const struct option options
[] = {
2535 OPT_STRING('k', "vmlinux", &symbol_conf
.vmlinux_name
,
2536 "file", "vmlinux pathname"),
2537 OPT_STRING('i', "input", &input_name
, "file",
2538 "the input file to process"),
2539 OPT_INCR('N', "node-info", &c2c
.node_info
,
2540 "show extra node info in report (repeat for more info)"),
2541 #ifdef HAVE_SLANG_SUPPORT
2542 OPT_BOOLEAN(0, "stdio", &c2c
.use_stdio
, "Use the stdio interface"),
2544 OPT_BOOLEAN(0, "stats", &c2c
.stats_only
,
2545 "Display only statistic tables (implies --stdio)"),
2546 OPT_BOOLEAN(0, "full-symbols", &c2c
.symbol_full
,
2547 "Display full length of symbols"),
2548 OPT_BOOLEAN(0, "no-source", &no_source
,
2549 "Do not display Source Line column"),
2550 OPT_BOOLEAN(0, "show-all", &c2c
.show_all
,
2551 "Show all captured HITM lines."),
2552 OPT_CALLBACK_DEFAULT('g', "call-graph", &callchain_param
,
2553 "print_type,threshold[,print_limit],order,sort_key[,branch],value",
2554 callchain_help
, &parse_callchain_opt
,
2555 callchain_default_opt
),
2556 OPT_STRING('d', "display", &display
, "Switch HITM output type", "lcl,rmt"),
2557 OPT_STRING('c', "coalesce", &coalesce
, "coalesce fields",
2558 "coalesce fields: pid,tid,iaddr,dso"),
2559 OPT_BOOLEAN('f', "force", &symbol_conf
.force
, "don't complain, do it"),
2560 OPT_PARENT(c2c_options
),
2565 argc
= parse_options(argc
, argv
, options
, report_c2c_usage
,
2566 PARSE_OPT_STOP_AT_NON_OPTION
);
2568 usage_with_options(report_c2c_usage
, options
);
2571 c2c
.use_stdio
= true;
2573 if (!input_name
|| !strlen(input_name
))
2574 input_name
= "perf.data";
2576 data
.file
.path
= input_name
;
2577 data
.force
= symbol_conf
.force
;
2579 err
= setup_display(display
);
2583 err
= setup_coalesce(coalesce
, no_source
);
2585 pr_debug("Failed to initialize hists\n");
2589 err
= c2c_hists__init(&c2c
.hists
, "dcacheline", 2);
2591 pr_debug("Failed to initialize hists\n");
2595 session
= perf_session__new(&data
, 0, &c2c
.tool
);
2596 if (session
== NULL
) {
2597 pr_debug("No memory for session\n");
2601 err
= setup_nodes(session
);
2603 pr_err("Failed setup nodes\n");
2607 err
= setup_callchain(session
->evlist
);
2611 if (symbol__init(&session
->header
.env
) < 0)
2614 /* No pipe support at the moment. */
2615 if (perf_data__is_pipe(session
->data
)) {
2616 pr_debug("No pipe support at the moment.\n");
2625 setup_browser(false);
2627 err
= perf_session__process_events(session
);
2629 pr_err("failed to process sample\n");
2633 c2c_hists__reinit(&c2c
.hists
,
2638 "tot_hitm,lcl_hitm,rmt_hitm,"
2639 "stores,stores_l1hit,stores_l1miss,"
2640 "dram_lcl,dram_rmt,"
2643 "ld_fbhit,ld_l1hit,ld_l2hit,"
2644 "ld_lclhit,ld_rmthit",
2645 c2c
.display
== DISPLAY_TOT
? "tot_hitm" :
2646 c2c
.display
== DISPLAY_LCL
? "lcl_hitm" : "rmt_hitm"
2649 ui_progress__init(&prog
, c2c
.hists
.hists
.nr_entries
, "Sorting...");
2651 hists__collapse_resort(&c2c
.hists
.hists
, NULL
);
2652 hists__output_resort_cb(&c2c
.hists
.hists
, &prog
, resort_hitm_cb
);
2653 hists__iterate_cb(&c2c
.hists
.hists
, resort_cl_cb
);
2655 ui_progress__finish();
2659 perf_c2c_display(session
);
2662 perf_session__delete(session
);
2667 static int parse_record_events(const struct option
*opt
,
2668 const char *str
, int unset __maybe_unused
)
2670 bool *event_set
= (bool *) opt
->value
;
2673 return perf_mem_events__parse(str
);
2677 static const char * const __usage_record
[] = {
2678 "perf c2c record [<options>] [<command>]",
2679 "perf c2c record [<options>] -- <command> [<options>]",
2683 static const char * const *record_mem_usage
= __usage_record
;
2685 static int perf_c2c__record(int argc
, const char **argv
)
2687 int rec_argc
, i
= 0, j
;
2688 const char **rec_argv
;
2690 bool all_user
= false, all_kernel
= false;
2691 bool event_set
= false;
2692 struct option options
[] = {
2693 OPT_CALLBACK('e', "event", &event_set
, "event",
2694 "event selector. Use 'perf mem record -e list' to list available events",
2695 parse_record_events
),
2696 OPT_BOOLEAN('u', "all-user", &all_user
, "collect only user level data"),
2697 OPT_BOOLEAN('k', "all-kernel", &all_kernel
, "collect only kernel level data"),
2698 OPT_UINTEGER('l', "ldlat", &perf_mem_events__loads_ldlat
, "setup mem-loads latency"),
2699 OPT_PARENT(c2c_options
),
2703 if (perf_mem_events__init()) {
2704 pr_err("failed: memory events not supported\n");
2708 argc
= parse_options(argc
, argv
, options
, record_mem_usage
,
2709 PARSE_OPT_KEEP_UNKNOWN
);
2711 rec_argc
= argc
+ 10; /* max number of arguments */
2712 rec_argv
= calloc(rec_argc
+ 1, sizeof(char *));
2716 rec_argv
[i
++] = "record";
2719 perf_mem_events
[PERF_MEM_EVENTS__LOAD
].record
= true;
2720 perf_mem_events
[PERF_MEM_EVENTS__STORE
].record
= true;
2723 if (perf_mem_events
[PERF_MEM_EVENTS__LOAD
].record
)
2724 rec_argv
[i
++] = "-W";
2726 rec_argv
[i
++] = "-d";
2727 rec_argv
[i
++] = "--sample-cpu";
2729 for (j
= 0; j
< PERF_MEM_EVENTS__MAX
; j
++) {
2730 if (!perf_mem_events
[j
].record
)
2733 if (!perf_mem_events
[j
].supported
) {
2734 pr_err("failed: event '%s' not supported\n",
2735 perf_mem_events
[j
].name
);
2740 rec_argv
[i
++] = "-e";
2741 rec_argv
[i
++] = perf_mem_events__name(j
);
2745 rec_argv
[i
++] = "--all-user";
2748 rec_argv
[i
++] = "--all-kernel";
2750 for (j
= 0; j
< argc
; j
++, i
++)
2751 rec_argv
[i
] = argv
[j
];
2754 pr_debug("calling: ");
2758 while (rec_argv
[j
]) {
2759 pr_debug("%s ", rec_argv
[j
]);
2765 ret
= cmd_record(i
, rec_argv
);
2770 int cmd_c2c(int argc
, const char **argv
)
2772 argc
= parse_options(argc
, argv
, c2c_options
, c2c_usage
,
2773 PARSE_OPT_STOP_AT_NON_OPTION
);
2776 usage_with_options(c2c_usage
, c2c_options
);
2778 if (!strncmp(argv
[0], "rec", 3)) {
2779 return perf_c2c__record(argc
, argv
);
2780 } else if (!strncmp(argv
[0], "rep", 3)) {
2781 return perf_c2c__report(argc
, argv
);
2783 usage_with_options(c2c_usage
, c2c_options
);