Skip to contentSkip to conversation

signal: replace !likely with unlikely!

RFC PATCH In review [email protected] 3 participants 5 messages Sep 11, 2014 – Sep 13, 2014

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 signal: replace !likely with unlikely!

From: Li RongQing <[email protected]>

!likely() is hard to be understood, and I do not know if compiler can optimise this condition, but unlikely(!()) is clear

---
 kernel/signal.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/signal.c +1 -1
index 8f0876f..6156cfa 100644
@@ -1571,7 +1571,7 @@ int send_sigqueue(struct sigqueue *q, struct task_struct *t, int group)
 	BUG_ON(!(q->flags & SIGQUEUE_PREALLOC));
 
 	ret = -1;
-	if (!likely(lock_task_sighand(t, &flags)))
+	if (unlikely(!lock_task_sighand(t, &flags)))
 		goto ret;
 
 	ret = 1; /* the signal is ignored */
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 15 lines · On Thu, Sep 11, 2014 at 08:48:16AM +0800, [email protected] wrote:

From: Li RongQing <[email protected]>

!likely() is hard to be understood, and I do not know if compiler can optimise this condition, but unlikely(!()) is clear

---
 kernel/signal.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/signal.c +0 -0
index 8f0876f..6156cfa 100644

kernel/signal.c int send_sigqueue(struct sigqueue *q, struct task_struct *t, int group) · line 1574

Quoted 5 lines
kernel/signal.c +1 -1
@@ -1571,7 +1571,7 @@ int send_sigqueue(struct sigqueue *q, struct task_struct *t, int group)
 	BUG_ON(!(q->flags & SIGQUEUE_PREALLOC));
 
 	ret = -1;
-	if (!likely(lock_task_sighand(t, &flags)))
+	if (unlikely(!lock_task_sighand(t, &flags)))

I wonder if you tested this code. Seems to be unlikely (punt not intended).

Guenter

Quoted 13 lines
kernel/signal.c +0 -0
 		goto ret;
 
 	ret = 1; /* the signal is ignored */
Signature · 7 lines
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
#2 lore raw

I did not test, how to test it?

Quoted 39 lines · Guenter Roeck
Quoted 15 lines · On Thu, Sep 11, 2014 at 08:48:16AM +0800, [email protected] wrote:

From: Li RongQing <[email protected]>

!likely() is hard to be understood, and I do not know if compiler can optimise this condition, but unlikely(!()) is clear

---
 kernel/signal.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/signal.c +0 -0
index 8f0876f..6156cfa 100644

kernel/signal.c int send_sigqueue(struct sigqueue *q, struct task_struct *t, int group) · line 1574

Quoted 5 lines
kernel/signal.c +1 -1
@@ -1571,7 +1571,7 @@ int send_sigqueue(struct sigqueue *q, struct task_struct *t, int group)
      BUG_ON(!(q->flags & SIGQUEUE_PREALLOC));
 
      ret = -1;
-     if (!likely(lock_task_sighand(t, &flags)))
+     if (unlikely(!lock_task_sighand(t, &flags)))

I wonder if you tested this code. Seems to be unlikely (punt not intended).

Guenter

Quoted 13 lines
kernel/signal.c +0 -1
              goto ret;
 
      ret = 1; /* the signal is ignored */
--

1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

#3 lore raw

Am 13.09.2014 04:48, schrieb Li RongQing:

Quoted 1 line

I did not test, how to test it?

Compare the object files of both variants to find out whether both create semantically equivalent code and whether the un/likely have an effect. i.e. objdump -S -d kernel/signal.o
I guess you can just remove the likely as gcc is smart enough to detect the "goto ret;" as an unlikely taken branch.

Thanks,
//richard

#4 lore raw
Quoted 9 lines · Richard Weinberger

Am 13.09.2014 04:48, schrieb Li RongQing:

Quoted 1 line

I did not test, how to test it?

Compare the object files of both variants to find out whether both create semantically equivalent code and whether the un/likely have an effect. i.e. objdump -S -d kernel/signal.o
I guess you can just remove the likely as gcc is smart enough to detect the "goto ret;" as an unlikely taken branch.

Or just write similar test code and observe the result.

When you are doing that, you might learn that if "(!likely(expression))" is _not_ the same as "if (unlikely(!expression))".

Guenter