From 3938f80055e6fc912e32c88629fad17998584e02 Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Wed, 15 May 2013 12:37:39 +0200 Subject: [PATCH] Add timens(2). --- libc/Makefile | 1 + libc/include/time.h | 4 +++ libc/time/timens.cpp | 34 +++++++++++++++++++++++ sortix/include/sortix/syscallnum.h | 3 ++- sortix/include/sortix/tmns.h | 43 ++++++++++++++++++++++++++++++ sortix/user-timer.cpp | 28 +++++++++++++++++-- 6 files changed, 110 insertions(+), 3 deletions(-) create mode 100644 libc/time/timens.cpp create mode 100644 sortix/include/sortix/tmns.h diff --git a/libc/Makefile b/libc/Makefile index f9dfe5cd..27ddc314 100644 --- a/libc/Makefile +++ b/libc/Makefile @@ -358,6 +358,7 @@ time/clock_nanosleep.o \ time/clock_settime.o \ time/clock_settimeres.o \ time/nanosleep.o \ +time/timens.o \ time/time.o \ time/timer_create.o \ time/timer_delete.o \ diff --git a/libc/include/time.h b/libc/include/time.h index 6d7305b3..2ebe8a03 100644 --- a/libc/include/time.h +++ b/libc/include/time.h @@ -55,6 +55,9 @@ struct tm __END_DECLS #include #include +#if defined(_SORTIX_SOURCE) +#include +#endif __BEGIN_DECLS @include(NULL.h) @@ -106,6 +109,7 @@ void tzset(void); #if defined(_SORTIX_SOURCE) int clock_gettimeres(clockid_t, struct timespec*, struct timespec*); int clock_settimeres(clockid_t, const struct timespec*, const struct timespec*); +int timens(struct tmns* tmns); #endif extern int daylight; diff --git a/libc/time/timens.cpp b/libc/time/timens.cpp new file mode 100644 index 00000000..9119f13a --- /dev/null +++ b/libc/time/timens.cpp @@ -0,0 +1,34 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013 + + This file is part of the Sortix C Library. + + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your + option) any later version. + + The Sortix C Library is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with the Sortix C Library. If not, see . + + time/timens.cpp + Get process execution time statistics. + +*******************************************************************************/ + +#include + +#include + +DEFN_SYSCALL1(int, sys_timens, SYSCALL_TIMENS, struct tmns*); + +extern "C" int timens(struct tmns* tmns) +{ + return sys_timens(tmns); +} diff --git a/sortix/include/sortix/syscallnum.h b/sortix/include/sortix/syscallnum.h index 7895d32b..664abe06 100644 --- a/sortix/include/sortix/syscallnum.h +++ b/sortix/include/sortix/syscallnum.h @@ -127,6 +127,7 @@ #define SYSCALL_CLOCK_GETTIMERES 103 #define SYSCALL_CLOCK_SETTIMERES 104 #define SYSCALL_CLOCK_NANOSLEEP 105 -#define SYSCALL_MAX_NUM 106 /* index of highest constant + 1 */ +#define SYSCALL_TIMENS 106 +#define SYSCALL_MAX_NUM 107 /* index of highest constant + 1 */ #endif diff --git a/sortix/include/sortix/tmns.h b/sortix/include/sortix/tmns.h new file mode 100644 index 00000000..d8a73cfa --- /dev/null +++ b/sortix/include/sortix/tmns.h @@ -0,0 +1,43 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of Sortix. + + Sortix is free software: you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation, either version 3 of the License, or (at your option) any later + version. + + Sortix is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + details. + + You should have received a copy of the GNU General Public License along with + Sortix. If not, see . + + sortix/tmns.h + Declarations for the kernel time interfaces. + +*******************************************************************************/ + +#ifndef INCLUDE_SORTIX_TMNS_H +#define INCLUDE_SORTIX_TMNS_H + +#include +#include + +__BEGIN_DECLS + +struct tmns +{ + struct timespec tmns_utime; + struct timespec tmns_stime; + struct timespec tmns_cutime; + struct timespec tmns_cstime; +}; + +__END_DECLS + +#endif diff --git a/sortix/user-timer.cpp b/sortix/user-timer.cpp index 26396145..ed14df8a 100644 --- a/sortix/user-timer.cpp +++ b/sortix/user-timer.cpp @@ -31,12 +31,14 @@ #include #include #include +#include #include #include +#include #include -#include #include +#include #include #include @@ -277,11 +279,33 @@ static int sys_uptime(uintmax_t* usecssinceboot) return CopyToUser(usecssinceboot, &ret, sizeof(ret)) ? 0 : -1; } +static int sys_timens(struct tmns* user_tmns) +{ + Clock* execute_clock = Time::GetClock(CLOCK_PROCESS_CPUTIME_ID); + Clock* system_clock = Time::GetClock(CLOCK_PROCESS_SYSTIME_ID); + Clock* child_execute_clock = Time::GetClock(CLOCK_CHILD_CPUTIME_ID); + Clock* child_system_clock = Time::GetClock(CLOCK_CHILD_SYSTIME_ID); + + // Note: It is safe to access the clocks in this manner as each of them are + // locked by disabling interrupts. This is perhaps not SMP-ready, but + // it will do for now. + struct tmns tmns; + Interrupt::Disable(); + tmns.tmns_utime = execute_clock->current_time; + tmns.tmns_stime = system_clock->current_time; + tmns.tmns_cutime = child_execute_clock->current_time; + tmns.tmns_cstime = child_system_clock->current_time; + Interrupt::Enable(); + + return CopyToUser(user_tmns, &tmns, sizeof(tmns)) ? 0 : -1; +} + void UserTimer::Init() { Syscall::Register(SYSCALL_CLOCK_GETTIMERES, (void*) sys_clock_gettimeres); - Syscall::Register(SYSCALL_CLOCK_SETTIMERES, (void*) sys_clock_settimeres); Syscall::Register(SYSCALL_CLOCK_NANOSLEEP, (void*) sys_clock_nanosleep); + Syscall::Register(SYSCALL_CLOCK_SETTIMERES, (void*) sys_clock_settimeres); + Syscall::Register(SYSCALL_TIMENS, (void*) sys_timens); Syscall::Register(SYSCALL_TIMER_CREATE, (void*) sys_timer_create); Syscall::Register(SYSCALL_TIMER_DELETE, (void*) sys_timer_delete); Syscall::Register(SYSCALL_TIMER_GETOVERRUN, (void*) sys_timer_getoverrun);