mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Song Liu <songliubraving@fb.com>
To: open list <linux-kernel@vger.kernel.org>,
	Peter Zijlstra <peterz@infradead.org>
Cc: Kernel Team <Kernel-team@fb.com>,
	"stable@vger.kernel.org" <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: Sun, 6 Oct 2019 06:09:29 +0000	[thread overview]
Message-ID: <C0355084-8227-4380-AF6F-EEBFC0BE6E37@fb.com> (raw)
In-Reply-To: <20191003064317.3961135-1-songliubraving@fb.com>



> On Oct 2, 2019, at 11:43 PM, Song Liu <songliubraving@fb.com> 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. Since cpu_event is
> NULL, perf_rotate_context will _NOT_ call cpu_ctx_sched_out(), thus
> cpuctx->ctx.is_active will have EVENT_FLEXIBLE set. Then, the next
> perf_event_sched_in() will skip all cpu flexible events because of the
> EVENT_FLEXIBLE bit.
> 
> In the next call of perf_rotate_context(), cpu_rotate stays 1, and
> cpu_event stays NULL, so this process repeats. The end result is, flexible
> events on this cpu will not be scheduled (until another event being added
> to the cpuctx).
> 
> Similar issue may happen with the task_ctx. But it is usually not a
> problem because the task_ctx moves around different CPU.
> 
> Fix this corner case by using cpu_rotate and task_rotate to gate calls for
> (cpu_)ctx_sched_out and rotate_ctx. Also enable rotate_ctx() to handle
> event == NULL case.

Here is an easy repro of this issue. On Intel CPUs, where ref-cycles 
could only use one counter, run one pinned event for ref-cycles, one
flexible event for ref-cycles, and one flexible event for cycles. The 
flexible ref-cycles is never scheduled, which is expected. However, 
because of this issue, the cycle event is never scheduled either. 

perf stat -e ref-cycles:D,ref-cycles,cycles -C 5 -I 1000
#           time             counts unit events
     1.000152973         15,412,480      ref-cycles:D
     1.000152973      <not counted>      ref-cycles     (0.00%)
     1.000152973      <not counted>      cycles         (0.00%)
     2.000486957         18,263,120      ref-cycles:D
     2.000486957      <not counted>      ref-cycles     (0.00%)
     2.000486957      <not counted>      cycles         (0.00%)

Thanks,
Song


  reply	other threads:[~2019-10-06  6:09 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-03  6:43 Song Liu
2019-10-06  6:09 ` Song Liu [this message]
2019-10-08  8:57 ` [perf/core] a449d92620: vm-scalability.median -6.8% regression kernel test robot
2019-10-08  9:35 ` [PATCH] perf/core: fix corner case in perf_rotate_context() Peter Zijlstra
2019-10-08 14:03   ` 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=C0355084-8227-4380-AF6F-EEBFC0BE6E37@fb.com \
    --to=songliubraving@fb.com \
    --cc=Kernel-team@fb.com \
    --cc=acme@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterz@infradead.org \
    --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

all inboxes | Powered by JetHome®