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