aboutsummaryrefslogtreecommitdiff
path: root/include/hw
diff options
context:
space:
mode:
authorXiao Guangrong <xiaoguangrong@tencent.com>2017-05-27 10:53:01 +0800
committerPaolo Bonzini <pbonzini@redhat.com>2017-06-06 20:18:35 +0200
commitbd618eab7641693f0838da52c5af5c8050f831d3 (patch)
tree67073e289005de2a59b5c1f722a981b0c9aacb0e /include/hw
parente0c8b950d17a57343926ed937af10e8903b0d6cc (diff)
qtest: add rtc periodic timer test
It tests the accuracy of rtc periodic timer which is recently improved & fixed by commit 7ffcb539a3 ("mc146818rtc: precisely count the clock for periodic timer", 2017-05-19). Signed-off-by: Xiao Guangrong <xiaoguangrong@tencent.com> Message-Id: <20170527025301.23499-1-xiaoguangrong@tencent.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'include/hw')
-rw-r--r--include/hw/timer/mc146818rtc_regs.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/include/hw/timer/mc146818rtc_regs.h b/include/hw/timer/mc146818rtc_regs.h
index 6ede6c832e..c62f17bf2d 100644
--- a/include/hw/timer/mc146818rtc_regs.h
+++ b/include/hw/timer/mc146818rtc_regs.h
@@ -65,4 +65,24 @@
#define REG_C_AF 0x20
#define REG_C_MASK 0x70
+static inline uint32_t periodic_period_to_clock(int period_code)
+{
+ if (!period_code) {
+ return 0;
+ }
+
+ if (period_code <= 2) {
+ period_code += 7;
+ }
+ /* period in 32 Khz cycles */
+ return 1 << (period_code - 1);
+}
+
+#define RTC_CLOCK_RATE 32768
+
+static inline int64_t periodic_clock_to_ns(int64_t clocks)
+{
+ return muldiv64(clocks, NANOSECONDS_PER_SECOND, RTC_CLOCK_RATE);
+}
+
#endif