This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.
Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
| Other format: | [Raw text] | |
Hi,
I didn't hear anything back on this one, so I just wanted to hear if
there were any objections to this patch?
Thanks,
Jes
>>>>> "Jes" == Jes Sorensen <jes@wildopensource.com> writes:
>>>>> "Ulrich" == Ulrich Drepper <drepper@redhat.com> writes:
Ulrich> Jes Sorensen wrote:
>>> Not knowing enough about HPET, my biggest worry is if we have to
>>> open up an extra file descriptor for a permanent mmap of it.
Ulrich> One immediately closes the filedescriptor after the mmap call
Ulrich> if this mmaped region is all that is needed.
Jes> Ok, what about something like this, it makes
Jes> clock_getcpuclokcid() return ENOENT if the itc drifts. I left
Jes> __itc_drift_internal as a global variable as I am not sure
Jes> whether clock_gettime should be change to check it as well before
Jes> allowing a call for CLOCK_PROCESS_CPUTIME_ID.
Jes> I still want to look into supporting the HPET and SN2 RTC at a
Jes> later stage.
2003-12-01 Jes Sorensen <jes@wildopensource.com>
* rt/tst-clock.c (do_test): Print message when skipping
CLOCK_PROCESS_CPUTIME_ID test.
* sysdeps/unix/sysv/linux/ia64/clock_getcpuclockid.c: New file.
Provide CLOCK_PROCESS_CPUTIME_ID only if /proc/sal/itc_drift is 0.
--- libc-old/rt/tst-clock.c 6 Jul 2001 04:55:39 -0000 1.3
+++ libc-2.3/rt/tst-clock.c 1 Dec 2003 14:52:07 -0000
@@ -113,6 +113,8 @@
if (clock_getcpuclockid (0, &cl) == 0)
/* XXX It's not yet a bug when this fails. */
clock_test (cl);
+ else
+ printf("CPU clock unavailble, skipping test\n");
return result;
}
--- /dev/null Wed Dec 31 16:00:00 1969
+++ libc-2.3/sysdeps/unix/sysv/linux/ia64/clock_getcpuclockid.c Mon Dec 1 06:21:42 2003
@@ -0,0 +1,75 @@
+/* Copyright (C) 2000, 2001, 2003 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 <time.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <fcntl.h>
+
+int __itc_drift_internal;
+
+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;
+
+#ifdef CLOCK_PROCESS_CPUTIME_ID
+ {
+ int retval = ENOENT;
+
+ if (__builtin_expect (__itc_drift_internal == 0, 0))
+ {
+ int fd;
+
+ fd = open ("/proc/sal/itc_drift", O_RDONLY);
+ if (__builtin_expect (fd != -1, 1))
+ {
+ char buf[16];
+ ssize_t n;
+ n = read (fd, buf, sizeof buf);
+ if (__builtin_expect (n, 1) > 0)
+ {
+ if (buf[0] != '0')
+ __itc_drift_internal = 1;
+ else
+ __itc_drift_internal = -1;
+ }
+ close (fd);
+ }
+ else
+ __itc_drift_internal = -1;
+ }
+
+ if (__itc_drift_internal != 1)
+ {
+ /* Store the number. */
+ *clock_id = CLOCK_PROCESS_CPUTIME_ID;
+ retval = 0;
+ }
+
+ return retval;
+ }
+#else
+ /* We don't have a timer for that. */
+ return ENOENT;
+#endif
+}
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |