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:
Xiaoguang Sun
2013-06-25 20:41:01 +08:00
committed by Gerrit Code Review
parent 4241cc5d98
commit 64f10ee644
41 changed files with 403 additions and 29 deletions

View File

@@ -1906,3 +1906,8 @@ void ser_dump_proc()
print_proc_recursive(pp);
}
}
void increase_proc_signals(struct proc *p)
{
p->p_signal_received++;
}

View File

@@ -126,6 +126,8 @@ struct proc {
*/
struct { reg_t r1, r2, r3; } p_defer;
u64_t p_signal_received;
#if DEBUG_TRACE
int p_schedules;
#endif

View File

@@ -76,6 +76,7 @@ int isokendpt_f(endpoint_t e, int *p, int f);
#endif
void proc_no_time(struct proc *p);
void reset_proc_accounting(struct proc *p);
void increase_proc_signals(struct proc *p);
void flag_account(struct proc *p, int flag);
int try_deliver_senda(struct proc *caller_ptr, asynmsg_t *table, size_t
size);

View File

@@ -373,6 +373,7 @@ int send_sig(endpoint_t ep, int sig_nr)
priv = priv(rp);
if(!priv) return ENOENT;
sigaddset(&priv->s_sig_pending, sig_nr);
increase_proc_signals(rp);
mini_notify(proc_addr(SYSTEM), rp->p_endpoint);
return OK;
@@ -434,6 +435,7 @@ int sig_nr; /* signal to be sent */
/* Check if the signal is already pending. Process it otherwise. */
if (! sigismember(&rp->p_pending, sig_nr)) {
sigaddset(&rp->p_pending, sig_nr);
increase_proc_signals(rp);
if (! (RTS_ISSET(rp, RTS_SIGNALED))) { /* other pending */
RTS_SET(rp, RTS_SIGNALED | RTS_SIG_PENDING);
if(OK != send_sig(sig_mgr, SIGKSIG))

View File

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

View File

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