This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch to have clock_gettime(CLOCK_CPUTIME_ID) return ENOENT if HPtiming is unreliable


The following patch insures that clock_gettime(CLOCK_CPUTIME_ID) does not
return a value if HP timing is unreliable (because the ITC/TSCs on a SMP
systems are not synchronized).

Would that be acceptable?

itc_usable may be better renamed to hp_reliable and some other niceties
added but is the basic patch okay?

Index: libc/sysdeps/unix/sysv/linux/ia64/clock_getcpuclockid.c
===================================================================
--- libc.orig/sysdeps/unix/sysv/linux/ia64/clock_getcpuclockid.c	2004-05-27 18:26:58.170594467 -0700
+++ libc/sysdeps/unix/sysv/linux/ia64/clock_getcpuclockid.c	2004-06-09 11:27:09.270731016 -0700
@@ -23,6 +23,7 @@
 #include <sys/types.h>
 #include <fcntl.h>

+extern int itc_usable;

 int
 clock_getcpuclockid (pid_t pid, clockid_t *clock_id)
@@ -31,7 +32,6 @@
   if (pid != 0 && pid != getpid ())
     return EPERM;

-  static int itc_usable;
   int retval = ENOENT;

   if (__builtin_expect (itc_usable == 0, 0))
Index: libc/sysdeps/unix/clock_gettime.c
===================================================================
--- libc.orig/sysdeps/unix/clock_gettime.c	2004-06-09 11:30:47.381079907 -0700
+++ libc/sysdeps/unix/clock_gettime.c	2004-06-09 11:37:09.235567416 -0700
@@ -29,7 +29,7 @@
    because some jokers are already playing with processors with more
    than 4GHz.  */
 static hp_timing_t freq;
-
+int itc_usable;

 /* This function is defined in the thread library.  */
 extern int __pthread_clock_gettime (clockid_t clock_id, hp_timing_t freq,
@@ -78,7 +78,9 @@
 #if HP_TIMING_AVAIL
       /* FALLTHROUGH.  */
     case CLOCK_PROCESS_CPUTIME_ID:
-      {
+      /* If itc usability has not been determined then do so now */
+      if (itc_usable==0) clock_getcpuclockid();
+      if (itc_usable>0) {
 	hp_timing_t tsc;

 	if (__builtin_expect (freq == 0, 0))
@@ -115,6 +117,9 @@

 	retval = 0;
       }
+    else
+	_set_errno(ENOENT);
+
     break;
 #endif
     }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]