diff options
author | Alexey Dobriyan <adobriyan@openvz.org> | 2007-02-16 04:48:11 -0500 |
---|---|---|
committer | Dave Jones <davej@redhat.com> | 2007-02-20 14:23:43 -0500 |
commit | b077ffb3b767c3efb44d00b998385a9cb127255c (patch) | |
tree | 160369b5541142afedc20a97a9c89718550cf2a3 /arch/i386 | |
parent | 22f7bb0329a506f2fd61c14ce3c8bc632e08c732 (diff) |
rdmsr_on_cpu, wrmsr_on_cpu
There was OpenVZ specific bug rendering some cpufreq drivers unusable on SMP.
In short, when cpufreq code thinks it confined itself to needed cpu by means
of set_cpus_allowed() to execute rdmsr, some "virtual cpu" feature can migrate
process to anywhere. This triggers bugons and does wrong things in general.
This got fixed by introducing rdmsr_on_cpu and wrmsr_on_cpu executing rdmsr
and wrmsr on given physical cpu by means of smp_call_function_single().
Dave Jones mentioned cpufreq might be not only user of rdmsr_on_cpu() and
wrmsr_on_cpu(), so I'm putting them into arch/{i386,x86_64}/lib/ .
Signed-off-by: Alexey Dobriyan <adobriyan@openvz.org>
Cc: Andi Kleen <ak@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Dave Jones <davej@redhat.com>
Diffstat (limited to 'arch/i386')
-rw-r--r-- | arch/i386/lib/Makefile | 2 | ||||
-rw-r--r-- | arch/i386/lib/msr-on-cpu.c | 70 |
2 files changed, 72 insertions, 0 deletions
diff --git a/arch/i386/lib/Makefile b/arch/i386/lib/Makefile index d86a548b8d54..0d41223472c2 100644 --- a/arch/i386/lib/Makefile +++ b/arch/i386/lib/Makefile | |||
@@ -7,3 +7,5 @@ lib-y = checksum.o delay.o usercopy.o getuser.o putuser.o memcpy.o strstr.o \ | |||
7 | bitops.o semaphore.o | 7 | bitops.o semaphore.o |
8 | 8 | ||
9 | lib-$(CONFIG_X86_USE_3DNOW) += mmx.o | 9 | lib-$(CONFIG_X86_USE_3DNOW) += mmx.o |
10 | |||
11 | obj-y = msr-on-cpu.o | ||
diff --git a/arch/i386/lib/msr-on-cpu.c b/arch/i386/lib/msr-on-cpu.c new file mode 100644 index 000000000000..2092ea15ba85 --- /dev/null +++ b/arch/i386/lib/msr-on-cpu.c | |||
@@ -0,0 +1,70 @@ | |||
1 | #include <linux/module.h> | ||
2 | #include <linux/preempt.h> | ||
3 | #include <linux/smp.h> | ||
4 | #include <asm/msr.h> | ||
5 | |||
6 | #ifdef CONFIG_SMP | ||
7 | struct msr_info { | ||
8 | u32 msr_no; | ||
9 | u32 l, h; | ||
10 | }; | ||
11 | |||
12 | static void __rdmsr_on_cpu(void *info) | ||
13 | { | ||
14 | struct msr_info *rv = info; | ||
15 | |||
16 | rdmsr(rv->msr_no, rv->l, rv->h); | ||
17 | } | ||
18 | |||
19 | void rdmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 *l, u32 *h) | ||
20 | { | ||
21 | preempt_disable(); | ||
22 | if (smp_processor_id() == cpu) | ||
23 | rdmsr(msr_no, *l, *h); | ||
24 | else { | ||
25 | struct msr_info rv; | ||
26 | |||
27 | rv.msr_no = msr_no; | ||
28 | smp_call_function_single(cpu, __rdmsr_on_cpu, &rv, 0, 1); | ||
29 | *l = rv.l; | ||
30 | *h = rv.h; | ||
31 | } | ||
32 | preempt_enable(); | ||
33 | } | ||
34 | |||
35 | static void __wrmsr_on_cpu(void *info) | ||
36 | { | ||
37 | struct msr_info *rv = info; | ||
38 | |||
39 | wrmsr(rv->msr_no, rv->l, rv->h); | ||
40 | } | ||
41 | |||
42 | void wrmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h) | ||
43 | { | ||
44 | preempt_disable(); | ||
45 | if (smp_processor_id() == cpu) | ||
46 | wrmsr(msr_no, l, h); | ||
47 | else { | ||
48 | struct msr_info rv; | ||
49 | |||
50 | rv.msr_no = msr_no; | ||
51 | rv.l = l; | ||
52 | rv.h = h; | ||
53 | smp_call_function_single(cpu, __wrmsr_on_cpu, &rv, 0, 1); | ||
54 | } | ||
55 | preempt_enable(); | ||
56 | } | ||
57 | #else | ||
58 | void rdmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 *l, u32 *h) | ||
59 | { | ||
60 | rdmsr(msr_no, *l, *h); | ||
61 | } | ||
62 | |||
63 | void wrmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h) | ||
64 | { | ||
65 | wrmsr(msr_no, l, h); | ||
66 | } | ||
67 | #endif | ||
68 | |||
69 | EXPORT_SYMBOL(rdmsr_on_cpu); | ||
70 | EXPORT_SYMBOL(wrmsr_on_cpu); | ||