Skip to contentSkip to conversation

cyclictest: Various fixes and a new option

PATCH Applied [email protected] 3 participants 17 messages May 26, 2015 – Jun 8, 2015

lore
Share & tools
lore
#12 lore raw

PATCH 3/3 cyclictest: Align measurement threads to the next full second

In reply to [email protected]

cyclictest starts the test threads at a random point in time. For fully reproducible tests it is required to schedule the threads with a specified offset from the timer tick. The influence of the tick can be measured by running the test with offset = 0 and offset = tickinterval/2.

To achieve this we rely on the fact, that the kernel starts the tick at CLOCK_MONOTONIC time 0. So it's guaranteed that the tick timer expires always every second (if the interval between the ticks defined by CONFIG_HZ is a whole-number divider of a second). Setting the global start time of the test threads to a full second (plus offset) and the interval to the interval between the ticks, the threads are scheduled with the specified offset to the tick.

Add a new option --secaligned which select this mode and modify the --aligned option code to support this. The --secaligned and --aligned options are mutually exclusive.

Signed-off-by Anna-Maria Gleixner <[email protected]>

---
 src/cyclictest/cyclictest.c |   39 ++++++++++++++++++++++++++++++++++-----
 1 file changed, 34 insertions(+), 5 deletions(-)
src/cyclictest/cyclictest.c +34 -5
Index: rt-tests/src/cyclictest/cyclictest.c
===================================================================
@@ -185,6 +185,7 @@ static int ct_debug;
 static int use_fifo = 0;
 static pthread_t fifo_threadid;
 static int aligned = 0;
+static int secaligned = 0;
 static int offset = 0;
 static int laptop = 0;
 
@@ -798,14 +799,27 @@ void *timerthread(void *param)
 		fatal("timerthread%d: failed to set priority to %d\n", par->cpu, par->prio);
 
 	/* Get current time */
-	if(aligned){
+	if (aligned || secaligned) {
 		pthread_barrier_wait(&globalt_barr);
-		if(par->tnum==0)
+		if (par->tnum == 0) {
 			clock_gettime(par->clock, &globalt);
+			if (secaligned) {
+				/* Ensure that the thread start timestamp is not
+				   in the past */
+				if (globalt.tv_nsec > 900000000)
+					globalt.tv_sec += 2;
+				else
+					globalt.tv_sec++;
+				globalt.tv_nsec = 0;
+			}
+		}
 		pthread_barrier_wait(&align_barr);
 		now = globalt;
 		if(offset) {
-			now.tv_nsec += offset * par->tnum;
+			if (aligned)
+				now.tv_nsec += offset * par->tnum;
+			else
+				now.tv_nsec += offset;
 			tsnorm(&now);
 		}
 	}
@@ -1056,6 +1070,8 @@ static void display_help(int error)
 	       "-R       --resolution      check clock resolution, calling clock_gettime() many\n"
 	       "                           times.  list of clock_gettime() values will be\n"
 	       "                           reported with -X\n"
+	       "         --secaligned [USEC] align thread wakeups to the next full second,\n"
+	       "                           and apply the optional offset\n"
 	       "-s       --system          use sys_nanosleep and sys_setitimer\n"
 	       "-S       --smp             Standard SMP testing: options -a -t -n and\n"
 	       "                           same priority of all threads\n"
@@ -1204,7 +1220,7 @@ enum option_values {
 	OPT_QUIET, OPT_PRIOSPREAD, OPT_RELATIVE, OPT_RESOLUTION, OPT_SYSTEM,
 	OPT_SMP, OPT_THREADS, OPT_TRACER, OPT_UNBUFFERED, OPT_NUMA, OPT_VERBOSE,
 	OPT_WAKEUP, OPT_WAKEUPRT, OPT_DBGCYCLIC, OPT_POLICY, OPT_HELP, OPT_NUMOPTS,
-	OPT_ALIGNED, OPT_LAPTOP,
+	OPT_ALIGNED, OPT_LAPTOP, OPT_SECALIGNED,
 };
 
 /* Process commandline options */
@@ -1251,6 +1267,7 @@ static void process_options (int argc, c
 			{"priospread",       no_argument,       NULL, OPT_PRIOSPREAD },
 			{"relative",         no_argument,       NULL, OPT_RELATIVE },
 			{"resolution",       no_argument,       NULL, OPT_RESOLUTION },
+			{"secaligned",       optional_argument, NULL, OPT_SECALIGNED },
 			{"system",           no_argument,       NULL, OPT_SYSTEM },
 			{"smp",              no_argument,       NULL, OPT_SMP },
 			{"threads",          optional_argument, NULL, OPT_THREADS },
@@ -1391,6 +1408,15 @@ static void process_options (int argc, c
 		case OPT_RESOLUTION:
 			check_clock_resolution = 1; break;
 		case 's':
+		case OPT_SECALIGNED:
+			secaligned = 1;
+			if (optarg != NULL)
+				offset = atoi(optarg) * 1000;
+			else if (optind < argc && atoi(argv[optind]))
+				offset = atoi(argv[optind]);
+			else
+				offset = 0;
+			break;
 		case OPT_SYSTEM:
 			use_system = MODE_SYS_OFFSET; break;
 		case 'S':
@@ -1528,7 +1554,10 @@ static void process_options (int argc, c
 	if (num_threads < 1)
 		error = 1;
 
-	if (aligned) {
+	if (aligned && secaligned)
+		error = 1;
+
+	if (aligned || secaligned) {
 		pthread_barrier_init(&globalt_barr, NULL, num_threads);
 		pthread_barrier_init(&align_barr, NULL, num_threads);
 	}
#1 lore raw

PATCH 1/3 cyclictest: Ensure that next wakeup time is never in the past

In reply to [email protected]

The calculated next wakeup time is already in the past, if the latency is longer than the interval. Thereby latency is detected that does not correspond to latency caused by the system but by cyclictest itself.

Force forward the next wakeup time past now.

---
 src/cyclictest/cyclictest.c |   12 ++++++++++++
 1 file changed, 12 insertions(+)
src/cyclictest/cyclictest.c +12 -0
Index: rt-tests/src/cyclictest/cyclictest.c
===================================================================
@@ -369,6 +369,12 @@ static inline void tsnorm(struct timespe
 	}
 }
 
+static inline int tsgreater(struct timespec *a, struct timespec *b)
+{
+	return ((a->tv_sec > b->tv_sec) ||
+		(a->tv_sec == b->tv_sec && a->tv_nsec > b->tv_nsec));
+}
+
 static inline int64_t calcdiff(struct timespec t1, struct timespec t2)
 {
 	int64_t diff;
@@ -949,6 +955,12 @@ void *timerthread(void *param)
 		}
 		tsnorm(&next);
 
+		while (tsgreater(&now, &next)) {
+			next.tv_sec += interval.tv_sec;
+			next.tv_nsec += interval.tv_nsec;
+			tsnorm(&next);
+		}
+
 		if (par->max_cycles && par->max_cycles == stat->cycles)
 			break;
 	}
#3 lore raw

PATCH 2/3 cyclictest: Convert the offset of the alignment option to microseconds

In reply to [email protected]

The offset is specified in microseconds according to the documentation, but, the microseconds to nanoseconds conversion is missing so the effective offset has the unit of nanoseconds.

---
 src/cyclictest/cyclictest.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/cyclictest/cyclictest.c +1 -1
Index: rt-tests/src/cyclictest/cyclictest.c
===================================================================
@@ -1289,7 +1289,7 @@ static void process_options (int argc, c
 		case OPT_ALIGNED:
 			aligned=1;
 			if (optarg != NULL)
-				offset = atoi(optarg);
+				offset = atoi(optarg) * 1000;
 			else if (optind<argc && atoi(argv[optind]))
 				offset = atoi(argv[optind]);
 			else
#0 lore raw

cover cyclictest: Various fixes and a new option

This patch series addresses two shortcomings of the cyclictest code:

- Calculation of the next wakeup time does not take latencies longer than the interval time into account, so the next scheduled event is already in the past.

- The offset value of the --aligned option should be counted in microseconds, but the code lacks a conversion to nanoseconds

Aside of this, add a new option which allows to align the measurement threads to the next full second with an optional offset.

Anna-Maria

#4 lore raw

Re: [patch 2/3] cyclictest: Convert the offset of the alignment option to microseconds

In reply to [email protected]
Quoted 14 lines · On Tue, 26 May 2015, [email protected] wrote:

The offset is specified in microseconds according to the documentation, but, the microseconds to nanoseconds conversion is missing so the effective offset has the unit of nanoseconds.

---
 src/cyclictest/cyclictest.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Index: rt-tests/src/cyclictest/cyclictest.c
===================================================================

src/cyclictest/cyclictest.c static void process_options (int argc, c · line 1293

Quoted 6 lines
src/cyclictest/cyclictest.c +1 -1
@@ -1289,7 +1289,7 @@ static void process_options (int argc, c
 		case OPT_ALIGNED:
 			aligned=1;
 			if (optarg != NULL)
-				offset = atoi(optarg);
+				offset = atoi(optarg) * 1000;
 			else if (optind<argc && atoi(argv[optind])

Don't we need the conversion here too then?

Quoted 6 lines
src/cyclictest/cyclictest.c +0 -0
 				offset = atoi(argv[optind]);
 

else

--

Thanks

John

#5 lore raw

Re: [patch 2/3] cyclictest: Convert the offset of the alignment option to microseconds

Quoted 3 lines · John Kacur

On Tue, 26 May 2015, [email protected] wrote:
Don't we need the conversion here too then?

Quoted 1 line

offset = atoi(argv[optind]);

Jap, this is right. I forgot it. I changed the patch.
I forgot the same in the third patch of this series. I'll fix it and send the patch back to you.

Anna-Maria

The offset is specified in microseconds according to the documentation, but, the microseconds to nanoseconds conversion is missing so the effective offset has the unit of nanoseconds.

---
 src/cyclictest/cyclictest.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
src/cyclictest/cyclictest.c +2 -2
Index: rt-tests/src/cyclictest/cyclictest.c
===================================================================
@@ -1289,9 +1289,9 @@ static void process_options (int argc, c
 		case OPT_ALIGNED:
 			aligned=1;
 			if (optarg != NULL)
-				offset = atoi(optarg);
+				offset = atoi(optarg) * 1000;
 			else if (optind<argc && atoi(argv[optind]))
-				offset = atoi(argv[optind]);
+				offset = atoi(argv[optind]) * 1000;
 			else
 				offset = 0;
 			break;
#13 lore raw

Re: [patch 3/3] cyclictest: Align measurement threads to the next full second

In reply to [email protected]

Review

Quoted 5 lines · On 2015-05-26 21:07, [email protected] wrote:
(quoted diff) +5 -0
+		case OPT_SECALIGNED:
+			secaligned = 1;
+			if (optarg != NULL)
+				offset = atoi(optarg) * 1000;
+			else if (optind < argc && atoi(argv[optind]))

The conversion to microseconds is missing as well.

Review

Quoted 2 lines
(quoted diff) +2 -0
+				offset = atoi(argv[optind]);
+			else

The patch is fixed.

Anna-Maria

cyclictest starts the test threads at a random point in time. For fully reproducible tests it is required to schedule the threads with a specified offset from the timer tick. The influence of the tick can be measured by running the test with offset = 0 and offset = tickinterval/2.

To achieve this we rely on the fact, that the kernel starts the tick at CLOCK_MONOTONIC time 0. So it's guaranteed that the tick timer expires always every second (if the interval between the ticks defined by CONFIG_HZ is a whole-number divider of a second). Setting the global start time of the test threads to a full second (plus offset) and the interval to the interval between the ticks, the threads are scheduled with the specified offset to the tick.

Add a new option --secaligned which select this mode and modify the --aligned option code to support this. The --secaligned and --aligned options are mutually exclusive.

Signed-off-by Anna-Maria Gleixner <[email protected]>

---
 src/cyclictest/cyclictest.c |   39 
++++++++++++++++++++++++++++++++++-----
 1 file changed, 34 insertions(+), 5 deletions(-)
src/cyclictest/cyclictest.c +1 -0
Index: rt-tests/src/cyclictest/cyclictest.c
===================================================================
@@ -185,6 +185,7 @@ static int ct_debug;
 static int use_fifo = 0;
 static pthread_t fifo_threadid;
 static int aligned = 0;
+static int secaligned = 0;
 static int offset = 0;
 static int laptop = 0;
 
@@ -798,14 +799,27 @@ void *timerthread(void *param)
 		fatal("timerthread%d: failed to set priority to %d\n", par->cpu, 

par->prio);

/* Get current time */
- if(aligned){
+ if (aligned || secaligned) {
pthread_barrier_wait(&globalt_barr);
- if(par->tnum==0)
+ if (par->tnum == 0) {
clock_gettime(par->clock, &globalt);
+ if (secaligned) {
+ /* Ensure that the thread start timestamp is not
+ in the past */
+ if (globalt.tv_nsec > 900000000)
+ globalt.tv_sec += 2;
+ else
+ globalt.tv_sec++;
+ globalt.tv_nsec = 0;
+ }
+ }
pthread_barrier_wait(&align_barr);
now = globalt;
if(offset) {
- now.tv_nsec += offset * par->tnum;
+ if (aligned)
+ now.tv_nsec += offset * par->tnum;
+ else
+ now.tv_nsec += offset;
tsnorm(&now);
}
}
@@ -1056,6 +1070,8 @@ static void display_help(int error)
"-R --resolution check clock resolution, calling
clock_gettime() many\n"
" times. list of clock_gettime()
values will be\n"
" reported with -X\n"
+ " --secaligned [USEC] align thread wakeups to the next full second,\n"
+ " and apply the optional offset\n"
"-s --system use sys_nanosleep and
sys_setitimer\n"
"-S --smp Standard SMP testing: options -a
-t -n and\n"
" same priority of all threads\n"
@@ -1204,7 +1220,7 @@ enum option_values {
OPT_QUIET, OPT_PRIOSPREAD, OPT_RELATIVE, OPT_RESOLUTION, OPT_SYSTEM, OPT_SMP, OPT_THREADS, OPT_TRACER, OPT_UNBUFFERED, OPT_NUMA,
OPT_VERBOSE,
OPT_WAKEUP, OPT_WAKEUPRT, OPT_DBGCYCLIC, OPT_POLICY, OPT_HELP,
OPT_NUMOPTS,
- OPT_ALIGNED, OPT_LAPTOP,
+ OPT_ALIGNED, OPT_LAPTOP, OPT_SECALIGNED,
};

/* Process commandline options */
@@ -1251,6 +1267,7 @@ static void process_options (int argc, c

 			{"priospread",       no_argument,       NULL, OPT_PRIOSPREAD },
 			{"relative",         no_argument,       NULL, OPT_RELATIVE },
 			{"resolution",       no_argument,       NULL, OPT_RESOLUTION },
+			{"secaligned",       optional_argument, NULL, OPT_SECALIGNED },
 			{"system",           no_argument,       NULL, OPT_SYSTEM },
 			{"smp",              no_argument,       NULL, OPT_SMP },
 			{"threads",          optional_argument, NULL, OPT_THREADS },

@@ -1391,6 +1408,15 @@ static void process_options (int argc, c
case OPT_RESOLUTION:
check_clock_resolution = 1; break;
case 's':
+ case OPT_SECALIGNED:
+ secaligned = 1;
+ if (optarg != NULL)
+ offset = atoi(optarg) * 1000;
+ else if (optind < argc && atoi(argv[optind]))
+ offset = atoi(argv[optind]) * 1000;
+ else
+ offset = 0;
+ break;
case OPT_SYSTEM:
use_system = MODE_SYS_OFFSET; break;
case 'S':
@@ -1528,7 +1554,10 @@ static void process_options (int argc, c
if (num_threads < 1)
error = 1;

- if (aligned) {
+ if (aligned && secaligned)
+ error = 1;
+
+ if (aligned || secaligned) {
pthread_barrier_init(&globalt_barr, NULL, num_threads); pthread_barrier_init(&align_barr, NULL, num_threads);
}

#6 lore raw

Re: [patch 2/3] cyclictest: Convert the offset of the alignment option to microseconds

In reply to Anna-Maria Gleixner

src/cyclictest/cyclictest.c static void process_options (int argc, c

Quoted 26 lines · Anna-Maria Gleixner
Quoted 3 lines · John Kacur

On Tue, 26 May 2015, [email protected] wrote:
Don't we need the conversion here too then?

Quoted 1 line

offset = atoi(argv[optind]);

Jap, this is right. I forgot it. I changed the patch.
I forgot the same in the third patch of this series. I'll fix it and send the patch back to you.

Anna-Maria

The offset is specified in microseconds according to the documentation, but, the microseconds to nanoseconds conversion is missing so the effective offset has the unit of nanoseconds.

---
 src/cyclictest/cyclictest.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Index: rt-tests/src/cyclictest/cyclictest.c
===================================================================

src/cyclictest/cyclictest.c +0 -0
@@ -1289,9 +1289,9 @@ static void process_options (int argc, c

I fixed your patch manually, but you are doing something wrong generating it, see how the function header get's cut off above there?

Quoted 16 lines
src/cyclictest/cyclictest.c +2 -3
 		case OPT_ALIGNED:
 			aligned=1;
 			if (optarg != NULL)
-				offset = atoi(optarg);
+				offset = atoi(optarg) * 1000;
 			else if (optind<argc && atoi(argv[optind]))
-				offset = atoi(argv[optind]);
+				offset = atoi(argv[optind]) * 1000;
 			else
 				offset = 0;
 			break;
--

To unsubscribe from this list: send the line "unsubscribe linux-rt-users" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#14 lore raw

Re: [patch 3/3] cyclictest: Align measurement threads to the next full second

In reply to Anna-Maria Gleixner
Quoted 145 lines · Anna-Maria Gleixner

Review

Quoted 5 lines · On 2015-05-26 21:07, [email protected] wrote:
(quoted diff) +5 -0
+		case OPT_SECALIGNED:
+			secaligned = 1;
+			if (optarg != NULL)
+				offset = atoi(optarg) * 1000;
+			else if (optind < argc && atoi(argv[optind]))

The conversion to microseconds is missing as well.

Review

Quoted 2 lines
(quoted diff) +2 -0
+				offset = atoi(argv[optind]);
+			else

The patch is fixed.

Anna-Maria

cyclictest starts the test threads at a random point in time. For fully reproducible tests it is required to schedule the threads with a specified offset from the timer tick. The influence of the tick can be measured by running the test with offset = 0 and offset = tickinterval/2.

To achieve this we rely on the fact, that the kernel starts the tick at CLOCK_MONOTONIC time 0. So it's guaranteed that the tick timer expires always every second (if the interval between the ticks defined by CONFIG_HZ is a whole-number divider of a second). Setting the global start time of the test threads to a full second (plus offset) and the interval to the interval between the ticks, the threads are scheduled with the specified offset to the tick.

Add a new option --secaligned which select this mode and modify the --aligned option code to support this. The --secaligned and --aligned options are mutually exclusive.

Signed-off-by Anna-Maria Gleixner <[email protected]>

---
 src/cyclictest/cyclictest.c |   39 ++++++++++++++++++++++++++++++++++-----
 1 file changed, 34 insertions(+), 5 deletions(-)

Index: rt-tests/src/cyclictest/cyclictest.c
===================================================================

src/cyclictest/cyclictest.c +5 -2
@@ -185,6 +185,7 @@ static int ct_debug;
 static int use_fifo = 0;
 static pthread_t fifo_threadid;
 static int aligned = 0;
+static int secaligned = 0;
 static int offset = 0;
 static int laptop = 0;
 
@@ -798,14 +799,27 @@ void *timerthread(void *param)
 		fatal("timerthread%d: failed to set priority to %d\n",
 par->cpu, par->prio);
 
 	/* Get current time */
-	if(aligned){
+	if (aligned || secaligned) {
 		pthread_barrier_wait(&globalt_barr);
-		if(par->tnum==0)
+		if (par->tnum == 0) {
 			clock_gettime(par->clock, &globalt);
+			if (secaligned) {
+				/* Ensure that the thread start timestamp is

not

src/cyclictest/cyclictest.c +12 -1
+				   in the past */
+				if (globalt.tv_nsec > 900000000)
+					globalt.tv_sec += 2;
+				else
+					globalt.tv_sec++;
+				globalt.tv_nsec = 0;
+			}
+		}
 		pthread_barrier_wait(&align_barr);
 		now = globalt;
 		if(offset) {
-			now.tv_nsec += offset * par->tnum;
+			if (aligned)
+				now.tv_nsec += offset * par->tnum;
+			else
+				now.tv_nsec += offset;
 			tsnorm(&now);
 		}
 	}
@@ -1056,6 +1070,8 @@ static void display_help(int error)
 	       "-R       --resolution      check clock resolution, calling

clock_gettime() many\n"
" times. list of clock_gettime()
values will be\n"

src/cyclictest/cyclictest.c +1 -0
 	       "                           reported with -X\n"
+	       "         --secaligned [USEC] align thread wakeups to the next

full second,\n"

src/cyclictest/cyclictest.c +1 -0
+	       "                           and apply the optional offset\n"
 	       "-s       --system          use sys_nanosleep and

sys_setitimer\n"

src/cyclictest/cyclictest.c +1 -2
 	       "-S       --smp             Standard SMP testing: options -a -t
-n and\n"
 	       "                           same priority of all threads\n"
@@ -1204,7 +1220,7 @@ enum option_values {
 	OPT_QUIET, OPT_PRIOSPREAD, OPT_RELATIVE, OPT_RESOLUTION, OPT_SYSTEM,
 	OPT_SMP, OPT_THREADS, OPT_TRACER, OPT_UNBUFFERED, OPT_NUMA,
 OPT_VERBOSE,
 	OPT_WAKEUP, OPT_WAKEUPRT, OPT_DBGCYCLIC, OPT_POLICY, OPT_HELP,
 OPT_NUMOPTS,
-	OPT_ALIGNED, OPT_LAPTOP,
+	OPT_ALIGNED, OPT_LAPTOP, OPT_SECALIGNED,
 };

/* Process commandline options */

src/cyclictest/cyclictest.c +1 -0
@@ -1251,6 +1267,7 @@ static void process_options (int argc, c
 			{"priospread",       no_argument,       NULL,
 OPT_PRIOSPREAD },
 			{"relative",         no_argument,       NULL,
 OPT_RELATIVE },
 			{"resolution",       no_argument,       NULL,
 OPT_RESOLUTION },
+			{"secaligned",       optional_argument, NULL,

OPT_SECALIGNED },
{"system", no_argument, NULL,
OPT_SYSTEM },
{"smp", no_argument, NULL, OPT_SMP
},
{"threads", optional_argument, NULL,
OPT_THREADS },

src/cyclictest/cyclictest.c +9 -0
@@ -1391,6 +1408,15 @@ static void process_options (int argc, c
 		case OPT_RESOLUTION:
 			check_clock_resolution = 1; break;
 		case 's':
+		case OPT_SECALIGNED:
+			secaligned = 1;
+			if (optarg != NULL)
+				offset = atoi(optarg) * 1000;
+			else if (optind < argc && atoi(argv[optind]))
+				offset = atoi(argv[optind]) * 1000;
+			else
+				offset = 0;
+			break;
 		case OPT_SYSTEM:
 			use_system = MODE_SYS_OFFSET; break;
 		case 'S':
@@ -1528,7 +1554,10 @@ static void process_options (int argc, c
 	if (num_threads < 1)
 		error = 1;

src/cyclictest/cyclictest.c static void process_options (int argc, c

Quoted 10 lines
src/cyclictest/cyclictest.c +4 -2
 
-	if (aligned) {
+	if (aligned && secaligned)
+		error = 1;
+
+	if (aligned || secaligned) {
 		pthread_barrier_init(&globalt_barr, NULL, num_threads);
 		pthread_barrier_init(&align_barr, NULL, num_threads);
 	}
--

Sorry, this one isn't applying either, perhaps your emailer is doing automatic word wrap? Can you fix this up, and resend please?

Thank you

John Kacur

#2 lore raw

Re: [patch 1/3] cyclictest: Ensure that next wakeup time is never in the past

In reply to [email protected]
Quoted 34 lines · On Tue, 26 May 2015, [email protected] wrote:

The calculated next wakeup time is already in the past, if the latency is longer than the interval. Thereby latency is detected that does not correspond to latency caused by the system but by cyclictest itself.

Force forward the next wakeup time past now.

---
 src/cyclictest/cyclictest.c |   12 ++++++++++++
 1 file changed, 12 insertions(+)

Index: rt-tests/src/cyclictest/cyclictest.c
===================================================================

src/cyclictest/cyclictest.c +8 -0
@@ -369,6 +369,12 @@ static inline void tsnorm(struct timespe
 	}
 }
 
+static inline int tsgreater(struct timespec *a, struct timespec *b)
+{
+	return ((a->tv_sec > b->tv_sec) ||
+		(a->tv_sec == b->tv_sec && a->tv_nsec > b->tv_nsec));
+}
+
 static inline int64_t calcdiff(struct timespec t1, struct timespec t2)
 {
 	int64_t diff;
@@ -949,6 +955,12 @@ void *timerthread(void *param)
 		}
 		tsnorm(&next);
 
+		while (tsgreater(&now, &next)) {
+			next.tv_sec += interval.tv_sec;

src/cyclictest/cyclictest.c void *timerthread(void *param)

Quoted 10 lines
src/cyclictest/cyclictest.c +4 -1
+			next.tv_nsec += interval.tv_nsec;
+			tsnorm(&next);
+		}
+
 		if (par->max_cycles && par->max_cycles == stat->cycles)
 			break;
 	}
 
 
--

Applied, this one will be in the next build
Thanks!

John Kacur

#7 lore raw

Re: [patch 2/3] cyclictest: Convert the offset of the alignment option to microseconds

In reply to John Kacur
Quoted 8 lines · John Kacur

src/cyclictest/cyclictest.c static void process_options (int argc, c

Quoted 4 lines

===================================================================

src/cyclictest/cyclictest.c +0 -0
@@ -1289,9 +1289,9 @@ static void process_options (int argc, c

I fixed your patch manually, but you are doing something wrong generating it, see how the function header get's cut off above there?

No. This is entirely correct. diff cuts off the function declaration at some random column and it's completely irrelevant to the correctness of the patch. That line is merily an extra for navigation purpose and not at all relevant to the patch itself.

@@ -1289,9 +1289,9 @@

would be a completly sufficient header for the hunk.

The reason why this patch did not apply is, that it is a complete replacement of the original patch and not a delta patch.

Anna-Maria should have sent a new series(PATCH V2) instead of patches which can be mistaken as delta fixes.

Thanks,

tglx

#8 lore raw

Re: [patch 2/3] cyclictest: Convert the offset of the alignment option to microseconds

Quoted 22 lines · Thomas Gleixner
Quoted 8 lines · John Kacur

src/cyclictest/cyclictest.c static void process_options (int argc, c

Quoted 4 lines

===================================================================

src/cyclictest/cyclictest.c +0 -0
@@ -1289,9 +1289,9 @@ static void process_options (int argc, c

I fixed your patch manually, but you are doing something wrong generating it, see how the function header get's cut off above there?

No. This is entirely correct. diff cuts off the function declaration at some random column and it's completely irrelevant to the correctness of the patch. That line is merily an extra for navigation purpose and not at all relevant to the patch itself.

(quoted diff) +0 -0
@@ -1289,9 +1289,9 @@
 

would be a completly sufficient header for the hunk.

The reason why this patch did not apply is, that it is a complete replacement of the original patch and not a delta patch.

Quoted 7 lines

Anna-Maria should have sent a new series(PATCH V2) instead of patches which can be mistaken as delta fixes.

Thanks,

tglx

Yeah, my guess as to why her patches are failing was wrong, but they are failing. Maybe it's a wordwrap problem. When I try with patch -p1 < annas-patch, I get this.

patch -p1 < ~/patches/anna/align_measurement_threads.patch
patching file src/cyclictest/cyclictest.c
Hunk #1 FAILED at 185.
patch: **** malformed patch at line 64: par->prio);

Thanks

John

#9 lore raw

Re: [patch 2/3] cyclictest: Convert the offset of the alignment option to microseconds

Quoted 8 lines · John Kacur

Yeah, my guess as to why her patches are failing was wrong, but they are failing. Maybe it's a wordwrap problem. When I try with patch -p1 < annas-patch, I get this.

patch -p1 < ~/patches/anna/align_measurement_threads.patch
patching file src/cyclictest/cyclictest.c
Hunk #1 FAILED at 185.
patch: **** malformed patch at line 64: par->prio);

Fair enough. Let her resend then.

Thanks,

tglx

#10 lore raw

Re: [patch 2/3] cyclictest: Convert the offset of the alignment option to microseconds

Quoted 1 line · Thomas Gleixner

Fair enough. Let her resend then.

I'm sorry. Now it applies.
Anna-Maria

cyclictest: Convert the offset of the alignment option to microseconds

The offset is specified in microseconds according to the documentation, but, the microseconds to nanoseconds conversion is missing so the effective offset has the unit of nanoseconds.

---
 src/cyclictest/cyclictest.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
src/cyclictest/cyclictest.c +2 -2
Index: rt-tests/src/cyclictest/cyclictest.c
===================================================================
@@ -1289,9 +1289,9 @@ static void process_options (int argc, c
 		case OPT_ALIGNED:
 			aligned=1;
 			if (optarg != NULL)
-				offset = atoi(optarg);
+				offset = atoi(optarg) * 1000;
 			else if (optind<argc && atoi(argv[optind]))
-				offset = atoi(argv[optind]);
+				offset = atoi(argv[optind]) * 1000;
 			else
 				offset = 0;
 			break;
#15 lore raw

Re: [patch 3/3] cyclictest: Align measurement threads to the next full second

In reply to John Kacur
Quoted 1 line · John Kacur

Can you fix this up, and resend please?

Now it should work.
Anna-Maria

cyclictest: Align measurement threads to the next full second

cyclictest starts the test threads at a random point in time. For fully reproducible tests it is required to schedule the threads with a specified offset from the timer tick. The influence of the tick can be measured by running the test with offset = 0 and offset = tickinterval/2.

To achieve this we rely on the fact, that the kernel starts the tick at CLOCK_MONOTONIC time 0. So it's guaranteed that the tick timer expires always every second (if the interval between the ticks defined by CONFIG_HZ is a whole-number divider of a second). Setting the global start time of the test threads to a full second (plus offset) and the interval to the interval between the ticks, the threads are scheduled with the specified offset to the tick.

Add a new option --secaligned which select this mode and modify the --aligned option code to support this. The --secaligned and --aligned options are mutually exclusive.

Signed-off-by Anna-Maria Gleixner <[email protected]>

---
 src/cyclictest/cyclictest.c |   39 ++++++++++++++++++++++++++++++++++-----
 1 file changed, 34 insertions(+), 5 deletions(-)
src/cyclictest/cyclictest.c +34 -5
Index: rt-tests/src/cyclictest/cyclictest.c
===================================================================
@@ -185,6 +185,7 @@ static int ct_debug;
 static int use_fifo = 0;
 static pthread_t fifo_threadid;
 static int aligned = 0;
+static int secaligned = 0;
 static int offset = 0;
 static int laptop = 0;
 
@@ -798,14 +799,27 @@ void *timerthread(void *param)
 		fatal("timerthread%d: failed to set priority to %d\n", par->cpu, par->prio);
 
 	/* Get current time */
-	if(aligned){
+	if (aligned || secaligned) {
 		pthread_barrier_wait(&globalt_barr);
-		if(par->tnum==0)
+		if (par->tnum == 0) {
 			clock_gettime(par->clock, &globalt);
+			if (secaligned) {
+				/* Ensure that the thread start timestamp is not
+				   in the past */
+				if (globalt.tv_nsec > 900000000)
+					globalt.tv_sec += 2;
+				else
+					globalt.tv_sec++;
+				globalt.tv_nsec = 0;
+			}
+		}
 		pthread_barrier_wait(&align_barr);
 		now = globalt;
 		if(offset) {
-			now.tv_nsec += offset * par->tnum;
+			if (aligned)
+				now.tv_nsec += offset * par->tnum;
+			else
+				now.tv_nsec += offset;
 			tsnorm(&now);
 		}
 	}
@@ -1056,6 +1070,8 @@ static void display_help(int error)
 	       "-R       --resolution      check clock resolution, calling clock_gettime() many\n"
 	       "                           times.  list of clock_gettime() values will be\n"
 	       "                           reported with -X\n"
+	       "         --secaligned [USEC] align thread wakeups to the next full second,\n"
+	       "                           and apply the optional offset\n"
 	       "-s       --system          use sys_nanosleep and sys_setitimer\n"
 	       "-S       --smp             Standard SMP testing: options -a -t -n and\n"
 	       "                           same priority of all threads\n"
@@ -1204,7 +1220,7 @@ enum option_values {
 	OPT_QUIET, OPT_PRIOSPREAD, OPT_RELATIVE, OPT_RESOLUTION, OPT_SYSTEM,
 	OPT_SMP, OPT_THREADS, OPT_TRACER, OPT_UNBUFFERED, OPT_NUMA, OPT_VERBOSE,
 	OPT_WAKEUP, OPT_WAKEUPRT, OPT_DBGCYCLIC, OPT_POLICY, OPT_HELP, OPT_NUMOPTS,
-	OPT_ALIGNED, OPT_LAPTOP,
+	OPT_ALIGNED, OPT_LAPTOP, OPT_SECALIGNED,
 };
 
 /* Process commandline options */
@@ -1251,6 +1267,7 @@ static void process_options (int argc, c
 			{"priospread",       no_argument,       NULL, OPT_PRIOSPREAD },
 			{"relative",         no_argument,       NULL, OPT_RELATIVE },
 			{"resolution",       no_argument,       NULL, OPT_RESOLUTION },
+			{"secaligned",       optional_argument, NULL, OPT_SECALIGNED },
 			{"system",           no_argument,       NULL, OPT_SYSTEM },
 			{"smp",              no_argument,       NULL, OPT_SMP },
 			{"threads",          optional_argument, NULL, OPT_THREADS },
@@ -1391,6 +1408,15 @@ static void process_options (int argc, c
 		case OPT_RESOLUTION:
 			check_clock_resolution = 1; break;
 		case 's':
+		case OPT_SECALIGNED:
+			secaligned = 1;
+			if (optarg != NULL)
+				offset = atoi(optarg) * 1000;
+			else if (optind < argc && atoi(argv[optind]))
+				offset = atoi(argv[optind]) * 1000;
+			else
+				offset = 0;
+			break;
 		case OPT_SYSTEM:
 			use_system = MODE_SYS_OFFSET; break;
 		case 'S':
@@ -1528,7 +1554,10 @@ static void process_options (int argc, c
 	if (num_threads < 1)
 		error = 1;
 
-	if (aligned) {
+	if (aligned && secaligned)
+		error = 1;
+
+	if (aligned || secaligned) {
 		pthread_barrier_init(&globalt_barr, NULL, num_threads);
 		pthread_barrier_init(&align_barr, NULL, num_threads);
 	}
Applied
#11 lore raw

Re: [patch 2/3] cyclictest: Convert the offset of the alignment option to microseconds

In reply to Anna-Maria Gleixner
Quoted 25 lines · Anna-Maria Gleixner
Quoted 1 line · Thomas Gleixner

Fair enough. Let her resend then.

I'm sorry. Now it applies.
Anna-Maria

cyclictest: Convert the offset of the alignment option to microseconds

The offset is specified in microseconds according to the documentation, but, the microseconds to nanoseconds conversion is missing so the effective offset has the unit of nanoseconds.

---
 src/cyclictest/cyclictest.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Index: rt-tests/src/cyclictest/cyclictest.c
===================================================================

src/cyclictest/cyclictest.c +0 -0
@@ -1289,9 +1289,9 @@ static void process_options (int argc, c
 		case OPT_ALIGNED:
 			aligned=1;

src/cyclictest/cyclictest.c static void process_options (int argc, c

Quoted 10 lines
src/cyclictest/cyclictest.c +2 -3
 			if (optarg != NULL)
-				offset = atoi(optarg);
+				offset = atoi(optarg) * 1000;
 			else if (optind<argc && atoi(argv[optind]))
-				offset = atoi(argv[optind]);
+				offset = atoi(argv[optind]) * 1000;
 			else
 				offset = 0;
 			break;
--

Thanks, applied, this will be in the next release

John

Applied
#16 lore raw

Re: [patch 3/3] cyclictest: Align measurement threads to the next full second

In reply to Anna-Maria Gleixner
Quoted 121 lines · Anna-Maria Gleixner
Quoted 1 line · John Kacur

Can you fix this up, and resend please?

Now it should work.
Anna-Maria

cyclictest: Align measurement threads to the next full second

cyclictest starts the test threads at a random point in time. For fully reproducible tests it is required to schedule the threads with a specified offset from the timer tick. The influence of the tick can be measured by running the test with offset = 0 and offset = tickinterval/2.

To achieve this we rely on the fact, that the kernel starts the tick at CLOCK_MONOTONIC time 0. So it's guaranteed that the tick timer expires always every second (if the interval between the ticks defined by CONFIG_HZ is a whole-number divider of a second). Setting the global start time of the test threads to a full second (plus offset) and the interval to the interval between the ticks, the threads are scheduled with the specified offset to the tick.

Add a new option --secaligned which select this mode and modify the --aligned option code to support this. The --secaligned and --aligned options are mutually exclusive.

Signed-off-by Anna-Maria Gleixner <[email protected]>

---
 src/cyclictest/cyclictest.c |   39 ++++++++++++++++++++++++++++++++++-----
 1 file changed, 34 insertions(+), 5 deletions(-)

Index: rt-tests/src/cyclictest/cyclictest.c
===================================================================

src/cyclictest/cyclictest.c +30 -4
@@ -185,6 +185,7 @@ static int ct_debug;
 static int use_fifo = 0;
 static pthread_t fifo_threadid;
 static int aligned = 0;
+static int secaligned = 0;
 static int offset = 0;
 static int laptop = 0;
 
@@ -798,14 +799,27 @@ void *timerthread(void *param)
 		fatal("timerthread%d: failed to set priority to %d\n", par->cpu, par->prio);
 
 	/* Get current time */
-	if(aligned){
+	if (aligned || secaligned) {
 		pthread_barrier_wait(&globalt_barr);
-		if(par->tnum==0)
+		if (par->tnum == 0) {
 			clock_gettime(par->clock, &globalt);
+			if (secaligned) {
+				/* Ensure that the thread start timestamp is not
+				   in the past */
+				if (globalt.tv_nsec > 900000000)
+					globalt.tv_sec += 2;
+				else
+					globalt.tv_sec++;
+				globalt.tv_nsec = 0;
+			}
+		}
 		pthread_barrier_wait(&align_barr);
 		now = globalt;
 		if(offset) {
-			now.tv_nsec += offset * par->tnum;
+			if (aligned)
+				now.tv_nsec += offset * par->tnum;
+			else
+				now.tv_nsec += offset;
 			tsnorm(&now);
 		}
 	}
@@ -1056,6 +1070,8 @@ static void display_help(int error)
 	       "-R       --resolution      check clock resolution, calling clock_gettime() many\n"
 	       "                           times.  list of clock_gettime() values will be\n"
 	       "                           reported with -X\n"
+	       "         --secaligned [USEC] align thread wakeups to the next full second,\n"
+	       "                           and apply the optional offset\n"
 	       "-s       --system          use sys_nanosleep and sys_setitimer\n"
 	       "-S       --smp             Standard SMP testing: options -a -t -n and\n"
 	       "                           same priority of all threads\n"
@@ -1204,7 +1220,7 @@ enum option_values {
 	OPT_QUIET, OPT_PRIOSPREAD, OPT_RELATIVE, OPT_RESOLUTION, OPT_SYSTEM,
 	OPT_SMP, OPT_THREADS, OPT_TRACER, OPT_UNBUFFERED, OPT_NUMA, OPT_VERBOSE,
 	OPT_WAKEUP, OPT_WAKEUPRT, OPT_DBGCYCLIC, OPT_POLICY, OPT_HELP, OPT_NUMOPTS,
-	OPT_ALIGNED, OPT_LAPTOP,
+	OPT_ALIGNED, OPT_LAPTOP, OPT_SECALIGNED,
 };
 
 /* Process commandline options */
@@ -1251,6 +1267,7 @@ static void process_options (int argc, c
 			{"priospread",       no_argument,       NULL, OPT_PRIOSPREAD },
 			{"relative",         no_argument,       NULL, OPT_RELATIVE },
 			{"resolution",       no_argument,       NULL, OPT_RESOLUTION },
+			{"secaligned",       optional_argument, NULL, OPT_SECALIGNED },
 			{"system",           no_argument,       NULL, OPT_SYSTEM },
 			{"smp",              no_argument,       NULL, OPT_SMP },
 			{"threads",          optional_argument, NULL, OPT_THREADS },
@@ -1391,6 +1408,15 @@ static void process_options (int argc, c
 		case OPT_RESOLUTION:
 			check_clock_resolution = 1; break;
 		case 's':
+		case OPT_SECALIGNED:
+			secaligned = 1;
+			if (optarg != NULL)
+				offset = atoi(optarg) * 1000;
+			else if (optind < argc && atoi(argv[optind]))
+				offset = atoi(argv[optind]) * 1000;
+			else
+				offset = 0;
+			break;
 		case OPT_SYSTEM:
 			use_system = MODE_SYS_OFFSET; break;
 		case 'S':
@@ -1528,7 +1554,10 @@ static void process_options (int argc, c
 	if (num_threads < 1)
 		error = 1;

src/cyclictest/cyclictest.c static void process_options (int argc, c

Quoted 10 lines
src/cyclictest/cyclictest.c +4 -2
 
-	if (aligned) {
+	if (aligned && secaligned)
+		error = 1;
+
+	if (aligned || secaligned) {
 		pthread_barrier_init(&globalt_barr, NULL, num_threads);
 		pthread_barrier_init(&align_barr, NULL, num_threads);
 	}
--

Thanks, applied, this will appear in the next release

John