New cpu macro and i386 cleanup
PATCH 1/1 New cpu macro and i386 cleanup
This annoyed me just enough to try and fix it. I'd
fix all the rest but I know how annoyed people get at massive changes:
include/linux/smp.h +0 -0
@ -134,6 +134,8 @
}
#endif /* !SMP */
+#define is_current_cpu(cpu) ((cpu) == smp_processor_id())
+
#define get_cpu() ({ preempt_disable(); smp_processor_id(); })
#define put_cpu() preempt_enable()
#define put_cpu_no_resched() preempt_enable_no_resched()
arch/i386/kernel/cpuid.c +0 -0
@ -56,7 +56,7 @
{
struct cpuid_command *cmd = (struct cpuid_command *) cmd_block;
- if ( cmd->cpu == smp_processor_id() )
+ if ( is_current_cpu(cmd->cpu) )
cpuid(cmd->reg, &cmd->data[0], &cmd->data[1], &cmd->data[2], &cmd->data[3]);
}
@ -65,7 +65,7 @
struct cpuid_command cmd;
preempt_disable();
- if ( cpu == smp_processor_id() ) {
+ if ( is_current_cpu(cpu) ) {
cpuid(reg, &data[0], &data[1], &data[2], &data[3]);
} else {
cmd.cpu = cpu;arch/i386/kernel/msr.c +0 -0
@ -100,7 +100,7 @
{
struct msr_command *cmd = (struct msr_command *) cmd_block;
- if ( cmd->cpu == smp_processor_id() )
+ if ( is_current_cpu(cmd->cpu) )
cmd->err = wrmsr_eio(cmd->reg, cmd->data[0], cmd->data[1]);
}
@ -108,7 +108,7 @
{
struct msr_command *cmd = (struct msr_command *) cmd_block;
- if ( cmd->cpu == smp_processor_id() )
+ if ( is_current_cpu(cmd->cpu) )
cmd->err = rdmsr_eio(cmd->reg, &cmd->data[0], &cmd->data[1]);
}
@ -118,7 +118,7 @
int ret;
preempt_disable();
- if ( cpu == smp_processor_id() ) {
+ if ( is_current_cpu(cpu) ) {
ret = wrmsr_eio(reg, eax, edx);
preempt_enable();
return ret;@ -138,7 +138,7 @
{
struct msr_command cmd;
- if ( cpu == smp_processor_id() ) {
+ if ( is_current_cpu(cpu) ) {
return rdmsr_eio(reg, eax, edx);
} else {
cmd.cpu = cpu;--
Chuck
I am not a number!
Quoted 3 lines · Chuck Ebbert
This annoyed me just enough to try and fix it. I'd
fix all the rest but I know how annoyed people get at massive changes:
I like, although I am not hot on the name, but that is just taste.
One minor nit: it is not preempt-safe. But then again, neither is any code that calls it without disabling preemption first. Maybe put a comment above it like:
/*
* is_current_cpu() - are we running on the given processor? *
* Note this is not preempt-safe: you need to explicitly
* disable preemption before calling this if you care
* about any consistency in the result
*/
The problem is not so much the call itself, but the use of the results. Anywhere you care that 'cpu' is the current processor, kernel preemption needs to remain disabled.
Robert Love