Kernel module to generate timers and hrtimers for the test and shell commands. Signed-off-by: Costa Shulyupin <costa.shul@xxxxxxxxxx> --- tests/timers.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 tests/timers.c diff --git a/tests/timers.c b/tests/timers.c new file mode 100644 index 0000000000000..bf6ef3244bc05 --- /dev/null +++ b/tests/timers.c @@ -0,0 +1,58 @@ +#include <linux/timer.h> +#include <linux/hrtimer.h> +#include <linux/module.h> + +/* + * Testing instructions: + * + * isolate=1 + * insmod timers.ko test_cpu=$isolate + * cd /sys/fs/cgroup/ + * echo +cpuset > cgroup.subtree_control + * mkdir test + * echo isolated > test/cpuset.cpus.partition + * echo $isolate > test/cpuset.cpus + * + * awk "/cpu:/{y=0};/cpu: $isolate\$/{y=1};/ #[0-9]/ && y;" /proc/timer_list \ + * | grep -q test_hrtimer_cb && echo FAIL || echo PASS + * + * Assure that there is no timers on the isolated cpu. + */ + +static void test_timer_cb(struct timer_list *unused) { } + +static struct timer_list test_timer; + +static struct hrtimer test_hrtimer; + +static enum hrtimer_restart test_hrtimer_cb(struct hrtimer *hr_timer) +{ + return HRTIMER_NORESTART; +} + +static int test_cpu = 1; +module_param(test_cpu, int, 0444); + +static int timers_init(void) +{ + set_cpus_allowed_ptr(current, cpumask_of(test_cpu)); + timer_setup(&test_timer, test_timer_cb, TIMER_PINNED); + test_timer.expires = KTIME_MAX; + add_timer(&test_timer); + + hrtimer_init(&test_hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); + test_hrtimer.function = test_hrtimer_cb; + hrtimer_start(&test_hrtimer, -1, HRTIMER_MODE_REL); + return 0; +} + +static void timers_exit(void) +{ + del_timer(&test_timer); + hrtimer_cancel(&test_hrtimer); +} + +module_init(timers_init); +module_exit(timers_exit); + +MODULE_LICENSE("GPL"); -- 2.45.0