Re: [PATCH] perf: Fix missing SIGTRAPs
From: Peter Zijlstra
Date: Sat Oct 08 2022 - 10:08:33 EST
On Sat, Oct 08, 2022 at 03:51:24PM +0200, Peter Zijlstra wrote:
> On Fri, Oct 07, 2022 at 03:58:03PM +0200, Marco Elver wrote:
> > diff --git a/kernel/events/core.c b/kernel/events/core.c
> > index 9319af6013f1..7de83c42d312 100644
> > --- a/kernel/events/core.c
> > +++ b/kernel/events/core.c
> > @@ -2285,9 +2285,10 @@ event_sched_out(struct perf_event *event,
> > */
> > local_dec(&event->ctx->nr_pending);
> > } else {
> > - WARN_ON_ONCE(event->pending_work);
> > - event->pending_work = 1;
> > - task_work_add(current, &event->pending_task, TWA_RESUME);
> > + if (!event->pending_work) {
> > + event->pending_work = 1;
> > + task_work_add(current, &event->pending_task, TWA_RESUME);
> > + }
> else {
> local_dec(&event->ctx->nr_pending);
> }
> > }
> > }
>
> That whole thing can be written much saner like:
>
> if (event->pending_sigtrap) {
> event->pending_sigtrap = 0;
> if (state != PERF_EVENT_STATE_OFF &&
> !event->pending_work) {
> event->pending_work = 1;
> local_inc(&event->ctx->nr_pending);
> task_work_add(current, &event->pending_task, TWA_RESUME);
> }
> local_dec(&event->ctx->nr_pending);
> }
>
> Except now we have two nr_pending ops -- I'm torn.
I've settled for:
+ if (event->pending_sigtrap) {
+ bool dec = true;
+
+ event->pending_sigtrap = 0;
+ if (state != PERF_EVENT_STATE_OFF &&
+ !event->pending_work) {
+ event->pending_work = 1;
+ dec = false;
+ task_work_add(current, &event->pending_task, TWA_RESUME);
+ }
+ if (dec)
+ local_dec(&event->ctx->nr_pending);
+ }