Skip to contentSkip to conversation

add libsync.h helper

PATCH In review Rob Clark 4 participants 14 messages Oct 31, 2016 Kbuild

lore
Share & tools
lore

Rob Clark

author
#0 lore raw

PATCH 1/1 add libsync.h helper

From: Rob Clark <[email protected]>

Rather than cut/pasting these couple ioctl wrappers everywhere, just stuff them as static-inline into a header.

---
This is probably mostly used from mesa, but some drivers, test apps, etc may also want to use it from libdrm.

 Makefile.sources |  1 +
 libsync.h        | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 75 insertions(+)
 create mode 100644 libsync.h
Makefile.sources +1 -0
index a57036a..10aa1d0 100644
@@ -13,6 +13,7 @@ LIBDRM_FILES := \
 	util_math.h
 
 LIBDRM_H_FILES := \
+	libsync.h \
 	xf86drm.h \
 	xf86drmMode.h
 
libsync.h new file +74 -0

74 lines not on this page · raw message

Signature · 6 lines
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw
Quoted 77 lines · Rob Clark

From: Rob Clark <[email protected]>

Rather than cut/pasting these couple ioctl wrappers everywhere, just stuff them as static-inline into a header.

---
This is probably mostly used from mesa, but some drivers, test apps, etc may also want to use it from libdrm.

 Makefile.sources |  1 +
 libsync.h        | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 75 insertions(+)
 create mode 100644 libsync.h
Makefile.sources +1 -0
index a57036a..10aa1d0 100644
@@ -13,6 +13,7 @@ LIBDRM_FILES := \
 	util_math.h
 
 LIBDRM_H_FILES := \
+	libsync.h \
 	xf86drm.h \
 	xf86drmMode.h
 
libsync.h new file +44 -0
new file mode 100644
index 0000000..fc23b7f
@@ -0,0 +1,74 @@
+/*
+ *  sync abstraction
+ *  Copyright 2015-2016 Collabora Ltd.
+ *
+ *  Based on the implementation from the Android Open Source Project,
+ *
+ *  Copyright 2012 Google, Inc
+ *
+ *  Permission is hereby granted, free of charge, to any person obtaining a
+ *  copy of this software and associated documentation files (the "Software"),
+ *  to deal in the Software without restriction, including without limitation
+ *  the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ *  and/or sell copies of the Software, and to permit persons to whom the
+ *  Software is furnished to do so, subject to the following conditions:
+ *
+ *  The above copyright notice and this permission notice shall be included in
+ *  all copies or substantial portions of the Software.
+ *
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ *  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ *  OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ *  ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ *  OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef _LIBSYNC_H
+#define _LIBSYNC_H
+
+#include <stdint.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <sys/poll.h>
+
+// todo prob should just #include <linux/sync_file.h> ?
+struct sync_merge_data {
+	char	name[32];
+	int32_t	fd2;
+	int32_t	fence;
+	uint32_t	flags;
+	uint32_t	pad;
+};
+#define SYNC_IOC_MAGIC		'>'

libsync.h line 54

Quoted 10 lines
libsync.h new file +10 -0
+#define SYNC_IOC_MERGE		_IOWR(SYNC_IOC_MAGIC, 3, struct sync_merge_data)
+
+
+
+static inline int sync_wait(int fd, int timeout)
+{
+	struct pollfd fds;
+
+	fds.fd = fd;
+	fds.events = POLLIN | POLLERR;

POLLERR is implied and ignored in fds.events.

libsync.h line 55

Quoted 1 line
libsync.h new file +1 -0
+	return poll(&fds, 1, timeout);

Returns: -1 on error, 0 on timeout, 1 if signaled.

This function is horrible wrt to -EINTR for example :) Hmm, mixing poll() and looping over signals until timeout doesn't look as straightforward.

libsync.h line 61

Quoted 6 lines
libsync.h new file +6 -0
+}
+
+static inline int sync_merge(const char *name, int fd1, int fd2)
+{
+	struct sync_merge_data data = {};
+	int err;

What I liked was doing

if (fd2 < 0)

	return dup(fd1);

if (fd1 < 0)

	return dup(fd2);

That makes accumulating the fences in the caller much easier (i.e. they start with

	batch.fence_in = -1;
then
	batch.fence_in = sync_merge(batch.fence_in, fence);
finished by
	execbuf(&batch);
	close(batch.fence_in);
	batch.fence_in = -1;

-Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author
#2 lore raw
Quoted 91 lines · Chris Wilson
Quoted 77 lines · Rob Clark

From: Rob Clark <[email protected]>

Rather than cut/pasting these couple ioctl wrappers everywhere, just stuff them as static-inline into a header.

---
This is probably mostly used from mesa, but some drivers, test apps, etc may also want to use it from libdrm.

 Makefile.sources |  1 +
 libsync.h        | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 75 insertions(+)
 create mode 100644 libsync.h
Makefile.sources +1 -0
index a57036a..10aa1d0 100644
@@ -13,6 +13,7 @@ LIBDRM_FILES := \
      util_math.h
 
 LIBDRM_H_FILES := \
+     libsync.h \
      xf86drm.h \
      xf86drmMode.h
 
libsync.h new file +44 -0
new file mode 100644
index 0000000..fc23b7f
@@ -0,0 +1,74 @@
+/*
+ *  sync abstraction
+ *  Copyright 2015-2016 Collabora Ltd.
+ *
+ *  Based on the implementation from the Android Open Source Project,
+ *
+ *  Copyright 2012 Google, Inc
+ *
+ *  Permission is hereby granted, free of charge, to any person obtaining a
+ *  copy of this software and associated documentation files (the "Software"),
+ *  to deal in the Software without restriction, including without limitation
+ *  the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ *  and/or sell copies of the Software, and to permit persons to whom the
+ *  Software is furnished to do so, subject to the following conditions:
+ *
+ *  The above copyright notice and this permission notice shall be included in
+ *  all copies or substantial portions of the Software.
+ *
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ *  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ *  OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ *  ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ *  OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef _LIBSYNC_H
+#define _LIBSYNC_H
+
+#include <stdint.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <sys/poll.h>
+
+// todo prob should just #include <linux/sync_file.h> ?
+struct sync_merge_data {
+     char    name[32];
+     int32_t fd2;
+     int32_t fence;
+     uint32_t        flags;
+     uint32_t        pad;
+};
+#define SYNC_IOC_MAGIC               '>'

libsync.h line 54

Quoted 10 lines
libsync.h new file +10 -0
+#define SYNC_IOC_MERGE               _IOWR(SYNC_IOC_MAGIC, 3, struct sync_merge_data)
+
+
+
+static inline int sync_wait(int fd, int timeout)
+{
+     struct pollfd fds;
+
+     fds.fd = fd;
+     fds.events = POLLIN | POLLERR;

POLLERR is implied and ignored in fds.events.

Quoted 7 lines

libsync.h line 55

Quoted 1 line
libsync.h new file +1 -0
+     return poll(&fds, 1, timeout);

Returns: -1 on error, 0 on timeout, 1 if signaled.

This function is horrible wrt to -EINTR for example :) Hmm, mixing poll() and looping over signals until timeout doesn't look as straightforward.

hmm, this was just basically cut/paste from android libsync (and iirc removing the legacy ioctls).. although I did just realize there was a newer version which turned this into:

   ret = poll(..);
   if (ret > 0)
      return 0;
   return ret;

perhaps not super-awesome for -EINTR handling.. and tbh I'm 100% of the behavior when this used to be simply "return ioctl(fd, SYNC_IOC_WAIT, &to);"..

Quoted 17 lines

libsync.h line 61

Quoted 6 lines
libsync.h new file +6 -0
+}
+
+static inline int sync_merge(const char *name, int fd1, int fd2)
+{
+     struct sync_merge_data data = {};
+     int err;

What I liked was doing

if (fd2 < 0)

        return dup(fd1);

if (fd1 < 0)

        return dup(fd2);

That makes accumulating the fences in the caller much easier (i.e. they start with

Quoted 7 lines
        batch.fence_in = -1;
then
        batch.fence_in = sync_merge(batch.fence_in, fence);
finished by
        execbuf(&batch);
        close(batch.fence_in);
        batch.fence_in = -1;

I guess that would end up ignoring the fence name.. although not sure that I care. But probably we should either make the android version behave the same, or pick new names for these fxns. I think having same names but slightly different behaviour would be confusing.

Oh, and now that I'm actually looking at that code, the extra null terminator bit after the strncpy() is kinda unneeded.. should just do:

       strncpy(data.name, name, sizeof(data.name));

(without the -1) instead

BR,
-R

Quoted 4 lines

-Chris

--
Chris Wilson, Intel Open Source Technology Centre

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#3 lore raw

2016-10-31 Rob Clark <[email protected]>:

Quoted 104 lines · Chris Wilson
Quoted 91 lines · Rob Clark
Quoted 77 lines

From: Rob Clark <[email protected]>

Rather than cut/pasting these couple ioctl wrappers everywhere, just stuff them as static-inline into a header.

---
This is probably mostly used from mesa, but some drivers, test apps, etc may also want to use it from libdrm.

 Makefile.sources |  1 +
 libsync.h        | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 75 insertions(+)
 create mode 100644 libsync.h
Makefile.sources +1 -0
index a57036a..10aa1d0 100644
@@ -13,6 +13,7 @@ LIBDRM_FILES := \
      util_math.h
 
 LIBDRM_H_FILES := \
+     libsync.h \
      xf86drm.h \
      xf86drmMode.h
 
libsync.h new file +44 -0
new file mode 100644
index 0000000..fc23b7f
@@ -0,0 +1,74 @@
+/*
+ *  sync abstraction
+ *  Copyright 2015-2016 Collabora Ltd.
+ *
+ *  Based on the implementation from the Android Open Source Project,
+ *
+ *  Copyright 2012 Google, Inc
+ *
+ *  Permission is hereby granted, free of charge, to any person obtaining a
+ *  copy of this software and associated documentation files (the "Software"),
+ *  to deal in the Software without restriction, including without limitation
+ *  the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ *  and/or sell copies of the Software, and to permit persons to whom the
+ *  Software is furnished to do so, subject to the following conditions:
+ *
+ *  The above copyright notice and this permission notice shall be included in
+ *  all copies or substantial portions of the Software.
+ *
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ *  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ *  OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ *  ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ *  OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef _LIBSYNC_H
+#define _LIBSYNC_H
+
+#include <stdint.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <sys/poll.h>
+
+// todo prob should just #include <linux/sync_file.h> ?
+struct sync_merge_data {
+     char    name[32];
+     int32_t fd2;
+     int32_t fence;
+     uint32_t        flags;
+     uint32_t        pad;
+};
+#define SYNC_IOC_MAGIC               '>'

libsync.h line 54

Quoted 10 lines
libsync.h new file +10 -0
+#define SYNC_IOC_MERGE               _IOWR(SYNC_IOC_MAGIC, 3, struct sync_merge_data)
+
+
+
+static inline int sync_wait(int fd, int timeout)
+{
+     struct pollfd fds;
+
+     fds.fd = fd;
+     fds.events = POLLIN | POLLERR;

POLLERR is implied and ignored in fds.events.

Quoted 7 lines

libsync.h line 55

Quoted 1 line
libsync.h new file +1 -0
+     return poll(&fds, 1, timeout);

Returns: -1 on error, 0 on timeout, 1 if signaled.

This function is horrible wrt to -EINTR for example :) Hmm, mixing poll() and looping over signals until timeout doesn't look as straightforward.

hmm, this was just basically cut/paste from android libsync (and iirc removing the legacy ioctls).. although I did just realize there was a newer version which turned this into:

Quoted 8 lines
   ret = poll(..);
   if (ret > 0)
      return 0;
   return ret;

perhaps not super-awesome for -EINTR handling.. and tbh I'm 100% of the behavior when this used to be simply "return ioctl(fd, SYNC_IOC_WAIT, &to);"..

The latest version take a few more cases in account and should behave exatly like SYNC_IOC_WAIT.

int sync_wait(int fd, int timeout)

{                                                                               
    struct pollfd fds;                                                          
    int ret;                                                                    
                                                                                
    fds.fd = fd;                                                                
    fds.events = POLLIN;                                                        
    ret = poll(&fds, 1, timeout);                                               
    if (ret > 0) {                                                              
        if (fds.revents & (POLLERR | POLLNVAL))                                 
            errno = EINVAL;                                                     
            return -1;                                                          
        return 0;                                                               
    } else if (ret == 0) {                                                      
        errno = ETIME;                                                          
        return -1;                                                              
    }                                                                           
    return ret;                                                                 
}
Quoted 42 lines
Quoted 18 lines

libsync.h line 61

Quoted 7 lines
libsync.h new file +6 -0
+}
+
+static inline int sync_merge(const char *name, int fd1, int fd2)
+{
+     struct sync_merge_data data = {};
+     int err;

What I liked was doing

if (fd2 < 0)

        return dup(fd1);

if (fd1 < 0)

        return dup(fd2);

That makes accumulating the fences in the caller much easier (i.e. they start with

Quoted 7 lines
        batch.fence_in = -1;
then
        batch.fence_in = sync_merge(batch.fence_in, fence);
finished by
        execbuf(&batch);
        close(batch.fence_in);
        batch.fence_in = -1;

I guess that would end up ignoring the fence name.. although not sure that I care. But probably we should either make the android version behave the same, or pick new names for these fxns. I think having same names but slightly different behaviour would be confusing.

Oh, and now that I'm actually looking at that code, the extra null terminator bit after the strncpy() is kinda unneeded.. should just do:

       strncpy(data.name, name, sizeof(data.name));

(without the -1) instead

BR,
-R

Quoted 8 lines
Quoted 4 lines

-Chris

--
Chris Wilson, Intel Open Source Technology Centre

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

author
#4 lore raw
In reply to Chris Wilson
Quoted 111 lines · Chris Wilson
Quoted 77 lines · Rob Clark

From: Rob Clark <[email protected]>

Rather than cut/pasting these couple ioctl wrappers everywhere, just stuff them as static-inline into a header.

---
This is probably mostly used from mesa, but some drivers, test apps, etc may also want to use it from libdrm.

 Makefile.sources |  1 +
 libsync.h        | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 75 insertions(+)
 create mode 100644 libsync.h
Makefile.sources +1 -0
index a57036a..10aa1d0 100644
@@ -13,6 +13,7 @@ LIBDRM_FILES := \
      util_math.h
 
 LIBDRM_H_FILES := \
+     libsync.h \
      xf86drm.h \
      xf86drmMode.h
 
libsync.h new file +44 -0
new file mode 100644
index 0000000..fc23b7f
@@ -0,0 +1,74 @@
+/*
+ *  sync abstraction
+ *  Copyright 2015-2016 Collabora Ltd.
+ *
+ *  Based on the implementation from the Android Open Source Project,
+ *
+ *  Copyright 2012 Google, Inc
+ *
+ *  Permission is hereby granted, free of charge, to any person obtaining a
+ *  copy of this software and associated documentation files (the "Software"),
+ *  to deal in the Software without restriction, including without limitation
+ *  the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ *  and/or sell copies of the Software, and to permit persons to whom the
+ *  Software is furnished to do so, subject to the following conditions:
+ *
+ *  The above copyright notice and this permission notice shall be included in
+ *  all copies or substantial portions of the Software.
+ *
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ *  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ *  OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ *  ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ *  OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef _LIBSYNC_H
+#define _LIBSYNC_H
+
+#include <stdint.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <sys/poll.h>
+
+// todo prob should just #include <linux/sync_file.h> ?
+struct sync_merge_data {
+     char    name[32];
+     int32_t fd2;
+     int32_t fence;
+     uint32_t        flags;
+     uint32_t        pad;
+};
+#define SYNC_IOC_MAGIC               '>'

libsync.h line 54

Quoted 10 lines
libsync.h new file +10 -0
+#define SYNC_IOC_MERGE               _IOWR(SYNC_IOC_MAGIC, 3, struct sync_merge_data)
+
+
+
+static inline int sync_wait(int fd, int timeout)
+{
+     struct pollfd fds;
+
+     fds.fd = fd;
+     fds.events = POLLIN | POLLERR;

POLLERR is implied and ignored in fds.events.

libsync.h line 55

Quoted 1 line
libsync.h new file +1 -0
+     return poll(&fds, 1, timeout);

Returns: -1 on error, 0 on timeout, 1 if signaled.

This function is horrible wrt to -EINTR for example :) Hmm, mixing poll() and looping over signals until timeout doesn't look as straightforward.

libsync.h line 61

Quoted 6 lines
libsync.h new file +6 -0
+}
+
+static inline int sync_merge(const char *name, int fd1, int fd2)
+{
+     struct sync_merge_data data = {};
+     int err;

What I liked was doing

if (fd2 < 0)

        return dup(fd1);
Quoted 8 lines

if (fd1 < 0)

        return dup(fd2);

That makes accumulating the fences in the caller much easier (i.e. they start with

        batch.fence_in = -1;
then
        batch.fence_in = sync_merge(batch.fence_in, fence);

note that if you don't want to leak fd's you'd have to do something more like:

  int new_fence = sync_merge(batch->fence_in, fence);
  if (batch->fence_in != -1)
     close(batch->fence_in);
  batch->fence_in = new_fence;

so it isn't *that* much better.. I guess you could do the close() unconditionally and ignore the error if batch->fence_in==-1..

BR,
-R

Quoted 8 lines

finished by

        execbuf(&batch);
        close(batch.fence_in);
        batch.fence_in = -1;

-Chris

--
Chris Wilson, Intel Open Source Technology Centre

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#5 lore raw
Quoted 15 lines · Rob Clark
Quoted 5 lines · Chris Wilson

What I liked was doing

if (fd2 < 0)

        return dup(fd1);
Quoted 8 lines

if (fd1 < 0)

        return dup(fd2);

That makes accumulating the fences in the caller much easier (i.e. they start with

        batch.fence_in = -1;
then
        batch.fence_in = sync_merge(batch.fence_in, fence);
Quoted 6 lines

note that if you don't want to leak fd's you'd have to do something more like:

  int new_fence = sync_merge(batch->fence_in, fence);
  if (batch->fence_in != -1)
     close(batch->fence_in);
  batch->fence_in = new_fence;

Hmm. so I thought the ioctl was closing the input.

Quoted 2 lines

so it isn't *that* much better.. I guess you could do the close() unconditionally and ignore the error if batch->fence_in==-1..

Yup, realised after writing that a bit more on the input side is required.

if (fd2 < 0)

	return fd1;

if (fd1 < 0)

	return dup(fd2);

ret = ioctl();
if (ret < 0)

	return fd1;

close(fd1);
return result.fence;

Which discards the synchronisation on the new fence if there's an error, are we meant to flag a GL_ERROR?
-Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author
#6 lore raw
Quoted 16 lines · Chris Wilson
Quoted 15 lines · Rob Clark
Quoted 13 lines · Chris Wilson

What I liked was doing

if (fd2 < 0)

        return dup(fd1);

if (fd1 < 0)

        return dup(fd2);

That makes accumulating the fences in the caller much easier (i.e. they start with

        batch.fence_in = -1;
then
        batch.fence_in = sync_merge(batch.fence_in, fence);
Quoted 8 lines
Quoted 6 lines

note that if you don't want to leak fd's you'd have to do something more like:

  int new_fence = sync_merge(batch->fence_in, fence);
  if (batch->fence_in != -1)
     close(batch->fence_in);
  batch->fence_in = new_fence;

Hmm. so I thought the ioctl was closing the input.

hmm, the new ioctl is not.. I guess I need to dig up the old code to confirm it's behaviour was the same.

In reality I think most things would want to close() the old fence, but I don't want to change the behaviour from an existing android libsync function of the same name. So probably will keep the existing behaviour but add a new function (sync_merge_if() or something like that.. feel free to suggest a better name) which does the dup/close dance.

Quoted 15 lines
Quoted 2 lines

so it isn't *that* much better.. I guess you could do the close() unconditionally and ignore the error if batch->fence_in==-1..

Yup, realised after writing that a bit more on the input side is required.

if (fd2 < 0)

        return fd1;

if (fd1 < 0)

        return dup(fd2);

ret = ioctl();
if (ret < 0)

Quoted 7 lines
        return fd1;

close(fd1);
return result.fence;

Which discards the synchronisation on the new fence if there's an error, are we meant to flag a GL_ERROR?

The error checking should already be done at the egl level. The same eglCreateSync() has two modes, one where you pass in -1 and are asking the driver to create a fence, and one where you pass in a valid fd which you want to sync on. For at least the gallium bits, these turn into different code paths into the driver. So the fd2<0 case would be an assert(). I'm not entirely sure what behaviour you'd want for i965.

BR,
-R

Quoted 4 lines

-Chris

--
Chris Wilson, Intel Open Source Technology Centre

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#7 lore raw
Quoted 11 lines · Rob Clark
Quoted 2 lines · Chris Wilson

Which discards the synchronisation on the new fence if there's an error, are we meant to flag a GL_ERROR?

The error checking should already be done at the egl level. The same eglCreateSync() has two modes, one where you pass in -1 and are asking the driver to create a fence, and one where you pass in a valid fd which you want to sync on. For at least the gallium bits, these turn into different code paths into the driver. So the fd2<0 case would be an assert(). I'm not entirely sure what behaviour you'd want for i965.

Either path could reasonably err with ENOMEM, ENFILE. Disregarding the fence (so we keep on bumbling on) and logging the error for later inspection. As far as the backend is concerned, it looks like we just have to ensure we don't lose the current fences and return NULL/-1.

Check dri2_dup_native_fence_fd() for error handling of its dup(sync->SyncFd), only some paths set the _eglError(). -Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author
#8 lore raw
Quoted 13 lines · Chris Wilson
Quoted 11 lines · Rob Clark
Quoted 2 lines · Chris Wilson

Which discards the synchronisation on the new fence if there's an error, are we meant to flag a GL_ERROR?

The error checking should already be done at the egl level. The same eglCreateSync() has two modes, one where you pass in -1 and are asking the driver to create a fence, and one where you pass in a valid fd which you want to sync on. For at least the gallium bits, these turn into different code paths into the driver. So the fd2<0 case would be an assert(). I'm not entirely sure what behaviour you'd want for i965.

Quoted 7 lines

Either path could reasonably err with ENOMEM, ENFILE. Disregarding the fence (so we keep on bumbling on) and logging the error for later inspection. As far as the backend is concerned, it looks like we just have to ensure we don't lose the current fences and return NULL/-1.

Check dri2_dup_native_fence_fd() for error handling of its dup(sync->SyncFd), only some paths set the _eglError().

yeah, I guess spec doesn't really define what happens if EMFILE.. although really quite a lot of things will start falling over at that point. I guess we could set EGL_BAD_PARAMETER although that isn't really the perfect error.

BR,
-R

Quoted 4 lines

-Chris

--
Chris Wilson, Intel Open Source Technology Centre

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#9 lore raw
In reply to Rob Clark
Quoted 10 lines · Rob Clark

From: Rob Clark <[email protected]>

Rather than cut/pasting these couple ioctl wrappers everywhere, just stuff them as static-inline into a header.

---
This is probably mostly used from mesa, but some drivers, test apps, etc may also want to use it from libdrm.

It makes sense imho. To avoid fun experiences we want the header synced in an identical manner (make headers_install) to the include/drm ones. One might as well move it there, so make its "more" obvious.

libsync.h line 54

Quoted 6 lines
libsync.h new file +6 -0
+static inline int sync_wait(int fd, int timeout)
+{
+       struct pollfd fds;
+
+       fds.fd = fd;
+       fds.events = POLLIN | POLLERR;

IIRC the API does not mention (forbid even) additional members of the pollfd struct.
Let's zero init fds, and the compiler will drop it if/where applicable ?

Thanks
Emil
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

author
#10 lore raw
Quoted 11 lines · Emil Velikov
Quoted 10 lines · Rob Clark

From: Rob Clark <[email protected]>

Rather than cut/pasting these couple ioctl wrappers everywhere, just stuff them as static-inline into a header.

---
This is probably mostly used from mesa, but some drivers, test apps, etc may also want to use it from libdrm.

Quoted 5 lines

It makes sense imho. To avoid fun experiences we want the header synced in an identical manner (make headers_install) to the include/drm ones. One might as well move it there, so make its "more" obvious.

hmm, not sure I understand, but '#include <libsync.h>' seems to work in either case..

Quoted 10 lines

libsync.h line 54

Quoted 7 lines
libsync.h new file +6 -0
+static inline int sync_wait(int fd, int timeout)
+{
+       struct pollfd fds;
+
+       fds.fd = fd;
+       fds.events = POLLIN | POLLERR;

IIRC the API does not mention (forbid even) additional members of the pollfd struct.
Let's zero init fds, and the compiler will drop it if/where applicable ?

hmm, and I guess if this gets #include'd from c++ code, does it get more fun? I thought there were some different rules about struct initializers in c++? Or maybe that was just with certain compilers?

BR,
-R
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#11 lore raw
Quoted 12 lines · Rob Clark
Quoted 11 lines · Emil Velikov
Quoted 10 lines · Rob Clark

From: Rob Clark <[email protected]>

Rather than cut/pasting these couple ioctl wrappers everywhere, just stuff them as static-inline into a header.

---
This is probably mostly used from mesa, but some drivers, test apps, etc may also want to use it from libdrm.

Quoted 9 lines
Quoted 5 lines

It makes sense imho. To avoid fun experiences we want the header synced in an identical manner (make headers_install) to the include/drm ones. One might as well move it there, so make its "more" obvious.

hmm, not sure I understand, but '#include <libsync.h>' seems to work in either case..

The file is from the kernel UAPI, correct ? If so store it alongside the other UAPI ones include/drm/ and import `make headers_install' (see git log -- include/drm for examples).

We should add a README with the above specifics to include/drm/ one of these days :-)

Quoted 12 lines
Quoted 10 lines

libsync.h line 54

Quoted 7 lines
libsync.h new file +6 -0
+static inline int sync_wait(int fd, int timeout)
+{
+       struct pollfd fds;
+
+       fds.fd = fd;
+       fds.events = POLLIN | POLLERR;

IIRC the API does not mention (forbid even) additional members of the pollfd struct.
Let's zero init fds, and the compiler will drop it if/where applicable ?

Quoted 4 lines

hmm, and I guess if this gets #include'd from c++ code, does it get more fun? I thought there were some different rules about struct initializers in c++? Or maybe that was just with certain compilers?

Initializers are fun in C++ indeed. Having the extern C wrappers (as per your v2) helps.

Thanks
Emil
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

author
#12 lore raw
Quoted 19 lines · Emil Velikov
Quoted 18 lines · Rob Clark
Quoted 16 lines · Emil Velikov
Quoted 10 lines · Rob Clark

From: Rob Clark <[email protected]>

Rather than cut/pasting these couple ioctl wrappers everywhere, just stuff them as static-inline into a header.

---
This is probably mostly used from mesa, but some drivers, test apps, etc may also want to use it from libdrm.

It makes sense imho. To avoid fun experiences we want the header synced in an identical manner (make headers_install) to the include/drm ones. One might as well move it there, so make its "more" obvious.

Quoted 6 lines
Quoted 3 lines

hmm, not sure I understand, but '#include <libsync.h>' seems to work in either case..

The file is from the kernel UAPI, correct ? If so store it alongside the other UAPI ones include/drm/ and import `make headers_install' (see git log -- include/drm for examples).

no, it copy/pastes a few lines from uabi/linux/sync_file.h just to avoid a dependency on kernel headers. I guess I *could* copy sync_file.h into libdrm, but it isn't really a drm uabi header, so I didn't want to do that

BR,
-R

Quoted 19 lines

We should add a README with the above specifics to include/drm/ one of these days :-)

Quoted 12 lines
Quoted 10 lines

libsync.h line 54

Quoted 7 lines
libsync.h new file +6 -0
+static inline int sync_wait(int fd, int timeout)
+{
+       struct pollfd fds;
+
+       fds.fd = fd;
+       fds.events = POLLIN | POLLERR;

IIRC the API does not mention (forbid even) additional members of the pollfd struct.
Let's zero init fds, and the compiler will drop it if/where applicable ?

Quoted 4 lines

hmm, and I guess if this gets #include'd from c++ code, does it get more fun? I thought there were some different rules about struct initializers in c++? Or maybe that was just with certain compilers?

Quoted 5 lines

Initializers are fun in C++ indeed. Having the extern C wrappers (as per your v2) helps.

Thanks
Emil

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#13 lore raw
Quoted 23 lines · Rob Clark
Quoted 22 lines · Emil Velikov
Quoted 21 lines · Rob Clark
Quoted 11 lines · Emil Velikov
Quoted 10 lines · Rob Clark

From: Rob Clark <[email protected]>

Rather than cut/pasting these couple ioctl wrappers everywhere, just stuff them as static-inline into a header.

---
This is probably mostly used from mesa, but some drivers, test apps, etc may also want to use it from libdrm.

Quoted 5 lines

It makes sense imho. To avoid fun experiences we want the header synced in an identical manner (make headers_install) to the include/drm ones. One might as well move it there, so make its "more" obvious.

hmm, not sure I understand, but '#include <libsync.h>' seems to work in either case..

Quoted 9 lines
Quoted 3 lines

The file is from the kernel UAPI, correct ? If so store it alongside the other UAPI ones include/drm/ and import `make headers_install' (see git log -- include/drm for examples).

no, it copy/pastes a few lines from uabi/linux/sync_file.h just to avoid a dependency on kernel headers. I guess I *could* copy sync_file.h into libdrm, but it isn't really a drm uabi header, so I didn't want to do that

#include <linux/sync_file.h> and drop the copy/pasta ? The latter will come to bite us sooner or later.

Just for information: memset should work everywhere. Everything else will produce a warning as you move through GCC versions.

Thanks
Emil
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel