Skip to content

Commit

Permalink
support pebs v3
Browse files Browse the repository at this point in the history
  • Loading branch information
daishengdong authored and andikleen committed Dec 14, 2023
1 parent bcf293e commit 1fc9709
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
17 changes: 14 additions & 3 deletions pebs-grabber/pebs-grabber.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
make [KDIR=/my/kernel/build/dir]
insmod pebs-grabber.ko
# needs to record as root
perf record -e cycles:p,pebs:pebs_v1,pebs:pebs_v2 [command, -a for all etc.]
perf record -e cycles:p,pebs:pebs_v1,pebs:pebs_v2,pebs:pebs_v3 [command, -a for all etc.]
perf report
perf script to display pebs data
# alternatively trace-cmd and kernelshark can be also used to dump
Expand Down Expand Up @@ -59,6 +59,11 @@ struct pebs_v2 {
u64 tsx_tuning;
};

struct pebs_v3 {
struct pebs_v2 v2;
u64 tsc;
};

struct debug_store {
u64 buffer_base;
u64 index;
Expand All @@ -81,11 +86,13 @@ static char *handler_names[] = {
#else
[2] = "intel_pmu_drain_pebs_nhm",
#endif
[3] = "intel_pmu_drain_pebs_nhm",
};

static unsigned pebs_record_size[] = {
[1] = sizeof(struct pebs_v1),
[2] = sizeof(struct pebs_v2),
[3] = sizeof(struct pebs_v3),
};

static int pebs_grabber(struct kprobe *kp, struct pt_regs *regs)
Expand All @@ -110,12 +117,16 @@ static int pebs_grabber(struct kprobe *kp, struct pt_regs *regs)
v1->dla,
v1->dse,
v1->lat);
if (pebs_version == 2) {
if (pebs_version >= 2) {
struct pebs_v2 *v2 = pebs;
trace_pebs_v2(v2->eventingip,
v2->tsx_tuning,
v1->regs[0]);
}
if (pebs_version == 3) {
struct pebs_v3 *v3 = pebs;
trace_pebs_v3(v3->tsc);
}
trace_pebs_regs(v1->flags, v1->regs);
}
return 0;
Expand Down Expand Up @@ -147,7 +158,7 @@ static int init_pebs_grabber(void)
pebs_version = (cap >> 8) & 0xf;
pr_info("PEBS version %u\n", pebs_version);

if (pebs_version < 1 || pebs_version > 2) {
if (pebs_version < 1 || pebs_version > 3) {
pr_err("Unsupported PEBS version %u\n", pebs_version);
return -EIO;
}
Expand Down
12 changes: 12 additions & 0 deletions pebs-grabber/pebs.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ TRACE_EVENT(pebs_v2,
__entry->ax)
);

TRACE_EVENT(pebs_v3,
TP_PROTO(u64 tsc),
TP_ARGS(tsc),
TP_STRUCT__entry(
__field(u64, tsc)
),
TP_fast_assign(
__entry->tsc = tsc;
),
TP_printk("tsc=%llx\n", __entry->tsc)
);

TRACE_EVENT(pebs_regs,
TP_PROTO(u64 flags, u64 *regs),
TP_ARGS(flags, regs),
Expand Down

0 comments on commit 1fc9709

Please sign in to comment.