All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] Threads and win32
@ 2009-07-18 19:27 Teemu Nätkinniemi
  2009-07-19 12:11 ` [Qemu-devel] " Sebastian Herbszt
  0 siblings, 1 reply; 8+ messages in thread
From: Teemu Nätkinniemi @ 2009-07-18 19:27 UTC (permalink / raw)
  To: qemu-devel


Hello!

Are there any plans to make qemu-thread.c compatible with win32? At the moment compilation errors as CLOCK_REALTIME is not available on MinGW and I don't know any way around this.

Thanks for any solutions!




^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Qemu-devel] Re: Threads and win32
  2009-07-18 19:27 [Qemu-devel] Threads and win32 Teemu Nätkinniemi
@ 2009-07-19 12:11 ` Sebastian Herbszt
  2009-07-20 16:07   ` Marcelo Tosatti
  0 siblings, 1 reply; 8+ messages in thread
From: Sebastian Herbszt @ 2009-07-19 12:11 UTC (permalink / raw)
  To: Teemu Nätkinniemi, qemu-devel, mtosatti; +Cc: Anthony Liguori

Teemu Nätkinniemi wrote:
> Hello!
>
> Are there any plans to make qemu-thread.c compatible with win32? At the moment compilation errors as
> CLOCK_REALTIME is not available on MinGW and I don't know any way around this.
>
> Thanks for any solutions!

I have noticed the problem back in April when the IO thread work got commited, but noone seemed to care [1].

Marcelo, can gettimeofday be used instead of clock_gettime?

[1] http://lists.gnu.org/archive/html/qemu-devel/2009-04/msg01656.html

- Sebastian

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Qemu-devel] Re: Threads and win32
  2009-07-19 12:11 ` [Qemu-devel] " Sebastian Herbszt
@ 2009-07-20 16:07   ` Marcelo Tosatti
  2009-07-20 19:09     ` Sebastian Herbszt
  0 siblings, 1 reply; 8+ messages in thread
From: Marcelo Tosatti @ 2009-07-20 16:07 UTC (permalink / raw)
  To: Sebastian Herbszt; +Cc: Anthony Liguori, qemu-devel, Teemu Nätkinniemi

On Sun, Jul 19, 2009 at 02:11:09PM +0200, Sebastian Herbszt wrote:
> Teemu Nätkinniemi wrote:
>> Hello!
>>
>> Are there any plans to make qemu-thread.c compatible with win32? At the moment compilation errors as
>> CLOCK_REALTIME is not available on MinGW and I don't know any way around this.
>>
>> Thanks for any solutions!
>
> I have noticed the problem back in April when the IO thread work got commited, but noone seemed to care [1].
>
> Marcelo, can gettimeofday be used instead of clock_gettime?
>
> [1] http://lists.gnu.org/archive/html/qemu-devel/2009-04/msg01656.html
>
> - Sebastian

Sure, gettimeofday instead of clock_gettime is fine.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Qemu-devel] Re: Threads and win32
  2009-07-20 16:07   ` Marcelo Tosatti
@ 2009-07-20 19:09     ` Sebastian Herbszt
  2009-07-20 23:52       ` Marcelo Tosatti
  0 siblings, 1 reply; 8+ messages in thread
From: Sebastian Herbszt @ 2009-07-20 19:09 UTC (permalink / raw)
  To: Marcelo Tosatti; +Cc: Anthony Liguori, qemu-devel, Teemu Nätkinniemi

Marcelo Tosatti wrote:
> On Sun, Jul 19, 2009 at 02:11:09PM +0200, Sebastian Herbszt wrote:
>> Marcelo, can gettimeofday be used instead of clock_gettime?
>>
> Sure, gettimeofday instead of clock_gettime is fine.

If clock_gettime() is replaced by gettimeofday() qemu-thread.c does compile on MinGW if
also the pthread_equal patch [1] is applied. Unfortunatelly there is a ton of compile errors
in vl.c due to incomplete signal support (?).

[1] http://lists.gnu.org/archive/html/qemu-devel/2009-07/msg01514.html

- Sebastian

[PATCH] qemu-thread: replace clock_gettime() by gettimeofday()

Replace clock_gettime() which is not available on MinGW by gettimeofday().

Signed-off-by: Sebastian Herbszt <herbszt@gmx.de>

--- qemu-c62bb/qemu-thread.c.orig Mon Jul 20 18:38:24 2009
+++ qemu-c62bb/qemu-thread.c Mon Jul 20 18:53:53 2009
@@ -14,6 +14,7 @@
 #include <stdio.h>
 #include <errno.h>
 #include <time.h>
+#include <sys/time.h>
 #include <signal.h>
 #include <stdint.h>
 #include <string.h>
@@ -62,8 +63,11 @@ int qemu_mutex_timedlock(QemuMutex *mute
 {
     int err;
     struct timespec ts;
+    struct timeval now;
 
-    clock_gettime(CLOCK_REALTIME, &ts);
+    gettimeofday(&now, NULL);
+    ts.tv_sec = now.tv_sec;
+    ts.tv_nsec = now.tv_usec * 1000;
     timespec_add_ms(&ts, msecs);
 
     err = pthread_mutex_timedlock(&mutex->lock, &ts);
@@ -120,9 +124,12 @@ void qemu_cond_wait(QemuCond *cond, Qemu
 int qemu_cond_timedwait(QemuCond *cond, QemuMutex *mutex, uint64_t msecs)
 {
     struct timespec ts;
+    struct timeval now;
     int err;
 
-    clock_gettime(CLOCK_REALTIME, &ts);
+    gettimeofday(&now, NULL);
+    ts.tv_sec = now.tv_sec;
+    ts.tv_nsec = now.tv_usec * 1000;
     timespec_add_ms(&ts, msecs);
 
     err = pthread_cond_timedwait(&cond->cond, &mutex->lock, &ts);

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Qemu-devel] Re: Threads and win32
  2009-07-20 19:09     ` Sebastian Herbszt
@ 2009-07-20 23:52       ` Marcelo Tosatti
  2009-07-21 12:11         ` Sebastian Herbszt
  0 siblings, 1 reply; 8+ messages in thread
From: Marcelo Tosatti @ 2009-07-20 23:52 UTC (permalink / raw)
  To: Sebastian Herbszt; +Cc: Anthony Liguori, qemu-devel, Teemu Nätkinniemi

On Mon, Jul 20, 2009 at 09:09:47PM +0200, Sebastian Herbszt wrote:
> Marcelo Tosatti wrote:
>> On Sun, Jul 19, 2009 at 02:11:09PM +0200, Sebastian Herbszt wrote:
>>> Marcelo, can gettimeofday be used instead of clock_gettime?
>>>
>> Sure, gettimeofday instead of clock_gettime is fine.
>
> If clock_gettime() is replaced by gettimeofday() qemu-thread.c does compile on MinGW if
> also the pthread_equal patch [1] is applied. Unfortunatelly there is a ton of compile errors
> in vl.c due to incomplete signal support (?).
>
> [1] http://lists.gnu.org/archive/html/qemu-devel/2009-07/msg01514.html
>
> - Sebastian
>
> [PATCH] qemu-thread: replace clock_gettime() by gettimeofday()
>
> Replace clock_gettime() which is not available on MinGW by gettimeofday().

Sweet. Have you tested it?

Do the signal warnings make any sense??

>
> Signed-off-by: Sebastian Herbszt <herbszt@gmx.de>
>
> --- qemu-c62bb/qemu-thread.c.orig Mon Jul 20 18:38:24 2009
> +++ qemu-c62bb/qemu-thread.c Mon Jul 20 18:53:53 2009
> @@ -14,6 +14,7 @@
> #include <stdio.h>
> #include <errno.h>
> #include <time.h>
> +#include <sys/time.h>
> #include <signal.h>
> #include <stdint.h>
> #include <string.h>
> @@ -62,8 +63,11 @@ int qemu_mutex_timedlock(QemuMutex *mute
> {
>     int err;
>     struct timespec ts;
> +    struct timeval now;
>
> -    clock_gettime(CLOCK_REALTIME, &ts);
> +    gettimeofday(&now, NULL);
> +    ts.tv_sec = now.tv_sec;
> +    ts.tv_nsec = now.tv_usec * 1000;
>     timespec_add_ms(&ts, msecs);
>
>     err = pthread_mutex_timedlock(&mutex->lock, &ts);
> @@ -120,9 +124,12 @@ void qemu_cond_wait(QemuCond *cond, Qemu
> int qemu_cond_timedwait(QemuCond *cond, QemuMutex *mutex, uint64_t msecs)
> {
>     struct timespec ts;
> +    struct timeval now;
>     int err;
>
> -    clock_gettime(CLOCK_REALTIME, &ts);
> +    gettimeofday(&now, NULL);
> +    ts.tv_sec = now.tv_sec;
> +    ts.tv_nsec = now.tv_usec * 1000;
>     timespec_add_ms(&ts, msecs);
>
>     err = pthread_cond_timedwait(&cond->cond, &mutex->lock, &ts);

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Qemu-devel] Re: Threads and win32
  2009-07-20 23:52       ` Marcelo Tosatti
@ 2009-07-21 12:11         ` Sebastian Herbszt
  2009-07-21 12:58           ` Jamie Lokier
  2009-07-21 13:22           ` Teemu Nätkinniemi
  0 siblings, 2 replies; 8+ messages in thread
From: Sebastian Herbszt @ 2009-07-21 12:11 UTC (permalink / raw)
  To: Marcelo Tosatti; +Cc: Anthony Liguori, qemu-devel, Teemu Nätkinniemi

Marcelo Tosatti wrote:
> On Mon, Jul 20, 2009 at 09:09:47PM +0200, Sebastian Herbszt wrote:
>> [PATCH] qemu-thread: replace clock_gettime() by gettimeofday()
>>
>> Replace clock_gettime() which is not available on MinGW by gettimeofday().
> 
> Sweet. Have you tested it?

Slightly on linux.

> Do the signal warnings make any sense??

  CC    i386-softmmu/vl.o
vl.c: In function `qemu_cpu_kick':
vl.c:3842: error: `SIGUSR1' undeclared (first use in this function)
vl.c:3842: error: (Each undeclared identifier is reported only once
vl.c:3842: error: for each function it appears in.)
vl.c: In function `block_io_signals':
vl.c:3859: error: storage size of 'sigact' isn't known
vl.c:3861: warning: implicit declaration of function `sigemptyset'
vl.c:3862: warning: implicit declaration of function `sigaddset'
vl.c:3862: error: `SIGUSR2' undeclared (first use in this function)
vl.c:3863: error: `SIGIO' undeclared (first use in this function)
vl.c:3864: error: `SIGALRM' undeclared (first use in this function)
vl.c:3865: warning: implicit declaration of function `pthread_sigmask'
vl.c:3868: error: `SIGUSR1' undeclared (first use in this function)
vl.c:3873: warning: implicit declaration of function `sigaction'
vl.c:3859: warning: unused variable `sigact'
vl.c: In function `unblock_io_signals':
vl.c:3861: warning: redundant redeclaration of 'sigemptyset'
vl.c:3861: warning: previous implicit declaration of 'sigemptyset' was here
vl.c:3862: warning: redundant redeclaration of 'sigaddset'
vl.c:3862: warning: previous implicit declaration of 'sigaddset' was here
vl.c:3881: error: `SIGUSR2' undeclared (first use in this function)
vl.c:3882: error: `SIGIO' undeclared (first use in this function)
vl.c:3883: error: `SIGALRM' undeclared (first use in this function)
vl.c:3865: warning: redundant redeclaration of 'pthread_sigmask'
vl.c:3865: warning: previous implicit declaration of 'pthread_sigmask' was here
vl.c:3887: error: `SIGUSR1' undeclared (first use in this function)
vl.c: In function `qemu_signal_lock':
vl.c:3896: error: `SIGUSR1' undeclared (first use in this function)
vl.c: In function `pause_all_vcpus':
vl.c:3937: error: `SIGUSR1' undeclared (first use in this function)
vl.c: In function `resume_all_vcpus':
vl.c:3959: error: `SIGUSR1' undeclared (first use in this function)
make[1]: *** [vl.o] Error 1
make: *** [subdir-i386-softmmu] Error 2

- Sebastian

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] Re: Threads and win32
  2009-07-21 12:11         ` Sebastian Herbszt
@ 2009-07-21 12:58           ` Jamie Lokier
  2009-07-21 13:22           ` Teemu Nätkinniemi
  1 sibling, 0 replies; 8+ messages in thread
From: Jamie Lokier @ 2009-07-21 12:58 UTC (permalink / raw)
  To: Sebastian Herbszt
  Cc: Anthony Liguori, Marcelo Tosatti, qemu-devel, Teemu Nätkinniemi

Sebastian Herbszt wrote:
> vl.c:3873: warning: implicit declaration of function `sigaction'
> vl.c:3887: error: `SIGUSR1' undeclared (first use in this function)
> vl.c:3881: error: `SIGUSR2' undeclared (first use in this function)
> vl.c:3882: error: `SIGIO' undeclared (first use in this function)
> vl.c:3883: error: `SIGALRM' undeclared (first use in this function)

It's not surprising.

WIN32 doesn't have unix-style signals :-)

WIN32 doesn't have pthreads either, but there's a
pthread-compatibility library people often use.  That provides
pthreads emulation but not signal emulation.  WIN32 does provide
threads and locking primitives, and it's not too painful to build
pthreads on t top of that.

To emulate signals you really have to use Cygwin or one of the other
unix-on-WIN32 emulation packages.  Or change the code to not use signals.

WIN32 has native async I/O, by the way.  I don't know if it's
suitable, especially since we found how broken Linux async I/O is
despite the simple API, but Windows has had it since the early 90s
(all versions derived from Windows NT) and inherited the design from
VMS, so it's probably in good shape.

-- Jamie

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Qemu-devel] Re: Threads and win32
  2009-07-21 12:11         ` Sebastian Herbszt
  2009-07-21 12:58           ` Jamie Lokier
@ 2009-07-21 13:22           ` Teemu Nätkinniemi
  1 sibling, 0 replies; 8+ messages in thread
From: Teemu Nätkinniemi @ 2009-07-21 13:22 UTC (permalink / raw)
  To: Sebastian Herbszt; +Cc: aliguori, mtosatti, qemu-devel



> > Do the signal warnings make any sense??
> 
>   CC    i386-softmmu/vl.o
> vl.c: In function `qemu_cpu_kick':
> vl.c:3842: error: `SIGUSR1' undeclared (first use in this
> function)
> vl.c:3842: error: (Each undeclared identifier is reported
> only once
> vl.c:3842: error: for each function it appears in.)
> vl.c: In function `block_io_signals':
> vl.c:3859: error: storage size of 'sigact' isn't known
> vl.c:3861: warning: implicit declaration of function
> `sigemptyset'
> vl.c:3862: warning: implicit declaration of function
> `sigaddset'
> vl.c:3862: error: `SIGUSR2' undeclared (first use in this
> function)
> vl.c:3863: error: `SIGIO' undeclared (first use in this
> function)
> vl.c:3864: error: `SIGALRM' undeclared (first use in this
> function)
> vl.c:3865: warning: implicit declaration of function
> `pthread_sigmask'
> vl.c:3868: error: `SIGUSR1' undeclared (first use in this
> function)
> vl.c:3873: warning: implicit declaration of function
> `sigaction'
> vl.c:3859: warning: unused variable `sigact'
> vl.c: In function `unblock_io_signals':
> vl.c:3861: warning: redundant redeclaration of
> 'sigemptyset'
> vl.c:3861: warning: previous implicit declaration of
> 'sigemptyset' was here
> vl.c:3862: warning: redundant redeclaration of 'sigaddset'
> vl.c:3862: warning: previous implicit declaration of
> 'sigaddset' was here
> vl.c:3881: error: `SIGUSR2' undeclared (first use in this
> function)
> vl.c:3882: error: `SIGIO' undeclared (first use in this
> function)
> vl.c:3883: error: `SIGALRM' undeclared (first use in this
> function)
> vl.c:3865: warning: redundant redeclaration of
> 'pthread_sigmask'
> vl.c:3865: warning: previous implicit declaration of
> 'pthread_sigmask' was here
> vl.c:3887: error: `SIGUSR1' undeclared (first use in this
> function)
> vl.c: In function `qemu_signal_lock':
> vl.c:3896: error: `SIGUSR1' undeclared (first use in this
> function)
> vl.c: In function `pause_all_vcpus':
> vl.c:3937: error: `SIGUSR1' undeclared (first use in this
> function)
> vl.c: In function `resume_all_vcpus':
> vl.c:3959: error: `SIGUSR1' undeclared (first use in this
> function)
> make[1]: *** [vl.o] Error 1
> make: *** [subdir-i386-softmmu] Error 2

MinGW's signal support is very limited and it does not have these signals. One solution would be to use GnuWin32 support library (http://gnuwin32.sourceforge.net/) but I encounter following errors:

In file included from /mingw/lib/gcc/mingw32/../../../include/winx/signalx.h:5,
                 from D:/msys/src/qemu/vl.c:27:
/mingw/lib/gcc/mingw32/../../../include/winx/sys/signalx.h:57: error: expected specifier-qualifier-list before '__sigset_t'
/mingw/lib/gcc/mingw32/../../../include/winx/sys/signalx.h:64: error: expected specifier-qualifier-list before '__ptr_t'
/mingw/lib/gcc/mingw32/../../../include/winx/sys/signalx.h:72: error: expected specifier-qualifier-list before '__ptr_t'
D:/msys/src/qemu/vl.c: In function 'block_io_signals':
D:/msys/src/qemu/vl.c:3865: warning: implicit declaration of function 'sigaddset'
D:/msys/src/qemu/vl.c:3868: warning: implicit declaration of function 'pthread_sigmask'
D:/msys/src/qemu/vl.c:3876: warning: implicit declaration of function 'sigaction'
D:/msys/src/qemu/vl.c: In function 'qemu_uuid_parse':
D:/msys/src/qemu/vl.c:4664: warning: unknown conversion type character 'h' in format
D:/msys/src/qemu/vl.c:4664: warning: unknown conversion type character 'h' in format
D:/msys/src/qemu/vl.c:4664: warning: unknown conversion type character 'h' in format
D:/msys/src/qemu/vl.c:4664: warning: unknown conversion type character 'h' in format
D:/msys/src/qemu/vl.c:4664: warning: unknown conversion type character 'h' in format
D:/msys/src/qemu/vl.c:4664: warning: unknown conversion type character 'h' in format
D:/msys/src/qemu/vl.c:4664: warning: unknown conversion type character 'h' in format
D:/msys/src/qemu/vl.c:4664: warning: unknown conversion type character 'h' in format
D:/msys/src/qemu/vl.c:4664: warning: unknown conversion type character 'h' in format
D:/msys/src/qemu/vl.c:4664: warning: unknown conversion type character 'h' in format
D:/msys/src/qemu/vl.c:4664: warning: unknown conversion type character 'h' in format
D:/msys/src/qemu/vl.c:4664: warning: unknown conversion type character 'h' in format
D:/msys/src/qemu/vl.c:4664: warning: unknown conversion type character 'h' in format
D:/msys/src/qemu/vl.c:4664: warning: unknown conversion type character 'h' in format
D:/msys/src/qemu/vl.c:4664: warning: unknown conversion type character 'h' in format
D:/msys/src/qemu/vl.c:4664: warning: unknown conversion type character 'h' in format
D:/msys/src/qemu/vl.c:4664: warning: too many arguments for format
make[1]: *** [vl.o] Error 1
make: *** [subdir-i386-softmmu] Error 2

The actual include file winx/sys/signalx.h looks like this:

#ifndef __WINX_SYS_SIGNALX_H__
#define __WINX_SYS_SIGNALX_H__

#include <features.h>
#include <sys/types.h>
#include <bits/sigset.h>

/* Type of a signal handler.  */
typedef void (*__sighandler_t) (int);

#ifdef __USE_BSD
typedef __sighandler_t sig_t;
#endif

#  define SIGHUP      -1
#  define SIGQUIT     -3
#  define SIGTRAP     -5
#  define SIGIOT      -6
#  define SIGEMT      -7
#  define SIGKILL     -9
#  define SIGBUS      -10
#  define SIGSYS      -12
#  define SIGPIPE     -13
#  define SIGALRM     -14
#  define SIGURG      -16
#  define SIGSTOP     -17
#  define SIGTSTP     -18
#  define SIGCONT     -19
#  define SIGCHLD     -20
#  define SIGTTIN     -21
#  define SIGTTOU     -22
#  define SIGIO       -23
#  define SIGXCPU     -24
#  define SIGXFSZ     -25
#  define SIGVTALRM   -26
#  define SIGPROF     -27
#  define SIGWINCH    -28
#  define SIGLOST     -29
#  define SIGUSR1     -30
#  define SIGUSR2     -32

#define SIG_SETMASK 0	/* set mask with sigprocmask() */
#define SIG_BLOCK 1	/* set of signals to block */
#define SIG_UNBLOCK 2	/* set of signals to, well, unblock */

/* Type of a signal handler.  */
typedef void (*__sighandler_t) (int);

struct sigaction
  {
    /* Signal handler.  */
    __sighandler_t sa_handler;
    /* Additional set of signals to be blocked.  */
    __sigset_t sa_mask;
    /* Special flags.  */
    int sa_flags;
  };


/* Structure describing a signal stack (obsolete).  */
struct sigstack
  {
    __ptr_t ss_sp;       /* Signal stack pointer.  */
    int ss_onstack;      /* Nonzero if executing on this stack.  */
  };


/* Alternate, preferred interface.  */
typedef struct sigaltstack
  {
    __ptr_t ss_sp;
    size_t ss_size;
    int ss_flags;
  } stack_t;

/* POSIX sigsetjmp/siglongjmp macros */
#define sigjmp_buf jmp_buf

#define _SAVEMASK	_JBLEN
#define _SIGMASK	(_JBLEN+1)

/*
#define sigsetjmp(env, savemask) ((env)[_SAVEMASK] = savemask,\
               sigprocmask (SIG_SETMASK, 0, (sigset_t *) ((env) + _SIGMASK)),\
               setjmp (env))

#define siglongjmp(env, val) ((((env)[_SAVEMASK])?\
               sigprocmask (SIG_SETMASK, (sigset_t *) ((env) + _SIGMASK), 0):0),\
               longjmp (env, val))


#define sigsetjmp(env, savemask) (1)
#define siglongjmp(env, val) (1)
*/
#ifndef sigemptyset
# define sigemptyset(s) (*(s) = 0)
#endif
#ifndef sigmask
# define sigmask(sig) (1 << ((sig) - 1))
#endif
/* # define sigaddset(s, sig) (*(s) |= sigmask (sig)) */

#endif /* __WINX_SYS_SIGNALX_H__ */

Teemu




^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2009-07-21 13:23 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-07-18 19:27 [Qemu-devel] Threads and win32 Teemu Nätkinniemi
2009-07-19 12:11 ` [Qemu-devel] " Sebastian Herbszt
2009-07-20 16:07   ` Marcelo Tosatti
2009-07-20 19:09     ` Sebastian Herbszt
2009-07-20 23:52       ` Marcelo Tosatti
2009-07-21 12:11         ` Sebastian Herbszt
2009-07-21 12:58           ` Jamie Lokier
2009-07-21 13:22           ` Teemu Nätkinniemi

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.