Messages in this thread | | | Date | Fri, 5 Apr 2019 09:13:33 +0200 | From | Peter Zijlstra <> | Subject | Re: [PATCH 3/3] perf/x86/intel: force resched when TFA sysctl is modified |
| |
On Thu, Apr 04, 2019 at 11:32:19AM -0700, Stephane Eranian wrote: > diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c > index a4b7711ef0ee..8d356c2096bc 100644 > --- a/arch/x86/events/intel/core.c > +++ b/arch/x86/events/intel/core.c > @@ -4483,6 +4483,60 @@ static ssize_t freeze_on_smi_store(struct device *cdev, > return count; > } > > +static void update_tfa_sched(void *ignored) > +{ > + struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events); > + struct pmu *pmu = x86_get_pmu(); > + struct perf_cpu_context *cpuctx = this_cpu_ptr(pmu->pmu_cpu_context); > + struct perf_event_context *task_ctx = cpuctx->task_ctx; > + > + /* prevent any changes to the two contexts */ > + perf_ctx_lock(cpuctx, task_ctx); > + > + /* > + * check if PMC3 is used > + * and if so force schedule out for all event types all contexts > + */ > + if (test_bit(3, cpuc->active_mask)) > + perf_ctx_resched(cpuctx, task_ctx, EVENT_ALL|EVENT_CPU); > + > + perf_ctx_unlock(cpuctx, task_ctx);
I'm not particularly happy with exporting all that. Can't we create this new perf_ctx_resched() to include the locking and everything. Then the above reduces to:
if (test_bit(3, cpuc->active_mask)) perf_ctx_resched(cpuctx);
And we don't get to export the tricky bits.
> +} > + > +static ssize_t show_sysctl_tfa(struct device *cdev, > + struct device_attribute *attr, > + char *buf) > +{ > + return snprintf(buf, 40, "%d\n", allow_tsx_force_abort); > +} > + > +static ssize_t set_sysctl_tfa(struct device *cdev, > + struct device_attribute *attr, > + const char *buf, size_t count) > +{ > + unsigned long val; > + ssize_t ret; > + > + ret = kstrtoul(buf, 0, &val);
You want kstrtobool()
> + if (ret) > + return ret; > + > + /* looking for boolean value */ > + if (val > 2) > + return -EINVAL; > + > + /* no change */ > + if (val == allow_tsx_force_abort) > + return count; > + > + allow_tsx_force_abort ^= 1;
allow_tsx_force_abort = val;
is simpler
> + > + on_each_cpu(update_tfa_sched, NULL, 1); > + > + return count; > +}
| |