All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stephane Eranian <eranian@google.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Andi Kleen <ak@linux.intel.com>,
	"Liang, Kan" <kan.liang@intel.com>,
	mingo@elte.hu, nelson.dsouza@intel.com,
	Jiri Olsa <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 10:00:03 -0700	[thread overview]
Message-ID: <CABPqkBTzBYSN_k6FV=iOmmBfZWmG2N9fYHke_MdiCCgO=KFeUw@mail.gmail.com> (raw)
In-Reply-To: <20190405071333.GB4038@hirez.programming.kicks-ass.net>

On Fri, Apr 5, 2019 at 12:13 AM Peter Zijlstra <peterz@infradead.org> wrote:
>
> 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.
>
The only reason I exported the locking is to protect
cpuc->active_mask. But if you
think there is no race, then sure,  we can just export a new
perf_ctx_resched() that
does the locking and invokes the ctx_resched() function.

> > +}
> > +
> > +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()
>
ok.

> > +     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
>
ok.

> > +
> > +     on_each_cpu(update_tfa_sched, NULL, 1);
> > +
> > +     return count;
> > +}

  reply	other threads:[~2019-04-05 17:00 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
2019-04-05 17:00     ` Stephane Eranian [this message]
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='CABPqkBTzBYSN_k6FV=iOmmBfZWmG2N9fYHke_MdiCCgO=KFeUw@mail.gmail.com' \
    --to=eranian@google.com \
    --cc=ak@linux.intel.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=peterz@infradead.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.