[PATCH v2 1/6] perf: Add new types PERF_TYPE_KPROBE and PERF_TYPE_UPROBE

From: Song Liu
Date: Wed Nov 29 2017 - 20:45:04 EST


Two new perf types, PERF_TYPE_KPROBE and PERF_TYPE_UPROBE, are added
to allow creating [k,u]probe with perf_event_open. These [k,u]probe
are associated with the file decriptor created by perf_event_open,
thus are easy to clean when the file descriptor is destroyed.

kprobe_func and uprobe_path are added to union config1 for pointers
to function name for kprobe or binary path for uprobe.

kprobe_addr and probe_offset are added to union config2 for kernel
address (when kprobe_func is NULL), or [k,u]probe offset.

Signed-off-by: Song Liu <songliubraving@xxxxxx>
Reviewed-by: Yonghong Song <yhs@xxxxxx>
Reviewed-by: Josef Bacik <jbacik@xxxxxx>
Acked-by: Alexei Starovoitov <ast@xxxxxxxxxx>
---
include/uapi/linux/perf_event.h | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/include/uapi/linux/perf_event.h b/include/uapi/linux/perf_event.h
index 362493a..5220600 100644
--- a/include/uapi/linux/perf_event.h
+++ b/include/uapi/linux/perf_event.h
@@ -33,6 +33,8 @@ enum perf_type_id {
PERF_TYPE_HW_CACHE = 3,
PERF_TYPE_RAW = 4,
PERF_TYPE_BREAKPOINT = 5,
+ PERF_TYPE_KPROBE = 6,
+ PERF_TYPE_UPROBE = 7,

PERF_TYPE_MAX, /* non-ABI */
};
@@ -299,6 +301,8 @@ enum perf_event_read_format {
#define PERF_ATTR_SIZE_VER4 104 /* add: sample_regs_intr */
#define PERF_ATTR_SIZE_VER5 112 /* add: aux_watermark */

+#define MAX_PROBE_FUNC_NAME_LEN 64
+
/*
* Hardware event_id to monitor via a performance monitoring event:
*
@@ -380,10 +384,14 @@ struct perf_event_attr {
__u32 bp_type;
union {
__u64 bp_addr;
+ __u64 kprobe_func; /* for PERF_TYPE_KPROBE */
+ __u64 uprobe_path; /* for PERF_TYPE_UPROBE */
__u64 config1; /* extension of config */
};
union {
__u64 bp_len;
+ __u64 kprobe_addr; /* for PERF_TYPE_KPROBE, with kprobe_func == NULL */
+ __u64 probe_offset; /* for PERF_TYPE_[K,U]PROBE */
__u64 config2; /* extension of config1 */
};
__u64 branch_sample_type; /* enum perf_branch_sample_type */
--
2.9.5