(OLDER) <- More Stuff -> (NEWER) (NEWEST)
Printer Friendly Version



linux multitasking cpu


What is this stuff?

If this isn't exactly what you wanted, please try our Search (there's a LOT of techy and non-techy stuff here about Linux, Unix, Mac OS X and just computers in general!):



From: Richard Pitt <richard@belcarra.com>
Subject: Re: Linux multitasking
References: <3CA4927A.5050700@sandia.gov> 
Date: Fri, 29 Mar 2002 19:47:48 GMT

You have a pretty good idea of what is happening already it seems.




On Fri, 29 Mar 2002 08:12:42 -0800, Christopher R. Carlen wrote:

> Hi:
> 
> I would like to understand why I experience certain kinds of behavior
> using Linux.  I have Suse 7.3 with 2.4.10.
> 
> I find that it is possible running programs in X, particularly Netscape,
> that the program can get stuck.  When it does this, the pointer will not
>   operate on X.  That is, if I try to move out of Netscape's window I
> can do so, but then no other applications respond either.  The KDE panel
> doesn't respond.  Nothing.  Not until Netscape recovers, or I kill it by
> going to a console (the keyboard fortunately responds).
> 
> The pointer stays stuck in a funny shape when this happens, so it
> doesn't undergo the usual changes when moving across windows, etc.  When
> this happens I know that there is the problem I described.

Don't know the exact problem here - but have had it myself on older
version of Netscape. This is X problem, not multi-tasking at the OS level.
In this case X switches the pointer output (mouse in this case) from
program to program based on where it is in relation to the images on the
screen (as you move from window to window, the "focus" of the pointer
changes to each underlying program in turn. I'll leave it to one of the
GUI gurus to explain why/how it can get wedged on a particular program.


> My question is how can this happen?  Perhaps a definition of "preemptive
> multitasking" would be useful here.

General description - look at the source for more definitive details:
Linux kernel maintains a list of processes and their states. (see top and
vmstat for a look at what is going on) - when a process becomes "runable"
i.e. has input and wants to do something - the processor gives it control
of the CPU for the shorter of: what it wants, or 1 clock tick. So the
program can reliquish the CPU before the clock tick, or the kernel can
grab it back at the clock tick. The kerenel then gives the next runable
process the same opportunity. If there are no runable processes, the CPU
goes into a "wait loop" where it effectively puts the CPU to sleep (on
Intel architecture this means executing NOP which can lower CPU power
drain quite a bit thereby saving battery on laptops for example) - an
interrupt wakes it if something happens.



There is a fudge factor called "niceness" -scale of -20 to +20 with -20
being high priority and +20 being low priority.

The kernel schedules high priority processes to run before lower priority
is given a chance. Kernel runs with highest priority (so it can hog the
CPU quite a bit if it wants to)

The kernel can (and does) change the niceness of low priority processes
based on whether they have had a "fair" share of CPU resources in recent
time - so eventually all processes will run. This process happens over
seconds, not microseconds.

When a process is started, or at other times using a tool called renice,
its niceness level is set at some value. (nice --20 bash will give you a
highest priority shell prompt - great for debugging runaway systems if you
can get it to run at all - takes patience on a truly wedged system). root
can create high priority processes - others can only lower their priority.


> My conception of it is that there is a hardware timer interrupt that
> periodically returns control to the kernel from any userland process.
> Once the kernel is in control, it switches control to another process.
> The processes thus get timeslices.  I realize it is complicated by
> priority levels.  But it seems that in a preemptive system, it would be
> impossible for any hung program to cause the input devices to fail to
> respond.

Correct. there is a heartbeat timer. As noted, the input device is
responding - but X is not correctly dealing with the input focus change.
Different from the kernel.


> Of course, the input devices are responding in my situation, but their
> input (actually just the mouse) doesn't go to any other program except
> the stuck one.
> 
> I suppose this is really a problem with the architecture of X.  It is
> apparent that the kernel is multitasking.

Right.


> But I would appreciate hearing someone do some narration about what goes
> on under the hood, that might lend some understanding to why this kind
> of thing can happen.

> Also, when doing very intensive file or network IO, like when I do a
> file search or start VMware, the system can become very sluggish.  99%
> of CPU cycles wind up going to the offending task.  How can this happen?
>   Is a process that runs as root the only one that can do this?
> 
> Any insights appreciated.

I run VMware and have xosview locked on my screen so I see exactly how it
behaves - have been watching it for over 3 years.

On my system (1.2GHz Athalon, 1.2G RAM) the system is responsive in
loading VMware up to the point where the amount of RAM VMware wants is
more than what is avaialble - then the system pages to the swap file
quite a bit until everything is in place at which time the system is
fine.

If the Windows system needs to check its disk due to problem shutdown,
this will beat up the Linux system too since it is a virtual disk (in my
case).

If the Windows system runs Norton (as mine does) and you have not
recently done a virus scan, this will start up shortly after boot and
beat up the disk.

All of this causes the CPU to show lots of SYS activity as the VMware
system calls for disk I/O - note that I'm using emulated IDE drives. I
have not tried emulated SCSI drives yet - IDE is very CPU intensive (on
the Windows side as well as on the Linux side) which may be the reason
for the high SYS levels during intensive virtual disk I/O.

Note that on my system I also have a couple of X-windows terminals (old
CPUs with NFS booted version of Linux running diskless) and when the
screen saver on them kicks in I see lots of CPU too - but all NICE'd down
so it doesn't affect the running of the rest of the box.

xosview is great for visualizing what is going on.

Hope this helps

richard

-- 
Richard C. Pitt                 C.E.O. Belcarra Messaging Corp.
richard@belcarra.com            604-644-9265    www.belcarra.com
Embedded Linux Systems: Design, Creation, Integration
Specializing in USB, Flash, and all things TCP/IP
 



Click here to add your comments



Don't miss responses! Subscribe to Comments by RSS or by Email

Click here to add your comments


If you want a picture to show with your comment, go get a Gravatar


ad


/Bofcusm/1537.html copyright 1997-2004 (various authors) All Rights Reserved

Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more. We appreciate comments and article submissions.

Publishing your articles here

Jump to Comments



Many of the products and books I review are things I purchased for my own use. Some were given to me specifically for the purpose of reviewing them. I resell or can earn commissions from the sale of some of these items. Links within these pages may be affiliate links that pay me for referring you to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain. I also may own stock in companies mentioned here. If you have any question, please do feel free to contact me.

Specific links that take you to pages that allow you to purchase the item I reviewed are very likely to pay me a commission. Many of the books I review were given to me by the publishers specifically for the purpose of writing a review. These gifts and referral fees do not affect my opinions; I often give bad reviews anyway.

We use Google third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.



More:
       - Linux
       - Bofcusm


Unix/Linux Consultants

Skills Tests

Guest Post Here











My Favorites

Change Congress