* [Qemu-devel] [PATCH 0/2] cpu-exec: simplify -icount align
@ 2015-01-28 9:36 Paolo Bonzini
2015-01-28 9:36 ` [Qemu-devel] [PATCH 1/2] cpu-exec: simplify align_clocks Paolo Bonzini
2015-01-28 9:36 ` [Qemu-devel] [PATCH 2/2] cpu-exec: simplify init_delay_params Paolo Bonzini
0 siblings, 2 replies; 3+ messages in thread
From: Paolo Bonzini @ 2015-01-28 9:36 UTC (permalink / raw)
To: qemu-devel; +Cc: Sebastian Tanase
Two simplifications to the -icount align code.
Paolo Bonzini (2):
cpu-exec: simplify align_clocks
cpu-exec: simplify init_delay_params
cpu-exec.c | 9 +++------
cpus.c | 17 -----------------
include/qemu/timer.h | 1 -
3 files changed, 3 insertions(+), 24 deletions(-)
--
2.1.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Qemu-devel] [PATCH 1/2] cpu-exec: simplify align_clocks
2015-01-28 9:36 [Qemu-devel] [PATCH 0/2] cpu-exec: simplify -icount align Paolo Bonzini
@ 2015-01-28 9:36 ` Paolo Bonzini
2015-01-28 9:36 ` [Qemu-devel] [PATCH 2/2] cpu-exec: simplify init_delay_params Paolo Bonzini
1 sibling, 0 replies; 3+ messages in thread
From: Paolo Bonzini @ 2015-01-28 9:36 UTC (permalink / raw)
To: qemu-devel; +Cc: Sebastian Tanase
sc->diff_clk is already equal to sleep_delay (split in a second and a
nanosecond part). If you subtract sleep_delay - rem_delay, the result
is exactly rem_delay.
Cc: Sebastian Tanase <sebastian.tanase@openwide.fr>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
cpu-exec.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/cpu-exec.c b/cpu-exec.c
index a4f0eff..ef0f12c 100644
--- a/cpu-exec.c
+++ b/cpu-exec.c
@@ -61,8 +61,7 @@ static void align_clocks(SyncClocks *sc, const CPUState *cpu)
sleep_delay.tv_sec = sc->diff_clk / 1000000000LL;
sleep_delay.tv_nsec = sc->diff_clk % 1000000000LL;
if (nanosleep(&sleep_delay, &rem_delay) < 0) {
- sc->diff_clk -= (sleep_delay.tv_sec - rem_delay.tv_sec) * 1000000000LL;
- sc->diff_clk -= sleep_delay.tv_nsec - rem_delay.tv_nsec;
+ sc->diff_clk = rem_delay.tv_sec * 1000000000LL + rem_delay.tv_nsec;
} else {
sc->diff_clk = 0;
}
--
2.1.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [Qemu-devel] [PATCH 2/2] cpu-exec: simplify init_delay_params
2015-01-28 9:36 [Qemu-devel] [PATCH 0/2] cpu-exec: simplify -icount align Paolo Bonzini
2015-01-28 9:36 ` [Qemu-devel] [PATCH 1/2] cpu-exec: simplify align_clocks Paolo Bonzini
@ 2015-01-28 9:36 ` Paolo Bonzini
1 sibling, 0 replies; 3+ messages in thread
From: Paolo Bonzini @ 2015-01-28 9:36 UTC (permalink / raw)
To: qemu-devel; +Cc: Sebastian Tanase
With the introduction of QEMU_CLOCK_VIRTUAL_RT, the computation of
sc->diff_clk can be simplified nicely:
qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) -
qemu_clock_get_ns(QEMU_CLOCK_REALTIME) +
cpu_get_clock_offset()
= qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) -
(qemu_clock_get_ns(QEMU_CLOCK_REALTIME) - cpu_get_clock_offset())
= qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) -
(qemu_clock_get_ns(QEMU_CLOCK_REALTIME) + timers_state.cpu_clock_offset)
= qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) -
qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL_RT)
Cc: Sebastian Tanase <sebastian.tanase@openwide.fr>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
cpu-exec.c | 8 +++-----
cpus.c | 17 -----------------
include/qemu/timer.h | 1 -
3 files changed, 3 insertions(+), 23 deletions(-)
diff --git a/cpu-exec.c b/cpu-exec.c
index ef0f12c..fa506e6 100644
--- a/cpu-exec.c
+++ b/cpu-exec.c
@@ -61,7 +61,7 @@ static void align_clocks(SyncClocks *sc, const CPUState *cpu)
sleep_delay.tv_sec = sc->diff_clk / 1000000000LL;
sleep_delay.tv_nsec = sc->diff_clk % 1000000000LL;
if (nanosleep(&sleep_delay, &rem_delay) < 0) {
- sc->diff_clk = rem_delay.tv_sec * 1000000000LL + rem_delay.tv_nsec;
+ sc->diff_clk = rem_delay.tv_sec * 1000000000LL + rem_delay.tv_nsec;
} else {
sc->diff_clk = 0;
}
@@ -100,10 +100,8 @@ static void init_delay_params(SyncClocks *sc,
if (!icount_align_option) {
return;
}
- sc->realtime_clock = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
- sc->diff_clk = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) -
- sc->realtime_clock +
- cpu_get_clock_offset();
+ sc->realtime_clock = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL_RT);
+ sc->diff_clk = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) - sc->realtime_clock;
sc->last_cpu_icount = cpu->icount_extra + cpu->icount_decr.u16.low;
if (sc->diff_clk < max_delay) {
max_delay = sc->diff_clk;
diff --git a/cpus.c b/cpus.c
index 2edb5cd..b8bd127 100644
--- a/cpus.c
+++ b/cpus.c
@@ -229,23 +229,6 @@ int64_t cpu_get_clock(void)
return ti;
}
-/* return the offset between the host clock and virtual CPU clock */
-int64_t cpu_get_clock_offset(void)
-{
- int64_t ti;
- unsigned start;
-
- do {
- start = seqlock_read_begin(&timers_state.vm_clock_seqlock);
- ti = timers_state.cpu_clock_offset;
- if (!timers_state.cpu_ticks_enabled) {
- ti -= get_clock();
- }
- } while (seqlock_read_retry(&timers_state.vm_clock_seqlock, start));
-
- return -ti;
-}
-
/* enable cpu_get_ticks()
* Caller must hold BQL which server as mutex for vm_clock_seqlock.
*/
diff --git a/include/qemu/timer.h b/include/qemu/timer.h
index d9df094..ff4e794 100644
--- a/include/qemu/timer.h
+++ b/include/qemu/timer.h
@@ -754,7 +754,6 @@ static inline int64_t get_clock(void)
int64_t cpu_get_icount_raw(void);
int64_t cpu_get_icount(void);
int64_t cpu_get_clock(void);
-int64_t cpu_get_clock_offset(void);
int64_t cpu_icount_to_ns(int64_t icount);
/*******************************************/
--
2.1.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-01-28 9:36 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-28 9:36 [Qemu-devel] [PATCH 0/2] cpu-exec: simplify -icount align Paolo Bonzini
2015-01-28 9:36 ` [Qemu-devel] [PATCH 1/2] cpu-exec: simplify align_clocks Paolo Bonzini
2015-01-28 9:36 ` [Qemu-devel] [PATCH 2/2] cpu-exec: simplify init_delay_params Paolo Bonzini
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).