mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mark Rutland <mark.rutland@arm.com>
To: linux-kernel@vger.kernel.org
Cc: will.deacon@arm.com, dave.martin@arm.com,
	Mark Rutland <mark.rutland@arm.com>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Ingo Molnar <mingo@redhat.com>
Subject: [PATCH 5/7] perf: kill pmu::hrtimer_interval_ms
Date: Mon, 10 Feb 2014 17:44:22 +0000	[thread overview]
Message-ID: <1392054264-23570-6-git-send-email-mark.rutland@arm.com> (raw)
In-Reply-To: <1392054264-23570-1-git-send-email-mark.rutland@arm.com>

The hrtimers affecting a pmu live in perf_cpu_context, which may be
shared by multiple pmus. As such it does not make sense for the pmu to
track the interval, which is a property of the shared context.

This patch removes pmu::hrtimer_interval_ms, and reworks all existing
users to use perf_cpu_context::hrtimer_interval instead. No pmu
implementations currently override the default hrtimer_interval_ms
statically, so we don't lose any existing implementation-specific
intervals (which could themselves be problematic if two pmus had
different hrtimer_interval_ms values).

While we're in the area we also replace uses of
ns_to_ktime(NSEC_PER_MSEC * $x) with ms_to_ktime($x), which does the
same thing.

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Reviewed-by: Dave Martin <Dave.Martin@arm.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Ingo Molnar <mingo@redhat.com>
---
 include/linux/perf_event.h |  1 -
 kernel/events/core.c       | 24 +++++++++++++-----------
 2 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index df3d34a..7794a39 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -180,7 +180,6 @@ struct pmu {
 	int * __percpu			pmu_disable_count;
 	struct perf_cpu_context * __percpu pmu_cpu_context;
 	int				task_ctx_nr;
-	int				hrtimer_interval_ms;
 
 	/*
 	 * Fully disable/enable this PMU, can be used to protect from the PMI
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 13ede70..710c3fe 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -816,14 +816,11 @@ static void __perf_cpu_hrtimer_init(struct perf_cpu_context *cpuctx, int cpu)
 		return;
 
 	/*
-	 * check default is sane, if not set then force to
-	 * default interval (1/tick)
+	 * Set sane default interval (1/tick)
 	 */
-	timer = pmu->hrtimer_interval_ms;
-	if (timer < 1)
-		timer = pmu->hrtimer_interval_ms = PERF_CPU_HRTIMER;
+	timer = PERF_CPU_HRTIMER;
 
-	cpuctx->hrtimer_interval = ns_to_ktime(NSEC_PER_MSEC * timer);
+	cpuctx->hrtimer_interval = ms_to_ktime(timer);
 
 	hrtimer_init(hr, CLOCK_MONOTONIC, HRTIMER_MODE_REL_PINNED);
 	hr->function = perf_cpu_hrtimer_handler;
@@ -6346,14 +6343,21 @@ type_show(struct device *dev, struct device_attribute *attr, char *page)
 }
 static DEVICE_ATTR_RO(type);
 
+static int get_pmu_hrtimer_interval(struct pmu *pmu)
+{
+	struct perf_cpu_context *cpu_ctx = this_cpu_ptr(pmu->pmu_cpu_context);
+	return ktime_to_ms(cpu_ctx->hrtimer_interval);
+}
+
 static ssize_t
 perf_event_mux_interval_ms_show(struct device *dev,
 				struct device_attribute *attr,
 				char *page)
 {
 	struct pmu *pmu = dev_get_drvdata(dev);
+	int interval_ms = get_pmu_hrtimer_interval(pmu);
 
-	return snprintf(page, PAGE_SIZE-1, "%d\n", pmu->hrtimer_interval_ms);
+	return snprintf(page, PAGE_SIZE-1, "%d\n", interval_ms);
 }
 
 static ssize_t
@@ -6372,16 +6376,14 @@ perf_event_mux_interval_ms_store(struct device *dev,
 		return -EINVAL;
 
 	/* same value, noting to do */
-	if (timer == pmu->hrtimer_interval_ms)
+	if (timer == get_pmu_hrtimer_interval(pmu))
 		return count;
 
-	pmu->hrtimer_interval_ms = timer;
-
 	/* update all cpuctx for this PMU */
 	for_each_possible_cpu(cpu) {
 		struct perf_cpu_context *cpuctx;
 		cpuctx = per_cpu_ptr(pmu->pmu_cpu_context, cpu);
-		cpuctx->hrtimer_interval = ns_to_ktime(NSEC_PER_MSEC * timer);
+		cpuctx->hrtimer_interval = ms_to_ktime(timer);
 
 		if (hrtimer_active(&cpuctx->hrtimer))
 			hrtimer_forward_now(&cpuctx->hrtimer, cpuctx->hrtimer_interval);
-- 
1.8.1.1


  parent reply	other threads:[~2014-02-10 17:45 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-10 17:44 [PATCH 0/7] Perf core cleanups for shared perf_event_contexts Mark Rutland
2014-02-10 17:44 ` [PATCH 1/7] perf: fix prototype of find_pmu_context Mark Rutland
2014-02-27 13:33   ` [tip:perf/core] perf: Fix prototype of find_pmu_context() tip-bot for Mark Rutland
2014-02-10 17:44 ` [PATCH 2/7] perf: remove redundant pmu assignment Mark Rutland
2014-02-27 13:33   ` [tip:perf/core] perf: Remove redundant PMU assignment tip-bot for Mark Rutland
2014-02-10 17:44 ` [PATCH 3/7] perf: kill perf_event_context_type Mark Rutland
2014-02-25 11:38   ` Peter Zijlstra
2014-02-27 11:46     ` Mark Rutland
2014-02-10 17:44 ` [PATCH 4/7] perf: be less pessimistic when scheduling events Mark Rutland
2014-02-10 17:58   ` Peter Zijlstra
2014-02-11 17:48     ` Mark Rutland
2014-02-25 11:29       ` Peter Zijlstra
2014-02-27 12:07         ` Mark Rutland
2014-02-10 17:44 ` Mark Rutland [this message]
2014-02-10 17:44 ` [PATCH 6/7] perf: Centralise context pmu disabling Mark Rutland
2014-02-10 18:08   ` Peter Zijlstra
2014-02-10 17:44 ` [PATCH 7/7] perf: kill perf_event_context::pmu Mark Rutland
2014-02-10 18:10   ` Peter Zijlstra
2014-02-11 17:56     ` Mark Rutland
2014-02-12 15:01       ` Dave Martin
2014-02-25 11:31       ` Peter Zijlstra
2014-02-27 11:48         ` Mark Rutland
2014-02-27 11:51           ` Peter Zijlstra
2014-02-27 12:30             ` Mark Rutland
2014-02-19 13:43 ` [PATCH 0/7] Perf core cleanups for shared perf_event_contexts Mark Rutland
2014-02-25 11:39   ` Peter Zijlstra

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=1392054264-23570-6-git-send-email-mark.rutland@arm.com \
    --to=mark.rutland@arm.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=dave.martin@arm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=will.deacon@arm.com \
    /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®