[PATCH] perf_event_open.2: PERF_RECORD_NAMESPACES support

From: Hari Bathini
Date: Mon Dec 12 2016 - 13:54:39 EST


Linux 4.10 introduces new PERF_RECORD_NAMESPACES for recording
namespaces specific information. This information can be used
to trace performace issues in the context of namespaces.

Signed-off-by: Hari Bathini <hbathini@xxxxxxxxxxxxxxxxxx>
---

TODOs
* Depends on acceptability of https://lkml.org/lkml/2016/12/12/413
* TBA needs to be replaced with actual commit id


man2/perf_event_open.2 | 42 +++++++++++++++++++++++++++++++++++++++++-
1 file changed, 41 insertions(+), 1 deletion(-)

diff --git a/man2/perf_event_open.2 b/man2/perf_event_open.2
index 65239e6..6ce5796 100644
--- a/man2/perf_event_open.2
+++ b/man2/perf_event_open.2
@@ -244,8 +244,10 @@ struct perf_event_attr {
due to exec */
use_clockid : 1, /* use clockid for time fields */
context_switch : 1, /* context switch data */
+ write_backward : 1, /* Write ring buffer from end to beginning */
+ namespaces : 1, /* include namespaces data */

- __reserved_1 : 37;
+ __reserved_1 : 35;

union {
__u32 wakeup_events; /* wakeup every n events */
@@ -1128,6 +1130,11 @@ information even with strict
.I perf_event_paranoid
settings.
.TP
+.IR "namespaces" " (since Linux 4.10)"
+.\" commit TBA
+If this bit is set, then namespaces info of every task is
+included in the ring buffer.
+.TP
.IR "wakeup_events" ", " "wakeup_watermark"
This union sets how many samples
.RI ( wakeup_events )
@@ -2674,6 +2681,39 @@ or next (if switching out) process on the CPU.
The thread ID of the previous (if switching in)
or next (if switching out) thread on the CPU.
.RE
+.TP
+.BR PERF_RECORD_NAMESPACES " (since Linux 4.10)"
+\" commit TBA
+This events record namespaces info of each task, to
+enable tracing in the context of namespaces. They
+have the following structure:
+
+.in +4n
+.nf
+struct {
+ struct perf_event_header header;
+ u32 pid;
+ u32 tid;
+ u64 dev_num;
+ u64 inode_num[NAMESPACES_MAX];
+ struct sample_id sample_id;
+};
+.fi
+.in
+.RS
+.TP
+.I pid
+is the process ID.
+.TP
+.I tid
+is the thread ID.
+.TP
+.I dev_num
+is the number of the device the inodes correspond to.
+.TP
+.I inode_num[NAMESPACES_MAX]
+is the array of inodes of the process's namespaces.
+.RE
.RE
.SS Overflow handling
Events can be set to notify when a threshold is crossed,