Skip to content

Commit 2fb2920

Browse files
author
Peter Zijlstra
committed
futex: Pull futex_hash() out of futex_q_lock()
Getting the hash bucket and queuing it are two distinct actions. In light of wanting to add a put hash bucket function later, untangle them. Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Signed-off-by: Sebastian Andrzej Siewior <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 93f1b6d commit 2fb2920

File tree

4 files changed

+8
-10
lines changed

4 files changed

+8
-10
lines changed

kernel/futex/core.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -502,13 +502,9 @@ void __futex_unqueue(struct futex_q *q)
502502
}
503503

504504
/* The key must be already stored in q->key. */
505-
struct futex_hash_bucket *futex_q_lock(struct futex_q *q)
505+
void futex_q_lock(struct futex_q *q, struct futex_hash_bucket *hb)
506506
__acquires(&hb->lock)
507507
{
508-
struct futex_hash_bucket *hb;
509-
510-
hb = futex_hash(&q->key);
511-
512508
/*
513509
* Increment the counter before taking the lock so that
514510
* a potential waker won't miss a to-be-slept task that is
@@ -522,7 +518,6 @@ struct futex_hash_bucket *futex_q_lock(struct futex_q *q)
522518
q->lock_ptr = &hb->lock;
523519

524520
spin_lock(&hb->lock);
525-
return hb;
526521
}
527522

528523
void futex_q_unlock(struct futex_hash_bucket *hb)

kernel/futex/futex.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ static inline int futex_hb_waiters_pending(struct futex_hash_bucket *hb)
354354
#endif
355355
}
356356

357-
extern struct futex_hash_bucket *futex_q_lock(struct futex_q *q);
357+
extern void futex_q_lock(struct futex_q *q, struct futex_hash_bucket *hb);
358358
extern void futex_q_unlock(struct futex_hash_bucket *hb);
359359

360360

kernel/futex/pi.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,8 @@ int futex_lock_pi(u32 __user *uaddr, unsigned int flags, ktime_t *time, int tryl
939939
goto out;
940940

941941
retry_private:
942-
hb = futex_q_lock(&q);
942+
hb = futex_hash(&q.key);
943+
futex_q_lock(&q, hb);
943944

944945
ret = futex_lock_pi_atomic(uaddr, hb, &q.key, &q.pi_state, current,
945946
&exiting, 0);

kernel/futex/waitwake.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,8 @@ int futex_wait_multiple_setup(struct futex_vector *vs, int count, int *woken)
441441
struct futex_q *q = &vs[i].q;
442442
u32 val = vs[i].w.val;
443443

444-
hb = futex_q_lock(q);
444+
hb = futex_hash(&q->key);
445+
futex_q_lock(q, hb);
445446
ret = futex_get_value_locked(&uval, uaddr);
446447

447448
if (!ret && uval == val) {
@@ -611,7 +612,8 @@ int futex_wait_setup(u32 __user *uaddr, u32 val, unsigned int flags,
611612
return ret;
612613

613614
retry_private:
614-
hb = futex_q_lock(q);
615+
hb = futex_hash(&q->key);
616+
futex_q_lock(q, hb);
615617

616618
ret = futex_get_value_locked(&uval, uaddr);
617619

0 commit comments

Comments
 (0)