If you want to pass data to your work queue function, just embed the work_struct structure inside your own data structure and use container_of inside your work function to retrieve it.

As for a simple example, the kernel is full of it - just git grep work_struct. You can look at drivers/cpufreq/cpufreq.c (handle_update function) for a simple example. The article below also embeds an example at the end, but it does not use container_of and instead relies on the fact that the first member of a structure has the same address as its parent:

http://www.ibm.com/developerworks/linux/library/l-tasklets/index.html

Answer from Gnurou on Stack Overflow
🌐
Linux Kernel
docs.kernel.org › core-api › workqueue.html
Workqueue — The Linux Kernel documentation
When such an asynchronous execution context is needed, a work item describing which function to execute is put on a queue. An independent thread serves as the asynchronous execution context. The queue is called workqueue and the thread is called worker.
🌐
O'Reilly
oreilly.com › library › view › understanding-the-linux › 0596005652 › ch04s08.html
4.8. Work Queues - Understanding the Linux Kernel, 3rd Edition [Book]
November 17, 2005 - Work Queues The work queues have been introduced in Linux 2.6 and replace a similar construct called “task queue” used in Linux 2.4. They allow kernel functions to be activated...
Authors   Daniel P. BovetMarco Cesati
Published   2005
Pages   942
🌐
Linux Kernel
kernel.org › doc › html › v4.14 › core-api › workqueue.html
Concurrency Managed Workqueue (cmwq) — The Linux Kernel documentation
When such an asynchronous execution context is needed, a work item describing which function to execute is put on a queue. An independent thread serves as the asynchronous execution context. The queue is called workqueue and the thread is called worker.
🌐
GitHub
github.com › torvalds › linux › blob › master › include › linux › workqueue.h
linux/include/linux/workqueue.h at master · torvalds/linux
* workqueue.h --- work queue handling for Linux. */ · #ifndef _LINUX_WORKQUEUE_H · #define _LINUX_WORKQUEUE_H ·
Author   torvalds
🌐
EmbeTronicX
embetronicx.com › tutorials › linux › device-drivers › workqueue-in-linux-kernel
Workqueue in Linux Kernel Part 1 – Linux Device Driver Tutorial Part 14
September 24, 2023 - Work queues are added in the Linux kernel 2.6 version. Work queues are a different form of deferring work. Work queues defer work into a kernel thread; this bottom half always runs in the process context.
🌐
LWN.net
lwn.net › Articles › 11360
Details of the workqueue interface [LWN.net]
A "workqueue" is a list of tasks to perform, along with a (per-CPU) kernel thread to execute those tasks. Since a kernel thread is used, all tasks are run in process context and may safely sleep. Tasks running out of a special-purpose workqueue can sleep indefinitely, since they will not interfere ...
🌐
GitHub
github.com › torvalds › linux › blob › master › kernel › workqueue.c
linux/kernel/workqueue.c at master · torvalds/linux
system_dfl_wq = alloc_workqueue("events_unbound", WQ_UNBOUND, WQ_MAX_ACTIVE);
Author   torvalds
Find elsewhere
🌐
Linux Kernel Labs
linux-kernel-labs.github.io › refs › heads › master › labs › deferred_work.html
Deferred work — The Linux Kernel documentation
Workqueues are used to schedule actions to run in process context. The base unit with which they work is called work.
🌐
EmbeTronicX
embetronicx.com › tutorials › linux › device-drivers › work-queue-in-linux-own-workqueue
Workqueue in Linux Kernel Part 3 – Linux Device Driver Tutorial Part 16
October 5, 2022 - In our previous (Part 1, Part 2) tutorials we haven’t created any of the workqueue. We were just used the global workqueue and creating work and scheduling that work to the global workqueue. Now we are going to create our own Workqueue in Linux Device Driver.
🌐
GitHub
github.com › torvalds › linux › blob › master › Documentation › core-api › workqueue.rst
linux/Documentation/core-api/workqueue.rst at master · torvalds/linux
When such an asynchronous execution context is needed, a work item describing which function to execute is put on a queue. An independent thread serves as the asynchronous execution context. The queue is called workqueue and the thread is called worker.
Author   torvalds
🌐
EmbeTronicX
embetronicx.com › tutorials › linux › device-drivers › workqueue-in-linux-dynamic-creation
Workqueue in Linux Kernel Part 2 – Linux Device Driver Tutorial Part 15
October 5, 2022 - In that source code, When we read the /dev/etx_device, the interrupt will hit (To understand interrupts in Linux go to this tutorial). Whenever an interrupt hits, I’m scheduling the work to the workqueue. I’m not going to do any job in both interrupt handler and workqueue function since it is a tutorial post.
🌐
Infradead
infradead.org › ~mchehab › kernel_docs › core-api › workqueue.html
Concurrency Managed Workqueue (cmwq) — The Linux Kernel 5.10.0-rc1+ documentation
When such an asynchronous execution context is needed, a work item describing which function to execute is put on a queue. An independent thread serves as the asynchronous execution context. The queue is called workqueue and the thread is called worker.
🌐
Linux Inside
0xax.gitbooks.io › linux-insides › content › Interrupts › linux-interrupts-9.html
Softirq, Tasklets and Workqueues · Linux Inside - 0xax
In its most basic form, the work queue subsystem is an interface for creating kernel threads to handle work that is queued from elsewhere. All of these kernel threads are called -- worker threads. The work queue are maintained by the work_struct that defined in the include/linux/workqueue.h.
🌐
Linuxfound
events.static.linuxfound.org › sites › events › files › slides › Async execution with wqs.pdf pdf
Async execution with workqueues Bhaktipriya Shridhar
CMWQ extends workqueue such that it can · serve as robust async mechanism. ➔ · Less to worry about causing · deadlocks around execution · resources. ➔ · Far fewer number of kthreads. ➔ · More flexibility without runtime · overhead. ➔ · Richer and far more expressive · Benefits · Many thanks to.... Tejun Heo · Outreachy Team · Organizing Committee, LinuxCon NA 2016 ·
🌐
Paper Checker
hub.paper-checker.com › blog › multitasking-in-the-linux-kernel-an-in-depth-guide-to-workqueues
Multitasking in Linux Kernel: Exploring Workqueues
January 16, 2025 - Workqueues are a flexible mechanism in the Linux kernel that allow tasks to be queued and executed by worker threads in the background.
🌐
Phoronix
phoronix.com › news › Linux-6.13-Workqueues
Linux 6.13 Quadrupling Workqueue Concurrency Limit - Phoronix
The Linux kernel Workqueue (WQ) is used for handling asynchronous process execution. For the past many years there has been an upper limit on the number of workqueue execution contexts per CPU at 512, but with Linux 6.13 that is being quadrupled to a limit of 2048.
🌐
Hitchhikersguidetolearning
hitchhikersguidetolearning.com › 2023 › 04 › 05 › workqueues-as-bottom-half-methods-in-the-linux-kernel
WorkQueues as bottom half methods in the Linux kernel | Hitch Hiker's Guide to Learning
Another bottom half method that is used in the linux kernel is the Workqueue. The work queue is an interface for creating kernel threads to handle work which is queued from elsewhere. The kernel threads so created are called as Worker threads.