public inbox for linux-rt-users@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/6] cyclictest: Add support for auxiliary clocks
@ 2026-04-07  6:48 Thomas Weißschuh (Schneider Electric)
  2026-04-07  6:48 ` [PATCH 1/6] cyclictest: Centralize clock option parsing Thomas Weißschuh (Schneider Electric)
                   ` (5 more replies)
  0 siblings, 6 replies; 18+ messages in thread
From: Thomas Weißschuh (Schneider Electric) @ 2026-04-07  6:48 UTC (permalink / raw)
  To: Clark Williams, John Kacur
  Cc: linux-rt-users, Thomas Weißschuh (Schneider Electric)

The Linux kernel provides support for non-standard auxiliary clocks.
These run independently from the system clock and each other.

Allow cyclictest to also use those.

Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
---
Thomas Weißschuh (Schneider Electric) (6):
      cyclictest: Centralize clock option parsing
      cyclictest: Test the return value of timer_create()
      cyclictest: Fix error error returns for uclibc clock_nanosleep() fallback
      cyclictest: Correctly print clock_nanosleep() errors
      cyclictest: Allow symbolic clock names
      cyclictest: Add support for auxiliary clocks

 src/cyclictest/cyclictest.8 |  6 ++--
 src/cyclictest/cyclictest.c | 80 ++++++++++++++++++++++++++++++++-------------
 2 files changed, 61 insertions(+), 25 deletions(-)
---
base-commit: f9c82184ce88d8de3ffe588279b0bc41d3887998
change-id: 20260121-auxclocks-7f3a13bbc199

Best regards,
--  
Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>


^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH 1/6] cyclictest: Centralize clock option parsing
  2026-04-07  6:48 [PATCH 0/6] cyclictest: Add support for auxiliary clocks Thomas Weißschuh (Schneider Electric)
@ 2026-04-07  6:48 ` Thomas Weißschuh (Schneider Electric)
  2026-04-07  8:27   ` Florian Bezdeka
  2026-04-15 14:46   ` John Kacur
  2026-04-07  6:48 ` [PATCH 2/6] cyclictest: Test the return value of timer_create() Thomas Weißschuh (Schneider Electric)
                   ` (4 subsequent siblings)
  5 siblings, 2 replies; 18+ messages in thread
From: Thomas Weißschuh (Schneider Electric) @ 2026-04-07  6:48 UTC (permalink / raw)
  To: Clark Williams, John Kacur
  Cc: linux-rt-users, Thomas Weißschuh (Schneider Electric)

Currently the lookup of the clockid from the commandline options is done
in multiple places. This makes the addition of symbolic clock names and
new clocks cumbersome.

Move all of the clock option parsing into a new helper function.

As a side-effect fix an off-by-one error in the validation of the
clock command line argument.

The new variable can not be named 'clock' as that would conflict with
the libc function of the same name.

Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
---
 src/cyclictest/cyclictest.c | 35 ++++++++++++++++++-----------------
 1 file changed, 18 insertions(+), 17 deletions(-)

diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c
index 960c90560668..592cf9d9387d 100644
--- a/src/cyclictest/cyclictest.c
+++ b/src/cyclictest/cyclictest.c
@@ -1022,7 +1022,7 @@ static int priority;
 static int policy = SCHED_OTHER;	/* default policy if not specified */
 static int num_threads = 1;
 static int max_cycles;
-static int clocksel = 0;
+static clockid_t used_clock;
 static int quiet;
 static int interval = DEFAULT_INTERVAL;
 static int distance = -1;
@@ -1031,10 +1031,17 @@ static struct bitmask *main_affinity_mask = NULL;
 static int smp = 0;
 static int setaffinity = AFFINITY_UNSPECIFIED;
 
-static int clocksources[] = {
-	CLOCK_MONOTONIC,
-	CLOCK_REALTIME,
-};
+static int handleclock(const char *clockarg)
+{
+	if (strcmp(clockarg, "0") == 0)
+		used_clock = CLOCK_MONOTONIC;
+	else if (strcmp(clockarg, "1") == 0)
+		used_clock = CLOCK_REALTIME;
+	else
+		return 1;
+
+	return 0;
+}
 
 static void handlepolicy(char *polname)
 {
@@ -1195,7 +1202,7 @@ static void process_options(int argc, char *argv[], int max_cpus)
 			tracelimit = atoi(optarg); break;
 		case 'c':
 		case OPT_CLOCK:
-			clocksel = atoi(optarg); break;
+			error |= handleclock(optarg); break;
 		case OPT_DEFAULT_SYSTEM:
 			power_management = 1; break;
 		case 'd':
@@ -1377,9 +1384,6 @@ static void process_options(int argc, char *argv[], int max_cpus)
 			      "on this processor\n");
 	}
 
-	if (clocksel < 0 || clocksel > ARRAY_SIZE(clocksources))
-		error = 1;
-
 	if (oscope_reduction < 1)
 		error = 1;
 
@@ -1983,7 +1987,6 @@ int main(int argc, char **argv)
 		warn("High resolution timers not available\n");
 
 	if (check_clock_resolution) {
-		int clock;
 		uint64_t diff;
 		int k;
 		uint64_t min_non_zero_diff = UINT64_MAX;
@@ -1994,9 +1997,7 @@ int main(int argc, char **argv)
 		struct timespec *time;
 		int times;
 
-		clock = clocksources[clocksel];
-
-		if (clock_getres(clock, &res))
+		if (clock_getres(used_clock, &res))
 			warn("clock_getres failed");
 		else
 			reported_resolution = (NSEC_PER_SEC * res.tv_sec) + res.tv_nsec;
@@ -2009,9 +2010,9 @@ int main(int argc, char **argv)
 		 * This will reliably capture resolution <= 500 usec.
 		 */
 		times = 1000;
-		clock_gettime(clock, &prev);
+		clock_gettime(used_clock, &prev);
 		for (k=0; k < times; k++)
-			clock_gettime(clock, &now);
+			clock_gettime(used_clock, &now);
 
 		diff = calcdiff_ns(now, prev);
 		if (diff == 0) {
@@ -2035,7 +2036,7 @@ int main(int argc, char **argv)
 		time = calloc(times, sizeof(*time));
 
 		for (k=0; k < times; k++)
-			clock_gettime(clock, &time[k]);
+			clock_gettime(used_clock, &time[k]);
 
 		info(ct_debug, "For %d consecutive calls to clock_gettime():\n", times);
 		info(ct_debug, "time, delta time (nsec)\n");
@@ -2193,7 +2194,7 @@ int main(int argc, char **argv)
 		}
 		if (priospread)
 			priority--;
-		par->clock = clocksources[clocksel];
+		par->clock = used_clock;
 		par->mode = mode;
 		par->timermode = timermode;
 		par->signal = signum;

-- 
2.53.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 2/6] cyclictest: Test the return value of timer_create()
  2026-04-07  6:48 [PATCH 0/6] cyclictest: Add support for auxiliary clocks Thomas Weißschuh (Schneider Electric)
  2026-04-07  6:48 ` [PATCH 1/6] cyclictest: Centralize clock option parsing Thomas Weißschuh (Schneider Electric)
@ 2026-04-07  6:48 ` Thomas Weißschuh (Schneider Electric)
  2026-04-15 14:47   ` John Kacur
  2026-04-07  6:48 ` [PATCH 3/6] cyclictest: Fix error error returns for uclibc clock_nanosleep() fallback Thomas Weißschuh (Schneider Electric)
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 18+ messages in thread
From: Thomas Weißschuh (Schneider Electric) @ 2026-04-07  6:48 UTC (permalink / raw)
  To: Clark Williams, John Kacur
  Cc: linux-rt-users, Thomas Weißschuh (Schneider Electric)

The operating system may not support timers for the select clock.

Report these errors to the user.

Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
---
 src/cyclictest/cyclictest.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c
index 592cf9d9387d..0c30e767e685 100644
--- a/src/cyclictest/cyclictest.c
+++ b/src/cyclictest/cyclictest.c
@@ -671,7 +671,9 @@ static void *timerthread(void *param)
 		sigev.sigev_notify = SIGEV_THREAD_ID | SIGEV_SIGNAL;
 		sigev.sigev_signo = par->signal;
 		sigev.sigev_notify_thread_id = stat->tid;
-		timer_create(par->clock, &sigev, &timer);
+		if (timer_create(par->clock, &sigev, &timer))
+			fatal("timerthread%d: failed to create timer for clock %d, errno: %d\n",
+			      par->cpu, par->clock, errno);
 		tspec.it_interval = interval;
 	}
 

-- 
2.53.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 3/6] cyclictest: Fix error error returns for uclibc clock_nanosleep() fallback
  2026-04-07  6:48 [PATCH 0/6] cyclictest: Add support for auxiliary clocks Thomas Weißschuh (Schneider Electric)
  2026-04-07  6:48 ` [PATCH 1/6] cyclictest: Centralize clock option parsing Thomas Weißschuh (Schneider Electric)
  2026-04-07  6:48 ` [PATCH 2/6] cyclictest: Test the return value of timer_create() Thomas Weißschuh (Schneider Electric)
@ 2026-04-07  6:48 ` Thomas Weißschuh (Schneider Electric)
  2026-04-07  8:16   ` Florian Bezdeka
  2026-04-15 14:47   ` John Kacur
  2026-04-07  6:48 ` [PATCH 4/6] cyclictest: Correctly print clock_nanosleep() errors Thomas Weißschuh (Schneider Electric)
                   ` (2 subsequent siblings)
  5 siblings, 2 replies; 18+ messages in thread
From: Thomas Weißschuh (Schneider Electric) @ 2026-04-07  6:48 UTC (permalink / raw)
  To: Clark Williams, John Kacur
  Cc: linux-rt-users, Thomas Weißschuh (Schneider Electric)

clock_nanosleep() is expected to return errors as a positive number,
without relying on errno.

Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
---
 src/cyclictest/cyclictest.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c
index 0c30e767e685..dacf0b7a718e 100644
--- a/src/cyclictest/cyclictest.c
+++ b/src/cyclictest/cyclictest.c
@@ -62,12 +62,18 @@
 static int clock_nanosleep(clockid_t clock_id, int flags, const struct timespec *req,
 			   struct timespec *rem)
 {
+	int retval;
+
 	if (clock_id == CLOCK_THREAD_CPUTIME_ID)
 		return -EINVAL;
 	if (clock_id == CLOCK_PROCESS_CPUTIME_ID)
 		clock_id = MAKE_PROCESS_CPUCLOCK(0, CPUCLOCK_SCHED);
 
-	return syscall(__NR_clock_nanosleep, clock_id, flags, req, rem);
+	retval = syscall(__NR_clock_nanosleep, clock_id, flags, req, rem);
+	if (retval == 0)
+		return 0;
+
+	return errno;
 }
 
 int sched_setaffinity(__pid_t __pid, size_t __cpusetsize,

-- 
2.53.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 4/6] cyclictest: Correctly print clock_nanosleep() errors
  2026-04-07  6:48 [PATCH 0/6] cyclictest: Add support for auxiliary clocks Thomas Weißschuh (Schneider Electric)
                   ` (2 preceding siblings ...)
  2026-04-07  6:48 ` [PATCH 3/6] cyclictest: Fix error error returns for uclibc clock_nanosleep() fallback Thomas Weißschuh (Schneider Electric)
@ 2026-04-07  6:48 ` Thomas Weißschuh (Schneider Electric)
  2026-04-15 14:47   ` John Kacur
  2026-04-07  6:48 ` [PATCH 5/6] cyclictest: Allow symbolic clock names Thomas Weißschuh (Schneider Electric)
  2026-04-07  6:48 ` [PATCH 6/6] cyclictest: Add support for auxiliary clocks Thomas Weißschuh (Schneider Electric)
  5 siblings, 1 reply; 18+ messages in thread
From: Thomas Weißschuh (Schneider Electric) @ 2026-04-07  6:48 UTC (permalink / raw)
  To: Clark Williams, John Kacur
  Cc: linux-rt-users, Thomas Weißschuh (Schneider Electric)

clock_nanosleep() does not set errno on errors but instead returns a
positive error number directly.

Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
---
 src/cyclictest/cyclictest.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c
index dacf0b7a718e..40da2cc4119d 100644
--- a/src/cyclictest/cyclictest.c
+++ b/src/cyclictest/cyclictest.c
@@ -773,7 +773,7 @@ static void *timerthread(void *param)
 						      &next, NULL);
 				if (ret != 0) {
 					if (ret != EINTR)
-						warn("clock_nanosleep failed. errno: %d\n", errno);
+						warn("clock_nanosleep failed. errno: %d\n", ret);
 					goto out;
 				}
 			} else {
@@ -787,7 +787,7 @@ static void *timerthread(void *param)
 					TIMER_RELTIME, &interval, NULL);
 				if (ret != 0) {
 					if (ret != EINTR)
-						warn("clock_nanosleep() failed. errno: %d\n", errno);
+						warn("clock_nanosleep() failed. errno: %d\n", ret);
 					goto out;
 				}
 				next.tv_sec = now.tv_sec + interval.tv_sec;

-- 
2.53.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 5/6] cyclictest: Allow symbolic clock names
  2026-04-07  6:48 [PATCH 0/6] cyclictest: Add support for auxiliary clocks Thomas Weißschuh (Schneider Electric)
                   ` (3 preceding siblings ...)
  2026-04-07  6:48 ` [PATCH 4/6] cyclictest: Correctly print clock_nanosleep() errors Thomas Weißschuh (Schneider Electric)
@ 2026-04-07  6:48 ` Thomas Weißschuh (Schneider Electric)
  2026-04-15 14:48   ` John Kacur
  2026-04-07  6:48 ` [PATCH 6/6] cyclictest: Add support for auxiliary clocks Thomas Weißschuh (Schneider Electric)
  5 siblings, 1 reply; 18+ messages in thread
From: Thomas Weißschuh (Schneider Electric) @ 2026-04-07  6:48 UTC (permalink / raw)
  To: Clark Williams, John Kacur
  Cc: linux-rt-users, Thomas Weißschuh (Schneider Electric)

The numeric values are not self-explanatory. New clocks are about to be
added, exarcerbating the issue.

Allow users to specify symbolic clock names and document those.

The old numbers are still handled for backwards compatibility.

Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
---
 src/cyclictest/cyclictest.8 | 4 ++--
 src/cyclictest/cyclictest.c | 8 ++++++--
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/cyclictest/cyclictest.8 b/src/cyclictest/cyclictest.8
index ff2cb968fc01..1a59d3b29048 100644
--- a/src/cyclictest/cyclictest.8
+++ b/src/cyclictest/cyclictest.8
@@ -56,9 +56,9 @@ Send break trace command when latency > USEC
 .B \-c, \-\-clock=CLOCK
 select clock
 .br
-0 = CLOCK_MONOTONIC (default)
+monotonic (default)
 .br
-1 = CLOCK_REALTIME
+realtime
 .TP
 .B \-\-deepest\-idle\-state=n
 Reduce exit from idle latency by limiting idle state up to n on used cpus (-1 disables all idle states). Power management is not suppresed on other cpus.
diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c
index 40da2cc4119d..2d1ff968f8aa 100644
--- a/src/cyclictest/cyclictest.c
+++ b/src/cyclictest/cyclictest.c
@@ -950,8 +950,8 @@ static void display_help(int error)
 	       "-A USEC  --aligned=USEC    align thread wakeups to a specific offset\n"
 	       "-b USEC  --breaktrace=USEC send break trace command when latency > USEC\n"
 	       "-c CLOCK --clock=CLOCK     select clock\n"
-	       "                           0 = CLOCK_MONOTONIC (default)\n"
-	       "                           1 = CLOCK_REALTIME\n"
+	       "                           monotonic (default)\n"
+	       "                           realtime\n"
 	       "         --deepest-idle-state=n\n"
 	       "                           Reduce exit from idle latency by limiting idle state\n"
 	       "                           up to n on used cpus (-1 disables all idle states).\n"
@@ -1043,8 +1043,12 @@ static int handleclock(const char *clockarg)
 {
 	if (strcmp(clockarg, "0") == 0)
 		used_clock = CLOCK_MONOTONIC;
+	else if (strcmp(clockarg, "monotonic") == 0)
+		used_clock = CLOCK_MONOTONIC;
 	else if (strcmp(clockarg, "1") == 0)
 		used_clock = CLOCK_REALTIME;
+	else if (strcmp(clockarg, "realtime") == 0)
+		used_clock = CLOCK_REALTIME;
 	else
 		return 1;
 

-- 
2.53.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 6/6] cyclictest: Add support for auxiliary clocks
  2026-04-07  6:48 [PATCH 0/6] cyclictest: Add support for auxiliary clocks Thomas Weißschuh (Schneider Electric)
                   ` (4 preceding siblings ...)
  2026-04-07  6:48 ` [PATCH 5/6] cyclictest: Allow symbolic clock names Thomas Weißschuh (Schneider Electric)
@ 2026-04-07  6:48 ` Thomas Weißschuh (Schneider Electric)
  2026-04-15 14:48   ` John Kacur
  5 siblings, 1 reply; 18+ messages in thread
From: Thomas Weißschuh (Schneider Electric) @ 2026-04-07  6:48 UTC (permalink / raw)
  To: Clark Williams, John Kacur
  Cc: linux-rt-users, Thomas Weißschuh (Schneider Electric)

The Linux kernel provides support for non-standard auxiliary clocks.
These run independently from the system clock and each other.

Allow cyclictest to also use those.

Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>

---
Currently clock_nanosleep() for these auxiliary clocks is not yet in the
mainline kernel.

Instead of having a dedicated parsing function, I used the unrolled
switch-case as it keeps the logic simple in the face of error handling.
---
 src/cyclictest/cyclictest.8 |  2 ++
 src/cyclictest/cyclictest.c | 21 +++++++++++++++++++++
 2 files changed, 23 insertions(+)

diff --git a/src/cyclictest/cyclictest.8 b/src/cyclictest/cyclictest.8
index 1a59d3b29048..f3390bc5c57d 100644
--- a/src/cyclictest/cyclictest.8
+++ b/src/cyclictest/cyclictest.8
@@ -59,6 +59,8 @@ select clock
 monotonic (default)
 .br
 realtime
+.br
+aux0 - aux7
 .TP
 .B \-\-deepest\-idle\-state=n
 Reduce exit from idle latency by limiting idle state up to n on used cpus (-1 disables all idle states). Power management is not suppresed on other cpus.
diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c
index 2d1ff968f8aa..afc3a8c452da 100644
--- a/src/cyclictest/cyclictest.c
+++ b/src/cyclictest/cyclictest.c
@@ -52,6 +52,10 @@
 #define SCHED_NORMAL SCHED_OTHER
 #endif
 
+#ifndef CLOCK_AUX
+#define CLOCK_AUX 16
+#endif
+
 #define sigev_notify_thread_id _sigev_un._tid
 
 #ifdef __UCLIBC__
@@ -952,6 +956,7 @@ static void display_help(int error)
 	       "-c CLOCK --clock=CLOCK     select clock\n"
 	       "                           monotonic (default)\n"
 	       "                           realtime\n"
+	       "                           aux0 - aux7\n"
 	       "         --deepest-idle-state=n\n"
 	       "                           Reduce exit from idle latency by limiting idle state\n"
 	       "                           up to n on used cpus (-1 disables all idle states).\n"
@@ -1049,6 +1054,22 @@ static int handleclock(const char *clockarg)
 		used_clock = CLOCK_REALTIME;
 	else if (strcmp(clockarg, "realtime") == 0)
 		used_clock = CLOCK_REALTIME;
+	else if (strcmp(clockarg, "aux0") == 0)
+		used_clock = CLOCK_AUX + 0;
+	else if (strcmp(clockarg, "aux1") == 0)
+		used_clock = CLOCK_AUX + 1;
+	else if (strcmp(clockarg, "aux2") == 0)
+		used_clock = CLOCK_AUX + 2;
+	else if (strcmp(clockarg, "aux3") == 0)
+		used_clock = CLOCK_AUX + 3;
+	else if (strcmp(clockarg, "aux4") == 0)
+		used_clock = CLOCK_AUX + 4;
+	else if (strcmp(clockarg, "aux5") == 0)
+		used_clock = CLOCK_AUX + 5;
+	else if (strcmp(clockarg, "aux6") == 0)
+		used_clock = CLOCK_AUX + 6;
+	else if (strcmp(clockarg, "aux7") == 0)
+		used_clock = CLOCK_AUX + 7;
 	else
 		return 1;
 

-- 
2.53.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH 3/6] cyclictest: Fix error error returns for uclibc clock_nanosleep() fallback
  2026-04-07  6:48 ` [PATCH 3/6] cyclictest: Fix error error returns for uclibc clock_nanosleep() fallback Thomas Weißschuh (Schneider Electric)
@ 2026-04-07  8:16   ` Florian Bezdeka
  2026-04-07  8:50     ` Thomas Weißschuh (Schneider Electric)
  2026-04-15 14:47   ` John Kacur
  1 sibling, 1 reply; 18+ messages in thread
From: Florian Bezdeka @ 2026-04-07  8:16 UTC (permalink / raw)
  To: Thomas Weißschuh (Schneider Electric), Clark Williams,
	John Kacur
  Cc: linux-rt-users

On Tue, 2026-04-07 at 08:48 +0200, Thomas Weißschuh (Schneider Electric)
wrote:
> clock_nanosleep() is expected to return errors as a positive number,
> without relying on errno.
> 
> Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
> ---
>  src/cyclictest/cyclictest.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c
> index 0c30e767e685..dacf0b7a718e 100644
> --- a/src/cyclictest/cyclictest.c
> +++ b/src/cyclictest/cyclictest.c
> @@ -62,12 +62,18 @@
>  static int clock_nanosleep(clockid_t clock_id, int flags, const struct timespec *req,
>  			   struct timespec *rem)
>  {
> +	int retval;
> +
>  	if (clock_id == CLOCK_THREAD_CPUTIME_ID)
>  		return -EINVAL;
>  	if (clock_id == CLOCK_PROCESS_CPUTIME_ID)
>  		clock_id = MAKE_PROCESS_CPUCLOCK(0, CPUCLOCK_SCHED);
>  
> -	return syscall(__NR_clock_nanosleep, clock_id, flags, req, rem);
> +	retval = syscall(__NR_clock_nanosleep, clock_id, flags, req, rem);
> +	if (retval == 0)
> +		return 0;
> +
> +	return errno;

That doesn't match with the commit message above, does it? syscall() to
my knowledge will not set/touch errno. syscall() will return whatever
came back from the kernel.

The value of errno is "undefined" (in terms of "contains the last error
code, wherever this is coming from") here.

Looking at patch 4: Looks like this patch can be dropped.

>  }
>  
>  int sched_setaffinity(__pid_t __pid, size_t __cpusetsize,
> 
> -- 
> 2.53.0

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 1/6] cyclictest: Centralize clock option parsing
  2026-04-07  6:48 ` [PATCH 1/6] cyclictest: Centralize clock option parsing Thomas Weißschuh (Schneider Electric)
@ 2026-04-07  8:27   ` Florian Bezdeka
  2026-04-07  8:45     ` Thomas Weißschuh (Schneider Electric)
  2026-04-15 14:46   ` John Kacur
  1 sibling, 1 reply; 18+ messages in thread
From: Florian Bezdeka @ 2026-04-07  8:27 UTC (permalink / raw)
  To: Thomas Weißschuh (Schneider Electric), Clark Williams,
	John Kacur
  Cc: linux-rt-users

On Tue, 2026-04-07 at 08:48 +0200, Thomas Weißschuh (Schneider Electric)
wrote:
> Currently the lookup of the clockid from the commandline options is done
> in multiple places. This makes the addition of symbolic clock names and
> new clocks cumbersome.
> 
> Move all of the clock option parsing into a new helper function.
> 
> As a side-effect fix an off-by-one error in the validation of the
> clock command line argument.
> 
> The new variable can not be named 'clock' as that would conflict with
> the libc function of the same name.
> 
> Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
> ---
>  src/cyclictest/cyclictest.c | 35 ++++++++++++++++++-----------------
>  1 file changed, 18 insertions(+), 17 deletions(-)
> 
> diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c
> index 960c90560668..592cf9d9387d 100644
> --- a/src/cyclictest/cyclictest.c
> +++ b/src/cyclictest/cyclictest.c
> @@ -1022,7 +1022,7 @@ static int priority;
>  static int policy = SCHED_OTHER;	/* default policy if not specified */
>  static int num_threads = 1;
>  static int max_cycles;
> -static int clocksel = 0;
> +static clockid_t used_clock;
>  static int quiet;
>  static int interval = DEFAULT_INTERVAL;
>  static int distance = -1;
> @@ -1031,10 +1031,17 @@ static struct bitmask *main_affinity_mask = NULL;
>  static int smp = 0;
>  static int setaffinity = AFFINITY_UNSPECIFIED;
>  
> -static int clocksources[] = {
> -	CLOCK_MONOTONIC,
> -	CLOCK_REALTIME,
> -};
> +static int handleclock(const char *clockarg)
> +{
> +	if (strcmp(clockarg, "0") == 0)
> +		used_clock = CLOCK_MONOTONIC;
> +	else if (strcmp(clockarg, "1") == 0)
> +		used_clock = CLOCK_REALTIME;
> +	else
> +		return 1;
> +
> +	return 0;
> +}

What happens to "unexpected" cmdline parameters now? used_clocks will
not be set and ...

>  
>  static void handlepolicy(char *polname)
>  {
> @@ -1195,7 +1202,7 @@ static void process_options(int argc, char *argv[], int max_cpus)
>  			tracelimit = atoi(optarg); break;
>  		case 'c':
>  		case OPT_CLOCK:
> -			clocksel = atoi(optarg); break;
> +			error |= handleclock(optarg); break;
>  		case OPT_DEFAULT_SYSTEM:
>  			power_management = 1; break;
>  		case 'd':
> @@ -1377,9 +1384,6 @@ static void process_options(int argc, char *argv[], int max_cpus)
>  			      "on this processor\n");
>  	}
>  
> -	if (clocksel < 0 || clocksel > ARRAY_SIZE(clocksources))
> -		error = 1;
> -

... the validation check has been removed. As unused_clock is static
(and with that initialized to zero) all invalid parameter values will
silently be "migrated" to CLOCK_REALTIME. Right?

I would vote for an error/warn message to avoid that a fat fingered
cmdline argument invalidates your measurements.

>  	if (oscope_reduction < 1)
>  		error = 1;
>  
> @@ -1983,7 +1987,6 @@ int main(int argc, char **argv)
>  		warn("High resolution timers not available\n");
>  
>  	if (check_clock_resolution) {
> -		int clock;
>  		uint64_t diff;
>  		int k;
>  		uint64_t min_non_zero_diff = UINT64_MAX;
> @@ -1994,9 +1997,7 @@ int main(int argc, char **argv)
>  		struct timespec *time;
>  		int times;
>  
> -		clock = clocksources[clocksel];
> -
> -		if (clock_getres(clock, &res))
> +		if (clock_getres(used_clock, &res))
>  			warn("clock_getres failed");
>  		else
>  			reported_resolution = (NSEC_PER_SEC * res.tv_sec) + res.tv_nsec;
> @@ -2009,9 +2010,9 @@ int main(int argc, char **argv)
>  		 * This will reliably capture resolution <= 500 usec.
>  		 */
>  		times = 1000;
> -		clock_gettime(clock, &prev);
> +		clock_gettime(used_clock, &prev);
>  		for (k=0; k < times; k++)
> -			clock_gettime(clock, &now);
> +			clock_gettime(used_clock, &now);
>  
>  		diff = calcdiff_ns(now, prev);
>  		if (diff == 0) {
> @@ -2035,7 +2036,7 @@ int main(int argc, char **argv)
>  		time = calloc(times, sizeof(*time));
>  
>  		for (k=0; k < times; k++)
> -			clock_gettime(clock, &time[k]);
> +			clock_gettime(used_clock, &time[k]);
>  
>  		info(ct_debug, "For %d consecutive calls to clock_gettime():\n", times);
>  		info(ct_debug, "time, delta time (nsec)\n");
> @@ -2193,7 +2194,7 @@ int main(int argc, char **argv)
>  		}
>  		if (priospread)
>  			priority--;
> -		par->clock = clocksources[clocksel];
> +		par->clock = used_clock;
>  		par->mode = mode;
>  		par->timermode = timermode;
>  		par->signal = signum;
> 
> -- 
> 2.53.0

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 1/6] cyclictest: Centralize clock option parsing
  2026-04-07  8:27   ` Florian Bezdeka
@ 2026-04-07  8:45     ` Thomas Weißschuh (Schneider Electric)
  0 siblings, 0 replies; 18+ messages in thread
From: Thomas Weißschuh (Schneider Electric) @ 2026-04-07  8:45 UTC (permalink / raw)
  To: Florian Bezdeka; +Cc: Clark Williams, John Kacur, linux-rt-users

On Tue, Apr 07, 2026 at 10:27:39AM +0200, Florian Bezdeka wrote:
> On Tue, 2026-04-07 at 08:48 +0200, Thomas Weißschuh (Schneider Electric)
> wrote:
> > Currently the lookup of the clockid from the commandline options is done
> > in multiple places. This makes the addition of symbolic clock names and
> > new clocks cumbersome.
> > 
> > Move all of the clock option parsing into a new helper function.
> > 
> > As a side-effect fix an off-by-one error in the validation of the
> > clock command line argument.
> > 
> > The new variable can not be named 'clock' as that would conflict with
> > the libc function of the same name.
> > 
> > Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
> > ---
> >  src/cyclictest/cyclictest.c | 35 ++++++++++++++++++-----------------
> >  1 file changed, 18 insertions(+), 17 deletions(-)
> > 
> > diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c
> > index 960c90560668..592cf9d9387d 100644
> > --- a/src/cyclictest/cyclictest.c
> > +++ b/src/cyclictest/cyclictest.c
> > @@ -1022,7 +1022,7 @@ static int priority;
> >  static int policy = SCHED_OTHER;	/* default policy if not specified */
> >  static int num_threads = 1;
> >  static int max_cycles;
> > -static int clocksel = 0;
> > +static clockid_t used_clock;
> >  static int quiet;
> >  static int interval = DEFAULT_INTERVAL;
> >  static int distance = -1;
> > @@ -1031,10 +1031,17 @@ static struct bitmask *main_affinity_mask = NULL;
> >  static int smp = 0;
> >  static int setaffinity = AFFINITY_UNSPECIFIED;
> >  
> > -static int clocksources[] = {
> > -	CLOCK_MONOTONIC,
> > -	CLOCK_REALTIME,
> > -};
> > +static int handleclock(const char *clockarg)
> > +{
> > +	if (strcmp(clockarg, "0") == 0)
> > +		used_clock = CLOCK_MONOTONIC;
> > +	else if (strcmp(clockarg, "1") == 0)
> > +		used_clock = CLOCK_REALTIME;
> > +	else
> > +		return 1;
> > +
> > +	return 0;
> > +}
> 
> What happens to "unexpected" cmdline parameters now? used_clocks will
> not be set and ...

Then handleclock() will return 1 ...

> >  
> >  static void handlepolicy(char *polname)
> >  {
> > @@ -1195,7 +1202,7 @@ static void process_options(int argc, char *argv[], int max_cpus)
> >  			tracelimit = atoi(optarg); break;
> >  		case 'c':
> >  		case OPT_CLOCK:
> > -			clocksel = atoi(optarg); break;
> > +			error |= handleclock(optarg); break;

... which will set the error flag here.

> >  		case OPT_DEFAULT_SYSTEM:
> >  			power_management = 1; break;
> >  		case 'd':
> > @@ -1377,9 +1384,6 @@ static void process_options(int argc, char *argv[], int max_cpus)
> >  			      "on this processor\n");
> >  	}
> >  
> > -	if (clocksel < 0 || clocksel > ARRAY_SIZE(clocksources))
> > -		error = 1;
> > -
> 
> ... the validation check has been removed. As unused_clock is static
> (and with that initialized to zero) all invalid parameter values will
> silently be "migrated" to CLOCK_REALTIME. Right?

I don't think so, see above.

> I would vote for an error/warn message to avoid that a fat fingered
> cmdline argument invalidates your measurements.

With this patch in its current form, the usage guide will be printed
in case of invalid clock ids. I also just noticed that the behavior
*before* this patch is to silently treat non-numeric arguments as
CLOCK_REALTIME.

> >  	if (oscope_reduction < 1)
> >  		error = 1;

(...)

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 3/6] cyclictest: Fix error error returns for uclibc clock_nanosleep() fallback
  2026-04-07  8:16   ` Florian Bezdeka
@ 2026-04-07  8:50     ` Thomas Weißschuh (Schneider Electric)
  2026-04-07  8:59       ` Florian Bezdeka
  0 siblings, 1 reply; 18+ messages in thread
From: Thomas Weißschuh (Schneider Electric) @ 2026-04-07  8:50 UTC (permalink / raw)
  To: Florian Bezdeka; +Cc: Clark Williams, John Kacur, linux-rt-users

On Tue, Apr 07, 2026 at 10:16:08AM +0200, Florian Bezdeka wrote:
> On Tue, 2026-04-07 at 08:48 +0200, Thomas Weißschuh (Schneider Electric)
> wrote:
> > clock_nanosleep() is expected to return errors as a positive number,
> > without relying on errno.
> > 
> > Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
> > ---
> >  src/cyclictest/cyclictest.c | 8 +++++++-
> >  1 file changed, 7 insertions(+), 1 deletion(-)
> > 
> > diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c
> > index 0c30e767e685..dacf0b7a718e 100644
> > --- a/src/cyclictest/cyclictest.c
> > +++ b/src/cyclictest/cyclictest.c
> > @@ -62,12 +62,18 @@
> >  static int clock_nanosleep(clockid_t clock_id, int flags, const struct timespec *req,
> >  			   struct timespec *rem)
> >  {
> > +	int retval;
> > +
> >  	if (clock_id == CLOCK_THREAD_CPUTIME_ID)
> >  		return -EINVAL;
> >  	if (clock_id == CLOCK_PROCESS_CPUTIME_ID)
> >  		clock_id = MAKE_PROCESS_CPUCLOCK(0, CPUCLOCK_SCHED);
> >  
> > -	return syscall(__NR_clock_nanosleep, clock_id, flags, req, rem);
> > +	retval = syscall(__NR_clock_nanosleep, clock_id, flags, req, rem);
> > +	if (retval == 0)
> > +		return 0;
> > +
> > +	return errno;
> 
> That doesn't match with the commit message above, does it? syscall() to
> my knowledge will not set/touch errno. syscall() will return whatever
> came back from the kernel.

syscall() *does* indeed touch errno. From syscall(2):
"A -1 return value indicates an error, and an error number is stored in errno."

Unfortunately there is no standard variant of syscall() which does not
touch errno.

> The value of errno is "undefined" (in terms of "contains the last error
> code, wherever this is coming from") here.
> 
> Looking at patch 4: Looks like this patch can be dropped.

No, this patch (patch 3) is only for the fallback definition of uclibc.
Patch 4 is necessary for all libcs. For some (to me unknown) reason
clock_nanosleep() works different from all the other libc functions.

> >  }
> >  
> >  int sched_setaffinity(__pid_t __pid, size_t __cpusetsize,
> > 
> > -- 
> > 2.53.0

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 3/6] cyclictest: Fix error error returns for uclibc clock_nanosleep() fallback
  2026-04-07  8:50     ` Thomas Weißschuh (Schneider Electric)
@ 2026-04-07  8:59       ` Florian Bezdeka
  0 siblings, 0 replies; 18+ messages in thread
From: Florian Bezdeka @ 2026-04-07  8:59 UTC (permalink / raw)
  To: Thomas Weißschuh (Schneider Electric)
  Cc: Clark Williams, John Kacur, linux-rt-users

On Tue, 2026-04-07 at 10:50 +0200, Thomas Weißschuh (Schneider Electric)
wrote:
> On Tue, Apr 07, 2026 at 10:16:08AM +0200, Florian Bezdeka wrote:
> > On Tue, 2026-04-07 at 08:48 +0200, Thomas Weißschuh (Schneider Electric)
> > wrote:
> > > clock_nanosleep() is expected to return errors as a positive number,
> > > without relying on errno.
> > > 
> > > Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
> > > ---
> > >  src/cyclictest/cyclictest.c | 8 +++++++-
> > >  1 file changed, 7 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c
> > > index 0c30e767e685..dacf0b7a718e 100644
> > > --- a/src/cyclictest/cyclictest.c
> > > +++ b/src/cyclictest/cyclictest.c
> > > @@ -62,12 +62,18 @@
> > >  static int clock_nanosleep(clockid_t clock_id, int flags, const struct timespec *req,
> > >  			   struct timespec *rem)
> > >  {
> > > +	int retval;
> > > +
> > >  	if (clock_id == CLOCK_THREAD_CPUTIME_ID)
> > >  		return -EINVAL;
> > >  	if (clock_id == CLOCK_PROCESS_CPUTIME_ID)
> > >  		clock_id = MAKE_PROCESS_CPUCLOCK(0, CPUCLOCK_SCHED);
> > >  
> > > -	return syscall(__NR_clock_nanosleep, clock_id, flags, req, rem);
> > > +	retval = syscall(__NR_clock_nanosleep, clock_id, flags, req, rem);
> > > +	if (retval == 0)
> > > +		return 0;
> > > +
> > > +	return errno;
> > 
> > That doesn't match with the commit message above, does it? syscall() to
> > my knowledge will not set/touch errno. syscall() will return whatever
> > came back from the kernel.
> 
> syscall() *does* indeed touch errno. From syscall(2):
> "A -1 return value indicates an error, and an error number is stored in errno."

Right. I stopped reading to early. 

I would vote for

if (retval == -1)
	return errno;

then. But that's just a minor detail.

> 
> Unfortunately there is no standard variant of syscall() which does not
> touch errno.
> 
> > The value of errno is "undefined" (in terms of "contains the last error
> > code, wherever this is coming from") here.
> > 
> > Looking at patch 4: Looks like this patch can be dropped.
> 
> No, this patch (patch 3) is only for the fallback definition of uclibc.
> Patch 4 is necessary for all libcs. For some (to me unknown) reason
> clock_nanosleep() works different from all the other libc functions.

POSIX...
> > 

Thanks for the clarifications. Here as well as in the other thread.

Best regards,
Florian

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 1/6] cyclictest: Centralize clock option parsing
  2026-04-07  6:48 ` [PATCH 1/6] cyclictest: Centralize clock option parsing Thomas Weißschuh (Schneider Electric)
  2026-04-07  8:27   ` Florian Bezdeka
@ 2026-04-15 14:46   ` John Kacur
  1 sibling, 0 replies; 18+ messages in thread
From: John Kacur @ 2026-04-15 14:46 UTC (permalink / raw)
  To: Thomas Weißschuh; +Cc: linux-rt-users

On Tue, 07 Apr 2026 at 08:48:41AM +0200, Thomas Weißschuh (Schneider Electric) wrote:
> cyclictest: Centralize clock option parsing

Applied, thanks!

Signed-off-by: John Kacur <jkacur@redhat.com>

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 2/6] cyclictest: Test the return value of timer_create()
  2026-04-07  6:48 ` [PATCH 2/6] cyclictest: Test the return value of timer_create() Thomas Weißschuh (Schneider Electric)
@ 2026-04-15 14:47   ` John Kacur
  0 siblings, 0 replies; 18+ messages in thread
From: John Kacur @ 2026-04-15 14:47 UTC (permalink / raw)
  To: Thomas Weißschuh; +Cc: linux-rt-users

On Tue, 07 Apr 2026 at 08:48:42AM +0200, Thomas Weißschuh (Schneider Electric) wrote:
> cyclictest: Test the return value of timer_create()

Applied, thanks!

Signed-off-by: John Kacur <jkacur@redhat.com>

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 3/6] cyclictest: Fix error error returns for uclibc clock_nanosleep() fallback
  2026-04-07  6:48 ` [PATCH 3/6] cyclictest: Fix error error returns for uclibc clock_nanosleep() fallback Thomas Weißschuh (Schneider Electric)
  2026-04-07  8:16   ` Florian Bezdeka
@ 2026-04-15 14:47   ` John Kacur
  1 sibling, 0 replies; 18+ messages in thread
From: John Kacur @ 2026-04-15 14:47 UTC (permalink / raw)
  To: Thomas Weißschuh; +Cc: linux-rt-users

On Tue, 07 Apr 2026 at 08:48:43AM +0200, Thomas Weißschuh (Schneider Electric) wrote:
> cyclictest: Fix error error returns for uclibc clock_nanosleep() fallback

Applied, thanks!

Signed-off-by: John Kacur <jkacur@redhat.com>

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 4/6] cyclictest: Correctly print clock_nanosleep() errors
  2026-04-07  6:48 ` [PATCH 4/6] cyclictest: Correctly print clock_nanosleep() errors Thomas Weißschuh (Schneider Electric)
@ 2026-04-15 14:47   ` John Kacur
  0 siblings, 0 replies; 18+ messages in thread
From: John Kacur @ 2026-04-15 14:47 UTC (permalink / raw)
  To: Thomas Weißschuh; +Cc: linux-rt-users

On Tue, 07 Apr 2026 at 08:48:44AM +0200, Thomas Weißschuh (Schneider Electric) wrote:
> cyclictest: Correctly print clock_nanosleep() errors

Applied, thanks!

Signed-off-by: John Kacur <jkacur@redhat.com>

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 5/6] cyclictest: Allow symbolic clock names
  2026-04-07  6:48 ` [PATCH 5/6] cyclictest: Allow symbolic clock names Thomas Weißschuh (Schneider Electric)
@ 2026-04-15 14:48   ` John Kacur
  0 siblings, 0 replies; 18+ messages in thread
From: John Kacur @ 2026-04-15 14:48 UTC (permalink / raw)
  To: Thomas Weißschuh; +Cc: linux-rt-users

On Tue, 07 Apr 2026 at 08:48:45AM +0200, Thomas Weißschuh (Schneider Electric) wrote:
> cyclictest: Allow symbolic clock names

Applied, thanks!

Signed-off-by: John Kacur <jkacur@redhat.com>

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 6/6] cyclictest: Add support for auxiliary clocks
  2026-04-07  6:48 ` [PATCH 6/6] cyclictest: Add support for auxiliary clocks Thomas Weißschuh (Schneider Electric)
@ 2026-04-15 14:48   ` John Kacur
  0 siblings, 0 replies; 18+ messages in thread
From: John Kacur @ 2026-04-15 14:48 UTC (permalink / raw)
  To: Thomas Weißschuh; +Cc: linux-rt-users

On Tue, 07 Apr 2026 at 08:48:46AM +0200, Thomas Weißschuh (Schneider Electric) wrote:
> cyclictest: Add support for auxiliary clocks

Applied, thanks!

Signed-off-by: John Kacur <jkacur@redhat.com>

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2026-04-15 14:48 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-07  6:48 [PATCH 0/6] cyclictest: Add support for auxiliary clocks Thomas Weißschuh (Schneider Electric)
2026-04-07  6:48 ` [PATCH 1/6] cyclictest: Centralize clock option parsing Thomas Weißschuh (Schneider Electric)
2026-04-07  8:27   ` Florian Bezdeka
2026-04-07  8:45     ` Thomas Weißschuh (Schneider Electric)
2026-04-15 14:46   ` John Kacur
2026-04-07  6:48 ` [PATCH 2/6] cyclictest: Test the return value of timer_create() Thomas Weißschuh (Schneider Electric)
2026-04-15 14:47   ` John Kacur
2026-04-07  6:48 ` [PATCH 3/6] cyclictest: Fix error error returns for uclibc clock_nanosleep() fallback Thomas Weißschuh (Schneider Electric)
2026-04-07  8:16   ` Florian Bezdeka
2026-04-07  8:50     ` Thomas Weißschuh (Schneider Electric)
2026-04-07  8:59       ` Florian Bezdeka
2026-04-15 14:47   ` John Kacur
2026-04-07  6:48 ` [PATCH 4/6] cyclictest: Correctly print clock_nanosleep() errors Thomas Weißschuh (Schneider Electric)
2026-04-15 14:47   ` John Kacur
2026-04-07  6:48 ` [PATCH 5/6] cyclictest: Allow symbolic clock names Thomas Weißschuh (Schneider Electric)
2026-04-15 14:48   ` John Kacur
2026-04-07  6:48 ` [PATCH 6/6] cyclictest: Add support for auxiliary clocks Thomas Weißschuh (Schneider Electric)
2026-04-15 14:48   ` John Kacur

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox