vrend: move eventfd manipulations to virgl_util.c

So that it can be shared by different renderers (there is only vrend
right now).

Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-by: Gert Wollny <gert.wollny@collabora.com>
macos/master
Chia-I Wu 4 years ago
parent b87b69eda0
commit ccda76bb7d
  1. 57
      src/virgl_util.c
  2. 5
      src/virgl_util.h
  3. 42
      src/vrend_renderer.c

@ -22,8 +22,18 @@
* *
**************************************************************************/ **************************************************************************/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "virgl_util.h" #include "virgl_util.h"
#include <errno.h>
#ifdef HAVE_EVENTFD_H
#include <sys/eventfd.h>
#endif
#include <unistd.h>
#include "util/u_pointer.h" #include "util/u_pointer.h"
unsigned hash_func_u32(void *key) unsigned hash_func_u32(void *key)
@ -41,3 +51,50 @@ int compare_func(void *key1, void *key2)
else else
return 0; return 0;
} }
bool has_eventfd(void)
{
#ifdef HAVE_EVENTFD_H
return true;
#else
return false;
#endif
}
int create_eventfd(unsigned int initval)
{
#ifdef HAVE_EVENTFD_H
return eventfd(initval, EFD_CLOEXEC | EFD_NONBLOCK);
#else
return -1;
#endif
}
int write_eventfd(int fd, uint64_t val)
{
const char *buf = (const char *)&val;
size_t count = sizeof(val);
ssize_t ret = 0;
while (count) {
ret = write(fd, buf, count);
if (ret < 0) {
if (errno == EINTR)
continue;
break;
}
count -= ret;
buf += ret;
}
return count ? -1 : 0;
}
void flush_eventfd(int fd)
{
ssize_t len;
uint64_t value;
do {
len = read(fd, &value, sizeof(value));
} while ((len == -1 && errno == EINTR) || len == sizeof(value));
}

@ -49,4 +49,9 @@ unsigned hash_func_u32(void *key);
int compare_func(void *key1, void *key2); int compare_func(void *key1, void *key2);
bool has_eventfd(void);
int create_eventfd(unsigned int initval);
int write_eventfd(int fd, uint64_t val);
void flush_eventfd(int fd);
#endif /* VIRGL_UTIL_H */ #endif /* VIRGL_UTIL_H */

@ -57,10 +57,6 @@
#include "tgsi/tgsi_text.h" #include "tgsi/tgsi_text.h"
#ifdef HAVE_EVENTFD_H
#include <sys/eventfd.h>
#endif
static const uint32_t fake_occlusion_query_samples_passed_default = 1024; static const uint32_t fake_occlusion_query_samples_passed_default = 1024;
const struct vrend_if_cbs *vrend_clicbs; const struct vrend_if_cbs *vrend_clicbs;
@ -5771,40 +5767,15 @@ static bool do_wait(struct vrend_fence *fence, bool can_block)
} }
#ifdef HAVE_EVENTFD_H #ifdef HAVE_EVENTFD_H
static ssize_t
write_full(int fd, const void *ptr, size_t count)
{
const char *buf = ptr;
ssize_t ret = 0;
ssize_t total = 0;
while (count) {
ret = write(fd, buf, count);
if (ret < 0) {
if (errno == EINTR)
continue;
break;
}
count -= ret;
buf += ret;
total += ret;
}
return total;
}
static void wait_sync(struct vrend_fence *fence) static void wait_sync(struct vrend_fence *fence)
{ {
ssize_t n;
uint64_t value = 1;
do_wait(fence, /* can_block */ true); do_wait(fence, /* can_block */ true);
pipe_mutex_lock(vrend_state.fence_mutex); pipe_mutex_lock(vrend_state.fence_mutex);
list_addtail(&fence->fences, &vrend_state.fence_list); list_addtail(&fence->fences, &vrend_state.fence_list);
pipe_mutex_unlock(vrend_state.fence_mutex); pipe_mutex_unlock(vrend_state.fence_mutex);
n = write_full(vrend_state.eventfd, &value, sizeof(value)); if (write_eventfd(vrend_state.eventfd, 1)) {
if (n != sizeof(value)) {
perror("failed to write to eventfd\n"); perror("failed to write to eventfd\n");
} }
} }
@ -5860,7 +5831,7 @@ static void vrend_renderer_use_threaded_sync(void)
return; return;
} }
vrend_state.eventfd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK); vrend_state.eventfd = create_eventfd(0);
if (vrend_state.eventfd == -1) { if (vrend_state.eventfd == -1) {
vrend_printf( "Failed to create eventfd\n"); vrend_printf( "Failed to create eventfd\n");
vrend_clicbs->destroy_gl_context(vrend_state.sync_context); vrend_clicbs->destroy_gl_context(vrend_state.sync_context);
@ -9034,15 +9005,6 @@ int vrend_renderer_create_fence(int client_fence_id, uint32_t ctx_id)
return ENOMEM; return ENOMEM;
} }
static void flush_eventfd(int fd)
{
ssize_t len;
uint64_t value;
do {
len = read(fd, &value, sizeof(value));
} while ((len == -1 && errno == EINTR) || len == sizeof(value));
}
static void vrend_renderer_check_queries(void); static void vrend_renderer_check_queries(void);
void vrend_renderer_check_fences(void) void vrend_renderer_check_fences(void)

Loading…
Cancel
Save