arch/x86/oprofile/op_model_amd.c: Perform initialisation on a single CPU [Linux 2.6.37]

This Linux kernel change "arch/x86/oprofile/op_model_amd.c: Perform initialisation on a single CPU" is included in the Linux 2.6.37 release. This change is authored by Robert Richter <robert.richter [at] amd.com> on Mon Jan 3 12:15:14 2011 +0100. The commit for this change in Linux stable tree is c7c2580 (patch).

arch/x86/oprofile/op_model_amd.c: Perform initialisation on a single CPU

Disable preemption in init_ibs(). The function only checks the
ibs capabilities and sets up pci devices (if necessary). It runs
only on one cpu but operates with the local APIC and some MSRs,
thus it is better to disable preemption.

[    7.034377] BUG: using smp_processor_id() in preemptible [00000000] code: modprobe/483
[    7.034385] caller is setup_APIC_eilvt+0x155/0x180
[    7.034389] Pid: 483, comm: modprobe Not tainted 2.6.37-rc1-20101110+ #1
[    7.034392] Call Trace:
[    7.034400]  [<ffffffff812a2b72>] debug_smp_processor_id+0xd2/0xf0
[    7.034404]  [<ffffffff8101e985>] setup_APIC_eilvt+0x155/0x180
[ ... ]

Addresses https://bugzilla.kernel.org/show_bug.cgi?id=22812

Reported-by: <[email protected]>
Signed-off-by: Robert Richter <[email protected]>
Cc: [email protected] <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: Rafael J. Wysocki <[email protected]>
Cc: Dan Carpenter <[email protected]>
Cc: Andrew Morton <[email protected]>
Cc: <[email protected]>         [2.6.37.x]
LKML-Reference: <[email protected]>
[ small cleanups ]
Signed-off-by: Ingo Molnar <[email protected]>

There are 24 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 arch/x86/oprofile/op_model_amd.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
index a011bcc..7d90d47 100644
--- a/arch/x86/oprofile/op_model_amd.c
+++ b/arch/x86/oprofile/op_model_amd.c
@@ -630,21 +630,29 @@ static int __init_ibs_nmi(void)
    return 0;
 }

-/* initialize the APIC for the IBS interrupts if available */
+/*
+ * check and reserve APIC extended interrupt LVT offset for IBS if
+ * available
+ *
+ * init_ibs() preforms implicitly cpu-local operations, so pin this
+ * thread to its current CPU
+ */
+
 static void init_ibs(void)
 {
-   ibs_caps = get_ibs_caps();
+   preempt_disable();

+   ibs_caps = get_ibs_caps();
    if (!ibs_caps)
-       return;
+       goto out;

-   if (__init_ibs_nmi()) {
+   if (__init_ibs_nmi() < 0)
        ibs_caps = 0;
-       return;
-   }
+   else
+       printk(KERN_INFO "oprofile: AMD IBS detected (0x%08x)n", ibs_caps);

-   printk(KERN_INFO "oprofile: AMD IBS detected (0x%08x)n",
-          (unsigned)ibs_caps);
+out:
+   preempt_enable();
 }

 static int (*create_arch_files)(struct super_block *sb, struct dentry *root);

Leave a Reply

Your email address will not be published. Required fields are marked *