preemptive kernels and the use of smp_processor_id()
Hey guys, while attempting to port a relatively small kernel module that was written for Linux kernel 3.1.4 to git master, I was encountering a few issues. First to note, I am really new to kernel development. So while knowing C, I don't know much about the kernel APIs yet :) Things that have changed mostly has been visibility changes, like symbols got unexported and such, but the thing that worries me are the stack traces regarding the use of smp_processor_id() when using a PREEMPTible kernel. So it seems the kernel module I am porting assumed to always run on the same CPU core once entered kernelspace, but on a preemptive system you cannot guarantee that. So my question is, how can I force certain calls not to be preempted by the scheduler and/or not changing the core it was running on? AFAIK, the userspace has already defined a cpu affinity mask, and that's why that kernel module assumes that. 1.) If that stack trace is non-fatal, can I make it less spammy in the log files, meaning, that the use of smp_processor_id() is only used for logging / informational purposes? 2.) there is one part in the kernel where it actually uses the smp_processor_id() value for further tests, so here it really shouldn't reschedule during the call - how do I ensure not being preempted there then? Many thanks, and best regards, Christian Parpart.
On Tue, 09 Jul 2013 12:20:41 +0200, Christian Parpart said:
So it seems the kernel module I am porting assumed to always run on the same CPU core once entered kernelspace, but on a preemptive system you cannot guarantee that.
Correct. You probably want to fix the assumption(s) in the kernel module, that's in the long term probably easier than trying to make it work otherwise
So my question is, how can I force certain calls not to be preempted by the scheduler and/or not changing the core it was running on?
The trick is that if you're not interruptible, you can't be pre-empted. Note however that *does* limit what you can do - for instance, memory allocations that might sleep will cause problems. Also, since any running non-preemptible increases latency for whatever wanted to preempt you, you want to minimize the size of such regions as much as possible.
2.) there is one part in the kernel where it actually uses the smp_processor_id() value for further tests, so here it really shouldn't reschedule during the call -
The big question is why the code cares. Unless you're running on a non-symmetric configuration where the processor feature set differs, you usually don't care what CPU you're on - but you *may* care about something affected by the CPU (for example, cache line ping-ponging). It may make sense to not worry as much about what processor you're on and instead think of ways to deal with the issue you're trying to solve by selecting the processor (for instance, firing an IPI to run the critical code on the CPU that it needs to be on).
Hi,
So it seems the kernel module I am porting assumed to always run on the same CPU core once entered kernelspace, but on a preemptive system you cannot guarantee that.
Correct. You probably want to fix the assumption(s) in the kernel module, that's in the long term probably easier than trying to make it work otherwise
Uh, are we saying that once a process (say running on core-0) has entered preemptible kernel , there is a chance that suddenly the scheduler might decide it to move to core-1? I though preemptible only means that a process can only be preempted (not moved to another core) under following situations: 1) An interrupt happens (In case of timer, it could put the process back in queue if its time slice expired). 2) The process goes to sleep (can be a result of a call that can sleep). Can some one shed light on what conditions would a running process be moved to another core? Thanks, rajat
participants (3)
-
Christian Parpart -
Rajat Jain -
Valdis.Kletnieks@vt.edu