diff options
author | Ulrich Drepper <drepper@redhat.com> | 2000-04-11 07:08:31 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2000-04-11 07:08:31 +0000 |
commit | 6689a1882be51506e254adbf088a61968604f498 (patch) | |
tree | 8e3a6ef34fdc3218b5d8d024314a4c6b6a124f80 /sysdeps/unix/i386/i586/clock_getres.c | |
parent | 25ee87d6f1b1ae018441f8af7b150f922d567ca3 (diff) | |
download | glibc-6689a1882be51506e254adbf088a61968604f498.tar.gz glibc-6689a1882be51506e254adbf088a61968604f498.tar.xz glibc-6689a1882be51506e254adbf088a61968604f498.zip |
Update.
2000-04-10 Ulrich Drepper <drepper@redhat.com> * Versions.def (librt): Add GLIBC_2.2. * rt/Makefile (librt-routines): Add get_clockfreq, clock_getcpuclockid, clock_getres, clock_gettime, clock_settime, timer_create, timer_delete, timer_getoverr, timer_gettime, and timer_settime. * rt/Versions [librt] (GLIBC_2.2): Add clock_getres, clock_gettime, clock_settime, timer_create, timer_delete, timer_getoverrun, timer_gettime, and timer_settime. * sysdeps/generic/clock_getcpuclockid.c: New file. * sysdeps/generic/get_clockfreq.c: New file. * sysdeps/unix/i386/clock_getcpuclockid.c: New file. * sysdeps/unix/sysv/linux/i386/get_clockfreq.c: New file. * sysdeps/mach/hurd/i386/bits/time.h: New file. * sysdeps/unix/i386/i586/clock_getres.c: New file. * sysdeps/unix/i386/i586/clock_gettime.c: New file. * sysdeps/unix/i386/i686/Implies: New file. * sysdpes/unix/sysv/linux/i386/bits/time.h: New file. * time/Makefile (routines): Move clock_getres, clock_gettime, clock_settime, timer_create, timer_delete, timer_getoverr, timer_gettime, and timer_settime to rt/Makefile. * time/Versions [libc] (GLIBC_2.2): Remove clock_getres, clock_gettime, clock_settime, timer_create, timer_delete, timer_getoverrun, timer_gettime, and timer_settime. * sysdeps/mach/hurd/bits/time.h: Drop K&R compatibility. Use __const__ and not const as attribute name.
Diffstat (limited to 'sysdeps/unix/i386/i586/clock_getres.c')
-rw-r--r-- | sysdeps/unix/i386/i586/clock_getres.c | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/sysdeps/unix/i386/i586/clock_getres.c b/sysdeps/unix/i386/i586/clock_getres.c new file mode 100644 index 0000000000..abafcc079b --- /dev/null +++ b/sysdeps/unix/i386/i586/clock_getres.c @@ -0,0 +1,71 @@ +/* Copyright (C) 1999, 2000 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 Library General Public License as + published by the Free Software Foundation; either version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include <sys/param.h> +#include <sys/time.h> + +/* This implementation uses the TSC register in modern (i586 and up) IA-32 + processors (most modern clones also provide it). Since we need the + resolution of the clock and since determining this is not cheap, we + cache the value. But this means that systems with processors running + at different speeds or process migration to machines with slower or + faster processors will not work without changes. */ + + +/* Function to determine processor frequency. */ +extern unsigned long long int __get_clockfreq (void); + +/* 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 long int nsec; + + +/* We add an limitation here: we assume that the machine is not up as + long as it takes to wrap-around the 64-bit timestamp counter. On a + 4GHz machine it would take 136 years of uptime to wrap around so + this "limitation" is not severe. */ +#define EXTRA_CLOCK_CASES \ + case __CLOCK_HIGHRES: \ + { \ + if (__builtin_expect (nsec != 0, 0)) \ + { \ + unsigned long long int freq; \ + \ + /* 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. */ \ + break; \ + \ + nsec = MAX (1000000000ULL / freq, 1); \ + } \ + \ + /* File in the values. The seconds are always zero (unless we \ + have a 1Hz machine). */ \ + res->tv_sec = 0; \ + res->tv_nsec = nsec; \ + \ + retval = 0; \ + } \ + break; + +#include <sysdeps/posix/clock_getres.c> |