Converge on secs_to_jiffies()
v3 cover Converge on secs_to_jiffies()
There are ~1150 call sites for msecs_to_jiffies() that:
- Use a multiplier of 1000, or MSEC_PER_SEC, or
- have timeouts that are denominated in seconds, i.e. end in 000
There are yet more sites that use (secs * HZ). Provide secs_to_jiffies() as a new member of the *_to_jiffies() family and convert a few instances as a first user.
---
changelog:
v3:
- Pickup Reviewed-by tag from Luiz Augusto von Dentz
- Add kernel doc comment for secs_to_jiffies() (tglx)
- secs_to_jiffies() is defined as a macro rather than a static inline
function due to its potential usage in struct initializers, where it
wouldn't work per Geert (documentation in changelog requested per tglx)
v2: https://lore.kernel.org/r/20241028-open-coded-timeouts-v2-0-c7294bb845a1@linux.microsoft.com
- Add a cover letter
- Define secs_to_jiffies(s) as (s * HZ) instead of msecs_to_jiffies(s * MSEC_PER_SEC) (Anna-Maria)
v1: https://lore.kernel.org/all/[email protected]/
- Move secs_to_jiffies in include/linux/jiffies.h
- Use secs_to_jiffies in drivers/hv
RFC: https://lore.kernel.org/all/[email protected]/
- Convert open coded timeouts (secs * HZ) in drivers/hv to msecs_to_jiffies()
---
Easwar Hariharan (2):
jiffies: Define secs_to_jiffies()
drivers: hv: Convert open-coded timeouts to secs_to_jiffies()
drivers/hv/hv_balloon.c | 9 +++++---- drivers/hv/hv_kvp.c | 4 ++-- drivers/hv/hv_snapshot.c | 3 ++- drivers/hv/vmbus_drv.c | 2 +- include/linux/jiffies.h | 12 ++++++++++++ net/bluetooth/hci_event.c | 2 -- 6 files changed, 22 insertions(+), 10 deletions(-)
---
base-commit: 81983758430957d9a5cb3333fe324fd70cf63e7e
change-id: 20241028-open-coded-timeouts-6dc7cbb6572d
Best regards,
Signature · 1 line
Easwar Hariharan <[email protected]>
PATCH v3 1/2 jiffies: Define secs_to_jiffies()
secs_to_jiffies() is defined in hci_event.c and cannot be reused by other call sites. Hoist it into the core code to allow conversion of the ~1150 usages of msecs_to_jiffies() that either:
- use a multiplier value of 1000 or equivalently MSEC_PER_SEC, or
- have timeouts that are denominated in seconds (i.e. end in 000)
This will also allow conversion of yet more sites that use (sec * HZ) directly, and improve their readability.
TO: K. Y. Srinivasan <[email protected]>
TO: Haiyang Zhang <[email protected]>
TO: Wei Liu <[email protected]>
TO: Dexuan Cui <[email protected]>
TO: [email protected]
TO: Anna-Maria Behnsen <[email protected]>
TO: Thomas Gleixner <[email protected]>
TO: Geert Uytterhoeven <[email protected]>
TO: Marcel Holtmann <[email protected]>
TO: Johan Hedberg <[email protected]>
TO: Luiz Augusto von Dentz <[email protected]>
TO: [email protected]
TO: [email protected]
--- include/linux/jiffies.h | 12 ++++++++++++ net/bluetooth/hci_event.c | 2 -- 2 files changed, 12 insertions(+), 2 deletions(-)
include/linux/jiffies.h +12 -0
@@ -526,6 +526,18 @@ static __always_inline unsigned long msecs_to_jiffies(const unsigned int m) } } +/** +* secs_to_jiffies: - convert seconds to jiffies +* @_secs: time in seconds +* +* Conversion is done by simple multiplication with HZ +* secs_to_jiffies() is defined as a macro rather than a static inline +* function due to its potential application in struct initializers. +* +* Return: jiffies value +*/ +#define secs_to_jiffies (_secs) ((_secs) * HZ) +extern unsigned long __usecs_to_jiffies (const unsigned int u);#if !(USEC_PER_SEC %HZ )static inline unsigned long _usecs_to_jiffies (const unsigned int u)
net/bluetooth/hci_event.c +0 -2
@@ -42,8 +42,6 @@#define ZERO_KEY "\x00\x00\x00\x00\x00\x00\x00\x00" \ "\x00\x00\x00\x00\x00\x00\x00\x00" -#define secs_to_jiffies (_secs) msecs_to_jiffies((_secs) * 1000) -/* Handle HCI Event packets */ static void *hci_ev_skb_pull(struct hci_dev *hdev, struct sk_buff *skb,
Signature · 1 line
2.34.1
[tip: timers/core] jiffies: Define secs_to_jiffies()
The following commit has been merged into the timers/core branch of tip:
The following commit has been merged into the timers/core branch of tip:
Commit-ID: b35108a51cf7bab58d7eace1267d7965978bcdb8 Gitweb: https://git.kernel.org/tip/b35108a51cf7bab58d7eace1267d7965978bcdb8 Author: Easwar Hariharan <[email protected]> AuthorDate: Wed, 30 Oct 2024 17:47:35 Committer: Thomas Gleixner <[email protected]> CommitterDate: Wed, 30 Oct 2024 19:47:20 +01:00
jiffies: Define secs_to_jiffies()
secs_to_jiffies() is defined in hci_event.c and cannot be reused by other call sites. Hoist it into the core code to allow conversion of the ~1150 usages of msecs_to_jiffies() that either:
- use a multiplier value of 1000 or equivalently MSEC_PER_SEC, or
- have timeouts that are denominated in seconds (i.e. end in 000)
It's implemented as a macro to allow usage in static initializers.
This will also allow conversion of yet more sites that use (sec * HZ) directly, and improve their readability.
--- include/linux/jiffies.h | 13 +++++++++++++ net/bluetooth/hci_event.c | 2 -- 2 files changed, 13 insertions(+), 2 deletions(-)
include/linux/jiffies.h +13 -0
@@ -526,6 +526,19 @@ static __always_inline unsigned long msecs_to_jiffies(const unsigned int m) } } +/** +* secs_to_jiffies: - convert seconds to jiffies +* @_secs: time in seconds +* +* Conversion is done by simple multiplication with HZ +* +* secs_to_jiffies() is defined as a macro rather than a static inline +* function so it can be used in static initializers. +* +* Return: jiffies value +*/ +#define secs_to_jiffies (_secs) ((_secs) * HZ) +extern unsigned long __usecs_to_jiffies (const unsigned int u);#if !(USEC_PER_SEC %HZ )static inline unsigned long _usecs_to_jiffies (const unsigned int u)
net/bluetooth/hci_event.c +0 -2
@@ -42,8 +42,6 @@#define ZERO_KEY "\x00\x00\x00\x00\x00\x00\x00\x00" \ "\x00\x00\x00\x00\x00\x00\x00\x00" -#define secs_to_jiffies (_secs) msecs_to_jiffies((_secs) * 1000) -/* Handle HCI Event packets */ static void *hci_ev_skb_pull(struct hci_dev *hdev, struct sk_buff *skb,
Haiyang Zhang
maintainerRE: [PATCH v3 1/2] jiffies: Define secs_to_jiffies()
In reply to Easwar HariharanQuoted 93 lines
-----Original Message-----
From: Easwar Hariharan <[email protected]>
Sent: Wednesday, October 30, 2024 1:48 PM
To: KY Srinivasan <[email protected]>; Haiyang Zhang <[email protected]>; Wei Liu <[email protected]>; Dexuan Cui <[email protected]>; [email protected]; Anna-Maria Behnsen <[email protected]>; Thomas Gleixner <[email protected]>; Geert Uytterhoeven <[email protected]>; Marcel Holtmann <[email protected]>; Johan Hedberg <[email protected]>; Luiz Augusto von Dentz <[email protected]>; linux- [email protected]; [email protected]; Praveen Kumar <[email protected]>; Naman Jain <[email protected]>
Cc: Michael Kelley <[email protected]>; Easwar Hariharan <[email protected]>; Von Dentz, Luiz <[email protected]>
Subject: [PATCH v3 1/2] jiffies: Definesecs_to_jiffies()
secs_to_jiffies()is defined inhci_event.cand cannot be reused by other call sites. Hoist it into the core code to allow conversion of the ~1150 usages ofmsecs_to_jiffies()that either:
- use a multiplier value of 1000 or equivalentlyMSEC_PER_SEC, or
- have timeouts that are denominated in seconds (i.e. end in 000)This will also allow conversion of yet more sites that use (sec * HZ) directly, and improve their readability.
TO: K. Y. Srinivasan <[email protected]>
TO: Haiyang Zhang <[email protected]>
TO: Wei Liu <[email protected]>
TO: Dexuan Cui <[email protected]>
TO: [email protected]
TO: Anna-Maria Behnsen <[email protected]>
TO: Thomas Gleixner <[email protected]>
TO: Geert Uytterhoeven <[email protected]>
TO: Marcel Holtmann <[email protected]>
TO: Johan Hedberg <[email protected]>
TO: Luiz Augusto von Dentz <[email protected]>
TO: [email protected]
TO: [email protected]Suggested-by Michael Kelley <[email protected]>Reviewed-by Luiz Augusto von Dentz <[email protected]>Signed-off-by Easwar Hariharan <[email protected]>--- include/linux/jiffies.h | 12 ++++++++++++ net/bluetooth/hci_event.c | 2 -- 2 files changed, 12 insertions(+), 2 deletions(-)include/linux/jiffies.h +0
-0index
1220f0fbe5bf9fb6c559b4efd603db3e97db9b65..e17c220ed56e587fd55fb9cf4a133a53588af940100644include/linux/jiffies.h +12
-0@@ -526,6 +526,18 @@ static __always_inline unsigned long msecs_to_jiffies(const unsigned int m) } } +/** +* secs_to_jiffies: - convert seconds to jiffies +* @_secs: time in seconds +* +* Conversion is done by simple multiplication with HZ +* secs_to_jiffies() is defined as a macro rather than a static inline +* function due to its potential application in struct initializers. +* +* Return: jiffies value +*/ +#define secs_to_jiffies (_secs) ((_secs) * HZ) +extern unsigned long __usecs_to_jiffies (const unsigned int u);#if !(USEC_PER_SEC %HZ )static inline unsigned long
_usecs_to_jiffies(const unsigned int u)net/bluetooth/hci_event.c +0
-0index
0bbad90ddd6f87e87c03859bae48a7901d39b634..7b35c58bbbeb79f2b50a02212771fb283ba5643d100644net/bluetooth/hci_event.c +0
-3@@ -42,8 +42,6 @@#define ZERO_KEY "\x00\x00\x00\x00\x00\x00\x00\x00" \ "\x00\x00\x00\x00\x00\x00\x00\x00" -#define secs_to_jiffies (_secs) msecs_to_jiffies((_secs) * 1000) -/* Handle HCI Event packets */ static void *hci_ev_skb_pull(struct hci_dev *hdev, struct sk_buff *skb, --
Quoted 1 line
2.34.1
All looks good.
But can you consider naming the macro as s2jiffy()? Just to be shorter, so after adopting this macro we don't have to split some lines for over 80 characters:)
Thanks,
- Haiyang
Re: [PATCH v3 1/2] jiffies: Define secs_to_jiffies()
Quoted 100 lines · Haiyang Zhang
Quoted 93 lines
-----Original Message-----
From: Easwar Hariharan <[email protected]>
Sent: Wednesday, October 30, 2024 1:48 PM
To: KY Srinivasan <[email protected]>; Haiyang Zhang <[email protected]>; Wei Liu <[email protected]>; Dexuan Cui <[email protected]>; [email protected]; Anna-Maria Behnsen <[email protected]>; Thomas Gleixner <[email protected]>; Geert Uytterhoeven <[email protected]>; Marcel Holtmann <[email protected]>; Johan Hedberg <[email protected]>; Luiz Augusto von Dentz <[email protected]>; linux- [email protected]; [email protected]; Praveen Kumar <[email protected]>; Naman Jain <[email protected]>
Cc: Michael Kelley <[email protected]>; Easwar Hariharan <[email protected]>; Von Dentz, Luiz <[email protected]>
Subject: [PATCH v3 1/2] jiffies: Definesecs_to_jiffies()
secs_to_jiffies()is defined inhci_event.cand cannot be reused by other call sites. Hoist it into the core code to allow conversion of the ~1150 usages ofmsecs_to_jiffies()that either:
- use a multiplier value of 1000 or equivalentlyMSEC_PER_SEC, or
- have timeouts that are denominated in seconds (i.e. end in 000)This will also allow conversion of yet more sites that use (sec * HZ) directly, and improve their readability.
TO: K. Y. Srinivasan <[email protected]>
TO: Haiyang Zhang <[email protected]>
TO: Wei Liu <[email protected]>
TO: Dexuan Cui <[email protected]>
TO: [email protected]
TO: Anna-Maria Behnsen <[email protected]>
TO: Thomas Gleixner <[email protected]>
TO: Geert Uytterhoeven <[email protected]>
TO: Marcel Holtmann <[email protected]>
TO: Johan Hedberg <[email protected]>
TO: Luiz Augusto von Dentz <[email protected]>
TO: [email protected]
TO: [email protected]Suggested-by Michael Kelley <[email protected]>Reviewed-by Luiz Augusto von Dentz <[email protected]>Signed-off-by Easwar Hariharan <[email protected]>--- include/linux/jiffies.h | 12 ++++++++++++ net/bluetooth/hci_event.c | 2 -- 2 files changed, 12 insertions(+), 2 deletions(-)include/linux/jiffies.h +0
-0index
1220f0fbe5bf9fb6c559b4efd603db3e97db9b65..e17c220ed56e587fd55fb9cf4a133a53588af940100644include/linux/jiffies.h +12
-0@@ -526,6 +526,18 @@ static __always_inline unsigned long msecs_to_jiffies(const unsigned int m) } } +/** +* secs_to_jiffies: - convert seconds to jiffies +* @_secs: time in seconds +* +* Conversion is done by simple multiplication with HZ +* secs_to_jiffies() is defined as a macro rather than a static inline +* function due to its potential application in struct initializers. +* +* Return: jiffies value +*/ +#define secs_to_jiffies (_secs) ((_secs) * HZ) +extern unsigned long __usecs_to_jiffies (const unsigned int u);#if !(USEC_PER_SEC %HZ )static inline unsigned long
_usecs_to_jiffies(const unsigned int u)net/bluetooth/hci_event.c +0
-0index
0bbad90ddd6f87e87c03859bae48a7901d39b634..7b35c58bbbeb79f2b50a02212771fb283ba5643d100644net/bluetooth/hci_event.c +0
-3@@ -42,8 +42,6 @@#define ZERO_KEY "\x00\x00\x00\x00\x00\x00\x00\x00" \ "\x00\x00\x00\x00\x00\x00\x00\x00" -#define secs_to_jiffies (_secs) msecs_to_jiffies((_secs) * 1000) -/* Handle HCI Event packets */ static void *hci_ev_skb_pull(struct hci_dev *hdev, struct sk_buff *skb, --Quoted 1 line
2.34.1
All looks good.
But can you consider naming the macro ass2jiffy()? Just to be shorter, so after adopting this macro we don't have to split some lines for over 80 characters:)
Quoted 3 lines
Thanks,
- Haiyang
Thanks for the review! The patch introducing the macro has already been accepted into timers/core in tip[1], so unfortunately I can't make that change anymore. For readability considerations, I also find it better to match the remaining APIs in the jiffies family, i.e. msecs_to_jiffies(), nsecs_to_jiffies(), usecs_to_jiffies().
[1] https://git.kernel.org/tip/b35108a51cf7bab58d7eace1267d7965978bcdb8
Thanks,
Easwar
Haiyang Zhang
maintainerRE: [PATCH v3 1/2] jiffies: Define secs_to_jiffies()
Quoted 137 lines
-----Original Message-----
From: Easwar Hariharan <[email protected]>
Sent: Thursday, October 31, 2024 1:06 PM
To: Haiyang Zhang <[email protected]>; KY Srinivasan <[email protected]>; Wei Liu <[email protected]>; Dexuan Cui <[email protected]>; [email protected]; Anna-Maria Behnsen <[email protected]>; Thomas Gleixner <[email protected]>; Geert Uytterhoeven <[email protected]>; Marcel Holtmann <[email protected]>; Johan Hedberg <[email protected]>; Luiz Augusto von Dentz <[email protected]>; linux- [email protected]; [email protected]; Praveen Kumar <[email protected]>; Naman Jain <[email protected]>
Cc: [email protected]; Michael Kelley <[email protected]>; Von Dentz, Luiz <[email protected]>
Subject: Re: [PATCH v3 1/2] jiffies: Definesecs_to_jiffies()Quoted 8 lines · Haiyang Zhang
Quoted 8 lines
-----Original Message-----
From: Easwar Hariharan <[email protected]>
Sent: Wednesday, October 30, 2024 1:48 PM
To: KY Srinivasan <[email protected]>; Haiyang Zhang <[email protected]>; Wei Liu <[email protected]>; Dexuan Cui <[email protected]>; [email protected]; Anna-MariaBehnsen
Quoted 1 line
Quoted 1 line
<[email protected]>; Thomas Gleixner <[email protected]>;
Geert
Quoted 11 lines
Quoted 11 lines
Uytterhoeven <[email protected]>; Marcel Holtmann <[email protected]>; Johan Hedberg <[email protected]>; Luiz Augusto von Dentz <[email protected]>; linux- [email protected]; [email protected]; Praveen Kumar <[email protected]>; Naman Jain <[email protected]>
Cc: Michael Kelley <[email protected]>; Easwar Hariharan <[email protected]>; Von Dentz, Luiz <[email protected]>
Subject: [PATCH v3 1/2] jiffies: Definesecs_to_jiffies()Quoted 2 lines
Quoted 2 lines
secs_to_jiffies()is defined inhci_event.cand cannot be reused by other call sites. Hoist it into the core code to allow conversion ofthe
Quoted 28 lines
Quoted 28 lines
~1150 usages of
msecs_to_jiffies()that either:
- use a multiplier value of 1000 or equivalentlyMSEC_PER_SEC, or
- have timeouts that are denominated in seconds (i.e. end in 000)This will also allow conversion of yet more sites that use (sec * HZ) directly, and improve their readability.
TO: K. Y. Srinivasan <[email protected]>
TO: Haiyang Zhang <[email protected]>
TO: Wei Liu <[email protected]>
TO: Dexuan Cui <[email protected]>
TO: [email protected]
TO: Anna-Maria Behnsen <[email protected]>
TO: Thomas Gleixner <[email protected]>
TO: Geert Uytterhoeven <[email protected]>
TO: Marcel Holtmann <[email protected]>
TO: Johan Hedberg <[email protected]>
TO: Luiz Augusto von Dentz <[email protected]>
TO: [email protected]
TO: [email protected]Suggested-by Michael Kelley <[email protected]>Reviewed-by Luiz Augusto von Dentz <[email protected]>Signed-off-by Easwar Hariharan <[email protected]>--- include/linux/jiffies.h | 12 ++++++++++++ net/bluetooth/hci_event.c | 2 -- 2 files changed, 12 insertions(+), 2 deletions(-)Quoted 3 lines
Quoted 3 lines
include/linux/jiffies.h +0
-0index
1220f0fbe5bf9fb6c559b4efd603db3e97db9b65..e17c220ed56e587fd55fb9cf4a133a5Quoted 8 lines
Quoted 8 lines
3588af940100644include/linux/jiffies.h +0
-0@@ -526,6 +526,18 @@ static __always_inline unsigned long msecs_to_jiffies(const unsigned int m) } }Quoted 6 lines
include/linux/jiffies.h static __always_inline unsigned long msecs_to_jiffies(const unsigned int m)
Quoted 6 lines
include/linux/jiffies.h +6
-0+/** +* secs_to_jiffies: - convert seconds to jiffies +* @_secs: time in seconds +* +* Conversion is done by simple multiplication with HZ +* secs_to_jiffies() is defined as a macro rather than a static inline
Quoted 4 lines
Quoted 4 lines
include/linux/jiffies.h +4
-0+* function due to its potential application in struct initializers. +* +* Return: jiffies value +*/ Quoted 8 lines
Quoted 8 lines
include/linux/jiffies.h +2
-0+#define secs_to_jiffies (_secs) ((_secs) * HZ) +extern unsigned long __usecs_to_jiffies (const unsigned int u);#if !(USEC_PER_SEC %HZ )static inline unsigned long
_usecs_to_jiffies(const unsigned int u)net/bluetooth/hci_event.c +0
-0index
0bbad90ddd6f87e87c03859bae48a7901d39b634..7b35c58bbbeb79f2b50a02212771fb2Quoted 7 lines
Quoted 7 lines
83ba5643d100644net/bluetooth/hci_event.c +0
-0@@ -42,8 +42,6 @@#define ZERO_KEY "\x00\x00\x00\x00\x00\x00\x00\x00" \ "\x00\x00\x00\x00\x00\x00\x00\x00"Quoted 5 lines
net/bluetooth/hci_event.c
Quoted 5 lines
net/bluetooth/hci_event.c +0
-2-#define secs_to_jiffies (_secs) msecs_to_jiffies((_secs) * 1000) -/* Handle HCI Event packets */ static void *hci_ev_skb_pull(struct hci_dev *hdev, struct sk_buff*skb,
Quoted 4 lines
Quoted 3 lines
--
2.34.1Quoted 8 lines
All looks good.
But can you consider naming the macro ass2jiffy()? Just to be shorter, so after adopting this macro we don't have to split some lines for over 80 characters:)Thanks,
- HaiyangThanks for the review! The patch introducing the macro has already been accepted into timers/core in tip[1], so unfortunately I can't make that change anymore. For readability considerations, I also find it better to match the remaining APIs in the jiffies family, i.e.
msecs_to_jiffies(),nsecs_to_jiffies(),usecs_to_jiffies().
Quoted 9 lines
[1]
https://git.ker/
nel.org%2Ftip%2Fb35108a51cf7bab58d7eace1267d7965978bcdb8&data=05%7C02%7Ch aiyangz%40microsoft.com%7C7d5db079ed124f62ac2a08dcf9ce4b20%7C72f988bf86f1 41af91ab2d7cd011db47%7C1%7C0%7C638659911651280804%7CUnknown%7CTWFpbGZsb3d 8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFp bCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=hz5UtwU9CLw068z4tpr9kPMANntwX58De A5dXi9pqSg%3D&reserved=0
Then, that's fine.
Thanks
- Haiyang
PATCH v3 2/2 drivers: hv: Convert open-coded timeouts to secs_to_jiffies()
In reply to Easwar HariharanWe have several places where timeouts are open-coded as N (seconds) * HZ, but best practice is to use the utility functions from jiffies.h. Convert the timeouts to be compliant. This doesn't fix any bugs, it's a simple code improvement.
TO: "K. Y. Srinivasan" <[email protected]>
TO: Haiyang Zhang <[email protected]>
TO: Wei Liu <[email protected]>
TO: Dexuan Cui <[email protected]>
TO: [email protected]
TO: Anna-Maria Behnsen <[email protected]>
TO: Thomas Gleixner <[email protected]>
TO: Geert Uytterhoeven <[email protected]>
TO: Marcel Holtmann <[email protected]>
TO: Johan Hedberg <[email protected]>
TO: Luiz Augusto von Dentz <[email protected]>
TO: [email protected]
TO: [email protected]
--- drivers/hv/hv_balloon.c | 9 +++++---- drivers/hv/hv_kvp.c | 4 ++-- drivers/hv/hv_snapshot.c | 3 ++- drivers/hv/vmbus_drv.c | 2 +- 4 files changed, 10 insertions(+), 8 deletions(-)
drivers/hv/hv_balloon.c +5 -4
@@ -756,7 +756,7 @@ static void hv_mem_hot_add(unsigned long start, unsigned long size,* adding succeeded, it is ok to proceed even if the memory was * not onlined in time. */ -wait_for_completion_timeout (&dm_device.ol_waitevent,5 *HZ ); +wait_for_completion_timeout (&dm_device.ol_waitevent,secs_to_jiffies (5 ));post_status (&dm_device); } }
@@ -1373,7 +1373,8 @@ static int dm_thread_func(void *dm_dev)struct hv_dynmem_device *dm = dm_dev;while (!kthread_should_stop ()) { -wait_for_completion_interruptible_timeout (&dm_device.config_event,1 *HZ ); +wait_for_completion_interruptible_timeout (&dm_device.config_event, +secs_to_jiffies (1 ));/* * The host expects us to post information on the memory * pressure every second.
@@ -1748,7 +1749,7 @@ static int balloon_connect_vsp(struct hv_device *dev)if (ret) goto out; - t =wait_for_completion_timeout (&dm_device.host_event,5 *HZ ); + t =wait_for_completion_timeout (&dm_device.host_event,secs_to_jiffies (5 ));if (t ==0 ) { ret = -ETIMEDOUT ; goto out;
@@ -1806,7 +1807,7 @@ static int balloon_connect_vsp(struct hv_device *dev)if (ret) goto out; - t =wait_for_completion_timeout (&dm_device.host_event,5 *HZ ); + t =wait_for_completion_timeout (&dm_device.host_event,secs_to_jiffies (5 ));if (t ==0 ) { ret = -ETIMEDOUT ; goto out;
drivers/hv/hv_kvp.c +2 -2
@@ -655,7 +655,7 @@ void hv_kvp_onchannelcallback(void *context)if (host_negotiatied ==NEGO_NOT_STARTED ) { host_negotiatied =NEGO_IN_PROGRESS ;schedule_delayed_work (&kvp_host_handshake_work, -HV_UTIL_NEGO_TIMEOUT *HZ ); +secs_to_jiffies (HV_UTIL_NEGO_TIMEOUT )); }return ; }
@@ -724,7 +724,7 @@ void hv_kvp_onchannelcallback(void *context)*/ schedule_work (&kvp_sendkey_work);schedule_delayed_work (&kvp_timeout_work, -HV_UTIL_TIMEOUT *HZ ); +secs_to_jiffies (HV_UTIL_TIMEOUT ));return ;
drivers/hv/hv_snapshot.c +2 -1
@@ -193,7 +193,8 @@ static void vss_send_op(void) vss_transaction.state =HVUTIL_USERSPACE_REQ ;schedule_delayed_work (&vss_timeout_work, op ==VSS_OP_FREEZE ? -VSS_FREEZE_TIMEOUT *HZ :HV_UTIL_TIMEOUT *HZ ); +secs_to_jiffies (VSS_FREEZE_TIMEOUT ) : +secs_to_jiffies (HV_UTIL_TIMEOUT )); rc =hvutil_transport_send (hvt, vss_msg,sizeof (*vss_msg),NULL );if (rc) {
drivers/hv/vmbus_drv.c +1 -1
@@ -2507,7 +2507,7 @@ static int vmbus_bus_resume(struct device *dev)vmbus_request_offers ();if (wait_for_completion_timeout ( - &vmbus_connection.ready_for_resume_event,10 *HZ ) ==0 ) + &vmbus_connection.ready_for_resume_event,secs_to_jiffies (10 )) ==0 )pr_err ("Some vmbus device is missing after suspending?\n" );/* Reset the event for the next suspend. */
Signature · 1 line
2.34.1
RE: [PATCH v3 2/2] drivers: hv: Convert open-coded timeouts to secs_to_jiffies()
From: Easwar Hariharan <[email protected]> Sent: Wednesday, October 30, 2024 10:48 AM
Quoted 119 lines
We have several places where timeouts are open-coded as N (seconds) * HZ, but best practice is to use the utility functions from
jiffies.h. Convert the timeouts to be compliant. This doesn't fix any bugs, it's a simple code improvement.TO: "K. Y. Srinivasan" <[email protected]>
TO: Haiyang Zhang <[email protected]>
TO: Wei Liu <[email protected]>
TO: Dexuan Cui <[email protected]>
TO: [email protected]
TO: Anna-Maria Behnsen <[email protected]>
TO: Thomas Gleixner <[email protected]>
TO: Geert Uytterhoeven <[email protected]>
TO: Marcel Holtmann <[email protected]>
TO: Johan Hedberg <[email protected]>
TO: Luiz Augusto von Dentz <[email protected]>
TO: [email protected]
TO: [email protected]CC Michael Kelley <[email protected]>Signed-off-by Easwar Hariharan <[email protected]>--- drivers/hv/hv_balloon.c | 9 +++++---- drivers/hv/hv_kvp.c | 4 ++-- drivers/hv/hv_snapshot.c | 3 ++- drivers/hv/vmbus_drv.c | 2 +- 4 files changed, 10 insertions(+), 8 deletions(-)drivers/hv/hv_balloon.c +0
-0index
c38dcdfcb914dcc3515be100cba0beb4a3f9b975..a99112e6f0b8534cf5c8c963e343019061bd34f6100644drivers/hv/hv_balloon.c +5
-4@@ -756,7 +756,7 @@ static void hv_mem_hot_add(unsigned long start, unsigned long size,* adding succeeded, it is ok to proceed even if the memory was * not onlined in time. */ -wait_for_completion_timeout (&dm_device.ol_waitevent,5 *HZ ); +wait_for_completion_timeout (&dm_device.ol_waitevent,secs_to_jiffies (5 ));post_status (&dm_device); } }@@ -1373,7 +1373,8 @@ static int dm_thread_func(void *dm_dev)struct hv_dynmem_device *dm = dm_dev;while (!kthread_should_stop ()) { -wait_for_completion_interruptible_timeout (&dm_device.config_event,1 *HZ ); +wait_for_completion_interruptible_timeout (&dm_device.config_event, +secs_to_jiffies (1 ));/* * The host expects us to post information on the memory * pressure every second. @@ -1748,7 +1749,7 @@ static int balloon_connect_vsp(struct hv_device *dev)if (ret) goto out; - t =wait_for_completion_timeout (&dm_device.host_event,5 *HZ ); + t =wait_for_completion_timeout (&dm_device.host_event,secs_to_jiffies (5 ));if (t ==0 ) { ret = -ETIMEDOUT ; goto out;@@ -1806,7 +1807,7 @@ static int balloon_connect_vsp(struct hv_device *dev)if (ret) goto out; - t =wait_for_completion_timeout (&dm_device.host_event,5 *HZ ); + t =wait_for_completion_timeout (&dm_device.host_event,secs_to_jiffies (5 ));if (t ==0 ) { ret = -ETIMEDOUT ; goto out;drivers/hv/hv_kvp.c +0
-0index
d35b60c0611486c8c909d2f8f7c730ff913df30d..29e01247a0870fdb9eebd92bdd16fd371450240c100644drivers/hv/hv_kvp.c +2
-2@@ -655,7 +655,7 @@ void hv_kvp_onchannelcallback(void *context)if (host_negotiatied ==NEGO_NOT_STARTED ) { host_negotiatied =NEGO_IN_PROGRESS ;schedule_delayed_work (&kvp_host_handshake_work, -HV_UTIL_NEGO_TIMEOUT *HZ ); +secs_to_jiffies (HV_UTIL_NEGO_TIMEOUT )); }return ; }@@ -724,7 +724,7 @@ void hv_kvp_onchannelcallback(void *context)*/ schedule_work (&kvp_sendkey_work);schedule_delayed_work (&kvp_timeout_work, -HV_UTIL_TIMEOUT *HZ ); +secs_to_jiffies (HV_UTIL_TIMEOUT ));return ;drivers/hv/hv_snapshot.c +0
-0index
0d2184be16912559a8cfa784c762e6418ebd3279..86d87486ed40b3ca9f6674650e5a86a7184e2fa6100644drivers/hv/hv_snapshot.c +2
-1@@ -193,7 +193,8 @@ static void vss_send_op(void) vss_transaction.state =HVUTIL_USERSPACE_REQ ;schedule_delayed_work (&vss_timeout_work, op ==VSS_OP_FREEZE ? -VSS_FREEZE_TIMEOUT *HZ :HV_UTIL_TIMEOUT *HZ ); +secs_to_jiffies (VSS_FREEZE_TIMEOUT ) : +secs_to_jiffies (HV_UTIL_TIMEOUT )); rc =hvutil_transport_send (hvt, vss_msg,sizeof (*vss_msg),NULL );if (rc) {drivers/hv/vmbus_drv.c +0
-0index
9b15f7daf5059750e17ea3607b52dee967c1c059..7db30881e83ad4b406413641413d68329fc663e2100644
drivers/hv/vmbus_drv.c static int vmbus_bus_resume(struct device *dev) · line 2513
Quoted 8 lines
drivers/hv/vmbus_drv.c +1
-1@@ -2507,7 +2507,7 @@ static int vmbus_bus_resume(struct device *dev)vmbus_request_offers ();if (wait_for_completion_timeout ( - &vmbus_connection.ready_for_resume_event,10 *HZ ) ==0 ) + &vmbus_connection.ready_for_resume_event,secs_to_jiffies (10 )) ==0 )pr_err ("Some vmbus device is missing after suspending?\n" );/* Reset the event for the next suspend. */
Re: [PATCH v3 2/2] drivers: hv: Convert open-coded timeouts to secs_to_jiffies()
In reply to Easwar HariharanQuoted 5 lines · Easwar Hariharan
We have several places where timeouts are open-coded as N (seconds) * HZ, but best practice is to use the utility functions from
jiffies.h. Convert the timeouts to be compliant. This doesn't fix any bugs, it's a simple code improvement.
Quoted 14 lines
TO: "K. Y. Srinivasan" <[email protected]>
TO: Haiyang Zhang <[email protected]>
TO: Wei Liu <[email protected]>
TO: Dexuan Cui <[email protected]>
TO: [email protected]
TO: Anna-Maria Behnsen <[email protected]>
TO: Thomas Gleixner <[email protected]>
TO: Geert Uytterhoeven <[email protected]>
TO: Marcel Holtmann <[email protected]>
TO: Johan Hedberg <[email protected]>
TO: Luiz Augusto von Dentz <[email protected]>
TO: [email protected]
TO: [email protected]
CC: Michael Kelley <[email protected]>
In the future you can put these items after the --- line, so that they are stripped when the patch is applied.
Quoted 1 line
Signed-off-by Easwar Hariharan <[email protected]>
The first patch is already in.
I applied this patch to hyperv-fixes. Thanks.
Quoted 101 lines
--- drivers/hv/hv_balloon.c | 9 +++++---- drivers/hv/hv_kvp.c | 4 ++-- drivers/hv/hv_snapshot.c | 3 ++- drivers/hv/vmbus_drv.c | 2 +- 4 files changed, 10 insertions(+), 8 deletions(-)drivers/hv/hv_balloon.c +5
-4@@ -756,7 +756,7 @@ static void hv_mem_hot_add(unsigned long start, unsigned long size,* adding succeeded, it is ok to proceed even if the memory was * not onlined in time. */ -wait_for_completion_timeout (&dm_device.ol_waitevent,5 *HZ ); +wait_for_completion_timeout (&dm_device.ol_waitevent,secs_to_jiffies (5 ));post_status (&dm_device); } }@@ -1373,7 +1373,8 @@ static int dm_thread_func(void *dm_dev)struct hv_dynmem_device *dm = dm_dev;while (!kthread_should_stop ()) { -wait_for_completion_interruptible_timeout (&dm_device.config_event,1 *HZ ); +wait_for_completion_interruptible_timeout (&dm_device.config_event, +secs_to_jiffies (1 ));/* * The host expects us to post information on the memory * pressure every second. @@ -1748,7 +1749,7 @@ static int balloon_connect_vsp(struct hv_device *dev)if (ret) goto out; - t =wait_for_completion_timeout (&dm_device.host_event,5 *HZ ); + t =wait_for_completion_timeout (&dm_device.host_event,secs_to_jiffies (5 ));if (t ==0 ) { ret = -ETIMEDOUT ; goto out;@@ -1806,7 +1807,7 @@ static int balloon_connect_vsp(struct hv_device *dev)if (ret) goto out; - t =wait_for_completion_timeout (&dm_device.host_event,5 *HZ ); + t =wait_for_completion_timeout (&dm_device.host_event,secs_to_jiffies (5 ));if (t ==0 ) { ret = -ETIMEDOUT ; goto out;drivers/hv/hv_kvp.c +2
-2@@ -655,7 +655,7 @@ void hv_kvp_onchannelcallback(void *context)if (host_negotiatied ==NEGO_NOT_STARTED ) { host_negotiatied =NEGO_IN_PROGRESS ;schedule_delayed_work (&kvp_host_handshake_work, -HV_UTIL_NEGO_TIMEOUT *HZ ); +secs_to_jiffies (HV_UTIL_NEGO_TIMEOUT )); }return ; }@@ -724,7 +724,7 @@ void hv_kvp_onchannelcallback(void *context)*/ schedule_work (&kvp_sendkey_work);schedule_delayed_work (&kvp_timeout_work, -HV_UTIL_TIMEOUT *HZ ); +secs_to_jiffies (HV_UTIL_TIMEOUT ));return ;drivers/hv/hv_snapshot.c +2
-1@@ -193,7 +193,8 @@ static void vss_send_op(void) vss_transaction.state =HVUTIL_USERSPACE_REQ ;schedule_delayed_work (&vss_timeout_work, op ==VSS_OP_FREEZE ? -VSS_FREEZE_TIMEOUT *HZ :HV_UTIL_TIMEOUT *HZ ); +secs_to_jiffies (VSS_FREEZE_TIMEOUT ) : +secs_to_jiffies (HV_UTIL_TIMEOUT )); rc =hvutil_transport_send (hvt, vss_msg,sizeof (*vss_msg),NULL );if (rc) {drivers/hv/vmbus_drv.c +1
-1@@ -2507,7 +2507,7 @@ static int vmbus_bus_resume(struct device *dev)vmbus_request_offers ();if (wait_for_completion_timeout ( - &vmbus_connection.ready_for_resume_event,10 *HZ ) ==0 ) + &vmbus_connection.ready_for_resume_event,secs_to_jiffies (10 )) ==0 )pr_err ("Some vmbus device is missing after suspending?\n" );/* Reset the event for the next suspend. */ Signature · 2 lines
-- 2.34.1