linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: stable@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: "David S. Miller" <davem@davemloft.net>, Sasha Levin <sashal@kernel.org>
Subject: [PATCH AUTOSEL 4.14 06/19] sparc: Fix single-pcr perf event counter management.
Date: Tue, 30 Oct 2018 09:28:11 -0400	[thread overview]
Message-ID: <20181030132824.218056-6-sashal@kernel.org> (raw)
In-Reply-To: <20181030132824.218056-1-sashal@kernel.org>

From: "David S. Miller" <davem@davemloft.net>

[ Upstream commit cfdc3170d214046b9509183fe9b9544dc644d40b ]

It is important to clear the hw->state value for non-stopped events
when they are added into the PMU.  Otherwise when the event is
scheduled out, we won't read the counter because HES_UPTODATE is still
set.  This breaks 'perf stat' and similar use cases, causing all the
events to show zero.

This worked for multi-pcr because we make explicit sparc_pmu_start()
calls in calculate_multiple_pcrs().  calculate_single_pcr() doesn't do
this because the idea there is to accumulate all of the counter
settings into the single pcr value.  So we have to add explicit
hw->state handling there.

Like x86, we use the PERF_HES_ARCH bit to track truly stopped events
so that we don't accidently start them on a reload.

Related to all of this, sparc_pmu_start() is missing a userpage update
so add it.

Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 arch/sparc/kernel/perf_event.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/arch/sparc/kernel/perf_event.c b/arch/sparc/kernel/perf_event.c
index 5c1f54758312..8a569b09d2c2 100644
--- a/arch/sparc/kernel/perf_event.c
+++ b/arch/sparc/kernel/perf_event.c
@@ -927,6 +927,8 @@ static void read_in_all_counters(struct cpu_hw_events *cpuc)
 			sparc_perf_event_update(cp, &cp->hw,
 						cpuc->current_idx[i]);
 			cpuc->current_idx[i] = PIC_NO_INDEX;
+			if (cp->hw.state & PERF_HES_STOPPED)
+				cp->hw.state |= PERF_HES_ARCH;
 		}
 	}
 }
@@ -959,10 +961,12 @@ static void calculate_single_pcr(struct cpu_hw_events *cpuc)
 
 		enc = perf_event_get_enc(cpuc->events[i]);
 		cpuc->pcr[0] &= ~mask_for_index(idx);
-		if (hwc->state & PERF_HES_STOPPED)
+		if (hwc->state & PERF_HES_ARCH) {
 			cpuc->pcr[0] |= nop_for_index(idx);
-		else
+		} else {
 			cpuc->pcr[0] |= event_encoding(enc, idx);
+			hwc->state = 0;
+		}
 	}
 out:
 	cpuc->pcr[0] |= cpuc->event[0]->hw.config_base;
@@ -988,6 +992,9 @@ static void calculate_multiple_pcrs(struct cpu_hw_events *cpuc)
 
 		cpuc->current_idx[i] = idx;
 
+		if (cp->hw.state & PERF_HES_ARCH)
+			continue;
+
 		sparc_pmu_start(cp, PERF_EF_RELOAD);
 	}
 out:
@@ -1079,6 +1086,8 @@ static void sparc_pmu_start(struct perf_event *event, int flags)
 	event->hw.state = 0;
 
 	sparc_pmu_enable_event(cpuc, &event->hw, idx);
+
+	perf_event_update_userpage(event);
 }
 
 static void sparc_pmu_stop(struct perf_event *event, int flags)
@@ -1371,9 +1380,9 @@ static int sparc_pmu_add(struct perf_event *event, int ef_flags)
 	cpuc->events[n0] = event->hw.event_base;
 	cpuc->current_idx[n0] = PIC_NO_INDEX;
 
-	event->hw.state = PERF_HES_UPTODATE;
+	event->hw.state = PERF_HES_UPTODATE | PERF_HES_STOPPED;
 	if (!(ef_flags & PERF_EF_START))
-		event->hw.state |= PERF_HES_STOPPED;
+		event->hw.state |= PERF_HES_ARCH;
 
 	/*
 	 * If group events scheduling transaction was started,
-- 
2.17.1


  parent reply	other threads:[~2018-10-30 13:28 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-30 13:28 [PATCH AUTOSEL 4.14 01/19] bpf: do not blindly change rlimit in reuseport net selftest Sasha Levin
2018-10-30 13:28 ` [PATCH AUTOSEL 4.14 02/19] Revert "perf tools: Fix PMU term format max value calculation" Sasha Levin
2018-10-30 13:28 ` [PATCH AUTOSEL 4.14 03/19] net/mlx5: Take only bit 24-26 of wqe.pftype_wq for page fault type Sasha Levin
2018-10-30 13:28 ` [PATCH AUTOSEL 4.14 04/19] xfrm: policy: use hlist rcu variants on insert Sasha Levin
2018-10-30 13:28 ` [PATCH AUTOSEL 4.14 05/19] perf vendor events intel: Fix wrong filter_band* values for uncore events Sasha Levin
2018-10-30 13:28 ` Sasha Levin [this message]
2018-10-30 13:28 ` [PATCH AUTOSEL 4.14 07/19] sparc: Throttle perf events properly Sasha Levin
2018-10-30 13:28 ` [PATCH AUTOSEL 4.14 08/19] sparc64: Make proc_id signed Sasha Levin
2018-10-30 13:28 ` [PATCH AUTOSEL 4.14 09/19] net: fec: don't dump RX FIFO register when not available Sasha Levin
2018-10-30 13:28 ` [PATCH AUTOSEL 4.14 10/19] sched/fair: Fix the min_vruntime update logic in dequeue_entity() Sasha Levin
2018-10-30 13:28 ` [PATCH AUTOSEL 4.14 11/19] perf tools: Fix use of alternatives to find JDIR Sasha Levin
2018-10-30 13:28 ` [PATCH AUTOSEL 4.14 12/19] perf cpu_map: Align cpu map synthesized events properly Sasha Levin
2018-10-30 13:28 ` [PATCH AUTOSEL 4.14 13/19] x86/fpu: Remove second definition of fpu in __fpu__restore_sig() Sasha Levin
2018-10-30 13:28 ` [PATCH AUTOSEL 4.14 14/19] net: qla3xxx: Remove overflowing shift statement Sasha Levin
2018-10-30 13:28 ` [PATCH AUTOSEL 4.14 15/19] virtio_net: avoid using netif_tx_disable() for serializing tx routine Sasha Levin
2018-10-30 13:28 ` [PATCH AUTOSEL 4.14 16/19] r8169: fix NAPI handling under high load Sasha Levin
2018-10-30 13:28 ` [PATCH AUTOSEL 4.14 17/19] selftests: ftrace: Add synthetic event syntax testcase Sasha Levin
2018-10-30 14:58   ` Steven Rostedt
2018-10-30 18:21     ` Sasha Levin
2018-11-01 17:34       ` Masami Hiramatsu
2018-10-30 13:28 ` [PATCH AUTOSEL 4.14 18/19] net: fix pskb_trim_rcsum_slow() with odd trim offset Sasha Levin
2018-10-30 13:28 ` [PATCH AUTOSEL 4.14 19/19] i2c: rcar: cleanup DMA for all kinds of failure Sasha Levin

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=20181030132824.218056-6-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=davem@davemloft.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).