diff mbox

[PATCHv2,8/8] pseries: Export RTC time via QOM

Message ID 1419293824-2654-9-git-send-email-david@gibson.dropbear.id.au
State New
Headers show

Commit Message

David Gibson Dec. 23, 2014, 12:17 a.m. UTC
On x86, the guest's RTC can be read with QMP, either from the RTC device's
"date" property or via the "rtc-time" property on the machine (which is an
alias to the former).  This is set up in the mc146818rtc driver, and
doesn't work on other targets.

This patch adds a similar "date" property to the pseries machine's RTAS RTC
and adds a compatible alias to the machine.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
 hw/ppc/spapr.c     | 3 +++
 hw/ppc/spapr_rtc.c | 7 +++++++
 2 files changed, 10 insertions(+)

Comments

Alexander Graf Dec. 23, 2014, 12:26 a.m. UTC | #1
On 23.12.14 01:17, David Gibson wrote:
> On x86, the guest's RTC can be read with QMP, either from the RTC device's
> "date" property or via the "rtc-time" property on the machine (which is an
> alias to the former).  This is set up in the mc146818rtc driver, and
> doesn't work on other targets.
> 
> This patch adds a similar "date" property to the pseries machine's RTAS RTC
> and adds a compatible alias to the machine.
> 
> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>

Very nice, can we somehow get rid of an exported spapr_rtc_read() with
this as well?


Alex
David Gibson Dec. 23, 2014, 3:14 a.m. UTC | #2
On Tue, Dec 23, 2014 at 01:26:58AM +0100, Alexander Graf wrote:
> 
> 
> On 23.12.14 01:17, David Gibson wrote:
> > On x86, the guest's RTC can be read with QMP, either from the RTC device's
> > "date" property or via the "rtc-time" property on the machine (which is an
> > alias to the former).  This is set up in the mc146818rtc driver, and
> > doesn't work on other targets.
> > 
> > This patch adds a similar "date" property to the pseries machine's RTAS RTC
> > and adds a compatible alias to the machine.
> > 
> > Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
> 
> Very nice, can we somehow get rid of an exported spapr_rtc_read() with
> this as well?

Uhhh.. we could, but I really don't like the idea.

It seems perverse to encode the current time into JSON, just so we can
decode it into a struct tm again in the events code.
Alexander Graf Dec. 23, 2014, 6:33 a.m. UTC | #3
> Am 23.12.2014 um 04:14 schrieb David Gibson <david@gibson.dropbear.id.au>:
> 
>> On Tue, Dec 23, 2014 at 01:26:58AM +0100, Alexander Graf wrote:
>> 
>> 
>>> On 23.12.14 01:17, David Gibson wrote:
>>> On x86, the guest's RTC can be read with QMP, either from the RTC device's
>>> "date" property or via the "rtc-time" property on the machine (which is an
>>> alias to the former).  This is set up in the mc146818rtc driver, and
>>> doesn't work on other targets.
>>> 
>>> This patch adds a similar "date" property to the pseries machine's RTAS RTC
>>> and adds a compatible alias to the machine.
>>> 
>>> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
>> 
>> Very nice, can we somehow get rid of an exported spapr_rtc_read() with
>> this as well?
> 
> Uhhh.. we could, but I really don't like the idea.
> 
> It seems perverse to encode the current time into JSON, just so we can
> decode it into a struct tm again in the events code.

I don't understand - what does JSON have to do with it?

Alex
David Gibson Jan. 28, 2015, 5:28 a.m. UTC | #4
On Tue, Dec 23, 2014 at 07:33:30AM +0100, Alexander Graf wrote:
> 
> 
> 
> > Am 23.12.2014 um 04:14 schrieb David Gibson <david@gibson.dropbear.id.au>:
> > 
> >> On Tue, Dec 23, 2014 at 01:26:58AM +0100, Alexander Graf wrote:
> >> 
> >> 
> >>> On 23.12.14 01:17, David Gibson wrote:
> >>> On x86, the guest's RTC can be read with QMP, either from the RTC device's
> >>> "date" property or via the "rtc-time" property on the machine (which is an
> >>> alias to the former).  This is set up in the mc146818rtc driver, and
> >>> doesn't work on other targets.
> >>> 
> >>> This patch adds a similar "date" property to the pseries machine's RTAS RTC
> >>> and adds a compatible alias to the machine.
> >>> 
> >>> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
> >> 
> >> Very nice, can we somehow get rid of an exported spapr_rtc_read() with
> >> this as well?
> > 
> > Uhhh.. we could, but I really don't like the idea.
> > 
> > It seems perverse to encode the current time into JSON, just so we can
> > decode it into a struct tm again in the events code.
> 
> I don't understand - what does JSON have to do with it?

My misunderstanding, it doesn't actually deal with JSON here.  But if
I'm following how this would work, it would be a way of getting a
struct tm from point A to point B, by:
  1. building a temporary visitor object (object_property_get_qobject)
  2. finding and calling the general property getter callback
     (object_property_get)
  3. Making multiple callbacks into the visitor with pieces of point
     A's struct tm (property_get_tm)
  4. In those visitor callbacks building an associative array
     (qmp_output_start_struct), then filling it with object wrappers
     around integers (qmp_output_type_int)
  5. Digging through the nested qobject thus constructed to extract
     the various ints and put them into point B's struct tm
     (hypothetical object_property_get_tm)
  6. Cleaning up the various temporaries created during the process


Seriously, w. t. f.!?

Maybe there's a simpler way of doing this via the object property
mechanism, but it's sure as hell not obvious to me.
diff mbox

Patch

diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index 3070be0..88fabc8 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -961,6 +961,9 @@  static void spapr_rtc_create(sPAPREnvironment *spapr)
 
     qdev_init_nofail(dev);
     spapr->rtc = dev;
+
+    object_property_add_alias(qdev_get_machine(), "rtc-time",
+                              OBJECT(spapr->rtc), "date", NULL);
 }
 
 /* Returns whether we want to use VGA or not */
diff --git a/hw/ppc/spapr_rtc.c b/hw/ppc/spapr_rtc.c
index 5ad0823..83eb7c1 100644
--- a/hw/ppc/spapr_rtc.c
+++ b/hw/ppc/spapr_rtc.c
@@ -152,6 +152,11 @@  static void rtas_set_time_of_day(PowerPCCPU *cpu, sPAPREnvironment *spapr,
     rtas_st(rets, 0, RTAS_OUT_SUCCESS);
 }
 
+static void spapr_rtc_qom_date(Object *obj, struct tm *current_tm, Error **errp)
+{
+    spapr_rtc_read(DEVICE(obj), current_tm, NULL);
+}
+
 static void spapr_rtc_realize(DeviceState *dev, Error **errp)
 {
     sPAPRRTCState *rtc = SPAPR_RTC(dev);
@@ -165,6 +170,8 @@  static void spapr_rtc_realize(DeviceState *dev, Error **errp)
     host_s = mktimegm(&tm);
     rtc_ns = qemu_clock_get_ns(rtc_clock);
     rtc->ns_offset = host_s * NSEC_PER_SEC - rtc_ns;
+
+    object_property_add_tm(OBJECT(rtc), "date", spapr_rtc_qom_date, NULL);
 }
 
 static const VMStateDescription vmstate_spapr_rtc = {