Skip to contentSkip to conversation

perf_counter: Use PID namespaces properly

tip:perfcounters/core tip-bot for Peter Zijlstra 2 participants 4 messages Jun 2, 2009

lore
Share & tools
lore
#0 lore raw
Commit-ID:  709e50cf870e61745b39552044aa6c7c38e4f9e0
Gitweb:     http://git.kernel.org/tip/709e50cf870e61745b39552044aa6c7c38e4f9e0
Author:     Peter Zijlstra <[email protected]>
AuthorDate: Tue, 2 Jun 2009 14:13:15 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Tue, 2 Jun 2009 16:16:25 +0200

perf_counter: Use PID namespaces properly

Stop using task_struct::pid and start using PID namespaces.

PIDs will be reported in the PID namespace of the monitoring task at the moment of counter creation.

Cc Eric W. Biederman <[email protected]>
Cc Oleg Nesterov <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Corey Ashford <[email protected]>
Cc Marcelo Tosatti <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc John Kacur <[email protected]>

LKML-Reference: <new-submission>

---
 include/linux/perf_counter.h |    3 +++
 kernel/perf_counter.c        |   42 ++++++++++++++++++++++++++++++++++--------
 2 files changed, 37 insertions(+), 8 deletions(-)
include/linux/perf_counter.h +3 -0
index d970fbc..9ec20fc 100644
@@ -317,6 +317,7 @@ enum perf_event_type {
 #include <linux/spinlock.h>
 #include <linux/hrtimer.h>
 #include <linux/fs.h>
+#include <linux/pid_namespace.h>
 #include <asm/atomic.h>
 
 struct task_struct;
@@ -500,6 +501,8 @@ struct perf_counter {
 
 	void (*destroy)(struct perf_counter *);
 	struct rcu_head			rcu_head;
+
+	struct pid_namespace		*ns;
 #endif
 };
 
kernel/perf_counter.c +34 -8

96 lines not on this page · raw message

#1 lore raw
Quoted 11 lines · tip-bot for Peter Zijlstra
kernel/perf_counter.c +10 -0
+static u32 perf_counter_pid(struct perf_counter *counter, struct task_struct *p)
+{
+	/*
+	 * only top level counters have the pid namespace they were created in
+	 */
+	if (counter->parent)
+		counter = counter->parent;
+
+	return task_tgid_nr_ns(p, counter->ns);
+}

kernel/perf_counter.c static void perf_output_end(struct perf_output_handle *handle) · line 2291

Quoted 10 lines
kernel/perf_counter.c +10 -0
+
+static u32 perf_counter_tid(struct perf_counter *counter, struct task_struct *p)
+{
+	/*
+	 * only top level counters have the pid namespace they were created in
+	 */
+	if (counter->parent)
+		counter = counter->parent;
+
+	return task_pid_nr_ns(p, counter->ns);

Perhaps this should be

	return task_pid_nr_ns(p->group_leader);

?

kernel/perf_counter.c static void perf_counter_output(struct perf_counter *counter, · line 2331

Quoted 2 lines
kernel/perf_counter.c +2 -0
+		tid_entry.pid = perf_counter_pid(counter, current);
+		tid_entry.tid = perf_counter_tid(counter, current);

Otherwise we seem to always report .pid == .tid

Oleg.

#2 lore raw
Quoted 25 lines · Oleg Nesterov
Quoted 11 lines · tip-bot for Peter Zijlstra
kernel/perf_counter.c +10 -0
+static u32 perf_counter_pid(struct perf_counter *counter, struct task_struct *p)
+{
+	/*
+	 * only top level counters have the pid namespace they were created in
+	 */
+	if (counter->parent)
+		counter = counter->parent;
+
+	return task_tgid_nr_ns(p, counter->ns);
+}

kernel/perf_counter.c static void perf_output_end(struct perf_output_handle *handle) · line 2291

Quoted 10 lines
kernel/perf_counter.c +10 -0
+
+static u32 perf_counter_tid(struct perf_counter *counter, struct task_struct *p)
+{
+	/*
+	 * only top level counters have the pid namespace they were created in
+	 */
+	if (counter->parent)
+		counter = counter->parent;
+
+	return task_pid_nr_ns(p, counter->ns);

Perhaps this should be

Quoted 3 lines
	return task_pid_nr_ns(p->group_leader);

?

That seems to be exactly what task_tgid_nr_ns() does.

so pid = task->group_leader->pids[PIDTYPE_PID].pid and tid = task->pids[PIDTYPE_PID].pid

Quoted 5 lines

kernel/perf_counter.c static void perf_counter_output(struct perf_counter *counter, · line 2331

Quoted 2 lines
kernel/perf_counter.c +2 -0
+		tid_entry.pid = perf_counter_pid(counter, current);
+		tid_entry.tid = perf_counter_tid(counter, current);

Otherwise we seem to always report .pid == .tid

tgid vs pid, I don't think they end up being equal. Are they?

#3 lore raw
Quoted 27 lines · Peter Zijlstra
Quoted 25 lines · Oleg Nesterov
Quoted 11 lines · tip-bot for Peter Zijlstra
kernel/perf_counter.c +10 -0
+static u32 perf_counter_pid(struct perf_counter *counter, struct task_struct *p)
+{
+	/*
+	 * only top level counters have the pid namespace they were created in
+	 */
+	if (counter->parent)
+		counter = counter->parent;
+
+	return task_tgid_nr_ns(p, counter->ns);
+}

kernel/perf_counter.c static void perf_output_end(struct perf_output_handle *handle) · line 2291

Quoted 10 lines
kernel/perf_counter.c +10 -0
+
+static u32 perf_counter_tid(struct perf_counter *counter, struct task_struct *p)
+{
+	/*
+	 * only top level counters have the pid namespace they were created in
+	 */
+	if (counter->parent)
+		counter = counter->parent;
+
+	return task_pid_nr_ns(p, counter->ns);

Perhaps this should be

Quoted 5 lines
Quoted 3 lines
	return task_pid_nr_ns(p->group_leader);

?

That seems to be exactly what task_tgid_nr_ns() does.

Ah, yes, I didn't notice _tgid_ above.

Oleg.