Linux Audio

Check our new training course

Loading...
v6.8
 1// SPDX-License-Identifier: GPL-2.0
 2// Copyright (C) 2018 Joe Lawrence <joe.lawrence@redhat.com>
 3
 4#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 5
 6#include <linux/module.h>
 7#include <linux/kernel.h>
 8#include <linux/sched.h>
 9#include <linux/workqueue.h>
10#include <linux/delay.h>
11
12/* load/run-time control from sysfs writer  */
13static bool block_transition;
14module_param(block_transition, bool, 0644);
15MODULE_PARM_DESC(block_transition, "block_transition (default=false)");
16
17static void busymod_work_func(struct work_struct *work);
18static DECLARE_WORK(work, busymod_work_func);
19static DECLARE_COMPLETION(busymod_work_started);
20
21static void busymod_work_func(struct work_struct *work)
22{
23	pr_info("%s enter\n", __func__);
24	complete(&busymod_work_started);
25
26	while (READ_ONCE(block_transition)) {
27		/*
28		 * Busy-wait until the sysfs writer has acknowledged a
29		 * blocked transition and clears the flag.
30		 */
31		msleep(20);
32	}
33
34	pr_info("%s exit\n", __func__);
35}
36
37static int test_klp_callbacks_busy_init(void)
38{
39	pr_info("%s\n", __func__);
40	schedule_work(&work);
41
42	/*
43	 * To synchronize kernel messages, hold the init function from
44	 * exiting until the work function's entry message has printed.
45	 */
46	wait_for_completion(&busymod_work_started);
47
48	if (!block_transition) {
49		/*
50		 * Serialize output: print all messages from the work
51		 * function before returning from init().
52		 */
53		flush_work(&work);
54	}
55
56	return 0;
57}
58
59static void test_klp_callbacks_busy_exit(void)
60{
61	WRITE_ONCE(block_transition, false);
62	flush_work(&work);
63	pr_info("%s\n", __func__);
64}
65
66module_init(test_klp_callbacks_busy_init);
67module_exit(test_klp_callbacks_busy_exit);
68MODULE_LICENSE("GPL");
69MODULE_AUTHOR("Joe Lawrence <joe.lawrence@redhat.com>");
70MODULE_DESCRIPTION("Livepatch test: busy target module");
v5.4
 1// SPDX-License-Identifier: GPL-2.0
 2// Copyright (C) 2018 Joe Lawrence <joe.lawrence@redhat.com>
 3
 4#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 5
 6#include <linux/module.h>
 7#include <linux/kernel.h>
 
 8#include <linux/workqueue.h>
 9#include <linux/delay.h>
10
11static int sleep_secs;
12module_param(sleep_secs, int, 0644);
13MODULE_PARM_DESC(sleep_secs, "sleep_secs (default=0)");
 
14
15static void busymod_work_func(struct work_struct *work);
16static DECLARE_DELAYED_WORK(work, busymod_work_func);
 
17
18static void busymod_work_func(struct work_struct *work)
19{
20	pr_info("%s, sleeping %d seconds ...\n", __func__, sleep_secs);
21	msleep(sleep_secs * 1000);
 
 
 
 
 
 
 
 
 
22	pr_info("%s exit\n", __func__);
23}
24
25static int test_klp_callbacks_busy_init(void)
26{
27	pr_info("%s\n", __func__);
28	schedule_delayed_work(&work,
29		msecs_to_jiffies(1000 * 0));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30	return 0;
31}
32
33static void test_klp_callbacks_busy_exit(void)
34{
35	cancel_delayed_work_sync(&work);
 
36	pr_info("%s\n", __func__);
37}
38
39module_init(test_klp_callbacks_busy_init);
40module_exit(test_klp_callbacks_busy_exit);
41MODULE_LICENSE("GPL");
42MODULE_AUTHOR("Joe Lawrence <joe.lawrence@redhat.com>");
43MODULE_DESCRIPTION("Livepatch test: busy target module");