Threaded VNC server
v3 cover Threaded VNC server
Hi,
This series add a threaded VNC server and should be applied on top on my previous patch set (adding tight encoding). The first patch add some functions to qemu-thread. The last oneis the threaded VNC server.
Thanks
Since v1:
* Moved locks from VncState to VncDisplay because it's only used in vnc_refresh
* Use trylock in vnc_refresh. If there is an encoding task still running, reschedule the refresh. This really boost performances and make the vnc server truly asynchroneous. The only blocking lock is the output_mutex which is only held during a simple memcpy().
* Fixed issues found by Paolo, except the exit condition, mainly because we can only have one queue per VncState (due to zstreams), so this is not really an issue.
* Rebased on top of jpeg and ui/ patchs
Since v2:
* renamed vnc-jobs.c vnc-jobs-async.c
* added vnc-jobs.h, refactor functions declarations, export vnc_[un]lock_display() and vnc_[un]lock_output() and use them in vnc-jobs-async.c (reported by Avi)
* rework exit condition for vnc_worker_thread_loop (Paolo)
* abord -> abort (Paolo)
* call qemu_thread_self() (Paolo)
* Coding style issues (Alexander)
* Move from empty macros to empty statis inline (Alexander)
Alexander also suggested me to use stw_be_p() defined in cpu-all.h, but when I tried to include cpu-all.h, it broke every thing. Anyway it can be done later since this code is already present in vnc.c.
Also vnc_async_encoding_start() could be cleaner if encoding members where in a specific structure, but this is a lot of changes, and as I'm also working on encodings, I want this patch to be easy to rebase. So I'll do as soon as the VNC server is merged.
Corentin Chary (2):
qemu-thread: add qemu_mutex/cond_destroy and qemu_mutex_exit
vnc: threaded VNC server
Makefile.objs | 7 +- configure | 13 ++ qemu-thread.c | 22 +++ qemu-thread.h | 4 + ui/vnc-jobs-async.c | 357 +++++++++++++++++++++++++++++++++++++++++++++++++++ ui/vnc-jobs-sync.c | 73 +++++++++++ ui/vnc-jobs.h | 87 +++++++++++++ ui/vnc.c | 144 +++++++++++++++++---- ui/vnc.h | 49 +++++++ 9 files changed, 731 insertions(+), 25 deletions(-) create mode 100644 ui/vnc-jobs-async.c create mode 100644 ui/vnc-jobs-sync.c create mode 100644 ui/vnc-jobs.h
PATCH v3 1/2 qemu-thread: add qemu_mutex/cond_destroy and qemu_mutex_exit
Add some missing functions in qemu-thread. Currently qemu-thread is only used for io-thread but it will used by the vnc server soon and we need those functions instead of calling pthread directly.
--- qemu-thread.c | 22 ++++++++++++++++++++++ qemu-thread.h | 4 ++++ 2 files changed, 26 insertions(+), 0 deletions(-)
qemu-thread.c +22 -0
@@ -34,6 +34,15 @@ void qemu_mutex_init(QemuMutex *mutex)error_exit (err, __func__); } +void qemu_mutex_destroy (QemuMutex *mutex) +{ +int err; + + err =pthread_mutex_destroy (&mutex->lock); +if (err) +error_exit (err, __func__); +} +void qemu_mutex_lock (QemuMutex *mutex) {int err;
@@ -90,6 +99,15 @@ void qemu_cond_init(QemuCond *cond)error_exit (err, __func__); } +void qemu_cond_destroy (QemuCond *cond) +{ +int err; + + err =pthread_cond_destroy (&cond->cond); +if (err) +error_exit (err, __func__); +} +void qemu_cond_signal (QemuCond *cond) {int err;
@@ -161,3 +179,7 @@ int qemu_thread_equal(QemuThread *thread1, QemuThread *thread2)return pthread_equal (thread1->thread, thread2->thread); } +void qemu_thread_exit (void *retval) +{ +pthread_exit (retval); +}
qemu-thread.h +4 -0
@@ -20,12 +20,14 @@ typedef struct QemuCond QemuCond;typedef struct QemuThread QemuThread ;void qemu_mutex_init (QemuMutex *mutex); +void qemu_mutex_destroy (QemuMutex *mutex);void qemu_mutex_lock (QemuMutex *mutex);int qemu_mutex_trylock (QemuMutex *mutex);int qemu_mutex_timedlock (QemuMutex *mutex,uint64_t msecs);void qemu_mutex_unlock (QemuMutex *mutex);void qemu_cond_init (QemuCond *cond); +void qemu_cond_destroy (QemuCond *cond);void qemu_cond_signal (QemuCond *cond);void qemu_cond_broadcast (QemuCond *cond);void qemu_cond_wait (QemuCond *cond,QemuMutex *mutex);
@@ -37,4 +39,6 @@ void qemu_thread_create(QemuThread *thread,void qemu_thread_signal (QemuThread *thread,int sig);void qemu_thread_self (QemuThread *thread);int qemu_thread_equal (QemuThread *thread1,QemuThread *thread2); +void qemu_thread_exit (void *retval); +#endif
Signature · 1 line
1.7.1
PATCH v3 2/2 vnc: threaded VNC server
In reply to Corentin CharyImplement a threaded VNC server using the producer-consumer model. The main thread will push encoding jobs (a list a rectangles to update) in a queue, and the VNC worker thread will consume that queue and send framebuffer updates to the output buffer.
The threaded VNC server can be enabled with ./configure --enable-vnc-thread.
If you don't want it, just use ./configure --disable-vnc-thread and a syncrhonous queue of job will be used (which as exactly the same behavior as the old queue). If you disable the VNC thread, all thread related code will not be built and there will be no overhead.
--- Makefile.objs | 7 +- configure | 13 ++ ui/vnc-jobs-async.c | 357 +++++++++++++++++++++++++++++++++++++++++++++++++++ ui/vnc-jobs-sync.c | 73 +++++++++++ ui/vnc-jobs.h | 87 +++++++++++++ ui/vnc.c | 144 +++++++++++++++++---- ui/vnc.h | 49 +++++++ 7 files changed, 705 insertions(+), 25 deletions(-) create mode 100644 ui/vnc-jobs-async.c create mode 100644 ui/vnc-jobs-sync.c create mode 100644 ui/vnc-jobs.h
Makefile.objs +6 -1
@@ -109,10 +109,15 @@ ui-obj-y += vnc-enc-tight.o ui-obj-$(CONFIG_VNC_TLS) += vnc-tls.o vnc-auth-vencrypt.o ui-obj-$(CONFIG_VNC_SASL) += vnc-auth-sasl.o ui-obj-$(CONFIG_COCOA) += cocoa.o +ifdef CONFIG_VNC_THREAD +ui-obj-y += vnc-jobs-async.o +else +ui-obj-y += vnc-jobs-sync.o +endif common-obj-y += $(addprefix ui/, $(ui-obj-y)) common-obj-y += iov.o acl.o -common-obj-$(CONFIG_IOTHREAD) += qemu-thread.o +common-obj-$(CONFIG_THREAD) += qemu-thread.o common-obj-y += notify.o event_notifier.o common-obj-y += qemu-timer.o
configure +13 -0
@@ -264,6 +264,7 @@ vde="" vnc_tls="" vnc_sasl="" vnc_jpeg="" +vnc_thread="" xen="" linux_aio="" vhost_net=""
@@ -552,6 +553,10 @@ for opt do ;; --enable-vnc-jpeg) vnc_jpeg="yes" ;; + --disable-vnc-thread) vnc_thread="no" + ;; + --enable-vnc-thread) vnc_thread="yes" + ;; --disable-slirp) slirp="no" ;; --disable-uuid) uuid="no"
@@ -786,6 +791,8 @@ echo " --disable-vnc-sasl disable SASL encryption for VNC server" echo " --enable-vnc-sasl enable SASL encryption for VNC server" echo " --disable-vnc-jpeg disable JPEG lossy compression for VNC server" echo " --enable-vnc-jpeg enable JPEG lossy compression for VNC server" +echo " --disable-vnc-thread disable threaded VNC server" +echo " --enable-vnc-thread enable threaded VNC server" echo " --disable-curses disable curses output" echo " --enable-curses enable curses output" echo " --disable-curl disable curl connectivity"
@@ -2048,6 +2055,7 @@ echo "Mixer emulation $mixemu" echo "VNC TLS support $vnc_tls" echo "VNC SASL support $vnc_sasl" echo "VNC JPEG support $vnc_jpeg" +echo "VNC thread $vnc_thread" if test -n "$sparc_cpu"; then echo "Target Sparc Arch $sparc_cpu" fi
@@ -2191,6 +2199,10 @@ if test "$vnc_jpeg" = "yes" ; then echo "CONFIG_VNC_JPEG=y" >> $config_host_mak echo "VNC_JPEG_CFLAGS=$vnc_jpeg_cflags" >> $config_host_mak fi +if test "$vnc_thread" = "yes" ; then + echo "CONFIG_VNC_THREAD=y" >> $config_host_mak + echo "CONFIG_THREAD=y" >> $config_host_mak +fi if test "$fnmatch" = "yes" ; then echo "CONFIG_FNMATCH=y" >> $config_host_mak fi
@@ -2267,6 +2279,7 @@ if test "$xen" = "yes" ; then fi if test "$io_thread" = "yes" ; then echo "CONFIG_IOTHREAD=y" >> $config_host_mak + echo "CONFIG_THREAD=y" >> $config_host_mak fi if test "$linux_aio" = "yes" ; then echo "CONFIG_LINUX_AIO=y" >> $config_host_mak
ui/vnc-jobs-async.c new file +357 -0
357 lines not on this page · raw message
ui/vnc-jobs-sync.c new file +73 -0
73 lines not on this page · raw message
ui/vnc-jobs.h new file +87 -0
87 lines not on this page · raw message
ui/vnc.c +120 -24
364 lines not on this page · raw message
ui/vnc.h +49 -0
85 lines not on this page · raw message
Signature · 1 line
1.7.1