Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * kernel/workqueue_internal.h
0004  *
0005  * Workqueue internal header file.  Only to be included by workqueue and
0006  * core kernel subsystems.
0007  */
0008 #ifndef _KERNEL_WORKQUEUE_INTERNAL_H
0009 #define _KERNEL_WORKQUEUE_INTERNAL_H
0010 
0011 #include <linux/workqueue.h>
0012 #include <linux/kthread.h>
0013 #include <linux/preempt.h>
0014 
0015 struct worker_pool;
0016 
0017 /*
0018  * The poor guys doing the actual heavy lifting.  All on-duty workers are
0019  * either serving the manager role, on idle list or on busy hash.  For
0020  * details on the locking annotation (L, I, X...), refer to workqueue.c.
0021  *
0022  * Only to be used in workqueue and async.
0023  */
0024 struct worker {
0025     /* on idle list while idle, on busy hash table while busy */
0026     union {
0027         struct list_head    entry;  /* L: while idle */
0028         struct hlist_node   hentry; /* L: while busy */
0029     };
0030 
0031     struct work_struct  *current_work;  /* L: work being processed */
0032     work_func_t     current_func;   /* L: current_work's fn */
0033     struct pool_workqueue   *current_pwq;   /* L: current_work's pwq */
0034     unsigned int        current_color;  /* L: current_work's color */
0035     struct list_head    scheduled;  /* L: scheduled works */
0036 
0037     /* 64 bytes boundary on 64bit, 32 on 32bit */
0038 
0039     struct task_struct  *task;      /* I: worker task */
0040     struct worker_pool  *pool;      /* A: the associated pool */
0041                         /* L: for rescuers */
0042     struct list_head    node;       /* A: anchored at pool->workers */
0043                         /* A: runs through worker->node */
0044 
0045     unsigned long       last_active;    /* L: last active timestamp */
0046     unsigned int        flags;      /* X: flags */
0047     int         id;     /* I: worker id */
0048     int         sleeping;   /* None */
0049 
0050     /*
0051      * Opaque string set with work_set_desc().  Printed out with task
0052      * dump for debugging - WARN, BUG, panic or sysrq.
0053      */
0054     char            desc[WORKER_DESC_LEN];
0055 
0056     /* used only by rescuers to point to the target workqueue */
0057     struct workqueue_struct *rescue_wq; /* I: the workqueue to rescue */
0058 
0059     /* used by the scheduler to determine a worker's last known identity */
0060     work_func_t     last_func;
0061 };
0062 
0063 /**
0064  * current_wq_worker - return struct worker if %current is a workqueue worker
0065  */
0066 static inline struct worker *current_wq_worker(void)
0067 {
0068     if (in_task() && (current->flags & PF_WQ_WORKER))
0069         return kthread_data(current);
0070     return NULL;
0071 }
0072 
0073 /*
0074  * Scheduler hooks for concurrency managed workqueue.  Only to be used from
0075  * sched/ and workqueue.c.
0076  */
0077 void wq_worker_running(struct task_struct *task);
0078 void wq_worker_sleeping(struct task_struct *task);
0079 work_func_t wq_worker_last_func(struct task_struct *task);
0080 
0081 #endif /* _KERNEL_WORKQUEUE_INTERNAL_H */