Skip to content

Commit

Permalink
kthread: kthread worker API cleanup
Browse files Browse the repository at this point in the history
A good practice is to prefix the names of functions by the name
of the subsystem.

The kthread worker API is a mix of classic kthreads and workqueues.  Each
worker has a dedicated kthread.  It runs a generic function that process
queued works.  It is implemented as part of the kthread subsystem.

This patch renames the existing kthread worker API to use
the corresponding name from the workqueues API prefixed by
kthread_:

__init_kthread_worker()		-> __kthread_init_worker()
init_kthread_worker()		-> kthread_init_worker()
init_kthread_work()		-> kthread_init_work()
insert_kthread_work()		-> kthread_insert_work()
queue_kthread_work()		-> kthread_queue_work()
flush_kthread_work()		-> kthread_flush_work()
flush_kthread_worker()		-> kthread_flush_worker()

Note that the names of DEFINE_KTHREAD_WORK*() macros stay
as they are. It is common that the "DEFINE_" prefix has
precedence over the subsystem names.

Note that INIT() macros and init() functions use different
naming scheme. There is no good solution. There are several
reasons for this solution:

  + "init" in the function names stands for the verb "initialize"
    aka "initialize worker". While "INIT" in the macro names
    stands for the noun "INITIALIZER" aka "worker initializer".

  + INIT() macros are used only in DEFINE() macros

  + init() functions are used close to the other kthread()
    functions. It looks much better if all the functions
    use the same scheme.

  + There will be also kthread_destroy_worker() that will
    be used close to kthread_cancel_work(). It is related
    to the init() function. Again it looks better if all
    functions use the same naming scheme.

  + there are several precedents for such init() function
    names, e.g. amd_iommu_init_device(), free_area_init_node(),
    jump_label_init_type(),  regmap_init_mmio_clk(),

  + It is not an argument but it was inconsistent even before.

[[email protected]: fix linux-next merge conflict]
 Link: http://lkml.kernel.org/r/[email protected]
Link: http://lkml.kernel.org/r/[email protected]
Suggested-by: Andrew Morton <[email protected]>
Signed-off-by: Petr Mladek <[email protected]>
Cc: Oleg Nesterov <[email protected]>
Cc: Tejun Heo <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Steven Rostedt <[email protected]>
Cc: "Paul E. McKenney" <[email protected]>
Cc: Josh Triplett <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Jiri Kosina <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Michal Hocko <[email protected]>
Cc: Vlastimil Babka <[email protected]>
Signed-off-by: Arnd Bergmann <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
pmladek authored and torvalds committed Oct 11, 2016
1 parent e700591 commit 3989144
Show file tree
Hide file tree
Showing 18 changed files with 93 additions and 92 deletions.
2 changes: 1 addition & 1 deletion Documentation/RCU/lockdep-splat.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Call Trace:
[<ffffffff817db154>] kernel_thread_helper+0x4/0x10
[<ffffffff81066430>] ? finish_task_switch+0x80/0x110
[<ffffffff817d9c04>] ? retint_restore_args+0xe/0xe
[<ffffffff81097510>] ? __init_kthread_worker+0x70/0x70
[<ffffffff81097510>] ? __kthread_init_worker+0x70/0x70
[<ffffffff817db150>] ? gs_change+0xb/0xb

Line 2776 of block/cfq-iosched.c in v3.0-rc5 is as follows:
Expand Down
14 changes: 7 additions & 7 deletions arch/x86/kvm/i8254.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ static void kvm_pit_ack_irq(struct kvm_irq_ack_notifier *kian)
*/
smp_mb();
if (atomic_dec_if_positive(&ps->pending) > 0)
queue_kthread_work(&pit->worker, &pit->expired);
kthread_queue_work(&pit->worker, &pit->expired);
}

void __kvm_migrate_pit_timer(struct kvm_vcpu *vcpu)
Expand All @@ -233,7 +233,7 @@ void __kvm_migrate_pit_timer(struct kvm_vcpu *vcpu)
static void destroy_pit_timer(struct kvm_pit *pit)
{
hrtimer_cancel(&pit->pit_state.timer);
flush_kthread_work(&pit->expired);
kthread_flush_work(&pit->expired);
}

static void pit_do_work(struct kthread_work *work)
Expand Down Expand Up @@ -272,7 +272,7 @@ static enum hrtimer_restart pit_timer_fn(struct hrtimer *data)
if (atomic_read(&ps->reinject))
atomic_inc(&ps->pending);

queue_kthread_work(&pt->worker, &pt->expired);
kthread_queue_work(&pt->worker, &pt->expired);

if (ps->is_periodic) {
hrtimer_add_expires_ns(&ps->timer, ps->period);
Expand Down Expand Up @@ -324,7 +324,7 @@ static void create_pit_timer(struct kvm_pit *pit, u32 val, int is_period)

/* TODO The new value only affected after the retriggered */
hrtimer_cancel(&ps->timer);
flush_kthread_work(&pit->expired);
kthread_flush_work(&pit->expired);
ps->period = interval;
ps->is_periodic = is_period;

Expand Down Expand Up @@ -667,13 +667,13 @@ struct kvm_pit *kvm_create_pit(struct kvm *kvm, u32 flags)
pid_nr = pid_vnr(pid);
put_pid(pid);

init_kthread_worker(&pit->worker);
kthread_init_worker(&pit->worker);
pit->worker_task = kthread_run(kthread_worker_fn, &pit->worker,
"kvm-pit/%d", pid_nr);
if (IS_ERR(pit->worker_task))
goto fail_kthread;

init_kthread_work(&pit->expired, pit_do_work);
kthread_init_work(&pit->expired, pit_do_work);

pit->kvm = kvm;

Expand Down Expand Up @@ -730,7 +730,7 @@ void kvm_free_pit(struct kvm *kvm)
kvm_io_bus_unregister_dev(kvm, KVM_PIO_BUS, &pit->speaker_dev);
kvm_pit_set_reinject(pit, false);
hrtimer_cancel(&pit->pit_state.timer);
flush_kthread_work(&pit->expired);
kthread_flush_work(&pit->expired);
kthread_stop(pit->worker_task);
kvm_free_irq_source_id(kvm, pit->irq_source_id);
kfree(pit);
Expand Down
20 changes: 10 additions & 10 deletions crypto/crypto_engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static void crypto_pump_requests(struct crypto_engine *engine,

/* If another context is idling then defer */
if (engine->idling) {
queue_kthread_work(&engine->kworker, &engine->pump_requests);
kthread_queue_work(&engine->kworker, &engine->pump_requests);
goto out;
}

Expand All @@ -58,7 +58,7 @@ static void crypto_pump_requests(struct crypto_engine *engine,

/* Only do teardown in the thread */
if (!in_kthread) {
queue_kthread_work(&engine->kworker,
kthread_queue_work(&engine->kworker,
&engine->pump_requests);
goto out;
}
Expand Down Expand Up @@ -189,7 +189,7 @@ int crypto_transfer_cipher_request(struct crypto_engine *engine,
ret = ablkcipher_enqueue_request(&engine->queue, req);

if (!engine->busy && need_pump)
queue_kthread_work(&engine->kworker, &engine->pump_requests);
kthread_queue_work(&engine->kworker, &engine->pump_requests);

spin_unlock_irqrestore(&engine->queue_lock, flags);
return ret;
Expand Down Expand Up @@ -231,7 +231,7 @@ int crypto_transfer_hash_request(struct crypto_engine *engine,
ret = ahash_enqueue_request(&engine->queue, req);

if (!engine->busy && need_pump)
queue_kthread_work(&engine->kworker, &engine->pump_requests);
kthread_queue_work(&engine->kworker, &engine->pump_requests);

spin_unlock_irqrestore(&engine->queue_lock, flags);
return ret;
Expand Down Expand Up @@ -284,7 +284,7 @@ void crypto_finalize_cipher_request(struct crypto_engine *engine,

req->base.complete(&req->base, err);

queue_kthread_work(&engine->kworker, &engine->pump_requests);
kthread_queue_work(&engine->kworker, &engine->pump_requests);
}
EXPORT_SYMBOL_GPL(crypto_finalize_cipher_request);

Expand Down Expand Up @@ -321,7 +321,7 @@ void crypto_finalize_hash_request(struct crypto_engine *engine,

req->base.complete(&req->base, err);

queue_kthread_work(&engine->kworker, &engine->pump_requests);
kthread_queue_work(&engine->kworker, &engine->pump_requests);
}
EXPORT_SYMBOL_GPL(crypto_finalize_hash_request);

Expand All @@ -345,7 +345,7 @@ int crypto_engine_start(struct crypto_engine *engine)
engine->running = true;
spin_unlock_irqrestore(&engine->queue_lock, flags);

queue_kthread_work(&engine->kworker, &engine->pump_requests);
kthread_queue_work(&engine->kworker, &engine->pump_requests);

return 0;
}
Expand Down Expand Up @@ -422,15 +422,15 @@ struct crypto_engine *crypto_engine_alloc_init(struct device *dev, bool rt)
crypto_init_queue(&engine->queue, CRYPTO_ENGINE_MAX_QLEN);
spin_lock_init(&engine->queue_lock);

init_kthread_worker(&engine->kworker);
kthread_init_worker(&engine->kworker);
engine->kworker_task = kthread_run(kthread_worker_fn,
&engine->kworker, "%s",
engine->name);
if (IS_ERR(engine->kworker_task)) {
dev_err(dev, "failed to create crypto request pump task\n");
return NULL;
}
init_kthread_work(&engine->pump_requests, crypto_pump_work);
kthread_init_work(&engine->pump_requests, crypto_pump_work);

if (engine->rt) {
dev_info(dev, "will run requests pump with realtime priority\n");
Expand All @@ -455,7 +455,7 @@ int crypto_engine_exit(struct crypto_engine *engine)
if (ret)
return ret;

flush_kthread_worker(&engine->kworker);
kthread_flush_worker(&engine->kworker);
kthread_stop(engine->kworker_task);

return 0;
Expand Down
8 changes: 4 additions & 4 deletions drivers/block/loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -840,13 +840,13 @@ static void loop_config_discard(struct loop_device *lo)

static void loop_unprepare_queue(struct loop_device *lo)
{
flush_kthread_worker(&lo->worker);
kthread_flush_worker(&lo->worker);
kthread_stop(lo->worker_task);
}

static int loop_prepare_queue(struct loop_device *lo)
{
init_kthread_worker(&lo->worker);
kthread_init_worker(&lo->worker);
lo->worker_task = kthread_run(kthread_worker_fn,
&lo->worker, "loop%d", lo->lo_number);
if (IS_ERR(lo->worker_task))
Expand Down Expand Up @@ -1658,7 +1658,7 @@ static int loop_queue_rq(struct blk_mq_hw_ctx *hctx,
break;
}

queue_kthread_work(&lo->worker, &cmd->work);
kthread_queue_work(&lo->worker, &cmd->work);

return BLK_MQ_RQ_QUEUE_OK;
}
Expand Down Expand Up @@ -1696,7 +1696,7 @@ static int loop_init_request(void *data, struct request *rq,
struct loop_cmd *cmd = blk_mq_rq_to_pdu(rq);

cmd->rq = rq;
init_kthread_work(&cmd->work, loop_queue_work);
kthread_init_work(&cmd->work, loop_queue_work);

return 0;
}
Expand Down
10 changes: 5 additions & 5 deletions drivers/infiniband/sw/rdmavt/cq.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ void rvt_cq_enter(struct rvt_cq *cq, struct ib_wc *entry, bool solicited)
if (likely(worker)) {
cq->notify = RVT_CQ_NONE;
cq->triggered++;
queue_kthread_work(worker, &cq->comptask);
kthread_queue_work(worker, &cq->comptask);
}
}

Expand Down Expand Up @@ -265,7 +265,7 @@ struct ib_cq *rvt_create_cq(struct ib_device *ibdev,
cq->ibcq.cqe = entries;
cq->notify = RVT_CQ_NONE;
spin_lock_init(&cq->lock);
init_kthread_work(&cq->comptask, send_complete);
kthread_init_work(&cq->comptask, send_complete);
cq->queue = wc;

ret = &cq->ibcq;
Expand Down Expand Up @@ -295,7 +295,7 @@ int rvt_destroy_cq(struct ib_cq *ibcq)
struct rvt_cq *cq = ibcq_to_rvtcq(ibcq);
struct rvt_dev_info *rdi = cq->rdi;

flush_kthread_work(&cq->comptask);
kthread_flush_work(&cq->comptask);
spin_lock(&rdi->n_cqs_lock);
rdi->n_cqs_allocated--;
spin_unlock(&rdi->n_cqs_lock);
Expand Down Expand Up @@ -514,7 +514,7 @@ int rvt_driver_cq_init(struct rvt_dev_info *rdi)
rdi->worker = kzalloc(sizeof(*rdi->worker), GFP_KERNEL);
if (!rdi->worker)
return -ENOMEM;
init_kthread_worker(rdi->worker);
kthread_init_worker(rdi->worker);
task = kthread_create_on_node(
kthread_worker_fn,
rdi->worker,
Expand Down Expand Up @@ -547,7 +547,7 @@ void rvt_cq_exit(struct rvt_dev_info *rdi)
/* blocks future queuing from send_complete() */
rdi->worker = NULL;
smp_wmb(); /* See rdi_cq_enter */
flush_kthread_worker(worker);
kthread_flush_worker(worker);
kthread_stop(worker->task);
kfree(worker);
}
6 changes: 3 additions & 3 deletions drivers/md/dm-rq.c
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ static void init_tio(struct dm_rq_target_io *tio, struct request *rq,
if (!md->init_tio_pdu)
memset(&tio->info, 0, sizeof(tio->info));
if (md->kworker_task)
init_kthread_work(&tio->work, map_tio_request);
kthread_init_work(&tio->work, map_tio_request);
}

static struct dm_rq_target_io *dm_old_prep_tio(struct request *rq,
Expand Down Expand Up @@ -831,7 +831,7 @@ static void dm_old_request_fn(struct request_queue *q)
tio = tio_from_request(rq);
/* Establish tio->ti before queuing work (map_tio_request) */
tio->ti = ti;
queue_kthread_work(&md->kworker, &tio->work);
kthread_queue_work(&md->kworker, &tio->work);
BUG_ON(!irqs_disabled());
}
}
Expand All @@ -853,7 +853,7 @@ int dm_old_init_request_queue(struct mapped_device *md)
blk_queue_prep_rq(md->queue, dm_old_prep_fn);

/* Initialize the request-based DM worker thread */
init_kthread_worker(&md->kworker);
kthread_init_worker(&md->kworker);
md->kworker_task = kthread_run(kthread_worker_fn, &md->kworker,
"kdmwork-%s", dm_device_name(md));
if (IS_ERR(md->kworker_task))
Expand Down
4 changes: 2 additions & 2 deletions drivers/md/dm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1891,7 +1891,7 @@ static void __dm_destroy(struct mapped_device *md, bool wait)
spin_unlock_irq(q->queue_lock);

if (dm_request_based(md) && md->kworker_task)
flush_kthread_worker(&md->kworker);
kthread_flush_worker(&md->kworker);

/*
* Take suspend_lock so that presuspend and postsuspend methods
Expand Down Expand Up @@ -2147,7 +2147,7 @@ static int __dm_suspend(struct mapped_device *md, struct dm_table *map,
if (dm_request_based(md)) {
dm_stop_queue(md->queue);
if (md->kworker_task)
flush_kthread_worker(&md->kworker);
kthread_flush_worker(&md->kworker);
}

flush_workqueue(md->wq);
Expand Down
6 changes: 3 additions & 3 deletions drivers/media/pci/ivtv/ivtv-driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ static int ivtv_init_struct1(struct ivtv *itv)
spin_lock_init(&itv->lock);
spin_lock_init(&itv->dma_reg_lock);

init_kthread_worker(&itv->irq_worker);
kthread_init_worker(&itv->irq_worker);
itv->irq_worker_task = kthread_run(kthread_worker_fn, &itv->irq_worker,
"%s", itv->v4l2_dev.name);
if (IS_ERR(itv->irq_worker_task)) {
Expand All @@ -760,7 +760,7 @@ static int ivtv_init_struct1(struct ivtv *itv)
/* must use the FIFO scheduler as it is realtime sensitive */
sched_setscheduler(itv->irq_worker_task, SCHED_FIFO, &param);

init_kthread_work(&itv->irq_work, ivtv_irq_work_handler);
kthread_init_work(&itv->irq_work, ivtv_irq_work_handler);

/* Initial settings */
itv->cxhdl.port = CX2341X_PORT_MEMORY;
Expand Down Expand Up @@ -1441,7 +1441,7 @@ static void ivtv_remove(struct pci_dev *pdev)
del_timer_sync(&itv->dma_timer);

/* Kill irq worker */
flush_kthread_worker(&itv->irq_worker);
kthread_flush_worker(&itv->irq_worker);
kthread_stop(itv->irq_worker_task);

ivtv_streams_cleanup(itv);
Expand Down
2 changes: 1 addition & 1 deletion drivers/media/pci/ivtv/ivtv-irq.c
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,7 @@ irqreturn_t ivtv_irq_handler(int irq, void *dev_id)
}

if (test_and_clear_bit(IVTV_F_I_HAVE_WORK, &itv->i_flags)) {
queue_kthread_work(&itv->irq_worker, &itv->irq_work);
kthread_queue_work(&itv->irq_worker, &itv->irq_work);
}

spin_unlock(&itv->dma_reg_lock);
Expand Down
10 changes: 5 additions & 5 deletions drivers/net/ethernet/microchip/encx24j600.c
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ static void encx24j600_set_multicast_list(struct net_device *dev)
}

if (oldfilter != priv->rxfilter)
queue_kthread_work(&priv->kworker, &priv->setrx_work);
kthread_queue_work(&priv->kworker, &priv->setrx_work);
}

static void encx24j600_hw_tx(struct encx24j600_priv *priv)
Expand Down Expand Up @@ -879,7 +879,7 @@ static netdev_tx_t encx24j600_tx(struct sk_buff *skb, struct net_device *dev)
/* Remember the skb for deferred processing */
priv->tx_skb = skb;

queue_kthread_work(&priv->kworker, &priv->tx_work);
kthread_queue_work(&priv->kworker, &priv->tx_work);

return NETDEV_TX_OK;
}
Expand Down Expand Up @@ -1037,9 +1037,9 @@ static int encx24j600_spi_probe(struct spi_device *spi)
goto out_free;
}

init_kthread_worker(&priv->kworker);
init_kthread_work(&priv->tx_work, encx24j600_tx_proc);
init_kthread_work(&priv->setrx_work, encx24j600_setrx_proc);
kthread_init_worker(&priv->kworker);
kthread_init_work(&priv->tx_work, encx24j600_tx_proc);
kthread_init_work(&priv->setrx_work, encx24j600_setrx_proc);

priv->kworker_task = kthread_run(kthread_worker_fn, &priv->kworker,
"encx24j600");
Expand Down
Loading

0 comments on commit 3989144

Please sign in to comment.