From b8d3e32bdfdc85841a3de4f4589ce972e9cb1987 Mon Sep 17 00:00:00 2001 From: Petro Karashchenko Date: Fri, 7 Jul 2023 12:04:59 +0300 Subject: [PATCH] sched/clock: move clock_getcpuclockid() and clock_getres() to libc Signed-off-by: Petro Karashchenko --- include/sys/syscall_lookup.h | 2 -- libs/libc/libc.csv | 3 ++- libs/libc/sched/Make.defs | 1 + .../libc/sched}/clock_getcpuclockid.c | 20 +++++++++---------- .../clock => libs/libc/sched}/clock_getres.c | 4 ++-- sched/clock/Make.defs | 6 ++---- syscall/syscall.csv | 2 -- 7 files changed, 16 insertions(+), 22 deletions(-) rename {sched/clock => libs/libc/sched}/clock_getcpuclockid.c (92%) rename {sched/clock => libs/libc/sched}/clock_getres.c (97%) diff --git a/include/sys/syscall_lookup.h b/include/sys/syscall_lookup.h index fde71f9d82..ebe9f0bff9 100644 --- a/include/sys/syscall_lookup.h +++ b/include/sys/syscall_lookup.h @@ -170,8 +170,6 @@ SYSCALL_LOOKUP(clock_nanosleep, 4) */ SYSCALL_LOOKUP(clock, 0) -SYSCALL_LOOKUP(clock_getcpuclockid, 2) -SYSCALL_LOOKUP(clock_getres, 2) SYSCALL_LOOKUP(clock_gettime, 2) SYSCALL_LOOKUP(clock_settime, 2) #ifdef CONFIG_CLOCK_TIMEKEEPING diff --git a/libs/libc/libc.csv b/libs/libc/libc.csv index e4d729b72b..7b76aa4b3f 100644 --- a/libs/libc/libc.csv +++ b/libs/libc/libc.csv @@ -33,7 +33,8 @@ "cfgetspeed","termios.h","","speed_t","FAR const struct termios *" "cfsetspeed","termios.h","","int","FAR struct termios *","speed_t" "chdir","unistd.h","!defined(CONFIG_DISABLE_ENVIRON)","int","FAR const char *" -"clock","time.h","","clock_t" +"clock_getcpuclockid","time.h","","int","pid_t","FAR clockid_t *" +"clock_getres","time.h","","int","clockid_t","FAR struct timespec *" "closedir","dirent.h","","int","DIR *" "crc32","nuttx/crc32.h","","uint32_t","FAR const uint8_t *","size_t" "crc32part","nuttx/crc32.h","","uint32_t","FAR const uint8_t *","size_t","uint32_t" diff --git a/libs/libc/sched/Make.defs b/libs/libc/sched/Make.defs index 9c639bc20d..e62603aa7c 100644 --- a/libs/libc/sched/Make.defs +++ b/libs/libc/sched/Make.defs @@ -23,6 +23,7 @@ CSRCS += sched_getprioritymax.c sched_getprioritymin.c CSRCS += clock_ticks2time.c clock_time2ticks.c CSRCS += clock_timespec_add.c clock_timespec_subtract.c +CSRCS += clock_getcpuclockid.c clock_getres.c ifneq ($(CONFIG_CANCELLATION_POINTS),y) CSRCS += task_setcanceltype.c task_testcancel.c diff --git a/sched/clock/clock_getcpuclockid.c b/libs/libc/sched/clock_getcpuclockid.c similarity index 92% rename from sched/clock/clock_getcpuclockid.c rename to libs/libc/sched/clock_getcpuclockid.c index d26731bee1..fe73f29e74 100644 --- a/sched/clock/clock_getcpuclockid.c +++ b/libs/libc/sched/clock_getcpuclockid.c @@ -1,5 +1,5 @@ /**************************************************************************** - * sched/clock/clock_getcpuclockid.c + * libs/libc/sched/clock_getcpuclockid.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -25,10 +25,10 @@ #include #include -#include -#include -#include "clock/clock.h" +#include +#include +#include /**************************************************************************** * Public Functions @@ -52,17 +52,15 @@ int clock_getcpuclockid(pid_t pid, FAR clockid_t *clockid) { - if (pid < 0) - { - set_errno(EINVAL); - return ERROR; - } - /* If the pid is 0, we need to use the pid of current process */ if (pid == 0) { - pid = getpid(); + pid = _SCHED_GETPID(); + } + else if (_SIG_KILL(pid, 0) < 0) + { + return ERROR; } /* For clock_getcpuclockid, the clock type are diff --git a/sched/clock/clock_getres.c b/libs/libc/sched/clock_getres.c similarity index 97% rename from sched/clock/clock_getres.c rename to libs/libc/sched/clock_getres.c index 99ed173a5f..3da1f34413 100644 --- a/sched/clock/clock_getres.c +++ b/libs/libc/sched/clock_getres.c @@ -1,5 +1,5 @@ /**************************************************************************** - * sched/clock/clock_getres.c + * libs/libc/sched/clock_getres.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -29,7 +29,7 @@ #include #include -#include "clock/clock.h" +#include /**************************************************************************** * Public Functions diff --git a/sched/clock/Make.defs b/sched/clock/Make.defs index fc7ff0a952..2a05343824 100644 --- a/sched/clock/Make.defs +++ b/sched/clock/Make.defs @@ -18,10 +18,8 @@ # ############################################################################ -CSRCS += clock_initialize.c clock_settime.c clock_gettime.c clock_getres.c -CSRCS += clock_abstime2ticks.c -CSRCS += clock_systime_ticks.c clock_systime_timespec.c -CSRCS += clock.c clock_getcpuclockid.c +CSRCS += clock.c clock_initialize.c clock_settime.c clock_gettime.c +CSRCS += clock_abstime2ticks.c clock_systime_ticks.c clock_systime_timespec.c ifeq ($(CONFIG_CLOCK_TIMEKEEPING),y) CSRCS += clock_timekeeping.c diff --git a/syscall/syscall.csv b/syscall/syscall.csv index d0f1b3433f..c6a535d2ec 100644 --- a/syscall/syscall.csv +++ b/syscall/syscall.csv @@ -13,8 +13,6 @@ "chown","unistd.h","","int","FAR const char *","uid_t","gid_t" "clearenv","stdlib.h","!defined(CONFIG_DISABLE_ENVIRON)","int" "clock","time.h","","clock_t" -"clock_getcpuclockid","time.h","","int","pid_t","FAR clockid_t *" -"clock_getres","time.h","","int","clockid_t","FAR struct timespec *" "clock_gettime","time.h","","int","clockid_t","FAR struct timespec *" "clock_nanosleep","time.h","","int","clockid_t","int","FAR const struct timespec *", "FAR struct timespec *" "clock_settime","time.h","","int","clockid_t","const struct timespec*"