Kernel module to generatemanaged irqs for the test and shell commands. Signed-off-by: Costa Shulyupin <costa.shul@xxxxxxxxxx> --- tests/managed_irq.c | 71 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 tests/managed_irq.c diff --git a/tests/managed_irq.c b/tests/managed_irq.c new file mode 100644 index 0000000000000..fd4e91e44e59d --- /dev/null +++ b/tests/managed_irq.c @@ -0,0 +1,71 @@ +#include <linux/interrupt.h> +#include <linux/irq.h> +#include <linux/module.h> + +/* + * Testing instructions: + * + * isolate=1 + * insmod managed_irq.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 + * read test_irq < /sys/module/managed_irq/parameters/test_irq + * + * cat /proc/irq/$test_irq/smp_affinity_list + * + * read affinity < /proc/irq/$test_irq/smp_affinity + * test 0 -ne $((0x$affinity & 1 << $isolate)) && echo FAIL | PASS + * + * Assure that irq affinity doesn't contain isolated cpu. + */ + +static int test_cpu = 1; +module_param(test_cpu, int, 0444); + +static int test_irq; +module_param(test_irq, int, 0444); + +static irqreturn_t test_irq_cb(int irq, void *dev_id) +{ + return IRQ_HANDLED; +} + +static int test_set_affinity(struct irq_data *d, const struct cpumask *m, bool f) +{ + irq_data_update_effective_affinity(d, m); + return 0; +} + +static int make_test_irq(void) +{ + struct irq_affinity_desc a = { + mask: *cpumask_of(test_cpu), + is_managed: true + }; + int test_irq = __irq_alloc_descs(-1, 1, 1, 0, THIS_MODULE, &a); + static struct irq_chip test_chip = { .irq_set_affinity = + test_set_affinity }; + + irq_set_chip(test_irq, &test_chip); + irq_set_status_flags(test_irq, IRQ_MOVE_PCNTXT); + pr_debug("test_irq=%d\n", test_irq); + int err = request_irq(test_irq, test_irq_cb, 0, "test_affinity", 0); + + if (err) + pr_err("%d\n", err); + + return test_irq; +} + +static int managed_irq_init(void) +{ + test_irq = make_test_irq(); + return 0; +} + +module_init(managed_irq_init); + +MODULE_LICENSE("GPL"); -- 2.45.0