Skip to content

Commit

Permalink
timeval: Preserve quiescence across time_poll().
Browse files Browse the repository at this point in the history
Otherwise ovsrcu_synchronize() busy-waits in its loop because its
poll_block() un-quiesces, causing the global_seqno to increase, which is
what it waits for.

Reported-by: Alex Wang <[email protected]>
Signed-off-by: Ben Pfaff <[email protected]>
Acked-by: Alex Wang <[email protected]>
  • Loading branch information
blp committed Apr 28, 2014
1 parent 1edc458 commit 3308c69
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
7 changes: 7 additions & 0 deletions lib/ovs-rcu.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,13 @@ ovsrcu_quiesce(void)
ovsrcu_quiesced();
}

bool
ovsrcu_is_quiescent(void)
{
ovsrcu_init();
return pthread_getspecific(perthread_key) == NULL;
}

static void
ovsrcu_synchronize(void)
{
Expand Down
1 change: 1 addition & 0 deletions lib/ovs-rcu.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,5 +178,6 @@ void ovsrcu_postpone__(void (*function)(void *aux), void *aux);
void ovsrcu_quiesce_start(void);
void ovsrcu_quiesce_end(void);
void ovsrcu_quiesce(void);
bool ovsrcu_is_quiescent(void);

#endif /* ovs-rcu.h */
14 changes: 9 additions & 5 deletions lib/timeval.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ time_poll(struct pollfd *pollfds, int n_pollfds, HANDLE *handles OVS_UNUSED,
{
long long int *last_wakeup = last_wakeup_get();
long long int start;
bool quiescent;
int retval = 0;

time_init();
Expand All @@ -274,6 +275,7 @@ time_poll(struct pollfd *pollfds, int n_pollfds, HANDLE *handles OVS_UNUSED,
start = time_msec();

timeout_when = MIN(timeout_when, deadline);
quiescent = ovsrcu_is_quiescent();

for (;;) {
long long int now = time_msec();
Expand All @@ -287,10 +289,12 @@ time_poll(struct pollfd *pollfds, int n_pollfds, HANDLE *handles OVS_UNUSED,
time_left = timeout_when - now;
}

if (!time_left) {
ovsrcu_quiesce();
} else {
ovsrcu_quiesce_start();
if (!quiescent) {
if (!time_left) {
ovsrcu_quiesce();
} else {
ovsrcu_quiesce_start();
}
}

#ifndef _WIN32
Expand All @@ -313,7 +317,7 @@ time_poll(struct pollfd *pollfds, int n_pollfds, HANDLE *handles OVS_UNUSED,
}
#endif

if (time_left) {
if (!quiescent && time_left) {
ovsrcu_quiesce_end();
}

Expand Down

0 comments on commit 3308c69

Please sign in to comment.