libc/sched: Map the nice value more correctly

from https://pubs.opengroup.org/onlinepubs/007904875/functions/setpriority.html:
1.The nice value shall in the range [-{NZERO},{NZERO} -1]
2.Lower nice value shall cause more favorable scheduling

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: I5ad60d92abc3b69fbaa406da68cec2e40ca3fa6d
This commit is contained in:
Xiang Xiao 2021-06-22 17:00:09 +08:00 committed by Alan Carvalho de Assis
parent fe992a5b6c
commit 3d0320f891
3 changed files with 8 additions and 4 deletions

View File

@ -276,10 +276,10 @@
#define NL_TEXTMAX _POSIX2_LINE_MAX
/* NZERO
* Default process priority. Minimum Acceptable Value: 20
* Default process priority. Minimum Acceptable Value: 128
*/
#define NZERO 20
#define NZERO 128
/* Required for asynchronous I/O */

View File

@ -82,5 +82,9 @@ int getpriority(int which, id_t who)
return ret;
}
return param.sched_priority;
/* Since -1 is a legal return value, clear errno to avoid the chaos */
set_errno(0);
return NZERO - param.sched_priority;
}

View File

@ -69,7 +69,7 @@ int setpriority(int which, id_t who, int value)
return ret;
}
param.sched_priority = value;
param.sched_priority = NZERO - value;
return sched_setparam(who, &param);
}