- cleanup

- fix non UTF-8 in comments
- fixed unix priority scaling


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29946 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
François Revol
2009-04-05 18:18:27 +00:00
parent dd6ab6242c
commit 1a7cbee5c2
+25 -22
View File
@@ -1,5 +1,5 @@
/* renice.c - unixish renice command for BeOs /* renice.c - unixish renice command for BeOs
* (c) 2001, 2002, François Revol (mmu_man) for OpenBeOS * (c) 2001, 2002, François Revol (mmu_man) for OpenBeOS
* released under the MIT licence. * released under the MIT licence.
* *
* How did I live without it before ??? ;) * How did I live without it before ??? ;)
@@ -8,7 +8,7 @@
* Cleanup for inclusion in OpenBeOS, * Cleanup for inclusion in OpenBeOS,
* Used the code to rewrite the 'prio' BeOS command for OpenBeOS. * Used the code to rewrite the 'prio' BeOS command for OpenBeOS.
* 04-14-2002 v1.1 * 04-14-2002 v1.1
* Added -f upon suggestion from Idéfix on BeShare * Added -f upon suggestion from Idéfix on BeShare
* 2001 v1.0 * 2001 v1.0
* Initial. * Initial.
*/ */
@@ -24,41 +24,43 @@ From man renice:
/usr/sbin/renice [-n increment] [-p] [-g | -u] ID ... /usr/sbin/renice priority [-p] pid ... [-g pgrp ...] [-u user ...] /usr/sbin/renice [-n increment] [-p] [-g | -u] ID ... /usr/sbin/renice priority [-p] pid ... [-g pgrp ...] [-u user ...]
#define B_LOW_PRIORITY 5
#define B_NORMAL_PRIORITY 10
#define B_DISPLAY_PRIORITY 15
#define B_URGENT_DISPLAY_PRIORITY 20
#define B_REAL_TIME_DISPLAY_PRIORITY 100
#define B_URGENT_PRIORITY 110
#define B_REAL_TIME_PRIORITY 120
BeOs priorities: BeOs priorities:
High Prio (realtime) Default Low Prio (realtime) High Prio Default Low Prio
120 10 1 (0 only for idle_thread) 120 99 10 1 (0 only for idle_thread)
UNIX Priorities: UNIX nice:
-20 0 20 -20 0 19
UNIX priorities:
Note that however this isn't perfect, since priorities 0 20 39
beyond 100 in BeOS move the thread into the real-time class.
Linux for example, has a separate API for doing this,
and even a process set to -20 can be in the normal scheduling class.
renice can be given more than one pid on the command line. renice can be given more than one pid on the command line.
prio is locked into one pid, then the priority. prio is locked into one pid, then the priority.
*/ */
#ifndef NZERO
#define NZERO 20
#endif
#define BZERO B_NORMAL_PRIORITY
#define BMIN (B_REAL_TIME_DISPLAY_PRIORITY-1)
//#define BMAX B_NORMAL_PRIORITY
#define BMAX 1
// returns an equivalent UNIX priority for a given BeOS priority. // returns an equivalent UNIX priority for a given BeOS priority.
static int32 prio_be_to_unix(int32 prio) static int32 prio_be_to_unix(int32 prio)
{ {
return (prio > 10)?(- (20 * (prio - 10)) / 110):(2 * (10 - prio)); if (prio > BZERO)
return NZERO - ((prio - BZERO) * NZERO) / (BMIN - BZERO);
return NZERO + ((BZERO - prio) * (NZERO - 1)) / (BZERO - BMAX);
} }
// returns an equivalent BeOS priority for a given UNIX priority. // returns an equivalent BeOS priority for a given UNIX priority.
static int32 prio_unix_to_be(int32 prio) static int32 prio_unix_to_be(int32 prio)
{ {
return (prio > 0)?(10 - (prio/2)):(10 + 110 * (-prio) / 20); if (prio > NZERO)
return BZERO - ((prio - NZERO) * (BZERO - BMAX)) / (NZERO-1);
return BZERO + ((NZERO - prio) * (BMIN - BZERO)) / (NZERO);
} }
static status_t renice_thread(int32 prio, int32 increment, bool use_be_prio, thread_id th) static status_t renice_thread(int32 prio, int32 increment, bool use_be_prio, thread_id th)
@@ -94,7 +96,7 @@ int main(int argc, char **argv)
int err = 1; int err = 1;
char *thname; char *thname;
prio = 9; // default UNIX priority for nice prio = NZERO; // default UNIX priority for nice
// convert it to beos // convert it to beos
if (!use_be_prio) if (!use_be_prio)
prio = prio_unix_to_be(prio); prio = prio_unix_to_be(prio);
@@ -130,6 +132,7 @@ int main(int argc, char **argv)
th = thinfo.thread; th = thinfo.thread;
renice_thread(prio, increment, use_be_prio, th); renice_thread(prio, increment, use_be_prio, th);
err = 0; err = 0;
/* find another one */
} }
} }
} }