[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230612093540.638818161@infradead.org>
Date: Mon, 12 Jun 2023 11:07:56 +0200
From: Peter Zijlstra <peterz@...radead.org>
To: torvalds@...ux-foundation.org, keescook@...omium.org,
gregkh@...uxfoundation.org, pbonzini@...hat.com
Cc: masahiroy@...nel.org, nathan@...nel.org, ndesaulniers@...gle.com,
nicolas@...sle.eu, catalin.marinas@....com, will@...nel.org,
vkoul@...nel.org, trix@...hat.com, ojeda@...nel.org,
peterz@...radead.org, mingo@...hat.com, longman@...hat.com,
boqun.feng@...il.com, dennis@...nel.org, tj@...nel.org,
cl@...ux.com, acme@...nel.org, mark.rutland@....com,
alexander.shishkin@...ux.intel.com, jolsa@...nel.org,
namhyung@...nel.org, irogers@...gle.com, adrian.hunter@...el.com,
juri.lelli@...hat.com, vincent.guittot@...aro.org,
dietmar.eggemann@....com, rostedt@...dmis.org, bsegall@...gle.com,
mgorman@...e.de, bristot@...hat.com, vschneid@...hat.com,
paulmck@...nel.org, frederic@...nel.org, quic_neeraju@...cinc.com,
joel@...lfernandes.org, josh@...htriplett.org,
mathieu.desnoyers@...icios.com, jiangshanlai@...il.com,
rientjes@...gle.com, vbabka@...e.cz, roman.gushchin@...ux.dev,
42.hyeyoo@...il.com, apw@...onical.com, joe@...ches.com,
dwaipayanray1@...il.com, lukas.bulwahn@...il.com,
john.johansen@...onical.com, paul@...l-moore.com,
jmorris@...ei.org, serge@...lyn.com, linux-kbuild@...r.kernel.org,
linux-kernel@...r.kernel.org, dmaengine@...r.kernel.org,
llvm@...ts.linux.dev, linux-perf-users@...r.kernel.org,
rcu@...r.kernel.org, linux-security-module@...r.kernel.org,
tglx@...utronix.de, ravi.bangoria@....com, error27@...il.com,
luc.vanoostenryck@...il.com
Subject: [PATCH v3 43/57] perf: Simplify perf_sw_event()
Signed-off-by: Peter Zijlstra (Intel) <peterz@...radead.org>
---
kernel/events/core.c | 37 ++++++++++++-------------------------
1 file changed, 12 insertions(+), 25 deletions(-)
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -9701,17 +9701,15 @@ static void do_perf_sw_event(enum perf_t
struct perf_event *event;
struct hlist_head *head;
- rcu_read_lock();
+ guard(rcu)();
head = find_swevent_head_rcu(swhash, type, event_id);
if (!head)
- goto end;
+ return;
hlist_for_each_entry_rcu(event, head, hlist_entry) {
if (perf_swevent_match(event, type, event_id, data, regs))
perf_swevent_event(event, nr, data, regs);
}
-end:
- rcu_read_unlock();
}
DEFINE_PER_CPU(struct pt_regs, __perf_regs[4]);
@@ -9746,16 +9744,13 @@ void __perf_sw_event(u32 event_id, u64 n
{
int rctx;
- preempt_disable_notrace();
+ guard(preempt_notrace)();
rctx = perf_swevent_get_recursion_context();
if (unlikely(rctx < 0))
- goto fail;
+ return;
___perf_sw_event(event_id, nr, regs, addr);
-
perf_swevent_put_recursion_context(rctx);
-fail:
- preempt_enable_notrace();
}
static void perf_swevent_read(struct perf_event *event)
@@ -9844,21 +9839,17 @@ static int swevent_hlist_get_cpu(int cpu
struct swevent_htable *swhash = &per_cpu(swevent_htable, cpu);
int err = 0;
- mutex_lock(&swhash->hlist_mutex);
+ guard(mutex)(&swhash->hlist_mutex);
if (!swevent_hlist_deref(swhash) &&
cpumask_test_cpu(cpu, perf_online_mask)) {
struct swevent_hlist *hlist;
hlist = kzalloc(sizeof(*hlist), GFP_KERNEL);
- if (!hlist) {
- err = -ENOMEM;
- goto exit;
- }
+ if (!hlist)
+ return -ENOMEM;
rcu_assign_pointer(swhash->swevent_hlist, hlist);
}
swhash->hlist_refcount++;
-exit:
- mutex_unlock(&swhash->hlist_mutex);
return err;
}
@@ -10115,16 +10106,12 @@ void perf_tp_event(u16 event_type, u64 c
if (task && task != current) {
struct perf_event_context *ctx;
- rcu_read_lock();
+ guard(rcu)();
ctx = rcu_dereference(task->perf_event_ctxp);
- if (!ctx)
- goto unlock;
-
- raw_spin_lock(&ctx->lock);
- perf_tp_event_target_task(count, record, regs, &data, ctx);
- raw_spin_unlock(&ctx->lock);
-unlock:
- rcu_read_unlock();
+ if (ctx) {
+ guard(raw_spinlock)(&ctx->lock);
+ perf_tp_event_target_task(count, record, regs, &data, ctx);
+ }
}
perf_swevent_put_recursion_context(rctx);
Powered by blists - more mailing lists