xref: /minix3/minix/kernel/system/do_times.c (revision d91f738bd8d93aa6befa2a8d07581040607a512a)
1433d6423SLionel Sambuc /* The kernel call implemented in this file:
2433d6423SLionel Sambuc  *   m_type:	SYS_TIMES
3433d6423SLionel Sambuc  *
4433d6423SLionel Sambuc  * The parameters for this kernel call are:
5433d6423SLionel Sambuc  *   m_lsys_krn_sys_times.endpt		(get info for this process)
6433d6423SLionel Sambuc  *   m_krn_lsys_sys_times.user_time	(return values ...)
7433d6423SLionel Sambuc  *   m_krn_lsys_sys_times.system_time
8433d6423SLionel Sambuc  *   m_krn_lsys_sys_times.boot_time
9433d6423SLionel Sambuc  *   m_krn_lsys_sys_times.boot_ticks
10433d6423SLionel Sambuc  *   m_krn_lsys_sys_times.real_ticks
11433d6423SLionel Sambuc  */
12433d6423SLionel Sambuc 
13433d6423SLionel Sambuc #include "kernel/system.h"
14433d6423SLionel Sambuc 
15433d6423SLionel Sambuc #include <minix/endpoint.h>
16433d6423SLionel Sambuc 
17433d6423SLionel Sambuc #if USE_TIMES
18433d6423SLionel Sambuc 
19433d6423SLionel Sambuc /*===========================================================================*
20433d6423SLionel Sambuc  *				do_times				     *
21433d6423SLionel Sambuc  *===========================================================================*/
do_times(struct proc * caller,message * m_ptr)22433d6423SLionel Sambuc int do_times(struct proc * caller, message * m_ptr)
23433d6423SLionel Sambuc {
24433d6423SLionel Sambuc /* Handle sys_times().  Retrieve the accounting information. */
25433d6423SLionel Sambuc   register const struct proc *rp;
26433d6423SLionel Sambuc   int proc_nr;
27433d6423SLionel Sambuc   endpoint_t e_proc_nr;
28433d6423SLionel Sambuc 
29433d6423SLionel Sambuc   /* Insert the times needed by the SYS_TIMES kernel call in the message.
30433d6423SLionel Sambuc    * The clock's interrupt handler may run to update the user or system time
31433d6423SLionel Sambuc    * while in this code, but that cannot do any harm.
32433d6423SLionel Sambuc    */
33433d6423SLionel Sambuc   e_proc_nr = (m_ptr->m_lsys_krn_sys_times.endpt == SELF) ?
34433d6423SLionel Sambuc       caller->p_endpoint : m_ptr->m_lsys_krn_sys_times.endpt;
35433d6423SLionel Sambuc   if(e_proc_nr != NONE && isokendpt(e_proc_nr, &proc_nr)) {
36433d6423SLionel Sambuc       rp = proc_addr(proc_nr);
37433d6423SLionel Sambuc       m_ptr->m_krn_lsys_sys_times.user_time   = rp->p_user_time;
38433d6423SLionel Sambuc       m_ptr->m_krn_lsys_sys_times.system_time = rp->p_sys_time;
39433d6423SLionel Sambuc   }
40433d6423SLionel Sambuc   m_ptr->m_krn_lsys_sys_times.boot_ticks = get_monotonic();
41433d6423SLionel Sambuc   m_ptr->m_krn_lsys_sys_times.real_ticks = get_realtime();
42*d91f738bSDavid van Moolenbroek   m_ptr->m_krn_lsys_sys_times.boot_time = get_boottime();
43433d6423SLionel Sambuc   return(OK);
44433d6423SLionel Sambuc }
45433d6423SLionel Sambuc 
46433d6423SLionel Sambuc #endif /* USE_TIMES */
47