Skip to content

Commit 6cebb17

Browse files
htejundavem330
authored andcommitted
connector: remove lazy workqueue creation
Commit 1a5645b (connector: create connector workqueue only while needed once) implements lazy workqueue creation for connector workqueue. With cmwq now in place, lazy workqueue creation doesn't make much sense while adding a lot of complexity. Remove it and allocate an ordered workqueue during initialization. This also removes a call to flush_scheduled_work() which is deprecated and scheduled to be removed. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Frederic Weisbecker <fweisbec@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 229aebb commit 6cebb17

3 files changed

Lines changed: 12 additions & 80 deletions

File tree

‎drivers/connector/cn_queue.c‎

Lines changed: 8 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -31,48 +31,6 @@
3131
#include <linux/connector.h>
3232
#include <linux/delay.h>
3333

34-
35-
/*
36-
* This job is sent to the kevent workqueue.
37-
* While no event is once sent to any callback, the connector workqueue
38-
* is not created to avoid a useless waiting kernel task.
39-
* Once the first event is received, we create this dedicated workqueue which
40-
* is necessary because the flow of data can be high and we don't want
41-
* to encumber keventd with that.
42-
*/
43-
static void cn_queue_create(struct work_struct *work)
44-
{
45-
struct cn_queue_dev *dev;
46-
47-
dev = container_of(work, struct cn_queue_dev, wq_creation);
48-
49-
dev->cn_queue = create_singlethread_workqueue(dev->name);
50-
/* If we fail, we will use keventd for all following connector jobs */
51-
WARN_ON(!dev->cn_queue);
52-
}
53-
54-
/*
55-
* Queue a data sent to a callback.
56-
* If the connector workqueue is already created, we queue the job on it.
57-
* Otherwise, we queue the job to kevent and queue the connector workqueue
58-
* creation too.
59-
*/
60-
int queue_cn_work(struct cn_callback_entry *cbq, struct work_struct *work)
61-
{
62-
struct cn_queue_dev *pdev = cbq->pdev;
63-
64-
if (likely(pdev->cn_queue))
65-
return queue_work(pdev->cn_queue, work);
66-
67-
/* Don't create the connector workqueue twice */
68-
if (atomic_inc_return(&pdev->wq_requested) == 1)
69-
schedule_work(&pdev->wq_creation);
70-
else
71-
atomic_dec(&pdev->wq_requested);
72-
73-
return schedule_work(work);
74-
}
75-
7634
void cn_queue_wrapper(struct work_struct *work)
7735
{
7836
struct cn_callback_entry *cbq =
@@ -111,11 +69,7 @@ cn_queue_alloc_callback_entry(char *name, struct cb_id *id,
11169

11270
static void cn_queue_free_callback(struct cn_callback_entry *cbq)
11371
{
114-
/* The first jobs have been sent to kevent, flush them too */
115-
flush_scheduled_work();
116-
if (cbq->pdev->cn_queue)
117-
flush_workqueue(cbq->pdev->cn_queue);
118-
72+
flush_workqueue(cbq->pdev->cn_queue);
11973
kfree(cbq);
12074
}
12175

@@ -193,37 +147,24 @@ struct cn_queue_dev *cn_queue_alloc_dev(char *name, struct sock *nls)
193147
atomic_set(&dev->refcnt, 0);
194148
INIT_LIST_HEAD(&dev->queue_list);
195149
spin_lock_init(&dev->queue_lock);
196-
init_waitqueue_head(&dev->wq_created);
197150

198151
dev->nls = nls;
199152

200-
INIT_WORK(&dev->wq_creation, cn_queue_create);
153+
dev->cn_queue = alloc_ordered_workqueue(dev->name, 0);
154+
if (!dev->cn_queue) {
155+
kfree(dev);
156+
return NULL;
157+
}
201158

202159
return dev;
203160
}
204161

205162
void cn_queue_free_dev(struct cn_queue_dev *dev)
206163
{
207164
struct cn_callback_entry *cbq, *n;
208-
long timeout;
209-
DEFINE_WAIT(wait);
210-
211-
/* Flush the first pending jobs queued on kevent */
212-
flush_scheduled_work();
213-
214-
/* If the connector workqueue creation is still pending, wait for it */
215-
prepare_to_wait(&dev->wq_created, &wait, TASK_UNINTERRUPTIBLE);
216-
if (atomic_read(&dev->wq_requested) && !dev->cn_queue) {
217-
timeout = schedule_timeout(HZ * 2);
218-
if (!timeout && !dev->cn_queue)
219-
WARN_ON(1);
220-
}
221-
finish_wait(&dev->wq_created, &wait);
222165

223-
if (dev->cn_queue) {
224-
flush_workqueue(dev->cn_queue);
225-
destroy_workqueue(dev->cn_queue);
226-
}
166+
flush_workqueue(dev->cn_queue);
167+
destroy_workqueue(dev->cn_queue);
227168

228169
spin_lock_bh(&dev->queue_lock);
229170
list_for_each_entry_safe(cbq, n, &dev->queue_list, callback_entry)

‎drivers/connector/connector.c‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ static int cn_call_callback(struct sk_buff *skb)
133133
__cbq->data.skb == NULL)) {
134134
__cbq->data.skb = skb;
135135

136-
if (queue_cn_work(__cbq, &__cbq->work))
136+
if (queue_work(dev->cbdev->cn_queue,
137+
&__cbq->work))
137138
err = 0;
138139
else
139140
err = -EINVAL;
@@ -148,13 +149,11 @@ static int cn_call_callback(struct sk_buff *skb)
148149
d->callback = __cbq->data.callback;
149150
d->free = __new_cbq;
150151

151-
__new_cbq->pdev = __cbq->pdev;
152-
153152
INIT_WORK(&__new_cbq->work,
154153
&cn_queue_wrapper);
155154

156-
if (queue_cn_work(__new_cbq,
157-
&__new_cbq->work))
155+
if (queue_work(dev->cbdev->cn_queue,
156+
&__new_cbq->work))
158157
err = 0;
159158
else {
160159
kfree(__new_cbq);

‎include/linux/connector.h‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,6 @@ struct cn_queue_dev {
8888
unsigned char name[CN_CBQ_NAMELEN];
8989

9090
struct workqueue_struct *cn_queue;
91-
/* Sent to kevent to create cn_queue only when needed */
92-
struct work_struct wq_creation;
93-
/* Tell if the wq_creation job is pending/completed */
94-
atomic_t wq_requested;
95-
/* Wait for cn_queue to be created */
96-
wait_queue_head_t wq_created;
9791

9892
struct list_head queue_list;
9993
spinlock_t queue_lock;
@@ -141,8 +135,6 @@ int cn_netlink_send(struct cn_msg *, u32, gfp_t);
141135
int cn_queue_add_callback(struct cn_queue_dev *dev, char *name, struct cb_id *id, void (*callback)(struct cn_msg *, struct netlink_skb_parms *));
142136
void cn_queue_del_callback(struct cn_queue_dev *dev, struct cb_id *id);
143137

144-
int queue_cn_work(struct cn_callback_entry *cbq, struct work_struct *work);
145-
146138
struct cn_queue_dev *cn_queue_alloc_dev(char *name, struct sock *);
147139
void cn_queue_free_dev(struct cn_queue_dev *dev);
148140

0 commit comments

Comments
 (0)