From 97559999f0921b200817d9914ad4478b7d94c237 Mon Sep 17 00:00:00 2001 From: caifuzhou <504631861@qq.com> Date: Thu, 2 Dec 2021 09:35:28 +0800 Subject: [PATCH] =?UTF-8?q?porting=E9=87=8C=E6=96=B0=E5=A2=9E=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3sched=5Fsetscheduler=EF=BC=8C=E4=BF=AE=E6=94=B9musl=5F?= =?UTF-8?q?src.gni=EF=BC=8C=E6=96=B0=E5=A2=9E=E5=AF=B9=E5=BA=94=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E7=94=A8=E4=BE=8B=E5=B9=B6=E4=BF=AE=E6=94=B9test=5Fsr?= =?UTF-8?q?c=5Ffunctional.gni?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: caifuzhou <504631861@qq.com> --- libc-test/src/functional/sched_setscheduler.c | 28 +++++++++++++++++++ .../src/functional/test_src_functional.gni | 1 + musl_src.gni | 1 + .../linux/user/src/sched/sched_setscheduler.c | 20 +++++++++++++ 4 files changed, 50 insertions(+) create mode 100644 libc-test/src/functional/sched_setscheduler.c create mode 100644 porting/linux/user/src/sched/sched_setscheduler.c diff --git a/libc-test/src/functional/sched_setscheduler.c b/libc-test/src/functional/sched_setscheduler.c new file mode 100644 index 00000000..bb12bd20 --- /dev/null +++ b/libc-test/src/functional/sched_setscheduler.c @@ -0,0 +1,28 @@ +#include +#include +#include +#include +#include +#include +#include "test.h" + +#define TEST(c) ((!c) ? 1 : (t_error(#c" failed: %s" ,strerror(errno)),0)) + +int main(int argc,char *argv[]) +{ + struct sched_param param; + int maxpri; + + maxpri = sched_get_priority_max(SCHED_FIFO); + if(maxpri == -1) + { + perror("get priority failed"); + return -1; + } + param.sched_priority = maxpri; + TEST(sched_setscheduler(getpid(), SCHED_FIFO, ¶m)); + TEST(!(sched_getscheduler(getpid()) == SCHED_FIFO)); + + return 0; +} + diff --git a/libc-test/src/functional/test_src_functional.gni b/libc-test/src/functional/test_src_functional.gni index d1b53399..405e3a85 100644 --- a/libc-test/src/functional/test_src_functional.gni +++ b/libc-test/src/functional/test_src_functional.gni @@ -58,6 +58,7 @@ functional_list = [ "strtol", "strtold", "swprintf", + "sched_setscheduler", "tgmath", "time", "tls_align", diff --git a/musl_src.gni b/musl_src.gni index e4029927..27ab81f3 100644 --- a/musl_src.gni +++ b/musl_src.gni @@ -1838,6 +1838,7 @@ musl_src_porting_file = [ "src/multibyte/wcsnrtombs.c", "src/network/inet_legacy.c", "src/passwd/getspnam_r.c", + "src/sched/sched_setscheduler.c", "src/thread/arm/clone.s", "src/thread/arm/syscall_cp.s", ] diff --git a/porting/linux/user/src/sched/sched_setscheduler.c b/porting/linux/user/src/sched/sched_setscheduler.c new file mode 100644 index 00000000..bfedb49b --- /dev/null +++ b/porting/linux/user/src/sched/sched_setscheduler.c @@ -0,0 +1,20 @@ +#include +#include +#include "syscall.h" +#include "pthread_impl.h" + +int sched_setscheduler(pid_t pid, int sched, const struct sched_param *param) +{ + int r; + if (!param) { + r = -EINVAL; + goto exit; + } + + r = __syscall(SYS_sched_setscheduler, pid, sched, param);//, MUSL_TYPE_PROCESS +; +exit: + + + return __syscall_ret(r); +} \ No newline at end of file -- GitLab