Skip to content

Commit ee7dc86

Browse files
krismanaxboe
authored andcommitted
wait: Return number of exclusive waiters awaken
Sbitmap code will need to know how many waiters were actually woken for its batched wakeups implementation. Return the number of woken exclusive waiters from __wake_up() to facilitate that. Suggested-by: Jan Kara <[email protected]> Signed-off-by: Gabriel Krisman Bertazi <[email protected]> Reviewed-by: Jan Kara <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 976570b commit ee7dc86

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

include/linux/wait.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ __remove_wait_queue(struct wait_queue_head *wq_head, struct wait_queue_entry *wq
209209
list_del(&wq_entry->entry);
210210
}
211211

212-
void __wake_up(struct wait_queue_head *wq_head, unsigned int mode, int nr, void *key);
212+
int __wake_up(struct wait_queue_head *wq_head, unsigned int mode, int nr, void *key);
213213
void __wake_up_locked_key(struct wait_queue_head *wq_head, unsigned int mode, void *key);
214214
void __wake_up_locked_key_bookmark(struct wait_queue_head *wq_head,
215215
unsigned int mode, void *key, wait_queue_entry_t *bookmark);

kernel/sched/wait.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,12 @@ static int __wake_up_common(struct wait_queue_head *wq_head, unsigned int mode,
121121
return nr_exclusive;
122122
}
123123

124-
static void __wake_up_common_lock(struct wait_queue_head *wq_head, unsigned int mode,
124+
static int __wake_up_common_lock(struct wait_queue_head *wq_head, unsigned int mode,
125125
int nr_exclusive, int wake_flags, void *key)
126126
{
127127
unsigned long flags;
128128
wait_queue_entry_t bookmark;
129+
int remaining = nr_exclusive;
129130

130131
bookmark.flags = 0;
131132
bookmark.private = NULL;
@@ -134,10 +135,12 @@ static void __wake_up_common_lock(struct wait_queue_head *wq_head, unsigned int
134135

135136
do {
136137
spin_lock_irqsave(&wq_head->lock, flags);
137-
nr_exclusive = __wake_up_common(wq_head, mode, nr_exclusive,
138+
remaining = __wake_up_common(wq_head, mode, remaining,
138139
wake_flags, key, &bookmark);
139140
spin_unlock_irqrestore(&wq_head->lock, flags);
140141
} while (bookmark.flags & WQ_FLAG_BOOKMARK);
142+
143+
return nr_exclusive - remaining;
141144
}
142145

143146
/**
@@ -147,13 +150,14 @@ static void __wake_up_common_lock(struct wait_queue_head *wq_head, unsigned int
147150
* @nr_exclusive: how many wake-one or wake-many threads to wake up
148151
* @key: is directly passed to the wakeup function
149152
*
150-
* If this function wakes up a task, it executes a full memory barrier before
151-
* accessing the task state.
153+
* If this function wakes up a task, it executes a full memory barrier
154+
* before accessing the task state. Returns the number of exclusive
155+
* tasks that were awaken.
152156
*/
153-
void __wake_up(struct wait_queue_head *wq_head, unsigned int mode,
154-
int nr_exclusive, void *key)
157+
int __wake_up(struct wait_queue_head *wq_head, unsigned int mode,
158+
int nr_exclusive, void *key)
155159
{
156-
__wake_up_common_lock(wq_head, mode, nr_exclusive, 0, key);
160+
return __wake_up_common_lock(wq_head, mode, nr_exclusive, 0, key);
157161
}
158162
EXPORT_SYMBOL(__wake_up);
159163

0 commit comments

Comments
 (0)