Patch queue for w32/w64
The following changes since commit 9438fe9e56760e5e5e11d6c7d12ed9c64a0c8446:
Merge remote-tracking branch 'remotes/elmarco/tags/rm-libcacard' into staging (2015-09-24 17:04:31 +0100)
are available in the git repository at:
git://qemu.weilnetz.de/qemu.git tags/pull-wxx-20150924
for you to fetch changes up to 4d9310f427b477a126f6f2006c3a73b9764948b6:
oslib-win32: only provide localtime_r/gmtime_r if missing (2015-09-24 21:13:49 +0200)
----------------------------------------------------------------
wxx patch queue
- Faster Win32 QemuEvent
- Fixes needed for latest Mingw-w64 build environment
- Version information in QEMU installer for Windows
----------------------------------------------------------------
Daniel P. Berrange (2):
gtk: avoid redefining _WIN32_WINNT macro
oslib-win32: only provide localtime_r/gmtime_r if missing
Paolo Bonzini (1):
qemu-thread: add a fast path to the Win32 QemuEvent
Stefan Weil (2):
nsis: Add QEMU version information to Windows registry
slirp: Fix non blocking connect for w32
Makefile | 1 + configure | 34 ++++++++++++++++++++++++++++++++++ docs/win32-qemu-event.promela | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ include/qemu/osdep.h | 4 +++- include/qemu/thread-win32.h | 1 + include/sysemu/os-win32.h | 2 ++ include/ui/gtk.h | 4 ---- qemu.nsi | 3 +++ slirp/tcp_input.c | 8 +++++++- ui/gtk.c | 9 +++++++++ util/oslib-win32.c | 2 ++ util/qemu-thread-win32.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 12 files changed, 222 insertions(+), 10 deletions(-) create mode 100644 docs/win32-qemu-event.promela
[PULL 1/5] nsis: Add QEMU version information to Windows registry [PULL 2/5] slirp: Fix non blocking connect for w32
[PULL 3/5] qemu-thread: add a fast path to the Win32 QemuEvent [PULL 4/5] gtk: avoid redefining _WIN32_WINNT macro
[PULL 5/5] oslib-win32: only provide localtime_r/gmtime_r if missing
[Qemu-devel] [PULL 1/5] nsis: Add QEMU version information to Windows registry
The uninstall keys include an option key "DisplayVersion" which we set now. By default the version value is read from file VERSION, but it is also possible to pass VERSION=#.#.# to make.
--- Makefile | 1 + qemu.nsi | 3 +++ 2 files changed, 4 insertions(+)
Makefile +1 -0
@@ -623,6 +623,7 @@ endif # SIGNCODE $(if $(DLL_PATH),-DDLLDIR="$(DLL_PATH)") \ -DSRCDIR="$(SRC_PATH)" \ -DOUTFILE="$(INSTALLER)" \ + -DDISPLAYVERSION="$(VERSION)" \ $(SRC_PATH)/qemu.nsi rm -r ${INSTDIR} ifdef SIGNCODE
qemu.nsi +3 -0
@@ -139,6 +139,9 @@ Section "${PRODUCT} (required)" ; Write the uninstall keys for Windows WriteRegStr HKLM "${UNINST_KEY}" "DisplayName" "QEMU" +!ifdef DISPLAYVERSION + WriteRegStr HKLM "${UNINST_KEY}" "DisplayVersion" "${DISPLAYVERSION}" +!endif WriteRegStr HKLM "${UNINST_KEY}" "UninstallString" '"${UNINST_EXE}"' WriteRegDWORD HKLM "${UNINST_KEY}" "NoModify" 1 WriteRegDWORD HKLM "${UNINST_KEY}" "NoRepair" 1
Signature · 1 line
2.1.4
[Qemu-devel] [PULL 2/5] slirp: Fix non blocking connect for w32
In reply to Stefan Weil--- slirp/tcp_input.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
slirp/tcp_input.c +7 -1
@@ -584,7 +584,13 @@ findso: goto cont_input; } -if ((tcp_fconnect (so) ==-1 ) && (errno !=EINPROGRESS ) && (errno !=EWOULDBLOCK )) { +if ((tcp_fconnect (so) ==-1 ) && +#if defined(_WIN32) + socket_error() != WSAEWOULDBLOCK +#else + (errno != EINPROGRESS) && (errno != EWOULDBLOCK) +#endif + ) {u_char code=ICMP_UNREACH_NET ;DEBUG_MISC ((dfd," tcp fconnect errno = %d-%s\n" , errno,strerror (errno)));
Signature · 1 line
2.1.4
[Qemu-devel] [PULL 3/5] qemu-thread: add a fast path to the Win32 QemuEvent
In reply to Stefan WeilFrom: Paolo Bonzini <[email protected]>
QemuEvents are used heavily by call_rcu. We do not want them to be slow, but the current implementation does a kernel call on every invocation of qemu_event_* and won't cut it.
So, wrap a Win32 manual-reset event with a fast userspace path. The states and transitions are the same as for the futex and mutex/condvar implementations, but the slow path is different of course. The idea is to reset the Win32 event lazily, as part of a test-reset-test-wait sequence. Such a sequence is, indeed, how QemuEvents are used by RCU and other subsystems!
The patch includes a formal model of the algorithm.
--- docs/win32-qemu-event.promela | 98 +++++++++++++++++++++++++++++++++++++++++++ include/qemu/thread-win32.h | 1 + util/qemu-thread-win32.c | 66 +++++++++++++++++++++++++++-- 3 files changed, 161 insertions(+), 4 deletions(-) create mode 100644 docs/win32-qemu-event.promela
docs/win32-qemu-event.promela new file +98 -0
@@ -0,0 +1,98 @@ +/* + * This model describes the implementation of QemuEvent in + * util/qemu-thread-win32.c. + * + * Author: Paolo Bonzini <[email protected]> + * + * This file is in the public domain. If you really want a license, + * the WTFPL will do. + * + * To verify it: + * spin -a docs/event.promela + * gcc -O2 pan.c -DSAFETY + * ./a.out + */ + +bool event; +int value; + +/* Primitives for a Win32 event */ +#define RAW_RESET event = false +#define RAW_SET event = true +#define RAW_WAIT do :: event -> break; od + +#if 0 +/* Basic sanity checking: test the Win32 event primitives */ +#define RESET RAW_RESET +#define SET RAW_SET +#define WAIT RAW_WAIT +#else +/* Full model: layer a userspace-only fast path on top of the RAW_* + * primitives. SET/RESET/WAIT have exactly the same semantics as + * RAW_SET/RAW_RESET/RAW_WAIT, but try to avoid invoking them. + */ +#define EV_SET 0 +#define EV_FREE 1 +#define EV_BUSY -1 + +int state = EV_FREE; + +int xchg_result; +#define SET if :: state != EV_SET -> \ + atomic { /* xchg_result=xchg(state, EV_SET) */ \ + xchg_result = state; \ + state = EV_SET; \ + } \ + if :: xchg_result == EV_BUSY -> RAW_SET; \ + :: else -> skip; \ + fi; \ + :: else -> skip; \ + fi + +#define RESET if :: state == EV_SET -> atomic { state = state | EV_FREE; } \ + :: else -> skip; \ + fi + +int tmp1, tmp2; +#define WAIT tmp1 = state; \ + if :: tmp1 != EV_SET -> \ + if :: tmp1 == EV_FREE -> \ + RAW_RESET; \ + atomic { /* tmp2=cas(state, EV_FREE, EV_BUSY) */ \ + tmp2 = state; \ + if :: tmp2 == EV_FREE -> state = EV_BUSY; \ + :: else -> skip; \ + fi; \ + } \ + if :: tmp2 == EV_SET -> tmp1 = EV_SET; \ + :: else -> tmp1 = EV_BUSY; \ + fi; \ + :: else -> skip; \ + fi; \ + assert(tmp1 != EV_FREE); \ + if :: tmp1 == EV_BUSY -> RAW_WAIT; \ + :: else -> skip; \ + fi; \ + :: else -> skip; \ + fi +#endif + +active proctype waiter() +{ + if + :: !value -> + RESET; + if + :: !value -> WAIT; + :: else -> skip; + fi; + :: else -> skip; + fi; + assert(value); +} + +active proctype notifier() +{ + value = true; + SET; +}
include/qemu/thread-win32.h +1 -0
@@ -18,6 +18,7 @@ struct QemuSemaphore { };struct QemuEvent { +int value;HANDLE event; };
util/qemu-thread-win32.c +62 -4
89 lines not on this page · raw message
Signature · 1 line
2.1.4
[Qemu-devel] [PULL 4/5] gtk: avoid redefining _WIN32_WINNT macro
In reply to Stefan WeilFrom: "Daniel P. Berrange" <[email protected]>
When building for Mingw64 target on Fedora 22 a warning is issued about _WIN32_WINNT being redefined.
In file included from ui/gtk.c:40:0:include/ui/gtk.h:5:0: warning: "_WIN32_WINNT" redefined
# define _WIN32_WINNT 0x0601 /* needed to get definition of MAPVK_VK_TO_VSC */
^
In file included from /usr/i686-w64-mingw32/sys-root/mingw/include/crtdefs.h:10:0,
from /usr/i686-w64-mingw32/sys-root/mingw/include/stdio.h:9,
from /home/berrange/src/virt/qemu/include/qemu/fprintf-fn.h:12,
from /home/berrange/src/virt/qemu/include/qemu-common.h:18,
from ui/gtk.c:37:
/usr/i686-w64-mingw32/sys-root/mingw/include/_mingw.h:225:0: note: this is the location of the previous definition
#define _WIN32_WINNT 0x502
^Rather than try to get MAPVK_VK_TO_VSC defined indirectly by defining _WIN32_WINNT, instead just define it explicitly if missing.
--- include/ui/gtk.h | 4 ---- ui/gtk.c | 9 +++++++++ 2 files changed, 9 insertions(+), 4 deletions(-)
include/ui/gtk.h +0 -4
@@ -1,10 +1,6 @@#ifndef UI_GTK_H #define UI_GTK_H -#ifdef _WIN32 -# define _WIN32_WINNT 0x0601/* needed to get definition of MAPVK_VK_TO_VSC */ -#endif -#ifdef CONFIG_PRAGMA_DIAGNOSTIC_AVAILABLE /* Work around an -Wstrict-prototypes warning in GTK headers */ #pragma GCC diagnostic push
ui/gtk.c +9 -0
@@ -104,6 +104,15 @@#define GDK_KEY_Pause GDK_Pause#endif +/* Some older mingw versions lack this constant or have +* it conditionally defined */ +#ifdef _WIN32 +# ifndef MAPVK_VK_TO_VSC +# define MAPVK_VK_TO_VSC 0 +# endif +#endif + +#define HOTKEY_MODIFIERS (GDK_CONTROL_MASK | GDK_MOD1_MASK)static const int modifier_keycode[] = {
Signature · 1 line
2.1.4
[Qemu-devel] [PULL 5/5] oslib-win32: only provide localtime_r/gmtime_r if missing
In reply to Stefan WeilFrom: "Daniel P. Berrange" <[email protected]>
The oslib-win32 file currently provides a localtime_r and gmtime_r replacement unconditionally. Some versions of Mingw-w64 would provide crude macros for localtime_r/gmtime_r which QEMU takes care to disable. Latest versions of Mingw-w64 now provide actual functions for localtime_r/gmtime_r, but with a twist that you have to include unistd.h or pthread.h before including time.h. By luck some files in QEMU have such an include order, resulting in compile errors:
CC util/osdep.o
In file included from include/qemu-common.h:48:0,
from util/osdep.c:48:
include/sysemu/os-win32.h:77:12: error: redundant redeclaration of 'gmtime_r' [-Werror=redundant-decls]
struct tm *gmtime_r(const time_t *timep, struct tm *result);
^
In file included from include/qemu-common.h:35:0,
from util/osdep.c:48:
/usr/i686-w64-mingw32/sys-root/mingw/include/time.h:272:107: note: previous definition of 'gmtime_r' was here
In file included from include/qemu-common.h:48:0,
from util/osdep.c:48:
include/sysemu/os-win32.h:79:12: error: redundant redeclaration of 'localtime_r' [-Werror=redundant-decls]
struct tm *localtime_r(const time_t *timep, struct tm *result);
^
In file included from include/qemu-common.h:35:0,
from util/osdep.c:48:/usr/i686-w64-mingw32/sys-root/mingw/include/time.h:269:107: note: previous definition of 'localtime_r' was here
This change adds a configure test to see if localtime_r exits, and only enables the QEMU impl if missing. We also re-arrange qemu-common.h try attempt to guarantee that all source files get unistd.h before time.h and thus see the localtime_r/gmtime_r defs.
[sw: Use "official" spellings for Mingw-w64, MinGW in comments.] [sw: Terminate sentences with a dot in comments.]
--- configure | 34 ++++++++++++++++++++++++++++++++++ include/qemu/osdep.h | 4 +++- include/sysemu/os-win32.h | 2 ++ util/oslib-win32.c | 2 ++ 4 files changed, 41 insertions(+), 1 deletion(-)
configure +34 -0
@@ -1737,6 +1737,37 @@ else fi ########################################## +# MinGW / Mingw-w64 localtime_r/gmtime_r check + +if test "$mingw32" = "yes"; then + # Some versions of MinGW / Mingw-w64 lack localtime_r + # and gmtime_r entirely. + # + # Some versions of Mingw-w64 define a macro for + # localtime_r/gmtime_r. + # + # Some versions of Mingw-w64 will define functions + # for localtime_r/gmtime_r, but only if you have + # _POSIX_THREAD_SAFE_FUNCTIONS defined. For fun + # though, unistd.h and pthread.h both define + # that for you. + # + # So this #undef localtime_r and #include <unistd.h> + # are not in fact redundant. +cat > $TMPC << EOF +#include <unistd.h> +#include <time.h> +#undef localtime_r +int main(void) { localtime_r(NULL, NULL); return 0; } +EOF + if compile_prog "" "" ; then + localtime_r="yes" + else + localtime_r="no" + fi +fi + +########################################## # pkg-config probe if ! has "$pkg_config_exe"; then
@@ -5034,6 +5065,9 @@ fi if test "$zero_malloc" = "yes" ; then echo "CONFIG_ZERO_MALLOC=y" >> $config_host_mak fi +if test "$localtime_r" = "yes" ; then + echo "CONFIG_LOCALTIME_R=y" >> $config_host_mak +fi if test "$qom_cast_debug" = "yes" ; then echo "CONFIG_QOM_CAST_DEBUG=y" >> $config_host_mak fi
include/qemu/osdep.h +3 -1
@@ -38,10 +38,12 @@#include <strings.h> #include <inttypes.h> #include <limits.h> +/* Put unistd.h before time.h as that triggers localtime_r/gmtime_r +* function availability on recentish Mingw-w64 platforms. */ +#include <unistd.h> #include <time.h> #include <ctype.h> #include <errno.h> -#include <unistd.h> #include <fcntl.h> #include <sys/stat.h> #include <sys/time.h>
include/sysemu/os-win32.h +2 -0
@@ -73,10 +73,12 @@#define siglongjmp (env, val) longjmp(env, val)/* Missing POSIX functions. Don't use MinGW-w64 macros. */ +#ifndef CONFIG_LOCALTIME_R #undef gmtime_rstruct tm *gmtime_r (const time_t *timep,struct tm *result);#undef localtime_rstruct tm *localtime_r (const time_t *timep,struct tm *result); +#endif /* CONFIG_LOCALTIME_R */ static inline void os_setup_signal_handling (void ) {}
util/oslib-win32.c +2 -0
@@ -95,6 +95,7 @@ void qemu_anon_ram_free(void *ptr, size_t size) } } +#ifndef CONFIG_LOCALTIME_R /* FIXME: add proper locking */ struct tm *gmtime_r (const time_t *timep,struct tm *result) {
@@ -118,6 +119,7 @@ struct tm *localtime_r(const time_t *timep, struct tm *result) }return p; } +#endif /* CONFIG_LOCALTIME_R */ void qemu_set_block (int fd) {
Signature · 1 line
2.1.4
Peter Maydell
AppliedQuoted 12 lines · Stefan Weil
The following changes since commit
9438fe9e56760e5e5e11d6c7d12ed9c64a0c8446:Merge remote-tracking branch 'remotes/elmarco/tags/rm-libcacard' into staging (2015-09-24 17:04:31 +0100)
are available in the git repository at:
git://qemu.weilnetz.de/qemu.gittags/pull-wxx-20150924for you to fetch changes up to
4d9310f427b477a126f6f2006c3a73b9764948b6:oslib-win32: only provide localtime_r/gmtime_r if missing (2015-09-24 21:13:49 +0200)
Quoted 8 lines
----------------------------------------------------------------
wxx patch queue- Faster Win32 QemuEvent
- Fixes needed for latest Mingw-w64 build environment
- Version information in QEMU installer for Windows----------------------------------------------------------------
Applied, thanks.
-- PMM