Skip to content
Navigation Menu
Toggle navigation
Sign in
In this repository
All GitHub Enterprise
↵
Jump to
↵
No suggested jump to results
In this repository
All GitHub Enterprise
↵
Jump to
↵
In this organization
All GitHub Enterprise
↵
Jump to
↵
In this repository
All GitHub Enterprise
↵
Jump to
↵
Sign in
Reseting focus
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
git-mirror
/
glibc
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
0
Security
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security
Insights
Files
363dd97
abilist
aout
argp
assert
bare
bits
catgets
conf
conform
crypt
csu
ctype
debug
dirent
dlfcn
elf
gmon
gnulib
grp
hesiod
hurd
iconv
iconvdata
include
inet
intl
io
libidn
libio
linuxthreads
linuxthreads_db
locale
localedata
login
mach
malloc
manual
math
misc
nis
nptl
nptl_db
nscd
nss
po
posix
pwd
resolv
resource
rt
scripts
setjmp
shadow
signal
socket
soft-fp
stdio-common
stdlib
streams
string
sunrpc
sysdeps
alpha
arm
generic
gnu
hppa
i386
ia64
ieee754
m68k
mach
mips
posix
powerpc
pthread
rs6000
s390
sh
sparc
unix
alpha
arm
bsd
common
i386
inet
mips
mman
powerpc
sh
sparc
sysv
x86_64
Dist
Implies
Makefile
Subdirs
_exit.S
alarm.c
clock_gettime.c
clock_nanosleep.c
clock_settime.c
closedir.c
configure
configure.in
confstr.h
dirfd.c
dirstream.h
errnos-tmpl.c
errnos.awk
execve.S
fork.S
fxstat.c
getdents.c
getegid.S
geteuid.S
getlogin.c
getlogin_r.c
getpagesize.c
getppid.S
grantpt.c
ioctls-tmpl.c
ioctls.awk
make-syscalls.sh
make_errlist.c
mk-local_lim.c
mkdir.c
mkfifo.c
nice.c
opendir.c
readdir.c
readdir_r.c
rewinddir.c
rmdir.c
s-proto-bp.S
s-proto-cancel.S
s-proto.S
seekdir.c
setxid.h
siglist.c
snarf-ioctls
sockatmark.c
start.c
stime.c
syscall.S
syscalls.list
sysdep.h
system.c
telldir.c
time.c
utime.c
xmknod.c
xstat.c
wordsize-32
wordsize-64
x86_64
linkmap.h
sysvipc
termios
time
timezone
wcsmbs
wctype
.cvsignore
BUGS
CANCEL-FCT-WAIVE
CANCEL-FILE-WAIVE
CONFORMANCE
COPYING
COPYING.LIB
ChangeLog
ChangeLog.1
ChangeLog.10
ChangeLog.11
ChangeLog.12
ChangeLog.13
ChangeLog.14
ChangeLog.15
ChangeLog.2
ChangeLog.3
ChangeLog.4
ChangeLog.5
ChangeLog.6
ChangeLog.7
ChangeLog.8
ChangeLog.9
FAQ
FAQ.in
INSTALL
INTERFACE
LICENSES
MakeTAGS
Makeconfig
Makefile
Makefile.in
Makerules
NAMESPACE
NEWS
NOTES
PROJECTS
README
README.libm
README.template
Rules
Versions.def
WUR-REPORT
abi-tags
aclocal.m4
config-name.in
config.h.in
config.make.in
configure
configure.in
cppflags-iterator.mk
extra-lib.mk
extra-modules.mk
o-iterator.mk
shlib-versions
test-skeleton.c
tls.make.c
version.h
Breadcrumbs
glibc
/
sysdeps
/
unix
/
clock_gettime.c
Blame
Blame
Latest commit
History
History
130 lines (105 loc) · 3.42 KB
Breadcrumbs
glibc
/
sysdeps
/
unix
/
clock_gettime.c
Top
File metadata and controls
Code
Blame
130 lines (105 loc) · 3.42 KB
Raw
/* clock_gettime -- Get the current time from a POSIX clockid_t. Unix version. Copyright (C) 1999-2004, 2005 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. The GNU C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with the GNU C Library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ #include <errno.h> #include <stdint.h> #include <time.h> #include <sys/time.h> #include <libc-internal.h> #include <ldsodefs.h> #if HP_TIMING_AVAIL /* Clock frequency of the processor. We make it a 64-bit variable because some jokers are already playing with processors with more than 4GHz. */ static hp_timing_t freq; /* This function is defined in the thread library. */ extern int __pthread_clock_gettime (clockid_t clock_id, hp_timing_t freq, struct timespec *tp) __attribute__ ((__weak__)); static int hp_timing_gettime (clockid_t clock_id, struct timespec *tp) { hp_timing_t tsc; if (__builtin_expect (freq == 0, 0)) { /* This can only happen if we haven't initialized the `freq' variable yet. Do this now. We don't have to protect this code against multiple execution since all of them should lead to the same result. */ freq = __get_clockfreq (); if (__builtin_expect (freq == 0, 0)) /* Something went wrong. */ return -1; } if (clock_id != CLOCK_PROCESS_CPUTIME_ID && __pthread_clock_gettime != NULL) return __pthread_clock_gettime (clock_id, freq, tp); /* Get the current counter. */ HP_TIMING_NOW (tsc); /* Compute the offset since the start time of the process. */ tsc -= GL(dl_cpuclock_offset); /* Compute the seconds. */ tp->tv_sec = tsc / freq; /* And the nanoseconds. This computation should be stable until we get machines with about 16GHz frequency. */ tp->tv_nsec = ((tsc % freq) * UINT64_C (1000000000)) / freq; return 0; } #endif static inline int realtime_gettime (struct timespec *tp) { struct timeval tv; int retval = gettimeofday (&tv, NULL); if (retval == 0) /* Convert into `timespec'. */ TIMEVAL_TO_TIMESPEC (&tv, tp); return retval; } /* Get current value of CLOCK and store it in TP. */ int clock_gettime (clockid_t clock_id, struct timespec *tp) { int retval = -1; switch (clock_id) { #ifdef SYSDEP_GETTIME SYSDEP_GETTIME; #endif #ifdef HANDLED_REALTIME case CLOCK_REALTIME: HANDLE_REALTIME; break; #endif default: #ifdef SYSDEP_GETTIME_CPU SYSDEP_GETTIME_CPU; #endif #if HP_TIMING_AVAIL if ((clock_id & ((1 << CLOCK_IDFIELD_SIZE) - 1)) == CLOCK_THREAD_CPUTIME_ID) retval = hp_timing_gettime (clock_id, tp); else #endif __set_errno (EINVAL); break; #if HP_TIMING_AVAIL && !defined HANDLED_CPUTIME case CLOCK_PROCESS_CPUTIME_ID: retval = hp_timing_gettime (clock_id, tp); break; #endif } return retval; }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
You can’t perform that action at this time.