Note: I haven't tested this series yet. Thanks for finding the problem! Il 17/05/2012 04:28, Zhang, Yang Z ha scritto: > Use offset instead of timer to calculate guest rtc. Guest rtc is calculated > by (base_rtc + guest_time_now - guest_time_last_update_rtc + offset). > Base_rtc means the rtc value of last update. > Guest_time_now means the guest time that access happens. > Guest_time_last_update means the guest time of last update rtc. > Offset is used when divider reset happened or set bit is changed. > > +static void rtc_set_offset(RTCState *s, bool running, bool div_reset) > +{ > + if (div_reset) > + s->offset = 500000; > + else if (!running) > + s->offset = s->old_guest_usec % USEC_PER_SEC; > +}
This is probably clearer if you just inline it at the appropriate places---especially because rtc_set_offset(s, 0, 0) is a no-op. > -static void rtc_update_second(void *opaque) > -{ > - RTCState *s = opaque; > - int64_t delay; > - > - /* if the oscillator is not in normal operation, we do not update */ > - if ((s->cmos_data[RTC_REG_A] & 0x70) != 0x20) { > - s->next_second_time += get_ticks_per_sec(); > - qemu_mod_timer(s->second_timer, s->next_second_time); > - } else { > - rtc_next_second(&s->current_tm); > - > - if (!(s->cmos_data[RTC_REG_B] & REG_B_SET)) { > - /* update in progress bit */ > - s->cmos_data[RTC_REG_A] |= REG_A_UIP; > - } > - /* should be 244 us = 8 / 32768 seconds, but currently the > - timers do not have the necessary resolution. */ > - delay = (get_ticks_per_sec() * 1) / 100; > - if (delay < 1) > - delay = 1; > - qemu_mod_timer(s->second_timer2, > - s->next_second_time + delay); > - } > -} This patch breaks REG_A_UIP. You can squash patches 2 and 3 together to avoid this problem. Paolo