From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,206c7b2c386d7932 X-Google-Attributes: gidfee84,public From: Dave Butenhof Subject: Re: pthread_setprio: There is just one catch...... Date: 1996/06/10 Message-ID: <31BC0B38.2781@zko.dec.com> X-Deja-AN: 159445181 references: <01bb53e3.82428620$b6de5982@Baldrick.student.utwente.nl> content-type: text/plain; charset=us-ascii organization: Digital Equipment Corporation mime-version: 1.0 newsgroups: comp.unix.osf.osf1 x-mailer: Mozilla 3.0b4 (X11; I; OSF1 V4.0 alpha) -- M. van Wijk wrote: > > Do priorities work under OSF pthreads? I get the impression that they are > not implemented. Setting the schedule priority higher or lower dowsn't > work in the three policies (SCHED_RR, SCHED_FIFO and SCHED_OTHER). > > What's wrong? (probably me) > Yes, they do work, and you haven't given enough information (here or in comp.programming.threads) to determine what you're doing, what you expect to happen, or what is happening. Here's my reply from comp.programming.threads, just to avoid leaving this loose end. M. van Wijk wrote: > I have created a thread and it works fine. That's nice but not nice > enough. I want to set the scheduling and priority as well. But every time > I set the priority of a thread higher the pthread_create fails. Setting > the priority lower works fine though. > > As workaround I've set the priority of the main thread lower. Like this: > > pthread_setscheduler(pthread_self(), SCHED_RR, PRI_RR_MIN); > > This works fine, but is main also executed as a thread on all platforms? > > Allow me to correct myself, setting the priority lower doesn't even work. > Are priorities implemented at all in OSF? In case you are wanedring what > kind of system I'm working on: > OSF1 V3.2 214 alpha > > But if priorities are not implemented wouldn't it be much better to define > PRI_policy_MIN = PRI_policy_MAX? > > I think threads are severely crippled without a propper priority control. > > Marc van Wijk > wijk@cs.utwente.nl > wijk@pegasus.epsrit.ec.org > m.vanwijk@student.utwente.nl I don't know anything about your program or your problem, and it may well be that your application truly requires priority control and that you understand how to use it correctly. However, as a general statement, threads are certainly not in any respect "crippled" without priority control. Most programs gain nothing from priority control except complication. And the vast majority of people who want to use priority control on a timesharing system don't know what they're doing (and won't accomplish what they intend). Now, to your question. Or at least, as well as I can address your question without more information. First off, prior to Digital UNIX 4.0, Digital UNIX (and its old name, "DEC OSF/1") implemented what POSIX calls "system contention scope". That means that all threads you create in a process are directly represented as kernel scheduling entities ("Mach threads"). The scheduling policy and priority you specify for those threads affects how they are scheduled against ALL other threads on the system. Clearly, it is not reasonable to allow a non-privileged user to create, for example, a compute-bound thread that will lock out all other activity in other processes (and even inside the kernel). The default priority of a thread is 19 (in POSIX priority terms, which is very different from the traditional "UNIX priority" controlled by nice & friends). So when you create a thread set to priority 20, it locks out all normal user process activity. If you go any higher than that, you start locking out kernel activity. >From that perspective, it may not be surprising to anyone that it requires privilege (in specific, root access) to set a thread's priority higher than 19. SCHED_FIFO threads only get to go up to 18, because they aren't timesliced against other threads at the same priority. For somewhat arbitrary historical reasons, the priority range symbols were defined so that the "mid point" of the SCHED_FIFO and SCHED_RR priority ranges would yield the highest priority to which you could set the thread without privilege. That is, 18 for SCHED_FIFO and 19 for SCHED_RR. Now, when you say "setting the priority lower doesn't even work", exactly what do you mean? What did you do, and what happened as a result? "ps xm -O psxpri" will show you the POSIX priority for all your threads (a "non-threaded" process is really just a single thread). Prior to DEC OSF/1 3.0 (e.g., 2.x), the "realtime kernel" was an optional feature; and without it, setting POSIX priorities was impossible. Trying to set any POSIX priority would fail with ENOSYS when the realtime kernel wasn't installed. DEC OSF/1 3.0, however, made the "realtime kernel" support standard, so setting priority will always be possible -- as long as you're running as root or using "approved" priority values. Certainly setting the SCHED_RR/PRI_RR_MIN will succeed. Might well not do what you want, however, since PRI_RR_MIN is lower than 19, which means you are running at lower priority than Jane Schmoe's shell (and compiler, editor, etc.) In Digital UNIX 4.0, POSIX threads are strictly "process contention scope". You can set any POSIX priority without privilege -- but none of them mean anything against threads in other processes. In an update to 4.0, we'll be adding support for the pthread_attr_setscope() attribute, so you can explicitly create threads in system contention scope when you need them: and those threads will again require root privilege to set priorities higher than 19 (18 for SCHED_FIFO). +-------------------------------------------------------------------+ | Dave Butenhof Digital Equipment Corporation | | butenhof@zko.dec.com 110 Spit Brook Rd, ZKO2-3/Q18 | | PH 603.881.2218, FAX 603.881.0120 Nashua, NH 03062-2711 | +----------+ "Better Living Through Concurrency" +----------+ +---------------------------------------------+