1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 3 * Copyright (c) 2016 Cyril Hrubis <[email protected]> 4 */ 5 6 /** 7 * DOC: Checkpoints introduction 8 * 9 * Checkpoints implements a futex based synchronization primitive for threads 10 * and processes. When a process calls wait function its execution is suspended 11 * until wake is called for a corresponding checkpoint. Checkpoints are 12 * numbered from 0 and process can use at least hundred of them. 13 * 14 * In order to use checkpoints the test must set the tst_test.needs_checkpoints 15 * flag. 16 */ 17 18 #ifndef TST_CHECKPOINT__ 19 #define TST_CHECKPOINT__ 20 21 #include "tst_checkpoint_fn.h" 22 23 /** 24 * TST_CHECKPOINT_WAIT() - Waits for a checkpoint. 25 * 26 * @id: A checkpoint id a positive integer. 27 * 28 * Suspends thread/process execution until it's woken up with a wake. The call 29 * does not wait indefinitely it gives up after 10 seconds. If an error 30 * happened or timeout was reached the function calls tst_brk(TBROK, ...) which 31 * exits the test. 32 */ 33 #define TST_CHECKPOINT_WAIT(id) \ 34 tst_safe_checkpoint_wait(__FILE__, __LINE__, NULL, id, 0) 35 36 /** 37 * TST_CHECKPOINT_WAIT2() - Waits for a checkpoint. 38 * 39 * @id: A checkpoint id a positive integer. 40 * @msec_timeout: A timeout. 41 * 42 * Suspends thread/process execution until it's woken up with a wake. If an 43 * error happened or timeout was reached the function calls tst_brk(TBROK, ...) 44 * which exits the test. 45 */ 46 #define TST_CHECKPOINT_WAIT2(id, msec_timeout) \ 47 tst_safe_checkpoint_wait(__FILE__, __LINE__, NULL, id, msec_timeout) 48 49 /** 50 * TST_CHECKPOINT_WAKE() - Wakes up a checkpoint. 51 * 52 * @id: A checkpoint id a positive integer. 53 * 54 * Wakes up a process suspended on a checkpoint and retries if there is no 55 * process suspended on the checkpoint yet. The call does not retry 56 * indefinitely but gives up after 10 seconds. If an error happened or timeout 57 * was reached the function calls tst_brk(TBROK, ...) which exits the test. 58 */ 59 #define TST_CHECKPOINT_WAKE(id) \ 60 tst_safe_checkpoint_wake(__FILE__, __LINE__, NULL, id, 1) 61 62 /** 63 * TST_CHECKPOINT_WAKE2() - Wakes up several checkpoints. 64 * 65 * @id: A checkpoint id a positive integer. 66 * @nr_wake: A number of processes to wake. 67 * 68 * Wakes up nr_wake processes suspended on a checkpoint and retries if there 69 * wasn't enough process suspended on the checkpoint yet. The call does not 70 * retry indefinitely but gives up if it does not wake nr_wake processes after 71 * 10 seconds. If an error happened or timeout was reached the function calls 72 * tst_brk(TBROK, ...) which exits the test. 73 */ 74 #define TST_CHECKPOINT_WAKE2(id, nr_wake) \ 75 tst_safe_checkpoint_wake(__FILE__, __LINE__, NULL, id, nr_wake) 76 77 /** 78 * TST_CHECKPOINT_WAKE_AND_WAIT() - Wakes up a checkpoint and immediately waits on it. 79 * 80 * @id: A checkpoint id a positive integer. 81 * 82 * This is a combination of TST_CHECKPOINT_WAKE() and TST_CHECKPOINT_WAIT(). 83 */ 84 #define TST_CHECKPOINT_WAKE_AND_WAIT(id) do { \ 85 tst_safe_checkpoint_wake(__FILE__, __LINE__, NULL, id, 1); \ 86 tst_safe_checkpoint_wait(__FILE__, __LINE__, NULL, id, 0); \ 87 } while (0) 88 89 extern const char *tst_ipc_path; 90 91 #endif /* TST_CHECKPOINT__ */ 92