Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bottom-half processing by transitioning to workqueue #292

Merged
merged 1 commit into from
Feb 17, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions examples/bottomhalf.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <linux/printk.h>
#include <linux/init.h>
#include <linux/version.h>
#include <linux/workqueue.h>

#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 10, 0)
#define NO_GPIO_REQUEST_ARRAY
Expand Down Expand Up @@ -42,16 +43,17 @@ static struct gpio buttons[] = {
{ 18, GPIOF_IN, "LED 1 OFF BUTTON" },
};

/* Tasklet containing some non-trivial amount of processing */
static void bottomhalf_tasklet_fn(unsigned long data)
/* Workqueue function containing some non-trivial amount of processing */
static void bottomhalf_work_fn(struct work_struct *work)
{
pr_info("Bottom half tasklet starts\n");
pr_info("Bottom half workqueue starts\n");
/* do something which takes a while */
mdelay(500);
pr_info("Bottom half tasklet ends\n");
msleep(500);

pr_info("Bottom half workqueue ends\n");
}

static DECLARE_TASKLET_OLD(buttontask, bottomhalf_tasklet_fn);
static DECLARE_WORK(bottomhalf_work, bottomhalf_work_fn);

/* interrupt function triggered when a button is pressed */
static irqreturn_t button_isr(int irq, void *data)
Expand All @@ -63,8 +65,7 @@ static irqreturn_t button_isr(int irq, void *data)
gpio_set_value(leds[0].gpio, 0);

/* Do the rest at leisure via the scheduler */
tasklet_schedule(&buttontask);

schedule_work(&bottomhalf_work);
return IRQ_HANDLED;
}

Expand Down