Message ID | 1381222058-16701-7-git-send-email-pbonzini@redhat.com |
---|---|
State | New |
Headers | show |
On 8 Oct 2013, at 09:47, Paolo Bonzini wrote: > This fixes a deadlock in cpu_disable_ticks. > > Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Alex Bligh <alex@alex.org.uk> > --- > Should be squashed in Ping Fan's patches. > > cpus.c | 21 +++++++++++++++------ > 1 file changed, 15 insertions(+), 6 deletions(-) > > diff --git a/cpus.c b/cpus.c > index 08eaf23..01acce2 100644 > --- a/cpus.c > +++ b/cpus.c > @@ -166,6 +166,20 @@ int64_t cpu_get_ticks(void) > } > } > > +static int64_t cpu_get_clock_locked(void) > +{ > + int64_t ti; > + > + if (!timers_state.cpu_ticks_enabled) { > + ti = timers_state.cpu_clock_offset; > + } else { > + ti = get_clock(); > + ti += timers_state.cpu_clock_offset; > + } > + > + return ti; > +} > + > /* return the host CPU monotonic timer and handle stop/restart */ > int64_t cpu_get_clock(void) > { > @@ -174,12 +188,7 @@ int64_t cpu_get_clock(void) > > do { > start = seqlock_read_begin(&timers_state.clock_seqlock); > - if (!timers_state.cpu_ticks_enabled) { > - ti = timers_state.cpu_clock_offset; > - } else { > - ti = get_clock(); > - ti += timers_state.cpu_clock_offset; > - } > + ti = cpu_get_clock_locked(); > } while (seqlock_read_retry(&timers_state.clock_seqlock, start)); > > return ti; > @@ -220,7 +233,7 @@ void cpu_disable_ticks(void) > seqlock_write_lock(&timers_state.clock_seqlock); > if (timers_state.cpu_ticks_enabled) { > timers_state.cpu_ticks_offset = cpu_get_ticks(); > - timers_state.cpu_clock_offset = cpu_get_clock(); > + timers_state.cpu_clock_offset = cpu_get_clock_locked(); > timers_state.cpu_ticks_enabled = 0; > } > seqlock_write_unlock(&timers_state.clock_seqlock); > -- > 1.8.3.1 > > > >
diff --git a/cpus.c b/cpus.c index 08eaf23..01acce2 100644 --- a/cpus.c +++ b/cpus.c @@ -166,6 +166,20 @@ int64_t cpu_get_ticks(void) } } +static int64_t cpu_get_clock_locked(void) +{ + int64_t ti; + + if (!timers_state.cpu_ticks_enabled) { + ti = timers_state.cpu_clock_offset; + } else { + ti = get_clock(); + ti += timers_state.cpu_clock_offset; + } + + return ti; +} + /* return the host CPU monotonic timer and handle stop/restart */ int64_t cpu_get_clock(void) { @@ -174,12 +188,7 @@ int64_t cpu_get_clock(void) do { start = seqlock_read_begin(&timers_state.clock_seqlock); - if (!timers_state.cpu_ticks_enabled) { - ti = timers_state.cpu_clock_offset; - } else { - ti = get_clock(); - ti += timers_state.cpu_clock_offset; - } + ti = cpu_get_clock_locked(); } while (seqlock_read_retry(&timers_state.clock_seqlock, start)); return ti; @@ -220,7 +233,7 @@ void cpu_disable_ticks(void) seqlock_write_lock(&timers_state.clock_seqlock); if (timers_state.cpu_ticks_enabled) { timers_state.cpu_ticks_offset = cpu_get_ticks(); - timers_state.cpu_clock_offset = cpu_get_clock(); + timers_state.cpu_clock_offset = cpu_get_clock_locked(); timers_state.cpu_ticks_enabled = 0; } seqlock_write_unlock(&timers_state.clock_seqlock);
This fixes a deadlock in cpu_disable_ticks. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> --- Should be squashed in Ping Fan's patches. cpus.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-)