mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Stephane Eranian <eranian@google.com>
Cc: linux-kernel@vger.kernel.org, tglx@linutronix.de,
	ak@linux.intel.com, kan.liang@intel.com, mingo@elte.hu,
	nelson.dsouza@intel.com, jolsa@redhat.com, tonyj@suse.com
Subject: Re: [PATCH 3/3] perf/x86/intel: force resched when TFA sysctl is modified
Date: Fri, 5 Apr 2019 09:13:33 +0200	[thread overview]
Message-ID: <20190405071333.GB4038@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20190404183219.125083-4-eranian@google.com>

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;
> +}

  reply	other threads:[~2019-04-05  7:55 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-04 18:32 [PATCH 0/3] perf/x86/intel: force reschedule on TFA changes Stephane Eranian
2019-04-04 18:32 ` [PATCH 1/3] perf/core: make perf_ctx_*lock() global inline functions Stephane Eranian
2019-04-04 18:32 ` [PATCH 2/3] perf/core: make ctx_resched() a global function Stephane Eranian
2019-04-04 18:32 ` [PATCH 3/3] perf/x86/intel: force resched when TFA sysctl is modified Stephane Eranian
2019-04-05  7:13   ` Peter Zijlstra [this message]
2019-04-05 17:00     ` Stephane Eranian
2019-04-05 20:26       ` Peter Zijlstra
2019-04-06  0:49         ` Stephane Eranian

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=20190405071333.GB4038@hirez.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=ak@linux.intel.com \
    --cc=eranian@google.com \
    --cc=jolsa@redhat.com \
    --cc=kan.liang@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=nelson.dsouza@intel.com \
    --cc=tglx@linutronix.de \
    --cc=tonyj@suse.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®