qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: yang.z.zhang@intel.com, mdroth@linux.vnet.ibm.com, quintela@redhat.com
Subject: [Qemu-devel] [PATCH 08/10] RTC: Get and set time without going through s->current_tm
Date: Wed,  1 Aug 2012 18:41:50 +0200	[thread overview]
Message-ID: <1343839312-24030-9-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1343839312-24030-1-git-send-email-pbonzini@redhat.com>

This patch makes rtc_set_time and rtc_set_cmos work without reading
s->current_tm.  In the case of rtc_set_time I introduce a new
function that retrieves the time and stores into a given struct tm
(not hard-coded to s->current_tm).  In the case of rtc_set_cmos, the
current time is similarly taken from a struct tm rather than
s->current_tm.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 hw/mc146818rtc.c |   38 ++++++++++++++++++++++----------------
 1 file changed, 22 insertions(+), 16 deletions(-)

diff --git a/hw/mc146818rtc.c b/hw/mc146818rtc.c
index 345886a..a69ddc3 100644
--- a/hw/mc146818rtc.c
+++ b/hw/mc146818rtc.c
@@ -84,7 +84,7 @@ typedef struct RTCState {
 
 static void rtc_set_time(RTCState *s);
 static void rtc_update_time(RTCState *s);
-static void rtc_set_cmos(RTCState *s);
+static void rtc_set_cmos(RTCState *s, const struct tm *tm);
 static inline int rtc_from_bcd(RTCState *s, int a);
 static uint64_t get_next_alarm(RTCState *s);
 
@@ -500,10 +500,8 @@ static inline int rtc_from_bcd(RTCState *s, int a)
     }
 }
 
-static void rtc_set_time(RTCState *s)
+static void rtc_get_time(RTCState *s, struct tm *tm)
 {
-    struct tm *tm = &s->current_tm;
-
     tm->tm_sec = rtc_from_bcd(s, s->cmos_data[RTC_SECONDS]);
     tm->tm_min = rtc_from_bcd(s, s->cmos_data[RTC_MINUTES]);
     tm->tm_hour = rtc_from_bcd(s, s->cmos_data[RTC_HOURS] & 0x7f);
@@ -517,16 +515,22 @@ static void rtc_set_time(RTCState *s)
     tm->tm_mday = rtc_from_bcd(s, s->cmos_data[RTC_DAY_OF_MONTH]);
     tm->tm_mon = rtc_from_bcd(s, s->cmos_data[RTC_MONTH]) - 1;
     tm->tm_year = rtc_from_bcd(s, s->cmos_data[RTC_YEAR]) + s->base_year - 1900;
+}
 
-    s->base_rtc = mktimegm(tm);
+static void rtc_set_time(RTCState *s)
+{
+    struct tm tm;
+
+    rtc_get_time(s, &tm);
+    s->current_tm = *tm;
+    s->base_rtc = mktimegm(&tm);
     s->last_update = qemu_get_clock_ns(rtc_clock);
 
-    rtc_change_mon_event(tm);
+    rtc_change_mon_event(&tm);
 }
 
-static void rtc_set_cmos(RTCState *s)
+static void rtc_set_cmos(RTCState *s, const struct tm *tm)
 {
-    const struct tm *tm = &s->current_tm;
     int year;
 
     s->cmos_data[RTC_SECONDS] = rtc_to_bcd(s, tm->tm_sec);
@@ -559,8 +563,8 @@ static void rtc_update_time(RTCState *s)
     guest_nsec = get_guest_rtc_ns(s);
     guest_sec = guest_nsec / NSEC_PER_SEC;
     ret = gmtime(&guest_sec);
+    rtc_set_cmos(s, ret);
     s->current_tm = *ret;
-    rtc_set_cmos(s);
 }
 
 static int update_in_progress(RTCState *s)
@@ -675,8 +679,8 @@ static void rtc_set_date_from_host(ISADevice *dev)
     s->offset = 0;
 
     /* set the CMOS date */
+    rtc_set_cmos(s, &tm);
     s->current_tm = tm;
-    rtc_set_cmos(s);
 
     val = rtc_to_bcd(s, (tm.tm_year / 100) + 19);
     rtc_set_memory(dev, REG_IBM_CENTURY_BYTE, val);
@@ -780,15 +784,17 @@ static void rtc_get_date(Object *obj, Visitor *v, void *opaque,
 {
     ISADevice *isa = ISA_DEVICE(obj);
     RTCState *s = DO_UPCAST(RTCState, dev, isa);
+    struct tm current_tm;
 
     rtc_update_time(s);
+    rtc_get_time(s, &current_tm);
     visit_start_struct(v, NULL, "struct tm", name, 0, errp);
-    visit_type_int32(v, &s->current_tm.tm_year, "tm_year", errp);
-    visit_type_int32(v, &s->current_tm.tm_mon, "tm_mon", errp);
-    visit_type_int32(v, &s->current_tm.tm_mday, "tm_mday", errp);
-    visit_type_int32(v, &s->current_tm.tm_hour, "tm_hour", errp);
-    visit_type_int32(v, &s->current_tm.tm_min, "tm_min", errp);
-    visit_type_int32(v, &s->current_tm.tm_sec, "tm_sec", errp);
+    visit_type_int32(v, &current_tm.tm_year, "tm_year", errp);
+    visit_type_int32(v, &current_tm.tm_mon, "tm_mon", errp);
+    visit_type_int32(v, &current_tm.tm_mday, "tm_mday", errp);
+    visit_type_int32(v, &current_tm.tm_hour, "tm_hour", errp);
+    visit_type_int32(v, &current_tm.tm_min, "tm_min", errp);
+    visit_type_int32(v, &current_tm.tm_sec, "tm_sec", errp);
     visit_end_struct(v, errp);
 }
 
-- 
1.7.10.4

  parent reply	other threads:[~2012-08-01 16:42 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-01 16:41 [Qemu-devel] [PATCH 0/10] Remove periodic wakeup from RTC timer Paolo Bonzini
2012-08-01 16:41 ` [Qemu-devel] [PATCH 01/10] RTC: Remove the logic to update time format when DM bit changed Paolo Bonzini
2012-08-01 16:41 ` [Qemu-devel] [PATCH 02/10] RTC: Rename rtc_timer_update Paolo Bonzini
2012-08-01 16:41 ` [Qemu-devel] [PATCH 03/10] RTC: Update interrupt state when interrupts are masked/unmasked Paolo Bonzini
2012-08-01 16:41 ` [Qemu-devel] [PATCH 06/10] vmstate: add VMSTATE_TIMER_V Paolo Bonzini
2012-08-02  8:56   ` Juan Quintela
2012-08-02  9:02     ` Paolo Bonzini
2012-08-01 16:41 ` [Qemu-devel] [PATCH 05/10] RTC: Update the RTC clock only when reading it Paolo Bonzini
2012-08-01 19:48   ` Anthony Liguori
2012-08-02  9:09   ` Juan Quintela
2012-08-02  9:14     ` Paolo Bonzini
2012-08-02  9:58       ` Juan Quintela
2012-08-01 16:41 ` [Qemu-devel] [PATCH 06/10] RTC: Add divider reset support Paolo Bonzini
2012-08-01 16:41 ` [Qemu-devel] [PATCH 07/10] RTC: Do not fire timer periodically to catch next alarm Paolo Bonzini
2012-08-01 16:41 ` Paolo Bonzini [this message]
2012-08-01 16:41 ` [Qemu-devel] [PATCH 09/10] RTC: Remove the current_tm field Paolo Bonzini
2012-08-01 16:41 ` [Qemu-devel] [PATCH 10/10] RTC: Allow to migrate from old QEMU Paolo Bonzini
2012-08-01 19:51 ` [Qemu-devel] [PATCH 0/10] Remove periodic wakeup from RTC timer Anthony Liguori
2012-08-02  6:32   ` Paolo Bonzini
2012-08-02  0:44 ` Zhang, Yang Z

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1343839312-24030-9-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    --cc=yang.z.zhang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).