From: Bela Lubkin <belal@sco.com> Subject: realtime priorities, Re: hylafax blocked by setiathome Date: Sat, 9 Feb 2002 10:00:48 GMT References: <20020209034142.GA10919@jpradley.jpr.com> [I will be forwarding this message to the Hylafax developer's list; don't want to attempt to crosspost to a newsgroup and a mailing list] Jean-Pierre Radley wrote:
> OSR 5.0.6
> Hylafax 4.1
>
> Hylafax will NOT send out a fax if 'setiathome -nice 19' is running .
>
> Sendfax is running, stuck on the fax-modem, and cannot be killed.
>
> But if I kill setiathome, the fax is sent.
>
> I've never seen setiathome interfere with anything else.
I would have to look at Hylafax source to be sure (and I don't have it),
but if this is what I guess it is, setiathome is not at fault. Stop it
and run:
sh -c 'while :; do :; done' &
which is a Bourne shell infinite loop. Now try sending a fax. I
suspect this will block sendfax just as effectively as setiathome does.
... Ok, I got the Hylafax source and it is just as I suspected. In
hylafax-4.1/faxd/ModemServer.c++, we have:
=============================================================================
#elif HAS_POSIXSCHED
/*
* In POSIX (i.e. Linux), a real time priority is
* between 1 (low) and 99 (high);
* for now we conservatively use 1. Priority of 0
* is without real-time application.
*/
#include <sched.h>
static const struct SchedInfo {
int policy;
int priority;
} sched_setschedulerParams[9] = {
{SCHED_OTHER, 0}, // BASE
{SCHED_OTHER, 0}, // RUNNING
{SCHED_OTHER, 0}, // MODEMWAIT
{SCHED_OTHER, 0}, // LOCKWAIT
{SCHED_OTHER, 0}, // GETTYWAIT
{SCHED_FIFO, 1}, // SENDING
{SCHED_FIFO, 1}, // ANSWERING
{SCHED_FIFO, 1}, // RECEIVING
{SCHED_OTHER, 0}, // LISTENING
};
...
struct sched_param sp;
sp.sched_priority = sched_setschedulerParams[s].priority;
if (sched_setscheduler(0, sched_setschedulerParams[s].policy, &sp))
traceServer("sched_setscheduler: %m");
=============================================================================
So Hylafax is calling sched_setscheduler(0, SCHED_FIFO, 1). This is probably correct for Linux. On OpenServer, the process is volunteering to be run only when no other process except the CPU idle thread is ready to run. It is giving itself a fixed priority of just about as low as possible. The code assumes that all realtime priorities are higher than all non-realtime priorities. This is not true on OpenServer, which offers realtime priorities of 0-127 and traditional Unix priorities of 0-95. Traditional Unix (SCHED_OTHER) scheduling involves the scheduler dynamically raising and lowering a process's priority based on recent CPU usage (more usage -> lower priority, which means that non-CPU- intensive tasks get quick response when they do need some CPU). Assigning a "realtime" (SCHED_RR or SCHED_FIFO) priority in the range of 0-95 just means that the process has nailed itself to a particular position within that range; SCHED_OTHER processes will drift above or below the realtime process depending on how much CPU they've been using recently. Only by requesting a realtime priority >95 can a process guarantee it'll always be more important than SCHED_OTHER processes. Perhaps Linux offers realtime priorities 0-99 which are all higher than the SCHED_OTHER priorities; that is, the two types of priority may have overlapping numeric ranges, but SCHED_RR/0 might still be scheduled with more priority than SCHED_OTHER/99. The Single Unix Spec v3 says "The priority ranges for each policy may overlap the priority ranges of other policies", but does not say anything about whether the _meanings_ of numeric values in different policies have to correlate in any particular way. In OpenServer they do. I know of no runtime way to configure this. One could write a program to play various sorts of processes off against each other, at various priorities, and try to guess what the kernel's doing, but that sounds fragile. Instead, Hylafax's configure script needs to just recognize the OS and assign suitable priority levels (or skip the priority diddling entirely -- is it really necessary on modern hardware?) There are hints in the code that similar problems have been seen on other systems that implement Posix realtime scheduling. A similar problem in NTP was fixed a couple of years back. >Bela<
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.
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.
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