Skip to contentSkip to conversation

xf86drm: inline drmIoctl()

PATCH NAK Eric Engestrom 3 participants 6 messages Jun 21, 2017 – Jun 23, 2017 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/2 xf86drm: inline drmIoctl()

As Chad [1] puts it:

Quoted 2 lines

it's excessive to jump through the PLT into a shared object for a mere ioctl wrapper.

[1] https://lists.freedesktop.org/archives/mesa-dev/2017-June/159951.html

---
 xf86drm.c | 14 --------------
 xf86drm.h | 18 +++++++++++++++++-
 2 files changed, 17 insertions(+), 15 deletions(-)
xf86drm.c +0 -14
index 728ac78c..c82a76d2 100644
@@ -179,20 +179,6 @@ void drmFree(void *pt)
     free(pt);
 }
 
-/**
- * Call ioctl, restarting if it is interupted
- */
-int
-drmIoctl(int fd, unsigned long request, void *arg)
-{
-    int ret;
-
-    do {
-        ret = ioctl(fd, request, arg);
-    } while (ret == -1 && (errno == EINTR || errno == EAGAIN));
-    return ret;
-}
-
 static unsigned long drmGetKeyFromFd(int fd)
 {
     stat_t     st;
xf86drm.h +17 -1
index 74f54f17..aeed543f 100644
@@ -38,6 +38,8 @@
 #include <sys/types.h>
 #include <stdint.h>
 #include <drm.h>
+#include <sys/ioctl.h>
+#include <errno.h>
 
 #if defined(__cplusplus)
 extern "C" {
@@ -118,7 +120,21 @@ typedef struct drmHashEntry {
     void     *tagTable;
 } drmHashEntry;
 
-extern int drmIoctl(int fd, unsigned long request, void *arg);
+/**
+ * Call ioctl, restarting if it is interupted
+ */
+static inline int
+drmIoctl(int fd, unsigned long request, void *arg)
+{
+    int ret;
+
+    do {
+        ret = ioctl(fd, request, arg);
+    } while (ret == -1 && (errno == EINTR || errno == EAGAIN));
+
+    return ret;
+}
+
 extern void *drmGetHashTable(void);
 extern drmHashEntry *drmGetEntry(int fd);
 
Signature · 7 lines
Cheers,
  Eric

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

PATCH 2/2 xf86drm: introduce drmIoctl2()

Basically ripped off of [1] by Chris Wilson, which I thought should live in libdrm too (even though it's needed in Mesa anyway).

[1] https://lists.freedesktop.org/archives/mesa-dev/2017-June/159894.html

---
 xf86drm.h | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
xf86drm.h +27 -0
index aeed543f..eb75b944 100644
@@ -38,6 +38,9 @@
 #include <sys/types.h>
 #include <stdint.h>
 #include <drm.h>
+#if defined(__linux__) && defined(__GNUC__) && defined (__x86_64__)
+#include <sys/syscall.h>
+#endif
 #include <sys/ioctl.h>
 #include <errno.h>
 
@@ -135,6 +138,30 @@ drmIoctl(int fd, unsigned long request, void *arg)
     return ret;
 }
 
+/**
+ * Call ioctl, restarting if it is interupted, and return the error.
+ */
+static inline int
+drmIoctl2(int fd, unsigned long request, void *arg)
+{
+    int result;
+
+    do {
+#if defined(__linux__) && defined(__GNUC__) && defined (__x86_64__)
+        __asm__("syscall"
+                : "=a" (result)
+                : "0" (__NR_ioctl), "D" (fd), "S" (request), "d" (arg)
+                : "cc", "rcx", "r11", "memory");
+#else
+        result = ioctl(fd, request, arg);
+        if (result == -1)
+            result = -errno;
+#endif
+    } while (result == -EINTR || result == -EAGAIN);
+
+    return result;
+}
+
 extern void *drmGetHashTable(void);
 extern drmHashEntry *drmGetEntry(int fd);
 
Signature · 7 lines
Cheers,
  Eric

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#3 lore raw
In reply to Eric Engestrom
Quoted 7 lines · Eric Engestrom

As Chad [1] puts it:

Quoted 2 lines

it's excessive to jump through the PLT into a shared object for a mere ioctl wrapper.

[1] https://lists.freedesktop.org/archives/mesa-dev/2017-June/159951.html

NAK, at least in this form:

Quoted 11 lines
xf86drm.c +0 -3
index 728ac78c..c82a76d2 100644
@@ -179,20 +179,6 @@ void drmFree(void *pt)
     free(pt);
 }
 
-/**
- * Call ioctl, restarting if it is interupted
- */

xf86drm.c void drmFree(void *pt) · line 194

Quoted 10 lines
xf86drm.c +0 -10
-int
-drmIoctl(int fd, unsigned long request, void *arg)
-{
-    int ret;
-
-    do {
-        ret = ioctl(fd, request, arg);
-    } while (ret == -1 && (errno == EINTR || errno == EAGAIN));
-    return ret;
-}

libdrm.so.2 must continue exporting a working drmIoctl symbol, otherwise it's an ABI break.

Also, there are downsides to exposing library API calls as inline
functions: E.g. if drmIoctl(2) ever needs a change (worst case a security bug fix), every user has to be recompiled to get the fix. It's kind of like static linking through the back door. Is it really worth it for drmIoctl(2)? Are they ever an actual bottleneck?

Signature · 6 lines
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#4 lore raw
Quoted 20 lines · Michel Dänzer
Quoted 7 lines · Eric Engestrom

As Chad [1] puts it:

Quoted 2 lines

it's excessive to jump through the PLT into a shared object for a mere ioctl wrapper.

[1] https://lists.freedesktop.org/archives/mesa-dev/2017-June/159951.html

NAK, at least in this form:

Quoted 8 lines
xf86drm.c +0 -0
index 728ac78c..c82a76d2 100644
@@ -179,20 +179,6 @@ void drmFree(void *pt)
     free(pt);
 }
 
Quoted 16 lines

xf86drm.c void drmFree(void *pt) · line 194

Quoted 13 lines
xf86drm.c +0 -13
-/**
- * Call ioctl, restarting if it is interupted
- */
-int
-drmIoctl(int fd, unsigned long request, void *arg)
-{
-    int ret;
-
-    do {
-        ret = ioctl(fd, request, arg);
-    } while (ret == -1 && (errno == EINTR || errno == EAGAIN));
-    return ret;
-}

libdrm.so.2 must continue exporting a working drmIoctl symbol, otherwise it's an ABI break.

Oops, you're absolutely right, my bad :/

Quoted 7 lines

Also, there are downsides to exposing library API calls as inline
functions: E.g. if drmIoctl(2) ever needs a change (worst case a security bug fix), every user has to be recompiled to get the fix. It's kind of like static linking through the back door. Is it really worth it for drmIoctl(2)? Are they ever an actual bottleneck?

The start of the conversation [1] was that the profiler was spending more time going through drmIoctl() than the actual syscall, which prompted Chris to write a local copy that would be inlined, and the fact some of that time was spend converting the error returned into a -1 and set the error in errno, which is rather pointless from a caller's perspective.

I simply took his proposal and applied it to libdrm, although I obviously did so badly.

Is the updatability of a loop around ioctl() really an issue? I can drop the first patch and respin the second as a normal dso function, would that be something people are interested in?

[1] https://lists.freedesktop.org/archives/mesa-dev/2017-June/159894.html

Quoted 5 lines
Signature · 3 lines
-- 
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer

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

#5 lore raw
Quoted 10 lines · Eric Engestrom
Quoted 6 lines · Michel Dänzer

Also, there are downsides to exposing library API calls as inline
functions: E.g. if drmIoctl(2) ever needs a change (worst case a security bug fix), every user has to be recompiled to get the fix. It's kind of like static linking through the back door. Is it really worth it for drmIoctl(2)? Are they ever an actual bottleneck?

The start of the conversation [1] was that the profiler was spending more time going through drmIoctl() than the actual syscall,

Is that an actual problem, as opposed to a cosmetic issue? I.e. is there any scenario where a metric is bounded by drmIoctl, and would otherwise only be bounded by the actual syscall?

Signature · 6 lines
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#6 lore raw
Quoted 12 lines · Michel Dänzer

On 22/06/17 11:45 PM, Eric Engestrom wrote:>

Quoted 5 lines

On Thursday, 2017-06-22 10:42:21 +0900, Michel Dänzer wrote:>

Quoted 4 lines
Quoted 1 line

Also, there are downsides to exposing library API calls as inline>
functions: E.g. if drmIoctl(2) ever needs a change (worst case a> security bug fix), every user has to be recompiled to get the fix.

It's>

Quoted 1 line
Quoted 1 line

kind of like static linking through the back door. Is it really

worth it>

Quoted 3 lines
Quoted 2 lines

for drmIoctl(2)? Are they ever an actual bottleneck?>

The start of the conversation [1] was that the profiler was

Quoted 8 lines

spending>

Quoted 2 lines

more time going through drmIoctl() than the actual syscall,>

Is that an actual problem, as opposed to a cosmetic issue? I.e. is there>
any scenario where a metric is bounded by drmIoctl, and would otherwise>
only be bounded by the actual syscall?>

I think this is a question for Chris (cc'ed)
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel