mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Robert Richter <robert.richter@amd.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@elte.hu>,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 2/7] perf, x86: Implement IBS initialization
Date: Fri, 12 Aug 2011 19:49:38 +0200	[thread overview]
Message-ID: <20110812174938.GC17199@erda.amd.com> (raw)
In-Reply-To: <1312285741.1147.124.camel@twins>

On 02.08.11 07:49:01, Peter Zijlstra wrote:
> On Thu, 2011-07-28 at 15:46 +0200, Robert Richter wrote:
> > +/*
> > + * This runs only on the current cpu. We try to find an LVT offset and
> > + * setup the local APIC. For this we must disable preemption. On
> > + * success we initialize all nodes with this offset. This updates then
> > + * the offset in the IBS_CTL per-node msr. The per-core APIC setup of
> > + * the IBS interrupt vector is handled by perf_ibs_cpu_notifier that
> > + * is using the new offset.
> > + */
> > +static int force_ibs_eilvt_setup(void)
> > +{
> > +       int offset;
> > +       int ret;
> > +
> > +       preempt_disable();
> > +       /* find the next free available EILVT entry, skip offset 0 */
> > +       for (offset = 1; offset < APIC_EILVT_NR_MAX; offset++) {
> > +               if (get_eilvt(offset))
> > +                       break;
> > +       }
> > +       preempt_enable();
> > +
> > +       if (offset == APIC_EILVT_NR_MAX) {
> > +               printk(KERN_DEBUG "No EILVT entry available\n");
> > +               return -EBUSY;
> > +       }
> > +
> > +       ret = setup_ibs_ctl(offset);
> > +       if (ret)
> > +               goto out;
> > +
> > +       if (!ibs_eilvt_valid()) {
> > +               ret = -EFAULT;
> > +               goto out;
> > +       }
> > +
> > +       pr_err(FW_BUG "using offset %d for IBS interrupts\n", offset);
> > +       pr_err(FW_BUG "workaround enabled for IBS LVT offset\n");
> > +
> > +       return 0;
> > +out:
> > +       preempt_disable();
> > +       put_eilvt(offset);
> > +       preempt_enable();
> > +       return ret;
> > +} 
> 
> So I don't get any of that preempt_disable/enable crap in this patch,
> but the above is esp. confusing. How is that preempt_disable() at out:
> still valid? We could be running on an entirely different cpu from when
> we did get_eilvt at the start.

Yes, this code is strange due to the hardware mixing up per-cpu and
per-node configuration. This code did many iterations in the oprofile
driver.

get/put_eilvt() accesses APIC registers on one *cpu* and then globally
reserves/releases the offset by keeping it in eilvt_offsets[]. To
avoid switching cpus in the middle of an apic access the funcions are
protected with preempt_disable/enable.

setup_ibs_ctl() then sets up this offset on all *nodes*. During node
setup the pci cpu devices are accessed and thus may not be called with
preemption disabled.

The offset is later taken from the per-node msr IBS_CTL and used for a
per-core setup of the NMI vector on each cpu.

It is save to have get_eilvt and put_eilvt on different cpus as the
offset is kept globally.

I was thinking of moving preempt_disable/enable to get/put_eilvt, but
also wanted to avoid switching to a different cpu while searching for
an offset in the for-loop.

-Robert

-- 
Advanced Micro Devices, Inc.
Operating System Research Center


  reply	other threads:[~2011-08-12 17:49 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-28 13:46 [PATCH 0/7] perf, x86: Implement AMD IBS Robert Richter
2011-07-28 13:46 ` [PATCH 1/7] perf, x86: share IBS macros between perf and oprofile Robert Richter
2011-07-28 13:46 ` [PATCH 2/7] perf, x86: Implement IBS initialization Robert Richter
2011-07-29 16:58   ` Peter Zijlstra
2011-08-01  5:27     ` Robert Richter
2011-08-02 11:49   ` Peter Zijlstra
2011-08-12 17:49     ` Robert Richter [this message]
2011-07-28 13:46 ` [PATCH 3/7] perf, x86: Implement IBS event configuration Robert Richter
2011-08-02 11:35   ` Peter Zijlstra
2011-08-12 19:51     ` Robert Richter
2011-07-28 13:46 ` [PATCH 4/7] perf, x86: Implement IBS interrupt handler Robert Richter
2011-07-29 16:58   ` Peter Zijlstra
2011-08-01  5:32     ` Robert Richter
2011-08-01 15:21       ` Peter Zijlstra
2011-08-01 16:38         ` Don Zickus
2011-08-05  9:55           ` Ingo Molnar
2011-08-05 13:47             ` Don Zickus
2011-08-02 11:43   ` Peter Zijlstra
2011-08-12 18:07     ` Robert Richter
2011-07-28 13:46 ` [PATCH 5/7] perf, x86: Implement IBS pmu control ops Robert Richter
2011-07-28 13:46 ` [PATCH 6/7] perf, x86: Example code for AMD IBS Robert Richter
2011-07-29 16:58   ` Peter Zijlstra
2011-08-01  5:50     ` Robert Richter
2011-08-02 10:37       ` Peter Zijlstra
2011-08-03  8:27         ` Michael Cree
2011-08-03 17:56           ` Robert Richter
2011-07-28 13:46 ` [PATCH 7/7] perf, x86: Implement 64 bit counter support for IBS Robert Richter
2011-07-29 16:58   ` Peter Zijlstra
2011-07-29 17:02     ` Peter Zijlstra
2011-08-01  5:55       ` Robert Richter
2011-07-29 17:01   ` Peter Zijlstra
2011-08-01  6:13     ` Robert Richter
2011-08-02 11:37   ` Peter Zijlstra
2011-08-12 18:11     ` Robert Richter
2011-07-29 17:07 ` [PATCH 0/7] perf, x86: Implement AMD IBS Peter Zijlstra
2011-08-01  5:21   ` Robert Richter
2011-08-02 11:29     ` Peter Zijlstra
2011-08-12 19:43       ` Robert Richter
2011-08-16 21:05         ` Robert Richter
2011-09-07 16:36 [PATCH 0/7 -v2] " Robert Richter
2011-09-07 16:36 ` [PATCH 2/7] perf, x86: Implement IBS initialization Robert Richter

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=20110812174938.GC17199@erda.amd.com \
    --to=robert.richter@amd.com \
    --cc=acme@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=peterz@infradead.org \
    /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

Powered by JetHome