Skip to contentSkip to conversation

Converge on using secs_to_jiffies() part two

PATCH Applied Easwar Hariharan 5 participants 7 messages Jul 7, 2025 – Jul 10, 2025

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

v2 cover Converge on using secs_to_jiffies() part two

This is the second series (part 1*) that converts users of msecs_to_jiffies() that either use the multiply pattern of either of:
- msecs_to_jiffies(N*1000) or
- msecs_to_jiffies(N*MSEC_PER_SEC)

where N is a constant or an expression, to avoid the multiplication.

The conversion is made with Coccinelle with the secs_to_jiffies() script in scripts/coccinelle/misc. Attention is paid to what the best change can be rather than restricting to what the tool provides.

This series is based on net-next.

* https://lore.kernel.org/all/20241212-netdev-converge-secs-to-jiffies-v4-0-6dac97a6d6ab@linux.microsoft.com/

---
Changes in v2:
- Implemented report mode for the secs_to_jiffies coccicheck script (Jakub), patch has been queued by Andrew Morton in mm-nonmm-unstable
- Link: https://web.git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git/commit/?h=mm-nonmm-unstable&id=a01189aaf16e8d8d619067939ea21ea97a279864
- Drop change to netfilter already merged upstream: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=f4293c2baf6faa5f1a1638bcce698ed88d0d396e
- Link to v1: https://lore.kernel.org/r/20250219-netdev-secs-to-jiffies-part-2-v1-0-c484cc63611b@linux.microsoft.com

---
Easwar Hariharan (2):
net/smc: convert timeouts to secs_to_jiffies()
net: ipconfig: convert timeouts to secs_to_jiffies()

 net/ipv4/ipconfig.c | 6 +++---
 net/smc/af_smc.c    | 3 +--
 2 files changed, 4 insertions(+), 5 deletions(-)

---
base-commit: 6b9fd8857b9fc4dd62e7cd300327f0e48dd76642
change-id: 20250128-netdev-secs-to-jiffies-part-2-8f0d2535096a

Best regards,

Signature · 1 line
Easwar Hariharan <[email protected]>
#1 lore raw

PATCH v2 1/2 net/smc: convert timeouts to secs_to_jiffies()

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:

@depends on patch@
expression E;
@@

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

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

---
 net/smc/af_smc.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
net/smc/af_smc.c +1 -2
index 8d56e4db63e041724f156aa3ab30bab745a15bad..bdbaad17f98012c10d0bbc721c80d4c5ae4fb220 100644
@@ -2735,8 +2735,7 @@ int smc_accept(struct socket *sock, struct socket *new_sock,
 
 	if (lsmc->sockopt_defer_accept && !(arg->flags & O_NONBLOCK)) {
 		/* wait till data arrives on the socket */
-		timeo = msecs_to_jiffies(lsmc->sockopt_defer_accept *
-								MSEC_PER_SEC);
+		timeo = secs_to_jiffies(lsmc->sockopt_defer_accept);
 		if (smc_sk(nsk)->use_fallback) {
 			struct sock *clcsk = smc_sk(nsk)->clcsock->sk;
 
Signature · 1 line
2.43.0
maintainer Reviewed-by on v2 1/2
#2 lore raw

Re: [PATCH net-next v2 1/2] net/smc: convert timeouts to secs_to_jiffies()

Quoted 17 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:

@depends on patch@
expression E;
@@

(quoted diff) +2 -2
-msecs_to_jiffies(E * 1000)
+secs_to_jiffies(E)
 
-msecs_to_jiffies(E * MSEC_PER_SEC)
+secs_to_jiffies(E)
Quoted 1 line

Best regards,
Dust

maintainer
#3 lore raw

Re: [PATCH net-next v2 1/2] net/smc: convert timeouts to secs_to_jiffies()

In reply to Easwar Hariharan
Quoted 28 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:

@depends on patch@
expression E;
@@

(quoted diff) +2 -2
-msecs_to_jiffies(E * 1000)
+secs_to_jiffies(E)
 
-msecs_to_jiffies(E * MSEC_PER_SEC)
+secs_to_jiffies(E)
---
  net/smc/af_smc.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
net/smc/af_smc.c +0 -0
index 8d56e4db63e041724f156aa3ab30bab745a15bad..bdbaad17f98012c10d0bbc721c80d4c5ae4fb220 100644

net/smc/af_smc.c int smc_accept(struct socket *sock, struct socket *new_sock, · line 2741

Quoted 9 lines
net/smc/af_smc.c +1 -2
@@ -2735,8 +2735,7 @@ int smc_accept(struct socket *sock, struct socket *new_sock,
 
  	if (lsmc->sockopt_defer_accept && !(arg->flags & O_NONBLOCK)) {
  		/* wait till data arrives on the socket */
-		timeo = msecs_to_jiffies(lsmc->sockopt_defer_accept *
-								MSEC_PER_SEC);
+		timeo = secs_to_jiffies(lsmc->sockopt_defer_accept);
  		if (smc_sk(nsk)->use_fallback) {
  			struct sock *clcsk = smc_sk(nsk)->clcsock->sk;
 

Reviewed-by: Sidraya Jayagond <[email protected]>

Reviewed-by on v2 1/2
#4 lore raw

Re: [PATCH net-next v2 1/2] net/smc: convert timeouts to secs_to_jiffies()

In reply to Easwar Hariharan
Quoted 28 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:

@depends on patch@
expression E;
@@

(quoted diff) +2 -2
-msecs_to_jiffies(E * 1000)
+secs_to_jiffies(E)
 
-msecs_to_jiffies(E * MSEC_PER_SEC)
+secs_to_jiffies(E)
---
 net/smc/af_smc.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
net/smc/af_smc.c +0 -0
index 8d56e4db63e041724f156aa3ab30bab745a15bad..bdbaad17f98012c10d0bbc721c80d4c5ae4fb220 100644

net/smc/af_smc.c int smc_accept(struct socket *sock, struct socket *new_sock, · line 2741

Quoted 9 lines
net/smc/af_smc.c +1 -2
@@ -2735,8 +2735,7 @@ int smc_accept(struct socket *sock, struct socket *new_sock,
 
 	if (lsmc->sockopt_defer_accept && !(arg->flags & O_NONBLOCK)) {
 		/* wait till data arrives on the socket */
-		timeo = msecs_to_jiffies(lsmc->sockopt_defer_accept *
-								MSEC_PER_SEC);
+		timeo = secs_to_jiffies(lsmc->sockopt_defer_accept);
 		if (smc_sk(nsk)->use_fallback) {
 			struct sock *clcsk = smc_sk(nsk)->clcsock->sk;
 

LGTM.

#5 lore raw

PATCH v2 2/2 net: ipconfig: 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:

@depends on patch@
expression E;
@@

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

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

While here, manually convert a couple timeouts denominated in seconds

---
 net/ipv4/ipconfig.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
net/ipv4/ipconfig.c +3 -3
index c56b6fe6f0d771e9275bb66c159d9abb330bdf4c..22a7889876c1cf7d5233fe8a0ee12e134b20c1cd 100644
@@ -274,9 +274,9 @@ static int __init ic_open_devs(void)
 
 	/* wait for a carrier on at least one device */
 	start = jiffies;
-	next_msg = start + msecs_to_jiffies(20000);
+	next_msg = start + secs_to_jiffies(20);
 	while (time_before(jiffies, start +
-			   msecs_to_jiffies(carrier_timeout * 1000))) {
+			   secs_to_jiffies(carrier_timeout))) {
 		int wait, elapsed;
 
 		rtnl_lock();
@@ -295,7 +295,7 @@ static int __init ic_open_devs(void)
 		elapsed = jiffies_to_msecs(jiffies - start);
 		wait = (carrier_timeout * 1000 - elapsed + 500) / 1000;
 		pr_info("Waiting up to %d more seconds for network.\n", wait);
-		next_msg = jiffies + msecs_to_jiffies(20000);
+		next_msg = jiffies + secs_to_jiffies(20);
 	}
 have_carrier:
 
Signature · 1 line
2.43.0
#6 lore raw
In reply to Easwar Hariharan
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Mon, 07 Jul 2025 15:03:31 -0700 you wrote:

This is the second series (part 1*) that converts users of msecs_to_jiffies() that either use the multiply pattern of either of:
- msecs_to_jiffies(N*1000) or
- msecs_to_jiffies(N*MSEC_PER_SEC)

where N is a constant or an expression, to avoid the multiplication.

[...]

Here is the summary with links:
- [net-next,v2,1/2] net/smc: convert timeouts to secs_to_jiffies()

    https://git.kernel.org/netdev/net-next/c/4814f9110ec6
  - [net-next,v2,2/2] net: ipconfig: convert timeouts to secs_to_jiffies()
    https://git.kernel.org/netdev/net-next/c/31326d98416e

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html