LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 11-12-2008, 02:57 AM   #1
patyogesh
LQ Newbie
 
Registered: Nov 2008
Posts: 3

Rep: Reputation: 0
Question How should i map Windows thread priority macros to Linux?


HI *,
i am porting Windows based application to Linux and facing some difficulties while mapping some thread prority macroes(Windows) to respective Linux values.

As far as i know thread priorities in Windows vary from 1(Lowest) to 31(Highest) where in Linux it varies from 1(Lowest) to 99(Highest).Is this information correct?

Now following are the Macros i am using in Windows for which i want corrosponding values in Linux....

THREAD_PRIORITY_NORMAL 24
THREAD_PRIORITY_TIME_CRITICAL 31
THREAD_PRIORITY_HIGHEST 26
THREAD_PRIORITY_ABOVE_NORMAL 25
THREAD_PRIORITY_BELOW_NORMAL 23
THREAD_PRIORITY_LOWEST 22


Please help ):
 
Old 11-12-2008, 03:13 AM   #2
pinniped
Senior Member
 
Registered: May 2008
Location: planet earth
Distribution: Debian
Posts: 1,732

Rep: Reputation: 50
Quote:
Originally Posted by patyogesh View Post
As far as i know thread priorities in Windows vary from 1(Lowest) to 31(Highest) where in Linux it varies from 1(Lowest) to 99(Highest).Is this information correct?
That is incorrect; from the 'nice' manual pages:

Quote:
Nicenesses range from -20 (most favorable scheduling) to 19 (least favorable).
And from the setpriority() man pages:

Quote:
The actual priority range varies between kernel versions. Linux before 1.3.36 had -infinity..15. Since kernel 1.3.43 Linux has the range -20..19. Within the kernel, nice values are actually represented using the corresponding range 40..1 (since negative numbers are error codes) and these are the values employed by the setpriority() and getpriority() system calls.
[edit] Just to complicate things a bit more, users may be limited in the range of schedule priorities they can request. You need to use sched_get_priority_{min,max}() to get the range you're allowed. Also, I can't remember if different pthreads may have different priorities or if priorities can only be assigned per process (in which case fork() processes can have different priorities but not pthread() processes).

Last edited by pinniped; 11-12-2008 at 03:18 AM.
 
Old 11-12-2008, 04:12 AM   #3
patyogesh
LQ Newbie
 
Registered: Nov 2008
Posts: 3

Original Poster
Rep: Reputation: 0
Question

" nice values are actually represented using the corresponding range 40..1 (since negative numbers are error codes) and these are the values employed by the setpriority() and getpriority() system calls."

so which values should i use corrosponding to following priorities?

THREAD_PRIORITY_NORMAL 24
THREAD_PRIORITY_TIME_CRITICAL 31
THREAD_PRIORITY_HIGHEST 26
THREAD_PRIORITY_ABOVE_NORMAL 25
THREAD_PRIORITY_BELOW_NORMAL 23
THREAD_PRIORITY_LOWEST 22


and if windows have these Predefien Macros corrosponding to thread priority values, doesn't Linux have the same kind of Macros?
 
Old 11-12-2008, 05:20 AM   #4
pinniped
Senior Member
 
Registered: May 2008
Location: planet earth
Distribution: Debian
Posts: 1,732

Rep: Reputation: 50
Quote:
Originally Posted by patyogesh View Post
so which values should i use corrosponding to following priorities?

THREAD_PRIORITY_NORMAL 24
THREAD_PRIORITY_TIME_CRITICAL 31
THREAD_PRIORITY_HIGHEST 26
THREAD_PRIORITY_ABOVE_NORMAL 25
THREAD_PRIORITY_BELOW_NORMAL 23
THREAD_PRIORITY_LOWEST 22


and if windows have these Predefien Macros corrosponding to thread priority values, doesn't Linux have the same kind of Macros?
1. It is absolutely ridiculous to think that a priority value in one system would map to a priority value in another system with the same effect; one (of numerous) contributing factor is the mechanics of the system's scheduler. On top of that, priority values must be set according to individual situations in order to achieve the desired performance. In applications where the priority does in fact matter, you cannot simply set a value and presume that is the correct value for different situations.

2. I can only guess that MS has defined those macros as some sort of guide to programmers; the names themselves have no special meaning whatsoever. As I have already mentioned, priorities need to be set on a case-by-case basis and the behavior depends on the implementation of the scheduler. In reality there is no guarantee that your software will meet requirements on a particular system even if you always requested the highest priority, so setting fixed priorities does not make sense. What would make sense is to test at runtime if requirements are being met and to escalate priority as required; keep in mind that it is possible that requirements cannot be met due to other circumstances such as high load.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
But why google map goes faster in windows explorer under XP, than linux ?? frenchn00b Debian 3 05-10-2008 12:13 AM
how to map linux share on windows domain controller prakash.j Linux - Newbie 1 01-25-2008 03:52 PM
Priority of Linux process/thread scanner Linux - Newbie 1 07-07-2006 12:49 AM
thread priority tornatom Programming 0 08-22-2005 01:00 PM
How do i map linux on Windows? vicky4u_hyd Linux - Networking 1 08-25-2004 01:29 AM


All times are GMT -5. The time now is 05:34 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration