Commit 5c21f7b3 authored by Davidlohr Bueso's avatar Davidlohr Bueso Committed by Paolo Bonzini

rcuwait: Introduce prepare_to and finish_rcuwait

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: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: default avatarDavidlohr Bueso <dbueso@suse.de>
Message-Id: <20200424054837.5138-4-dave@stgolabs.net>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 9d9a6ebf
...@@ -29,12 +29,25 @@ extern int rcuwait_wake_up(struct rcuwait *w); ...@@ -29,12 +29,25 @@ extern int rcuwait_wake_up(struct rcuwait *w);
/* /*
* The caller is responsible for locking around rcuwait_wait_event(), * 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) \ #define rcuwait_wait_event(w, condition, state) \
({ \ ({ \
int __ret = 0; \ int __ret = 0; \
rcu_assign_pointer((w)->task, current); \ prepare_to_rcuwait(w); \
for (;;) { \ for (;;) { \
/* \ /* \
* Implicit barrier (A) pairs with (B) in \ * Implicit barrier (A) pairs with (B) in \
...@@ -51,9 +64,7 @@ extern int rcuwait_wake_up(struct rcuwait *w); ...@@ -51,9 +64,7 @@ extern int rcuwait_wake_up(struct rcuwait *w);
\ \
schedule(); \ schedule(); \
} \ } \
\ finish_rcuwait(w); \
WRITE_ONCE((w)->task, NULL); \
__set_current_state(TASK_RUNNING); \
__ret; \ __ret; \
}) })
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment