From 9c3f85d14f1b73a3e6448cd26e05b39167e58a89 Mon Sep 17 00:00:00 2001 From: Philip Homburg Date: Thu, 16 Aug 2007 13:16:26 +0000 Subject: [PATCH] Better interface for sys_times. --- include/minix/syslib.h | 3 ++- lib/syslib/sys_times.c | 16 +++++++++------- servers/pm/forkexit.c | 8 ++++---- servers/pm/signal.c | 8 ++++---- servers/pm/time.c | 10 +++++----- 5 files changed, 24 insertions(+), 21 deletions(-) diff --git a/include/minix/syslib.h b/include/minix/syslib.h index 639fe78aa..77a1e4e8f 100755 --- a/include/minix/syslib.h +++ b/include/minix/syslib.h @@ -73,7 +73,8 @@ _PROTOTYPE( int sys_sdevio, (int req, long port, endpoint_t proc_nr, void *buffer, int count, vir_bytes offset)); /* Clock functionality: get system times or (un)schedule an alarm call. */ -_PROTOTYPE( int sys_times, (endpoint_t proc_nr, clock_t *ptr)); +_PROTOTYPE( int sys_times, (endpoint_t proc_nr, clock_t *user_time, + clock_t *sys_time, clock_t *uptime)); _PROTOTYPE(int sys_setalarm, (clock_t exp_time, int abs_time)); /* Shorthands for sys_irqctl() system call. */ diff --git a/lib/syslib/sys_times.c b/lib/syslib/sys_times.c index f6b84a7ff..cd36f58c1 100755 --- a/lib/syslib/sys_times.c +++ b/lib/syslib/sys_times.c @@ -1,8 +1,12 @@ #include "syslib.h" -PUBLIC int sys_times(proc, ptr) +PUBLIC int sys_times(proc, user_time, sys_time, uptime) int proc; /* proc whose times are needed */ -clock_t ptr[5]; /* pointer to time buffer */ +clock_t *user_time; /* time spend in the process itself */ +clock_t *sys_time; /* time spend in system on behalf of the + * process + */ +clock_t *uptime; /* time the system is running */ { /* Fetch the accounting info for a proc. */ message m; @@ -10,10 +14,8 @@ clock_t ptr[5]; /* pointer to time buffer */ m.T_ENDPT = proc; r = _taskcall(SYSTASK, SYS_TIMES, &m); - ptr[0] = m.T_USER_TIME; - ptr[1] = m.T_SYSTEM_TIME; - ptr[2] = 0; - ptr[3] = 0; - ptr[4] = m.T_BOOT_TICKS; + if (user_time) *user_time = m.T_USER_TIME; + if (sys_time) *sys_time = m.T_SYSTEM_TIME; + if (uptime) *uptime = m.T_BOOT_TICKS; return(r); } diff --git a/servers/pm/forkexit.c b/servers/pm/forkexit.c index 4128656c1..2a7c3567f 100644 --- a/servers/pm/forkexit.c +++ b/servers/pm/forkexit.c @@ -245,7 +245,7 @@ int for_trace; int parent_waiting, right_child, r; pid_t pidarg, procgrp; struct mproc *p_mp; - clock_t t[5]; + clock_t user_time, sys_time; proc_nr = (int) (rmp - mproc); /* get process slot number */ proc_nr_e = rmp->mp_endpoint; @@ -257,12 +257,12 @@ int for_trace; if (rmp->mp_flags & ALARM_ON) set_alarm(proc_nr_e, (unsigned) 0); /* Do accounting: fetch usage times and accumulate at parent. */ - if((r=sys_times(proc_nr_e, t)) != OK) + if((r=sys_times(proc_nr_e, &user_time, &sys_time, NULL)) != OK) panic(__FILE__,"pm_exit: sys_times failed", r); p_mp = &mproc[rmp->mp_parent]; /* process' parent */ - p_mp->mp_child_utime += t[0] + rmp->mp_child_utime; /* add user time */ - p_mp->mp_child_stime += t[1] + rmp->mp_child_stime; /* add system time */ + p_mp->mp_child_utime += user_time + rmp->mp_child_utime; /* add user time */ + p_mp->mp_child_stime += sys_time + rmp->mp_child_stime; /* add system time */ /* Tell the kernel the process is no longer runnable to prevent it from * being scheduled in between the following steps. Then tell FS that it diff --git a/servers/pm/signal.c b/servers/pm/signal.c index 4e3713838..def9e093d 100644 --- a/servers/pm/signal.c +++ b/servers/pm/signal.c @@ -691,7 +691,7 @@ register struct mproc *rmp; /* whose core is to be dumped */ pid_t procgrp; vir_bytes current_sp; struct mproc *p_mp; - clock_t t[5]; + clock_t user_time, sys_time; #if 0 printf("dumpcore for %d / %s\n", rmp->mp_pid, rmp->mp_name); @@ -731,12 +731,12 @@ register struct mproc *rmp; /* whose core is to be dumped */ if (rmp->mp_flags & ALARM_ON) set_alarm(proc_nr_e, (unsigned) 0); /* Do accounting: fetch usage times and accumulate at parent. */ - if((r=sys_times(proc_nr_e, t)) != OK) + if((r=sys_times(proc_nr_e, &user_time, &sys_time, NULL)) != OK) panic(__FILE__,"pm_exit: sys_times failed", r); p_mp = &mproc[rmp->mp_parent]; /* process' parent */ - p_mp->mp_child_utime += t[0] + rmp->mp_child_utime; /* add user time */ - p_mp->mp_child_stime += t[1] + rmp->mp_child_stime; /* add system time */ + p_mp->mp_child_utime += user_time + rmp->mp_child_utime; /* add user time */ + p_mp->mp_child_stime += sys_time + rmp->mp_child_stime; /* add system time */ /* Tell the kernel the process is no longer runnable to prevent it from * being scheduled in between the following steps. Then tell FS that it diff --git a/servers/pm/time.c b/servers/pm/time.c index c16370c90..fe59cd676 100644 --- a/servers/pm/time.c +++ b/servers/pm/time.c @@ -67,16 +67,16 @@ PUBLIC int do_times() { /* Perform the times(buffer) system call. */ register struct mproc *rmp = mp; - clock_t t[5]; + clock_t user_time, sys_time, uptime; int s; - if (OK != (s=sys_times(who_e, t))) + if (OK != (s=sys_times(who_e, &user_time, &sys_time, &uptime))) panic(__FILE__,"do_times couldn't get times", s); - rmp->mp_reply.reply_t1 = t[0]; /* user time */ - rmp->mp_reply.reply_t2 = t[1]; /* system time */ + rmp->mp_reply.reply_t1 = user_time; /* user time */ + rmp->mp_reply.reply_t2 = sys_time; /* system time */ rmp->mp_reply.reply_t3 = rmp->mp_child_utime; /* child user time */ rmp->mp_reply.reply_t4 = rmp->mp_child_stime; /* child system time */ - rmp->mp_reply.reply_t5 = t[4]; /* uptime since boot */ + rmp->mp_reply.reply_t5 = uptime; /* uptime since boot */ return(OK); } -- 2.44.0