diff mbox

[v2] mc146818rtc: add rtc-reset-reinjection QMP command

Message ID 20140617154751.GA3947@amt.cnet
State New
Headers show

Commit Message

Marcelo Tosatti June 17, 2014, 3:47 p.m. UTC
It is necessary to reset RTC interrupt reinjection backlog if
guest time is synchronized via a different mechanism, such as
QGA's guest-set-time command.

Failing to do so causes both corrections to be applied (summed),
resulting in an incorrect guest time.

Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>

Comments

Michael S. Tsirkin June 17, 2014, 4:32 p.m. UTC | #1
On Tue, Jun 17, 2014 at 12:47:51PM -0300, Marcelo Tosatti wrote:
> 
> It is necessary to reset RTC interrupt reinjection backlog if
> guest time is synchronized via a different mechanism, such as
> QGA's guest-set-time command.
> 
> Failing to do so causes both corrections to be applied (summed),
> resulting in an incorrect guest time.
> 
> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>

Thanks, I'll apply this on my tree, though I don't want
to redo the pull request so it'll be in the next one.
Seems small enough to be ok after soft freeze.


> diff --git a/hw/timer/mc146818rtc.c b/hw/timer/mc146818rtc.c
> index df54546..1782c4e 100644
> --- a/hw/timer/mc146818rtc.c
> +++ b/hw/timer/mc146818rtc.c
> @@ -26,6 +26,7 @@
>  #include "sysemu/sysemu.h"
>  #include "hw/timer/mc146818rtc.h"
>  #include "qapi/visitor.h"
> +#include "qmp-commands.h"
>  
>  #ifdef TARGET_I386
>  #include "hw/i386/apic.h"
> @@ -84,6 +85,7 @@ typedef struct RTCState {
>      Notifier clock_reset_notifier;
>      LostTickPolicy lost_tick_policy;
>      Notifier suspend_notifier;
> +    QLIST_ENTRY(RTCState) link;
>  } RTCState;
>  
>  static void rtc_set_time(RTCState *s);
> @@ -522,6 +524,20 @@ static void rtc_get_time(RTCState *s, struct tm *tm)
>          rtc_from_bcd(s, s->cmos_data[RTC_CENTURY]) * 100 - 1900;
>  }
>  
> +static QLIST_HEAD(, RTCState) rtc_devices =
> +    QLIST_HEAD_INITIALIZER(rtc_devices);
> +
> +#ifdef TARGET_I386
> +void qmp_rtc_reset_reinjection(Error **errp)
> +{
> +    RTCState *s;
> +
> +    QLIST_FOREACH(s, &rtc_devices, link) {
> +        s->irq_coalesced = 0;
> +    }
> +}
> +#endif
> +
>  static void rtc_set_time(RTCState *s)
>  {
>      struct tm tm;
> @@ -911,6 +927,8 @@ ISADevice *rtc_init(ISABus *bus, int base_year, qemu_irq intercept_irq)
>      } else {
>          isa_init_irq(isadev, &s->irq, RTC_ISA_IRQ);
>      }
> +    QLIST_INSERT_HEAD(&rtc_devices, s, link);
> +
>      return isadev;
>  }
>  
> diff --git a/qapi-schema.json b/qapi-schema.json
> index 7bc33ea..a4e2c21 100644
> --- a/qapi-schema.json
> +++ b/qapi-schema.json
> @@ -4722,3 +4722,15 @@
>                'btn'     : 'InputBtnEvent',
>                'rel'     : 'InputMoveEvent',
>                'abs'     : 'InputMoveEvent' } }
> +
> +##
> +# @rtc-reset-reinjection
> +#
> +# This command will reset the RTC interrupt reinjection backlog.
> +# Can be used if another mechanism to synchronize guest time
> +# is in effect, for example QEMU guest agent's guest-set-time
> +# command.
> +#
> +# Since: 2.1
> +##
> +{ 'command': 'rtc-reset-reinjection' }
> diff --git a/qmp-commands.hx b/qmp-commands.hx
> index d8aa4ed..dc43789 100644
> --- a/qmp-commands.hx
> +++ b/qmp-commands.hx
> @@ -3572,3 +3572,26 @@ Example:
>                     } } ] }
>  
>  EQMP
> +
> +#if defined (TARGET_I386)

Pls don't put space before (). I fixed it up.

> +    {
> +        .name       = "rtc-reset-reinjection",
> +        .args_type  = "",
> +        .mhandler.cmd_new = qmp_marshal_input_rtc_reset_reinjection,
> +    },
> +#endif
> +
> +SQMP
> +rtc-reset-reinjection
> +---------------------
> +
> +Reset the RTC interrupt reinjection backlog.
> +
> +Arguments: None.
> +
> +Example:
> +
> +-> { "execute": "rtc-reset-reinjection" }
> +<- { "return": {} }
> +
> +EQMP
Michael S. Tsirkin June 17, 2014, 4:48 p.m. UTC | #2
On Tue, Jun 17, 2014 at 12:47:51PM -0300, Marcelo Tosatti wrote:
> 
> It is necessary to reset RTC interrupt reinjection backlog if
> guest time is synchronized via a different mechanism, such as
> QGA's guest-set-time command.
> 
> Failing to do so causes both corrections to be applied (summed),
> resulting in an incorrect guest time.
> 
> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>

Fails build for non x86 target:

  LINK  arm-softmmu/qemu-system-arm
../qmp-marshal.o: In function `qmp_marshal_input_rtc_reset_reinjection':
/scm/qemu/qmp-marshal.c:5059: undefined reference to
`qmp_rtc_reset_reinjection'
collect2: error: ld returned 1 exit status
make[1]: *** [qemu-system-arm] Error 1
make: *** [subdir-arm-softmmu] Error 2


> diff --git a/hw/timer/mc146818rtc.c b/hw/timer/mc146818rtc.c
> index df54546..1782c4e 100644
> --- a/hw/timer/mc146818rtc.c
> +++ b/hw/timer/mc146818rtc.c
> @@ -26,6 +26,7 @@
>  #include "sysemu/sysemu.h"
>  #include "hw/timer/mc146818rtc.h"
>  #include "qapi/visitor.h"
> +#include "qmp-commands.h"
>  
>  #ifdef TARGET_I386
>  #include "hw/i386/apic.h"
> @@ -84,6 +85,7 @@ typedef struct RTCState {
>      Notifier clock_reset_notifier;
>      LostTickPolicy lost_tick_policy;
>      Notifier suspend_notifier;
> +    QLIST_ENTRY(RTCState) link;
>  } RTCState;
>  
>  static void rtc_set_time(RTCState *s);
> @@ -522,6 +524,20 @@ static void rtc_get_time(RTCState *s, struct tm *tm)
>          rtc_from_bcd(s, s->cmos_data[RTC_CENTURY]) * 100 - 1900;
>  }
>  
> +static QLIST_HEAD(, RTCState) rtc_devices =
> +    QLIST_HEAD_INITIALIZER(rtc_devices);
> +
> +#ifdef TARGET_I386
> +void qmp_rtc_reset_reinjection(Error **errp)
> +{
> +    RTCState *s;
> +
> +    QLIST_FOREACH(s, &rtc_devices, link) {
> +        s->irq_coalesced = 0;
> +    }
> +}
> +#endif
> +
>  static void rtc_set_time(RTCState *s)
>  {
>      struct tm tm;
> @@ -911,6 +927,8 @@ ISADevice *rtc_init(ISABus *bus, int base_year, qemu_irq intercept_irq)
>      } else {
>          isa_init_irq(isadev, &s->irq, RTC_ISA_IRQ);
>      }
> +    QLIST_INSERT_HEAD(&rtc_devices, s, link);
> +
>      return isadev;
>  }
>  
> diff --git a/qapi-schema.json b/qapi-schema.json
> index 7bc33ea..a4e2c21 100644
> --- a/qapi-schema.json
> +++ b/qapi-schema.json
> @@ -4722,3 +4722,15 @@
>                'btn'     : 'InputBtnEvent',
>                'rel'     : 'InputMoveEvent',
>                'abs'     : 'InputMoveEvent' } }
> +
> +##
> +# @rtc-reset-reinjection
> +#
> +# This command will reset the RTC interrupt reinjection backlog.
> +# Can be used if another mechanism to synchronize guest time
> +# is in effect, for example QEMU guest agent's guest-set-time
> +# command.
> +#
> +# Since: 2.1
> +##
> +{ 'command': 'rtc-reset-reinjection' }
> diff --git a/qmp-commands.hx b/qmp-commands.hx
> index d8aa4ed..dc43789 100644
> --- a/qmp-commands.hx
> +++ b/qmp-commands.hx
> @@ -3572,3 +3572,26 @@ Example:
>                     } } ] }
>  
>  EQMP
> +
> +#if defined (TARGET_I386)
> +    {
> +        .name       = "rtc-reset-reinjection",
> +        .args_type  = "",
> +        .mhandler.cmd_new = qmp_marshal_input_rtc_reset_reinjection,
> +    },
> +#endif
> +
> +SQMP
> +rtc-reset-reinjection
> +---------------------
> +
> +Reset the RTC interrupt reinjection backlog.
> +
> +Arguments: None.
> +
> +Example:
> +
> +-> { "execute": "rtc-reset-reinjection" }
> +<- { "return": {} }
> +
> +EQMP
Michael S. Tsirkin June 22, 2014, 10:54 a.m. UTC | #3
On Tue, Jun 17, 2014 at 07:48:36PM +0300, Michael S. Tsirkin wrote:
> On Tue, Jun 17, 2014 at 12:47:51PM -0300, Marcelo Tosatti wrote:
> > 
> > It is necessary to reset RTC interrupt reinjection backlog if
> > guest time is synchronized via a different mechanism, such as
> > QGA's guest-set-time command.
> > 
> > Failing to do so causes both corrections to be applied (summed),
> > resulting in an incorrect guest time.
> > 
> > Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
> 
> Fails build for non x86 target:
> 
>   LINK  arm-softmmu/qemu-system-arm
> ../qmp-marshal.o: In function `qmp_marshal_input_rtc_reset_reinjection':
> /scm/qemu/qmp-marshal.c:5059: undefined reference to
> `qmp_rtc_reset_reinjection'
> collect2: error: ld returned 1 exit status
> make[1]: *** [qemu-system-arm] Error 1
> make: *** [subdir-arm-softmmu] Error 2

Ping.
Do you plan to fix and re-post the patch?

> 
> > diff --git a/hw/timer/mc146818rtc.c b/hw/timer/mc146818rtc.c
> > index df54546..1782c4e 100644
> > --- a/hw/timer/mc146818rtc.c
> > +++ b/hw/timer/mc146818rtc.c
> > @@ -26,6 +26,7 @@
> >  #include "sysemu/sysemu.h"
> >  #include "hw/timer/mc146818rtc.h"
> >  #include "qapi/visitor.h"
> > +#include "qmp-commands.h"
> >  
> >  #ifdef TARGET_I386
> >  #include "hw/i386/apic.h"
> > @@ -84,6 +85,7 @@ typedef struct RTCState {
> >      Notifier clock_reset_notifier;
> >      LostTickPolicy lost_tick_policy;
> >      Notifier suspend_notifier;
> > +    QLIST_ENTRY(RTCState) link;
> >  } RTCState;
> >  
> >  static void rtc_set_time(RTCState *s);
> > @@ -522,6 +524,20 @@ static void rtc_get_time(RTCState *s, struct tm *tm)
> >          rtc_from_bcd(s, s->cmos_data[RTC_CENTURY]) * 100 - 1900;
> >  }
> >  
> > +static QLIST_HEAD(, RTCState) rtc_devices =
> > +    QLIST_HEAD_INITIALIZER(rtc_devices);
> > +
> > +#ifdef TARGET_I386
> > +void qmp_rtc_reset_reinjection(Error **errp)
> > +{
> > +    RTCState *s;
> > +
> > +    QLIST_FOREACH(s, &rtc_devices, link) {
> > +        s->irq_coalesced = 0;
> > +    }
> > +}
> > +#endif
> > +
> >  static void rtc_set_time(RTCState *s)
> >  {
> >      struct tm tm;
> > @@ -911,6 +927,8 @@ ISADevice *rtc_init(ISABus *bus, int base_year, qemu_irq intercept_irq)
> >      } else {
> >          isa_init_irq(isadev, &s->irq, RTC_ISA_IRQ);
> >      }
> > +    QLIST_INSERT_HEAD(&rtc_devices, s, link);
> > +
> >      return isadev;
> >  }
> >  
> > diff --git a/qapi-schema.json b/qapi-schema.json
> > index 7bc33ea..a4e2c21 100644
> > --- a/qapi-schema.json
> > +++ b/qapi-schema.json
> > @@ -4722,3 +4722,15 @@
> >                'btn'     : 'InputBtnEvent',
> >                'rel'     : 'InputMoveEvent',
> >                'abs'     : 'InputMoveEvent' } }
> > +
> > +##
> > +# @rtc-reset-reinjection
> > +#
> > +# This command will reset the RTC interrupt reinjection backlog.
> > +# Can be used if another mechanism to synchronize guest time
> > +# is in effect, for example QEMU guest agent's guest-set-time
> > +# command.
> > +#
> > +# Since: 2.1
> > +##
> > +{ 'command': 'rtc-reset-reinjection' }
> > diff --git a/qmp-commands.hx b/qmp-commands.hx
> > index d8aa4ed..dc43789 100644
> > --- a/qmp-commands.hx
> > +++ b/qmp-commands.hx
> > @@ -3572,3 +3572,26 @@ Example:
> >                     } } ] }
> >  
> >  EQMP
> > +
> > +#if defined (TARGET_I386)
> > +    {
> > +        .name       = "rtc-reset-reinjection",
> > +        .args_type  = "",
> > +        .mhandler.cmd_new = qmp_marshal_input_rtc_reset_reinjection,
> > +    },
> > +#endif
> > +
> > +SQMP
> > +rtc-reset-reinjection
> > +---------------------
> > +
> > +Reset the RTC interrupt reinjection backlog.
> > +
> > +Arguments: None.
> > +
> > +Example:
> > +
> > +-> { "execute": "rtc-reset-reinjection" }
> > +<- { "return": {} }
> > +
> > +EQMP
diff mbox

Patch

diff --git a/hw/timer/mc146818rtc.c b/hw/timer/mc146818rtc.c
index df54546..1782c4e 100644
--- a/hw/timer/mc146818rtc.c
+++ b/hw/timer/mc146818rtc.c
@@ -26,6 +26,7 @@ 
 #include "sysemu/sysemu.h"
 #include "hw/timer/mc146818rtc.h"
 #include "qapi/visitor.h"
+#include "qmp-commands.h"
 
 #ifdef TARGET_I386
 #include "hw/i386/apic.h"
@@ -84,6 +85,7 @@  typedef struct RTCState {
     Notifier clock_reset_notifier;
     LostTickPolicy lost_tick_policy;
     Notifier suspend_notifier;
+    QLIST_ENTRY(RTCState) link;
 } RTCState;
 
 static void rtc_set_time(RTCState *s);
@@ -522,6 +524,20 @@  static void rtc_get_time(RTCState *s, struct tm *tm)
         rtc_from_bcd(s, s->cmos_data[RTC_CENTURY]) * 100 - 1900;
 }
 
+static QLIST_HEAD(, RTCState) rtc_devices =
+    QLIST_HEAD_INITIALIZER(rtc_devices);
+
+#ifdef TARGET_I386
+void qmp_rtc_reset_reinjection(Error **errp)
+{
+    RTCState *s;
+
+    QLIST_FOREACH(s, &rtc_devices, link) {
+        s->irq_coalesced = 0;
+    }
+}
+#endif
+
 static void rtc_set_time(RTCState *s)
 {
     struct tm tm;
@@ -911,6 +927,8 @@  ISADevice *rtc_init(ISABus *bus, int base_year, qemu_irq intercept_irq)
     } else {
         isa_init_irq(isadev, &s->irq, RTC_ISA_IRQ);
     }
+    QLIST_INSERT_HEAD(&rtc_devices, s, link);
+
     return isadev;
 }
 
diff --git a/qapi-schema.json b/qapi-schema.json
index 7bc33ea..a4e2c21 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -4722,3 +4722,15 @@ 
               'btn'     : 'InputBtnEvent',
               'rel'     : 'InputMoveEvent',
               'abs'     : 'InputMoveEvent' } }
+
+##
+# @rtc-reset-reinjection
+#
+# This command will reset the RTC interrupt reinjection backlog.
+# Can be used if another mechanism to synchronize guest time
+# is in effect, for example QEMU guest agent's guest-set-time
+# command.
+#
+# Since: 2.1
+##
+{ 'command': 'rtc-reset-reinjection' }
diff --git a/qmp-commands.hx b/qmp-commands.hx
index d8aa4ed..dc43789 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -3572,3 +3572,26 @@  Example:
                    } } ] }
 
 EQMP
+
+#if defined (TARGET_I386)
+    {
+        .name       = "rtc-reset-reinjection",
+        .args_type  = "",
+        .mhandler.cmd_new = qmp_marshal_input_rtc_reset_reinjection,
+    },
+#endif
+
+SQMP
+rtc-reset-reinjection
+---------------------
+
+Reset the RTC interrupt reinjection backlog.
+
+Arguments: None.
+
+Example:
+
+-> { "execute": "rtc-reset-reinjection" }
+<- { "return": {} }
+
+EQMP