perf tests workloads: Support sub-second durations in noploop and thloop

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.

Assisted-by: Antigravity:gemini-3.1-pro
Signed-off-by: Ian Rogers <irogers@google.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
This commit is contained in:
Ian Rogers
2026-06-22 18:27:48 -07:00
committed by Namhyung Kim
parent 32e6312f7e
commit 810d0c9117
2 changed files with 25 additions and 8 deletions

View File

@@ -15,15 +15,26 @@ 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) {
useconds_t usecs = (useconds_t)(sec * 1000000.0);
ualarm(usecs > 0 ? usecs : 1, 0);
} else
alarm((unsigned int)sec);
while (!done)
continue;

View File

@@ -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,12 @@ static int thloop(int argc, const char **argv)
goto out;
}
}
alarm(sec);
if (sec < 1.0) {
useconds_t usecs = (useconds_t)(sec * 1000000.0);
ualarm(usecs > 0 ? usecs : 1, 0);
} else
alarm((unsigned int)sec);
test_loop();
err = 0;
out: