dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / kernel / syscall / times.c
blobcd268c0c0fb8ef66d542db82e3d400136154b62e
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
27 /* All Rights Reserved */
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>
43 * Return system and user times.
46 clock_t
47 times(struct tms *tp)
49 proc_t *p = ttoproc(curthread);
50 struct tms p_time;
51 clock_t ret_lbolt;
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);
62 if (copyout(&p_time, tp, sizeof (p_time)))
63 return (set_errno(EFAULT));
65 ret_lbolt = ddi_get_lbolt();
67 return (ret_lbolt == -1 ? 0 : ret_lbolt);
70 #ifdef _SYSCALL32_IMPL
73 * We deliberately -don't- return EOVERFLOW on type overflow,
74 * since the 32-bit kernel simply wraps 'em around.
76 clock32_t
77 times32(struct tms32 *tp)
79 proc_t *p = ttoproc(curthread);
80 struct tms32 p_time;
81 clock32_t ret_lbolt;
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);
92 if (copyout(&p_time, tp, sizeof (p_time)))
93 return (set_errno(EFAULT));
95 ret_lbolt = (clock32_t)ddi_get_lbolt();
97 return (ret_lbolt == (clock32_t)-1 ? 0 : ret_lbolt);
100 #endif /* _SYSCALL32_IMPL */