libroot: fix pthread_[g/s]etschedparam
Make `pthread_getschedparam` and `pthread_setschedparam` handle scheduling policies more consistently with `sched_get_priority_min` and `sched_get_priority_max`. Threads running in real-time priority will appear to be under the `SCHED_RR` policy, while normal threads will appaer to be `SCHED_OTHER`. This prevents POSIX code using `sched_get_priority_min` with the calling thread's current policy returned by `pthread_getschedparam` to adjust its priority from unwantedly promote into real-time code and affect overall system performance. Change-Id: I9664257dc1b98db579e55218ce352cb762524b0c Reviewed-on: https://review.haiku-os.org/c/haiku/+/6556 Reviewed-by: Adrien Destugues <[email protected]> Tested-by: Commit checker robot <[email protected]>
This commit is contained in:
committed by
waddlesplash
parent
6f3f29c7dd
commit
c80a875a74
@@ -285,8 +285,12 @@ pthread_getschedparam(pthread_t thread, int *policy, struct sched_param *param)
|
||||
if (status == B_BAD_THREAD_ID)
|
||||
return ESRCH;
|
||||
param->sched_priority = info.priority;
|
||||
if (policy != NULL)
|
||||
*policy = SCHED_RR;
|
||||
if (policy != NULL) {
|
||||
if (info.priority >= B_FIRST_REAL_TIME_PRIORITY)
|
||||
*policy = SCHED_RR;
|
||||
else
|
||||
*policy = SCHED_OTHER;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -296,8 +300,12 @@ pthread_setschedparam(pthread_t thread, int policy,
|
||||
const struct sched_param *param)
|
||||
{
|
||||
status_t status;
|
||||
if (policy != SCHED_RR)
|
||||
if (policy != SCHED_RR && policy != SCHED_OTHER)
|
||||
return ENOTSUP;
|
||||
if (policy == SCHED_RR && param->sched_priority < B_FIRST_REAL_TIME_PRIORITY)
|
||||
return EINVAL;
|
||||
if (policy == SCHED_OTHER && param->sched_priority >= B_FIRST_REAL_TIME_PRIORITY)
|
||||
return EINVAL;
|
||||
status = _kern_set_thread_priority(thread->id, param->sched_priority);
|
||||
if (status == B_BAD_THREAD_ID)
|
||||
return ESRCH;
|
||||
|
||||
Reference in New Issue
Block a user