netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] tipc: Replace msecs_to_jiffies() with secs_to_jiffies()
@ 2025-04-26 10:04 Thorsten Blum
  2025-04-28  2:31 ` Tung Quang Nguyen
  0 siblings, 1 reply; 4+ messages in thread
From: Thorsten Blum @ 2025-04-26 10:04 UTC (permalink / raw)
  To: Jon Maloy, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Simon Horman
  Cc: Thorsten Blum, netdev, tipc-discussion, linux-kernel

Use secs_to_jiffies() instead of msecs_to_jiffies() and avoid scaling
'delay' to milliseconds in tipc_crypto_rekeying_sched(). Compared to
msecs_to_jiffies(), secs_to_jiffies() expands to simpler code and
reduces the size of 'tipc.ko'.

Remove unnecessary parentheses around the local variable 'now'.

No functional changes intended.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
 net/tipc/crypto.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/net/tipc/crypto.c b/net/tipc/crypto.c
index c524421ec652..45edb29b6bd7 100644
--- a/net/tipc/crypto.c
+++ b/net/tipc/crypto.c
@@ -41,10 +41,10 @@
 #include "msg.h"
 #include "bcast.h"
 
-#define TIPC_TX_GRACE_PERIOD	msecs_to_jiffies(5000) /* 5s */
-#define TIPC_TX_LASTING_TIME	msecs_to_jiffies(10000) /* 10s */
-#define TIPC_RX_ACTIVE_LIM	msecs_to_jiffies(3000) /* 3s */
-#define TIPC_RX_PASSIVE_LIM	msecs_to_jiffies(15000) /* 15s */
+#define TIPC_TX_GRACE_PERIOD	secs_to_jiffies(5)
+#define TIPC_TX_LASTING_TIME	secs_to_jiffies(10)
+#define TIPC_RX_ACTIVE_LIM	secs_to_jiffies(3)
+#define TIPC_RX_PASSIVE_LIM	secs_to_jiffies(15)
 
 #define TIPC_MAX_TFMS_DEF	10
 #define TIPC_MAX_TFMS_LIM	1000
@@ -2348,7 +2348,7 @@ static void tipc_crypto_work_rx(struct work_struct *work)
 	struct delayed_work *dwork = to_delayed_work(work);
 	struct tipc_crypto *rx = container_of(dwork, struct tipc_crypto, work);
 	struct tipc_crypto *tx = tipc_net(rx->net)->crypto_tx;
-	unsigned long delay = msecs_to_jiffies(5000);
+	unsigned long delay = secs_to_jiffies(5);
 	bool resched = false;
 	u8 key;
 	int rc;
@@ -2418,8 +2418,8 @@ void tipc_crypto_rekeying_sched(struct tipc_crypto *tx, bool changed,
 	}
 
 	if (tx->rekeying_intv || now) {
-		delay = (now) ? 0 : tx->rekeying_intv * 60 * 1000;
-		queue_delayed_work(tx->wq, &tx->work, msecs_to_jiffies(delay));
+		delay = now ? 0 : tx->rekeying_intv * 60;
+		queue_delayed_work(tx->wq, &tx->work, secs_to_jiffies(delay));
 	}
 }
 
-- 
2.49.0


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

* RE: [PATCH net-next] tipc: Replace msecs_to_jiffies() with secs_to_jiffies()
  2025-04-26 10:04 [PATCH net-next] tipc: Replace msecs_to_jiffies() with secs_to_jiffies() Thorsten Blum
@ 2025-04-28  2:31 ` Tung Quang Nguyen
  2025-04-28 13:23   ` Thorsten Blum
  0 siblings, 1 reply; 4+ messages in thread
From: Tung Quang Nguyen @ 2025-04-28  2:31 UTC (permalink / raw)
  To: Thorsten Blum
  Cc: netdev@vger.kernel.org, tipc-discussion@lists.sourceforge.net,
	linux-kernel@vger.kernel.org, Jon Maloy, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman

>Subject: [PATCH net-next] tipc: Replace msecs_to_jiffies() with secs_to_jiffies()
This subject is confusing because we still use msecs_to_jiffies() for seconds-to-jiffies conversion in many other places, not just in crypto.c

>Use secs_to_jiffies() instead of msecs_to_jiffies() and avoid scaling 'delay' to
>milliseconds in tipc_crypto_rekeying_sched(). Compared to msecs_to_jiffies(),
>secs_to_jiffies() expands to simpler code and reduces the size of 'tipc.ko'.
I observed an opposite result after applying your patch, an increasement of 320 bytes.
Before patch:
969392 Apr 28 08:53 tipc.ko

After patch:
969712 Apr 28 09:11 tipc.ko

So, your patch is not necessary.

>Remove unnecessary parentheses around the local variable 'now'.
>
>No functional changes intended.
>
>Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
>---
> net/tipc/crypto.c | 14 +++++++-------
> 1 file changed, 7 insertions(+), 7 deletions(-)
>
>diff --git a/net/tipc/crypto.c b/net/tipc/crypto.c index
>c524421ec652..45edb29b6bd7 100644
>--- a/net/tipc/crypto.c
>+++ b/net/tipc/crypto.c
>@@ -41,10 +41,10 @@
> #include "msg.h"
> #include "bcast.h"
>
>-#define TIPC_TX_GRACE_PERIOD	msecs_to_jiffies(5000) /* 5s */
>-#define TIPC_TX_LASTING_TIME	msecs_to_jiffies(10000) /* 10s */
>-#define TIPC_RX_ACTIVE_LIM	msecs_to_jiffies(3000) /* 3s */
>-#define TIPC_RX_PASSIVE_LIM	msecs_to_jiffies(15000) /* 15s */
>+#define TIPC_TX_GRACE_PERIOD	secs_to_jiffies(5)
>+#define TIPC_TX_LASTING_TIME	secs_to_jiffies(10)
>+#define TIPC_RX_ACTIVE_LIM	secs_to_jiffies(3)
>+#define TIPC_RX_PASSIVE_LIM	secs_to_jiffies(15)
>
> #define TIPC_MAX_TFMS_DEF	10
> #define TIPC_MAX_TFMS_LIM	1000
>@@ -2348,7 +2348,7 @@ static void tipc_crypto_work_rx(struct work_struct
>*work)
> 	struct delayed_work *dwork = to_delayed_work(work);
> 	struct tipc_crypto *rx = container_of(dwork, struct tipc_crypto, work);
> 	struct tipc_crypto *tx = tipc_net(rx->net)->crypto_tx;
>-	unsigned long delay = msecs_to_jiffies(5000);
>+	unsigned long delay = secs_to_jiffies(5);
> 	bool resched = false;
> 	u8 key;
> 	int rc;
>@@ -2418,8 +2418,8 @@ void tipc_crypto_rekeying_sched(struct tipc_crypto
>*tx, bool changed,
> 	}
>
> 	if (tx->rekeying_intv || now) {
>-		delay = (now) ? 0 : tx->rekeying_intv * 60 * 1000;
>-		queue_delayed_work(tx->wq, &tx->work,
>msecs_to_jiffies(delay));
>+		delay = now ? 0 : tx->rekeying_intv * 60;
>+		queue_delayed_work(tx->wq, &tx->work,
>secs_to_jiffies(delay));
> 	}
> }
>
>--
>2.49.0
>


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

* Re: [PATCH net-next] tipc: Replace msecs_to_jiffies() with secs_to_jiffies()
  2025-04-28  2:31 ` Tung Quang Nguyen
@ 2025-04-28 13:23   ` Thorsten Blum
  2025-04-28 13:42     ` Tung Quang Nguyen
  0 siblings, 1 reply; 4+ messages in thread
From: Thorsten Blum @ 2025-04-28 13:23 UTC (permalink / raw)
  To: Tung Quang Nguyen
  Cc: netdev@vger.kernel.org, tipc-discussion@lists.sourceforge.net,
	linux-kernel@vger.kernel.org, Jon Maloy, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman

On 28. Apr 2025, at 04:31, Tung Quang Nguyen wrote:
>> Use secs_to_jiffies() instead of msecs_to_jiffies() and avoid scaling 'delay' to
>> milliseconds in tipc_crypto_rekeying_sched(). Compared to msecs_to_jiffies(),
>> secs_to_jiffies() expands to simpler code and reduces the size of 'tipc.ko'.
> I observed an opposite result after applying your patch, an increasement of 320 bytes.
> Before patch:
> 969392 Apr 28 08:53 tipc.ko
> 
> After patch:
> 969712 Apr 28 09:11 tipc.ko

Which architecture and config did you use?

For x86_64 using LLVM, defconfig, and CONFIG_TIPC=m I get 929960 bytes
before and 929864 bytes after my patch, so 96 bytes less than before.

For arm64 using LLVM, defconfig, and CONFIG_TIPC=m, I get 8005616 bytes
before and 8005304 bytes after my patch, so 312 bytes less than before.

Thanks,
Thorsten


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

* Re: [PATCH net-next] tipc: Replace msecs_to_jiffies() with secs_to_jiffies()
  2025-04-28 13:23   ` Thorsten Blum
@ 2025-04-28 13:42     ` Tung Quang Nguyen
  0 siblings, 0 replies; 4+ messages in thread
From: Tung Quang Nguyen @ 2025-04-28 13:42 UTC (permalink / raw)
  To: Thorsten Blum
  Cc: netdev@vger.kernel.org, tipc-discussion@lists.sourceforge.net,
	linux-kernel@vger.kernel.org, Jon Maloy, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman

> Which architecture and config did you use?
It is x86_64, gcc, CONFIG_TIPC=m, CONFIG_TIPC_CRYPTO=y


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

end of thread, other threads:[~2025-04-28 13:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-26 10:04 [PATCH net-next] tipc: Replace msecs_to_jiffies() with secs_to_jiffies() Thorsten Blum
2025-04-28  2:31 ` Tung Quang Nguyen
2025-04-28 13:23   ` Thorsten Blum
2025-04-28 13:42     ` Tung Quang Nguyen

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).