Skip to content

Commit

Permalink
rcuwait: Introduce prepare_to and finish_rcuwait
Browse files Browse the repository at this point in the history
This allows further flexibility for some callers to implement
ad-hoc versions of the generic rcuwait_wait_event(). For example,
kvm will need this to maintain tracing semantics. The naming
is of course similar to what waitqueue apis offer.

Also go ahead and make use of rcu_assign_pointer() for both task
writes as it will make the __rcu sparse people happy - this will
be the special nil case, thus no added serialization.

Acked-by: Peter Zijlstra (Intel) <[email protected]>
Signed-off-by: Davidlohr Bueso <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Paolo Bonzini <[email protected]>
  • Loading branch information
Davidlohr Bueso authored and bonzini committed May 13, 2020
1 parent 9d9a6eb commit 5c21f7b
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions include/linux/rcuwait.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,25 @@ extern int rcuwait_wake_up(struct rcuwait *w);

/*
* The caller is responsible for locking around rcuwait_wait_event(),
* such that writes to @task are properly serialized.
* and [prepare_to/finish]_rcuwait() such that writes to @task are
* properly serialized.
*/

static inline void prepare_to_rcuwait(struct rcuwait *w)
{
rcu_assign_pointer(w->task, current);
}

static inline void finish_rcuwait(struct rcuwait *w)
{
rcu_assign_pointer(w->task, NULL);
__set_current_state(TASK_RUNNING);
}

#define rcuwait_wait_event(w, condition, state) \
({ \
int __ret = 0; \
rcu_assign_pointer((w)->task, current); \
prepare_to_rcuwait(w); \
for (;;) { \
/* \
* Implicit barrier (A) pairs with (B) in \
Expand All @@ -51,9 +64,7 @@ extern int rcuwait_wake_up(struct rcuwait *w);
\
schedule(); \
} \
\
WRITE_ONCE((w)->task, NULL); \
__set_current_state(TASK_RUNNING); \
finish_rcuwait(w); \
__ret; \
})

Expand Down

0 comments on commit 5c21f7b

Please sign in to comment.