Add timens(2).

This commit is contained in:
Jonas 'Sortie' Termansen 2013-05-15 12:37:39 +02:00
parent 04f797490d
commit 3938f80055
6 changed files with 110 additions and 3 deletions

View File

@ -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 \

View File

@ -55,6 +55,9 @@ struct tm
__END_DECLS
#include <sortix/timespec.h>
#include <sortix/itimerspec.h>
#if defined(_SORTIX_SOURCE)
#include <sortix/tmns.h>
#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;

34
libc/time/timens.cpp Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
time/timens.cpp
Get process execution time statistics.
*******************************************************************************/
#include <sys/syscall.h>
#include <time.h>
DEFN_SYSCALL1(int, sys_timens, SYSCALL_TIMENS, struct tmns*);
extern "C" int timens(struct tmns* tmns)
{
return sys_timens(tmns);
}

View File

@ -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

View File

@ -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 <http://www.gnu.org/licenses/>.
sortix/tmns.h
Declarations for the kernel time interfaces.
*******************************************************************************/
#ifndef INCLUDE_SORTIX_TMNS_H
#define INCLUDE_SORTIX_TMNS_H
#include <features.h>
#include <sortix/timespec.h>
__BEGIN_DECLS
struct tmns
{
struct timespec tmns_utime;
struct timespec tmns_stime;
struct timespec tmns_cutime;
struct timespec tmns_cstime;
};
__END_DECLS
#endif

View File

@ -31,12 +31,14 @@
#include <sortix/signal.h>
#include <sortix/sigevent.h>
#include <sortix/time.h>
#include <sortix/tmns.h>
#include <sortix/kernel/platform.h>
#include <sortix/kernel/copy.h>
#include <sortix/kernel/interrupt.h>
#include <sortix/kernel/kthread.h>
#include <sortix/kernel/time.h>
#include <sortix/kernel/syscall.h>
#include <sortix/kernel/time.h>
#include <sortix/kernel/user-timer.h>
#include <sortix/kernel/process.h>
@ -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);