about summary refs log tree commit diff
path: root/sysdeps/unix/i386
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2000-04-11 07:08:31 +0000
committerUlrich Drepper <drepper@redhat.com>2000-04-11 07:08:31 +0000
commit6689a1882be51506e254adbf088a61968604f498 (patch)
tree8e3a6ef34fdc3218b5d8d024314a4c6b6a124f80 /sysdeps/unix/i386
parent25ee87d6f1b1ae018441f8af7b150f922d567ca3 (diff)
downloadglibc-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')
-rw-r--r--sysdeps/unix/i386/clock_getcpuclockid.c34
-rw-r--r--sysdeps/unix/i386/i586/clock_getres.c71
-rw-r--r--sysdeps/unix/i386/i586/clock_gettime.c71
-rw-r--r--sysdeps/unix/i386/i686/Implies1
4 files changed, 177 insertions, 0 deletions
diff --git a/sysdeps/unix/i386/clock_getcpuclockid.c b/sysdeps/unix/i386/clock_getcpuclockid.c
new file mode 100644
index 0000000000..1fd8ad9044
--- /dev/null
+++ b/sysdeps/unix/i386/clock_getcpuclockid.c
@@ -0,0 +1,34 @@
+/* Copyright (C) 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 <errno.h>
+#include <unistd.h>
+#include <sys/time.h>
+
+int
+clock_getcpuclockid (pid_t pid, clockid_t *clock_id)
+{
+  /* We don't allow any process ID but our own.  */
+  if (pid != 0 && pid != getpid ())
+    return EPERM;
+
+  /* Store the number.  */
+  *clock_id = __CLOCK_HIGHRES;
+
+  return 0;
+}
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>
diff --git a/sysdeps/unix/i386/i586/clock_gettime.c b/sysdeps/unix/i386/i586/clock_gettime.c
new file mode 100644
index 0000000000..f623cecd09
--- /dev/null
+++ b/sysdeps/unix/i386/i586/clock_gettime.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/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_glockfreq (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 unsigned long long int freq;
+
+
+/* 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:							      \
+    {									      \
+      unsigned long long int 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.  */				      \
+	    break;							      \
+	}								      \
+									      \
+      /* Get the current counter.  */					      \
+      asm volatile ("rdtsc" : "=A" (tsc));				      \
+									      \
+      /* 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) * 1000000000ULL) / freq;		      \
+    }									      \
+    break;
+
+#include <sysdeps/unix/clock_gettime.c>
diff --git a/sysdeps/unix/i386/i686/Implies b/sysdeps/unix/i386/i686/Implies
new file mode 100644
index 0000000000..6f31c95d44
--- /dev/null
+++ b/sysdeps/unix/i386/i686/Implies
@@ -0,0 +1 @@
+unix/i386/i586