1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * Copyright (C) 2013 Red Hat, Inc., Frederic Weisbecker <fweisbec@redhat.com> 4 * 5 * Selftests for a few posix timers interface. 6 * 7 * Kernel loop code stolen from Steven Rostedt <srostedt@redhat.com> 8 */ 9 #define _GNU_SOURCE 10 #include <sys/prctl.h> 11 #include <sys/time.h> 12 #include <sys/types.h> 13 #include <stdio.h> 14 #include <signal.h> 15 #include <stdint.h> 16 #include <string.h> 17 #include <unistd.h> 18 #include <time.h> 19 #include <include/vdso/time64.h> 20 #include <pthread.h> 21 #include <stdbool.h> 22 23 #include "kselftest.h" 24 25 #define DELAY 2 26 27 static void __fatal_error(const char *test, const char *name, const char *what) 28 { 29 char buf[64]; 30 char *ret_str = NULL; 31 32 ret_str = strerror_r(errno, buf, sizeof(buf)); 33 34 if (name && strlen(name) && ret_str) 35 ksft_exit_fail_msg("%s %s %s %s\n", test, name, what, ret_str); 36 else if (ret_str) 37 ksft_exit_fail_msg("%s %s %s\n", test, what, ret_str); 38 else 39 ksft_exit_fail_msg("%s %s\n", test, what); 40 41 } 42 43 #define fatal_error(name, what) __fatal_error(__func__, name, what) 44 45 static volatile int done; 46 47 /* Busy loop in userspace to elapse ITIMER_VIRTUAL */ 48 static void user_loop(void) 49 { 50 while (!done); 51 } 52 53 /* 54 * Try to spend as much time as possible in kernelspace 55 * to elapse ITIMER_PROF. 56 */ 57 static void kernel_loop(void) 58 { 59 void *addr = sbrk(0); 60 int err = 0; 61 62 while (!done && !err) { 63 err = brk(addr + 4096); 64 err |= brk(addr); 65 } 66 } 67 68 /* 69 * Sleep until ITIMER_REAL expiration. 70 */ 71 static void idle_loop(void) 72 { 73 pause(); 74 } 75 76 static void sig_handler(int nr) 77 { 78 done = 1; 79 } 80 81 static inline int64_t calcdiff_ns(struct timespec t1, struct timespec t2) 82 { 83 int64_t diff; 84 85 diff = NSEC_PER_SEC * (int64_t)((int) t1.tv_sec - (int) t2.tv_sec); 86 diff += ((int) t1.tv_nsec - (int) t2.tv_nsec); 87 return diff; 88 } 89 90 /* 91 * Check the expected timer expiration matches the GTOD elapsed delta since 92 * we armed the timer. Keep a 0.5 sec error margin due to various jitter. 93 */ 94 static int check_diff(struct timespec start, struct timespec end) 95 { 96 long long diff = calcdiff_ns(end, start); 97 98 if (llabs(diff - DELAY * NSEC_PER_SEC) > NSEC_PER_SEC / 2) { 99 printf("Diff too high: %lld ns..", diff); 100 return -1; 101 } 102 103 return 0; 104 } 105 106 static void check_itimer(int which, const char *name) 107 { 108 struct timespec start, end; 109 struct itimerval val = { 110 .it_value.tv_sec = DELAY, 111 }; 112 int clock_id = CLOCK_REALTIME; 113 114 done = 0; 115 116 if (which == ITIMER_VIRTUAL) 117 signal(SIGVTALRM, sig_handler); 118 else if (which == ITIMER_PROF) { 119 clock_id = CLOCK_THREAD_CPUTIME_ID; 120 signal(SIGPROF, sig_handler); 121 } 122 else if (which == ITIMER_REAL) 123 signal(SIGALRM, sig_handler); 124 125 if (clock_gettime(clock_id, &start)) 126 fatal_error(name, "clock_gettime()"); 127 128 if (setitimer(which, &val, NULL) < 0) 129 fatal_error(name, "setitimer()"); 130 131 if (which == ITIMER_VIRTUAL) 132 user_loop(); 133 else if (which == ITIMER_PROF) 134 kernel_loop(); 135 else if (which == ITIMER_REAL) 136 idle_loop(); 137 138 if (clock_gettime(clock_id, &end)) 139 fatal_error(name, "clock_gettime()"); 140 141 ksft_test_result(check_diff(start, end) == 0, "%s\n", name); 142 } 143 144 static void check_timer_create(int which, const char *name) 145 { 146 struct timespec start, end; 147 struct itimerspec val = { 148 .it_value.tv_sec = DELAY, 149 }; 150 int clock_id = CLOCK_REALTIME; 151 timer_t id; 152 153 done = 0; 154 155 if (timer_create(which, NULL, &id) < 0) 156 fatal_error(name, "timer_create()"); 157 158 if (signal(SIGALRM, sig_handler) == SIG_ERR) 159 fatal_error(name, "signal()"); 160 161 if (clock_gettime(clock_id, &start)) 162 fatal_error(name, "clock_gettime()"); 163 164 if (timer_settime(id, 0, &val, NULL) < 0) 165 fatal_error(name, "timer_settime()"); 166 167 user_loop(); 168 169 if (clock_gettime(clock_id, &end)) 170 fatal_error(name, "clock_gettime()"); 171 172 ksft_test_result(check_diff(start, end) == 0, 173 "timer_create() per %s\n", name); 174 } 175 176 static pthread_t ctd_thread; 177 static volatile int ctd_count, ctd_failed; 178 179 static void ctd_sighandler(int sig) 180 { 181 if (pthread_self() != ctd_thread) 182 ctd_failed = 1; 183 ctd_count--; 184 } 185 186 static void *ctd_thread_func(void *arg) 187 { 188 struct itimerspec val = { 189 .it_value.tv_sec = 0, 190 .it_value.tv_nsec = 1000 * 1000, 191 .it_interval.tv_sec = 0, 192 .it_interval.tv_nsec = 1000 * 1000, 193 }; 194 timer_t id; 195 196 /* 1/10 seconds to ensure the leader sleeps */ 197 usleep(10000); 198 199 ctd_count = 100; 200 if (timer_create(CLOCK_PROCESS_CPUTIME_ID, NULL, &id)) 201 fatal_error(NULL, "timer_create()"); 202 if (timer_settime(id, 0, &val, NULL)) 203 fatal_error(NULL, "timer_settime()"); 204 while (ctd_count > 0 && !ctd_failed) 205 ; 206 207 if (timer_delete(id)) 208 fatal_error(NULL, "timer_delete()"); 209 210 return NULL; 211 } 212 213 /* 214 * Test that only the running thread receives the timer signal. 215 */ 216 static void check_timer_distribution(void) 217 { 218 if (signal(SIGALRM, ctd_sighandler) == SIG_ERR) 219 fatal_error(NULL, "signal()"); 220 221 if (pthread_create(&ctd_thread, NULL, ctd_thread_func, NULL)) 222 fatal_error(NULL, "pthread_create()"); 223 224 if (pthread_join(ctd_thread, NULL)) 225 fatal_error(NULL, "pthread_join()"); 226 227 if (!ctd_failed) 228 ksft_test_result_pass("check signal distribution\n"); 229 else if (ksft_min_kernel_version(6, 3)) 230 ksft_test_result_fail("check signal distribution\n"); 231 else 232 ksft_test_result_skip("check signal distribution (old kernel)\n"); 233 } 234 235 struct tmrsig { 236 int signals; 237 int overruns; 238 }; 239 240 static void siginfo_handler(int sig, siginfo_t *si, void *uc) 241 { 242 struct tmrsig *tsig = si ? si->si_ptr : NULL; 243 244 if (tsig) { 245 tsig->signals++; 246 tsig->overruns += si->si_overrun; 247 } 248 } 249 250 static void *ignore_thread(void *arg) 251 { 252 unsigned int *tid = arg; 253 sigset_t set; 254 255 sigemptyset(&set); 256 sigaddset(&set, SIGUSR1); 257 if (sigprocmask(SIG_BLOCK, &set, NULL)) 258 fatal_error(NULL, "sigprocmask(SIG_BLOCK)"); 259 260 *tid = gettid(); 261 sleep(100); 262 263 if (sigprocmask(SIG_UNBLOCK, &set, NULL)) 264 fatal_error(NULL, "sigprocmask(SIG_UNBLOCK)"); 265 return NULL; 266 } 267 268 static void check_sig_ign(int thread) 269 { 270 struct tmrsig tsig = { }; 271 struct itimerspec its; 272 unsigned int tid = 0; 273 struct sigaction sa; 274 struct sigevent sev; 275 pthread_t pthread; 276 timer_t timerid; 277 sigset_t set; 278 279 if (thread) { 280 if (pthread_create(&pthread, NULL, ignore_thread, &tid)) 281 fatal_error(NULL, "pthread_create()"); 282 sleep(1); 283 } 284 285 sa.sa_flags = SA_SIGINFO; 286 sa.sa_sigaction = siginfo_handler; 287 sigemptyset(&sa.sa_mask); 288 if (sigaction(SIGUSR1, &sa, NULL)) 289 fatal_error(NULL, "sigaction()"); 290 291 /* Block the signal */ 292 sigemptyset(&set); 293 sigaddset(&set, SIGUSR1); 294 if (sigprocmask(SIG_BLOCK, &set, NULL)) 295 fatal_error(NULL, "sigprocmask(SIG_BLOCK)"); 296 297 memset(&sev, 0, sizeof(sev)); 298 sev.sigev_notify = SIGEV_SIGNAL; 299 sev.sigev_signo = SIGUSR1; 300 sev.sigev_value.sival_ptr = &tsig; 301 if (thread) { 302 sev.sigev_notify = SIGEV_THREAD_ID; 303 sev._sigev_un._tid = tid; 304 } 305 306 if (timer_create(CLOCK_MONOTONIC, &sev, &timerid)) 307 fatal_error(NULL, "timer_create()"); 308 309 /* Start the timer to expire in 100ms and 100ms intervals */ 310 its.it_value.tv_sec = 0; 311 its.it_value.tv_nsec = 100000000; 312 its.it_interval.tv_sec = 0; 313 its.it_interval.tv_nsec = 100000000; 314 timer_settime(timerid, 0, &its, NULL); 315 316 sleep(1); 317 318 /* Set the signal to be ignored */ 319 if (signal(SIGUSR1, SIG_IGN) == SIG_ERR) 320 fatal_error(NULL, "signal(SIG_IGN)"); 321 322 sleep(1); 323 324 if (thread) { 325 /* Stop the thread first. No signal should be delivered to it */ 326 if (pthread_cancel(pthread)) 327 fatal_error(NULL, "pthread_cancel()"); 328 if (pthread_join(pthread, NULL)) 329 fatal_error(NULL, "pthread_join()"); 330 } 331 332 /* Restore the handler */ 333 if (sigaction(SIGUSR1, &sa, NULL)) 334 fatal_error(NULL, "sigaction()"); 335 336 sleep(1); 337 338 /* Unblock it, which should deliver the signal in the !thread case*/ 339 if (sigprocmask(SIG_UNBLOCK, &set, NULL)) 340 fatal_error(NULL, "sigprocmask(SIG_UNBLOCK)"); 341 342 if (timer_delete(timerid)) 343 fatal_error(NULL, "timer_delete()"); 344 345 if (!thread) { 346 ksft_test_result(tsig.signals == 1 && tsig.overruns == 29, 347 "check_sig_ign SIGEV_SIGNAL\n"); 348 } else { 349 ksft_test_result(tsig.signals == 0 && tsig.overruns == 0, 350 "check_sig_ign SIGEV_THREAD_ID\n"); 351 } 352 } 353 354 static void check_rearm(void) 355 { 356 struct tmrsig tsig = { }; 357 struct itimerspec its; 358 struct sigaction sa; 359 struct sigevent sev; 360 timer_t timerid; 361 sigset_t set; 362 363 sa.sa_flags = SA_SIGINFO; 364 sa.sa_sigaction = siginfo_handler; 365 sigemptyset(&sa.sa_mask); 366 if (sigaction(SIGUSR1, &sa, NULL)) 367 fatal_error(NULL, "sigaction()"); 368 369 /* Block the signal */ 370 sigemptyset(&set); 371 sigaddset(&set, SIGUSR1); 372 if (sigprocmask(SIG_BLOCK, &set, NULL)) 373 fatal_error(NULL, "sigprocmask(SIG_BLOCK)"); 374 375 memset(&sev, 0, sizeof(sev)); 376 sev.sigev_notify = SIGEV_SIGNAL; 377 sev.sigev_signo = SIGUSR1; 378 sev.sigev_value.sival_ptr = &tsig; 379 if (timer_create(CLOCK_MONOTONIC, &sev, &timerid)) 380 fatal_error(NULL, "timer_create()"); 381 382 /* Start the timer to expire in 100ms and 100ms intervals */ 383 its.it_value.tv_sec = 0; 384 its.it_value.tv_nsec = 100000000; 385 its.it_interval.tv_sec = 0; 386 its.it_interval.tv_nsec = 100000000; 387 if (timer_settime(timerid, 0, &its, NULL)) 388 fatal_error(NULL, "timer_settime()"); 389 390 sleep(1); 391 392 /* Reprogram the timer to single shot */ 393 its.it_value.tv_sec = 10; 394 its.it_value.tv_nsec = 0; 395 its.it_interval.tv_sec = 0; 396 its.it_interval.tv_nsec = 0; 397 if (timer_settime(timerid, 0, &its, NULL)) 398 fatal_error(NULL, "timer_settime()"); 399 400 /* Unblock it, which should not deliver a signal */ 401 if (sigprocmask(SIG_UNBLOCK, &set, NULL)) 402 fatal_error(NULL, "sigprocmask(SIG_UNBLOCK)"); 403 404 if (timer_delete(timerid)) 405 fatal_error(NULL, "timer_delete()"); 406 407 ksft_test_result(!tsig.signals, "check_rearm\n"); 408 } 409 410 static void check_delete(void) 411 { 412 struct tmrsig tsig = { }; 413 struct itimerspec its; 414 struct sigaction sa; 415 struct sigevent sev; 416 timer_t timerid; 417 sigset_t set; 418 419 sa.sa_flags = SA_SIGINFO; 420 sa.sa_sigaction = siginfo_handler; 421 sigemptyset(&sa.sa_mask); 422 if (sigaction(SIGUSR1, &sa, NULL)) 423 fatal_error(NULL, "sigaction()"); 424 425 /* Block the signal */ 426 sigemptyset(&set); 427 sigaddset(&set, SIGUSR1); 428 if (sigprocmask(SIG_BLOCK, &set, NULL)) 429 fatal_error(NULL, "sigprocmask(SIG_BLOCK)"); 430 431 memset(&sev, 0, sizeof(sev)); 432 sev.sigev_notify = SIGEV_SIGNAL; 433 sev.sigev_signo = SIGUSR1; 434 sev.sigev_value.sival_ptr = &tsig; 435 if (timer_create(CLOCK_MONOTONIC, &sev, &timerid)) 436 fatal_error(NULL, "timer_create()"); 437 438 /* Start the timer to expire in 100ms and 100ms intervals */ 439 its.it_value.tv_sec = 0; 440 its.it_value.tv_nsec = 100000000; 441 its.it_interval.tv_sec = 0; 442 its.it_interval.tv_nsec = 100000000; 443 if (timer_settime(timerid, 0, &its, NULL)) 444 fatal_error(NULL, "timer_settime()"); 445 446 sleep(1); 447 448 if (timer_delete(timerid)) 449 fatal_error(NULL, "timer_delete()"); 450 451 /* Unblock it, which should not deliver a signal */ 452 if (sigprocmask(SIG_UNBLOCK, &set, NULL)) 453 fatal_error(NULL, "sigprocmask(SIG_UNBLOCK)"); 454 455 ksft_test_result(!tsig.signals, "check_delete\n"); 456 } 457 458 static void check_sigev_none(int which, const char *name) 459 { 460 struct timespec start, now; 461 struct itimerspec its; 462 struct sigevent sev; 463 timer_t timerid; 464 465 memset(&sev, 0, sizeof(sev)); 466 sev.sigev_notify = SIGEV_NONE; 467 468 if (timer_create(which, &sev, &timerid)) 469 fatal_error(name, "timer_create()"); 470 471 /* Start the timer to expire in 100ms and 100ms intervals */ 472 its.it_value.tv_sec = 0; 473 its.it_value.tv_nsec = 100000000; 474 its.it_interval.tv_sec = 0; 475 its.it_interval.tv_nsec = 100000000; 476 timer_settime(timerid, 0, &its, NULL); 477 478 if (clock_gettime(which, &start)) 479 fatal_error(name, "clock_gettime()"); 480 481 do { 482 if (clock_gettime(which, &now)) 483 fatal_error(name, "clock_gettime()"); 484 } while (calcdiff_ns(now, start) < NSEC_PER_SEC); 485 486 if (timer_gettime(timerid, &its)) 487 fatal_error(name, "timer_gettime()"); 488 489 if (timer_delete(timerid)) 490 fatal_error(name, "timer_delete()"); 491 492 ksft_test_result(its.it_value.tv_sec || its.it_value.tv_nsec, 493 "check_sigev_none %s\n", name); 494 } 495 496 static void check_gettime(int which, const char *name) 497 { 498 struct itimerspec its, prev; 499 struct timespec start, now; 500 struct sigevent sev; 501 timer_t timerid; 502 int wraps = 0; 503 sigset_t set; 504 505 /* Block the signal */ 506 sigemptyset(&set); 507 sigaddset(&set, SIGUSR1); 508 if (sigprocmask(SIG_BLOCK, &set, NULL)) 509 fatal_error(name, "sigprocmask(SIG_BLOCK)"); 510 511 memset(&sev, 0, sizeof(sev)); 512 sev.sigev_notify = SIGEV_SIGNAL; 513 sev.sigev_signo = SIGUSR1; 514 515 if (timer_create(which, &sev, &timerid)) 516 fatal_error(name, "timer_create()"); 517 518 /* Start the timer to expire in 100ms and 100ms intervals */ 519 its.it_value.tv_sec = 0; 520 its.it_value.tv_nsec = 100000000; 521 its.it_interval.tv_sec = 0; 522 its.it_interval.tv_nsec = 100000000; 523 if (timer_settime(timerid, 0, &its, NULL)) 524 fatal_error(name, "timer_settime()"); 525 526 if (timer_gettime(timerid, &prev)) 527 fatal_error(name, "timer_gettime()"); 528 529 if (clock_gettime(which, &start)) 530 fatal_error(name, "clock_gettime()"); 531 532 do { 533 if (clock_gettime(which, &now)) 534 fatal_error(name, "clock_gettime()"); 535 if (timer_gettime(timerid, &its)) 536 fatal_error(name, "timer_gettime()"); 537 if (its.it_value.tv_nsec > prev.it_value.tv_nsec) 538 wraps++; 539 prev = its; 540 541 } while (calcdiff_ns(now, start) < NSEC_PER_SEC); 542 543 if (timer_delete(timerid)) 544 fatal_error(name, "timer_delete()"); 545 546 ksft_test_result(wraps > 1, "check_gettime %s\n", name); 547 } 548 549 static void check_overrun(int which, const char *name) 550 { 551 struct timespec start, now; 552 struct tmrsig tsig = { }; 553 struct itimerspec its; 554 struct sigaction sa; 555 struct sigevent sev; 556 timer_t timerid; 557 sigset_t set; 558 559 sa.sa_flags = SA_SIGINFO; 560 sa.sa_sigaction = siginfo_handler; 561 sigemptyset(&sa.sa_mask); 562 if (sigaction(SIGUSR1, &sa, NULL)) 563 fatal_error(name, "sigaction()"); 564 565 /* Block the signal */ 566 sigemptyset(&set); 567 sigaddset(&set, SIGUSR1); 568 if (sigprocmask(SIG_BLOCK, &set, NULL)) 569 fatal_error(name, "sigprocmask(SIG_BLOCK)"); 570 571 memset(&sev, 0, sizeof(sev)); 572 sev.sigev_notify = SIGEV_SIGNAL; 573 sev.sigev_signo = SIGUSR1; 574 sev.sigev_value.sival_ptr = &tsig; 575 if (timer_create(which, &sev, &timerid)) 576 fatal_error(name, "timer_create()"); 577 578 /* Start the timer to expire in 100ms and 100ms intervals */ 579 its.it_value.tv_sec = 0; 580 its.it_value.tv_nsec = 100000000; 581 its.it_interval.tv_sec = 0; 582 its.it_interval.tv_nsec = 100000000; 583 if (timer_settime(timerid, 0, &its, NULL)) 584 fatal_error(name, "timer_settime()"); 585 586 if (clock_gettime(which, &start)) 587 fatal_error(name, "clock_gettime()"); 588 589 do { 590 if (clock_gettime(which, &now)) 591 fatal_error(name, "clock_gettime()"); 592 } while (calcdiff_ns(now, start) < NSEC_PER_SEC); 593 594 /* Unblock it, which should deliver a signal */ 595 if (sigprocmask(SIG_UNBLOCK, &set, NULL)) 596 fatal_error(name, "sigprocmask(SIG_UNBLOCK)"); 597 598 if (timer_delete(timerid)) 599 fatal_error(name, "timer_delete()"); 600 601 ksft_test_result(tsig.signals == 1 && tsig.overruns == 9, 602 "check_overrun %s\n", name); 603 } 604 605 #include <sys/syscall.h> 606 607 static int do_timer_create(int *id) 608 { 609 return syscall(__NR_timer_create, CLOCK_MONOTONIC, NULL, id); 610 } 611 612 static int do_timer_delete(int id) 613 { 614 return syscall(__NR_timer_delete, id); 615 } 616 617 #ifndef PR_TIMER_CREATE_RESTORE_IDS 618 # define PR_TIMER_CREATE_RESTORE_IDS 77 619 # define PR_TIMER_CREATE_RESTORE_IDS_OFF 0 620 # define PR_TIMER_CREATE_RESTORE_IDS_ON 1 621 # define PR_TIMER_CREATE_RESTORE_IDS_GET 2 622 #endif 623 624 static void check_timer_create_exact(void) 625 { 626 int id; 627 628 if (prctl(PR_TIMER_CREATE_RESTORE_IDS, PR_TIMER_CREATE_RESTORE_IDS_ON, 0, 0, 0)) { 629 switch (errno) { 630 case EINVAL: 631 ksft_test_result_skip("check timer create exact, not supported\n"); 632 return; 633 default: 634 ksft_test_result_skip("check timer create exact, errno = %d\n", errno); 635 return; 636 } 637 } 638 639 if (prctl(PR_TIMER_CREATE_RESTORE_IDS, PR_TIMER_CREATE_RESTORE_IDS_GET, 0, 0, 0) != 1) 640 fatal_error(NULL, "prctl(GET) failed\n"); 641 642 id = 8; 643 if (do_timer_create(&id) < 0) 644 fatal_error(NULL, "timer_create()"); 645 646 if (do_timer_delete(id)) 647 fatal_error(NULL, "timer_delete()"); 648 649 if (prctl(PR_TIMER_CREATE_RESTORE_IDS, PR_TIMER_CREATE_RESTORE_IDS_OFF, 0, 0, 0)) 650 fatal_error(NULL, "prctl(OFF)"); 651 652 if (prctl(PR_TIMER_CREATE_RESTORE_IDS, PR_TIMER_CREATE_RESTORE_IDS_GET, 0, 0, 0) != 0) 653 fatal_error(NULL, "prctl(GET) failed\n"); 654 655 if (id != 8) { 656 ksft_test_result_fail("check timer create exact %d != 8\n", id); 657 return; 658 } 659 660 /* Validate that it went back to normal mode and allocates ID 9 */ 661 if (do_timer_create(&id) < 0) 662 fatal_error(NULL, "timer_create()"); 663 664 if (do_timer_delete(id)) 665 fatal_error(NULL, "timer_delete()"); 666 667 if (id == 9) 668 ksft_test_result_pass("check timer create exact\n"); 669 else 670 ksft_test_result_fail("check timer create exact. Disabling failed.\n"); 671 } 672 673 int main(int argc, char **argv) 674 { 675 bool run_sig_ign_tests = ksft_min_kernel_version(6, 13); 676 677 ksft_print_header(); 678 if (run_sig_ign_tests) { 679 ksft_set_plan(19); 680 } else { 681 ksft_set_plan(10); 682 } 683 684 ksft_print_msg("Testing posix timers. False negative may happen on CPU execution \n"); 685 ksft_print_msg("based timers if other threads run on the CPU...\n"); 686 687 check_timer_create_exact(); 688 689 check_itimer(ITIMER_VIRTUAL, "ITIMER_VIRTUAL"); 690 check_itimer(ITIMER_PROF, "ITIMER_PROF"); 691 check_itimer(ITIMER_REAL, "ITIMER_REAL"); 692 check_timer_create(CLOCK_THREAD_CPUTIME_ID, "CLOCK_THREAD_CPUTIME_ID"); 693 694 /* 695 * It's unfortunately hard to reliably test a timer expiration 696 * on parallel multithread cputime. We could arm it to expire 697 * on DELAY * nr_threads, with nr_threads busy looping, then wait 698 * the normal DELAY since the time is elapsing nr_threads faster. 699 * But for that we need to ensure we have real physical free CPUs 700 * to ensure true parallelism. So test only one thread until we 701 * find a better solution. 702 */ 703 check_timer_create(CLOCK_PROCESS_CPUTIME_ID, "CLOCK_PROCESS_CPUTIME_ID"); 704 check_timer_distribution(); 705 706 if (run_sig_ign_tests) { 707 check_sig_ign(0); 708 check_sig_ign(1); 709 check_rearm(); 710 check_delete(); 711 check_sigev_none(CLOCK_MONOTONIC, "CLOCK_MONOTONIC"); 712 check_sigev_none(CLOCK_PROCESS_CPUTIME_ID, "CLOCK_PROCESS_CPUTIME_ID"); 713 check_gettime(CLOCK_MONOTONIC, "CLOCK_MONOTONIC"); 714 check_gettime(CLOCK_PROCESS_CPUTIME_ID, "CLOCK_PROCESS_CPUTIME_ID"); 715 check_gettime(CLOCK_THREAD_CPUTIME_ID, "CLOCK_THREAD_CPUTIME_ID"); 716 } else { 717 ksft_print_msg("Skipping SIG_IGN tests on kernel < 6.13\n"); 718 } 719 720 check_overrun(CLOCK_MONOTONIC, "CLOCK_MONOTONIC"); 721 check_overrun(CLOCK_PROCESS_CPUTIME_ID, "CLOCK_PROCESS_CPUTIME_ID"); 722 check_overrun(CLOCK_THREAD_CPUTIME_ID, "CLOCK_THREAD_CPUTIME_ID"); 723 724 ksft_finished(); 725 } 726