1 /* clock_getres -- Get the resolution of a POSIX clockid_t. Linux version.
2 Copyright (C) 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
22 #include "kernel-posix-cpu-timers.h"
24 #include "kernel-features.h"
27 #define SYSCALL_GETRES \
28 retval = INLINE_SYSCALL (clock_getres, 2, clock_id, res); \
31 #ifdef __ASSUME_POSIX_TIMERS
33 /* This means the REALTIME and MONOTONIC clock are definitely
34 supported in the kernel. */
35 # define SYSDEP_GETRES \
36 SYSDEP_GETRES_CPUTIME \
37 case CLOCK_REALTIME: \
38 case CLOCK_MONOTONIC: \
41 # define __libc_missing_posix_timers 0
42 #elif defined __NR_clock_getres
43 /* Is the syscall known to exist? */
44 extern int __libc_missing_posix_timers attribute_hidden
;
47 maybe_syscall_getres (clockid_t clock_id
, struct timespec
*res
)
51 if (!__libc_missing_posix_timers
)
53 INTERNAL_SYSCALL_DECL (err
);
54 int r
= INTERNAL_SYSCALL (clock_getres
, err
, 2, clock_id
, res
);
55 if (!INTERNAL_SYSCALL_ERROR_P (r
, err
))
58 e
= INTERNAL_SYSCALL_ERRNO (r
, err
);
61 __libc_missing_posix_timers
= 1;
69 /* The REALTIME and MONOTONIC clock might be available. Try the
71 # define SYSDEP_GETRES \
72 SYSDEP_GETRES_CPUTIME \
73 case CLOCK_REALTIME: \
74 case CLOCK_MONOTONIC: \
75 retval = maybe_syscall_getres (clock_id, res); \
78 /* Fallback code. */ \
79 if (retval == EINVAL && clock_id == CLOCK_REALTIME) \
80 retval = realtime_getres (res); \
83 __set_errno (retval); \
89 #ifdef __NR_clock_getres
90 /* We handled the REALTIME clock here. */
91 # define HANDLED_REALTIME 1
92 # define HANDLED_CPUTIME 1
94 # if __ASSUME_POSIX_CPU_TIMERS > 0
96 # define SYSDEP_GETRES_CPU SYSCALL_GETRES
97 # define SYSDEP_GETRES_CPUTIME /* Default catches them too. */
101 extern int __libc_missing_posix_cpu_timers attribute_hidden
;
104 maybe_syscall_getres_cpu (clockid_t clock_id
, struct timespec
*res
)
108 if (!__libc_missing_posix_cpu_timers
)
110 INTERNAL_SYSCALL_DECL (err
);
111 int r
= INTERNAL_SYSCALL (clock_getres
, err
, 2, clock_id
, res
);
112 if (!INTERNAL_SYSCALL_ERROR_P (r
, err
))
115 e
= INTERNAL_SYSCALL_ERRNO (r
, err
);
116 # ifndef __ASSUME_POSIX_TIMERS
119 __libc_missing_posix_timers
= 1;
120 __libc_missing_posix_cpu_timers
= 1;
128 /* Check whether the kernel supports CPU clocks at all.
129 If not, record it for the future. */
130 r
= INTERNAL_SYSCALL (clock_getres
, err
, 2,
131 MAKE_PROCESS_CPUCLOCK (0, CPUCLOCK_SCHED
),
133 if (INTERNAL_SYSCALL_ERROR_P (r
, err
))
134 __libc_missing_posix_cpu_timers
= 1;
142 # define SYSDEP_GETRES_CPU \
143 retval = maybe_syscall_getres_cpu (clock_id, res); \
146 if (retval != EINVAL || !__libc_missing_posix_cpu_timers) \
148 __set_errno (retval); \
152 retval = -1 /* Otherwise continue on to the HP_TIMING version. */;
155 maybe_syscall_getres_cputime (clockid_t clock_id
, struct timespec
*res
)
157 return maybe_syscall_getres_cpu
158 (clock_id
== CLOCK_THREAD_CPUTIME_ID
159 ? MAKE_THREAD_CPUCLOCK (0, CPUCLOCK_SCHED
)
160 : MAKE_PROCESS_CPUCLOCK (0, CPUCLOCK_SCHED
),
164 # define SYSDEP_GETRES_CPUTIME \
165 case CLOCK_PROCESS_CPUTIME_ID: \
166 case CLOCK_THREAD_CPUTIME_ID: \
167 retval = maybe_syscall_getres_cputime (clock_id, res); \
170 if (retval != EINVAL || !__libc_missing_posix_cpu_timers) \
172 __set_errno (retval); \
176 retval = hp_timing_getres (res); \
178 # if !HP_TIMING_AVAIL
179 # define hp_timing_getres(res) (__set_errno (EINVAL), -1)
185 #include <sysdeps/posix/clock_getres.c>