include/linux/kthread.h
Source file repositories/reference/linux-study-clean/include/linux/kthread.h
File Facts
- System
- Linux kernel
- Corpus path
include/linux/kthread.h- Extension
.h- Size
- 9281 bytes
- Lines
- 294
- Domain
- Core OS
- Bucket
- Core Kernel Interface
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/err.hlinux/sched.h
Detected Declarations
struct mm_structstruct kthreadstruct kthread_workstruct kthread_workerstruct kthread_workstruct kthread_delayed_workstruct cgroup_subsys_statefunction wake_up_processfunction wake_up_processfunction kthread_associate_blkcg
Annotated Snippet
struct kthread_worker {
unsigned int flags;
raw_spinlock_t lock;
struct list_head work_list;
struct list_head delayed_work_list;
struct task_struct *task;
struct kthread_work *current_work;
};
struct kthread_work {
struct list_head node;
kthread_work_func_t func;
struct kthread_worker *worker;
/* Number of canceling calls that are running at the moment. */
int canceling;
};
struct kthread_delayed_work {
struct kthread_work work;
struct timer_list timer;
};
#define KTHREAD_WORK_INIT(work, fn) { \
.node = LIST_HEAD_INIT((work).node), \
.func = (fn), \
}
#define KTHREAD_DELAYED_WORK_INIT(dwork, fn) { \
.work = KTHREAD_WORK_INIT((dwork).work, (fn)), \
.timer = __TIMER_INITIALIZER(kthread_delayed_work_timer_fn,\
TIMER_IRQSAFE), \
}
#define DEFINE_KTHREAD_WORK(work, fn) \
struct kthread_work work = KTHREAD_WORK_INIT(work, fn)
#define DEFINE_KTHREAD_DELAYED_WORK(dwork, fn) \
struct kthread_delayed_work dwork = \
KTHREAD_DELAYED_WORK_INIT(dwork, fn)
extern void __kthread_init_worker(struct kthread_worker *worker,
const char *name, struct lock_class_key *key);
#define kthread_init_worker(worker) \
do { \
static struct lock_class_key __key; \
__kthread_init_worker((worker), "("#worker")->lock", &__key); \
} while (0)
#define kthread_init_work(work, fn) \
do { \
memset((work), 0, sizeof(struct kthread_work)); \
INIT_LIST_HEAD(&(work)->node); \
(work)->func = (fn); \
} while (0)
#define kthread_init_delayed_work(dwork, fn) \
do { \
kthread_init_work(&(dwork)->work, (fn)); \
timer_setup(&(dwork)->timer, \
kthread_delayed_work_timer_fn, \
TIMER_IRQSAFE); \
} while (0)
int kthread_worker_fn(void *worker_ptr);
__printf(3, 4)
struct kthread_worker *kthread_create_worker_on_node(unsigned int flags,
int node,
const char namefmt[], ...);
#define kthread_create_worker(flags, namefmt, ...) \
kthread_create_worker_on_node(flags, NUMA_NO_NODE, namefmt, ## __VA_ARGS__);
/**
* kthread_run_worker - create and wake a kthread worker.
* @flags: flags modifying the default behavior of the worker
* @namefmt: printf-style name for the thread.
*
* Description: Convenient wrapper for kthread_create_worker() followed by
* wake_up_process(). Returns the kthread_worker or ERR_PTR(-ENOMEM).
*/
#define kthread_run_worker(flags, namefmt, ...) \
({ \
struct kthread_worker *__kw \
= kthread_create_worker(flags, namefmt, ## __VA_ARGS__); \
if (!IS_ERR(__kw)) \
wake_up_process(__kw->task); \
__kw; \
})
Annotation
- Immediate include surface: `linux/err.h`, `linux/sched.h`.
- Detected declarations: `struct mm_struct`, `struct kthread`, `struct kthread_work`, `struct kthread_worker`, `struct kthread_work`, `struct kthread_delayed_work`, `struct cgroup_subsys_state`, `function wake_up_process`, `function wake_up_process`, `function kthread_associate_blkcg`.
- Atlas domain: Core OS / Core Kernel Interface.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.