When does process swap happen in a system call?
Hi!
I'm new to Linux programming, and learning it for work. I'm running into a question about when a process swap can occur during a system call. For example, for the following statement, gettimeofday(&tv,NULL); is the sequence: 1) program calls kernel 2) kernel fills in tv structure 3) task manager swaps process out 4) task manager comes back to my process 5) kernel returns to program with old time or 1) program calls kernel 2) task manager swaps process out 3) task manager comes back to my process 4) kernel fills in tv structure 5) kernel returns to program with current time or could it be either, depending on various factors? If it makes a difference, the system in question is an Intel IXP425 running the 2.4 Snapgear kernel. Thanks! Bill |
If I'm remember correctly, if the function is a "fast system call" which gettimeofday would be, then the only chance you have of getting your process context switched out is during the backend of the syscal so I guess Sequence 1 would be more accurate?
|
What you are interested in are known as atomic system calls. These are guaranteed to complete without interruption.
These are common interrupts: 1. pre-empted by the scheduler which is a process context change 2. swapped out 3. signal receipt and processing For example dup2() is atomic, gettimeofday() is not. The only reason you really need to worry about things like this is in the case of threading. If a call can be interrupted it may return a failure but set errno to EINTR, which means nothing broke but please retry. read() and write() do this. Another situation is the case of an overloaded system. During normal operation of a properly tuned system with a reasonable load, swapping an active process seldom happens. This is why good testing of an app includes testing it on a severely stressed system. Swapping is the least of your worries. |
Quote:
And swapping is one of my BIGGEST worries. The sytem I'm using is actually an embedded system, but the vendor decided to use a "generic" Linux distribution instead of a real-time distribution. When an event happens, it needs to be time tagged. And the system is such that, at best, if I get swapped it will be at least 20ms before I get another timeslice. I've seen 240ms intervals between my timeslices. I can handle some of that if I know that, for example, gettimeofday() returns the time of the call, not the time after the swap. Bill |
All times are GMT -5. The time now is 04:50 PM. |