Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 147598
b: refs/heads/master
c: 709e50c
h: refs/heads/master
v: v3
  • Loading branch information
Peter Zijlstra authored and Ingo Molnar committed Jun 2, 2009
1 parent 4483831 commit fa2c40b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 9 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: bf4e0ed3d027ce581be18496036862131b5f32aa
refs/heads/master: 709e50cf870e61745b39552044aa6c7c38e4f9e0
3 changes: 3 additions & 0 deletions trunk/include/linux/perf_counter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -500,6 +501,8 @@ struct perf_counter {

void (*destroy)(struct perf_counter *);
struct rcu_head rcu_head;

struct pid_namespace *ns;
#endif
};

Expand Down
42 changes: 34 additions & 8 deletions trunk/kernel/perf_counter.c
Original file line number Diff line number Diff line change
Expand Up @@ -1432,6 +1432,8 @@ static void free_counter_rcu(struct rcu_head *head)
struct perf_counter *counter;

counter = container_of(head, struct perf_counter, rcu_head);
if (counter->ns)
put_pid_ns(counter->ns);
kfree(counter);
}

Expand Down Expand Up @@ -2267,6 +2269,28 @@ static void perf_output_end(struct perf_output_handle *handle)
rcu_read_unlock();
}

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);
}

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);
}

static void perf_counter_output(struct perf_counter *counter,
int nmi, struct pt_regs *regs, u64 addr)
{
Expand Down Expand Up @@ -2303,8 +2327,8 @@ static void perf_counter_output(struct perf_counter *counter,

if (record_type & PERF_RECORD_TID) {
/* namespace issues */
tid_entry.pid = current->group_leader->pid;
tid_entry.tid = current->pid;
tid_entry.pid = perf_counter_pid(counter, current);
tid_entry.tid = perf_counter_tid(counter, current);

header.type |= PERF_RECORD_TID;
header.size += sizeof(tid_entry);
Expand Down Expand Up @@ -2432,6 +2456,9 @@ static void perf_counter_comm_output(struct perf_counter *counter,
if (ret)
return;

comm_event->event.pid = perf_counter_pid(counter, comm_event->task);
comm_event->event.tid = perf_counter_tid(counter, comm_event->task);

perf_output_put(&handle, comm_event->event);
perf_output_copy(&handle, comm_event->comm,
comm_event->comm_size);
Expand Down Expand Up @@ -2504,8 +2531,6 @@ void perf_counter_comm(struct task_struct *task)
.task = task,
.event = {
.header = { .type = PERF_EVENT_COMM, },
.pid = task->group_leader->pid,
.tid = task->pid,
},
};

Expand Down Expand Up @@ -2542,6 +2567,9 @@ static void perf_counter_mmap_output(struct perf_counter *counter,
if (ret)
return;

mmap_event->event.pid = perf_counter_pid(counter, current);
mmap_event->event.tid = perf_counter_tid(counter, current);

perf_output_put(&handle, mmap_event->event);
perf_output_copy(&handle, mmap_event->file_name,
mmap_event->file_size);
Expand Down Expand Up @@ -2641,8 +2669,6 @@ void perf_counter_mmap(unsigned long addr, unsigned long len,
.file = file,
.event = {
.header = { .type = PERF_EVENT_MMAP, },
.pid = current->group_leader->pid,
.tid = current->pid,
.start = addr,
.len = len,
.pgoff = pgoff,
Expand All @@ -2664,8 +2690,6 @@ void perf_counter_munmap(unsigned long addr, unsigned long len,
.file = file,
.event = {
.header = { .type = PERF_EVENT_MUNMAP, },
.pid = current->group_leader->pid,
.tid = current->pid,
.start = addr,
.len = len,
.pgoff = pgoff,
Expand Down Expand Up @@ -3445,6 +3469,8 @@ SYSCALL_DEFINE5(perf_counter_open,
list_add_tail(&counter->owner_entry, &current->perf_counter_list);
mutex_unlock(&current->perf_counter_mutex);

counter->ns = get_pid_ns(current->nsproxy->pid_ns);

fput_light(counter_file, fput_needed2);

out_fput:
Expand Down

0 comments on commit fa2c40b

Please sign in to comment.