help: nptl thread priority setting

Submitted by Anonymous
on January 17, 2006 - 10:12am

Anybody know how to see threads from a single process and set their priority under kernel 2.6? I need to know this because i'm having a very strange behaviour of my Java threads under fedora core 4. Their priority seem overlapping each other.
In kernel 2.4 I can see threads as different processes. But with newly attached nptl, i cannot see them. I've tried ksysguard, top, ps, but none of them can give me the answer.

Thank you for anybody that can respond to this question. Mike.

found it in 5 seconds

strcmp
on
January 17, 2006 - 12:34pm

i just entered ps --help and it showed some possible flags under the 'misc options'. so try again...

thread is not different process

sunyzero
on
January 20, 2006 - 1:13am

may be used linuxthread on 2.4, i guess. (it's not native thread library. it just imitation)

NPTL is native thread library.
and you couldn't renice thread priority .

'ps' command can't show thread informations.

only you can renice about 'java' process.

"ps auxT" should show threads

Anonymous (not verified)
on
January 20, 2006 - 4:25am

"ps auxT" should show threads

Like somebody already said, you can only renice the whole JVM (as threads share the same PID)

To change individual thread priorities you could use Thread.setPriority() in Java.

Reading nptl-design.pdf (ch.

cavok
on
January 31, 2006 - 4:39am

Reading nptl-design.pdf (ch. "8 Remaining Challenges"):

"Realtime support is mostly missing from the library implementation. The system calls to select scheduling parameters are available but they have no effects. The reason for this is that large parts of the kernel do not follow the rules for realtime scheduling. Waking one of the threads waiting for a futex is not done by looking at the priorities of the waiters."

Reading this thread, it looks like this limitation has been removed.

Who is right?

Thanks

How do you set the thread priority with NPTL - 2.6 kernel?

sibel (not verified)
on
February 6, 2006 - 11:04am

AFAIK, 1)Since the NPTL threads share the same pid, it's not possible to use nice(). 2)pthread_setschedparam() is for changing the real time priority and has no effect on non-real time threads.

Is it possible to set the priority of a non-real time thread? If yes, how?
Thanks.
Sibel

Yes it is, using nice. From

Anonymous (not verified)
on
October 25, 2007 - 10:48pm

Yes it is, using nice.

From the manual of pthread(7):

NPTL still has a few non-conformances with POSIX.1:

- Threads do not share a common nice value.

With current procps tools:p

Con Kolivas
on
January 21, 2006 - 7:23pm

With current procps tools:
ps Haux

nptl thread priority strange behaviour

Anonymous (not verified)
on
January 22, 2006 - 2:07am

Thank you for everyone who give me replies.

Now i can see the threads from ps, and their priority too.
But their priority level give me more question.
I see some thread have priority -51 (from another process, not Java),
and my Java thread have priority 78,70,etc.
As i know , kernel 2.6 have -20 to 19 normal priority level, and
0 to 99 real-time priority level. And, the scheduler must give 5 level penalty for the CPU bound thread and boost 5 level for IO bound threads. How can I see priority numbers that is not in the range. I'm also not believing that my Java threads use real-time priority level.

I really appreciate your responses. Thank you.

Linux normally has its 139 pr

Anonymous (not verified)
on
January 31, 2006 - 1:42am

Linux normally has its 139 priorities. Real-time priorities ranging from 0-99 and dynamic priorities ranging from -19-20 (but actually acting as 100-139). I find the priority listings from ps or top confusing. Top looks like it maps the dynamic properties to positve values and the realtime to negative (or subtracts an offset of 100). I have found the best way to display them with 'ps -o rtprio,pri,command'. Though I cant make sense of you have processes with priorities -51 and 78.

Negative PR values are the pr

Con Kolivas
on
January 31, 2006 - 7:08pm

Negative PR values are the procps tools' way of showing real time threads. Anything below 0 is running real time. This is the scale because normal tasks are 0-39 and better priority must be a lower number so the negative values represent the proportionality of the priorities. A -20 PR for example would be approx realtime priority 20 and -50 PR would be realtime 50.

reply: Negative PR values are the pr

Anonymous (not verified)
on
February 1, 2006 - 9:14am

So in ps, realtime priority -> the lower the number the lower the priority and normal priority -> the higher the number the lower the priority? I mean, if we have pri -99 in ps, is it the lowest rt priority in the system? And if we have pri 39, is it the lowest normal priority in the system?

If yes, how can that explain this:
if i use ps -lAL, kthread has pri 70 and nice -5
if i use ps -ALo comm,pri,ni , kthread has pri 29 and nice -5

If i use top there is different result, kthread has pri 10 and nice -5

I'm sorry i ask too many question, but it's really confusing.
Thank you.

Nice != realtime priority

Con Kolivas
on
February 1, 2006 - 3:54pm

The lower the PR number, the *better* the priority is regardless of whether it is realtime or not. Nice value is NOT realtime priority; they are two different entities. Non realtime tasks only have a nice value. Realtime tasks have a realtime priority which is used, and a nice value which is unused unless they are dropped back to non-rt scheduling.

The other difference is that with 'nice' values, lower is *better*, and with realtime priorities, higher is *better*.

reply: Nice != realtime priority

Anonymous (not verified)
on
February 2, 2006 - 10:48am

Hello Con Colivas. Thank you for your explanation. But i still have questions.

I have read the sched.c for kernel 2.6.11.10

In the sched.c there is variable: #define NICE_TO_PRIO(nice) (MAX_RT_PRIO + (nice) + 20)
Because MAX_RT_PRIO is 100, so I expect that:

* if a process has nice = -20, it will get prio = 100-20+20 = 100
* if a process has nice = 0 , it will get prio = 100+0+20 = 120
* if a process has nice = 19 , it will get prio = 100+19+20 = 139

And so the range will be from 100(best priority) to 139(worst priority).
What is the best way to show this value from ps or top or any other tools?
With 100 is the best normal priority, i suppose that 0 is the best realtime priority
and 99 is the worst realtime priority. Am i right?

There is also variable: #define USER_PRIO(p) ((p)-MAX_RT_PRIO)

So the user_prio will have range from 0(best priority) to 39(worst priority).
Is it the value under (priority) column in (ps -ALo priority,pri,ni,comm) ?
Where did ps get the value under (pri) column?

And when i looked this comment:
/*
* Convert user-nice values [ -20 ... 0 ... 19 ]
* to static priority [ MAX_RT_PRIO..MAX_PRIO-1 ],
* and back.
*/
I suppose that there is MAX_PRIO priority in the system that has static
priority of 140. I believe that this value cannot be accessed with giving
a process a nice value of +20. How can i use this? Is it the IDLE_PRIORITY?

And in variable: #define NS_TO_JIFFIES(TIME) ((TIME) / (1000000000 / HZ))
What is HZ?

Thank you for your attention and answers.

'top' and 'ps' report PRI whi

Con Kolivas
on
February 2, 2006 - 8:34pm

'top' and 'ps' report PRI which is the dynamic priority the way userspace is meant to see it. The kernel does this by exporting the value of p->prio - 100.

And so the range will be from 100(best priority) to 139(worst priority).What is the best way to show this value from ps or top or any other tools?

Add 100 to the PRI column value.

With 100 is the best normal priority, i suppose that 0 is the best realtime priority and 99 is the worst realtime priority. Am i right?

Yes as represented in userspace, the lowest number is the best priority.

So the user_prio will have range from 0(best priority) to 39(worst priority).
Is it the value under (priority) column in (ps -ALo priority,pri,ni,comm) ?
Where did ps get the value under (pri) column?

It is pri which as I said before the kernel exports the 0-140 value subtracting 100.

I suppose that there is MAX_PRIO priority in the system that has static priority of 140. I believe that this value cannot be accessed with giving a process a nice value of +20. How can i use this? Is it the IDLE_PRIORITY?

You can't use it. It specifies idle because nothing is ever that priority.

And in variable: #define NS_TO_JIFFIES(TIME) ((TIME) / (1000000000 / HZ)) What is HZ?

It is whatever you configure it in your kernel build.. 100,250 or 1000.

reply: 'top' and 'ps' report PRI whi

Anonymous (not verified)
on
February 4, 2006 - 12:07pm

Thank you very much for your help. It's much clearer now

Do you know how to show threads from top? Because i want to
log the results of my Java performance to a text file.
Or any suggestion of another tool that can show threads and log the
results to a file.
Btw, do know how java thread priority are mapped to linux thread
priority?

Thank you.

'top' can't show threads. Wri

Con Kolivas
on
February 5, 2006 - 7:52pm

'top' can't show threads. Write a script to parse ps output at regular intervals. I have no idea about java but I suspect it just inherits the parent priority unless you specify otherwise.

Found priority mapping Java to Linux

Anonymous (not verified)
on
February 6, 2006 - 10:59am

Hello Con Kolivas.

Today i have downloaded the Java source. And in
\hotspot\src\os\linux\vm\os_linux.cpp i found this:

// thread priority support

// TODO: the entire priority issue needs to be overhauled.
// [jk]: Linux doesn't support priorities with SCHED_OTHER

#define T_PRI_MIN 1
#define T_PRI_NORM 1
#define T_PRI_MAX 1

int os::java_to_os_priority[MaxPriority + 1] = {
0, // 0 Entry should never be used

1, // 1 MinPriority
2, // 2
3, // 3

4, // 4
5, // 5 NormPriority
6, // 6

7, // 7
8, // 8
9, // 9 NearMaxPriority

10 // 10 MaxPriority
};

// Note: LinuxThreads only honor thread priority for real time threads.
// sched_priority is ignored if policy is SCHED_OTHER. This function is
// equivalent to a "noop" on current Linux platforms.

OSReturn os::set_native_priority(Thread* thread, int newpri) {
if ( !UseThreadPriorities ) return OS_OK;
pthread_t thr = thread->osthread()->pthread_id();
int policy = SCHED_OTHER;
struct sched_param param;
param.sched_priority = newpri;
int ret = pthread_setschedparam(thr, policy, &param);
return (ret == 0) ? OS_OK : OS_ERR;
}

Is it true that in Linux we can't set thread priority from SCHED_OTHER? Or is it just in LinuxThreads that we can't set thread priority?
If threads are created with this code, what behaviour will occur?

Thank you.

'top' can indeed show threads

Anonymous (not verified)
on
May 8, 2006 - 9:32am

'top' can indeed show threads. While top is running, press the 'H' key to toggle whether or not threads are displayed.

For a list of other useful top commands, press the 'h' key.

Can 'top' show threads in batch mode?

Anonymous (not verified)
on
May 10, 2006 - 8:53am

'top' can show threads in interactive mode, that's true. But I cannot find the way for it to show threads in batch mode. In 'man' the H option appears as a command-line option, but it actually doesn't let you introduce it as a command-line option. Is it a way of getting this info with the last version of 'top'? I cannot use 'ps' to that purpose, because it shows cumulative %CPU stats, and I need real-time ones.

Thanks to all,

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.