Skip to content

Commit 36d03cb

Browse files
Muchun Songaxboe
authored andcommitted
block: introduce init_wait_func()
There is already a macro DEFINE_WAIT_FUNC() to declare a wait_queue_entry with a specified waking function. But there is not a counterpart for initializing one wait_queue_entry with a specified waking function. So introducing init_wait_func() for this, which also could be used in iocost and rq-qos. Using default_wake_function() in rq_qos_wait() to wake up waiters, which could remove ->task field from rq_qos_wait_data. Cc: Ingo Molnar <mingo@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Signed-off-by: Muchun Song <songmuchun@bytedance.com> Acked-by: Tejun Heo <tj@kernel.org> Link: https://lore.kernel.org/r/20250208090416.38642-1-songmuchun@bytedance.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 3bee991 commit 36d03cb

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

block/blk-iocost.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2718,8 +2718,7 @@ static void ioc_rqos_throttle(struct rq_qos *rqos, struct bio *bio)
27182718
* All waiters are on iocg->waitq and the wait states are
27192719
* synchronized using waitq.lock.
27202720
*/
2721-
init_waitqueue_func_entry(&wait.wait, iocg_wake_fn);
2722-
wait.wait.private = current;
2721+
init_wait_func(&wait.wait, iocg_wake_fn);
27232722
wait.bio = bio;
27242723
wait.abs_cost = abs_cost;
27252724
wait.committed = false; /* will be set true by waker */

block/blk-rq-qos.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ bool rq_depth_scale_down(struct rq_depth *rqd, bool hard_throttle)
196196

197197
struct rq_qos_wait_data {
198198
struct wait_queue_entry wq;
199-
struct task_struct *task;
200199
struct rq_wait *rqw;
201200
acquire_inflight_cb_t *cb;
202201
void *private_data;
@@ -218,7 +217,12 @@ static int rq_qos_wake_function(struct wait_queue_entry *curr,
218217
return -1;
219218

220219
data->got_token = true;
221-
wake_up_process(data->task);
220+
/*
221+
* autoremove_wake_function() removes the wait entry only when it
222+
* actually changed the task state. We want the wait always removed.
223+
* Remove explicitly and use default_wake_function().
224+
*/
225+
default_wake_function(curr, mode, wake_flags, key);
222226
list_del_init_careful(&curr->entry);
223227
return 1;
224228
}
@@ -244,11 +248,6 @@ void rq_qos_wait(struct rq_wait *rqw, void *private_data,
244248
cleanup_cb_t *cleanup_cb)
245249
{
246250
struct rq_qos_wait_data data = {
247-
.wq = {
248-
.func = rq_qos_wake_function,
249-
.entry = LIST_HEAD_INIT(data.wq.entry),
250-
},
251-
.task = current,
252251
.rqw = rqw,
253252
.cb = acquire_inflight_cb,
254253
.private_data = private_data,
@@ -259,6 +258,7 @@ void rq_qos_wait(struct rq_wait *rqw, void *private_data,
259258
if (!has_sleeper && acquire_inflight_cb(rqw, private_data))
260259
return;
261260

261+
init_wait_func(&data.wq, rq_qos_wake_function);
262262
has_sleeper = !prepare_to_wait_exclusive(&rqw->wait, &data.wq,
263263
TASK_UNINTERRUPTIBLE);
264264
do {

include/linux/wait.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,14 +1207,16 @@ int autoremove_wake_function(struct wait_queue_entry *wq_entry, unsigned mode, i
12071207

12081208
#define DEFINE_WAIT(name) DEFINE_WAIT_FUNC(name, autoremove_wake_function)
12091209

1210-
#define init_wait(wait) \
1210+
#define init_wait_func(wait, function) \
12111211
do { \
12121212
(wait)->private = current; \
1213-
(wait)->func = autoremove_wake_function; \
1213+
(wait)->func = function; \
12141214
INIT_LIST_HEAD(&(wait)->entry); \
12151215
(wait)->flags = 0; \
12161216
} while (0)
12171217

1218+
#define init_wait(wait) init_wait_func(wait, autoremove_wake_function)
1219+
12181220
typedef int (*task_call_f)(struct task_struct *p, void *arg);
12191221
extern int task_call_func(struct task_struct *p, task_call_f func, void *arg);
12201222

0 commit comments

Comments
 (0)