Add spice support to qemu.
cover Add spice support to qemu.
Hi folks,
Here is a early spice patch series for review and comments. It is not yet complete (save/load/migration isn't addressed at all yet) and it has some known issues (local rendering isn't fully functional). Also things are in flux in upstream spice, this patch series depends on not-yet committed libspice patches (see below for build instructions). Nevertheless it works good enougth that you can start playing with it and I also like to gather review comments and get merge planning started.
Some background info:
Spice is a remote desktop protocol. The (slightly outdated) project website with background information is http://www.spice-space.org/ The download section has windows guest drivers. You need the unstable versions for these patches.
Building spice:
The spice project runs under the freedesktop.org umbrella now, the git repositories are hosted @ freedesktop.org. You'll need:
(1) spice-protocol. http://cgit.freedesktop.org/spice/spice-protocol/
This carries all the spice protocol structs.
(2) celt051. http://www.spice-space.org/yum_repo_data/f12/src/celt051-0.5.1.3-0.fc12.src.rpm
Version 0.5.1 of the celt audio codec. This is the only unusual
(aka distros don't carry it) build dependency left for spice.
(3) A bunch of devel packages. Especially log4cpp and cegui.
Everything else spice needs should be on your disk already if you
are doing qemu development.
(4) A pretty recent pixman version (0.18.0+).
(5) spice itself. http://cgit.freedesktop.org/~kraxel/spice/log/?h=api.v3
This brings both libspice-server and the spice client.
(6) This patch series. Also available from
http://cgit.freedesktop.org/spice/qemu/log/?h=spice.v3
If everything goes well qemu configure should autodetect that spice is available.
Testing & using spice:
* Enable spice in qemu:
qemu -spice port=1234,password=$secret # password protected
qemu -spice port=1234,disable-ticketing # allow connects without password
* Enable qxl vga device (recommended):
qemu -spice $options -vga qxl
* Enable multihead (in theory, just noticed its broken, to be debugged ...) qemu -spice $options -vga qxl -device qxl
* Enable sound:
QEMU_AUDIO_DRV=spice qemu -spice $options -device AC97
* Adding a absolute pointing device aka tablet is strongly recommended:
qemu -usbdevice tablet
* Start spice client:
spicec -h localhost -p 1234 -w $secret
The spice client has two important hot keys: Shift+F11 (toggle Fullscreen) and Shift+F12 (release pointer grab). If you add a usb tablet you hopefully never ever need Shift+F12 though.
cheers,
Gerd
RFC PATCH 1/11 vgabios update to 0.6c, add bios for qxl/unstable
--- Makefile | 2 +- pc-bios/vgabios-cirrus.bin | Bin 35840 -> 35840 bytes pc-bios/vgabios-qxl.bin | Bin 0 -> 40448 bytes pc-bios/vgabios.bin | Bin 38400 -> 40448 bytes 4 files changed, 1 insertions(+), 1 deletions(-) create mode 100644 pc-bios/vgabios-qxl.bin
Makefile +1 -1
@@ -170,7 +170,7 @@ ar de en-us fi fr-be hr it lv nl pl ru th \ common de-ch es fo fr-ca hu ja mk nl-be pt sl tr ifdef INSTALL_BLOBS -BLOBS=bios.bin vgabios.bin vgabios-cirrus.bin ppc_rom.bin \ +BLOBS=bios.bin vgabios.bin vgabios-cirrus.bin vgabios-qxl.bin ppc_rom.bin \ video.x openbios-sparc32 openbios-sparc64 openbios-ppc \ gpxe-eepro100-80861209.rom \ gpxe-eepro100-80861229.rom \
pc-bios/vgabios-cirrus.bin binary +0 -0
pc-bios/vgabios-qxl.bin new file binary +0 -0
pc-bios/vgabios.bin binary +0 -0
Signature · 1 line
1.6.6.1
RFC PATCH 2/11 add spice into the configure file
In reply to Gerd Hoffmann--- configure | 36 ++++++++++++++++++++++++++++++++++++ 1 files changed, 36 insertions(+), 0 deletions(-)
configure +36 -0
@@ -299,6 +299,7 @@ pkgversion="" check_utests="no" user_pie="no" zero_malloc="" +spice="" # OS specific if check_define __linux__ ; then
@@ -573,6 +574,10 @@ for opt do ;; --enable-kvm) kvm="yes" ;; + --disable-spice) spice="no" + ;; + --enable-spice) spice="yes" + ;; --enable-profiler) profiler="yes" ;; --enable-cocoa)
@@ -826,6 +831,8 @@ echo " --enable-docs enable documentation build" echo " --disable-docs disable documentation build" echo " --disable-vhost-net disable vhost-net acceleration support" echo " --enable-vhost-net enable vhost-net acceleration support" +echo " --disable-spice disable spice" +echo " --enable-spice enable spice" echo "" echo "NOTE: The object files are built at the place where configure is launched" exit 1
@@ -1891,6 +1898,30 @@ if compile_prog "" ""; then gcc_attribute_warn_unused_result=yes fi +# spice probe +if test "$spice" != "no" ; then + cat > $TMPC << EOF +#include <spice.h> +int main(void) { spice_server_new(); return 0; } +EOF + spice_proto_ver=$(pkg-config --modversion spice-protocol 2>/dev/null) + spice_server_ver=$(pkg-config --modversion spice-server 2>/dev/null) + spice_cflags=$(pkg-config --cflags spice-protocol spice-server 2>/dev/null) + spice_libs=$(pkg-config --libs spice-protocol spice-server 2>/dev/null) + if compile_prog "$spice_cflags" "$spice_libs" ; then + spice="yes" + libs_softmmu="$spice_libs $libs_softmmu" + QEMU_CFLAGS="$spice_cflags $QEMU_CFLAGS" + else + if test "$spice" = "yes" ; then + feature_not_found "spice" + fi + spice="no" + fi +fi + +########################################## + ########################################## # check if we have fdatasync
@@ -2030,6 +2061,7 @@ echo "preadv support $preadv" echo "fdatasync $fdatasync" echo "uuid support $uuid" echo "vhost-net support $vhost_net" +echo "spice support $spice" if test $sdl_too_old = "yes"; then echo "-> Your SDL version is too old - please upgrade to have SDL support"
@@ -2249,6 +2281,10 @@ if test "$fdatasync" = "yes" ; then echo "CONFIG_FDATASYNC=y" >> $config_host_mak fi +if test "$spice" = "yes" ; then + echo "CONFIG_SPICE=y" >> $config_host_mak +fi + # XXX: suppress that if [ "$bsd" = "yes" ] ; then echo "CONFIG_BSD=y" >> $config_host_mak
Signature · 1 line
1.6.6.1
RFC PATCH 3/11 spice: core bits
In reply to Gerd HoffmannAdd -spice command line switch. Has support setting passwd and port for now. With this patch applied the spice client can successfully connect to qemu. You can't do anything useful yet though.
--- Makefile.target | 1 + qemu-config.c | 3 + qemu-config.h | 1 + qemu-options.hx | 8 +++ qemu-spice.h | 22 +++++++ spice.c | 170 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ vl.c | 15 +++++ 7 files changed, 220 insertions(+), 0 deletions(-) create mode 100644 qemu-spice.h create mode 100644 spice.c
Makefile.target +1 -0
@@ -194,6 +194,7 @@ obj-i386-y += cirrus_vga.o apic.o ioapic.o piix_pci.o obj-i386-y += vmmouse.o vmport.o hpet.o obj-i386-y += device-hotplug.o pci-hotplug.o smbios.o wdt_ib700.o obj-i386-y += debugcon.o multiboot.o +obj-i386-$(CONFIG_SPICE) += spice.o # shared objects obj-ppc-y = ppc.o
qemu-config.c +3 -0
@@ -306,6 +306,9 @@ static QemuOptsList *lists[] = { &qemu_global_opts, &qemu_mon_opts, &qemu_cpudef_opts, +#ifdef CONFIG_SPICE + &qemu_spice_opts, +#endif NULL, };
qemu-config.h +1 -0
@@ -10,6 +10,7 @@ extern QemuOptsList qemu_rtc_opts;extern QemuOptsList qemu_global_opts;extern QemuOptsList qemu_mon_opts;extern QemuOptsList qemu_cpudef_opts; +extern QemuOptsList qemu_spice_opts;QemuOptsList *qemu_find_opts (const char *group);int qemu_set_option (const char *str);
qemu-options.hx +8 -0
@@ -594,6 +594,14 @@ STEXI Enable SDL. ETEXI +#ifdef CONFIG_SPICE +DEF("spice", HAS_ARG, QEMU_OPTION_spice, + "-spice <args> use spice\n", QEMU_ARCH_ALL) +STEXI +Use Spice. +ETEXI +#endif + DEF("portrait", 0, QEMU_OPTION_portrait, "-portrait rotate graphical output 90 deg left (only PXA LCD)\n", QEMU_ARCH_ALL)
qemu-spice.h new file +22 -0
@@ -0,0 +1,22 @@ +#ifndef QEMU_SPICE_H +#define QEMU_SPICE_H + +#ifdef CONFIG_SPICE + +#include <spice.h> + +#include "qemu-option.h" +#include "qemu-config.h" + +extern SpiceServer *spice_server; +extern int using_spice; + +void qemu_spice_init (void ); + +#else /* CONFIG_SPICE */ + +#define using_spice 0 + +#endif /* CONFIG_SPICE */ + +#endif /* QEMU_SPICE_H */
spice.c new file +170 -0
170 lines not on this page · raw message
vl.c +15 -0
@@ -160,6 +160,8 @@ int main(int argc, char **argv)#include "cpus.h" #include "arch_init.h" +#include "qemu-spice.h" +//#define DEBUG_NET //#define DEBUG_SLIRP
@@ -3348,6 +3350,15 @@ int main(int argc, char **argv, char **envp)fclose (fp);break ; } +#ifdef CONFIG_SPICE +case QEMU_OPTION_spice: + opts =qemu_opts_parse (&qemu_spice_opts, optarg,1 ); +if (!opts) { +fprintf (stderr,"parse error: %s\n" , optarg); +exit (1 ); + } +break ; +#endif case QEMU_OPTION_writeconfig: {FILE *fp;
@@ -3660,6 +3671,10 @@ int main(int argc, char **argv, char **envp) }qemu_add_globals (); +#ifdef CONFIG_SPICE +qemu_spice_init (); +#endif + machine->init (ram_size, boot_devices, kernel_filename, kernel_cmdline, initrd_filename, cpu_model);
Signature · 1 line
1.6.6.1
RFC PATCH 4/11 spice: add keyboard
In reply to Gerd HoffmannOpen keyboard channel. Now you can type into the spice client and the keyboard events are sent to your guest. You'll need some other display like vnc to actually see the guest responding to them though.
--- Makefile.target | 2 +- qemu-spice.h | 1 + spice-input.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ spice.c | 2 + 4 files changed, 61 insertions(+), 1 deletions(-) create mode 100644 spice-input.c
Makefile.target +1 -1
@@ -194,7 +194,7 @@ obj-i386-y += cirrus_vga.o apic.o ioapic.o piix_pci.o obj-i386-y += vmmouse.o vmport.o hpet.o obj-i386-y += device-hotplug.o pci-hotplug.o smbios.o wdt_ib700.o obj-i386-y += debugcon.o multiboot.o -obj-i386-$(CONFIG_SPICE) += spice.o +obj-i386-$(CONFIG_SPICE) += spice.o spice-input.o # shared objects obj-ppc-y = ppc.o
qemu-spice.h +1 -0
@@ -12,6 +12,7 @@ extern SpiceServer *spice_server;extern int using_spice;void qemu_spice_init (void ); +void qemu_spice_input_init (void );#else /* CONFIG_SPICE */
spice-input.c new file +57 -0
57 lines not on this page · raw message
spice.c +2 -0
@@ -167,4 +167,6 @@ void qemu_spice_init(void)spice_server_init (spice_server, &core_interface); using_spice =1 ; + +qemu_spice_input_init (); }
Signature · 1 line
1.6.6.1
RFC PATCH 5/11 spice: add mouse
In reply to Gerd HoffmannOpen mouse channel. Now you can move the guests mouse pointer. No tablet / absolute positioning (yet) though.
--- spice-input.c | 31 +++++++++++++++++++++++++++++++ 1 files changed, 31 insertions(+), 0 deletions(-)
spice-input.c +31 -0
@@ -46,12 +46,43 @@ static void kbd_leds(void *opaque, int ledstate)spice_server_kbd_leds (&kbd->sin, ledstate); } +/* mouse bits */ + +typedef struct QemuSpiceMouse { +SpiceMouseInstance sin; +}QemuSpiceMouse ; + +static void mouse_motion (SpiceMouseInstance *sin,int dx,int dy,int dz, +uint32_t buttons_state) +{ +kbd_mouse_event (dx, dy, dz, buttons_state); +} + +static void mouse_buttons (SpiceMouseInstance *sin,uint32_t buttons_state) +{ +kbd_mouse_event (0 ,0 ,0 , buttons_state); +} + +static SpiceMouseInterface mouse_interface = { + .base.type =SPICE_INTERFACE_MOUSE , + .base.description ="mouse" , + .base.major_version =SPICE_INTERFACE_MOUSE_MAJOR , + .base.minor_version =SPICE_INTERFACE_MOUSE_MINOR , + .motion = mouse_motion, + .buttons = mouse_buttons, +}; +void qemu_spice_input_init (void ) {QemuSpiceKbd *kbd; +QemuSpiceMouse *mouse; kbd =qemu_mallocz (sizeof (*kbd)); kbd->sin.base.sif = &kbd_interface.base;spice_server_add_interface (spice_server, &kbd->sin.base);qemu_add_led_event_handler (kbd_leds, kbd); + + mouse =qemu_mallocz (sizeof (*mouse)); + mouse->sin.base.sif = &mouse_interface.base; +spice_server_add_interface (spice_server, &mouse->sin.base); }
Signature · 1 line
1.6.6.1
RFC PATCH 6/11 spice: simple display
In reply to Gerd HoffmannWith that patch applied you'll actually see the guests screen in the spice client. This does *not* bring qxl and full spice support though. This is basically the qxl vga mode made more generic, so it plays together with any qemu-emulated gfx card. You can display stdvga or cirrus via spice client. You can have both vnc and spice enabled and clients connected at the same time.
--- Makefile.target | 2 +- qemu-spice.h | 1 + spice-display.c | 429 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ spice-display.h | 47 ++++++ vl.c | 7 +- 5 files changed, 484 insertions(+), 2 deletions(-) create mode 100644 spice-display.c create mode 100644 spice-display.h
Makefile.target +1 -1
@@ -194,7 +194,7 @@ obj-i386-y += cirrus_vga.o apic.o ioapic.o piix_pci.o obj-i386-y += vmmouse.o vmport.o hpet.o obj-i386-y += device-hotplug.o pci-hotplug.o smbios.o wdt_ib700.o obj-i386-y += debugcon.o multiboot.o -obj-i386-$(CONFIG_SPICE) += spice.o spice-input.o +obj-i386-$(CONFIG_SPICE) += spice.o spice-input.o spice-display.o # shared objects obj-ppc-y = ppc.o
qemu-spice.h +1 -0
@@ -13,6 +13,7 @@ extern int using_spice;void qemu_spice_init (void );void qemu_spice_input_init (void ); +void qemu_spice_display_init (DisplayState *ds);#else /* CONFIG_SPICE */
spice-display.c new file +429 -0
429 lines not on this page · raw message
spice-display.h new file +47 -0
47 lines not on this page · raw message
vl.c +6 -1
@@ -3704,7 +3704,7 @@ int main(int argc, char **argv, char **envp)/* just use the first displaystate for the moment */ ds =get_displaystate (); -if (display_type ==DT_DEFAULT ) { +if (display_type ==DT_DEFAULT && !using_spice) {#if defined(CONFIG_SDL ) || defined(CONFIG_COCOA ) display_type =DT_SDL ;#else
@@ -3744,6 +3744,11 @@ int main(int argc, char **argv, char **envp)default :break ; } +#ifdef CONFIG_SPICE +if (using_spice) { +qemu_spice_display_init (ds); + } +#endif dpy_resize (ds); dcl = ds->listeners;
Signature · 1 line
1.6.6.1
RFC PATCH 7/11 spice: tls support
In reply to Gerd HoffmannAdd options to the -spice command line switch to setup tls:
tls-port
listening port
x509-dir
x509 file directory. Expects same filenames as -vnc $display,x509=$dir
x509-key-file
x509-key-password
x509-cert-file
x509-cacert-file
x509-dh-key-file
x509 files can also be set individually.
tls-ciphers
which ciphers to use.
--- spice.c | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 86 insertions(+), 4 deletions(-)
spice.c +86 -4
@@ -8,6 +8,7 @@#include "qemu-spice.h" #include "qemu-timer.h" #include "qemu-queue.h" +#include "qemu-x509.h" #include "monitor.h" /* core bits */
@@ -132,11 +133,35 @@ QemuOptsList qemu_spice_opts = { .name = "port", .type = QEMU_OPT_NUMBER, },{ + .name = "tls-port", /* old: sport */ + .type = QEMU_OPT_NUMBER, + },{ .name = "password", .type = QEMU_OPT_STRING, },{ .name = "disable-ticketing", .type = QEMU_OPT_BOOL, + },{ + .name = "x509-dir", + .type = QEMU_OPT_STRING, + },{ + .name = "x509-key-file", /* old: sslkey */ + .type = QEMU_OPT_STRING, + },{ + .name = "x509-key-password", /* old: sslpassword */ + .type = QEMU_OPT_STRING, + },{ + .name = "x509-cert-file", /* old: sslcert */ + .type = QEMU_OPT_STRING, + },{ + .name = "x509-cacert-file", /* old: sslcafile */ + .type = QEMU_OPT_STRING, + },{ + .name = "x509-dh-key-file", /* old: ssldhfile */ + .type = QEMU_OPT_STRING, + },{ + .name = "tls-ciphers", /* old: sslciphersuite */ + .type = QEMU_OPT_STRING, }, { /* end if list */ } },
@@ -145,18 +170,71 @@ QemuOptsList qemu_spice_opts = {void qemu_spice_init (void ) {QemuOpts *opts =QTAILQ_FIRST (&qemu_spice_opts.head); -const char *password; -int port; +const char *password, *str, *x509_dir, + *x509_key_password =NULL , + *x509_dh_file =NULL , + *tls_ciphers =NULL ; +char *x509_key_file =NULL , + *x509_cert_file =NULL , + *x509_cacert_file =NULL ; +int port, tls_port, len;if (!opts)return ; port =qemu_opt_get_number (opts,"port" ,0 ); -if (!port) + tls_port =qemu_opt_get_number (opts,"tls-port" ,0 ); +if (!port && !tls_port)return ; password =qemu_opt_get (opts,"password" ); +if (tls_port) { + x509_dir =qemu_opt_get (opts,"x509-dir" ); +if (NULL == x509_dir) + x509_dir ="." ; + len =strlen (x509_dir) +32 ; + + str =qemu_opt_get (opts,"x509-key-file" ); +if (str) { + x509_key_file =qemu_strdup (str); + }else { + x509_key_file =qemu_malloc (len); +snprintf (x509_key_file, len,"%s/%s" , x509_dir,X509_SERVER_KEY_FILE ); + } + + str =qemu_opt_get (opts,"x509-cert-file" ); +if (str) { + x509_cert_file =qemu_strdup (str); + }else { + x509_cert_file =qemu_malloc (len); +snprintf (x509_cert_file, len,"%s/%s" , x509_dir,X509_SERVER_CERT_FILE ); + } + + str =qemu_opt_get (opts,"x509-cacert-file" ); +if (str) { + x509_cacert_file =qemu_strdup (str); + }else { + x509_cacert_file =qemu_malloc (len); +snprintf (x509_cacert_file, len,"%s/%s" , x509_dir,X509_CA_CERT_FILE ); + } + + x509_key_password =qemu_opt_get (opts,"x509-key-password" ); + x509_dh_file =qemu_opt_get (opts,"x509-dh-file" ); + tls_ciphers =qemu_opt_get (opts,"tls-ciphers" ); + } + spice_server =spice_server_new (); -spice_server_set_port (spice_server, port); +if (port) { +spice_server_set_port (spice_server, port); + } +if (tls_port) { +spice_server_set_tls (spice_server, tls_port, + x509_cacert_file, + x509_cert_file, + x509_key_file, + x509_key_password, + x509_dh_file, + tls_ciphers); + }if (password)spice_server_set_ticket (spice_server, password,0 ,0 ,0 );if (qemu_opt_get_bool (opts,"disable-ticketing" ,0 ))
@@ -169,4 +247,8 @@ void qemu_spice_init(void) using_spice =1 ;qemu_spice_input_init (); + +qemu_free (x509_key_file); +qemu_free (x509_cert_file); +qemu_free (x509_cacert_file); }
Signature · 1 line
1.6.6.1
RFC PATCH 8/11 spice: add qxl device
In reply to Gerd Hoffmann--- Makefile.target | 2 +- hw/hw.h | 14 + hw/pc.c | 8 + hw/qxl.c | 1035 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/vga_int.h | 2 +- qemu-spice.h | 2 + sysemu.h | 3 +- vl.c | 4 +- 8 files changed, 1066 insertions(+), 4 deletions(-) create mode 100644 hw/qxl.c
Makefile.target +1 -1
@@ -194,7 +194,7 @@ obj-i386-y += cirrus_vga.o apic.o ioapic.o piix_pci.o obj-i386-y += vmmouse.o vmport.o hpet.o obj-i386-y += device-hotplug.o pci-hotplug.o smbios.o wdt_ib700.o obj-i386-y += debugcon.o multiboot.o -obj-i386-$(CONFIG_SPICE) += spice.o spice-input.o spice-display.o +obj-i386-$(CONFIG_SPICE) += spice.o spice-input.o spice-display.o qxl.o # shared objects obj-ppc-y = ppc.o
hw/hw.h +14 -0
@@ -508,6 +508,17 @@ extern const VMStateInfo vmstate_info_unused_buffer; .start = (_start), \ } +#define VMSTATE_VBUFFER_UINT32 (_field, _state, _version, _test, _start, _field_size) { \ + .name = (stringify(_field)), \ + .version_id = (_version), \ + .field_exists = (_test), \ + .size_offset = vmstate_offset_value(_state, _field_size, uint32_t),\ + .info = &vmstate_info_buffer, \ + .flags = VMS_VBUFFER|VMS_POINTER, \ + .offset = offsetof(_state, _field), \ + .start = (_start), \ +} +#define VMSTATE_BUFFER_UNSAFE_INFO (_field, _state, _version, _info, _size) { \ .name = (stringify(_field)), \ .version_id = (_version), \
@@ -713,6 +724,9 @@ extern const VMStateDescription vmstate_i2c_slave;#define VMSTATE_PARTIAL_VBUFFER (_f, _s, _size) \ VMSTATE_VBUFFER(_f, _s, 0, NULL, 0, _size) +#define VMSTATE_PARTIAL_VBUFFER_UINT32 (_f, _s, _size) \ + VMSTATE_VBUFFER_UINT32(_f, _s, 0, NULL, 0, _size) +#define VMSTATE_SUB_VBUFFER (_f, _s, _start, _size) \ VMSTATE_VBUFFER(_f, _s, 0, NULL, _start, _size)
hw/pc.c +8 -0
@@ -47,6 +47,7 @@#include "elf.h" #include "multiboot.h" #include "kvm.h" +#include "qemu-spice.h" /* output Bochs bios info messages */ //#define DEBUG_BIOS
@@ -945,6 +946,13 @@ static void pc_init1(ram_addr_t ram_size,pci_vmsvga_init (pci_bus); else fprintf(stderr, "%s: vmware_vga: no PCI bus\n", __FUNCTION__); +#ifdef CONFIG_SPICE + }else if (qxl_enabled) { +if (pci_enabled) +pci_create_simple (pci_bus,-1 ,"qxl" ); +else +fprintf (stderr,"%s: qxl: no PCI bus\n" , __FUNCTION__); +#endif }else if (std_vga_enabled) {if (pci_enabled) {pci_vga_init (pci_bus,0 ,0 );
hw/qxl.c new file +1035 -0
1,035 lines not on this page · raw message
hw/vga_int.h +1 -1
@@ -106,7 +106,7 @@ typedef void (* vga_update_retrace_info_fn)(struct VGACommonState *s); typedef struct VGACommonState { uint8_t *vram_ptr; ram_addr_t vram_offset; - unsigned int vram_size; + uint32_t vram_size; uint32_t lfb_addr; uint32_t lfb_end; uint32_t map_addr;
qemu-spice.h +2 -0
@@ -15,6 +15,8 @@ void qemu_spice_init(void);void qemu_spice_input_init (void );void qemu_spice_display_init (DisplayState *ds); +void qxl_display_init (DisplayState *ds); +#else /* CONFIG_SPICE */ #define using_spice 0
sysemu.h +2 -1
@@ -103,7 +103,7 @@ extern int autostart;extern int bios_size;typedef enum { -VGA_NONE ,VGA_STD ,VGA_CIRRUS ,VGA_VMWARE ,VGA_XENFB +VGA_NONE ,VGA_STD ,VGA_CIRRUS ,VGA_VMWARE ,VGA_XENFB ,VGA_QXL , }VGAInterfaceType ;extern int vga_interface_type;
@@ -111,6 +111,7 @@ extern int vga_interface_type;#define std_vga_enabled (vga_interface_type == VGA_STD)#define xenfb_enabled (vga_interface_type == VGA_XENFB)#define vmsvga_enabled (vga_interface_type == VGA_VMWARE) +#define qxl_enabled (vga_interface_type == VGA_QXL)extern int graphic_width;extern int graphic_height;
vl.c +3 -1
@@ -2075,6 +2075,8 @@ static void select_vgahw (const char *p) vga_interface_type =VGA_VMWARE ; }else if (strstart (p,"xenfb" , &opts)) { vga_interface_type =VGA_XENFB ; + }else if (strstart (p,"qxl" , &opts)) { + vga_interface_type =VGA_QXL ; }else if (!strstart (p,"none" , &opts)) { invalid_vga:fprintf (stderr,"Unknown vga type: %s\n" , p);
@@ -3745,7 +3747,7 @@ int main(int argc, char **argv, char **envp)break ; }#ifdef CONFIG_SPICE -if (using_spice) { +if (using_spice && !qxl_enabled) {qemu_spice_display_init (ds); }#endif
Signature · 1 line
1.6.6.1
Re: [Qemu-devel] [RfC PATCH 08/11] spice: add qxl device
Quoted 4 lines · Gerd Hoffmann
+static inline void
atomic_or(uint32_t *var, uint32_t add)+{
+__asm____volatile__("lock; orl %1, %0" : "+m" (*var) : "r" (add) : "memory");
+}
This will break on non-x86 hosts.
Quoted 26 lines
+static QXLInterface
qxl_interface= {+ .base.type = SPICE_INTERFACE_QXL, + .base.description = "qxl gpu", + .base.major_version = SPICE_INTERFACE_QXL_MAJOR, + .base.minor_version = SPICE_INTERFACE_QXL_MINOR, + + .pci_vendor = REDHAT_PCI_VENDOR_ID, + .pci_id = QXL_DEVICE_ID, + .pci_revision = QXL_REVISION, + + .attache_worker = interface_attach_worker, + .set_compression_level = interface_set_compression_level, + .set_mm_time = interface_set_mm_time, + + .get_init_info = interface_get_init_info, + .get_command = interface_get_command, + .req_cmd_notification = interface_req_cmd_notification, + .has_command = interface_has_command, + .release_resource = interface_release_resource, + .get_cursor_command = interface_get_cursor_command, + .req_cursor_notification = interface_req_cursor_notification, + .get_update_area = interface_get_update_area, + .notify_update = interface_notify_update, + .set_save_data = interface_set_save_data, + .get_save_data = interface_get_save_data, + .flush_resources = interface_flush_resources,
Quoted 1 line
+};
Could this (and other similar cases) be const?
[Qemu-devel] Re: [RfC PATCH 08/11] spice: add qxl device
Quoted 7 lines · Blue Swirl
Quoted 4 lines · Gerd Hoffmann
+static inline void
atomic_or(uint32_t *var, uint32_t add)+{
+__asm____volatile__("lock; orl %1, %0" : "+m" (*var) : "r" (add) : "memory");
+}This will break on non-x86 hosts.
I'd just use __sync_fetch_and_or here.
Paolo
[Qemu-devel] Re: [RfC PATCH 08/11] spice: add qxl device
Quoted 7 lines · Paolo Bonzini
Quoted 5 lines · Blue Swirl
Quoted 3 lines · Gerd Hoffmann
+static inline void
atomic_or(uint32_t *var, uint32_t add)+{
+__asm____volatile__("lock; orl %1, %0" : "+m" (*var) : "r" (add)
Quoted 8 lines
: "memory");
Quoted 5 lines
Quoted 2 lines
+}
This will break on non-x86 hosts.
I'd just use
__sync_fetch_and_orhere.
And on environments without __sync_fetch_and_or? Where is that available?
Re: [Qemu-devel] Re: [RfC PATCH 08/11] spice: add qxl device
Quoted 12 lines · Blue Swirl
Quoted 11 lines · Paolo Bonzini
Quoted 5 lines · Blue Swirl
Quoted 3 lines · Gerd Hoffmann
+static inline void
atomic_or(uint32_t *var, uint32_t add)+{
+__asm____volatile__("lock; orl %1, %0" : "+m" (*var) : "r" (add): "memory");
Quoted 3 lines
Quoted 2 lines
+}
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
This will break on non-x86 hosts.
I'd just use
__sync_fetch_and_orhere.And on environments without
__sync_fetch_and_or? Where is that available?
GCC will provide it for capable cpus. So sparcv9 has it via CAS.
For less capable cpus, there may be cooperation with the system in some way. For instance, ARM, SH, and HPPA Linux kernels all provide various mechanisms to implement atomic sequences. The result continues to be provided by GCC in the form of entry points in libgcc.so.
For less capable cpus with no system support... well, the program itself needs to figure out what an appropriate response should be. I haven't gone back to look at the context from which this snippet was taken to know if a locally defined mutex would be adequate.
In either case, some configure tests that detect when various forms of atomic operations are available in the host compiler would not be amiss.
r~
[Qemu-devel] Re: [RfC PATCH 08/11] spice: add qxl device
In reply to Paolo BonziniQuoted 11 lines · Paolo Bonzini
Quoted 8 lines · Blue Swirl
Quoted 5 lines · Gerd Hoffmann
(quoted diff) +3
-0+static inline void atomic_or(uint32_t *var, uint32_t add) +{ + __asm__ __volatile__ ("lock; orl %1, %0" : "+m" (*var) : "r" (add): "memory");
+}This will break on non-x86 hosts.
I'd just use
__sync_fetch_and_orhere.
Good idea. I think we can zap the memory barrier and fix a small race while being at it, see the incremental fix below.
cheers,
Gerd
hw/qxl.c +4 -9
@@ -6,7 +6,6 @@#include <pthread.h> #include "qemu-common.h" -#include "qemu-barrier.h" #include "qemu-spice.h" #include "qemu-timer.h" #include "qemu-queue.h"
@@ -176,11 +175,6 @@ static inline uint32_t msb_mask(uint32_t val)return mask; } -static inline void atomic_or (uint32_t *var,uint32_t add) -{ - __asm__ __volatile__ ("lock; orl %1, %0" :"+m" (*var) :"r" (add) :"memory" ); -} -static ram_addr_t qxl_rom_size (void ) {uint32_t rom_size =sizeof (QXLRom) +sizeof (QXLModes) +sizeof (qxl_modes);
@@ -892,12 +886,13 @@ static void pipe_read(void *opaque)static void qxl_send_events (PCIQXLDevice *d,uint32_t events) { +uint32_t old_pending; +assert (d->ssd.running); -smp_wmb (); -if ((d->ram->int_pending & events) == events) { + old_pending =__sync_fetch_and_or (&d->ram->int_pending, events); +if ((old_pending & events) == events) {return ; } -atomic_or (&d->ram->int_pending, events);if (pthread_self () == d->main) {qxl_set_irq (d); }else {
[Qemu-devel] Re: [RfC PATCH 08/11] spice: add qxl device
Quoted 4 lines
Quoted 1 line
I'd just use
__sync_fetch_and_orhere.Good idea. I think we can zap the memory barrier and fix a small race while being at it, see the incremental fix below.
Not sure about the memory barrier semantics of __sync_* (rth?), but besides that the patch seems like a good idea.
Paolo
Re: [Qemu-devel] Re: [RfC PATCH 08/11] spice: add qxl device
Quoted 7 lines · Paolo Bonzini
Quoted 4 lines
Quoted 1 line
I'd just use
__sync_fetch_and_orhere.Good idea. I think we can zap the memory barrier and fix a small race while being at it, see the incremental fix below.
Not sure about the memory barrier semantics of __sync_* (rth?), but besides that the patch seems like a good idea.
I think a memory barrier isn't needed there. We don't touch anything shared beside int_pending which is only accessed using the sync op (after applying the patch).
cheers,
Gerd
[Qemu-devel] Re: [RfC PATCH 08/11] spice: add qxl device
In reply to Paolo BonziniQuoted 8 lines · Paolo Bonzini
Quoted 4 lines
Quoted 1 line
I'd just use
__sync_fetch_and_orhere.Good idea. I think we can zap the memory barrier and fix a small race while being at it, see the incremental fix below.
Not sure about the memory barrier semantics of __sync_* (rth?), but besides that the patch seems like a good idea.
The semantics of __sync_*, with only 2 exceptions, is full barrier.
r~
Re: [Qemu-devel] [RfC PATCH 08/11] spice: add qxl device
In reply to Gerd Hoffmannhw/qxl.c line 170
Quoted 4 lines · Gerd Hoffmann
hw/qxl.c new file +3
-0+static inline void atomic_or (uint32_t *var,uint32_t add) +{ + __asm__ __volatile__ ("lock; orl %1, %0" :"+m" (*var) :"r" (add) :"memory" );
I hope this is going away? I don't see why QXL should be coupled to x86 host and guest only.
Alex
Re: [Qemu-devel] [RfC PATCH 08/11] spice: add qxl device
Quoted 9 lines · Alexander Graf
hw/qxl.c line 170
Quoted 4 lines · Gerd Hoffmann
hw/qxl.c new file +3
-0+static inline void atomic_or (uint32_t *var,uint32_t add) +{ + __asm__ __volatile__ ("lock; orl %1, %0" :"+m" (*var) :"r" (add) :"memory" );I hope this is going away? I don't see why QXL should be coupled to x86 host and guest only.
Spice on !x86 (especially big endian boxes) isn't going to fly at the moment for a number of reasons. That is considered a bug though and we want fix it long-term. There is nothing fundamental which prevents qxl and spice from being used on -- say -- ppc.
cheers,
Gerd
RFC PATCH 9/11 qxl: local rendering for sdl/vnc
In reply to Gerd HoffmannNot fully functional yet. Known issues:
- if the guest creates a "top down" primary surface (windows does) the vns/sdl display will be upside down.
- mouse pointer isn't rendered.
--- hw/qxl.c | 121 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 117 insertions(+), 4 deletions(-)
hw/qxl.c +117 -4
@@ -61,6 +61,12 @@ typedef struct PCIQXLDevice {enum qxl_mode mode;int generation; +DisplaySurface *surface_native; +SpiceRect surface_rect; +uint32_t surface_id; +int surface_render; +int surface_commands; +/* thread signaling */ pthread_t main;int pipe[2 ];
@@ -325,6 +331,7 @@ static int interface_get_command(QXLInstance *sin, struct QXLCommandExt *ext)if (notify) {qxl_send_events (qxl,QXL_INTERRUPT_DISPLAY ); } + qxl->surface_commands++;return true;case QXL_MODE_UNDEFINED :default :
@@ -433,6 +440,7 @@ static int interface_get_cursor_command(QXLInstance *sin, struct QXLCommandExt *if (notify) {qxl_send_events (qxl,QXL_INTERRUPT_CURSOR ); } + qxl->surface_commands++;return true; }else {return false;
@@ -454,6 +462,13 @@ static void interface_get_update_area(QXLInstance *sin, const struct SpiceRect * {PCIQXLDevice *qxl =container_of (sin, PCIQXLDevice, ssd.qxl); +if (qxl->surface_render) { + qxl->surface_render =0 ; + *rect = &qxl->surface_rect; + *surface_id = &qxl->surface_id; +return ; + } + *rect = &qxl->ram->update_area; *surface_id = &qxl->ram->update_surface; }
@@ -711,6 +726,7 @@ static void qxl_del_memslot(PCIQXLDevice *d, uint32_t slot_id)static void qxl_create_guest_primary (PCIQXLDevice *d) {QXLDevSurfaceCreate surface; +void *ptr;assert (d->mode !=QXL_MODE_NATIVE );qxl_exit_vga_mode (d);
@@ -732,6 +748,30 @@ static void qxl_create_guest_primary(PCIQXLDevice *d) d->mode =QXL_MODE_NATIVE ; d->ssd.worker->create_primary_surface (d->ssd.worker,0 , &surface); + +fprintf (stderr,"%s: width %d height %d depth %d stride %d\n" , __FUNCTION__, + surface.width, surface.height, surface.depth, surface.stride); + +if (surface.stride <0 ) { +/* FIXME: will display upside down */ + surface.stride = -surface.stride; + } + +if (d->surface_native) { +qemu_free (d->surface_native); + d->surface_native =NULL ; + } + + ptr =qemu_get_ram_ptr (d->vga.vram_offset); + d->surface_native = +qemu_create_displaysurface_from (surface.width, surface.height, + surface.depth, surface.stride, ptr); + + d->surface_id =0 ; + d->surface_rect.top =0 ; + d->surface_rect.bottom = surface.height; + d->surface_rect.left =0 ; + d->surface_rect.right = surface.width; }static void qxl_destroy_primary (PCIQXLDevice *d)
@@ -826,10 +866,16 @@ static uint32_t ioport_read(void *opaque, uint32_t addr)static void qxl_map (PCIDevice *pci,int region_num,pcibus_t addr,pcibus_t size,int type) { +static const char *names[] = { + [QXL_IO_RANGE_INDEX ] ="ioports" , + [QXL_RAM_RANGE_INDEX ] ="devram" , + [QXL_ROM_RANGE_INDEX ] ="rom" , + [QXL_VRAM_RANGE_INDEX ] ="vram" , + };PCIQXLDevice *qxl =DO_UPCAST (PCIQXLDevice, pci, pci); -dprintf (1 ,"%s: bar %d addr 0x%lx size 0x%lx\n" , __FUNCTION__, - region_num, addr, size); +dprintf (1 ,"%s: bar %d [%s] addr 0x%lx size 0x%lx\n" , __FUNCTION__, + region_num, names[region_num], addr, size);switch (region_num) {case QXL_IO_RANGE_INDEX :
@@ -901,6 +947,67 @@ static void init_pipe_signaling(PCIQXLDevice *d)qemu_set_fd_handler (d->pipe[0 ], pipe_read,NULL , d); } +/* graphics console */ + +static void qxl_hw_update (void *opaque) +{ +PCIQXLDevice *qxl = opaque; +VGACommonState *vga = &qxl->vga; + +if (qxl->mode ==QXL_MODE_VGA ) { + vga->update (vga); +return ; + } + +if (qxl->surface_native) { +qemu_free_displaysurface (vga->ds); + vga->ds->surface = qxl->surface_native; + qxl->surface_native =NULL ; +dpy_resize (vga->ds); + } + +if (qxl->surface_commands) { + qxl->surface_commands =0 ; + qxl->surface_render =1 ; + qxl->ssd.worker->update_area (qxl->ssd.worker); + +/* FIXME: want more specific dirty region here */ +dpy_update (vga->ds,0 ,0 ,ds_get_width (vga->ds),ds_get_height (vga->ds)); + } +} + +static void qxl_hw_invalidate (void *opaque) +{ +PCIQXLDevice *qxl = opaque; +VGACommonState *vga = &qxl->vga; + + vga->invalidate (vga); +} + +static void qxl_hw_screen_dump (void *opaque,const char *filename) +{ +PCIQXLDevice *qxl = opaque; +VGACommonState *vga = &qxl->vga; + +if (qxl->mode ==QXL_MODE_VGA ) { + vga->screen_dump (vga, filename); +return ; + } +} + +static void qxl_hw_text_update (void *opaque,console_ch_t *chardata) +{ +PCIQXLDevice *qxl = opaque; +VGACommonState *vga = &qxl->vga; + +if (qxl->mode ==QXL_MODE_VGA ) { + vga->text_update (vga, chardata); +return ; + } +} + +/* display change listener */ +static void display_update (struct DisplayState *ds,int x,int y,int w,int h) {if (qxl0->mode ==QXL_MODE_VGA ) {
@@ -950,13 +1057,19 @@ static int qxl_init(PCIDevice *dev)register_ioport_write (0x3ba ,1 ,1 , qxl_vga_ioport_write, vga);register_ioport_write (0x3da ,1 ,1 , qxl_vga_ioport_write, vga); - qxl0 = qxl; +#if 0 vga->ds =graphic_console_init (vga->update, vga->invalidate, vga->screen_dump, vga->text_update, vga); +#else + vga->ds =graphic_console_init (qxl_hw_update, qxl_hw_invalidate, + qxl_hw_screen_dump, qxl_hw_text_update, qxl); +#endif qxl->ssd.ds = vga->ds; qxl->ssd.bufsize = (16 *1024 *1024 ); qxl->ssd.buf =qemu_malloc (qxl->ssd.bufsize);pthread_mutex_init (&qxl->ssd.lock,NULL ); + + qxl0 = qxl;register_displaychangelistener (vga->ds, &display_listener);if (qxl->pci.romfile ==NULL )
@@ -1021,7 +1134,7 @@ static PCIDeviceInfo qxl_info = { .init = qxl_init, .config_write = qxl_write_config, .qdev.props = (Property[]) { -DEFINE_PROP_UINT32 ("ram_size" , PCIQXLDevice, vga.vram_size,32 *1024 *1024 ), +DEFINE_PROP_UINT32 ("ram_size" , PCIQXLDevice, vga.vram_size,64 *1024 *1024 ),DEFINE_PROP_UINT32 ("vram_size" , PCIQXLDevice, vram_size,64 *1024 *1024 ),DEFINE_PROP_END_OF_LIST (), }
Signature · 1 line
1.6.6.1
RFC PATCH 10/11 spice: add tablet support
In reply to Gerd Hoffmann--- spice-display.c | 2 +- spice-input.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 89 insertions(+), 8 deletions(-)
spice-display.c +1 -1
@@ -149,7 +149,7 @@ void qemu_spice_create_host_primary(SimpleSpiceDisplay *ssd) surface.width =ds_get_width (ssd->ds); surface.height =ds_get_height (ssd->ds); surface.stride = -surface.width *4 ; - surface.mouse_mode =0 ; + surface.mouse_mode = true; surface.flags =0 ; surface.type =0 ; surface.mem = (intptr_t )ssd->buf;
spice-input.c +88 -7
119 lines not on this page · raw message
Signature · 1 line
1.6.6.1
RFC PATCH 11/11 spice: add audio
In reply to Gerd Hoffmann--- Makefile.objs | 1 + audio/audio.c | 3 + audio/audio_int.h | 1 + audio/spiceaudio.c | 315 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 320 insertions(+), 0 deletions(-) create mode 100644 audio/spiceaudio.c
Makefile.objs +1 -0
@@ -84,6 +84,7 @@ common-obj-$(CONFIG_POSIX) += migration-exec.o migration-unix.o migration-fd.o audio-obj-y = audio.o noaudio.o wavaudio.o mixeng.o audio-obj-$(CONFIG_SDL) += sdlaudio.o audio-obj-$(CONFIG_OSS) += ossaudio.o +audio-obj-$(CONFIG_SPICE) += spiceaudio.o audio-obj-$(CONFIG_COREAUDIO) += coreaudio.o audio-obj-$(CONFIG_ALSA) += alsaaudio.o audio-obj-$(CONFIG_DSOUND) += dsoundaudio.o
audio/audio.c +3 -0
@@ -45,6 +45,9 @@*/ static struct audio_driver *drvtab[] = {CONFIG_AUDIO_DRIVERS +#ifdef CONFIG_SPICE + &spice_audio_driver, +#endif &no_audio_driver, &wav_audio_driver };
audio/audio_int.h +1 -0
@@ -209,6 +209,7 @@ extern struct audio_driver coreaudio_audio_driver;extern struct audio_driver dsound_audio_driver;extern struct audio_driver esd_audio_driver;extern struct audio_driver pa_audio_driver; +extern struct audio_driver spice_audio_driver;extern struct audio_driver winwave_audio_driver;extern struct mixeng_volume nominal_volume;
audio/spiceaudio.c new file +315 -0
315 lines not on this page · raw message
Signature · 1 line
1.6.6.1
Re: [Qemu-devel] [RfC PATCH 11/11] spice: add audio
On Wed, 14 Apr 2010, Gerd Hoffmann wrote:
The code does not follow neither audio(which is passable should it be internally consistent) nor general QEMU code style (braces missing)
Quoted 90 lines
--- Makefile.objs | 1 + audio/audio.c | 3 + audio/audio_int.h | 1 + audio/spiceaudio.c | 315 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 320 insertions(+), 0 deletions(-) create mode 100644 audio/spiceaudio.cMakefile.objs +1
-0@@ -84,6 +84,7 @@ common-obj-$(CONFIG_POSIX) += migration-exec.o migration-unix.o migration-fd.o audio-obj-y = audio.o noaudio.o wavaudio.o mixeng.o audio-obj-$(CONFIG_SDL) += sdlaudio.o audio-obj-$(CONFIG_OSS) += ossaudio.o +audio-obj-$(CONFIG_SPICE) += spiceaudio.o audio-obj-$(CONFIG_COREAUDIO) += coreaudio.o audio-obj-$(CONFIG_ALSA) += alsaaudio.o audio-obj-$(CONFIG_DSOUND) += dsoundaudio.oaudio/audio.c +3
-0@@ -45,6 +45,9 @@*/ static struct audio_driver *drvtab[] = {CONFIG_AUDIO_DRIVERS +#ifdef CONFIG_SPICE + &spice_audio_driver, +#endif &no_audio_driver, &wav_audio_driver };audio/audio_int.h +1
-0@@ -209,6 +209,7 @@ extern struct audio_driver coreaudio_audio_driver;extern struct audio_driver dsound_audio_driver;extern struct audio_driver esd_audio_driver;extern struct audio_driver pa_audio_driver; +extern struct audio_driver spice_audio_driver;extern struct audio_driver winwave_audio_driver;extern struct mixeng_volume nominal_volume;audio/spiceaudio.c new file +38
-0@@ -0,0 +1,315 @@ +#include "hw/hw.h" +#include "qemu-timer.h" +#include "qemu-spice.h" + +#define AUDIO_CAP "spice" +#include "audio.h" +#include "audio_int.h" + +#define LINE_IN_SAMPLES 1024 +#define LINE_OUT_SAMPLES 1024 + +typedef struct SpiceVoiceOut { +HWVoiceOut hw; +SpicePlaybackInstance sin; +uint32_t *frame; +uint32_t *fpos; +uint32_t fsize; +uint64_t prev_ticks; +int active; +}SpiceVoiceOut ; + +typedef struct SpiceVoiceIn { +HWVoiceIn hw; +SpiceRecordInstance sin; +uint64_t prev_ticks; +int active; +uint32_t samples[LINE_IN_SAMPLES ]; +}SpiceVoiceIn ; + +static SpicePlaybackInterface playback_sif = { + .base.type =SPICE_INTERFACE_PLAYBACK , + .base.description ="playback" , + .base.major_version =SPICE_INTERFACE_PLAYBACK_MAJOR , + .base.minor_version =SPICE_INTERFACE_PLAYBACK_MINOR , +}; + +static SpiceRecordInterface record_sif = { + .base.type =SPICE_INTERFACE_RECORD ,
audio/spiceaudio.c line 48
Quoted 10 lines
audio/spiceaudio.c new file +10
-0+ .base.description = "record", + .base.major_version = SPICE_INTERFACE_RECORD_MAJOR, + .base.minor_version = SPICE_INTERFACE_RECORD_MINOR, +}; + +static void *spice_audio_init (void ) +{ +if (!using_spice) +return NULL ; +return qemu_malloc (42 );
Eh? The HGttG references should at least be given an explanation in the comments.
audio/spiceaudio.c line 59
Quoted 11 lines
audio/spiceaudio.c new file +11
-0+} + +static void spice_audio_fini (void *opaque) +{ +qemu_free (opaque); +} + +static uint64_t get_monotonic_time (void ) +{ +struct timespec time_space; +clock_gettime (CLOCK_MONOTONIC , &time_space);
a. The presence of monotonic clock is not guranteed
b. The call can fail yet the result value is not checked c. I have a really hard time following what rt clock (regardless
of monotonicity is doing here at all)
Quoted 257 lines
audio/spiceaudio.c new file +256
-0+return (uint64_t )time_space.tv_sec *1000 *1000 *1000 + time_space.tv_nsec; +} + +/* playback */ + +static int line_out_init (HWVoiceOut *hw,struct audsettings *as) +{ +SpiceVoiceOut *out =container_of (hw, SpiceVoiceOut, hw); +struct audsettings settings; + + settings.freq =SPICE_INTERFACE_PLAYBACK_FREQ ; + settings.nchannels =SPICE_INTERFACE_PLAYBACK_CHAN ; + settings.fmt =AUD_FMT_S16 ; + settings.endianness =AUDIO_HOST_ENDIANNESS ; + +audio_pcm_init_info (&hw->info, &settings); + hw->samples =LINE_OUT_SAMPLES ; + out->active =0 ; + + out->sin.base.sif = &playback_sif.base; +spice_server_add_interface (spice_server, &out->sin.base); +return 0 ; +} + +static void line_out_fini (HWVoiceOut *hw) +{ +SpiceVoiceOut *out =container_of (hw, SpiceVoiceOut, hw); + +spice_server_remove_interface (&out->sin.base); +} + +static int line_out_run (HWVoiceOut *hw,int live) +{ +SpiceVoiceOut *out =container_of (hw, SpiceVoiceOut, hw); +int rpos, decr; +int samples; +uint64_t now; +uint64_t ticks; +uint64_t bytes; + +if (!live) { +return 0 ; + } + + now =get_monotonic_time (); + ticks = now - out->prev_ticks; + bytes = (ticks * hw->info.bytes_per_second) / (1000 *1000 *1000 ); + out->prev_ticks = now; + + decr = (bytes >INT_MAX ) + ?INT_MAX >> hw->info.shift + : (bytes + (1 << (hw->info.shift -1 ))) >> hw->info.shift; + decr =audio_MIN (live, decr); + + samples = decr; + rpos = hw->rpos; +while (samples) { +int left_till_end_samples = hw->samples - rpos; +int len =audio_MIN (samples, left_till_end_samples); + +if (!out->frame) { +spice_server_playback_get_buffer (&out->sin, &out->frame, &out->fsize); + out->fpos = out->frame; + } +if (out->frame) { + len =audio_MIN (len, out->fsize); + hw->clip (out->fpos, hw->mix_buf + rpos, len); + out->fsize -= len; + out->fpos += len; +if (out->fsize ==0 ) { +spice_server_playback_put_samples (&out->sin, out->frame); + out->frame = out->fpos =NULL ; + } + } + rpos = (rpos + len) % hw->samples; + samples -= len; + } + hw->rpos = rpos; +return decr; +} + +static int line_out_write (SWVoiceOut *sw,void *buf,int len) +{ +return audio_pcm_sw_write (sw, buf, len); +} + +static int line_out_ctl (HWVoiceOut *hw,int cmd, ...) +{ +SpiceVoiceOut *out =container_of (hw, SpiceVoiceOut, hw); + +switch (cmd) { +case VOICE_ENABLE : +if (out->active) { +break ; + } + out->active =1 ; + out->prev_ticks =get_monotonic_time (); +spice_server_playback_start (&out->sin); +break ; +case VOICE_DISABLE : +if (!out->active) { +break ; + } + out->active =0 ; +if (out->frame) { +memset (out->fpos,0 , out->fsize <<2 ); +spice_server_playback_put_samples (&out->sin, out->frame); + out->frame = out->fpos =NULL ; +spice_server_playback_stop (&out->sin); + } +break ; + } +return 0 ; +} + +/* record */ + +static int line_in_init (HWVoiceIn *hw,struct audsettings *as) +{ +SpiceVoiceIn *in =container_of (hw, SpiceVoiceIn, hw); +struct audsettings settings; + + settings.freq =SPICE_INTERFACE_RECORD_FREQ ; + settings.nchannels =SPICE_INTERFACE_RECORD_CHAN ; + settings.fmt =AUD_FMT_S16 ; + settings.endianness =AUDIO_HOST_ENDIANNESS ; + +audio_pcm_init_info (&hw->info, &settings); + hw->samples =LINE_IN_SAMPLES ; + in->active =0 ; + + in->sin.base.sif = &record_sif.base; +spice_server_add_interface (spice_server, &in->sin.base); +return 0 ; +} + +static void line_in_fini (HWVoiceIn *hw) +{ +SpiceVoiceIn *in =container_of (hw, SpiceVoiceIn, hw); + +spice_server_remove_interface (&in->sin.base); +} + +static int line_in_run (HWVoiceIn *hw) +{ +SpiceVoiceIn *in =container_of (hw, SpiceVoiceIn, hw); +int num_samples; +int ready; +int len[2 ]; +uint64_t now; +uint64_t ticks; +uint64_t delta_samp; +uint32_t *samples; + +if (!(num_samples = hw->samples -audio_pcm_hw_get_live_in (hw))) { +return 0 ; + } + + now =get_monotonic_time (); + ticks = now - in->prev_ticks; + in->prev_ticks = now; + delta_samp = (ticks * hw->info.bytes_per_second) / (1000 *1000 *1000 ); + delta_samp = (delta_samp + (1 << (hw->info.shift -1 ))) >> hw->info.shift; + + num_samples =audio_MIN (num_samples, delta_samp); + + ready =spice_server_record_get_samples (&in->sin, in->samples, num_samples); + samples = in->samples; +if (ready ==0 ) { +static uint32_t silence[LINE_IN_SAMPLES ]; + samples = silence; + ready =LINE_IN_SAMPLES ; + } + + num_samples =audio_MIN (ready, num_samples); + +if (hw->wpos + num_samples > hw->samples) { + len[0 ] = hw->samples - hw->wpos; + len[1 ] = num_samples - len[0 ]; + }else { + len[0 ] = num_samples; + len[1 ] =0 ; + } + + hw->conv (hw->conv_buf + hw->wpos, samples, len[0 ], &nominal_volume); + +if (len[1 ]) { + hw->conv (hw->conv_buf, samples + len[0 ], len[1 ], + &nominal_volume); + } + + hw->wpos = (hw->wpos + num_samples) % hw->samples; + +return num_samples; +} + +static int line_in_read (SWVoiceIn *sw,void *buf,int size) +{ +return audio_pcm_sw_read (sw, buf, size); +} + +static int line_in_ctl (HWVoiceIn *hw,int cmd, ...) +{ +SpiceVoiceIn *in =container_of (hw, SpiceVoiceIn, hw); + +switch (cmd) { +case VOICE_ENABLE : +if (in->active) { +break ; + } + in->active =1 ; + in->prev_ticks =get_monotonic_time (); +spice_server_record_start (&in->sin); +break ; +case VOICE_DISABLE : +if (!in->active) { +break ; + } + in->active =0 ; +spice_server_record_stop (&in->sin); +break ; + } +return 0 ; +} + +static struct audio_option audio_options[] = { + {/* end of list */ }, +}; + +static struct audio_pcm_ops audio_callbacks = { + .init_out = line_out_init, + .fini_out = line_out_fini, + .run_out = line_out_run, + .write = line_out_write, + .ctl_out = line_out_ctl, + + .init_in = line_in_init, + .fini_in = line_in_fini, + .run_in = line_in_run, + .read = line_in_read, + .ctl_in = line_in_ctl, +}; + +struct audio_driver spice_audio_driver = { + .name ="spice" , + .descr ="spice audio driver" , + .options = audio_options, + .init = spice_audio_init, + .fini = spice_audio_fini, + .pcm_ops = &audio_callbacks, + .can_be_default =1 , + .max_voices_out =1 , + .max_voices_in =1 , + .voice_size_out =sizeof (SpiceVoiceOut), + .voice_size_in =sizeof (SpiceVoiceIn), +};
Signature · 1 line
mailto:[email protected]
[Qemu-devel] Re: [RfC PATCH 11/11] spice: add audio
Quoted 6 lines · malc
Quoted 5 lines
Quoted 5 lines
+
+staticuint64_tget_monotonic_time(void)
+{
+ struct timespectime_space;
+clock_gettime(CLOCK_MONOTONIC,&time_space);a. The presence of monotonic clock is not guranteed
There is qemu_get_clock_ns(rt_clock).
Paolo
[Qemu-devel] Re: [RfC PATCH 11/11] spice: add audio
Quoted 9 lines · Paolo Bonzini
Quoted 6 lines · malc
Quoted 5 lines
Quoted 5 lines
+
+staticuint64_tget_monotonic_time(void)
+{
+ struct timespectime_space;
+clock_gettime(CLOCK_MONOTONIC,&time_space);a. The presence of monotonic clock is not guranteed
There is
qemu_get_clock_ns(rt_clock).
Sorry, but what does it have to do with anything?
Quoted 3 lines
Paolo
Signature · 1 line
mailto:[email protected]
[Qemu-devel] Re: [RfC PATCH 11/11] spice: add audio
Quoted 8 lines · malc
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
+static
uint64_tget_monotonic_time(void)
+{
+ struct timespectime_space;
+clock_gettime(CLOCK_MONOTONIC,&time_space);a. The presence of monotonic clock is not guranteed
There is
qemu_get_clock_ns(rt_clock).Sorry, but what does it have to do with anything?
It is exactly the same as Gerd's function plus a fallback if no monotonic clock is available.
Paolo
[Qemu-devel] Re: [RfC PATCH 11/11] spice: add audio
Quoted 5 lines · Paolo Bonzini
Quoted 4 lines · malc
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
+static
uint64_tget_monotonic_time(void)
+{
+ struct timespectime_space;
+clock_gettime(CLOCK_MONOTONIC,&time_space);
Quoted 8 lines
Quoted 4 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line
a. The presence of monotonic clock is not guranteed
There is
qemu_get_clock_ns(rt_clock).Sorry, but what does it have to do with anything?
It is exactly the same as Gerd's function plus a fallback if no monotonic clock is available.
Ah get_clock which is as broken as snippet above.
Signature · 1 line
mailto:[email protected]
Re: [Qemu-devel] [RfC PATCH 11/11] spice: add audio
In reply to malcQuoted 4 lines · malc
On Wed, 14 Apr 2010, Gerd Hoffmann wrote:
The code does not follow neither audio(which is passable should it be internally consistent) nor general QEMU code style (braces missing)
Will add the missing braces.
Quoted 8 lines
audio/spiceaudio.c line 48
Quoted 5 lines
audio/spiceaudio.c new file +5
-0+static void *spice_audio_init (void ) +{ +if (!using_spice) +return NULL ; +return qemu_malloc (42 );Eh? The HGttG references should at least be given an explanation in the comments.
Just need return something non-NULL here to indicate success. Also wanted to check how carefully the reviewers are looking ;)
Quoted 2 lines
c. I have a really hard time following what rt clock (regardless
of monotonicity is doing here at all)
Accept audio data with the correct rate. When sending directly to the audio device the host hardware controls this. Spice sends the audio data off to the network, so this doesn't work. The math used by spice here looks like a old version of the noaudio code for rate control (/me inherited that code so I don't know for sure), which makes sense to me.
cheers,
Gerd
Re: [Qemu-devel] [RfC PATCH 11/11] spice: add audio
Hi,
Quoted 8 lines
Quoted 2 lines
c. I have a really hard time following what rt clock (regardless of monotonicity is doing here at all)
Accept audio data with the correct rate. When sending directly to the audio device the host hardware controls this. Spice sends the audio data off to the network, so this doesn't work. The math used by spice here looks like a old version of the noaudio code for rate control (/me inherited that code so I don't know for sure), which makes sense to me.
malc pointed out in irc simliar discussions came up for esd support. Thread starts here:
http://www.mail-archive.com/[email protected]/msg06593.html
Summary: having two clocks should better be avoided (one being vmclock and the other esd consuming the data, i.e. indirectly the sound hardware actually playing the data). So instead of using vmtime for rate control the esd driver just feeds esd as fast as it can accept data.
Advantage of that approach:
You'll avoid all clock sync issues such as audible audio blibs happening in case one clock is slightly faster as the other.
Problems with that approach:
General: It adds extra latency.
Spice: A client may or may not be connected. In case no client is connected nobody consumes the sound stream data and thus there is no clock ...
cheers,
Gerd