The following code snippet demonstrates the
int arr[NR_CPUS];
arr[smp_processor_id()] = i;
/* kernel preemption could happen here */ j = arr[smp_processor_id()];
/* i and j are not equal as smp_processor_id() may not be the same */
In this situation, if kernel preemption had happened at the specified point, the task would have been assigned to some other processor upon
FPU mode is another case where the state of the CPU should be protected from preemption. When the kernel is executing floating point instructions, the FPU state is not saved. If preemption happens here, then upon reschedule, the FPU state is completely different from what was there before preemption. So, FPU code must always be locked against kernel preemption.
Locking can be done by disabling preemption for the critical section and
2.6kernel has provided the following #defines to disable and enable preemption:
•preempt_enable()
•preempt_disable()
•get_cpu()
•put_cpu()
Using these #defines we could rewrite the above code as
int cpu, arr[NR_CPUS];
arr[get_cpu()] = i; /* disable preemption */ j = arr[smp_processor_id()];
/* do some critical stuff here */
put_cpu(); /*
Note that preempt_disable() and preempt_enable() calls are nested. That is,
preempt_disable() can be called n number of times, and preemption will only be
Preemption is implicitly disabled if any spin locks are held. For instance, a call to
spin_lock_irqsave() implicitly prevents preemption by calling preempt_disable(); a call to spin_unlock_irqrestore()
5.3Inter-process communication
The SLES kernel provides a number of
This section describes the general functionality and implementation of each IPC mechanism and focuses on DAC and object reuse handling.
61