[PATCH] Modified --spike and --breaktrace to allow capturing latencies lower than 2 us

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Currently it is not possible to record spikes lasting less than 2 us when
specifying the --spike option. This is behavior is the result of a combination
of the following factors:
1. Spikes are only recorded if spike > diff (i.e. NOT >=)
2. If one sets spike = 0, the option has no effect.
3. Setting negative values for the spike also does not have the desired affect
due to reasons related to type conversion.

This patch aims to correct this behavior by allowing one to record latencies
that are < 2us. The ability to record such latencies is important for some use
cases such as when one is interested in measuring the latency of a system that
is expected to be very low latency or for statistical purposes where having the
entire distribution of latencies is important (especially in the case of --spike).
Currently methods like analyzing print statements to console are not sufficient
as print messages to std out are only updated once every 10ms (which means one
will miss several individual latency records depending on the length of the
interval used). This same logical fix is also applied to the --breaktrace option
for consistency.

This patch also improves command documentation related to --spike and --breaktrace
by correcting inaccurate descriptions and documenting certain edge cases with
argument usage.

Signed-off-by: Aseef Imran <aimran@xxxxxxxxxx>
---
 src/cyclictest/cyclictest.c | 32 +++++++++++++++++---------------
 1 file changed, 17 insertions(+), 15 deletions(-)

diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c
index 890da5d..faa08c1 100644
--- a/src/cyclictest/cyclictest.c
+++ b/src/cyclictest/cyclictest.c
@@ -149,7 +149,7 @@ struct thread_stat {
 
 static pthread_mutex_t trigger_lock = PTHREAD_MUTEX_INITIALIZER;
 
-static int trigger = 0;	/* Record spikes > trigger, 0 means don't record */
+static int trigger = -2;	/* Record spikes > trigger, -2 or below means don't record */
 static int trigger_list_size = 1024;	/* Number of list nodes */
 
 /* Info to store when the diff is greater than the trigger */
@@ -171,7 +171,7 @@ static void trigger_print();
 static void trigger_update(struct thread_param *par, int diff, int64_t ts);
 
 static int shutdown;
-static int tracelimit = 0;
+static int tracelimit = -2;	/* Stop trace on latency > trigger, -2 or below means don't record */
 static int trace_marker = 0;
 static int verbose = 0;
 static int oscope_reduction = 1;
@@ -747,7 +747,7 @@ static void *timerthread(void *param)
 
 	while (!shutdown) {
 
-		uint64_t diff;
+		int64_t diff;
 		unsigned long diff_smi = 0;
 		int sigs, ret;
 
@@ -837,14 +837,14 @@ static void *timerthread(void *param)
 				pthread_cond_signal(&refresh_on_max_cond);
 		}
 		stat->avg += (double) diff;
-
-		if (trigger && (diff > trigger))
+		
+		if (trigger >= -1 && (diff > trigger))
 			trigger_update(par, diff, calctime(now));
-
+			
 		if (duration && (calcdiff(now, stop) >= 0))
 			shutdown++;
 
-		if (!stopped && tracelimit && (diff > tracelimit)) {
+		if (!stopped && tracelimit >= -1 && (diff > tracelimit)) {
 			stopped++;
 			shutdown++;
 			pthread_mutex_lock(&break_thread_id_lock);
@@ -939,7 +939,9 @@ static void display_help(int error)
 	       "                           the third thread on CPU 4,\n"
 	       "                           and the fourth thread on CPU 5.\n"
 	       "-A USEC  --aligned=USEC    align thread wakeups to a specific offset\n"
-	       "-b USEC  --breaktrace=USEC send break trace command when latency > USEC\n"
+	       "-b trgr  --breaktrace=trgr send break trace command when latency > trigger. Trigger\n"
+		   "						   threshold is in ns if the --nsec option is supplied and us\n"
+		   "			               otherwise.\n"
 	       "-c CLOCK --clock=CLOCK     select clock\n"
 	       "                           0 = CLOCK_MONOTONIC (default)\n"
 	       "                           1 = CLOCK_REALTIME\n"
@@ -991,10 +993,10 @@ static void display_help(int error)
 	       "-s       --system          use sys_nanosleep and sys_setitimer\n"
 	       "-S       --smp             Standard SMP testing: options -a -t and same priority\n"
 	       "                           of all threads\n"
-	       "	--spike=<trigger>  record all spikes > trigger\n"
+	       "	--spike=trgr  record all spikes > trgr. Set to -1 to record all measurements.\n"
 	       "	--spike-nodes=[num of nodes]\n"
-	       "			   These are the maximum number of spikes we can record.\n"
-	       "			   The default is 1024 if not specified\n"
+	       "			   These are the maximum number of spikes we can record. The default\n"
+	       "			   is 1024 if not specified. Must only be specified after --spike.\n"
 #ifdef ARCH_HAS_SMI_COUNTER
                "         --smi             Enable SMI counting\n"
 #endif
@@ -1304,7 +1306,7 @@ static void process_options(int argc, char *argv[], int max_cpus)
 			trigger = atoi(optarg);
 			break;
 		case OPT_TRIGGER_NODES:
-			if (trigger)
+			if (trigger >= -1)
 				trigger_list_size = atoi(optarg);
 			break;
 		case 'u':
@@ -1935,7 +1937,7 @@ int main(int argc, char **argv)
 				numa_bitmask_weight(affinity_mask));
 	}
 
-	if (trigger) {
+	if (trigger >= -1) {
 		int retval;
 		retval = trigger_init();
 		if (retval != 0) {
@@ -1974,7 +1976,7 @@ int main(int argc, char **argv)
 		}
 	}
 
-	if (tracelimit && trace_marker)
+	if (tracelimit >= -1 && trace_marker)
 		enable_trace_mark();
 
 	if (check_timer())
@@ -2300,7 +2302,7 @@ int main(int argc, char **argv)
 			threadfree(statistics[i]->values, VALBUF_SIZE*sizeof(long), parameters[i]->node);
 	}
 
-	if (trigger)
+	if (trigger >= -1)
 		trigger_print();
 
 	if (histogram)
-- 
2.49.0





[Index of Archives]     [RT Stable]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux