public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Sergey Bugaev <bugaevc@gmail.com>
To: libc-alpha@sourceware.org, bug-hurd@gnu.org
Cc: Samuel Thibault <samuel.thibault@gnu.org>,
	Sergey Bugaev <bugaevc@gmail.com>
Subject: [PATCH 2/5] hurd: Microoptimize sigreturn
Date: Fri, 14 Apr 2023 22:36:57 +0300	[thread overview]
Message-ID: <20230414193700.542116-2-bugaevc@gmail.com> (raw)
In-Reply-To: <20230414193700.542116-1-bugaevc@gmail.com>

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
---

I'll understand if this patch will be rejected, since this is not a hot path.
But I just couldn't help myself when I saw what this was being compiled to!
Much cleaner now.

If you don't like THREAD_GETMEM (THREAD_SELF, _hurd_sigstate), we could have
_hurd_self_sigstate_fast () or something.

 sysdeps/mach/hurd/i386/sigreturn.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/sysdeps/mach/hurd/i386/sigreturn.c b/sysdeps/mach/hurd/i386/sigreturn.c
index a0fc8891..6ad8a998 100644
--- a/sysdeps/mach/hurd/i386/sigreturn.c
+++ b/sysdeps/mach/hurd/i386/sigreturn.c
@@ -29,7 +29,12 @@ static void
 __sigreturn2 (int *usp, struct sigcontext *scp)
 {
   mach_port_t reply_port;
-  struct hurd_sigstate *ss = _hurd_self_sigstate ();
+  struct hurd_sigstate *ss;
+
+  /* We know the sigstate must be initialized, but the compiler does not.
+     Help it out a little bit by eliding the check that _hurd_self_sigstate
+     makes otherwise.  */
+  ss = THREAD_GETMEM (THREAD_SELF, _hurd_sigstate);
   _hurd_sigstate_unlock (ss);
 
   /* Destroy the MiG reply port used by the signal handler, and restore the
@@ -44,7 +49,7 @@ __sigreturn2 (int *usp, struct sigcontext *scp)
      do.  */
   reply_port = THREAD_GETMEM (THREAD_SELF, reply_port);
   THREAD_SETMEM (THREAD_SELF, reply_port, MACH_PORT_DEAD);
-  if (MACH_PORT_VALID (reply_port))
+  if (__glibc_likely (MACH_PORT_VALID (reply_port)))
     (void) __mach_port_mod_refs (__mach_task_self (), reply_port,
                                  MACH_PORT_RIGHT_RECEIVE, -1);
   THREAD_SETMEM (THREAD_SELF, reply_port, scp->sc_reply_port);
@@ -69,6 +74,7 @@ __sigreturn2 (int *usp, struct sigcontext *scp)
   /* Firewall.  */
   A (hlt);
 #undef A
+  __builtin_unreachable ();
 }
 
 int
@@ -77,13 +83,14 @@ __sigreturn (struct sigcontext *scp)
   struct hurd_sigstate *ss;
   struct hurd_userlink *link = (void *) &scp[1];
 
-  if (scp == NULL || (scp->sc_mask & _SIG_CANT_MASK))
+  if (__glibc_unlikely (scp == NULL || (scp->sc_mask & _SIG_CANT_MASK)))
     {
       errno = EINVAL;
       return -1;
     }
 
-  ss = _hurd_self_sigstate ();
+  /* Same as above, microoptimize _hurd_self_sigstate.  */
+  ss = THREAD_GETMEM (THREAD_SELF, _hurd_sigstate);
   _hurd_sigstate_lock (ss);
 
   /* Remove the link on the `active resources' chain added by
-- 
2.39.2


  reply	other threads:[~2023-04-14 19:37 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-14 19:36 [PATCH 1/5] hurd: Fix restoring reply port in sigreturn Sergey Bugaev
2023-04-14 19:36 ` Sergey Bugaev [this message]
2023-04-17 23:23   ` [PATCH 2/5] hurd: Microoptimize sigreturn Samuel Thibault
2023-04-18  9:34     ` Sergey Bugaev
2023-04-18 10:21     ` [PATCH 2/5] hurd: Microoptimize sigreturn Sergey Bugaev
2023-04-18 14:21       ` Samuel Thibault
2023-04-14 19:36 ` [PATCH 3/5] hurd: Implement sigreturn for x86_64 Sergey Bugaev
2023-04-14 19:36 ` [PATCH 4/5] hurd: Simplify _S_catch_exception_raise Sergey Bugaev
2023-04-17 23:24   ` Samuel Thibault
2023-04-14 19:37 ` [PATCH 5/5] hurd: Avoid leaking task & thread ports Sergey Bugaev
2023-04-17 23:24   ` Samuel Thibault
2023-04-17 19:00 ` [PATCH 1/5] hurd: Fix restoring reply port in sigreturn Samuel Thibault

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230414193700.542116-2-bugaevc@gmail.com \
    --to=bugaevc@gmail.com \
    --cc=bug-hurd@gnu.org \
    --cc=libc-alpha@sourceware.org \
    --cc=samuel.thibault@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).