linux-rt-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: anna-maria@glx-um.de
To: linux-rt-users@vger.kernel.org
Cc: Clark Williams <williams@redhat.com>
Subject: [patch 3/3] cyclictest: Align measurement threads to the next full second
Date: Tue, 26 May 2015 19:07:04 -0000	[thread overview]
Message-ID: <20150526190443.715858228@glx-um.de> (raw)
In-Reply-To: 20150526190333.510838769@glx-um.de

[-- Attachment #1: align-sec.patch --]
[-- Type: text/plain, Size: 4639 bytes --]

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 <anna-maria@glx-um.de>
---
 src/cyclictest/cyclictest.c |   39 ++++++++++++++++++++++++++++++++++-----
 1 file changed, 34 insertions(+), 5 deletions(-)

Index: rt-tests/src/cyclictest/cyclictest.c
===================================================================
--- rt-tests.orig/src/cyclictest/cyclictest.c
+++ 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);
 	}



  parent reply	other threads:[~2015-05-26 19:51 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-26 19:06 [patch 0/3] cyclictest: Various fixes and a new option anna-maria
2015-05-26 19:07 ` [patch 1/3] cyclictest: Ensure that next wakeup time is never in the past anna-maria
2015-06-02 13:06   ` John Kacur
2015-05-26 19:07 ` [patch 2/3] cyclictest: Convert the offset of the alignment option to microseconds anna-maria
2015-05-27 21:32   ` John Kacur
2015-05-30 11:01     ` Anna-Maria Gleixner
2015-06-02 13:00       ` John Kacur
2015-06-02 21:01         ` Thomas Gleixner
2015-06-02 21:17           ` John Kacur
2015-06-02 21:33             ` Thomas Gleixner
2015-06-08 13:18               ` Anna-Maria Gleixner
2015-06-08 17:31                 ` John Kacur
2015-05-26 19:07 ` anna-maria [this message]
2015-05-30 11:02   ` [patch 3/3] cyclictest: Align measurement threads to the next full second Anna-Maria Gleixner
2015-06-02 13:05     ` John Kacur
2015-06-08 13:21       ` Anna-Maria Gleixner
2015-06-08 17:32         ` John Kacur

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150526190443.715858228@glx-um.de \
    --to=anna-maria@glx-um.de \
    --cc=linux-rt-users@vger.kernel.org \
    --cc=williams@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).