summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTimothy Arceri <[email protected]>2019-10-29 17:43:40 +1100
committerTimothy Arceri <[email protected]>2019-10-30 04:49:58 +0000
commit28fff3efbcb15876b44107c56c8d3c3d10d8817e (patch)
tree34d50aa26bf875306883b8f6787af16482677365 /src
parent23a6827e4d96f03775f6127ee55ed93cbc279acb (diff)
radv: add radv_sc_read() helper
This is a function with timeout support for reading from the pipe between processes used for secure compile. Initially we hardcode the timeout to 5 seconds. We can adjust the timeout limit in future if needed. Reviewed-by: Bas Nieuwenhuizen <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/amd/vulkan/radv_device.c39
-rw-r--r--src/amd/vulkan/radv_private.h3
2 files changed, 42 insertions, 0 deletions
diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c
index b02483bb949..38ff0eb740d 100644
--- a/src/amd/vulkan/radv_device.c
+++ b/src/amd/vulkan/radv_device.c
@@ -1994,6 +1994,45 @@ static int install_seccomp_filter() {
return 0;
}
+/* Helper function with timeout support for reading from the pipe between
+ * processes used for secure compile.
+ */
+bool radv_sc_read(int fd, void *buf, size_t size, bool timeout)
+{
+ fd_set fds;
+ struct timeval tv;
+
+ FD_ZERO(&fds);
+ FD_SET(fd, &fds);
+
+ while (true) {
+ /* We can't rely on the value of tv after calling select() so
+ * we must reset it on each iteration of the loop.
+ */
+ tv.tv_sec = 5;
+ tv.tv_usec = 0;
+
+ int rval = select(fd + 1, &fds, NULL, NULL, timeout ? &tv : NULL);
+
+ if (rval == -1) {
+ /* select error */
+ return false;
+ } else if (rval) {
+ ssize_t bytes_read = read(fd, buf, size);
+ if (bytes_read < 0)
+ return false;
+
+ buf += bytes_read;
+ size -= bytes_read;
+ if (size == 0)
+ return true;
+ } else {
+ /* select timeout */
+ return false;
+ }
+ }
+}
+
static void run_secure_compile_device(struct radv_device *device, unsigned process,
int *fd_secure_input, int *fd_secure_output)
{
diff --git a/src/amd/vulkan/radv_private.h b/src/amd/vulkan/radv_private.h
index 12f192ed200..99cffc1f1b9 100644
--- a/src/amd/vulkan/radv_private.h
+++ b/src/amd/vulkan/radv_private.h
@@ -1151,6 +1151,9 @@ radv_initialise_ds_surface(struct radv_device *device,
struct radv_ds_buffer_info *ds,
struct radv_image_view *iview);
+bool
+radv_sc_read(int fd, void *buf, size_t size, bool timeout);
+
/**
* Attachment state when recording a renderpass instance.
*