[PATCH v1 03/12] perf tests workloads: Support sub-second durations in noploop and thloop

From: Ian Rogers

Date: Mon Jun 15 2026 - 21:28:21 EST


Currently, the noploop and thloop workloads only support sleep durations
in integer seconds because they parse the argument using atoi() and use
alarm() for timer signaling.

To support much shorter execution times in tests (speeding up test suites
and allowing faster retries), change the input parsing to use atof() for
double floating-point seconds. Use ualarm() for fractional durations less
than 1.0 seconds, and fall back to alarm() for durations of 1.0 second or more.

Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
---
tools/perf/tests/workloads/noploop.c | 15 ++++++++++++---
tools/perf/tests/workloads/thloop.c | 14 +++++++++-----
2 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/tools/perf/tests/workloads/noploop.c b/tools/perf/tests/workloads/noploop.c
index 656e472e6188..3fcba5ceaa3d 100644
--- a/tools/perf/tests/workloads/noploop.c
+++ b/tools/perf/tests/workloads/noploop.c
@@ -15,15 +15,24 @@ static void sighandler(int sig __maybe_unused)

static int noploop(int argc, const char **argv)
{
- int sec = 1;
+ double sec = 1.0;

pthread_setname_np(pthread_self(), "perf-noploop");
if (argc > 0)
- sec = atoi(argv[0]);
+ sec = atof(argv[0]);
+
+ if (sec <= 0.0) {
+ fprintf(stderr, "Error: seconds (%f) must be > 0\n", sec);
+ return 1;
+ }

signal(SIGINT, sighandler);
signal(SIGALRM, sighandler);
- alarm(sec);
+
+ if (sec < 1.0)
+ ualarm((useconds_t)(sec * 1000000.0), 0);
+ else
+ alarm((unsigned int)sec);

while (!done)
continue;
diff --git a/tools/perf/tests/workloads/thloop.c b/tools/perf/tests/workloads/thloop.c
index bd8168f883fb..bed3047fe9c2 100644
--- a/tools/perf/tests/workloads/thloop.c
+++ b/tools/perf/tests/workloads/thloop.c
@@ -31,14 +31,15 @@ static void *thfunc(void *arg)

static int thloop(int argc, const char **argv)
{
- int nt = 2, sec = 1, err = 1;
+ int nt = 2, err = 1;
+ double sec = 1.0;
pthread_t *thread_list = NULL;

if (argc > 0)
- sec = atoi(argv[0]);
+ sec = atof(argv[0]);

- if (sec <= 0) {
- fprintf(stderr, "Error: seconds (%d) must be >= 1\n", sec);
+ if (sec <= 0.0) {
+ fprintf(stderr, "Error: seconds (%f) must be > 0\n", sec);
return 1;
}

@@ -67,7 +68,10 @@ static int thloop(int argc, const char **argv)
goto out;
}
}
- alarm(sec);
+ if (sec < 1.0)
+ ualarm((useconds_t)(sec * 1000000.0), 0);
+ else
+ alarm((unsigned int)sec);
test_loop();
err = 0;
out:
--
2.54.0.1136.gdb2ca164c4-goog