mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-08-30 14:33:24 -04:00
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:
@@ -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;
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user