summaryrefslogtreecommitdiff
path: root/qemu-timer.c
AgeCommit message (Collapse)AuthorFilesLines
2012-12-19softmmu: move include files to include/sysemu/Paolo Bonzini1-1/+1
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-12-19misc: move include files to include/qemu/Paolo Bonzini1-2/+2
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-12-19monitor: move include files to include/monitor/Paolo Bonzini1-1/+1
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-12-19ui: move files to ui/ and include/ui/Paolo Bonzini1-1/+1
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-12-19net: do not include net.h everywherePaolo Bonzini1-1/+0
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-11-10qemu-timer: Fix compilation for non-POSIX hostsStefan Weil1-0/+2
A compiler warning is caused by the unused local function reinit_timers on non-POSIX hosts. Include that function only for POSIX hosts. Signed-off-by: Stefan Weil <sw@weilnetz.de> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
2012-11-04build: pthread_atfork() needs include of pthread.hAnthony Liguori1-0/+3
Cc: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-11-02qemu-timer: reinitialize timers after forkPaolo Bonzini1-0/+14
Timers are not inherited by the child of a fork(2), so just use pthread_atfork to reinstate them after daemonize. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-10-31Merge remote-tracking branch 'origin/master' into threadpoolPaolo Bonzini1-2/+2
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-10-30qemu-timer: make initialization functions idempotentPaolo Bonzini1-3/+9
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-10-28qemu-timer: Check for usable fields for SIGEV_THREAD_IDRichard Henderson1-2/+2
Older glibc (RHEL 5.x, Debian 5.x) does not have the _sigev_un._tid member in its structure definition, while the accompanying kernel headers do define SIGEV_THREAD_ID. We need configure to check for both before using it. Signed-off-by: Richard Henderson <rth@twiddle.net> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2012-09-23qemu-timer: simplify qemu_run_timersPaolo Bonzini1-4/+3
ptimer_head is an invariant pointer to clock->active_timers. Remove it, and just reference clock->active_timers directly. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Stefan Hajnoczi <stefanha@gmail.com>
2012-09-04qemu-timer: properly arm alarm timer for timers set by device initializationPaolo Bonzini1-3/+0
QEMU will hang when fed the following command-line qemu-system-mips -kernel vmlinux-2.6.32-5-4kc-malta -append "console=ttyS0" -nographic -net none The -net none is important otherwise it seems some events are generated causing the things to work. When it doesn't work, the guest hangs when measuring the CPU frequency, after the following line: [ 0.000000] NR_IRQS:256 Pressing a key on the serial port unblocks it, hinting that the problem is due to the recent elimination of the 1 second timeout in the main loop. The problem is that because init_timer_alarm sets the timer's pending flag to true, the alarm timer is never armed until after the first time through the main loop. Thus the bug started when QEMU started testing the pending flag in qemu_mod_timer (commit 1828be3, more alarm timer cleanup, 2010-03-10). But actually, it isn't true at all that a timer is pending when the alarm timer is created, and the real bug has been latent forever: the fix is to remove the bogus setting of pending flag. Reported-by: Aurelien Jarno <aurelien@aurel32.net> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Jan Kiszka <jan.kiszka@siemens.com> Tested-by: Aurelien Jarno <aurelien@aurel32.net> Tested-by: Michael Tokarev <mjt@tls.msk.ru> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2012-08-09qemu_rearm_alarm_timer: do not call rearm if the next deadline is INT64_MAXStefano Stabellini1-7/+3
qemu_rearm_alarm_timer partially duplicates the code in qemu_next_alarm_deadline to figure out if it needs to rearm the timer. If it calls qemu_next_alarm_deadline, it always rearms the timer even if the next deadline is INT64_MAX. This patch simplifies the behavior of qemu_rearm_alarm_timer and removes the duplicated code, always calling qemu_next_alarm_deadline and only rearming the timer if the deadline is less than INT64_MAX. Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com> Reviewed-by: Stefan Weil <sw@weilnetz.de> Tested-by: Andreas Färber <andreas.faerber@web.de> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
2012-08-02Support 'help' as a synonym for '?' in command line optionsPeter Maydell1-1/+1
For command line options which permit '?' meaning 'please list the permitted values', add support for 'help' as a synonym, by abstracting the check out into a helper function. This change means that in some cases where we were being lazy in our string parsing, "?junk" will now be rejected as an invalid option rather than being (undocumentedly) treated the same way as "?". Update the documentation to use 'help' rather than '?', since '?' is a shell metacharacter and thus prone to fail confusingly if there is a single character filename in the current working directory and the '?' has not been escaped. It's therefore better to steer users towards 'help', though '?' is retained for backwards compatibility. We do not, however, update the output of the system emulator's -help (or any documentation autogenerated from the qemu-options.hx which is the source of the -help text) because libvirt parses our -help output and will break. At a later date when QEMU provides a better interface so libvirt can avoid having to do this, we can update the -help text too. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-05-14qemu-timer: Fix wrong error messageStefan Weil1-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>
2012-05-08qemu-timer: Move include for __FreeBSD_version to headerAndreas Faerber1-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>
2012-05-03qemu-timer: Fix limits for w32 mmtimerStefan Weil1-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>
2012-04-27qemu-timer: Optimize data structuresStefan Weil1-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>
2012-04-27qemu-timer: Remove function alarm_has_dynticksStefan Weil1-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>
2012-04-27qemu-timer: Use bool, false, true for boolean valuesStefan Weil1-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>
2012-04-27qemu-timer: Remove unused function qemu_alarm_pendingStefan Weil1-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>
2012-04-27qemu-timer: Remove redundant include statementsStefan Weil1-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>
2012-04-26main_loop_wait: block indefinitelyStefano Stabellini1-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>
2012-04-26qemu_next_alarm_deadline: check the expire time of a clock only if it is enabledStefano Stabellini1-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>
2012-04-26timers: the rearm function should be able to handle delta = INT64_MAXStefano Stabellini1-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>
2012-04-16qemu-timer.c: Remove 250us timeoutsPeter Portante1-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>
2012-03-30qtest: add clock managementPaolo Bonzini1-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>
2012-02-17notifier: switch to QLISTPaolo Bonzini1-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>
2012-01-27remove #if 0 code for timersPaolo Bonzini1-29/+0
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
2011-11-09win32: remove broken timersPaolo Bonzini1-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>
2011-10-21qemu-timer: do not use RunState change handlersPaolo Bonzini1-8/+4
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2011-10-21qemu-timer: move more stuff out of qemu-timer.cPaolo Bonzini1-31/+4
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2011-10-21qemu-timer: use atexit for quit_timersPaolo Bonzini1-7/+8
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2011-10-21qemu-timer: do not refer to runstate_is_running()Paolo Bonzini1-4/+1
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2011-10-21qemu-timer: move icount to cpus.cPaolo Bonzini1-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>
2011-10-21qemu-timer: more clock functionsPaolo Bonzini1-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>
2011-10-21qemu-timer: move common code to qemu_rearm_alarm_timerPaolo Bonzini1-76/+53
Reviewed-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2011-10-21qemu-timer: remove active_timers arrayPaolo Bonzini1-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>
2011-09-15Drop the vm_running global variableLuiz Capitulino1-3/+3
Use runstate_is_running() instead, which is introduced by this commit. Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
2011-09-15Replace the VMSTOP macros with a proper state typeLuiz Capitulino1-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>
2011-09-02main: force enabling of I/O threadAnthony Liguori1-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>
2011-08-20Use glib memory allocation and free functionsAnthony Liguori1-5/+5
qemu_malloc/qemu_free no longer exist after this commit. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-07-23Register Linux dyntick timer as per-thread signalJan Kiszka1-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>
2011-07-23qemu-timer: Introduce clock reset notifierJan Kiszka1-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>
2011-07-23qemu-timer: change unix timer to dynticksPaolo Bonzini1-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>
2011-06-06timer: drop HPET and RTCAnthony Liguori1-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>
2011-04-27qemu-timer: Fix timers for w32Stefan Weil1-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>
2011-04-27qemu-timer: Avoid type castsStefan Weil1-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>
2011-04-27qemu-timer: Add and use new function qemu_timer_expired_nsStefan Weil1-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>