Re: [PATCH v4 2/2] perf: add sysfs entry to adjust multiplexinginterval per PMU

From: Jiri Olsa
Date: Tue Feb 19 2013 - 14:24:59 EST


On Mon, Feb 18, 2013 at 06:54:44PM +0100, Stephane Eranian wrote:

SNIP

> +perf_event_mux_interval_ms_store(struct device *dev,
> + struct device_attribute *attr,
> + const char *buf, size_t count)
> +{
> + struct pmu *pmu = dev_get_drvdata(dev);
> + int timer, cpu, ret;
> +
> + ret = kstrtoint(buf, 0, &timer);
> + if (ret)
> + return ret;
> +
> + if (timer < 1)
> + return -EINVAL;
> +
> + 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);
> + }

If we set the timer to some big value like few minutes,
then run the meassurements and then set the value back to 1,
we actually need to wait till the big timer is expired before
the new value takes place.

I think we need to cancel the possible running timer in here
like in the atached patch, but maybe consider some locking.

jirka


diff --git a/kernel/events/core.c b/kernel/events/core.c
index 7c3f00f..ce9cd54 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -6038,6 +6038,9 @@ perf_event_mux_interval_ms_store(struct device *dev,
struct perf_cpu_context *cpuctx;
cpuctx = per_cpu_ptr(pmu->pmu_cpu_context, cpu);
cpuctx->hrtimer_interval = ns_to_ktime(NSEC_PER_MSEC * timer);
+
+ if (hrtimer_active(&cpuctx->hrtimer))
+ hrtimer_cancel(&cpuctx->hrtimer);
}

return count;
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/