summaryrefslogtreecommitdiffstats
path: root/qemu-timer.c
Commit message (Collapse)AuthorAgeFilesLines
* qemu-timer: Fix wrong error messageStefan Weil2012-05-141-5/+2
| | | | | | | | | Function timeSetEvent returns 0 when it fails, but it does not set an error code which can be retrieved by GetLastError. Therefore calling GetLastError is useless. Signed-off-by: Stefan Weil <sw@weilnetz.de>
* qemu-timer: Move include for __FreeBSD_version to headerAndreas Faerber2012-05-081-4/+0
| | | | | | | | | sys/param.h is needed for __FreeBSD_version. Pointed out by Juergen, thanks. Signed-off-by: Andreas Faerber <andreas.faerber@web.de> Cc: Juergen Lock <nox@jelal.kn-bremen.de> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* qemu-timer: Fix limits for w32 mmtimerStefan Weil2012-05-031-20/+14
| | | | | | | | | | | | | | timeSetEvent only accepts delays in the range which is returned by timeGetDevCaps. The lower limit is typically 1 (= 1 ms), so the constant value of 1 in the old code usually worked. The upper limit can be as low as 10000 ms, so the latest changes in QEMU's timer handling which introduced timeout values above that limit could result in failures of timeSetEvent when the timer was re-armed. Signed-off-by: Stefan Weil <sw@weilnetz.de>
* qemu-timer: Optimize data structuresStefan Weil2012-04-271-7/+7
| | | | | | | | Remove all holes which were found by pahole on Linux x86_64 (and replace "struct QEMUTimer" by "QEMUTimer"). Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Stefan Weil <sw@weilnetz.de>
* qemu-timer: Remove function alarm_has_dynticksStefan Weil2012-04-271-31/+8
| | | | | | | | | | | | | | | | | Some time ago, the last time which did not have dynticks was removed, so now all timers have dynticks. I also removed a misleading error message for the dynticks timer. If timer_create fails, there is already an error message, and QEMU will use the unix timer which also provides dynamic ticks, therefore dynamic ticks are not disabled. v2: Remove two if statements because they were always true (thanks to Paolo Bonzini for this correction). Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Stefan Weil <sw@weilnetz.de>
* qemu-timer: Use bool, false, true for boolean valuesStefan Weil2012-04-271-15/+16
| | | | | | | | | This avoids conversions between int and bool / char. It also makes the code more readable. Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Stefan Weil <sw@weilnetz.de>
* qemu-timer: Remove unused function qemu_alarm_pendingStefan Weil2012-04-271-5/+0
| | | | | | | | The last user of this function was removed by commit 12d4536f7d911b6d87a766ad7300482ea663cea2. Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Stefan Weil <sw@weilnetz.de>
* qemu-timer: Remove redundant include statementsStefan Weil2012-04-271-9/+2
| | | | | | | | | | qemu-timer.h includes qemu-common.h which already includes time.h, sys/time.h, windows.h, unistd.h, fcntl.h, errno.h and signal.h. Therefore those include statements are redundant and can be removed. Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Stefan Weil <sw@weilnetz.de>
* main_loop_wait: block indefinitelyStefano Stabellini2012-04-261-5/+0
| | | | | | | | | | | | | | | - remove qemu_calculate_timeout; - explicitly size timeout to uint32_t; - introduce slirp_update_timeout; - pass NULL as timeout argument to select in case timeout is the maximum value; Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com> Acked-by: Paul Brook <paul@codesourcery.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* qemu_next_alarm_deadline: check the expire time of a clock only if it is enabledStefano Stabellini2012-04-261-6/+4
| | | | | | | | Also delta in qemu_next_alarm_deadline is a 64 bit value so set the default to INT64_MAX instead of INT32_MAX. Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* timers: the rearm function should be able to handle delta = INT64_MAXStefano Stabellini2012-04-261-5/+13
| | | | | | | | | | | | | | Fix win32_rearm_timer and mm_rearm_timer: they should be able to handle INT64_MAX as a delta parameter without overflowing. Also, the next deadline in ms should be calculated rounding down rather than up (see unix_rearm_timer and dynticks_rearm_timer). Finally ChangeTimerQueueTimer takes an unsigned long and timeSetEvent takes an unsigned int as delta, so cast the ms delta to the appropriate unsigned integer. Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* qemu-timer.c: Remove 250us timeoutsPeter Portante2012-04-161-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Basically, the main wait loop calls qemu_run_all_timers() unconditionally. The first thing this routine used to do is to see if a timer had been serviced, and then reset the loop timeout to the next deadline. However, the new deadlines had not been calculated at that point, as qemu_run_timers() had not been called yet for each of the clocks. So qemu_rearm_alarm_timer() would end up with a negative or zero deadline, and default to setting a 250us timeout for the loop. As qemu_run_timers() is called for each clock, the real deadlines would be put in place, but because a loop timeout was already set, the loop timeout would not be changed. Once that 250us timeout fired, the real deadline would be used for the subsequent timeout. For idle VMs, this effectively doubles the number of times through the loop, doubling the number of select() system calls, timer calls, etc. putting added scheduling pressure on the kernel. And under cgroups, this really causes a big problem because the cgroup code does not scale well. By simply running the timers before trying to rearm the timer, we always rearm with a non-zero deadline, effectively halving the number of system calls. Signed-off-by: Peter Portante <pportant@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* qtest: add clock managementPaolo Bonzini2012-03-301-1/+1
| | | | | | | | | | This patch combines qtest and -icount together to turn the vm_clock into a source that can be fully managed by the client. To this end new commands clock_step and clock_set are added. Hooking them with libqtest is left as an exercise to the reader. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* notifier: switch to QLISTPaolo Bonzini2012-02-171-1/+1
| | | | | | | | Notifiers do not need to access both ends of the list, and using a QLIST also simplifies the API. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* remove #if 0 code for timersPaolo Bonzini2012-01-271-29/+0
| | | | | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
* win32: remove broken timersPaolo Bonzini2011-11-091-3/+1
| | | | | | | | The non-dynticks timer variations are broken, so they can be removed. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* qemu-timer: do not use RunState change handlersPaolo Bonzini2011-10-211-8/+4
| | | | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* qemu-timer: move more stuff out of qemu-timer.cPaolo Bonzini2011-10-211-31/+4
| | | | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* qemu-timer: use atexit for quit_timersPaolo Bonzini2011-10-211-7/+8
| | | | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* qemu-timer: do not refer to runstate_is_running()Paolo Bonzini2011-10-211-4/+1
| | | | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* qemu-timer: move icount to cpus.cPaolo Bonzini2011-10-211-279/+0
| | | | | | | None of this is needed by tools, and most of it can even be made static inside cpus.c. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* qemu-timer: more clock functionsPaolo Bonzini2011-10-211-0/+25
| | | | | | | These will be used when moving icount accounting to cpus.c. Reviewed-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* qemu-timer: move common code to qemu_rearm_alarm_timerPaolo Bonzini2011-10-211-76/+53
| | | | | Reviewed-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* qemu-timer: remove active_timers arrayPaolo Bonzini2011-10-211-31/+28
| | | | | | | Embed the list in the QEMUClock instead. Reviewed-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* Drop the vm_running global variableLuiz Capitulino2011-09-151-3/+3
| | | | | | Use runstate_is_running() instead, which is introduced by this commit. Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
* Replace the VMSTOP macros with a proper state typeLuiz Capitulino2011-09-151-1/+2
| | | | | | | | | | | | | | | Today, when notifying a VM state change with vm_state_notify(), we pass a VMSTOP macro as the 'reason' argument. This is not ideal because the VMSTOP macros tell why qemu stopped and not exactly what the current VM state is. One example to demonstrate this problem is that vm_start() calls vm_state_notify() with reason=0, which turns out to be VMSTOP_USER. This commit fixes that by replacing the VMSTOP macros with a proper state type called RunState. Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
* main: force enabling of I/O threadAnthony Liguori2011-09-021-53/+0
| | | | | | | | | | | | | | | | Enabling the I/O thread by default seems like an important part of declaring 1.0. Besides allowing true SMP support with KVM, the I/O thread means that the TCG VCPU doesn't have to multiplex itself with the I/O dispatch routines which currently requires a (racey) signal based alarm system. I know there have been concerns about performance. I think so far the ones that have come up (virtio-net) are most likely due to secondary reasons like decreased batching. I think we ought to force enabling I/O thread early in 1.0 development and commit to resolving any lingering issues. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* Use glib memory allocation and free functionsAnthony Liguori2011-08-201-5/+5
| | | | | | qemu_malloc/qemu_free no longer exist after this commit. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* Register Linux dyntick timer as per-thread signalJan Kiszka2011-07-231-0/+8
| | | | | | | | | | | | | | | | | | Derived from kvm-tool patch http://thread.gmane.org/gmane.comp.emulators.kvm.devel/74309 Ingo Molnar pointed out that sending the timer signal to the whole process, just blocking it everywhere, is suboptimal with an increasing number of threads. QEMU is also using this pattern so far. Linux provides a (non-portable) way to restrict the signal to a single thread: We can use SIGEV_THREAD_ID unless we are forced to emulate signalfd via an additional thread. That case could theoretically be optimized as well, but it doesn't look worth bothering. Reviewed-by: Richard Henderson <rth@twiddle.net> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* qemu-timer: Introduce clock reset notifierJan Kiszka2011-07-231-1/+28
| | | | | | | | | | | | | | | QEMU_CLOCK_HOST is based on the system time which may jump backward in case the admin or NTP adjusts it. RTC emulations and other device models can suffer in this case as timers will stall for the period the clock was tuned back. This adds a detection mechanism that checks on every host clock readout if the new time is before the last result. If that is the case a notifier list is informed. Device models interested in this event can register a notifier with the clock. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* qemu-timer: change unix timer to dynticksPaolo Bonzini2011-07-231-12/+28
| | | | | | | | | | | A timer that wakes up every millisecond puts a lot of stress on the iothread. The large amount of IPIs causes very high context switch activity, making emulation slow and the UI unusable. This is by the way the same reason why the Windows timers were switched to dynticks. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Tested-by: Alexander Graf <agraf@suse.de> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* timer: drop HPET and RTCAnthony Liguori2011-06-061-120/+0
| | | | | | | dynticks will provide equally good timer granularity on all modern Linux systems. This is more or less dead code these days. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* qemu-timer: Fix timers for w32Stefan Weil2011-04-271-0/+96
| | | | | | | | | | | | | Commit 68c23e5520e8286d79d96ab47c0ea722ceb75041 removed the multimedia timer, but this timer is needed for certain Linux kernels. Otherwise Linux boot stops with this error: MP-BIOS bug: 8254 timer not connected to IO-APIC So the multimedia timer is added again here. Cc: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Stefan Weil <weil@mail.berlios.de>
* qemu-timer: Avoid type castsStefan Weil2011-04-271-20/+22
| | | | | | | | The type casts are no longer needed after some small changes in struct qemu_alarm_timer. This also improves readability of the code. Signed-off-by: Stefan Weil <weil@mail.berlios.de>
* qemu-timer: Add and use new function qemu_timer_expired_nsStefan Weil2011-04-271-7/+10
| | | | | | | This simply moves code which is used three times into a new function thus improving readability. Signed-off-by: Stefan Weil <weil@mail.berlios.de>
* qemu_next_deadline should not consider host-time timersPaolo Bonzini2011-04-151-9/+4
| | | | | | | | | It is purely for icount-based virtual timers. And now that we got the code right, rename the function to clarify the intended scope. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Tested-by: Edgar E. Iglesias <edgar.iglesias@gmail.com> Signed-off-by: Edgar E. Iglesias <edgar.iglesias@gmail.com>
* Revert wrong fixes for -icount in the iothread casePaolo Bonzini2011-04-151-30/+36
| | | | | | | | | This reverts commits 225d02cd and c9f7383c. While some parts of the latter could be saved, I preferred a smooth, complete revert. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Tested-by: Edgar E. Iglesias <edgar.iglesias@gmail.com> Signed-off-by: Edgar E. Iglesias <edgar.iglesias@gmail.com>
* enable vm_clock to "warp" in the iothread+icount casePaolo Bonzini2011-04-151-1/+93
| | | | | | | | | | | | | | | | | | | | | | | | | | The previous patch however is not enough, because if the virtual CPU goes to sleep waiting for a future timer interrupt to wake it up, qemu deadlocks. The timer interrupt never comes because time is driven by icount, but the vCPU doesn't run any insns. You could say that VCPUs should never go to sleep in icount mode if there is a pending vm_clock timer; rather time should just warp to the next vm_clock event with no sleep ever taking place. Even better, you can sleep for some time related to the time left until the next event, to avoid that the warps are too visible externally; for example, you could be sending network packets continously instead of every 100ms. This is what this patch implements. qemu_clock_warp is called: 1) whenever a vm_clock timer is adjusted, to ensure the warp_timer is synchronized; 2) at strategic points in the CPU thread, to make sure the insn counter is synchronized before the CPU starts running. In any case, the warp_timer is disabled while the CPU is running, because the insn counter will then be making progress on its own. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Tested-by: Edgar E. Iglesias <edgar.iglesias@gmail.com> Signed-off-by: Edgar E. Iglesias <edgar.iglesias@gmail.com>
* remove qemu_get_clockPaolo Bonzini2011-03-211-17/+0
| | | | | | | | | | These patches are already not doing a great service to out-of-tree modifications to QEMU. However, at least we can warn them by getting rid of the old confusing functions, or otherwise causing compilation errors. This patch removes qemu_get_clock; the previous one changed qemu_new_timer's signature. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* add a generic scaling mechanism for timersPaolo Bonzini2011-03-211-8/+17
| | | | | | | | | | | This enables rt_clock timers to use nanosecond resolution, just by using the _ns functions; there is really no reason to forbid that. Migrated timers are all using vm_clock (of course; but I checked that anyway) so the timers in the savevm files are already in nanosecond resolution. So this patch makes no change to the migration format. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* change all other clock references to use nanosecond resolution accessorsPaolo Bonzini2011-03-211-6/+6
| | | | | | | | | | | | | | | | | | | | | | This was done with: sed -i 's/qemu_get_clock\>/qemu_get_clock_ns/' \ $(git grep -l 'qemu_get_clock\>' ) sed -i 's/qemu_new_timer\>/qemu_new_timer_ns/' \ $(git grep -l 'qemu_new_timer\>' ) after checking that get_clock and new_timer never occur twice on the same line. There were no missed occurrences; however, even if there had been, they would have been caught by the compiler. There was exactly one false positive in qemu_run_timers: - current_time = qemu_get_clock (clock); + current_time = qemu_get_clock_ns (clock); which is of course not in this patch. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* change all rt_clock references to use millisecond resolution accessorsPaolo Bonzini2011-03-211-3/+3
| | | | | | | | | | | | | | | This was done with: sed -i '/get_clock\>.*rt_clock/s/get_clock\>/get_clock_ms/' \ $(git grep -l 'get_clock\>.*rt_clock' ) sed -i '/new_timer\>.*rt_clock/s/new_timer\>/new_timer_ms/' \ $(git grep -l 'new_timer\>.*rt_clock' ) after checking that get_clock and new_timer never occur twice on the same line. There were no missed occurrences; however, even if there had been, they would have been caught by the compiler. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* use win32 timer queuesPaolo Bonzini2011-03-131-51/+35
| | | | | | | | Multimedia timers are only useful for compatibility with Windows NT 4.0 and earlier. Plus, the implementation in Wine is extremely heavyweight. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* implement win32 dynticks timerPaolo Bonzini2011-03-131-1/+6
| | | | | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* do not use qemu_icount_delta in the !use_icount casePaolo Bonzini2011-02-231-34/+25
| | | | | | | | | | | | The !use_icount code is the same for iothread and non-iothread, except that the timeout is different. Since the timeout might as well be infinite and is only masking bugs, use the higher value. With this change the !use_icount code is handled equivalently in qemu_icount_delta and qemu_calculate_timeout, and we rip it out of the former. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Edgar E. Iglesias <edgar.iglesias@petalogix.com>
* qemu-timer: Fix compilation of new timer code for w32, w64Stefan Weil2011-02-071-2/+2
| | | | | | | | | | qemu_next_alarm_deadline() is needed by MinGW, too. Cc: Paolo Bonzini <pbonzini@redhat.com> Cc: Anthony Liguori <aliguori@us.ibm.com> Acked-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Stefan Weil <weil@mail.berlios.de> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* Unify alarm deadline computationPaolo Bonzini2011-02-041-17/+11
| | | | | | | | | This patch shows how using the correct formula for qemu_next_deadline_dyntick can simplify the code of host_alarm_handler and eliminate useless duplication. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* Correct alarm deadline computationPaolo Bonzini2011-02-041-4/+11
| | | | | | | | | | | | | | | | When the QEMU_CLOCK_HOST clock was added, computation of its deadline was added to qemu_next_deadline, which is correct but incomplete. I noticed this by reading the very convoluted rules whereby qemu_next_deadline_dyntick is computed, which miss QEMU_CLOCK_HOST when use_icount is true. This patch inlines qemu_next_deadline into qemu_next_deadline_dyntick, and then corrects the logic to skip only QEMU_CLOCK_VIRTUAL when use_icount is true. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Cc: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* use nanoseconds everywhere for timeout computationPaolo Bonzini2011-02-041-16/+16
| | | | | | | Suggested by Aurelien Jarno. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* Avoid deadlock whith iothread and icountEdgar E. Iglesias2011-01-231-6/+9
| | | | | | | | When using the iothread together with icount, make sure the qemu_icount counter makes forward progress when the vcpu is idle to avoid deadlocks. Signed-off-by: Edgar E. Iglesias <edgar.iglesias@gmail.com>
OpenPOWER on IntegriCloud