public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] SYSCALL_CANCEL: reduce the size of generated code
@ 2017-04-14 20:07 Yury Norov
  2017-04-15  7:38 ` Florian Weimer
  0 siblings, 1 reply; 2+ messages in thread
From: Yury Norov @ 2017-04-14 20:07 UTC (permalink / raw)
  To: libc-alpha; +Cc: Yury Norov, Adhemerval Zanella

SYSCALL_CANCEL() currently calls INLINE_SYSCALL_CALL() both in true and
false branches of the "if (SINGLE_THREAD_P)" condition. If arguments that
passed in INLINE_SYSCALL_CALL() are wrapped with tricky macros or require
other additional handling, the code that does it becomes duplicated, and
it may increase the size of function that use it significantly.

This patch reworks the SYSCALL_CANCEL() to call INLINE_SYSCALL_CALL() only
once. On arm64/ilp32 it reduces the size of sync_file_range.o from 8736 to
7660 bytes.

The sync_file_range() is a simple single-line function though:

int
sync_file_range (int fd, __off64_t offset, __off64_t len, unsigned int flags)
{
  return SYSCALL_CANCEL (sync_file_range2, fd, flags, SYSCALL_LL64 (offset),
			 SYSCALL_LL64 (len));
}

	* sysdeps/unix/sysdep.h: Reduce duplication in SYSCALL_CANCEL() macro.
---
 sysdeps/unix/sysdep.h | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/sysdeps/unix/sysdep.h b/sysdeps/unix/sysdep.h
index 38c2432..f0fa9da 100644
--- a/sysdeps/unix/sysdep.h
+++ b/sysdeps/unix/sysdep.h
@@ -91,14 +91,13 @@
 #define SYSCALL_CANCEL(...) \
   ({									     \
     long int sc_ret;							     \
-    if (SINGLE_THREAD_P) 						     \
-      sc_ret = INLINE_SYSCALL_CALL (__VA_ARGS__); 			     \
-    else								     \
-      {									     \
-	int sc_cancel_oldtype = LIBC_CANCEL_ASYNC ();			     \
-	sc_ret = INLINE_SYSCALL_CALL (__VA_ARGS__);			     \
-        LIBC_CANCEL_RESET (sc_cancel_oldtype);				     \
-      }									     \
+    int sc_cancel_oldtype;						     \
+    bool multithread = !SINGLE_THREAD_P;				     \
+    if (multithread)						             \
+      sc_cancel_oldtype = LIBC_CANCEL_ASYNC ();				     \
+    sc_ret = INLINE_SYSCALL_CALL (__VA_ARGS__);				     \
+    if (multithread)						             \
+      LIBC_CANCEL_RESET (sc_cancel_oldtype);				     \
     sc_ret;								     \
   })
 
-- 
2.7.4

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] SYSCALL_CANCEL: reduce the size of generated code
  2017-04-14 20:07 [PATCH] SYSCALL_CANCEL: reduce the size of generated code Yury Norov
@ 2017-04-15  7:38 ` Florian Weimer
  0 siblings, 0 replies; 2+ messages in thread
From: Florian Weimer @ 2017-04-15  7:38 UTC (permalink / raw)
  To: Yury Norov, libc-alpha; +Cc: Adhemerval Zanella

On 04/14/2017 10:07 PM, Yury Norov wrote:
> SYSCALL_CANCEL() currently calls INLINE_SYSCALL_CALL() both in true and
> false branches of the "if (SINGLE_THREAD_P)" condition. If arguments that
> passed in INLINE_SYSCALL_CALL() are wrapped with tricky macros or require
> other additional handling, the code that does it becomes duplicated, and
> it may increase the size of function that use it significantly.

It also widens the window for the race, so I'm not sure if this is a 
good idea.

I think this code will change with the cancellation fixes anyway.

Thanks,
Florian

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-04-15  7:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-14 20:07 [PATCH] SYSCALL_CANCEL: reduce the size of generated code Yury Norov
2017-04-15  7:38 ` Florian Weimer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).