All of lore.kernel.org
 help / color / mirror / Atom feed
From: kan.liang@linux.intel.com
To: peterz@infradead.org, mingo@redhat.com, linux-kernel@vger.kernel.org
Cc: irogers@google.com, eranian@google.com, ak@linux.intel.com,
	Kan Liang <kan.liang@linux.intel.com>
Subject: [PATCH] perf/core: Fix endless multiplex timer
Date: Tue,  3 Mar 2020 12:28:19 -0800	[thread overview]
Message-ID: <20200303202819.3942-1-kan.liang@linux.intel.com> (raw)

From: Kan Liang <kan.liang@linux.intel.com>

A lot of time are spent in writing uncore MSRs even though no perf is
running.

  4.66%  swapper      [kernel.kallsyms]        [k] native_write_msr
            |
             --4.56%--native_write_msr
                       |
                       |--1.68%--snbep_uncore_msr_enable_box
                       |          perf_mux_hrtimer_handler
                       |          __hrtimer_run_queues
                       |          hrtimer_interrupt
                       |          smp_apic_timer_interrupt
                       |          apic_timer_interrupt
                       |          cpuidle_enter_state
                       |          cpuidle_enter
                       |          do_idle
                       |          cpu_startup_entry
                       |          start_kernel
                       |          secondary_startup_64

The root cause is that multiplex timer was not stopped when perf stat
finished.
Current perf relies on rotate_necessary to determine whether the
multiplex timer should be stopped. The variable only be reset in
ctx_sched_out(), which is not enough for system-wide event.
Perf stat invokes PERF_EVENT_IOC_DISABLE to stop system-wide event
before closing it.
  perf_ioctl()
    perf_event_disable()
      event_sched_out()
The rotate_necessary will never be reset.

The issue is a generic issue, not just impact the uncore.

Check whether we had been multiplexing. If yes, reset rotate_necessary
for the last active event in __perf_event_disable().

Fixes: fd7d55172d1e ("perf/cgroups: Don't rotate events for cgroups unnecessarily")
Reported-by: Andi Kleen <ak@linux.intel.com>
Reviewed-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
---
 kernel/events/core.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index 3f1f77de7247..50688de56181 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -2242,6 +2242,16 @@ static void __perf_event_disable(struct perf_event *event,
 		update_cgrp_time_from_event(event);
 	}
 
+	/*
+	 * If we had been multiplexing,
+	 * stop the rotations for the last active event.
+	 * Only need to check system wide events.
+	 * For task events, it will be checked in ctx_sched_out().
+	 */
+	if ((cpuctx->ctx.nr_events != cpuctx->ctx.nr_active) &&
+	    (cpuctx->ctx.nr_active == 1))
+		cpuctx->ctx.rotate_necessary = 0;
+
 	if (event == event->group_leader)
 		group_sched_out(event, cpuctx, ctx);
 	else
-- 
2.17.1


             reply	other threads:[~2020-03-03 20:29 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-03 20:28 kan.liang [this message]
2020-03-03 21:08 ` [PATCH] perf/core: Fix endless multiplex timer Peter Zijlstra
2020-03-04  1:40   ` Liang, Kan
2020-03-04  9:33     ` Peter Zijlstra
2020-03-04 14:20       ` Liang, Kan
2020-03-05 12:38         ` Peter Zijlstra
2020-03-05 17:56           ` Liang, Kan
2020-03-20 12:58           ` [tip: perf/core] " tip-bot2 for Peter Zijlstra
2020-08-06 18:11             ` Robin Murphy
2020-08-06 18:53               ` Greg KH
2020-08-06 20:40                 ` Robin Murphy
2020-03-24  6:00 ` [perf/core] 92b1f046a2: BUG:kernel_NULL_pointer_dereference, address kernel test robot
2020-03-24  6:00   ` [perf/core] 92b1f046a2: BUG:kernel_NULL_pointer_dereference,address kernel test robot
2020-03-24 12:52   ` [perf/core] 92b1f046a2: BUG:kernel_NULL_pointer_dereference, address Liang, Kan
2020-03-24 12:52     ` [perf/core] 92b1f046a2: BUG:kernel_NULL_pointer_dereference,address Liang, Kan

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=20200303202819.3942-1-kan.liang@linux.intel.com \
    --to=kan.liang@linux.intel.com \
    --cc=ak@linux.intel.com \
    --cc=eranian@google.com \
    --cc=irogers@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.