The possibility of specifying more than just a nice
for the wq may be useful for a wide variety of applications.

Signed-off-by: Wen Yang <[email protected]>
Signed-off-by: Jiang Biao <[email protected]>
Signed-off-by: Tan Hu <[email protected]>
Suggested-by: Tejun Heo <[email protected]>
Cc: Tejun Heo <[email protected]>
Cc: Lai Jiangshan <[email protected]>
Cc: kernel test robot <[email protected]>
Cc: [email protected]
---
 include/linux/workqueue.h |  5 +++--
 kernel/workqueue.c        | 27 +++++++++++++++------------
 2 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h
index 4a54ef9..d9d0f36 100644
--- a/include/linux/workqueue.h
+++ b/include/linux/workqueue.h
@@ -13,6 +13,7 @@
 #include <linux/threads.h>
 #include <linux/atomic.h>
 #include <linux/cpumask.h>
+#include <uapi/linux/sched/types.h>
 
 struct workqueue_struct;
 
@@ -127,9 +128,9 @@ struct delayed_work {
  */
 struct workqueue_attrs {
        /**
-        * @nice: nice level
+        * @sched_attr: kworker's scheduling parameters
         */
-       int nice;
+       struct sched_attr sched_attr;
 
        /**
         * @cpumask: allowed CPUs
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index df22ecb..fca0e30 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -1772,7 +1772,7 @@ static struct worker *create_worker(struct worker_pool 
*pool)
 
        if (pool->cpu >= 0)
                snprintf(id_buf, sizeof(id_buf), "%d:%d%s", pool->cpu, id,
-                        pool->attrs->nice < 0  ? "H" : "");
+                        pool->attrs->sched_attr.sched_nice < 0  ? "H" : "");
        else
                snprintf(id_buf, sizeof(id_buf), "u%d:%d", pool->id, id);
 
@@ -1781,7 +1781,7 @@ static struct worker *create_worker(struct worker_pool 
*pool)
        if (IS_ERR(worker->task))
                goto fail;
 
-       set_user_nice(worker->task, pool->attrs->nice);
+       set_user_nice(worker->task, pool->attrs->sched_attr.sched_nice);
        kthread_bind_mask(worker->task, pool->attrs->cpumask);
 
        /* successful, attach the worker to the pool */
@@ -3169,7 +3169,7 @@ struct workqueue_attrs *alloc_workqueue_attrs(gfp_t 
gfp_mask)
 static void copy_workqueue_attrs(struct workqueue_attrs *to,
                                 const struct workqueue_attrs *from)
 {
-       to->nice = from->nice;
+       to->sched_attr.sched_nice = from->sched_attr.sched_nice;
        cpumask_copy(to->cpumask, from->cpumask);
        /*
         * Unlike hash and equality test, this function doesn't ignore
@@ -3184,7 +3184,7 @@ static u32 wqattrs_hash(const struct workqueue_attrs 
*attrs)
 {
        u32 hash = 0;
 
-       hash = jhash_1word(attrs->nice, hash);
+       hash = jhash_1word(attrs->sched_attr.sched_nice, hash);
        hash = jhash(cpumask_bits(attrs->cpumask),
                     BITS_TO_LONGS(nr_cpumask_bits) * sizeof(long), hash);
        return hash;
@@ -3194,7 +3194,7 @@ static u32 wqattrs_hash(const struct workqueue_attrs 
*attrs)
 static bool wqattrs_equal(const struct workqueue_attrs *a,
                          const struct workqueue_attrs *b)
 {
-       if (a->nice != b->nice)
+       if (a->sched_attr.sched_nice != b->sched_attr.sched_nice)
                return false;
        if (!cpumask_equal(a->cpumask, b->cpumask))
                return false;
@@ -4336,7 +4336,8 @@ static void pr_cont_pool_info(struct worker_pool *pool)
        pr_cont(" cpus=%*pbl", nr_cpumask_bits, pool->attrs->cpumask);
        if (pool->node != NUMA_NO_NODE)
                pr_cont(" node=%d", pool->node);
-       pr_cont(" flags=0x%x nice=%d", pool->flags, pool->attrs->nice);
+       pr_cont(" flags=0x%x nice=%d", pool->flags,
+                       pool->attrs->sched_attr.sched_nice);
 }
 
 static void pr_cont_work(bool comma, struct work_struct *work)
@@ -5074,7 +5075,8 @@ static ssize_t wq_nice_show(struct device *dev, struct 
device_attribute *attr,
        int written;
 
        mutex_lock(&wq->mutex);
-       written = scnprintf(buf, PAGE_SIZE, "%d\n", wq->attrs->nice);
+       written = scnprintf(buf, PAGE_SIZE, "%d\n",
+                       wq->attrs->sched_attr.sched_nice);
        mutex_unlock(&wq->mutex);
 
        return written;
@@ -5108,8 +5110,9 @@ static ssize_t wq_nice_store(struct device *dev, struct 
device_attribute *attr,
        if (!attrs)
                goto out_unlock;
 
-       if (sscanf(buf, "%d", &attrs->nice) == 1 &&
-           attrs->nice >= MIN_NICE && attrs->nice <= MAX_NICE)
+       if (sscanf(buf, "%d", &attrs->sched_attr.sched_nice) == 1 &&
+           attrs->sched_attr.sched_nice >= MIN_NICE &&
+           attrs->sched_attr.sched_nice <= MAX_NICE)
                ret = apply_workqueue_attrs_locked(wq, attrs);
        else
                ret = -EINVAL;
@@ -5573,7 +5576,7 @@ int __init workqueue_init_early(void)
                        BUG_ON(init_worker_pool(pool));
                        pool->cpu = cpu;
                        cpumask_copy(pool->attrs->cpumask, cpumask_of(cpu));
-                       pool->attrs->nice = std_nice[i++];
+                       pool->attrs->sched_attr.sched_nice = std_nice[i++];
                        pool->node = cpu_to_node(cpu);
 
                        /* alloc pool ID */
@@ -5588,7 +5591,7 @@ int __init workqueue_init_early(void)
                struct workqueue_attrs *attrs;
 
                BUG_ON(!(attrs = alloc_workqueue_attrs(GFP_KERNEL)));
-               attrs->nice = std_nice[i];
+               attrs->sched_attr.sched_nice = std_nice[i];
                unbound_std_wq_attrs[i] = attrs;
 
                /*
@@ -5597,7 +5600,7 @@ int __init workqueue_init_early(void)
                 * Turn off NUMA so that dfl_pwq is used for all nodes.
                 */
                BUG_ON(!(attrs = alloc_workqueue_attrs(GFP_KERNEL)));
-               attrs->nice = std_nice[i];
+               attrs->sched_attr.sched_nice = std_nice[i];
                attrs->no_numa = true;
                ordered_wq_attrs[i] = attrs;
        }
-- 
1.8.3.1

Reply via email to