xref: /titanic_44/usr/src/uts/common/syscall/times.c (revision c5a5e6f47e8f40ef4f4a14b199b09585e3ecf9a0)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
27 /*	  All Rights Reserved	*/
28 
29 
30 #include <sys/param.h>
31 #include <sys/types.h>
32 #include <sys/sysmacros.h>
33 #include <sys/systm.h>
34 #include <sys/tuneable.h>
35 #include <sys/errno.h>
36 #include <sys/proc.h>
37 #include <sys/time.h>
38 #include <sys/times.h>
39 #include <sys/debug.h>
40 #include <sys/msacct.h>
41 
42 /*
43  * Return system and user times.
44  */
45 
46 clock_t
47 times(struct tms *tp)
48 {
49 	proc_t *p = ttoproc(curthread);
50 	struct tms	p_time;
51 	clock_t ret_lbolt;
52 
53 	mutex_enter(&p->p_lock);
54 	p_time.tms_utime = (clock_t)NSEC_TO_TICK(
55 	    mstate_aggr_state(p, LMS_USER));
56 	p_time.tms_stime = (clock_t)NSEC_TO_TICK(
57 	    mstate_aggr_state(p, LMS_SYSTEM));
58 	p_time.tms_cutime = p->p_cutime;
59 	p_time.tms_cstime = p->p_cstime;
60 	mutex_exit(&p->p_lock);
61 
62 	if (copyout(&p_time, tp, sizeof (p_time)))
63 		return (set_errno(EFAULT));
64 
65 	ret_lbolt = ddi_get_lbolt();
66 
67 	return (ret_lbolt == -1 ? 0 : ret_lbolt);
68 }
69 
70 #ifdef _SYSCALL32_IMPL
71 
72 /*
73  * We deliberately -don't- return EOVERFLOW on type overflow,
74  * since the 32-bit kernel simply wraps 'em around.
75  */
76 clock32_t
77 times32(struct tms32 *tp)
78 {
79 	proc_t	*p = ttoproc(curthread);
80 	struct tms32	p_time;
81 	clock32_t	ret_lbolt;
82 
83 	mutex_enter(&p->p_lock);
84 	p_time.tms_utime = (clock32_t)NSEC_TO_TICK(
85 	    mstate_aggr_state(p, LMS_USER));
86 	p_time.tms_stime = (clock32_t)NSEC_TO_TICK(
87 	    mstate_aggr_state(p, LMS_SYSTEM));
88 	p_time.tms_cutime = (clock32_t)p->p_cutime;
89 	p_time.tms_cstime = (clock32_t)p->p_cstime;
90 	mutex_exit(&p->p_lock);
91 
92 	if (copyout(&p_time, tp, sizeof (p_time)))
93 		return (set_errno(EFAULT));
94 
95 	ret_lbolt = (clock32_t)ddi_get_lbolt();
96 
97 	return (ret_lbolt == (clock32_t)-1 ? 0 : ret_lbolt);
98 }
99 
100 #endif	/* _SYSCALL32_IMPL */
101