Skip to content

Commit

Permalink
posix: implement clock_getcpuclockid function
Browse files Browse the repository at this point in the history
Implements clock_getcpuclockid function

Fixes #59954

Signed-off-by: Jai Arora <infolinesoni@gmail.com>
  • Loading branch information
jaiiarora authored and carlescufi committed Jan 8, 2024
1 parent 410684c commit a3573a9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions include/zephyr/posix/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ extern "C" {
#define CLOCK_REALTIME 1
#endif

#ifndef CLOCK_PROCESS_CPUTIME_ID
#define CLOCK_PROCESS_CPUTIME_ID 2
#endif

#ifndef CLOCK_MONOTONIC
#define CLOCK_MONOTONIC 4
#endif
Expand All @@ -84,6 +88,7 @@ static inline int32_t _ts_to_ms(const struct timespec *to)

int clock_gettime(clockid_t clock_id, struct timespec *ts);
int clock_settime(clockid_t clock_id, const struct timespec *ts);
int clock_getcpuclockid(pid_t pid, clockid_t *clock_id);
/* Timer APIs */
int timer_create(clockid_t clockId, struct sigevent *evp, timer_t *timerid);
int timer_delete(timer_t timerid);
Expand Down
13 changes: 13 additions & 0 deletions lib/posix/clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <errno.h>
#include <zephyr/posix/time.h>
#include <zephyr/posix/sys/time.h>
#include <zephyr/posix/unistd.h>
#include <zephyr/internal/syscall_handler.h>
#include <zephyr/spinlock.h>

Expand Down Expand Up @@ -222,3 +223,15 @@ int gettimeofday(struct timeval *tv, void *tz)

return res;
}

int clock_getcpuclockid(pid_t pid, clockid_t *clock_id)
{
/* We don't allow any process ID but our own. */
if (pid != 0 && pid != getpid()) {
return EPERM;
}

*clock_id = CLOCK_PROCESS_CPUTIME_ID;

return 0;
}

0 comments on commit a3573a9

Please sign in to comment.