1 /* Return the CPU time used by the program so far. Hurd version.
2 Copyright (C) 2001-2022 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
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.
9
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.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
18
19 #include <time.h>
20 #include <sys/time.h>
21 #include <mach.h>
22 #include <mach/task_info.h>
23 #include <hurd.h>
24
25 /* Return the time used by the program so far (user time + system time). */
26 clock_t
clock(void)27 clock (void)
28 {
29 struct task_basic_info bi;
30 struct task_thread_times_info tti;
31 mach_msg_type_number_t count;
32 clock_t total;
33 error_t err;
34
35 count = TASK_BASIC_INFO_COUNT;
36 err = __task_info (__mach_task_self (), TASK_BASIC_INFO,
37 (task_info_t) &bi, &count);
38 if (err)
39 return __hurd_fail (err);
40
41 count = TASK_THREAD_TIMES_INFO_COUNT;
42 err = __task_info (__mach_task_self (), TASK_THREAD_TIMES_INFO,
43 (task_info_t) &tti, &count);
44 if (err)
45 return __hurd_fail (err);
46
47 total = bi.user_time.seconds * 1000000 + bi.user_time.microseconds;
48 total += tti.user_time.seconds * 1000000 + tti.user_time.microseconds;
49 total += bi.system_time.seconds * 1000000 + bi.system_time.microseconds;
50 total += tti.system_time.seconds * 1000000 + tti.system_time.microseconds;
51
52 return total;
53 }
54