Skip to contentSkip to conversation

treewide: Remove redundant branch predictions around signal_pending family

PATCH Applied Davidlohr Bueso 2 participants 8 messages Nov 16, 2018 – Nov 27, 2018

Subsystems (12)
lore
Share & tools
lore
#0 lore raw

cover treewide: Remove redundant branch predictions around signal_pending family

Hi,

This series trivially gets rid of users of signal_pending (and family) explicitly wrapping the call around an unlikely(). It is redundant as internally this is already done for us via signal_pending() and [__]fatal_signal_pending().

All patches are independent, so I split it up in case folks want to pick up bits separately.

Compile tested only. Please consider for v4.21.

Thanks!

Davidlohr Bueso (6):
locking/mutex: Remove caller signal_pending branch predictions kernel/sched: Remove caller signal_pending branch predictions arch/arc: Remove caller signal_pending_branch predictions
mm: Remove caller signal_pending branch predictions drivers/i2c: Remove caller signal_pending branch predictions
fs: Remove caller signal_pending branch predictions

 arch/arc/mm/fault.c              | 2 +-
 drivers/i2c/busses/i2c-ibm_iic.c | 2 +-
 fs/afs/fs_probe.c                | 2 +-
 fs/afs/vl_probe.c                | 2 +-
 fs/buffer.c                      | 2 +-
 fs/exec.c                        | 4 ++--
 fs/orangefs/orangefs-bufmap.c    | 2 +-
 kernel/locking/mutex.c           | 2 +-
 kernel/sched/core.c              | 2 +-
 kernel/sched/swait.c             | 2 +-
 kernel/sched/wait.c              | 2 +-
 mm/filemap.c                     | 2 +-
 mm/gup.c                         | 2 +-
 mm/hugetlb.c                     | 2 +-
 14 files changed, 15 insertions(+), 15 deletions(-)
Signature · 1 line
2.16.4
#1 lore raw

PATCH 1/6 locking/mutex: Remove caller signal_pending branch predictions

This is already done for us internally by the signal machinery.

---
 kernel/locking/mutex.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/locking/mutex.c +1 -1
index 3f8a35104285..db578783dd36 100644
@@ -987,7 +987,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
 		 * wait_lock. This ensures the lock cancellation is ordered
 		 * against mutex_unlock() and wake-ups do not go missing.
 		 */
-		if (unlikely(signal_pending_state(state, current))) {
+		if (signal_pending_state(state, current)) {
 			ret = -EINTR;
 			goto err;
 		}
Signature · 1 line
2.16.4
#2 lore raw

PATCH 2/6 kernel/sched: Remove caller signal_pending branch predictions

In reply to Davidlohr Bueso

This is already done for us internally by the signal machinery.

---
 kernel/sched/core.c  | 2 +-
 kernel/sched/swait.c | 2 +-
 kernel/sched/wait.c  | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
kernel/sched/core.c +1 -1
index f12225f26b70..1972b4c63a1f 100644
@@ -3416,7 +3416,7 @@ static void __sched notrace __schedule(bool preempt)
 
 	switch_count = &prev->nivcsw;
 	if (!preempt && prev->state) {
-		if (unlikely(signal_pending_state(prev->state, prev))) {
+		if (signal_pending_state(prev->state, prev)) {
 			prev->state = TASK_RUNNING;
 		} else {
 			deactivate_task(rq, prev, DEQUEUE_SLEEP | DEQUEUE_NOCLOCK);
kernel/sched/swait.c +1 -1
index 66b59ac77c22..e83a3f8449f6 100644
@@ -93,7 +93,7 @@ long prepare_to_swait_event(struct swait_queue_head *q, struct swait_queue *wait
 	long ret = 0;
 
 	raw_spin_lock_irqsave(&q->lock, flags);
-	if (unlikely(signal_pending_state(state, current))) {
+	if (signal_pending_state(state, current)) {
 		/*
 		 * See prepare_to_wait_event(). TL;DR, subsequent swake_up_one()
 		 * must not see us.
kernel/sched/wait.c +1 -1
index 5dd47f1103d1..6eb1f8efd221 100644
@@ -264,7 +264,7 @@ long prepare_to_wait_event(struct wait_queue_head *wq_head, struct wait_queue_en
 	long ret = 0;
 
 	spin_lock_irqsave(&wq_head->lock, flags);
-	if (unlikely(signal_pending_state(state, current))) {
+	if (signal_pending_state(state, current)) {
 		/*
 		 * Exclusive waiter must not fail if it was selected by wakeup,
 		 * it should "consume" the condition we were waiting for.
Signature · 1 line
2.16.4
#3 lore raw

PATCH 3/6 arch/arc: Remove caller signal_pending_branch predictions

In reply to Davidlohr Bueso

This is already done for us internally by the signal machinery.

---
 arch/arc/mm/fault.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arc/mm/fault.c +1 -1
index c9da6102eb4f..6b6df8f9f882 100644
@@ -142,7 +142,7 @@ void do_page_fault(unsigned long address, struct pt_regs *regs)
 	fault = handle_mm_fault(vma, address, flags);
 
 	/* If Pagefault was interrupted by SIGKILL, exit page fault "early" */
-	if (unlikely(fatal_signal_pending(current))) {
+	if (fatal_signal_pending(current)) {
 		if ((fault & VM_FAULT_ERROR) && !(fault & VM_FAULT_RETRY))
 			up_read(&mm->mmap_sem);
 		if (user_mode(regs))
Signature · 1 line
2.16.4
#4 lore raw

PATCH 4/6 mm: Remove caller signal_pending branch predictions

In reply to Davidlohr Bueso

This is already done for us internally by the signal machinery.

---
 mm/filemap.c | 2 +-
 mm/gup.c     | 2 +-
 mm/hugetlb.c | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
mm/filemap.c +1 -1
index 81adec8ee02c..abd6c4591855 100644
@@ -1096,7 +1096,7 @@ static inline int wait_on_page_bit_common(wait_queue_head_t *q,
 				break;
 		}
 
-		if (unlikely(signal_pending_state(state, current))) {
+		if (signal_pending_state(state, current)) {
 			ret = -EINTR;
 			break;
 		}
mm/gup.c +1 -1
index f76e77a2d34b..391c71dde267 100644
@@ -722,7 +722,7 @@ static long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
 		 * If we have a pending SIGKILL, don't keep faulting pages and
 		 * potentially allocating memory.
 		 */
-		if (unlikely(fatal_signal_pending(current))) {
+		if (fatal_signal_pending(current)) {
 			ret = -ERESTARTSYS;
 			goto out;
 		}
mm/hugetlb.c +1 -1
index c007fb5fb8d5..da798bc2e948 100644
@@ -4184,7 +4184,7 @@ long follow_hugetlb_page(struct mm_struct *mm, struct vm_area_struct *vma,
 		 * If we have a pending SIGKILL, don't keep faulting pages and
 		 * potentially allocating memory.
 		 */
-		if (unlikely(fatal_signal_pending(current))) {
+		if (fatal_signal_pending(current)) {
 			remainder = 0;
 			break;
 		}
Signature · 1 line
2.16.4
#5 lore raw

PATCH 5/6 drivers/i2c: Remove caller signal_pending branch predictions

In reply to Davidlohr Bueso

This is already done for us internally by the signal machinery.

---
 drivers/i2c/busses/i2c-ibm_iic.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/busses/i2c-ibm_iic.c +1 -1
index 6f6e1dfe7cce..d78023d42a35 100644
@@ -437,7 +437,7 @@ static int iic_wait_for_tc(struct ibm_iic_private* dev){
 				break;
 			}
 
-			if (unlikely(signal_pending(current))){
+			if (signal_pending(current)){
 				DBG("%d: poll interrupted\n", dev->idx);
 				ret = -ERESTARTSYS;
 				break;
Signature · 1 line
2.16.4
#7 lore raw

PATCH 6/6 fs: Remove caller signal_pending branch predictions

In reply to Davidlohr Bueso

This is already done for us internally by the signal machinery.

---
 fs/afs/fs_probe.c             | 2 +-
 fs/afs/vl_probe.c             | 2 +-
 fs/buffer.c                   | 2 +-
 fs/exec.c                     | 4 ++--
 fs/orangefs/orangefs-bufmap.c | 2 +-
 5 files changed, 6 insertions(+), 6 deletions(-)
fs/afs/fs_probe.c +1 -1
index d049cb459742..428588fb38c6 100644
@@ -238,7 +238,7 @@ int afs_wait_for_fs_probes(struct afs_server_list *slist, unsigned long untried)
 			}
 		}
 
-		if (!still_probing || unlikely(signal_pending(current)))
+		if (!still_probing || signal_pending(current))
 			goto stop;
 		schedule();
 	}
fs/afs/vl_probe.c +1 -1
index c0f616bd70cb..60069640b33d 100644
@@ -239,7 +239,7 @@ int afs_wait_for_vl_probes(struct afs_vlserver_list *vllist,
 			}
 		}
 
-		if (!still_probing || unlikely(signal_pending(current)))
+		if (!still_probing || signal_pending(current))
 			goto stop;
 		schedule();
 	}
fs/buffer.c +1 -1
index 1286c2b95498..f88ee2bb62fc 100644
@@ -2366,7 +2366,7 @@ static int cont_expand_zero(struct file *file, struct address_space *mapping,
 
 		balance_dirty_pages_ratelimited(mapping);
 
-		if (unlikely(fatal_signal_pending(current))) {
+		if (fatal_signal_pending(current))) {
 			err = -EINTR;
 			goto out;
 		}
fs/exec.c +2 -2
index fc281b738a98..2bb8bece54cc 100644
@@ -1084,7 +1084,7 @@ static int de_thread(struct task_struct *tsk)
 		__set_current_state(TASK_KILLABLE);
 		spin_unlock_irq(lock);
 		schedule();
-		if (unlikely(__fatal_signal_pending(tsk)))
+		if (__fatal_signal_pending(tsk))
 			goto killed;
 		spin_lock_irq(lock);
 	}
@@ -1112,7 +1112,7 @@ static int de_thread(struct task_struct *tsk)
 			write_unlock_irq(&tasklist_lock);
 			cgroup_threadgroup_change_end(tsk);
 			schedule();
-			if (unlikely(__fatal_signal_pending(tsk)))
+			if (__fatal_signal_pending(tsk))
 				goto killed;
 		}
 
fs/orangefs/orangefs-bufmap.c +1 -1
index c4e98c9c1621..443bcd8c3c19 100644
@@ -105,7 +105,7 @@ static int wait_for_free(struct slot_map *m)
 			left = t;
 		else
 			left = t + (left - n);
-		if (unlikely(signal_pending(current)))
+		if (signal_pending(current))
 			left = -EINTR;
 	} while (left > 0);
 
Signature · 1 line
2.16.4