#include <linux/irqflags.h>
#include <linux/kdebug.h>
#include <linux/kernel.h>
-#include <linux/list.h>
#include <linux/mutex.h>
#include <linux/notifier.h>
#include <linux/percpu.h>
+#include <linux/rhashtable.h>
#include <linux/sched.h>
#include <linux/slab.h>
}
/* Keep track of the breakpoints attached to tasks */
-static LIST_HEAD(bp_task_head);
+static struct rhltable task_bps_ht;
+static const struct rhashtable_params task_bps_ht_params = {
+ .head_offset = offsetof(struct hw_perf_event, bp_list),
+ .key_offset = offsetof(struct hw_perf_event, target),
+ .key_len = sizeof_field(struct hw_perf_event, target),
+ .automatic_shrinking = true,
+};
static int constraints_initialized;
*/
static int task_bp_pinned(int cpu, struct perf_event *bp, enum bp_type_idx type)
{
- struct task_struct *tsk = bp->hw.target;
+ struct rhlist_head *head, *pos;
struct perf_event *iter;
int count = 0;
- list_for_each_entry(iter, &bp_task_head, hw.bp_list) {
- if (iter->hw.target == tsk &&
- find_slot_idx(iter->attr.bp_type) == type &&
+ rcu_read_lock();
+ head = rhltable_lookup(&task_bps_ht, &bp->hw.target, task_bps_ht_params);
+ if (!head)
+ goto out;
+
+ rhl_for_each_entry_rcu(iter, pos, head, hw.bp_list) {
+ if (find_slot_idx(iter->attr.bp_type) == type &&
(iter->cpu < 0 || cpu == iter->cpu))
count += hw_breakpoint_weight(iter);
}
+out:
+ rcu_read_unlock();
return count;
}
/*
* Add/remove the given breakpoint in our constraint table
*/
-static void
+static int
toggle_bp_slot(struct perf_event *bp, bool enable, enum bp_type_idx type,
int weight)
{
/* Pinned counter cpu profiling */
if (!bp->hw.target) {
get_bp_info(bp->cpu, type)->cpu_pinned += weight;
- return;
+ return 0;
}
/* Pinned counter task profiling */
toggle_bp_task_slot(bp, cpu, type, weight);
if (enable)
- list_add_tail(&bp->hw.bp_list, &bp_task_head);
+ return rhltable_insert(&task_bps_ht, &bp->hw.bp_list, task_bps_ht_params);
else
- list_del(&bp->hw.bp_list);
+ return rhltable_remove(&task_bps_ht, &bp->hw.bp_list, task_bps_ht_params);
}
__weak int arch_reserve_bp_slot(struct perf_event *bp)
if (ret)
return ret;
- toggle_bp_slot(bp, true, type, weight);
-
- return 0;
+ return toggle_bp_slot(bp, true, type, weight);
}
int reserve_bp_slot(struct perf_event *bp)
type = find_slot_idx(bp_type);
weight = hw_breakpoint_weight(bp);
- toggle_bp_slot(bp, false, type, weight);
+ WARN_ON(toggle_bp_slot(bp, false, type, weight));
}
void release_bp_slot(struct perf_event *bp)
int __init init_hw_breakpoint(void)
{
int cpu, err_cpu;
- int i;
+ int i, ret;
for (i = 0; i < TYPE_MAX; i++)
nr_slots[i] = hw_breakpoint_slots(i);
info->tsk_pinned = kcalloc(nr_slots[i], sizeof(int),
GFP_KERNEL);
- if (!info->tsk_pinned)
- goto err_alloc;
+ if (!info->tsk_pinned) {
+ ret = -ENOMEM;
+ goto err;
+ }
}
}
+ ret = rhltable_init(&task_bps_ht, &task_bps_ht_params);
+ if (ret)
+ goto err;
+
constraints_initialized = 1;
perf_pmu_register(&perf_breakpoint, "breakpoint", PERF_TYPE_BREAKPOINT);
return register_die_notifier(&hw_breakpoint_exceptions_nb);
- err_alloc:
+err:
for_each_possible_cpu(err_cpu) {
for (i = 0; i < TYPE_MAX; i++)
kfree(get_bp_info(err_cpu, i)->tsk_pinned);
break;
}
- return -ENOMEM;
+ return ret;
}
-
-