mirror of
git://sourceware.org/git/glibc.git
synced 2024-12-27 04:41:02 +08:00
sysdeps/clock_gettime: Use clock_gettime64 if avaliable
With the clock_gettime64 call we prefer to use vDSO. There is no call to clock_gettime64 on glibc with older headers and kernel 5.1+ if it doesn't support vDSO. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
This commit is contained in:
parent
f6fbce7dd7
commit
ec138c67cb
@ -211,11 +211,14 @@ extern double __difftime (time_t time1, time_t time0);
|
|||||||
|
|
||||||
#if __TIMESIZE == 64
|
#if __TIMESIZE == 64
|
||||||
# define __clock_nanosleep_time64 __clock_nanosleep
|
# define __clock_nanosleep_time64 __clock_nanosleep
|
||||||
|
# define __clock_gettime64 __clock_gettime
|
||||||
#else
|
#else
|
||||||
extern int __clock_nanosleep_time64 (clockid_t clock_id,
|
extern int __clock_nanosleep_time64 (clockid_t clock_id,
|
||||||
int flags, const struct __timespec64 *req,
|
int flags, const struct __timespec64 *req,
|
||||||
struct __timespec64 *rem);
|
struct __timespec64 *rem);
|
||||||
libc_hidden_proto (__clock_nanosleep_time64)
|
libc_hidden_proto (__clock_nanosleep_time64)
|
||||||
|
extern int __clock_gettime64 (clockid_t clock_id, struct __timespec64 *tp);
|
||||||
|
libc_hidden_proto (__clock_gettime64)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Use in the clock_* functions. Size of the field representing the
|
/* Use in the clock_* functions. Size of the field representing the
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
<https://www.gnu.org/licenses/>. */
|
<https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
#include <sysdep.h>
|
#include <sysdep.h>
|
||||||
|
#include <kernel-features.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include "kernel-posix-cpu-timers.h"
|
#include "kernel-posix-cpu-timers.h"
|
||||||
@ -30,10 +31,51 @@
|
|||||||
|
|
||||||
/* Get current value of CLOCK and store it in TP. */
|
/* Get current value of CLOCK and store it in TP. */
|
||||||
int
|
int
|
||||||
|
__clock_gettime64 (clockid_t clock_id, struct __timespec64 *tp)
|
||||||
|
{
|
||||||
|
#ifdef __ASSUME_TIME64_SYSCALLS
|
||||||
|
# ifndef __NR_clock_gettime64
|
||||||
|
# define __NR_clock_gettime64 __NR_clock_gettime
|
||||||
|
# define __vdso_clock_gettime64 __vdso_clock_gettime
|
||||||
|
# endif
|
||||||
|
return INLINE_VSYSCALL (clock_gettime64, 2, clock_id, tp);
|
||||||
|
#else
|
||||||
|
# if defined HAVE_CLOCK_GETTIME64_VSYSCALL
|
||||||
|
int ret64 = INLINE_VSYSCALL (clock_gettime64, 2, clock_id, tp);
|
||||||
|
if (ret64 == 0 || errno != ENOSYS)
|
||||||
|
return ret64;
|
||||||
|
# endif
|
||||||
|
struct timespec tp32;
|
||||||
|
int ret = INLINE_VSYSCALL (clock_gettime, 2, clock_id, &tp32);
|
||||||
|
if (ret == 0)
|
||||||
|
*tp = valid_timespec_to_timespec64 (tp32);
|
||||||
|
return ret;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#if __TIMESIZE != 64
|
||||||
|
int
|
||||||
__clock_gettime (clockid_t clock_id, struct timespec *tp)
|
__clock_gettime (clockid_t clock_id, struct timespec *tp)
|
||||||
{
|
{
|
||||||
return INLINE_VSYSCALL (clock_gettime, 2, clock_id, tp);
|
int ret;
|
||||||
|
struct __timespec64 tp64;
|
||||||
|
|
||||||
|
ret = __clock_gettime64 (clock_id, &tp64);
|
||||||
|
|
||||||
|
if (ret == 0)
|
||||||
|
{
|
||||||
|
if (! in_time_t_range (tp64.tv_sec))
|
||||||
|
{
|
||||||
|
__set_errno (EOVERFLOW);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
*tp = valid_timespec64_to_timespec (tp64);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
libc_hidden_def (__clock_gettime)
|
libc_hidden_def (__clock_gettime)
|
||||||
|
|
||||||
versioned_symbol (libc, __clock_gettime, clock_gettime, GLIBC_2_17);
|
versioned_symbol (libc, __clock_gettime, clock_gettime, GLIBC_2_17);
|
||||||
|
Loading…
Reference in New Issue
Block a user