mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-29 14:23:22 +00:00
Fix mapping between sched_attr
and SchedPolicy
This commit is contained in:
@ -69,16 +69,26 @@ impl TryFrom<SchedPolicy> for LinuxSchedAttr {
|
||||
..Default::default()
|
||||
},
|
||||
|
||||
// The SCHED_IDLE policy is mapped to the highest nice value of
|
||||
// `SchedPolicy::Fair` instead of `SchedPolicy::Idle`. Tasks of the
|
||||
// latter policy are invisible to the user API.
|
||||
SchedPolicy::Fair(Nice::MAX) => LinuxSchedAttr {
|
||||
sched_policy: SCHED_IDLE,
|
||||
..Default::default()
|
||||
},
|
||||
|
||||
SchedPolicy::Fair(nice) => LinuxSchedAttr {
|
||||
sched_policy: SCHED_NORMAL,
|
||||
sched_nice: nice.value().get().into(),
|
||||
..Default::default()
|
||||
},
|
||||
|
||||
SchedPolicy::Idle => LinuxSchedAttr {
|
||||
sched_policy: SCHED_IDLE,
|
||||
..Default::default()
|
||||
},
|
||||
SchedPolicy::Idle => {
|
||||
return Err(Error::with_message(
|
||||
Errno::EACCES,
|
||||
"attr for idle tasks are not accessible",
|
||||
))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -112,7 +122,10 @@ impl TryFrom<LinuxSchedAttr> for SchedPolicy {
|
||||
.map_err(|msg| Error::with_message(Errno::EINVAL, msg))?,
|
||||
)),
|
||||
|
||||
SCHED_IDLE => SchedPolicy::Idle,
|
||||
// The SCHED_IDLE policy is mapped to the highest nice value of
|
||||
// `SchedPolicy::Fair` instead of `SchedPolicy::Idle`. Tasks of the
|
||||
// latter policy are invisible to the user API.
|
||||
SCHED_IDLE => SchedPolicy::Fair(Nice::MAX),
|
||||
|
||||
_ => {
|
||||
return Err(Error::with_message(
|
||||
|
31
test/apps/sched/sched_attr_idle.c
Normal file
31
test/apps/sched/sched_attr_idle.c
Normal file
@ -0,0 +1,31 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
#define _GNU_SOURCE
|
||||
#include <assert.h>
|
||||
#include <pthread.h>
|
||||
#include <sched.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define SCHED_IDLE 5
|
||||
|
||||
void *test(void *__arg)
|
||||
{
|
||||
struct sched_param param = { .sched_priority = 0 };
|
||||
assert(sched_setscheduler(0, SCHED_IDLE, ¶m) == 0);
|
||||
sleep(1);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
pthread_t thread;
|
||||
assert(pthread_create(&thread, NULL, test, NULL) == 0);
|
||||
test(NULL);
|
||||
|
||||
pthread_join(thread, NULL);
|
||||
printf("Test completed\n");
|
||||
|
||||
return 0;
|
||||
}
|
@ -39,6 +39,7 @@ pthread/pthread_test
|
||||
pty/open_pty
|
||||
pty/pty_blocking
|
||||
sched/sched_attr
|
||||
sched/sched_attr_idle
|
||||
shm/posix_shm
|
||||
signal_c/parent_death_signal
|
||||
signal_c/signal_test
|
||||
|
Reference in New Issue
Block a user