2.9
[glibc/nacl-glibc.git] / sysdeps / mach / hurd / times.c
blobdeab40e5ef19b3c3b68233b40fdc9255502d3ca6
1 /* Return CPU and real time used by process and its children. Hurd version.
2 Copyright (C) 2001,2002,2003,2004 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #include <errno.h>
21 #include <stddef.h>
22 #include <sys/resource.h>
23 #include <sys/times.h>
24 #include <sys/time.h>
25 #include <time.h>
26 #include <mach.h>
27 #include <mach/task_info.h>
28 #include <hurd.h>
30 static inline clock_t
31 clock_from_time_value (const time_value_t *t)
33 return t->seconds * 1000000 + t->microseconds;
36 /* Store the CPU time used by this process and all its
37 dead children (and their dead children) in BUFFER.
38 Return the elapsed real time, or (clock_t) -1 for errors.
39 All times are in CLK_TCKths of a second. */
40 clock_t
41 __times (struct tms *tms)
43 struct task_basic_info bi;
44 struct task_thread_times_info tti;
45 mach_msg_type_number_t count;
46 union { time_value_t tvt; struct timeval tv; } now;
47 error_t err;
49 count = TASK_BASIC_INFO_COUNT;
50 err = __task_info (__mach_task_self (), TASK_BASIC_INFO,
51 (task_info_t) &bi, &count);
52 if (err)
53 return __hurd_fail (err);
55 count = TASK_THREAD_TIMES_INFO_COUNT;
56 err = __task_info (__mach_task_self (), TASK_THREAD_TIMES_INFO,
57 (task_info_t) &tti, &count);
58 if (err)
59 return __hurd_fail (err);
61 tms->tms_utime = (clock_from_time_value (&bi.user_time)
62 + clock_from_time_value (&tti.user_time));
63 tms->tms_stime = (clock_from_time_value (&bi.system_time)
64 + clock_from_time_value (&tti.system_time));
66 /* XXX This can't be implemented until getrusage(RUSAGE_CHILDREN) can be. */
67 tms->tms_cutime = tms->tms_cstime = 0;
69 if (__gettimeofday (&now.tv, NULL) < 0)
70 return -1;
72 return (clock_from_time_value (&now.tvt)
73 - clock_from_time_value (&bi.creation_time));
75 weak_alias (__times, times)