public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Song Liu <songliubraving@fb.com>
Cc: linux-kernel@vger.kernel.org, kernel-team@fb.com,
	stable@vger.kernel.org,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>
Subject: Re: [PATCH] perf/core: fix corner case in perf_rotate_context()
Date: Tue, 8 Oct 2019 11:35:54 +0200	[thread overview]
Message-ID: <20191008093554.GK2294@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20191003064317.3961135-1-songliubraving@fb.com>

On Wed, Oct 02, 2019 at 11:43:17PM -0700, Song Liu wrote:
> This is a rare corner case, but it does happen:
> 
> In perf_rotate_context(), when the first cpu flexible event fail to
> schedule, cpu_rotate is 1, while cpu_event is NULL.

You're failing to explain how we get here in the first place.

> diff --git a/kernel/events/core.c b/kernel/events/core.c
> index 4655adbbae10..50021735f367 100644
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -3775,6 +3775,13 @@ static void rotate_ctx(struct perf_event_context *ctx, struct perf_event *event)
>  	if (ctx->rotate_disable)
>  		return;
>  
> +	/* if no event specified, try to rotate the first event */
> +	if (!event)
> +		event = rb_entry_safe(rb_first(&ctx->flexible_groups.tree),
> +				      typeof(*event), group_node);
> +	if (!event)
> +		return;
> +
>  	perf_event_groups_delete(&ctx->flexible_groups, event);
>  	perf_event_groups_insert(&ctx->flexible_groups, event);
>  }

I don't think that is a very nice solution; would not something simpler
like this be sufficient? (although possible we should rename that
function now).

And it needs more comments.

diff --git a/kernel/events/core.c b/kernel/events/core.c
index 4655adbbae10..772a9854eb3a 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -3782,8 +3797,17 @@ static void rotate_ctx(struct perf_event_context *ctx, struct perf_event *event)
 static inline struct perf_event *
 ctx_first_active(struct perf_event_context *ctx)
 {
-	return list_first_entry_or_null(&ctx->flexible_active,
-					struct perf_event, active_list);
+	struct perf_event *event;
+
+	event = list_first_entry_or_null(&ctx->flexible_active,
+					 struct perf_event, active_list);
+
+	if (!event) {
+		event = rb_entry_safe(rb_first(&ctx->flexible_groups.tree),
+				      typeof(*event), group_node);
+	}
+
+	return event;
 }
 
 static bool perf_rotate_context(struct perf_cpu_context *cpuctx)

  parent reply	other threads:[~2019-10-08  9:36 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-03  6:43 [PATCH] perf/core: fix corner case in perf_rotate_context() Song Liu
2019-10-06  6:09 ` Song Liu
2019-10-08  8:57 ` [perf/core] a449d92620: vm-scalability.median -6.8% regression kernel test robot
2019-10-08  9:35 ` Peter Zijlstra [this message]
2019-10-08 14:03   ` [PATCH] perf/core: fix corner case in perf_rotate_context() Song Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191008093554.GK2294@hirez.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=acme@kernel.org \
    --cc=kernel-team@fb.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=songliubraving@fb.com \
    --cc=stable@vger.kernel.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox