svn commit: samba r15508 - branches/SAMBA_3_0/source branches/SAMBA_3_0/source/include branches/SAMBA_3_0/source/lib branches/SAMBA_3_0/source/profile branches/SAMBA_3_0/source/tdb trunk/source trunk/source/include trunk/source/lib trunk/source/profile

jpeach at samba.org jpeach at samba.org
Mon May 8 03:20:52 GMT 2006


Author: jpeach
Date: 2006-05-08 03:20:49 +0000 (Mon, 08 May 2006)
New Revision: 15508

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=15508

Log:
Use clock_gettime for profiling timstamps if it is available. Use
the fastest clock available on uniprocessors.

Modified:
   branches/SAMBA_3_0/source/configure.in
   branches/SAMBA_3_0/source/include/smbprofile.h
   branches/SAMBA_3_0/source/lib/util.c
   branches/SAMBA_3_0/source/profile/profile.c
   branches/SAMBA_3_0/source/tdb/spinlock.c
   trunk/source/configure.in
   trunk/source/include/smbprofile.h
   trunk/source/lib/util.c
   trunk/source/profile/profile.c


Changeset:
Modified: branches/SAMBA_3_0/source/configure.in
===================================================================
--- branches/SAMBA_3_0/source/configure.in	2006-05-07 21:56:26 UTC (rev 15507)
+++ branches/SAMBA_3_0/source/configure.in	2006-05-08 03:20:49 UTC (rev 15508)
@@ -2019,6 +2019,8 @@
     AC_DEFINE(HAVE_GETTIMEOFDAY_TZ,1,[Whether gettimeofday() is available])
 fi
 
+AC_LIBTESTFUNC(rt, clock_gettime)
+
 AC_CACHE_CHECK([for va_copy],samba_cv_HAVE_VA_COPY,[
 AC_TRY_LINK([#include <stdarg.h>
 va_list ap1,ap2;], [va_copy(ap1,ap2);],

Modified: branches/SAMBA_3_0/source/include/smbprofile.h
===================================================================
--- branches/SAMBA_3_0/source/include/smbprofile.h	2006-05-07 21:56:26 UTC (rev 15507)
+++ branches/SAMBA_3_0/source/include/smbprofile.h	2006-05-08 03:20:49 UTC (rev 15508)
@@ -419,13 +419,34 @@
 #define DEC_PROFILE_COUNT(x) profile_p->x--
 #define ADD_PROFILE_COUNT(x,y) profile_p->x += (y)
 
+#if defined(HAVE_CLOCK_GETTIME)
+
+extern clockid_t __profile_clock;
+
 static inline unsigned long long profile_timestamp(void)
 {
+	struct timespec ts;
+
+	/* FIXME: On a single-CPU system, or a system where we have bound
+	 * daemon threads to single CPUs (eg. using cpusets or processor
+	 * affinity), it might be preferable to use CLOCK_PROCESS_CPUTIME_ID.
+	 */
+
+	clock_gettime(__profile_clock, &ts);
+	return (ts.tv_sec * 1000000) + (ts.tv_nsec / 1000); /* usec */
+}
+
+#else
+
+static inline unsigned long long profile_timestamp(void)
+{
 	struct timeval tv;
 	GetTimeOfDay(&tv);
 	return (tv.tv_sec * 1000000) + tv.tv_usec;
 }
 
+#endif
+
 /* end of helper macros */
 
 #define DO_PROFILE_INC(x) \

Modified: branches/SAMBA_3_0/source/lib/util.c
===================================================================
--- branches/SAMBA_3_0/source/lib/util.c	2006-05-07 21:56:26 UTC (rev 15507)
+++ branches/SAMBA_3_0/source/lib/util.c	2006-05-08 03:20:49 UTC (rev 15508)
@@ -2969,3 +2969,21 @@
 {
 	return True;
 }
+
+int this_is_smp(void)
+{
+#if defined(HAVE_SYSCONF)
+
+#if defined(SYSCONF_SC_NPROC_ONLN)
+        return (sysconf(_SC_NPROC_ONLN) > 1) ? 1 : 0;
+#elif defined(SYSCONF_SC_NPROCESSORS_ONLN)
+        return (sysconf(_SC_NPROCESSORS_ONLN) > 1) ? 1 : 0;
+#else
+	return 0;
+#endif
+
+#else
+	return 0;
+#endif
+}
+

Modified: branches/SAMBA_3_0/source/profile/profile.c
===================================================================
--- branches/SAMBA_3_0/source/profile/profile.c	2006-05-07 21:56:26 UTC (rev 15507)
+++ branches/SAMBA_3_0/source/profile/profile.c	2006-05-08 03:20:49 UTC (rev 15508)
@@ -28,7 +28,10 @@
 #ifdef WITH_PROFILE
 static int shm_id;
 static BOOL read_only;
+#if defined(HAVE_CLOCK_GETTIME)
+clockid_t __profile_clock;
 #endif
+#endif
 
 struct profile_header *profile_h;
 struct profile_stats *profile_p;
@@ -103,6 +106,24 @@
 
 	read_only = rdonly;
 
+#if defined(HAVE_CLOCK_GETTIME)
+	if (this_is_smp()) {
+		/* This is faster that gettimeofday, but not fast enough to
+		 * leave it enabled in production.
+		 */
+		__profile_clock = CLOCK_MONOTONIC;
+	} else {
+		/* CLOCK_PROCESS_CPUTIME_ID is sufficiently fast that the
+		 * always profiling times is plausible. Unfortunately it is
+		 * only accurate if we can guarantee we will not be scheduled
+		 * onto a different CPU between samples. Until there is some
+		 * way to set processor affinity, we can only use this on
+		 * uniprocessors.
+		 */
+		__profile_clock = CLOCK_PROCESS_CPUTIME_ID;
+	}
+#endif
+
  again:
 	/* try to use an existing key */
 	shm_id = shmget(PROF_SHMEM_KEY, 0, 0);

Modified: branches/SAMBA_3_0/source/tdb/spinlock.c
===================================================================
--- branches/SAMBA_3_0/source/tdb/spinlock.c	2006-05-07 21:56:26 UTC (rev 15507)
+++ branches/SAMBA_3_0/source/tdb/spinlock.c	2006-05-08 03:20:49 UTC (rev 15508)
@@ -266,23 +266,6 @@
 #endif
 }
 
-static int this_is_smp(void)
-{
-#if defined(HAVE_SYSCONF)
-
-#if defined(SYSCONF_SC_NPROC_ONLN)
-        return (sysconf(_SC_NPROC_ONLN) > 1) ? 1 : 0;
-#elif defined(SYSCONF_SC_NPROCESSORS_ONLN)
-        return (sysconf(_SC_NPROCESSORS_ONLN) > 1) ? 1 : 0;
-#else
-	return 0;
-#endif
-
-#else
-	return 0;
-#endif
-}
-
 /*
  * GENERIC
  */

Modified: trunk/source/configure.in
===================================================================
--- trunk/source/configure.in	2006-05-07 21:56:26 UTC (rev 15507)
+++ trunk/source/configure.in	2006-05-08 03:20:49 UTC (rev 15508)
@@ -2019,6 +2019,8 @@
     AC_DEFINE(HAVE_GETTIMEOFDAY_TZ,1,[Whether gettimeofday() is available])
 fi
 
+AC_LIBTESTFUNC(rt, clock_gettime)
+
 AC_CACHE_CHECK([for va_copy],samba_cv_HAVE_VA_COPY,[
 AC_TRY_LINK([#include <stdarg.h>
 va_list ap1,ap2;], [va_copy(ap1,ap2);],

Modified: trunk/source/include/smbprofile.h
===================================================================
--- trunk/source/include/smbprofile.h	2006-05-07 21:56:26 UTC (rev 15507)
+++ trunk/source/include/smbprofile.h	2006-05-08 03:20:49 UTC (rev 15508)
@@ -419,13 +419,34 @@
 #define DEC_PROFILE_COUNT(x) profile_p->x--
 #define ADD_PROFILE_COUNT(x,y) profile_p->x += (y)
 
+#if defined(HAVE_CLOCK_GETTIME)
+
+extern clockid_t __profile_clock;
+
 static inline unsigned long long profile_timestamp(void)
 {
+	struct timespec ts;
+
+	/* FIXME: On a single-CPU system, or a system where we have bound
+	 * daemon threads to single CPUs (eg. using cpusets or processor
+	 * affinity), it might be preferable to use CLOCK_PROCESS_CPUTIME_ID.
+	 */
+
+	clock_gettime(__profile_clock, &ts);
+	return (ts.tv_sec * 1000000) + (ts.tv_nsec / 1000); /* usec */
+}
+
+#else
+
+static inline unsigned long long profile_timestamp(void)
+{
 	struct timeval tv;
 	GetTimeOfDay(&tv);
 	return (tv.tv_sec * 1000000) + tv.tv_usec;
 }
 
+#endif
+
 /* end of helper macros */
 
 #define DO_PROFILE_INC(x) \

Modified: trunk/source/lib/util.c
===================================================================
--- trunk/source/lib/util.c	2006-05-07 21:56:26 UTC (rev 15507)
+++ trunk/source/lib/util.c	2006-05-08 03:20:49 UTC (rev 15508)
@@ -2969,3 +2969,21 @@
 {
 	return True;
 }
+
+int this_is_smp(void)
+{
+#if defined(HAVE_SYSCONF)
+
+#if defined(SYSCONF_SC_NPROC_ONLN)
+        return (sysconf(_SC_NPROC_ONLN) > 1) ? 1 : 0;
+#elif defined(SYSCONF_SC_NPROCESSORS_ONLN)
+        return (sysconf(_SC_NPROCESSORS_ONLN) > 1) ? 1 : 0;
+#else
+	return 0;
+#endif
+
+#else
+	return 0;
+#endif
+}
+

Modified: trunk/source/profile/profile.c
===================================================================
--- trunk/source/profile/profile.c	2006-05-07 21:56:26 UTC (rev 15507)
+++ trunk/source/profile/profile.c	2006-05-08 03:20:49 UTC (rev 15508)
@@ -28,7 +28,10 @@
 #ifdef WITH_PROFILE
 static int shm_id;
 static BOOL read_only;
+#if defined(HAVE_CLOCK_GETTIME)
+clockid_t __profile_clock;
 #endif
+#endif
 
 struct profile_header *profile_h;
 struct profile_stats *profile_p;
@@ -103,6 +106,24 @@
 
 	read_only = rdonly;
 
+#if defined(HAVE_CLOCK_GETTIME)
+	if (this_is_smp()) {
+		/* This is faster that gettimeofday, but not fast enough to
+		 * leave it enabled in production.
+		 */
+		__profile_clock = CLOCK_MONOTONIC;
+	} else {
+		/* CLOCK_PROCESS_CPUTIME_ID is sufficiently fast that the
+		 * always profiling times is plausible. Unfortunately it is
+		 * only accurate if we can guarantee we will not be scheduled
+		 * onto a different CPU between samples. Until there is some
+		 * way to set processor affinity, we can only use this on
+		 * uniprocessors.
+		 */
+		__profile_clock = CLOCK_PROCESS_CPUTIME_ID;
+	}
+#endif
+
  again:
 	/* try to use an existing key */
 	shm_id = shmget(PROF_SHMEM_KEY, 0, 0);



More information about the samba-cvs mailing list