aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/events
diff options
context:
space:
mode:
authorStephane Eranian <eranian@google.com>2013-04-03 08:21:34 -0400
committerIngo Molnar <mingo@kernel.org>2013-05-28 03:13:51 -0400
commit62b8563979273424d6ebe9201e34d1acc133ad4f (patch)
tree913ae791ea01842768a0a71a472779a62fc6ddcc /kernel/events
parent9e6302056f8029f438e853432a856b9f13de26a6 (diff)
perf: Add sysfs entry to adjust multiplexing interval per PMU
This patch adds /sys/device/xxx/perf_event_mux_interval_ms to ajust the multiplexing interval per PMU. The unit is milliseconds. Value has to be >= 1. In the 4th version, we renamed the sysfs file to be more consistent with the other /proc/sys/kernel entries for perf_events. In the 5th version, we handle the reprogramming of the hrtimer using hrtimer_forward_now(). That way, we sync up to new timer value quickly (suggested by Jiri Olsa). Signed-off-by: Stephane Eranian <eranian@google.com> Signed-off-by: Peter Zijlstra <peterz@infradead.org> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Arnaldo Carvalho de Melo <acme@redhat.com> Link: http://lkml.kernel.org/r/1364991694-5876-3-git-send-email-eranian@google.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'kernel/events')
-rw-r--r--kernel/events/core.c63
1 files changed, 59 insertions, 4 deletions
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 97bfac7e6f45..53d1b300116a 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -723,13 +723,21 @@ static void __perf_cpu_hrtimer_init(struct perf_cpu_context *cpuctx, int cpu)
723{ 723{
724 struct hrtimer *hr = &cpuctx->hrtimer; 724 struct hrtimer *hr = &cpuctx->hrtimer;
725 struct pmu *pmu = cpuctx->ctx.pmu; 725 struct pmu *pmu = cpuctx->ctx.pmu;
726 int timer;
726 727
727 /* no multiplexing needed for SW PMU */ 728 /* no multiplexing needed for SW PMU */
728 if (pmu->task_ctx_nr == perf_sw_context) 729 if (pmu->task_ctx_nr == perf_sw_context)
729 return; 730 return;
730 731
731 cpuctx->hrtimer_interval = 732 /*
732 ns_to_ktime(NSEC_PER_MSEC * PERF_CPU_HRTIMER); 733 * check default is sane, if not set then force to
734 * default interval (1/tick)
735 */
736 timer = pmu->hrtimer_interval_ms;
737 if (timer < 1)
738 timer = pmu->hrtimer_interval_ms = PERF_CPU_HRTIMER;
739
740 cpuctx->hrtimer_interval = ns_to_ktime(NSEC_PER_MSEC * timer);
733 741
734 hrtimer_init(hr, CLOCK_MONOTONIC, HRTIMER_MODE_REL_PINNED); 742 hrtimer_init(hr, CLOCK_MONOTONIC, HRTIMER_MODE_REL_PINNED);
735 hr->function = perf_cpu_hrtimer_handler; 743 hr->function = perf_cpu_hrtimer_handler;
@@ -6001,9 +6009,56 @@ type_show(struct device *dev, struct device_attribute *attr, char *page)
6001 return snprintf(page, PAGE_SIZE-1, "%d\n", pmu->type); 6009 return snprintf(page, PAGE_SIZE-1, "%d\n", pmu->type);
6002} 6010}
6003 6011
6012static ssize_t
6013perf_event_mux_interval_ms_show(struct device *dev,
6014 struct device_attribute *attr,
6015 char *page)
6016{
6017 struct pmu *pmu = dev_get_drvdata(dev);
6018
6019 return snprintf(page, PAGE_SIZE-1, "%d\n", pmu->hrtimer_interval_ms);
6020}
6021
6022static ssize_t
6023perf_event_mux_interval_ms_store(struct device *dev,
6024 struct device_attribute *attr,
6025 const char *buf, size_t count)
6026{
6027 struct pmu *pmu = dev_get_drvdata(dev);
6028 int timer, cpu, ret;
6029
6030 ret = kstrtoint(buf, 0, &timer);
6031 if (ret)
6032 return ret;
6033
6034 if (timer < 1)
6035 return -EINVAL;
6036
6037 /* same value, noting to do */
6038 if (timer == pmu->hrtimer_interval_ms)
6039 return count;
6040
6041 pmu->hrtimer_interval_ms = timer;
6042
6043 /* update all cpuctx for this PMU */
6044 for_each_possible_cpu(cpu) {
6045 struct perf_cpu_context *cpuctx;
6046 cpuctx = per_cpu_ptr(pmu->pmu_cpu_context, cpu);
6047 cpuctx->hrtimer_interval = ns_to_ktime(NSEC_PER_MSEC * timer);
6048
6049 if (hrtimer_active(&cpuctx->hrtimer))
6050 hrtimer_forward_now(&cpuctx->hrtimer, cpuctx->hrtimer_interval);
6051 }
6052
6053 return count;
6054}
6055
6056#define __ATTR_RW(attr) __ATTR(attr, 0644, attr##_show, attr##_store)
6057
6004static struct device_attribute pmu_dev_attrs[] = { 6058static struct device_attribute pmu_dev_attrs[] = {
6005 __ATTR_RO(type), 6059 __ATTR_RO(type),
6006 __ATTR_NULL, 6060 __ATTR_RW(perf_event_mux_interval_ms),
6061 __ATTR_NULL,
6007}; 6062};
6008 6063
6009static int pmu_bus_running; 6064static int pmu_bus_running;