Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 147255
b: refs/heads/master
c: 592903c
h: refs/heads/master
i:
  147253: d21897e
  147251: 56c5755
  147247: 950a40f
v: v3
  • Loading branch information
Peter Zijlstra authored and Ingo Molnar committed Apr 6, 2009
1 parent 2b236ba commit 89f74ff
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 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: d6d020e9957745c61285ef3da9f294c5e6801f0f
refs/heads/master: 592903cdcbf606a838056bae6d03fc557806c914
4 changes: 4 additions & 0 deletions trunk/include/linux/perf_counter.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ struct file;
struct perf_counter {
#ifdef CONFIG_PERF_COUNTERS
struct list_head list_entry;
struct list_head event_entry;
struct list_head sibling_list;
struct perf_counter *group_leader;
const struct hw_perf_counter_ops *hw_ops;
Expand Down Expand Up @@ -220,6 +221,8 @@ struct perf_counter {
struct perf_data *irqdata;
struct perf_data *usrdata;
struct perf_data data[2];

struct rcu_head rcu_head;
#endif
};

Expand All @@ -243,6 +246,7 @@ struct perf_counter_context {
struct mutex mutex;

struct list_head counter_list;
struct list_head event_list;
int nr_counters;
int nr_active;
int is_active;
Expand Down
30 changes: 19 additions & 11 deletions trunk/kernel/perf_counter.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <linux/perf_counter.h>
#include <linux/mm.h>
#include <linux/vmstat.h>
#include <linux/rculist.h>

/*
* Each CPU has a list of per CPU counters:
Expand Down Expand Up @@ -72,6 +73,8 @@ list_add_counter(struct perf_counter *counter, struct perf_counter_context *ctx)
list_add_tail(&counter->list_entry, &ctx->counter_list);
else
list_add_tail(&counter->list_entry, &group_leader->sibling_list);

list_add_rcu(&counter->event_entry, &ctx->event_list);
}

static void
Expand All @@ -80,6 +83,7 @@ list_del_counter(struct perf_counter *counter, struct perf_counter_context *ctx)
struct perf_counter *sibling, *tmp;

list_del_init(&counter->list_entry);
list_del_rcu(&counter->event_entry);

/*
* If this was a group counter with sibling counters then
Expand Down Expand Up @@ -1133,6 +1137,14 @@ static struct perf_counter_context *find_get_context(pid_t pid, int cpu)
return ctx;
}

static void free_counter_rcu(struct rcu_head *head)
{
struct perf_counter *counter;

counter = container_of(head, struct perf_counter, rcu_head);
kfree(counter);
}

/*
* Called when the last reference to the file is gone.
*/
Expand All @@ -1151,7 +1163,7 @@ static int perf_release(struct inode *inode, struct file *file)
mutex_unlock(&counter->mutex);
mutex_unlock(&ctx->mutex);

kfree(counter);
call_rcu(&counter->rcu_head, free_counter_rcu);
put_context(ctx);

return 0;
Expand Down Expand Up @@ -1491,22 +1503,16 @@ static void perf_swcounter_ctx_event(struct perf_counter_context *ctx,
int nmi, struct pt_regs *regs)
{
struct perf_counter *counter;
unsigned long flags;

if (list_empty(&ctx->counter_list))
if (list_empty(&ctx->event_list))
return;

spin_lock_irqsave(&ctx->lock, flags);

/*
* XXX: make counter_list RCU safe
*/
list_for_each_entry(counter, &ctx->counter_list, list_entry) {
rcu_read_lock();
list_for_each_entry_rcu(counter, &ctx->event_list, event_entry) {
if (perf_swcounter_match(counter, event, regs))
perf_swcounter_add(counter, nr, nmi, regs);
}

spin_unlock_irqrestore(&ctx->lock, flags);
rcu_read_unlock();
}

void perf_swcounter_event(enum hw_event_types event, u64 nr,
Expand Down Expand Up @@ -1846,6 +1852,7 @@ perf_counter_alloc(struct perf_counter_hw_event *hw_event,

mutex_init(&counter->mutex);
INIT_LIST_HEAD(&counter->list_entry);
INIT_LIST_HEAD(&counter->event_entry);
INIT_LIST_HEAD(&counter->sibling_list);
init_waitqueue_head(&counter->waitq);

Expand Down Expand Up @@ -1992,6 +1999,7 @@ __perf_counter_init_context(struct perf_counter_context *ctx,
spin_lock_init(&ctx->lock);
mutex_init(&ctx->mutex);
INIT_LIST_HEAD(&ctx->counter_list);
INIT_LIST_HEAD(&ctx->event_list);
ctx->task = task;
}

Expand Down

0 comments on commit 89f74ff

Please sign in to comment.