LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-03-2005, 09:51 AM   #1
oldfogie
LQ Newbie
 
Registered: May 2005
Posts: 2

Rep: Reputation: 0
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
 
Old 05-03-2005, 09:59 AM   #2
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
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?
 
Old 05-03-2005, 12:14 PM   #3
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
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.
 
Old 05-03-2005, 07:35 PM   #4
oldfogie
LQ Newbie
 
Registered: May 2005
Posts: 2

Original Poster
Rep: Reputation: 0
Quote:
Originally posted by jim mcnamara
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.

{...snip...}

Swapping is the least of your worries.
I'm familiar with atomic system calls, and that gettimeofday() is not one of them.

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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to disable swap space entry for a process (Sticky bit?) Pandamatak Linux - General 3 09-25-2006 06:17 PM
How to write a system call to display the process information? balasquare@yahoo.com Programming 3 09-30-2005 01:05 AM
What process is changing /etc/fstab and deleting my swap mount? ffrr Linux - Software 8 03-18-2005 09:16 PM
is there a system call to send process to run in the background? feetyouwell Programming 4 10-01-2004 04:58 AM
Changing Process Priority in Linux w/ System Call sptchamp Programming 2 07-21-2004 09:58 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:26 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration