xref: /illumos-gate/usr/src/uts/common/syscall/times.c (revision d3d50737)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*d3d50737SRafael Vanoni  * Common Development and Distribution License (the "License").
6*d3d50737SRafael Vanoni  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*d3d50737SRafael Vanoni  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
277c478bd9Sstevel@tonic-gate /*	  All Rights Reserved	*/
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #include <sys/param.h>
317c478bd9Sstevel@tonic-gate #include <sys/types.h>
327c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
337c478bd9Sstevel@tonic-gate #include <sys/systm.h>
347c478bd9Sstevel@tonic-gate #include <sys/tuneable.h>
357c478bd9Sstevel@tonic-gate #include <sys/errno.h>
367c478bd9Sstevel@tonic-gate #include <sys/proc.h>
377c478bd9Sstevel@tonic-gate #include <sys/time.h>
387c478bd9Sstevel@tonic-gate #include <sys/times.h>
397c478bd9Sstevel@tonic-gate #include <sys/debug.h>
407c478bd9Sstevel@tonic-gate #include <sys/msacct.h>
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate /*
437c478bd9Sstevel@tonic-gate  * Return system and user times.
447c478bd9Sstevel@tonic-gate  */
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate clock_t
times(struct tms * tp)477c478bd9Sstevel@tonic-gate times(struct tms *tp)
487c478bd9Sstevel@tonic-gate {
497c478bd9Sstevel@tonic-gate 	proc_t *p = ttoproc(curthread);
507c478bd9Sstevel@tonic-gate 	struct tms	p_time;
517c478bd9Sstevel@tonic-gate 	clock_t ret_lbolt;
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate 	mutex_enter(&p->p_lock);
547c478bd9Sstevel@tonic-gate 	p_time.tms_utime = (clock_t)NSEC_TO_TICK(
557c478bd9Sstevel@tonic-gate 	    mstate_aggr_state(p, LMS_USER));
567c478bd9Sstevel@tonic-gate 	p_time.tms_stime = (clock_t)NSEC_TO_TICK(
577c478bd9Sstevel@tonic-gate 	    mstate_aggr_state(p, LMS_SYSTEM));
587c478bd9Sstevel@tonic-gate 	p_time.tms_cutime = p->p_cutime;
597c478bd9Sstevel@tonic-gate 	p_time.tms_cstime = p->p_cstime;
607c478bd9Sstevel@tonic-gate 	mutex_exit(&p->p_lock);
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate 	if (copyout(&p_time, tp, sizeof (p_time)))
637c478bd9Sstevel@tonic-gate 		return (set_errno(EFAULT));
647c478bd9Sstevel@tonic-gate 
65*d3d50737SRafael Vanoni 	ret_lbolt = ddi_get_lbolt();
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate 	return (ret_lbolt == -1 ? 0 : ret_lbolt);
687c478bd9Sstevel@tonic-gate }
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32_IMPL
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate /*
737c478bd9Sstevel@tonic-gate  * We deliberately -don't- return EOVERFLOW on type overflow,
747c478bd9Sstevel@tonic-gate  * since the 32-bit kernel simply wraps 'em around.
757c478bd9Sstevel@tonic-gate  */
767c478bd9Sstevel@tonic-gate clock32_t
times32(struct tms32 * tp)777c478bd9Sstevel@tonic-gate times32(struct tms32 *tp)
787c478bd9Sstevel@tonic-gate {
797c478bd9Sstevel@tonic-gate 	proc_t	*p = ttoproc(curthread);
807c478bd9Sstevel@tonic-gate 	struct tms32	p_time;
817c478bd9Sstevel@tonic-gate 	clock32_t	ret_lbolt;
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate 	mutex_enter(&p->p_lock);
847c478bd9Sstevel@tonic-gate 	p_time.tms_utime = (clock32_t)NSEC_TO_TICK(
857c478bd9Sstevel@tonic-gate 	    mstate_aggr_state(p, LMS_USER));
867c478bd9Sstevel@tonic-gate 	p_time.tms_stime = (clock32_t)NSEC_TO_TICK(
877c478bd9Sstevel@tonic-gate 	    mstate_aggr_state(p, LMS_SYSTEM));
887c478bd9Sstevel@tonic-gate 	p_time.tms_cutime = (clock32_t)p->p_cutime;
897c478bd9Sstevel@tonic-gate 	p_time.tms_cstime = (clock32_t)p->p_cstime;
907c478bd9Sstevel@tonic-gate 	mutex_exit(&p->p_lock);
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate 	if (copyout(&p_time, tp, sizeof (p_time)))
937c478bd9Sstevel@tonic-gate 		return (set_errno(EFAULT));
947c478bd9Sstevel@tonic-gate 
95*d3d50737SRafael Vanoni 	ret_lbolt = (clock32_t)ddi_get_lbolt();
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate 	return (ret_lbolt == (clock32_t)-1 ? 0 : ret_lbolt);
987c478bd9Sstevel@tonic-gate }
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate #endif	/* _SYSCALL32_IMPL */
101