修订版 | 8ff62fe8dcefc3a0766ae2cac03033d9cf64e7fa (tree) |
---|---|
时间 | 2018-01-16 05:01:35 |
作者 | Waldemar Brodkorb <wbx@ucli...> |
Commiter | Waldemar Brodkorb |
rt: cleanup and allow to build for linuxthreads
It seems there is no real dependency to NPTL for these clock_*
functions when UCLIBC_ADVANCED_REALTIME is enabled.
No regressions found.
Reported-by: Baruch Siach <baruch@tkos.co.il>
@@ -96,8 +96,8 @@ CSRC-$(UCLIBC_HAS_REALTIME) += clock_adjtime.c clock_getres.c clock_gettime.c cl | ||
96 | 96 | nanosleep.c __rt_sigtimedwait.c __rt_sigwaitinfo.c sched_getparam.c \ |
97 | 97 | sched_get_priority_max.c sched_get_priority_min.c sched_getscheduler.c \ |
98 | 98 | sched_rr_get_interval.c sched_setparam.c sched_setscheduler.c sigqueue.c |
99 | -# use clock_gettime.c from librt only for NPTL | |
100 | -ifeq ($(UCLIBC_HAS_REALTIME)$(UCLIBC_HAS_THREADS_NATIVE),yy) | |
99 | +# use clock_gettime.c from librt | |
100 | +ifeq ($(UCLIBC_HAS_ADVANCED_REALTIME),y) | |
101 | 101 | CSRC- += clock_gettime.c |
102 | 102 | endif |
103 | 103 | # clock_getcpuclockid|clock_nanosleep|mq_timedreceive|mq_timedsend|posix_fadvise|posix_fallocate|posix_madvise|posix_memalign|posix_mem_offset|posix_spawnattr_destroy|posix_spawnattr_init|posix_spawnattr_getflags|posix_spawnattr_setflags|posix_spawnattr_getpgroup|posix_spawnattr_setpgroup|posix_spawnattr_getschedparam|posix_spawnattr_setschedparam|posix_spawnattr_getschedpolicy|posix_spawnattr_setschedpolicy|posix_spawnattr_getsigdefault|posix_spawnattr_setsigdefault|posix_spawnattr_getsigmask|posix_spawnattr_setsigmask|posix_spawnattr_init|posix_spawnattr_setflags|posix_spawnattr_setpgroup|posix_spawnattr_setschedparam|posix_spawnattr_setschedpolicy|posix_spawnattr_setsigdefault|posix_spawnattr_setsigmask|posix_spawn_file_actions_addclose|posix_spawn_file_actions_addopen|posix_spawn_file_actions_adddup2|posix_spawn_file_actions_addopen|posix_spawn_file_actions_destroy|posix_spawn_file_actions_init|posix_spawn_file_actions_init|posix_spawn|posix_spawnp|posix_spawnp|posix_typed_mem_get_info|pthread_mutex_timedlock|sem_timedwait |
@@ -17,8 +17,6 @@ librt_filter_SRC := | ||
17 | 17 | ifeq ($(UCLIBC_HAS_THREADS_NATIVE),y) |
18 | 18 | librt_filter_SRC += mq_notify.c timer_create.c timer_delete.c \ |
19 | 19 | timer_getoverr.c timer_gettime.c timer_settime.c |
20 | -else | |
21 | -librt_filter_SRC += clock_nanosleep.c clock_getcpuclockid.c clock_gettime.c | |
22 | 20 | endif |
23 | 21 | |
24 | 22 | librt_filter_SRC += $(if $(UCLIBC_HAS_ADVANCED_REALTIME),, \ |
@@ -16,176 +16,30 @@ | ||
16 | 16 | License along with the GNU C Library; if not, see |
17 | 17 | <http://www.gnu.org/licenses/>. */ |
18 | 18 | |
19 | -#include <sysdep.h> | |
20 | 19 | #include <errno.h> |
20 | +#include <sysdep.h> | |
21 | 21 | #include <time.h> |
22 | +#include <sys/time.h> | |
22 | 23 | #include "kernel-posix-cpu-timers.h" |
23 | -#include <bits/kernel-features.h> | |
24 | 24 | |
25 | 25 | |
26 | 26 | #define SYSCALL_GETTIME \ |
27 | 27 | retval = INLINE_SYSCALL (clock_gettime, 2, clock_id, tp); \ |
28 | 28 | break |
29 | 29 | |
30 | -#ifdef __ASSUME_POSIX_TIMERS | |
31 | - | |
32 | -/* This means the REALTIME and MONOTONIC clock are definitely | |
33 | - supported in the kernel. */ | |
34 | -# define SYSDEP_GETTIME \ | |
30 | +/* The REALTIME and MONOTONIC clock are definitely supported in the kernel. */ | |
31 | +#define SYSDEP_GETTIME \ | |
35 | 32 | SYSDEP_GETTIME_CPUTIME \ |
36 | 33 | case CLOCK_REALTIME: \ |
37 | 34 | case CLOCK_MONOTONIC: \ |
38 | 35 | SYSCALL_GETTIME |
39 | 36 | |
40 | -# define __libc_missing_posix_timers 0 | |
41 | -#elif defined __NR_clock_gettime | |
42 | -/* Is the syscall known to exist? */ | |
43 | -int __libc_missing_posix_timers attribute_hidden; | |
44 | - | |
45 | -static inline int | |
46 | -maybe_syscall_gettime (clockid_t clock_id, struct timespec *tp) | |
47 | -{ | |
48 | - int e = EINVAL; | |
49 | - | |
50 | - if (!__libc_missing_posix_timers) | |
51 | - { | |
52 | - INTERNAL_SYSCALL_DECL (err); | |
53 | - int r = INTERNAL_SYSCALL (clock_gettime, err, 2, clock_id, tp); | |
54 | - if (!INTERNAL_SYSCALL_ERROR_P (r, err)) | |
55 | - return 0; | |
56 | - | |
57 | - e = INTERNAL_SYSCALL_ERRNO (r, err); | |
58 | - if (e == ENOSYS) | |
59 | - { | |
60 | - __libc_missing_posix_timers = 1; | |
61 | - e = EINVAL; | |
62 | - } | |
63 | - } | |
64 | - | |
65 | - return e; | |
66 | -} | |
67 | - | |
68 | -/* The REALTIME and MONOTONIC clock might be available. Try the | |
69 | - syscall first. */ | |
70 | -# define SYSDEP_GETTIME \ | |
71 | - SYSDEP_GETTIME_CPUTIME \ | |
72 | - case CLOCK_REALTIME: \ | |
73 | - case CLOCK_MONOTONIC: \ | |
74 | - retval = maybe_syscall_gettime (clock_id, tp); \ | |
75 | - if (retval == 0) \ | |
76 | - break; \ | |
77 | - /* Fallback code. */ \ | |
78 | - if (retval == EINVAL && clock_id == CLOCK_REALTIME) \ | |
79 | - retval = realtime_gettime (tp); \ | |
80 | - else \ | |
81 | - { \ | |
82 | - __set_errno (retval); \ | |
83 | - retval = -1; \ | |
84 | - } \ | |
85 | - break; | |
86 | -#endif | |
87 | - | |
88 | -#ifdef __NR_clock_gettime | |
89 | 37 | /* We handled the REALTIME clock here. */ |
90 | -# define HANDLED_REALTIME 1 | |
91 | -# define HANDLED_CPUTIME 1 | |
92 | - | |
93 | -# if __ASSUME_POSIX_CPU_TIMERS > 0 | |
94 | - | |
95 | -# define SYSDEP_GETTIME_CPU SYSCALL_GETTIME | |
96 | -# define SYSDEP_GETTIME_CPUTIME /* Default catches them too. */ | |
97 | - | |
98 | -# else | |
38 | +#define HANDLED_REALTIME 1 | |
39 | +#define HANDLED_CPUTIME 1 | |
99 | 40 | |
100 | -int __libc_missing_posix_cpu_timers attribute_hidden; | |
101 | - | |
102 | -static int | |
103 | -maybe_syscall_gettime_cpu (clockid_t clock_id, struct timespec *tp) | |
104 | -{ | |
105 | - int e = EINVAL; | |
106 | - | |
107 | - if (!__libc_missing_posix_cpu_timers) | |
108 | - { | |
109 | - INTERNAL_SYSCALL_DECL (err); | |
110 | - int r = INTERNAL_SYSCALL (clock_gettime, err, 2, clock_id, tp); | |
111 | - if (!INTERNAL_SYSCALL_ERROR_P (r, err)) | |
112 | - return 0; | |
113 | - | |
114 | - e = INTERNAL_SYSCALL_ERRNO (r, err); | |
115 | -# ifndef __ASSUME_POSIX_TIMERS | |
116 | - if (e == ENOSYS) | |
117 | - { | |
118 | - __libc_missing_posix_timers = 1; | |
119 | - __libc_missing_posix_cpu_timers = 1; | |
120 | - e = EINVAL; | |
121 | - } | |
122 | - else | |
123 | -# endif | |
124 | - { | |
125 | - if (e == EINVAL) | |
126 | - { | |
127 | - /* Check whether the kernel supports CPU clocks at all. | |
128 | - If not, record it for the future. */ | |
129 | - r = INTERNAL_SYSCALL (clock_getres, err, 2, | |
130 | - MAKE_PROCESS_CPUCLOCK (0, CPUCLOCK_SCHED), | |
131 | - NULL); | |
132 | - if (INTERNAL_SYSCALL_ERROR_P (r, err)) | |
133 | - __libc_missing_posix_cpu_timers = 1; | |
134 | - } | |
135 | - } | |
136 | - } | |
137 | - | |
138 | - return e; | |
139 | -} | |
140 | - | |
141 | -# define SYSDEP_GETTIME_CPU \ | |
142 | - retval = maybe_syscall_gettime_cpu (clock_id, tp); \ | |
143 | - if (retval == 0) \ | |
144 | - break; \ | |
145 | - if (retval != EINVAL || !__libc_missing_posix_cpu_timers) \ | |
146 | - { \ | |
147 | - __set_errno (retval); \ | |
148 | - retval = -1; \ | |
149 | - break; \ | |
150 | - } \ | |
151 | - retval = -1 /* Otherwise continue on to the HP_TIMING version. */; | |
152 | - | |
153 | -static inline int | |
154 | -maybe_syscall_gettime_cputime (clockid_t clock_id, struct timespec *tp) | |
155 | -{ | |
156 | - return maybe_syscall_gettime_cpu | |
157 | - (clock_id == CLOCK_THREAD_CPUTIME_ID | |
158 | - ? MAKE_THREAD_CPUCLOCK (0, CPUCLOCK_SCHED) | |
159 | - : MAKE_PROCESS_CPUCLOCK (0, CPUCLOCK_SCHED), | |
160 | - tp); | |
161 | -} | |
162 | - | |
163 | -# define SYSDEP_GETTIME_CPUTIME \ | |
164 | - case CLOCK_PROCESS_CPUTIME_ID: \ | |
165 | - case CLOCK_THREAD_CPUTIME_ID: \ | |
166 | - retval = maybe_syscall_gettime_cputime (clock_id, tp); \ | |
167 | - if (retval == 0) \ | |
168 | - break; \ | |
169 | - if (retval != EINVAL || !__libc_missing_posix_cpu_timers) \ | |
170 | - { \ | |
171 | - __set_errno (retval); \ | |
172 | - retval = -1; \ | |
173 | - break; \ | |
174 | - } \ | |
175 | - retval = hp_timing_gettime (clock_id, tp); \ | |
176 | - break; | |
177 | -# if !HP_TIMING_AVAIL | |
178 | -# define hp_timing_gettime(clock_id, tp) (__set_errno (EINVAL), -1) | |
179 | -# endif | |
180 | - | |
181 | -# endif | |
182 | -#endif | |
183 | - | |
184 | -#include <errno.h> | |
185 | -#include <stdint.h> | |
186 | -#include <time.h> | |
187 | -#include <sys/time.h> | |
188 | -#include <ldsodefs.h> | |
41 | +#define SYSDEP_GETTIME_CPU SYSCALL_GETTIME | |
42 | +#define SYSDEP_GETTIME_CPUTIME /* Default catches them too. */ | |
189 | 43 | |
190 | 44 | static inline int |
191 | 45 | realtime_gettime (struct timespec *tp) |
@@ -198,7 +52,6 @@ realtime_gettime (struct timespec *tp) | ||
198 | 52 | return retval; |
199 | 53 | } |
200 | 54 | |
201 | -librt_hidden_proto (clock_gettime) | |
202 | 55 | /* Get current value of CLOCK and store it in TP. */ |
203 | 56 | int |
204 | 57 | clock_gettime (clockid_t clock_id, struct timespec *tp) |
@@ -232,4 +85,3 @@ clock_gettime (clockid_t clock_id, struct timespec *tp) | ||
232 | 85 | |
233 | 86 | return retval; |
234 | 87 | } |
235 | -librt_hidden_def (clock_gettime) |
@@ -1,5 +1,4 @@ | ||
1 | -/* Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc. | |
2 | - This file is part of the GNU C Library. | |
1 | +/* Copyright (C) 2003-2018 Free Software Foundation, Inc. | |
3 | 2 | |
4 | 3 | The GNU C Library is free software; you can redistribute it and/or |
5 | 4 | modify it under the terms of the GNU Lesser General Public |
@@ -17,18 +16,17 @@ | ||
17 | 16 | |
18 | 17 | #include <time.h> |
19 | 18 | #include <errno.h> |
19 | +#include <cancel.h> | |
20 | +#include <sys/syscall.h> | |
20 | 21 | |
21 | -#include <sysdep-cancel.h> | |
22 | -#include <bits/kernel-features.h> | |
23 | 22 | #include "kernel-posix-cpu-timers.h" |
24 | 23 | |
25 | 24 | |
26 | -#ifdef __ASSUME_POSIX_TIMERS | |
27 | 25 | /* We can simply use the syscall. The CPU clocks are not supported |
28 | 26 | with this function. */ |
29 | 27 | int |
30 | 28 | clock_nanosleep (clockid_t clock_id, int flags, const struct timespec *req, |
31 | - struct timespec *rem) | |
29 | + struct timespec *rem) | |
32 | 30 | { |
33 | 31 | INTERNAL_SYSCALL_DECL (err); |
34 | 32 | int r; |
@@ -53,43 +51,3 @@ clock_nanosleep (clockid_t clock_id, int flags, const struct timespec *req, | ||
53 | 51 | return (INTERNAL_SYSCALL_ERROR_P (r, err) |
54 | 52 | ? INTERNAL_SYSCALL_ERRNO (r, err) : 0); |
55 | 53 | } |
56 | - | |
57 | -#else | |
58 | -# ifdef __NR_clock_nanosleep | |
59 | -/* Is the syscall known to exist? */ | |
60 | -extern int __libc_missing_posix_timers attribute_hidden; | |
61 | - | |
62 | -/* The REALTIME and MONOTONIC clock might be available. Try the | |
63 | - syscall first. */ | |
64 | -# define SYSDEP_NANOSLEEP \ | |
65 | - if (!__libc_missing_posix_timers) \ | |
66 | - { \ | |
67 | - clockid_t syscall_clockid; \ | |
68 | - INTERNAL_SYSCALL_DECL (err); \ | |
69 | - \ | |
70 | - if (clock_id == CLOCK_THREAD_CPUTIME_ID) \ | |
71 | - return EINVAL; \ | |
72 | - if (clock_id == CLOCK_PROCESS_CPUTIME_ID) \ | |
73 | - syscall_clockid = MAKE_PROCESS_CPUCLOCK (0, CPUCLOCK_SCHED); \ | |
74 | - else \ | |
75 | - syscall_clockid = clock_id; \ | |
76 | - \ | |
77 | - int oldstate = LIBC_CANCEL_ASYNC (); \ | |
78 | - \ | |
79 | - int r = INTERNAL_SYSCALL (clock_nanosleep, err, 4, \ | |
80 | - syscall_clockid, flags, req, rem); \ | |
81 | - \ | |
82 | - LIBC_CANCEL_RESET (oldstate); \ | |
83 | - \ | |
84 | - if (!INTERNAL_SYSCALL_ERROR_P (r, err)) \ | |
85 | - return 0; \ | |
86 | - \ | |
87 | - if (INTERNAL_SYSCALL_ERRNO (r, err) != ENOSYS) \ | |
88 | - return INTERNAL_SYSCALL_ERRNO (r, err); \ | |
89 | - \ | |
90 | - __libc_missing_posix_timers = 1; \ | |
91 | - } | |
92 | -# endif | |
93 | - | |
94 | -# include <sysdeps/unix/clock_nanosleep.c> | |
95 | -#endif |