Patchwork [6/8] timers: introduce cpu_get_clock_locked

login
register
mail settings
Submitter Paolo Bonzini
Date Oct. 8, 2013, 8:47 a.m.
Message ID <1381222058-16701-7-git-send-email-pbonzini@redhat.com>
Download mbox | patch
Permalink /patch/281367/
State New
Headers show

Comments

Paolo Bonzini - Oct. 8, 2013, 8:47 a.m.
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(-)
Alex Bligh - Oct. 8, 2013, 4:55 p.m.
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
> 
> 
> 
>

Patch

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);