From 0317e3d27569dc74a549505af00d3764a2c8ba6c Mon Sep 17 00:00:00 2001 From: hselasky Date: Fri, 16 Feb 2018 15:41:16 +0000 Subject: [PATCH] Implement tasklet_enable() and tasklet_disable() in the LinuxKPI. MFC after: 1 week Requested by: Johannes Lundberg Sponsored by: Mellanox Technologies --- .../linuxkpi/common/include/linux/interrupt.h | 2 ++ .../linuxkpi/common/src/linux_tasklet.c | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/sys/compat/linuxkpi/common/include/linux/interrupt.h b/sys/compat/linuxkpi/common/include/linux/interrupt.h index e9bae513973..0d9a6656b86 100644 --- a/sys/compat/linuxkpi/common/include/linux/interrupt.h +++ b/sys/compat/linuxkpi/common/include/linux/interrupt.h @@ -200,5 +200,7 @@ extern void tasklet_schedule(struct tasklet_struct *); extern void tasklet_kill(struct tasklet_struct *); extern void tasklet_init(struct tasklet_struct *, tasklet_func_t *, unsigned long data); +extern void tasklet_enable(struct tasklet_struct *); +extern void tasklet_disable(struct tasklet_struct *); #endif /* _LINUX_INTERRUPT_H_ */ diff --git a/sys/compat/linuxkpi/common/src/linux_tasklet.c b/sys/compat/linuxkpi/common/src/linux_tasklet.c index 5fe94553c9d..549af864747 100644 --- a/sys/compat/linuxkpi/common/src/linux_tasklet.c +++ b/sys/compat/linuxkpi/common/src/linux_tasklet.c @@ -41,6 +41,7 @@ __FBSDID("$FreeBSD$"); #define TASKLET_ST_BUSY 1 #define TASKLET_ST_EXEC 2 #define TASKLET_ST_LOOP 3 +#define TASKLET_ST_PAUSED 4 #define TASKLET_ST_CMPSET(ts, old, new) \ atomic_cmpset_ptr((volatile uintptr_t *)&(ts)->entry.tqe_prev, old, new) @@ -196,3 +197,21 @@ tasklet_kill(struct tasklet_struct *ts) while (TASKLET_ST_GET(ts) != TASKLET_ST_IDLE) pause("W", 1); } + +void +tasklet_enable(struct tasklet_struct *ts) +{ + (void) TASKLET_ST_CMPSET(ts, TASKLET_ST_PAUSED, TASKLET_ST_IDLE); +} + +void +tasklet_disable(struct tasklet_struct *ts) +{ + while (1) { + if (TASKLET_ST_GET(ts) == TASKLET_ST_PAUSED) + break; + if (TASKLET_ST_CMPSET(ts, TASKLET_ST_IDLE, TASKLET_ST_PAUSED)) + break; + pause("W", 1); + } +} -- 2.45.0