Patchwork [RFC,V1,02/11] qemu-timer: Introduce qemu_run_one_timer

login
register
mail settings
Submitter Anthony PERARD
Date Oct. 4, 2011, 2:51 p.m.
Message ID <1317739882-4809-3-git-send-email-anthony.perard@citrix.com>
Download mbox | patch
Permalink /patch/117634/
State New
Headers show

Comments

Anthony PERARD - Oct. 4, 2011, 2:51 p.m.
Used by the Xen PCI Passthrough code to run the timer about the power
state transition.

Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
---
 qemu-timer.c |   15 +++++++++++++++
 qemu-timer.h |    3 +++
 2 files changed, 18 insertions(+), 0 deletions(-)
Jan Kiszka - Oct. 4, 2011, 5:27 p.m.
On 2011-10-04 16:51, Anthony PERARD wrote:
> Used by the Xen PCI Passthrough code to run the timer about the power
> state transition.
> 
> Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
> ---
>  qemu-timer.c |   15 +++++++++++++++
>  qemu-timer.h |    3 +++
>  2 files changed, 18 insertions(+), 0 deletions(-)
> 
> diff --git a/qemu-timer.c b/qemu-timer.c
> index 46dd483..15e659b 100644
> --- a/qemu-timer.c
> +++ b/qemu-timer.c
> @@ -1163,3 +1163,18 @@ int qemu_calculate_timeout(void)
>      return 1000;
>  }
>  
> +/* run the specified timer */
> +void qemu_run_one_timer(QEMUTimer *ts)
> +{
> +    uint64_t current_time;
> +
> +    /* remove timer from the list before calling the callback */
> +    qemu_del_timer(ts);
> +
> +    while ((current_time = qemu_get_clock_ms(rt_clock)) < ts->expire_time)
> +        /* sleep until the expire time */
> +        usleep((ts->expire_time - current_time) * 1000);
> +
> +    /* run the callback */
> +    ts->cb(ts->opaque);
> +}

This looks funny. I can't imagine that this could ever fit into the
standard (asynchronous) QEMU execution model for I/O. Keep it private to
Xen?

Jan
Stefano Stabellini - Oct. 4, 2011, 5:52 p.m.
On Tue, 4 Oct 2011, Jan Kiszka wrote:
> On 2011-10-04 16:51, Anthony PERARD wrote:
> > Used by the Xen PCI Passthrough code to run the timer about the power
> > state transition.
> > 
> > Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
> > ---
> >  qemu-timer.c |   15 +++++++++++++++
> >  qemu-timer.h |    3 +++
> >  2 files changed, 18 insertions(+), 0 deletions(-)
> > 
> > diff --git a/qemu-timer.c b/qemu-timer.c
> > index 46dd483..15e659b 100644
> > --- a/qemu-timer.c
> > +++ b/qemu-timer.c
> > @@ -1163,3 +1163,18 @@ int qemu_calculate_timeout(void)
> >      return 1000;
> >  }
> >  
> > +/* run the specified timer */
> > +void qemu_run_one_timer(QEMUTimer *ts)
> > +{
> > +    uint64_t current_time;
> > +
> > +    /* remove timer from the list before calling the callback */
> > +    qemu_del_timer(ts);
> > +
> > +    while ((current_time = qemu_get_clock_ms(rt_clock)) < ts->expire_time)
> > +        /* sleep until the expire time */
> > +        usleep((ts->expire_time - current_time) * 1000);
> > +
> > +    /* run the callback */
> > +    ts->cb(ts->opaque);
> > +}
> 
> This looks funny. I can't imagine that this could ever fit into the
> standard (asynchronous) QEMU execution model for I/O. Keep it private to
> Xen?

I haven't finished reading the series yet, but this caught my eye
because it is particularly ugly; we should get rid of it.

Considering that on a real device if you try to write to the PCI config
space before a power transition is completed the write just fails, maybe
we should do the same here and remove the timer.
Anthony Liguori - Oct. 4, 2011, 6:20 p.m.
On 10/04/2011 12:27 PM, Jan Kiszka wrote:
> On 2011-10-04 16:51, Anthony PERARD wrote:
>> Used by the Xen PCI Passthrough code to run the timer about the power
>> state transition.
>>
>> Signed-off-by: Anthony PERARD<anthony.perard@citrix.com>
>> ---
>>   qemu-timer.c |   15 +++++++++++++++
>>   qemu-timer.h |    3 +++
>>   2 files changed, 18 insertions(+), 0 deletions(-)
>>
>> diff --git a/qemu-timer.c b/qemu-timer.c
>> index 46dd483..15e659b 100644
>> --- a/qemu-timer.c
>> +++ b/qemu-timer.c
>> @@ -1163,3 +1163,18 @@ int qemu_calculate_timeout(void)
>>       return 1000;
>>   }
>>
>> +/* run the specified timer */
>> +void qemu_run_one_timer(QEMUTimer *ts)
>> +{
>> +    uint64_t current_time;
>> +
>> +    /* remove timer from the list before calling the callback */
>> +    qemu_del_timer(ts);
>> +
>> +    while ((current_time = qemu_get_clock_ms(rt_clock))<  ts->expire_time)
>> +        /* sleep until the expire time */
>> +        usleep((ts->expire_time - current_time) * 1000);
>> +
>> +    /* run the callback */
>> +    ts->cb(ts->opaque);
>> +}
>
> This looks funny. I can't imagine that this could ever fit into the
> standard (asynchronous) QEMU execution model for I/O. Keep it private to
> Xen?

I think it's funny for Xen too.  Why in the world would you need this?

Regards,

Anthony Liguroi

> Jan
>

Patch

diff --git a/qemu-timer.c b/qemu-timer.c
index 46dd483..15e659b 100644
--- a/qemu-timer.c
+++ b/qemu-timer.c
@@ -1163,3 +1163,18 @@  int qemu_calculate_timeout(void)
     return 1000;
 }
 
+/* run the specified timer */
+void qemu_run_one_timer(QEMUTimer *ts)
+{
+    uint64_t current_time;
+
+    /* remove timer from the list before calling the callback */
+    qemu_del_timer(ts);
+
+    while ((current_time = qemu_get_clock_ms(rt_clock)) < ts->expire_time)
+        /* sleep until the expire time */
+        usleep((ts->expire_time - current_time) * 1000);
+
+    /* run the callback */
+    ts->cb(ts->opaque);
+}
diff --git a/qemu-timer.h b/qemu-timer.h
index 0a43469..b7b907b 100644
--- a/qemu-timer.h
+++ b/qemu-timer.h
@@ -338,4 +338,7 @@  extern int64_t tlb_flush_time;
 extern int64_t dev_time;
 #endif
 
+/* run the specified timer */
+void qemu_run_one_timer(QEMUTimer *ts);
+
 #endif