Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 335345 - gnome-extra/gnome-system-monitor is unable to set priority to 20, setting it to 19 as a maximum level
Summary: gnome-extra/gnome-system-monitor is unable to set priority to 20, setting it ...
Status: RESOLVED UPSTREAM
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Unspecified (show other bugs)
Hardware: All Linux
: High normal (vote)
Assignee: Gentoo Linux Gnome Desktop Team
URL: https://bugzilla.gnome.org/show_bug.c...
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-08-31 01:21 UTC by Checker
Modified: 2011-01-27 19:43 UTC (History)
4 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
emerge --info (temp,4.89 KB, text/plain)
2010-09-08 11:00 UTC, Checker
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Checker 2010-08-31 01:21:04 UTC
cat  /usr/include/bits/resource.h | grep "#define PRIO_"
#define PRIO_MIN	-20	/* Minimum priority a process can have.  */
#define PRIO_MAX	20	/* Maximum priority a process can have.  */
....
straced bitcoin shows smth like\
23068 setpriority(PRIO_PROCESS, 0, 20) 

but nice level of 23068 stays 0


Reproducible: Always

Steps to Reproduce:
1. try to set nice level in gnome-system-manager to 20 (it is available there)


Actual Results:  
nice level stays 19


Expected Results:  
nice level must be 20

setpriority must set nice level 20 but after 23068 setpriority(PRIO_PROCESS, 0, 20) it stays 0
Comment 1 Jeroen Roovers (RETIRED) gentoo-dev 2010-09-07 16:48:06 UTC
Please post your `emerge --info' too.
Comment 2 Checker 2010-09-08 11:00:39 UTC
Created attachment 246444 [details]
emerge --info

http://paste.pocoo.org/show/259480/ -- pastebin version of emerge --info
Comment 3 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2010-09-12 08:03:56 UTC
Could you decide whether it sets it to 19 or leaves at 0? Because you mentioned both values in your bugreport.
Comment 4 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2010-09-12 08:43:55 UTC
I've checked POSIX and glibc manpages. It is POSIX limitation that the positive priority range is one shorter than negative one; glibc manpage strictly declares the range as -20..19.

The Notes, however, show that this is mostly kernel related, and some systems in fact use -20..20. Linux is not amongst that systems, as you can see in Documentation/scheduler/sched-nice-design.txt, where it is explicitly stated that nice values range from -20 to 19.

Additionally, I don't see PRIO_MIN or PRIO_MAX mentioned anywhere really. I found some Debian bugreport [1] which shows that these values are the same as in kernel headers. But a quick grep shows that they aren't used in kernel source anyway.

I think you could assume that the range for priorities is <PRIO_MIN, PRIO_MAX) ∩ ℤ. If you'd like to fight for it, I'd suggest going upstream (and that's what probably the dev would do) but I can reassign the bug. Otherwise, please let me know and I'll close the bug.

[1] http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=89089
Comment 5 Checker 2010-09-13 00:15:53 UTC
in gnome-system-manager it sets 19 nistead of 20
in another program (bitcoin) after setpriority(PRIO_PROCESS, 0, 20) it stays at 0
Comment 6 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2010-09-13 06:55:02 UTC
(In reply to comment #5)
> in gnome-system-manager it sets 19 nistead of 20

That's correct. That's what should happen after setpriority(PRIO_PROCESS, somepid, 1000) too.

> in another program (bitcoin) after setpriority(PRIO_PROCESS, 0, 20) it stays at
> 0

I don't see such a package in gx86. Could you point me to where the program comes from?
Comment 7 Checker 2010-09-14 09:51:22 UTC
bitcoin comes from booboo overlay

gnome-system-manager says that it can set 20 (max) but it sets 19...
Comment 8 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2010-09-14 16:03:24 UTC
(In reply to comment #7)
> bitcoin comes from booboo overlay

Ok, I've looked at its source code and I don't see anything special about it. A simple test program doing 'setpriority(PRIO_PROCESS, 0, 20)' works as expected. Thus, I assume this might be a forking/threading issue. Anyway, I can't do anything about it.

About gnome-system-manager, I don't know if we can do anything either. Maybe g-s-m gets the PRIO_MAX value wrong, or maybe glibc headers are indeed wrong.
Comment 9 SpanKY gentoo-dev 2010-09-14 20:59:09 UTC
i see nothing in your output that indicates a bug in glibc.  it merely exists to forward along calls to the kernel and as your strace shows, it is doing just that.

as for why a process doing "setpriority(PRIO_PROCESS, 0, 20)" on itself doesnt work, that sounds like something the process opted in for and the kernel is enforcing it, or the kernel is broken in someway.

you can try simple kernel calls yourself:
#include <sys/syscall.h>
main() {
    syscall(__NR_getpriority, 0, 0);
    syscall(__NR_setpriority, 0, 0, 200);
    syscall(__NR_getpriority, 0, 0);
}

stracing that on a simple process shows:
getpriority(PRIO_PROCESS, 0)            = 20
setpriority(PRIO_PROCESS, 0, 200)       = 0
getpriority(PRIO_PROCESS, 0)            = 1

the return value of the getpriority() syscall is biased so that it always returns a positive value.  so you have to take the kernel returned value, subtract it from 20, and that will tell you the nice level (i.e. prio = 20 - getpriority()).

the process started out with a nice level of 0, so the kernel returned 20 (20 - 20 == 0).  then the process raised itself to a really large value, but the kernel only allowed it up to 19 (20 - 19 == 1).  look at the 19th field of /proc/.../pid if you want to double check:
$ awk '{print $19}' /proc/`pidof a.out`/stat
19
Comment 10 Pacho Ramos gentoo-dev 2010-12-26 09:55:32 UTC
Well, gnome team only maintained gnome-system-monitor, then, this bug will be used for handling it. About "bitcoin", you should contact its upstream or, at least, the maintainer of that unofficial overlay.

Regarding the issue with gnome-system-monitor, I would probably open a bug to upstream: bugzilla.gnome.org (system-monitor product)
Comment 11 Pacho Ramos gentoo-dev 2011-01-27 19:43:12 UTC
Reported to upstream, we will track the issue there:
https://bugzilla.gnome.org/show_bug.cgi?id=640755