Skip to contentSkip to conversation

kernel/{exit.c, signal.c, power/process.c}: replace !likely(x) by likely(!x)

PATCH In review Roel Kluin 3 participants 8 messages Feb 16, 2008 – Feb 17, 2008

Subsystems (2)
lore
Share & tools
lore

Roel Kluin

author
#0 lore raw

PATCH 2/2 kernel/{exit.c, signal.c, power/process.c}: replace !likely(x) by likely(!x)

Not entirely sure who to send this to
---
Replace !likely(x) by likely(!x)

---

kernel/exit.c +2 -2
index 506a957..df207fc 100644
@@ -1497,7 +1497,7 @@ repeat:
 				/*
 				 * We don't reap group leaders with subthreads.
 				 */
-				if (!likely(options & WEXITED))
+				if (likely(!(options & WEXITED)))
 					continue;
 				retval = wait_task_zombie(p,
 						(options & WNOWAIT), infop,
@@ -1508,7 +1508,7 @@ repeat:
 				 * exit, stop, or stop and then continue.
 				 */
 				flag = 1;
-				if (!unlikely(options & WCONTINUED))
+				if (unlikely(!(options & WCONTINUED)))
 					continue;
 				retval = wait_task_continued(p,
 						(options & WNOWAIT), infop,
kernel/power/process.c +1 -1
index 7c2118f..b42254b 100644
@@ -36,7 +36,7 @@ static inline int freezeable(struct task_struct * p)
  */
 static inline void frozen_process(void)
 {
-	if (!unlikely(current->flags & PF_NOFREEZE)) {
+	if (unlikely(!(current->flags & PF_NOFREEZE))) {
 		current->flags |= PF_FROZEN;
 		wmb();
 	}
kernel/signal.c +5 -5
index 84917fe..1155e16 100644
@@ -1308,7 +1308,7 @@ int send_sigqueue(int sig, struct sigqueue *q, struct task_struct *p)
 	 */
 	rcu_read_lock();
 
-	if (!likely(lock_task_sighand(p, &flags))) {
+	if (likely(!lock_task_sighand(p, &flags))) {
 		ret = -1;
 		goto out_err;
 	}
@@ -1548,7 +1548,7 @@ static void do_notify_parent_cldstop(struct task_struct *tsk, int why)
 
 static inline int may_ptrace_stop(void)
 {
-	if (!likely(current->ptrace & PT_PTRACED))
+	if (likely(!(current->ptrace & PT_PTRACED)))
 		return 0;
 	/*
 	 * Are we in the middle of do_coredump?
@@ -1574,7 +1574,7 @@ static int sigkill_pending(struct task_struct *tsk)
 {
 	return ((sigismember(&tsk->pending.signal, SIGKILL) ||
 		 sigismember(&tsk->signal->shared_pending.signal, SIGKILL)) &&
-		!unlikely(sigismember(&tsk->blocked, SIGKILL)));
+		 unlikely(!sigismember(&tsk->blocked, SIGKILL)));
 }
 
 /*
@@ -1625,7 +1625,7 @@ static void ptrace_stop(int exit_code, int clear_code, siginfo_t *info)
 	spin_unlock_irq(&current->sighand->siglock);
 	try_to_freeze();
 	read_lock(&tasklist_lock);
-	if (!unlikely(killed) && may_ptrace_stop()) {
+	if (unlikely(!killed) && may_ptrace_stop()) {
 		do_notify_parent_cldstop(current, CLD_TRAPPED);
 		read_unlock(&tasklist_lock);
 		schedule();
@@ -1717,7 +1717,7 @@ static int do_signal_stop(int signr)
 	} else {
 		struct task_struct *t;
 
-		if (!likely(sig->flags & SIGNAL_STOP_DEQUEUED) ||
+		if (likely(!(sig->flags & SIGNAL_STOP_DEQUEUED)) ||
 		    unlikely(sig->group_exit_task))
 			return 0;
 		/*
#1 lore raw
Quoted 3 lines · Roel Kluin

Not entirely sure who to send this to
---
Replace !likely(x) by likely(!x)

Whoa...

Are you sure this is correct?

!likely(x) is equivalent to unlikely(!x), not the opposite, so this is a functional change...

-hpa

author
#2 lore raw
Quoted 5 lines · H. Peter Anvin
Quoted 3 lines · Roel Kluin

Not entirely sure who to send this to
---
Replace !likely(x) by likely(!x)

Quoted 9 lines

Whoa...

Are you sure this is correct?

!likely(x) is equivalent to unlikely(!x), not the opposite, so this is a functional change...

-hpa

You are right, sorry, Need more caffeine. I will send the right patch later.

#3 lore raw
Quoted 5 lines · Roel Kluin
Quoted 4 lines · H. Peter Anvin
Quoted 3 lines · Roel Kluin

Not entirely sure who to send this to
---
Replace !likely(x) by likely(!x)

Quoted 8 lines
Quoted 7 lines

Whoa...

Are you sure this is correct?

!likely(x) is equivalent to unlikely(!x), not the opposite, so this is a functional change...

You are right, sorry, Need more caffeine. I will send the right patch later.

Note I didn't say it was wrong, I just wanted a bit more explanation about why it's right, if it is.

-hpa

author
#4 lore raw
Quoted 10 lines · H. Peter Anvin
Quoted 9 lines · Roel Kluin
Quoted 8 lines · H. Peter Anvin
Quoted 3 lines · Roel Kluin

Not entirely sure who to send this to
---
Replace !likely(x) by likely(!x)

Whoa...

Are you sure this is correct?

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

!likely(x) is equivalent to unlikely(!x), not the opposite, so this is a functional change...

You are right, sorry, Need more caffeine. I will send the right patch later.

Note I didn't say it was wrong, I just wanted a bit more explanation about why it's right, if it is.

No, I just wanted to move the '!' within the parentheses, I didn't want to change semantics. below is how I guess the patch should have been. Thanks for your response.
---
Replace !likely(x) by unlikely(!x)

---

kernel/signal.c +6 -6
index 84917fe..cf5d45a 100644
@@ -1308,7 +1308,7 @@ int send_sigqueue(int sig, struct sigqueue *q, struct task_struct *p)
 	 */
 	rcu_read_lock();
 
-	if (!likely(lock_task_sighand(p, &flags))) {
+	if (unlikely(!lock_task_sighand(p, &flags))) {
 		ret = -1;
 		goto out_err;
 	}
@@ -1548,7 +1548,7 @@ static void do_notify_parent_cldstop(struct task_struct *tsk, int why)
 
 static inline int may_ptrace_stop(void)
 {
-	if (!likely(current->ptrace & PT_PTRACED))
+	if (unlikely(!(current->ptrace & PT_PTRACED)))
 		return 0;
 	/*
 	 * Are we in the middle of do_coredump?
@@ -1574,7 +1574,7 @@ static int sigkill_pending(struct task_struct *tsk)
 {
 	return ((sigismember(&tsk->pending.signal, SIGKILL) ||
 		 sigismember(&tsk->signal->shared_pending.signal, SIGKILL)) &&
-		!unlikely(sigismember(&tsk->blocked, SIGKILL)));
+		 likely(!sigismember(&tsk->blocked, SIGKILL)));
 }
 
 /*
@@ -1625,7 +1625,7 @@ static void ptrace_stop(int exit_code, int clear_code, siginfo_t *info)
 	spin_unlock_irq(&current->sighand->siglock);
 	try_to_freeze();
 	read_lock(&tasklist_lock);
-	if (!unlikely(killed) && may_ptrace_stop()) {
+	if (likely(!killed) && may_ptrace_stop()) {
 		do_notify_parent_cldstop(current, CLD_TRAPPED);
 		read_unlock(&tasklist_lock);
 		schedule();
@@ -1717,8 +1717,8 @@ static int do_signal_stop(int signr)
 	} else {
 		struct task_struct *t;
 
-		if (!likely(sig->flags & SIGNAL_STOP_DEQUEUED) ||
-		    unlikely(sig->group_exit_task))
+		if (unlikely(!(sig->flags & SIGNAL_STOP_DEQUEUED) ||
+		    sig->group_exit_task))
 			return 0;
 		/*
 		 * There is no group stop already in progress.
#5 lore raw
In reply to H. Peter Anvin
Quoted 10 lines · H. Peter Anvin
Quoted 3 lines · Roel Kluin

Not entirely sure who to send this to
---
Replace !likely(x) by likely(!x)

Whoa...

Are you sure this is correct?

!likely(x) is equivalent to unlikely(!x)

Not with respect to its value I believe? likely(x) == !!(x), and unlikely(!x) == !!(!x) = !x, so conditions work out differently?

Quoted 1 line

not the opposite, so this is a functional change...

Rene.

#6 lore raw
Quoted 6 lines · Rene Herman
Quoted 5 lines · H. Peter Anvin
Quoted 3 lines · Roel Kluin

Not entirely sure who to send this to
---
Replace !likely(x) by likely(!x)

Quoted 7 lines
Quoted 5 lines

Whoa...

Are you sure this is correct?

!likely(x) is equivalent to unlikely(!x)

Not with respect to its value I believe? likely(x) == !!(x), and unlikely(!x) == !!(!x) = !x, so conditions work out differently?

You missed one ! sign:

!likely(x) == !!!(x) == unlikely(!x) == !!(!(x))

-hpa

#7 lore raw
Quoted 11 lines · H. Peter Anvin
Quoted 10 lines · Rene Herman
Quoted 9 lines · H. Peter Anvin
Quoted 3 lines · Roel Kluin

Not entirely sure who to send this to
---
Replace !likely(x) by likely(!x)

Whoa...

Are you sure this is correct?

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

!likely(x) is equivalent to unlikely(!x)

Not with respect to its value I believe? likely(x) == !!(x), and unlikely(!x) == !!(!x) = !x, so conditions work out differently?

You missed one ! sign:

!likely(x) == !!!(x) == unlikely(!x) == !!(!(x))

Yup, sorry, misread.

Rene.