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;
struct perf_data *irqdata;
struct perf_data *usrdata;
struct perf_data data[2];
+
+ struct rcu_head rcu_head;
#endif
};
struct mutex mutex;
struct list_head counter_list;
+ struct list_head event_list;
int nr_counters;
int nr_active;
int is_active;
#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:
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
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
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.
*/
mutex_unlock(&counter->mutex);
mutex_unlock(&ctx->mutex);
- kfree(counter);
+ call_rcu(&counter->rcu_head, free_counter_rcu);
put_context(ctx);
return 0;
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,
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);
spin_lock_init(&ctx->lock);
mutex_init(&ctx->mutex);
INIT_LIST_HEAD(&ctx->counter_list);
+ INIT_LIST_HEAD(&ctx->event_list);
ctx->task = task;
}