On Thu, Sep 11, 2008 at 9:17 PM, Thomas Petazzoni <thomas.petazzoni@xxxxxxxxxxxxxxxxxx> wrote: > Le Thu, 11 Sep 2008 14:18:34 +0800, > "Peter Teoh" <htmldeveloper@xxxxxxxxx> a écrit : > >> In arch/x86/kernel/process_32.c: >> >> EXPORT_PER_CPU_SYMBOL(current_task); >> EXPORT_PER_CPU_SYMBOL(cpu_number); >> EXPORT_SYMBOL(kernel_thread); >> EXPORT_SYMBOL_GPL(start_thread); >> >> What is the rational behind exporting per CPU symbol? > > Export per-cpu variables <http://lwn.net/Articles/22911/> to modules ? > very useful, and first time I have seen such a declaration. just to recap one impt paragraph from the article: The above code can be dangerous, however. Accessing per-CPU variables can often be done without locking, since each processor has its own private area to work in. The 2.6 kernel is preemptible, however, and that adds a couple of challenges. Since kernel code can be preempted, it is possible to encounter race conditions with other kernel threads running on the same processor. Also, accessing a per-CPU variable requires knowing which processor you are running on; it would not do to be preempted and moved to a different CPU between looking up the processor ID and accessing a per-CPU variable. For both of the above reasons, kernel preemption usually must be disabled when working with per-CPU data. The usual way of doing this is with the get_cpu_var and put_cpu_var macros. get_cpu_var works as an lvalue, so it can be assigned to, have its address taken, etc. Perhaps the simplest example of the use of these macros can be found in net/socket.c: get_cpu_var(sockets_in_use)++; put_cpu_var(sockets_in_use); > current_task is a per-cpu variable: > DEFINE_PER_CPU(struct task_struct *, current_task) = &init_task; > > Thomas > -- > Thomas Petazzoni, Free Electrons > Kernel, drivers and embedded Linux development, > Thank you very much. -- Regards, Peter Teoh -- To unsubscribe from this list: send an email with "unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx Please read the FAQ at http://kernelnewbies.org/FAQ