Follow the Australian Telecommunications scene NEWSLETTER- FREE TRIAL
The Linux distillery
Bringing the world of Linux to you, David cuts through the tech and shows you how it works and how to use it, in terms that apply to any distro. RSS
Just what makes Linux tick E-mail
by David M Williams   
Thursday, 21 February 2008
Call up a command prompt and enter the command time sleep 5. The time command can be used before any other command. It will run the action as usual and displays the three time values afterwards. You will see the real time shows how long – to the human eye – the command took to run. The user time will actually be 0.000s because the sleep command is a system call. The sys time will be a value, but will be a small number. This is because sleep simply blocks and does not do any real work. Consequently, the kernel spent little time running it.

So there you have it; the CPU is taking quick bites at any running task and in all likelihood, unless it is very computationally intensive, most processes are spending more time idle than they are working. In this example, the CPU spent less than 1/10th of a second to run a command which caused it to sleep for five seconds.

This is informative for a couple of reasons. Not least of which is that the user time can help identify bad code. If your process seems to be taking a long time to run, check how much time the CPU is devoting to the user code, ie non system calls. If this is a large amount of time then the program could stand to be optimised or it may be performing very intense calculations. On the other hand, if the program is spending a lot of time running system calls then it may be making a particular system call over and over. You can delve deeper by using strace –c to execute the command again, eg strace –c sleep 5. The output from strace is all the system calls made by the program and how much time was spent on each one.

Also, as the sleep example shows, if the process is spending a lot of time blocking – waiting for input – then this will be indicated by relatively low user and system times compared to the real running time.
Time is measured in the Linux kernel as jiffies. One jiffy represents one tick of an internal hardware timer that is programmed to generate interrupts with a fixed frequency. The frequency is set when the kernel is built and it does not change unless the kernel is rebuilt.

For a long time most 32-bit ‘386 processor Linux distros used a default value of 100Hz – ie 100 interrupts per second – and this value is stored in a macro named HZ. Other architectures will have a different default value for HZ.

Ordinarily, only people concerned with real-time systems or multimedia work would modify the HZ value, and in particular they would tweak it to a higher value so that the frequency of ticks would be more regular.
The reason why is that a jiffy is the basis of time in the Linux kernel. It can take up to a jiffy to pre-empt a CPU-intense process. If a process does not yield of its volition it cannot be pre-empted until the next clock tick. At 100Hz a process can monopolise the CPU for up to 10ms at a time (1s divided by 100 interrupts = 10ms per interrupt.)

What does this mean? Please read on.

CONTINUED







 
< Next story in category   Previous story in the category >
iTWire user statistics Visitors last 30 days
694,279
Subscribers 15,210
#1 independent technology news advertise here
  •   *  
  • Search
  • AdvSeach
  • Login
  • Events
  • FreeStuff

- Advertisement -

Featured Whitepapers

Follow iTWire on Twitter

About iTWire

iTWire is all about technology news, information, jobs and community for the IT and telecommunications industry professional. Subscribe to our free ICT daily newsletter