This is a discussion on cpu load 2 within the Slackware Linux Support forums, part of the Unix Operating Systems category; --> Dear all, My first question has been answered, thnx a lot!!! Now, to solve the load problem i've noticed ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Dear all, My first question has been answered, thnx a lot!!! Now, to solve the load problem i've noticed that the program uses a tight for(; not needed (explaining the cpu hogging). Now, I could use e.g. sleep(), nanosleep() etc, but these seem to have side effects, either not actually sleeping or very course sleep intervals. Is there some kind of yield() that allows me to do just one for(; relinquish the remainder of the time slice allocated to the app? e.g.: for (; { dosomething(); yield_rest_of_timeslice(); } Thnx Max |
| |||
| On Feb 11, 10:58 am, TheMaxer <m...@max-irene.demon.nl> wrote: > Dear all, > > My first question has been answered, thnx a lot!!! > > Now, to solve the load problem i've noticed that the program uses a > tight for(; > not needed (explaining the cpu hogging). [snip] > Is there some > kind of yield() that allows me to do just one for(; > relinquish the remainder of the time slice allocated to the app? [snip] Yes, sched_yield(2) (see "man 2 sched_yield") .. . . SCHED_YIELD(2) Linux Programmer's Manual SCHED_YIELD(2) NAME sched_yield - yield the processor SYNOPSIS #include <sched.h> int sched_yield(void); DESCRIPTION A process can relinquish the processor voluntarily without blocking by calling sched_yield(). The process will then be moved to the end of the queue for its static priority and a new process gets to run. Note: If the current process is the only process in the highest prior- ity list at that time, this process will continue to run after a call to sched_yield(). POSIX systems on which sched_yield() is available define _POSIX_PRIOR- ITY_SCHEDULING in <unistd.h>. RETURN VALUE On success, sched_yield() returns 0. On error, -1 is returned, and errno is set appropriately. CONFORMING TO POSIX.1-2001. SEE ALSO sched_setscheduler(2) for a description of Linux scheduling. Programming for the real world - POSIX.4 by Bill O. Gallmeister, O'Reilly & Associates, Inc., ISBN 1-56592-074-0 Linux 1.3.81 1996-04-10 SCHED_YIELD(2) |
| |||
| On 11 feb, 19:33, Lew Pitcher <lpitc...@teksavvy.com> wrote: > On Feb 11, 10:58 am, TheMaxer <m...@max-irene.demon.nl> wrote:> Dear all, > > Yes, sched_yield(2) (see "man 2 sched_yield") Thnx Lew! However, the process is the only one running, therefore sched_yield() doesn't do something. A sleep() gives me the desired cpu load, but is too coarse. I want something like, wake-up every 20msec or so and then quickly dosomething() and sleep again.... Max |
| ||||
| On 12 feb, 09:13, TheMaxer <m...@max-irene.demon.nl> wrote: > On 11 feb, 19:33, Lew Pitcher <lpitc...@teksavvy.com> wrote: > > > On Feb 11, 10:58 am, TheMaxer <m...@max-irene.demon.nl> wrote:> Dear all, > > > Yes, sched_yield(2) (see "man 2 sched_yield") > > Thnx Lew! > > However, the process is the only one running, therefore sched_yield() > doesn't do something. A sleep() gives me the desired cpu load, but is > too coarse. I want something like, wake-up every 20msec or so and then > quickly dosomething() and sleep again.... > > Max dear all, It appears that nanosleep() is the way to go, after all. The issue being that nanosleep() degrades to a busy waiting loop below certain sleep values. This is ok from a nanosleep implementation point of view. I managed to change the app, so a bigger value for the sleep was acceptable, making the app actually sleep between loop iterations. Problem solved ;-) Thanks. Max |