Skip to contentSkip to conversation

Converge on using secs_to_jiffies()

PATCH In review Easwar Hariharan 3 participants 8 messages Dec 17, 2024 – Jan 2, 2025

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

v4 cover Converge on using secs_to_jiffies()

Fixups for a couple of patches that received review after the series was queued into mm.

---
Changes in v4:
- Replace schedule_delayed_work() that had a 0 timeout with
schedule_work() in livepatch (Christophe Leroy)
- Added requested hunk in s390 (Alexander Gordeev)
- Link to v3: https://lore.kernel.org/r/20241210-converge-secs-to-jiffies-v3-0-ddfefd7e9f2a@linux.microsoft.com
Changes in v3:
- Rebase on next-20241210
- Fix typo'ed timeout in net/netfilter/nf_conntrack_proto_sctp.c (Stephen Rothwell)
- Use Coccinelle operation modes for Coccinelle script (Markus Elfring)
- Remove redundant comments in arch/arm/mach-pxa/sharpsl_pm.c (Christophe Leroy)
- Remove excess line breaks (Heiko Carstens, Christophe Leroy)
- Add more detail into the commit messages throughout (Christophe Leroy)
- Pick up Reviewed-by Thomas Hellstrom for drm/xe
- Drop drm/etnaviv patch already queued into etnaviv/next
- Replace call to [m]secs_to_jiffies(0) with just 0 for livepatch (Dan Carpenter, Christophe Leroy)
- Split out nfp patch to send to net-next (Christophe Leroy)
- Pick up Acked-by from Jeff Johnson for ath11k
- Link to v2: https://lore.kernel.org/r/20241115-converge-secs-to-jiffies-v2-0-911fb7595e79@linux.microsoft.com
Changes in v2:
- Exclude already accepted patch adding secs_to_jiffies() https://git.kernel.org/tip/b35108a51cf7bab58d7eace1267d7965978bcdb8
- Link to v1: https://lore.kernel.org/r/20241115-converge-secs-to-jiffies-v1-0-19aadc34941b@linux.microsoft.com

Easwar Hariharan (2):
s390: kernel: Convert timeouts to use secs_to_jiffies()
livepatch: Convert timeouts to secs_to_jiffies()

 arch/s390/kernel/lgr.c                          |  2 +-
 arch/s390/kernel/time.c                         |  4 ++--
 arch/s390/kernel/topology.c                     |  2 +-
 arch/s390/mm/cmm.c                              |  2 +-
 samples/livepatch/livepatch-callbacks-busymod.c |  3 +--
 samples/livepatch/livepatch-shadow-fix1.c       |  3 +--
 samples/livepatch/livepatch-shadow-mod.c        | 15 +++++----------
 7 files changed, 12 insertions(+), 19 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH v4 1/2 s390: kernel: Convert timeouts to use secs_to_jiffies()

Commit b35108a51cf7 ("jiffies: Define secs_to_jiffies()") introduced secs_to_jiffies(). As the values here are a multiple of 1000, use secs_to_jiffies() instead of msecs_to_jiffies to avoid the multiplication.

This is converted using scripts/coccinelle/misc/secs_to_jiffies.cocci with the following Coccinelle rules:

@@ constant C; @@

- msecs_to_jiffies(C * 1000)
+ secs_to_jiffies(C)

@@ constant C; @@

- msecs_to_jiffies(C * MSEC_PER_SEC)
+ secs_to_jiffies(C)

While here, manually convert the one other remaining instance as requested.

---
 arch/s390/kernel/lgr.c      | 2 +-
 arch/s390/kernel/time.c     | 4 ++--
 arch/s390/kernel/topology.c | 2 +-
 arch/s390/mm/cmm.c          | 2 +-
 4 files changed, 5 insertions(+), 5 deletions(-)
arch/s390/kernel/lgr.c +1 -1
index 6652e54cf3db..6d1ffca5f798 100644
@@ -166,7 +166,7 @@ static struct timer_list lgr_timer;
  */
 static void lgr_timer_set(void)
 {
-	mod_timer(&lgr_timer, jiffies + msecs_to_jiffies(LGR_TIMER_INTERVAL_SECS * MSEC_PER_SEC));
+	mod_timer(&lgr_timer, jiffies + secs_to_jiffies(LGR_TIMER_INTERVAL_SECS));
 }
 
 /*
arch/s390/kernel/time.c +2 -2
index 34a65c141ea0..e9f47c3a6197 100644
@@ -662,12 +662,12 @@ static void stp_check_leap(void)
 		if (ret < 0)
 			pr_err("failed to set leap second flags\n");
 		/* arm Timer to clear leap second flags */
-		mod_timer(&stp_timer, jiffies + msecs_to_jiffies(14400 * MSEC_PER_SEC));
+		mod_timer(&stp_timer, jiffies + secs_to_jiffies(14400));
 	} else {
 		/* The day the leap second is scheduled for hasn't been reached. Retry
 		 * in one hour.
 		 */
-		mod_timer(&stp_timer, jiffies + msecs_to_jiffies(3600 * MSEC_PER_SEC));
+		mod_timer(&stp_timer, jiffies + secs_to_jiffies(3600));
 	}
 }
 
arch/s390/kernel/topology.c +1 -1
index 4f9c301a705b..0fd56a1cadbd 100644
@@ -371,7 +371,7 @@ static void set_topology_timer(void)
 	if (atomic_add_unless(&topology_poll, -1, 0))
 		mod_timer(&topology_timer, jiffies + msecs_to_jiffies(100));
 	else
-		mod_timer(&topology_timer, jiffies + msecs_to_jiffies(60 * MSEC_PER_SEC));
+		mod_timer(&topology_timer, jiffies + secs_to_jiffies(60));
 }
 
 void topology_expect_change(void)
arch/s390/mm/cmm.c +1 -1
index d01724a715d0..7bf0f691827b 100644
@@ -204,7 +204,7 @@ static void cmm_set_timer(void)
 			del_timer(&cmm_timer);
 		return;
 	}
-	mod_timer(&cmm_timer, jiffies + msecs_to_jiffies(cmm_timeout_seconds * MSEC_PER_SEC));
+	mod_timer(&cmm_timer, jiffies + secs_to_jiffies(cmm_timeout_seconds));
 }
 
 static void cmm_timer_fn(struct timer_list *unused)
Signature · 1 line
2.43.0
#2 lore raw

PATCH v4 2/2 livepatch: Convert timeouts to secs_to_jiffies()

In reply to Easwar Hariharan

Commit b35108a51cf7 ("jiffies: Define secs_to_jiffies()") introduced secs_to_jiffies(). As the value here is a multiple of 1000, use secs_to_jiffies() instead of msecs_to_jiffies to avoid the multiplication.

This is converted using scripts/coccinelle/misc/secs_to_jiffies.cocci with the following Coccinelle rules:

@@ constant C; @@

- msecs_to_jiffies(C * 1000)
+ secs_to_jiffies(C)

@@ constant C; @@

- msecs_to_jiffies(C * MSEC_PER_SEC)
+ secs_to_jiffies(C)

While here, replace the schedule_delayed_work() call with a 0 timeout with an immediate schedule_work() call.

---
 samples/livepatch/livepatch-callbacks-busymod.c |  3 +--
 samples/livepatch/livepatch-shadow-fix1.c       |  3 +--
 samples/livepatch/livepatch-shadow-mod.c        | 15 +++++----------
 3 files changed, 7 insertions(+), 14 deletions(-)
samples/livepatch/livepatch-callbacks-busymod.c +1 -2
index 378e2d40271a..0220f7715fcc 100644
@@ -44,8 +44,7 @@ static void busymod_work_func(struct work_struct *work)
 static int livepatch_callbacks_mod_init(void)
 {
 	pr_info("%s\n", __func__);
-	schedule_delayed_work(&work,
-		msecs_to_jiffies(1000 * 0));
+	schedule_work(&work);
 	return 0;
 }
 
samples/livepatch/livepatch-shadow-fix1.c +1 -2
index 6701641bf12d..f3f153895d6c 100644
@@ -72,8 +72,7 @@ static struct dummy *livepatch_fix1_dummy_alloc(void)
 	if (!d)
 		return NULL;
 
-	d->jiffies_expire = jiffies +
-		msecs_to_jiffies(1000 * EXPIRE_PERIOD);
+	d->jiffies_expire = jiffies + secs_to_jiffies(EXPIRE_PERIOD);
 
 	/*
 	 * Patch: save the extra memory location into a SV_LEAK shadow
samples/livepatch/livepatch-shadow-mod.c +5 -10
index 7e753b0d2fa6..5d83ad5a8118 100644
@@ -101,8 +101,7 @@ static __used noinline struct dummy *dummy_alloc(void)
 	if (!d)
 		return NULL;
 
-	d->jiffies_expire = jiffies +
-		msecs_to_jiffies(1000 * EXPIRE_PERIOD);
+	d->jiffies_expire = jiffies + secs_to_jiffies(EXPIRE_PERIOD);
 
 	/* Oops, forgot to save leak! */
 	leak = kzalloc(sizeof(*leak), GFP_KERNEL);
@@ -152,8 +151,7 @@ static void alloc_work_func(struct work_struct *work)
 	list_add(&d->list, &dummy_list);
 	mutex_unlock(&dummy_list_mutex);
 
-	schedule_delayed_work(&alloc_dwork,
-		msecs_to_jiffies(1000 * ALLOC_PERIOD));
+	schedule_delayed_work(&alloc_dwork, secs_to_jiffies(ALLOC_PERIOD));
 }
 
 /*
@@ -184,16 +182,13 @@ static void cleanup_work_func(struct work_struct *work)
 	}
 	mutex_unlock(&dummy_list_mutex);
 
-	schedule_delayed_work(&cleanup_dwork,
-		msecs_to_jiffies(1000 * CLEANUP_PERIOD));
+	schedule_delayed_work(&cleanup_dwork, secs_to_jiffies(CLEANUP_PERIOD));
 }
 
 static int livepatch_shadow_mod_init(void)
 {
-	schedule_delayed_work(&alloc_dwork,
-		msecs_to_jiffies(1000 * ALLOC_PERIOD));
-	schedule_delayed_work(&cleanup_dwork,
-		msecs_to_jiffies(1000 * CLEANUP_PERIOD));
+	schedule_delayed_work(&alloc_dwork, secs_to_jiffies(ALLOC_PERIOD));
+	schedule_delayed_work(&cleanup_dwork, secs_to_jiffies(CLEANUP_PERIOD));
 
 	return 0;
 }
Signature · 1 line
2.43.0
Reviewed-by on v4 2/2
#3 lore raw

Re: [PATCH v4 2/2] livepatch: Convert timeouts to secs_to_jiffies()

Le 18/12/2024 à 00:09, Easwar Hariharan a écrit :

Quoted 14 lines

Commit b35108a51cf7 ("jiffies: Define secs_to_jiffies()") introduced secs_to_jiffies(). As the value here is a multiple of 1000, use secs_to_jiffies() instead of msecs_to_jiffies to avoid the multiplication.

This is converted using scripts/coccinelle/misc/secs_to_jiffies.cocci with the following Coccinelle rules:

@@ constant C; @@

- msecs_to_jiffies(C * 1000)
+ secs_to_jiffies(C)

@@ constant C; @@

Quoted 7 lines

- msecs_to_jiffies(C * MSEC_PER_SEC)
+ secs_to_jiffies(C)

While here, replace the schedule_delayed_work() call with a 0 timeout with an immediate schedule_work() call.

Quoted 78 lines
---
  samples/livepatch/livepatch-callbacks-busymod.c |  3 +--
  samples/livepatch/livepatch-shadow-fix1.c       |  3 +--
  samples/livepatch/livepatch-shadow-mod.c        | 15 +++++----------
  3 files changed, 7 insertions(+), 14 deletions(-)
samples/livepatch/livepatch-callbacks-busymod.c +1 -2
index 378e2d40271a..0220f7715fcc 100644
@@ -44,8 +44,7 @@ static void busymod_work_func(struct work_struct *work)
  static int livepatch_callbacks_mod_init(void)
  {
  	pr_info("%s\n", __func__);
-	schedule_delayed_work(&work,
-		msecs_to_jiffies(1000 * 0));
+	schedule_work(&work);
  	return 0;
  }
 
samples/livepatch/livepatch-shadow-fix1.c +1 -2
index 6701641bf12d..f3f153895d6c 100644
@@ -72,8 +72,7 @@ static struct dummy *livepatch_fix1_dummy_alloc(void)
  	if (!d)
  		return NULL;
 
-	d->jiffies_expire = jiffies +
-		msecs_to_jiffies(1000 * EXPIRE_PERIOD);
+	d->jiffies_expire = jiffies + secs_to_jiffies(EXPIRE_PERIOD);
 
  	/*
  	 * Patch: save the extra memory location into a SV_LEAK shadow
samples/livepatch/livepatch-shadow-mod.c +5 -10
index 7e753b0d2fa6..5d83ad5a8118 100644
@@ -101,8 +101,7 @@ static __used noinline struct dummy *dummy_alloc(void)
  	if (!d)
  		return NULL;
 
-	d->jiffies_expire = jiffies +
-		msecs_to_jiffies(1000 * EXPIRE_PERIOD);
+	d->jiffies_expire = jiffies + secs_to_jiffies(EXPIRE_PERIOD);
 
  	/* Oops, forgot to save leak! */
  	leak = kzalloc(sizeof(*leak), GFP_KERNEL);
@@ -152,8 +151,7 @@ static void alloc_work_func(struct work_struct *work)
  	list_add(&d->list, &dummy_list);
  	mutex_unlock(&dummy_list_mutex);
 
-	schedule_delayed_work(&alloc_dwork,
-		msecs_to_jiffies(1000 * ALLOC_PERIOD));
+	schedule_delayed_work(&alloc_dwork, secs_to_jiffies(ALLOC_PERIOD));
  }
 
  /*
@@ -184,16 +182,13 @@ static void cleanup_work_func(struct work_struct *work)
  	}
  	mutex_unlock(&dummy_list_mutex);
 
-	schedule_delayed_work(&cleanup_dwork,
-		msecs_to_jiffies(1000 * CLEANUP_PERIOD));
+	schedule_delayed_work(&cleanup_dwork, secs_to_jiffies(CLEANUP_PERIOD));
  }
 
  static int livepatch_shadow_mod_init(void)
  {
-	schedule_delayed_work(&alloc_dwork,
-		msecs_to_jiffies(1000 * ALLOC_PERIOD));
-	schedule_delayed_work(&cleanup_dwork,
-		msecs_to_jiffies(1000 * CLEANUP_PERIOD));
+	schedule_delayed_work(&alloc_dwork, secs_to_jiffies(ALLOC_PERIOD));
+	schedule_delayed_work(&cleanup_dwork, secs_to_jiffies(CLEANUP_PERIOD));
 
  	return 0;
  }
maintainer
#4 lore raw

Re: [PATCH v4 2/2] livepatch: Convert timeouts to secs_to_jiffies()

In reply to Easwar Hariharan
Quoted 23 lines · Easwar Hariharan

Commit b35108a51cf7 ("jiffies: Define secs_to_jiffies()") introduced secs_to_jiffies(). As the value here is a multiple of 1000, use secs_to_jiffies() instead of msecs_to_jiffies to avoid the multiplication.

This is converted using scripts/coccinelle/misc/secs_to_jiffies.cocci with the following Coccinelle rules:

@@ constant C; @@

- msecs_to_jiffies(C * 1000)
+ secs_to_jiffies(C)

@@ constant C; @@

- msecs_to_jiffies(C * MSEC_PER_SEC)
+ secs_to_jiffies(C)

While here, replace the schedule_delayed_work() call with a 0 timeout with an immediate schedule_work() call.

samples/livepatch/livepatch-callbacks-busymod.c static void busymod_work_func(struct work_struct *work) · line 47

Quoted 6 lines
samples/livepatch/livepatch-callbacks-busymod.c +1 -2
@@ -44,8 +44,7 @@ static void busymod_work_func(struct work_struct *work)
 static int livepatch_callbacks_mod_init(void)
 {
 	pr_info("%s\n", __func__);
-	schedule_delayed_work(&work,
-		msecs_to_jiffies(1000 * 0));
+	schedule_work(&work);

Is it safe to use schedule_work() for struct delayed_work?

It might work in theory but I do not feel comfortable with it. Also I would expect a compiler warning.

If you really want to use schedule_work() then please also define the structure with DECLARE_WORK()
and use cancel_work_sync() in livepatch_callbacks_mod_exit().

Best Regards,
Petr

#5 lore raw

Re: [PATCH v4 2/2] livepatch: Convert timeouts to secs_to_jiffies()

Le 18/12/2024 à 09:38, Petr Mladek a écrit :

Quoted 21 lines · Easwar Hariharan
Quoted 20 lines

Commit b35108a51cf7 ("jiffies: Define secs_to_jiffies()") introduced secs_to_jiffies(). As the value here is a multiple of 1000, use secs_to_jiffies() instead of msecs_to_jiffies to avoid the multiplication.

This is converted using scripts/coccinelle/misc/secs_to_jiffies.cocci with the following Coccinelle rules:

@@ constant C; @@

- msecs_to_jiffies(C * 1000)
+ secs_to_jiffies(C)

@@ constant C; @@

- msecs_to_jiffies(C * MSEC_PER_SEC)
+ secs_to_jiffies(C)

While here, replace the schedule_delayed_work() call with a 0 timeout with an immediate schedule_work() call.

Quoted 11 lines

samples/livepatch/livepatch-callbacks-busymod.c static void busymod_work_func(struct work_struct *work) · line 47

Quoted 9 lines
samples/livepatch/livepatch-callbacks-busymod.c +1 -2
@@ -44,8 +44,7 @@ static void busymod_work_func(struct work_struct *work)
  static int livepatch_callbacks_mod_init(void)
  {
  	pr_info("%s\n", __func__);
-	schedule_delayed_work(&work,
-		msecs_to_jiffies(1000 * 0));
+	schedule_work(&work);

Is it safe to use schedule_work() for struct delayed_work?

Should be, but you are right it should then be a standard work not a delayed work.

So probably the easiest is to keep

schedule_delayed_work(&work, 0)

And eventually changing it to a not delayed work could be a follow-up patch.

Quoted 3 lines

It might work in theory but I do not feel comfortable with it. Also I would expect a compiler warning.

__queue_delayed_work() does :

	if (!delay) {
		__queue_work(cpu, wq, &dwork->work);
		return;
	}
Quoted 7 lines

If you really want to use schedule_work() then please also define the structure with DECLARE_WORK()
and use cancel_work_sync() in livepatch_callbacks_mod_exit().

Best Regards,
Petr

#6 lore raw

Re: [PATCH v4 2/2] livepatch: Convert timeouts to secs_to_jiffies()

Quoted 42 lines · Christophe Leroy

Le 18/12/2024 à 09:38, Petr Mladek a écrit :

Quoted 23 lines · Easwar Hariharan
Quoted 22 lines

Commit b35108a51cf7 ("jiffies: Define secs_to_jiffies()") introduced secs_to_jiffies(). As the value here is a multiple of 1000, use secs_to_jiffies() instead of msecs_to_jiffies to avoid the multiplication.

This is converted using scripts/coccinelle/misc/secs_to_jiffies.cocci with
the following Coccinelle rules:

@@ constant C; @@

- msecs_to_jiffies(C * 1000)
+ secs_to_jiffies(C)

@@ constant C; @@

- msecs_to_jiffies(C * MSEC_PER_SEC)
+ secs_to_jiffies(C)

While here, replace the schedule_delayed_work() call with a 0 timeout with an immediate schedule_work() call.

Quoted 12 lines

samples/livepatch/livepatch-callbacks-busymod.c static void busymod_work_func(struct work_struct · line 48

Quoted 10 lines
samples/livepatch/livepatch-callbacks-busymod.c +1 -2
@@ -44,8 +44,7 @@ static void busymod_work_func(struct work_struct
 *work)
   static int livepatch_callbacks_mod_init(void)
   {
       pr_info("%s\n", __func__);
-    schedule_delayed_work(&work,
-        msecs_to_jiffies(1000 * 0));
+    schedule_work(&work);

Is it safe to use schedule_work() for struct delayed_work?

Should be, but you are right it should then be a standard work not a delayed work.

Quoted 8 lines

So probably the easiest is to keep

    schedule_delayed_work(&work, 0)

And eventually changing it to a not delayed work could be a follow-up patch.

Quoted 1 line

Thanks for the catch, Petr! This suggestion would effectively revert this patch to the v3 version, albeit with some extra explanation in the commit message. I'd propose just keeping the v3 in the next branch where it is.

Andrew, Petr, Christophe, what do you think?

maintainer
#7 lore raw

Re: [PATCH v4 2/2] livepatch: Convert timeouts to secs_to_jiffies()

Quoted 52 lines · Easwar Hariharan
Quoted 42 lines · Christophe Leroy

Le 18/12/2024 à 09:38, Petr Mladek a écrit :

Quoted 23 lines · Easwar Hariharan
Quoted 22 lines

Commit b35108a51cf7 ("jiffies: Define secs_to_jiffies()") introduced secs_to_jiffies(). As the value here is a multiple of 1000, use secs_to_jiffies() instead of msecs_to_jiffies to avoid the multiplication.

This is converted using scripts/coccinelle/misc/secs_to_jiffies.cocci with
the following Coccinelle rules:

@@ constant C; @@

- msecs_to_jiffies(C * 1000)
+ secs_to_jiffies(C)

@@ constant C; @@

- msecs_to_jiffies(C * MSEC_PER_SEC)
+ secs_to_jiffies(C)

While here, replace the schedule_delayed_work() call with a 0 timeout with an immediate schedule_work() call.

Quoted 12 lines

samples/livepatch/livepatch-callbacks-busymod.c static void busymod_work_func(struct work_struct · line 48

Quoted 10 lines
samples/livepatch/livepatch-callbacks-busymod.c +1 -2
@@ -44,8 +44,7 @@ static void busymod_work_func(struct work_struct
 *work)
   static int livepatch_callbacks_mod_init(void)
   {
       pr_info("%s\n", __func__);
-    schedule_delayed_work(&work,
-        msecs_to_jiffies(1000 * 0));
+    schedule_work(&work);

Is it safe to use schedule_work() for struct delayed_work?

Should be, but you are right it should then be a standard work not a delayed work.

Quoted 8 lines

So probably the easiest is to keep

    schedule_delayed_work(&work, 0)

And eventually changing it to a not delayed work could be a follow-up patch.

Quoted 1 line
Quoted 6 lines

Thanks for the catch, Petr! This suggestion would effectively revert this patch to the v3 version, albeit with some extra explanation in the commit message. I'd propose just keeping the v3 in the next branch where it is.

Andrew, Petr, Christophe, what do you think?

I am fine with keeping v3 in next.

Best Regards,
Petr