IB/rdmavt: Handle the kthread worker using the new API
authorPetr Mladek <pmladek@suse.com>
Wed, 19 Oct 2016 12:07:20 +0000 (14:07 +0200)
committerDoug Ledford <dledford@redhat.com>
Wed, 14 Dec 2016 17:16:11 +0000 (12:16 -0500)
Use the new API to create and destroy the cq kthread worker.
The API hides some implementation details.

In particular, kthread_create_worker() allocates and initializes
struct kthread_worker. It runs the kthread the right way and stores
task_struct into the worker structure. In addition, the *on_cpu()
variant binds the kthread to the given cpu and the related memory
node.

kthread_destroy_worker() flushes all pending works, stops
the kthread and frees the structure.

This patch does not change the existing behavior. Note that we must
use the on_cpu() variant because the function starts the kthread
and it must bind it to the right CPU before waking. The numa node
is associated for given CPU as well.

Signed-off-by: Petr Mladek <pmladek@suse.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
drivers/infiniband/sw/rdmavt/cq.c

index 223ec4589fc7ad25deec99b37bed272bd01746cb..4d0b6992e847d960c0f34f8cd6726c588214e69f 100644 (file)
@@ -503,33 +503,23 @@ int rvt_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *entry)
  */
 int rvt_driver_cq_init(struct rvt_dev_info *rdi)
 {
-       int ret = 0;
        int cpu;
-       struct task_struct *task;
+       struct kthread_worker *worker;
 
        if (rdi->worker)
                return 0;
+
        spin_lock_init(&rdi->n_cqs_lock);
-       rdi->worker = kzalloc(sizeof(*rdi->worker), GFP_KERNEL);
-       if (!rdi->worker)
-               return -ENOMEM;
-       kthread_init_worker(rdi->worker);
-       task = kthread_create_on_node(
-               kthread_worker_fn,
-               rdi->worker,
-               rdi->dparms.node,
-               "%s", rdi->dparms.cq_name);
-       if (IS_ERR(task)) {
-               kfree(rdi->worker);
-               rdi->worker = NULL;
-               return PTR_ERR(task);
-       }
 
-       set_user_nice(task, MIN_NICE);
        cpu = cpumask_first(cpumask_of_node(rdi->dparms.node));
-       kthread_bind(task, cpu);
-       wake_up_process(task);
-       return ret;
+       worker = kthread_create_worker_on_cpu(cpu, 0,
+                                             "%s", rdi->dparms.cq_name);
+       if (IS_ERR(worker))
+               return PTR_ERR(worker);
+
+       set_user_nice(worker->task, MIN_NICE);
+       rdi->worker = worker;
+       return 0;
 }
 
 /**
@@ -549,7 +539,5 @@ void rvt_cq_exit(struct rvt_dev_info *rdi)
        rdi->worker = NULL;
        spin_unlock_irq(&rdi->n_cqs_lock);
 
-       kthread_flush_worker(worker);
-       kthread_stop(worker->task);
-       kfree(worker);
+       kthread_destroy_worker(worker);
 }