virtio_gpu_3d: make it possible to configure the fence poll time
PATCH 1/1 virtio_gpu_3d: make it possible to configure the fence poll time
The default fence poll time of 10ms (100 Hz) is sufficent for normal work loads, but if one wants to play games within the virtual machine this value might be too high, so make it possible to configure this value by using the environment variable QEMU_VIRGL_POLL_FREQ where the poll is given in Hz. To acommodate higher poll frequencies also change the timer to use micro seconds as base instead of milliseconds.
--- hw/display/virtio-gpu-3d.c | 18 ++++++++++++++++-- include/hw/virtio/virtio-gpu.h | 1 + 2 files changed, 17 insertions(+), 2 deletions(-)
hw/display/virtio-gpu-3d.c +16 -2
@@ -17,6 +17,7 @@#include "trace.h" #include "hw/virtio/virtio.h" #include "hw/virtio/virtio-gpu.h" +#include "qemu/cutils.h" #ifdef CONFIG_VIRGL
@@ -580,7 +581,8 @@ static void virtio_gpu_fence_poll(void *opaque)virgl_renderer_poll ();virtio_gpu_process_cmdq (g);if (!QTAILQ_EMPTY (&g->cmdq) || !QTAILQ_EMPTY (&g->fenceq)) { -timer_mod (g->fence_poll,qemu_clock_get_ms (QEMU_CLOCK_VIRTUAL ) +1 ); +timer_mod (g->fence_poll,qemu_clock_get_us (QEMU_CLOCK_VIRTUAL ) + + g->fence_poll_timeout); } }
@@ -605,13 +607,25 @@ void virtio_gpu_virgl_reset(VirtIOGPU *g)int virtio_gpu_virgl_init (VirtIOGPU *g) {int ret; +const char *val; ret =virgl_renderer_init (g,0 , &virtio_gpu_3d_cbs);if (ret !=0 ) {return ret; } - g->fence_poll =timer_new_ms (QEMU_CLOCK_VIRTUAL , + g->fence_poll_timeout =10000 ;/* default 10 ms */ + val =getenv ("QEMU_VIRGL_POLL_FREQ" ); +if (val) { +unsigned long long poll_freq; +if (parse_uint_full (val, &poll_freq,10 ) || poll_freq >UINT32_MAX ) { +fprintf (stderr,"VIRGL_POLL_FREQ: Invalid integer `%s'\n" , val); +exit (1 ); + } + g->fence_poll_timeout =1000000 / (uint32_t )poll_freq; + } + + g->fence_poll =timer_new_us (QEMU_CLOCK_VIRTUAL , virtio_gpu_fence_poll, g);if (virtio_gpu_stats_enabled (g->conf)) {
include/hw/virtio/virtio-gpu.h +1 -0
@@ -116,6 +116,7 @@ typedef struct VirtIOGPU {bool renderer_reset;QEMUTimer *fence_poll;QEMUTimer *print_stats; +uint32_t fence_poll_timeout;uint32_t inflight;struct {
Signature · 1 line
2.20.1
Hi
Quoted 9 lines · Gert Wollny
The default fence poll time of 10ms (100 Hz) is sufficent for normal work loads, but if one wants to play games within the virtual machine this value might be too high, so make it possible to configure this value by using the environment variable
QEMU_VIRGL_POLL_FREQwhere the poll is given in Hz. To acommodate higher poll frequencies also change the timer to use micro seconds as base instead of milliseconds.
This is what VIRGL_RENDERER_THREAD_SYNC helps with. You don't need to do regular polling, but I think it is currently limited to Linux/eventfd only.
fwiw, vhost-user-gpu uses it.
Quoted 71 lines
Signed-off-by Gert Wollny <[email protected]>--- hw/display/virtio-gpu-3d.c | 18 ++++++++++++++++-- include/hw/virtio/virtio-gpu.h | 1 + 2 files changed, 17 insertions(+), 2 deletions(-)hw/display/virtio-gpu-3d.c +16
-2@@ -17,6 +17,7 @@#include "trace.h" #include "hw/virtio/virtio.h" #include "hw/virtio/virtio-gpu.h" +#include "qemu/cutils.h" #ifdef CONFIG_VIRGL @@ -580,7 +581,8 @@ static void virtio_gpu_fence_poll(void *opaque)virgl_renderer_poll ();virtio_gpu_process_cmdq (g);if (!QTAILQ_EMPTY (&g->cmdq) || !QTAILQ_EMPTY (&g->fenceq)) { -timer_mod (g->fence_poll,qemu_clock_get_ms (QEMU_CLOCK_VIRTUAL ) +1 ); +timer_mod (g->fence_poll,qemu_clock_get_us (QEMU_CLOCK_VIRTUAL ) + + g->fence_poll_timeout); } }@@ -605,13 +607,25 @@ void virtio_gpu_virgl_reset(VirtIOGPU *g)int virtio_gpu_virgl_init (VirtIOGPU *g) {int ret; +const char *val; ret =virgl_renderer_init (g,0 , &virtio_gpu_3d_cbs);if (ret !=0 ) {return ret; } - g->fence_poll =timer_new_ms (QEMU_CLOCK_VIRTUAL , + g->fence_poll_timeout =10000 ;/* default 10 ms */ + val =getenv ("QEMU_VIRGL_POLL_FREQ" ); +if (val) { +unsigned long long poll_freq; +if (parse_uint_full (val, &poll_freq,10 ) || poll_freq >UINT32_MAX ) { +fprintf (stderr,"VIRGL_POLL_FREQ: Invalid integer `%s'\n" , val); +exit (1 ); + } + g->fence_poll_timeout =1000000 / (uint32_t )poll_freq; + } + + g->fence_poll =timer_new_us (QEMU_CLOCK_VIRTUAL , virtio_gpu_fence_poll, g);if (virtio_gpu_stats_enabled (g->conf)) {include/hw/virtio/virtio-gpu.h +1
-1@@ -116,6 +116,7 @@ typedef struct VirtIOGPU {bool renderer_reset;QEMUTimer *fence_poll;QEMUTimer *print_stats; +uint32_t fence_poll_timeout;uint32_t inflight;struct { --2.20.1
Signature · 1 line
Marc-André Lureau
Am Donnerstag, den 23.05.2019, 16:01 +0200 schrieb Marc-André Lureau:
Quoted 17 lines
Hi
Quoted 12 lines · Gert Wollny
The default fence poll time of 10ms (100 Hz) is sufficent for normal
work loads, but if one wants to play games within the virtual machine
this value might be too high, so make it possible to configure this value by using the environment variableQEMU_VIRGL_POLL_FREQwhere the
poll is given in Hz. To acommodate higher poll frequencies also change
the timer to use micro seconds as base instead of milliseconds.
Quoted 3 lines
This is what
VIRGL_RENDERER_THREAD_SYNChelps with. You don't need to do regular polling, but I think it is currently limited to Linux/eventfd only.
As far as I can see only vtest uses this, not qemu.
Quoted 2 lines
fwiw, vhost-user-gpu uses it.
Yeah, I tested it on Intel, but AFAICS this hasn't landed yet, no? OTOH the drm calls were only implemented for Intel, and I have no idea how to implement this for other hardware, like e.g. radeonsi, or even the Nvidia blob ...
Best,
Gert
Quoted 81 lines
Quoted 79 lines
Signed-off-by Gert Wollny <[email protected]>--- hw/display/virtio-gpu-3d.c | 18 ++++++++++++++++-- include/hw/virtio/virtio-gpu.h | 1 + 2 files changed, 17 insertions(+), 2 deletions(-)hw/display/virtio-gpu- renamed from hw/display/virtio-gpu-3d.c +0
-0
3d.c
index5ee3566ae0..120e593e76100644hw/display/virtio-gpu-3d.c +2
-1@@ -17,6 +17,7 @@#include "trace.h" #include "hw/virtio/virtio.h" #include "hw/virtio/virtio-gpu.h" +#include "qemu/cutils.h" #ifdef CONFIG_VIRGL @@ -580,7 +581,8 @@ static void virtio_gpu_fence_poll(void *opaque)virgl_renderer_poll ();virtio_gpu_process_cmdq (g);if (!QTAILQ_EMPTY (&g->cmdq) || !QTAILQ_EMPTY (&g->fenceq)) { -timer_mod (g->fence_poll, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + 1); + timer_mod(g->fence_poll,
qemu_clock_get_us(QEMU_CLOCK_VIRTUAL)+hw/display/virtio-gpu-3d.c +14
-1+ g->fence_poll_timeout); } }@@ -605,13 +607,25 @@ void virtio_gpu_virgl_reset(VirtIOGPU *g)int virtio_gpu_virgl_init (VirtIOGPU *g) {int ret; +const char *val; ret =virgl_renderer_init (g,0 , &virtio_gpu_3d_cbs);if (ret !=0 ) {return ret; } - g->fence_poll = timer_new_ms(QEMU_CLOCK_VIRTUAL, + g->fence_poll_timeout =10000 ;/* default 10 ms */ + val =getenv ("QEMU_VIRGL_POLL_FREQ" ); +if (val) { +unsigned long long poll_freq; +if (parse_uint_full (val, &poll_freq,10 ) || poll_freq >UINT32_MAX ) { +fprintf (stderr,"VIRGL_POLL_FREQ: Invalid integer `%s'\n", val); +exit (1 ); + } + g->fence_poll_timeout =1000000 / (uint32_t )poll_freq; + } + + g->fence_poll =timer_new_us (QEMU_CLOCK_VIRTUAL , virtio_gpu_fence_poll, g);if (virtio_gpu_stats_enabled(g->conf)) {include/hw/virtio/virtio-gpu.h +1
-1@@ -116,6 +116,7 @@ typedef struct VirtIOGPU {bool renderer_reset;QEMUTimer *fence_poll;QEMUTimer *print_stats; +uint32_t fence_poll_timeout;uint32_t inflight;struct { --2.20.1
Hi
Quoted 19 lines · Gert Wollny
Am Donnerstag, den 23.05.2019, 16:01 +0200 schrieb Marc-André Lureau:
Quoted 17 lines
Hi
Quoted 12 lines · Gert Wollny
The default fence poll time of 10ms (100 Hz) is sufficent for normal
work loads, but if one wants to play games within the virtual machine
this value might be too high, so make it possible to configure this value by using the environment variableQEMU_VIRGL_POLL_FREQwhere the
poll is given in Hz. To acommodate higher poll frequencies also change
the timer to use micro seconds as base instead of milliseconds.
Quoted 5 lines
Quoted 3 lines
This is what
VIRGL_RENDERER_THREAD_SYNChelps with. You don't need to do regular polling, but I think it is currently limited to Linux/eventfd only.As far as I can see only vtest uses this, not qemu.
I don't think there is anything preventing qemu from using it, except the portability which should be taken care more carefully.
Quoted 8 lines
Quoted 3 lines
fwiw, vhost-user-gpu uses it.
Yeah, I tested it on Intel, but AFAICS this hasn't landed yet, no? OTOH the drm calls were only implemented for Intel, and I have no idea how to implement this for other hardware, like e.g. radeonsi, or even the Nvidia blob ...
I just sent v8 for review today:
https://patchew.org/QEMU/[email protected]/
The DRM bits were replaced by GBM usage, which will give some portability.
Note that those bits are for 2d ops only, and have a simpler ram/mem fallback.
Quoted 87 lines
Best,
GertQuoted 81 lines
Quoted 79 lines
Signed-off-by Gert Wollny <[email protected]>--- hw/display/virtio-gpu-3d.c | 18 ++++++++++++++++-- include/hw/virtio/virtio-gpu.h | 1 + 2 files changed, 17 insertions(+), 2 deletions(-)hw/display/virtio-gpu- renamed from hw/display/virtio-gpu-3d.c +0
-0
3d.c
index5ee3566ae0..120e593e76100644hw/display/virtio-gpu-3d.c +2
-1@@ -17,6 +17,7 @@#include "trace.h" #include "hw/virtio/virtio.h" #include "hw/virtio/virtio-gpu.h" +#include "qemu/cutils.h" #ifdef CONFIG_VIRGL @@ -580,7 +581,8 @@ static void virtio_gpu_fence_poll(void *opaque)virgl_renderer_poll ();virtio_gpu_process_cmdq (g);if (!QTAILQ_EMPTY (&g->cmdq) || !QTAILQ_EMPTY (&g->fenceq)) { -timer_mod (g->fence_poll, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + 1); + timer_mod(g->fence_poll,
qemu_clock_get_us(QEMU_CLOCK_VIRTUAL)+hw/display/virtio-gpu-3d.c +14
-1+ g->fence_poll_timeout); } }@@ -605,13 +607,25 @@ void virtio_gpu_virgl_reset(VirtIOGPU *g)int virtio_gpu_virgl_init (VirtIOGPU *g) {int ret; +const char *val; ret =virgl_renderer_init (g,0 , &virtio_gpu_3d_cbs);if (ret !=0 ) {return ret; } - g->fence_poll = timer_new_ms(QEMU_CLOCK_VIRTUAL, + g->fence_poll_timeout =10000 ;/* default 10 ms */ + val =getenv ("QEMU_VIRGL_POLL_FREQ" ); +if (val) { +unsigned long long poll_freq; +if (parse_uint_full (val, &poll_freq,10 ) || poll_freq >UINT32_MAX ) { +fprintf (stderr,"VIRGL_POLL_FREQ: Invalid integer `%s'\n", val); +exit (1 ); + } + g->fence_poll_timeout =1000000 / (uint32_t )poll_freq; + } + + g->fence_poll =timer_new_us (QEMU_CLOCK_VIRTUAL , virtio_gpu_fence_poll, g);if (virtio_gpu_stats_enabled(g->conf)) {include/hw/virtio/virtio-gpu.h +1
-1@@ -116,6 +116,7 @@ typedef struct VirtIOGPU {bool renderer_reset;QEMUTimer *fence_poll;QEMUTimer *print_stats; +uint32_t fence_poll_timeout;uint32_t inflight;struct { --2.20.1
Signature · 1 line
Marc-André Lureau
Am Donnerstag, den 23.05.2019, 16:37 +0200 schrieb Marc-André Lureau:
Quoted 30 lines
Hi
Quoted 26 lines · Gert Wollny
Am Donnerstag, den 23.05.2019, 16:01 +0200 schrieb Marc-André Lureau:
Quoted 23 lines
Hi
Quoted 4 lines · Gert Wollny
The default fence poll time of 10ms (100 Hz) is sufficent for normal
work loads, but if one wants to play games within the virtual machineQuoted 10 lines
this value might be too high, so make it possible to configure this
value by using the environment variableQEMU_VIRGL_POLL_FREQwhere
the
poll is given in Hz. To acommodate higher poll frequencies also change
the timer to use micro seconds as base instead of milliseconds.This is what
VIRGL_RENDERER_THREAD_SYNChelps with. You don't need to
do regular polling, but I think it is currently limited to Linux/eventfd only.
Quoted 4 lines
Quoted 1 line
As far as I can see only vtest uses this, not qemu.
I don't think there is anything preventing qemu from using it, except the portability which should be taken care more carefully.
But to actually use it would need quite some work, wouldn't it? (I'm thinking of your series:
http://qemu.11.n7.nabble.com/PATCH-00-18-virgl-use-a-seperate-rendering-thread-tt429557.html
)
That's why I though that being able to configure the polling frequency might be an easy way to give some performance boost.
Quoted 11 lines
Quoted 10 lines
Quoted 2 lines
fwiw, vhost-user-gpu uses it.
Yeah, I tested it on Intel, but AFAICS this hasn't landed yet, no? OTOH
the drm calls were only implemented for Intel, and I have no idea how
to implement this for other hardware, like e.g. radeonsi, or even the
Nvidia blob ...
Quoted 5 lines
I just sent v8 for review today:
https://patchew.org/QEMU/[email protected]/The DRM bits were replaced by GBM usage, which will give some portability.
That's great, I'll give it a spin in the next view days.
Best,
Gert
Quoted 84 lines
Quoted 82 lines
Quoted 82 lines
Quoted 82 lines
Signed-off-by Gert Wollny <[email protected]>--- hw/display/virtio-gpu-3d.c | 18 ++++++++++++++++-- include/hw/virtio/virtio-gpu.h | 1 + 2 files changed, 17 insertions(+), 2 deletions(-)hw/display/virtio- renamed from hw/display/virtio-gpu-3d.c +0
-0gpu-
3d.c
index5ee3566ae0..120e593e76100644hw/display/virtio-gpu-3d.c +2
-1@@ -17,6 +17,7 @@#include "trace.h" #include "hw/virtio/virtio.h" #include "hw/virtio/virtio-gpu.h" +#include "qemu/cutils.h" #ifdef CONFIG_VIRGL @@ -580,7 +581,8 @@ static void virtio_gpu_fence_poll(void *opaque)virgl_renderer_poll ();virtio_gpu_process_cmdq (g);if (!QTAILQ_EMPTY (&g->cmdq) || !QTAILQ_EMPTY (&g->fenceq)) { -timer_mod (g->fence_poll, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + 1); + timer_mod(g->fence_poll,
qemu_clock_get_us(QEMU_CLOCK_VIRTUAL)+hw/display/virtio-gpu-3d.c +7
-1+ g->fence_poll_timeout); } }@@ -605,13 +607,25 @@ void virtio_gpu_virgl_reset(VirtIOGPU *g)int virtio_gpu_virgl_init (VirtIOGPU *g) {int ret; +const char *val; ret =virgl_renderer_init (g,0 , &virtio_gpu_3d_cbs);if (ret !=0 ) {return ret; } - g->fence_poll = timer_new_ms(QEMU_CLOCK_VIRTUAL, + g->fence_poll_timeout =10000 ;/* default 10 ms */ + val =getenv ("QEMU_VIRGL_POLL_FREQ" ); +if (val) { +unsigned long long poll_freq; + if (parse_uint_full(val, &poll_freq, 10) || poll_freqQuoted 1 line
UINT32_MAX) {
+ fprintf(stderr, "VIRGL_POLL_FREQ: Invalid integer
`%s'\n", val);hw/display/virtio-gpu-3d.c +6
-0+exit (1 ); + } + g->fence_poll_timeout =1000000 / (uint32_t )poll_freq; + } + + g->fence_poll =timer_new_us (QEMU_CLOCK_VIRTUAL , virtio_gpu_fence_poll, g);if (virtio_gpu_stats_enabled (g->conf)) {include/hw/virtio/virtio-gpu.h +1
-1@@ -116,6 +116,7 @@ typedef struct VirtIOGPU {bool renderer_reset;QEMUTimer *fence_poll;QEMUTimer *print_stats; +uint32_t fence_poll_timeout;uint32_t inflight;struct { --2.20.1
Hi
Quoted 34 lines · Gert Wollny
Am Donnerstag, den 23.05.2019, 16:37 +0200 schrieb Marc-André Lureau:
Quoted 32 lines
Hi
Quoted 27 lines · Gert Wollny
Am Donnerstag, den 23.05.2019, 16:01 +0200 schrieb Marc-André Lureau:
Quoted 19 lines
Hi
Quoted 4 lines · Gert Wollny
The default fence poll time of 10ms (100 Hz) is sufficent for normal
work loads, but if one wants to play games within the virtual machineQuoted 10 lines
this value might be too high, so make it possible to configure this
value by using the environment variableQEMU_VIRGL_POLL_FREQwhere
the
poll is given in Hz. To acommodate higher poll frequencies also change
the timer to use micro seconds as base instead of milliseconds.Quoted 4 lines
This is what
VIRGL_RENDERER_THREAD_SYNChelps with. You don't need to
do regular polling, but I think it is currently limited to Linux/eventfd only.As far as I can see only vtest uses this, not qemu.
Quoted 8 lines
Quoted 2 lines
I don't think there is anything preventing qemu from using it, except the portability which should be taken care more carefully.
But to actually use it would need quite some work, wouldn't it? (I'm thinking of your series:
http://qemu.11.n7.nabble.com/PATCH-00-18-virgl-use-a-seperate-rendering-thread-tt429557.html
)
I think you could use VIRGL_RENDERER_THREAD_SYNC, without using a seperate thread for virgl.
You need to register the pollfd virgl_renderer_get_poll_fd() with the main loop, but other than that it should, in theory, work.
Signature · 1 line
Marc-André Lureau