Implement getrusage
Implement getrusage. These fields of struct rusage are not supported and always set to zero at this time long ru_nswap; /* swaps */ long ru_inblock; /* block input operations */ long ru_oublock; /* block output operations */ long ru_msgsnd; /* messages sent */ long ru_msgrcv; /* messages received */ long ru_nvcsw; /* voluntary context switches */ long ru_nivcsw; /* involuntary context switches */ test75.c is the unit test for this new function Change-Id: I3f1eb69de1fce90d087d76773b09021fc6106539
This commit is contained in:
committed by
Gerrit Code Review
parent
4241cc5d98
commit
64f10ee644
@@ -90,6 +90,7 @@ int do_fork(struct proc * caller, message * m_ptr)
|
||||
make_zero64(rpc->p_cycles);
|
||||
make_zero64(rpc->p_kcall_cycles);
|
||||
make_zero64(rpc->p_kipc_cycles);
|
||||
rpc->p_signal_received = 0;
|
||||
|
||||
/* If the parent is a privileged process, take away the privileges from the
|
||||
* child process and inhibit it from running by setting the NO_PRIV flag.
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#if USE_GETINFO
|
||||
|
||||
#include <minix/u64.h>
|
||||
#include <sys/resource.h>
|
||||
|
||||
/*===========================================================================*
|
||||
* update_idle_time *
|
||||
@@ -47,6 +48,7 @@ int do_getinfo(struct proc * caller, message * m_ptr)
|
||||
int nr_e, nr, r;
|
||||
int wipe_rnd_bin = -1;
|
||||
struct proc *p;
|
||||
struct rusage r_usage;
|
||||
|
||||
/* Set source address and length based on request type. */
|
||||
switch (m_ptr->I_REQUEST) {
|
||||
@@ -180,6 +182,32 @@ int do_getinfo(struct proc * caller, message * m_ptr)
|
||||
src_vir = (vir_bytes) &idl->p_cycles;
|
||||
break;
|
||||
}
|
||||
case GET_RUSAGE: {
|
||||
struct proc *target = NULL;
|
||||
int target_slot = 0;
|
||||
u64_t usec;
|
||||
nr_e = (m_ptr->I_VAL_LEN2_E == SELF) ?
|
||||
caller->p_endpoint : m_ptr->I_VAL_LEN2_E;
|
||||
|
||||
if (!isokendpt(nr_e, &target_slot))
|
||||
return EINVAL;
|
||||
|
||||
target = proc_addr(target_slot);
|
||||
if (isemptyp(target))
|
||||
return EINVAL;
|
||||
|
||||
length = sizeof(r_usage);
|
||||
memset(&r_usage, 0, sizeof(r_usage));
|
||||
usec = target->p_user_time * 1000000 / system_hz;
|
||||
r_usage.ru_utime.tv_sec = usec / 1000000;
|
||||
r_usage.ru_utime.tv_usec = usec % 100000;
|
||||
usec = target->p_sys_time * 1000000 / system_hz;
|
||||
r_usage.ru_stime.tv_sec = usec / 1000000;
|
||||
r_usage.ru_stime.tv_usec = usec % 100000;
|
||||
r_usage.ru_nsignals = target->p_signal_received;
|
||||
src_vir = (vir_bytes) &r_usage;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
printf("do_getinfo: invalid request %d\n", m_ptr->I_REQUEST);
|
||||
return(EINVAL);
|
||||
|
||||
Reference in New Issue
Block a user