linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* posix-timers: Small cleanup in itimer_delete()
@ 2019-06-21 14:36 Sebastian Andrzej Siewior
  2019-06-21 14:36 ` [PATCH 1/2] posix-timers: Remove "it_signal = NULL" assignment " Sebastian Andrzej Siewior
  2019-06-21 14:36 ` [PATCH 2/2] posix-timers: Use spin_lock_irq() " Sebastian Andrzej Siewior
  0 siblings, 2 replies; 5+ messages in thread
From: Sebastian Andrzej Siewior @ 2019-06-21 14:36 UTC (permalink / raw)
  To: linux-kernel; +Cc: Thomas Gleixner

Small cleanup / optimisation / clarification in itimer_delete() which I
noticed while doing other things…

Sebastian



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

* [PATCH 1/2] posix-timers: Remove "it_signal = NULL" assignment in itimer_delete()
  2019-06-21 14:36 posix-timers: Small cleanup in itimer_delete() Sebastian Andrzej Siewior
@ 2019-06-21 14:36 ` Sebastian Andrzej Siewior
  2019-06-22 19:30   ` [tip:timers/core] " tip-bot for Sebastian Andrzej Siewior
  2019-06-21 14:36 ` [PATCH 2/2] posix-timers: Use spin_lock_irq() " Sebastian Andrzej Siewior
  1 sibling, 1 reply; 5+ messages in thread
From: Sebastian Andrzej Siewior @ 2019-06-21 14:36 UTC (permalink / raw)
  To: linux-kernel; +Cc: Thomas Gleixner, Sebastian Andrzej Siewior

itimer_delete() is invoked during do_exit(). At this point it is the
last thread in the group dying and doing the clean up.
Since it is the last thread in the group, there can not be any other
task attempting to lock the itimer which means the NULL assignment (which
avoids lookups in __lock_timer()) is not required.

The assignment and comment was copied in commit 0e568881178ff ("[PATCH]
fix posix-timers to have proper per-process scope") from
sys_timer_delete() which was/is the syscall interface and requires the
assignment.

Remove the superfluous ->it_signal = NULL assignment.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 kernel/time/posix-timers.c | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
index 29176635991f0..caa63e58e3d88 100644
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -990,11 +990,6 @@ static void itimer_delete(struct k_itimer *timer)
 		goto retry_delete;
 	}
 	list_del(&timer->list);
-	/*
-	 * This keeps any tasks waiting on the spin lock from thinking
-	 * they got something (see the lock code above).
-	 */
-	timer->it_signal = NULL;
 
 	unlock_timer(timer, flags);
 	release_posix_timer(timer, IT_ID_SET);
-- 
2.20.1


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

* [PATCH 2/2] posix-timers: Use spin_lock_irq() in itimer_delete()
  2019-06-21 14:36 posix-timers: Small cleanup in itimer_delete() Sebastian Andrzej Siewior
  2019-06-21 14:36 ` [PATCH 1/2] posix-timers: Remove "it_signal = NULL" assignment " Sebastian Andrzej Siewior
@ 2019-06-21 14:36 ` Sebastian Andrzej Siewior
  2019-06-22 19:31   ` [tip:timers/core] " tip-bot for Sebastian Andrzej Siewior
  1 sibling, 1 reply; 5+ messages in thread
From: Sebastian Andrzej Siewior @ 2019-06-21 14:36 UTC (permalink / raw)
  To: linux-kernel; +Cc: Thomas Gleixner, Sebastian Andrzej Siewior

itimer_delete() uses spin_lock_irqsave() to obtain a `flags' variable
which can then be passed to unlock_timer(). It uses already spin_lock
locking for the structure instead of lock_timer() because it has a timer
which can not be removed by others at this point. The cleanup is always
performed with enabled interrupts.

Use spin_lock_irq() / spin_unlock_irq() so the `flags' variable can be
removed.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 kernel/time/posix-timers.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
index caa63e58e3d88..d7f2d91acdac1 100644
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -980,18 +980,16 @@ SYSCALL_DEFINE1(timer_delete, timer_t, timer_id)
  */
 static void itimer_delete(struct k_itimer *timer)
 {
-	unsigned long flags;
-
 retry_delete:
-	spin_lock_irqsave(&timer->it_lock, flags);
+	spin_lock_irq(&timer->it_lock);
 
 	if (timer_delete_hook(timer) == TIMER_RETRY) {
-		unlock_timer(timer, flags);
+		spin_unlock_irq(&timer->it_lock);
 		goto retry_delete;
 	}
 	list_del(&timer->list);
 
-	unlock_timer(timer, flags);
+	spin_unlock_irq(&timer->it_lock);
 	release_posix_timer(timer, IT_ID_SET);
 }
 
-- 
2.20.1


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

* [tip:timers/core] posix-timers: Remove "it_signal = NULL" assignment in itimer_delete()
  2019-06-21 14:36 ` [PATCH 1/2] posix-timers: Remove "it_signal = NULL" assignment " Sebastian Andrzej Siewior
@ 2019-06-22 19:30   ` tip-bot for Sebastian Andrzej Siewior
  0 siblings, 0 replies; 5+ messages in thread
From: tip-bot for Sebastian Andrzej Siewior @ 2019-06-22 19:30 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: hpa, bigeasy, linux-kernel, tglx, mingo

Commit-ID:  12063d431078be73d11cb5e48a17c6db5f0d8254
Gitweb:     https://git.kernel.org/tip/12063d431078be73d11cb5e48a17c6db5f0d8254
Author:     Sebastian Andrzej Siewior <bigeasy@linutronix.de>
AuthorDate: Fri, 21 Jun 2019 16:36:42 +0200
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Sat, 22 Jun 2019 12:14:22 +0200

posix-timers: Remove "it_signal = NULL" assignment in itimer_delete()

itimer_delete() is invoked during do_exit(). At this point it is the
last thread in the group dying and doing the clean up.
Since it is the last thread in the group, there can not be any other
task attempting to lock the itimer which means the NULL assignment (which
avoids lookups in __lock_timer()) is not required.

The assignment and comment was copied in commit 0e568881178ff ("[PATCH]
fix posix-timers to have proper per-process scope") from
sys_timer_delete() which was/is the syscall interface and requires the
assignment.

Remove the superfluous ->it_signal = NULL assignment.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/20190621143643.25649-2-bigeasy@linutronix.de

---
 kernel/time/posix-timers.c | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
index 29176635991f..caa63e58e3d8 100644
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -990,11 +990,6 @@ retry_delete:
 		goto retry_delete;
 	}
 	list_del(&timer->list);
-	/*
-	 * This keeps any tasks waiting on the spin lock from thinking
-	 * they got something (see the lock code above).
-	 */
-	timer->it_signal = NULL;
 
 	unlock_timer(timer, flags);
 	release_posix_timer(timer, IT_ID_SET);

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

* [tip:timers/core] posix-timers: Use spin_lock_irq() in itimer_delete()
  2019-06-21 14:36 ` [PATCH 2/2] posix-timers: Use spin_lock_irq() " Sebastian Andrzej Siewior
@ 2019-06-22 19:31   ` tip-bot for Sebastian Andrzej Siewior
  0 siblings, 0 replies; 5+ messages in thread
From: tip-bot for Sebastian Andrzej Siewior @ 2019-06-22 19:31 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: linux-kernel, mingo, bigeasy, hpa, tglx

Commit-ID:  7586addb99322faf4d096fc8beb140f879409212
Gitweb:     https://git.kernel.org/tip/7586addb99322faf4d096fc8beb140f879409212
Author:     Sebastian Andrzej Siewior <bigeasy@linutronix.de>
AuthorDate: Fri, 21 Jun 2019 16:36:43 +0200
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Sat, 22 Jun 2019 12:14:22 +0200

posix-timers: Use spin_lock_irq() in itimer_delete()

itimer_delete() uses spin_lock_irqsave() to obtain a `flags' variable
which can then be passed to unlock_timer(). It uses already spin_lock
locking for the structure instead of lock_timer() because it has a timer
which can not be removed by others at this point. The cleanup is always
performed with enabled interrupts.

Use spin_lock_irq() / spin_unlock_irq() so the `flags' variable can be
removed.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/20190621143643.25649-3-bigeasy@linutronix.de

---
 kernel/time/posix-timers.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
index caa63e58e3d8..d7f2d91acdac 100644
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -980,18 +980,16 @@ retry_delete:
  */
 static void itimer_delete(struct k_itimer *timer)
 {
-	unsigned long flags;
-
 retry_delete:
-	spin_lock_irqsave(&timer->it_lock, flags);
+	spin_lock_irq(&timer->it_lock);
 
 	if (timer_delete_hook(timer) == TIMER_RETRY) {
-		unlock_timer(timer, flags);
+		spin_unlock_irq(&timer->it_lock);
 		goto retry_delete;
 	}
 	list_del(&timer->list);
 
-	unlock_timer(timer, flags);
+	spin_unlock_irq(&timer->it_lock);
 	release_posix_timer(timer, IT_ID_SET);
 }
 

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

end of thread, other threads:[~2019-06-22 19:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-21 14:36 posix-timers: Small cleanup in itimer_delete() Sebastian Andrzej Siewior
2019-06-21 14:36 ` [PATCH 1/2] posix-timers: Remove "it_signal = NULL" assignment " Sebastian Andrzej Siewior
2019-06-22 19:30   ` [tip:timers/core] " tip-bot for Sebastian Andrzej Siewior
2019-06-21 14:36 ` [PATCH 2/2] posix-timers: Use spin_lock_irq() " Sebastian Andrzej Siewior
2019-06-22 19:31   ` [tip:timers/core] " tip-bot for Sebastian Andrzej Siewior

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 NNTP newsgroup(s).