* [PATCH 1/2] firewire: core: use helper macros instead of direct access to HZ
2025-09-15 2:42 [PATCH 0/2] firewire: core: use helper macro to calculate jiffies count Takashi Sakamoto
@ 2025-09-15 2:42 ` Takashi Sakamoto
2025-09-15 2:42 ` [PATCH 2/2] firewire: core: use helper macro to compare against current jiffies Takashi Sakamoto
2025-09-15 23:20 ` [PATCH 0/2] firewire: core: use helper macro to calculate jiffies count Takashi Sakamoto
2 siblings, 0 replies; 4+ messages in thread
From: Takashi Sakamoto @ 2025-09-15 2:42 UTC (permalink / raw)
To: linux1394-devel; +Cc: linux-kernel
There are some macros available to convert usecs, msecs, and secs into
jiffies count.
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
drivers/firewire/core-card.c | 17 +++++++----------
drivers/firewire/core-cdev.c | 4 ++--
drivers/firewire/core-device.c | 6 +++---
drivers/firewire/core-transaction.c | 4 ++--
drivers/firewire/core.h | 2 ++
5 files changed, 16 insertions(+), 17 deletions(-)
diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
index adb90161c4c6..2541e8bb4b75 100644
--- a/drivers/firewire/core-card.c
+++ b/drivers/firewire/core-card.c
@@ -229,8 +229,7 @@ void fw_schedule_bus_reset(struct fw_card *card, bool delayed, bool short_reset)
/* Use an arbitrary short delay to combine multiple reset requests. */
fw_card_get(card);
- if (!queue_delayed_work(fw_workqueue, &card->br_work,
- delayed ? DIV_ROUND_UP(HZ, 100) : 0))
+ if (!queue_delayed_work(fw_workqueue, &card->br_work, delayed ? msecs_to_jiffies(10) : 0))
fw_card_put(card);
}
EXPORT_SYMBOL(fw_schedule_bus_reset);
@@ -241,10 +240,10 @@ static void br_work(struct work_struct *work)
/* Delay for 2s after last reset per IEEE 1394 clause 8.2.1. */
if (card->reset_jiffies != 0 &&
- time_before64(get_jiffies_64(), card->reset_jiffies + 2 * HZ)) {
+ time_before64(get_jiffies_64(), card->reset_jiffies + secs_to_jiffies(2))) {
trace_bus_reset_postpone(card->index, card->generation, card->br_short);
- if (!queue_delayed_work(fw_workqueue, &card->br_work, 2 * HZ))
+ if (!queue_delayed_work(fw_workqueue, &card->br_work, secs_to_jiffies(2)))
fw_card_put(card);
return;
}
@@ -309,8 +308,7 @@ static void bm_work(struct work_struct *work)
irm_id = card->irm_node->node_id;
local_id = card->local_node->node_id;
- grace = time_after64(get_jiffies_64(),
- card->reset_jiffies + DIV_ROUND_UP(HZ, 8));
+ grace = time_after64(get_jiffies_64(), card->reset_jiffies + msecs_to_jiffies(125));
if ((is_next_generation(generation, card->bm_generation) &&
!card->bm_abdicate) ||
@@ -396,7 +394,7 @@ static void bm_work(struct work_struct *work)
* that the problem has gone away by then.
*/
spin_unlock_irq(&card->lock);
- fw_schedule_bm_work(card, DIV_ROUND_UP(HZ, 8));
+ fw_schedule_bm_work(card, msecs_to_jiffies(125));
return;
}
@@ -418,7 +416,7 @@ static void bm_work(struct work_struct *work)
* bus reset is less than 125ms ago. Reschedule this job.
*/
spin_unlock_irq(&card->lock);
- fw_schedule_bm_work(card, DIV_ROUND_UP(HZ, 8));
+ fw_schedule_bm_work(card, msecs_to_jiffies(125));
return;
}
@@ -551,8 +549,7 @@ void fw_card_initialize(struct fw_card *card,
card->split_timeout_hi = DEFAULT_SPLIT_TIMEOUT / 8000;
card->split_timeout_lo = (DEFAULT_SPLIT_TIMEOUT % 8000) << 19;
card->split_timeout_cycles = DEFAULT_SPLIT_TIMEOUT;
- card->split_timeout_jiffies =
- DIV_ROUND_UP(DEFAULT_SPLIT_TIMEOUT * HZ, 8000);
+ card->split_timeout_jiffies = isoc_cycles_to_jiffies(DEFAULT_SPLIT_TIMEOUT);
card->color = 0;
card->broadcast_channel = BROADCAST_CHANNEL_INITIAL;
diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
index 78b10c6ef7fe..9e90c79becdb 100644
--- a/drivers/firewire/core-cdev.c
+++ b/drivers/firewire/core-cdev.c
@@ -1324,8 +1324,8 @@ static void iso_resource_work(struct work_struct *work)
todo = r->todo;
// Allow 1000ms grace period for other reallocations.
if (todo == ISO_RES_ALLOC &&
- time_before64(get_jiffies_64(), client->device->card->reset_jiffies + HZ)) {
- schedule_iso_resource(r, DIV_ROUND_UP(HZ, 3));
+ time_before64(get_jiffies_64(), client->device->card->reset_jiffies + secs_to_jiffies(1))) {
+ schedule_iso_resource(r, msecs_to_jiffies(333));
skip = true;
} else {
// We could be called twice within the same generation.
diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
index 6a04a0014694..7d5821cd9b37 100644
--- a/drivers/firewire/core-device.c
+++ b/drivers/firewire/core-device.c
@@ -847,9 +847,9 @@ static void fw_schedule_device_work(struct fw_device *device,
*/
#define MAX_RETRIES 10
-#define RETRY_DELAY (3 * HZ)
-#define INITIAL_DELAY (HZ / 2)
-#define SHUTDOWN_DELAY (2 * HZ)
+#define RETRY_DELAY secs_to_jiffies(3)
+#define INITIAL_DELAY msecs_to_jiffies(500)
+#define SHUTDOWN_DELAY secs_to_jiffies(2)
static void fw_device_shutdown(struct work_struct *work)
{
diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
index 1d1c2d8f85ae..623e1d9bd107 100644
--- a/drivers/firewire/core-transaction.c
+++ b/drivers/firewire/core-transaction.c
@@ -458,7 +458,7 @@ static struct fw_packet phy_config_packet = {
void fw_send_phy_config(struct fw_card *card,
int node_id, int generation, int gap_count)
{
- long timeout = DIV_ROUND_UP(HZ, 10);
+ long timeout = msecs_to_jiffies(100);
u32 data = 0;
phy_packet_set_packet_identifier(&data, PHY_PACKET_PACKET_IDENTIFIER_PHY_CONFIG);
@@ -1220,7 +1220,7 @@ static void update_split_timeout(struct fw_card *card)
cycles = clamp(cycles, 800u, 3u * 8000u);
card->split_timeout_cycles = cycles;
- card->split_timeout_jiffies = DIV_ROUND_UP(cycles * HZ, 8000);
+ card->split_timeout_jiffies = isoc_cycles_to_jiffies(cycles);
}
static void handle_registers(struct fw_card *card, struct fw_request *request,
diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
index 9e68ebf0673d..7f2ca93406ce 100644
--- a/drivers/firewire/core.h
+++ b/drivers/firewire/core.h
@@ -30,6 +30,8 @@ struct fw_packet;
// This is the arbitrary value we use to indicate a mismatched gap count.
#define GAP_COUNT_MISMATCHED 0
+#define isoc_cycles_to_jiffies(cycles) usecs_to_jiffies(cycles * USEC_PER_SEC / 8000)
+
extern __printf(2, 3)
void fw_err(const struct fw_card *card, const char *fmt, ...);
extern __printf(2, 3)
--
2.48.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH 2/2] firewire: core: use helper macro to compare against current jiffies
2025-09-15 2:42 [PATCH 0/2] firewire: core: use helper macro to calculate jiffies count Takashi Sakamoto
2025-09-15 2:42 ` [PATCH 1/2] firewire: core: use helper macros instead of direct access to HZ Takashi Sakamoto
@ 2025-09-15 2:42 ` Takashi Sakamoto
2025-09-15 23:20 ` [PATCH 0/2] firewire: core: use helper macro to calculate jiffies count Takashi Sakamoto
2 siblings, 0 replies; 4+ messages in thread
From: Takashi Sakamoto @ 2025-09-15 2:42 UTC (permalink / raw)
To: linux1394-devel; +Cc: linux-kernel
The pattern of calling either time_before64() or time_after64() with
get_jiffies_64() can be replaced with the corresponding helper macros.
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
drivers/firewire/core-card.c | 4 ++--
drivers/firewire/core-cdev.c | 2 +-
drivers/firewire/core-device.c | 3 +--
3 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
index 2541e8bb4b75..b5e01a711145 100644
--- a/drivers/firewire/core-card.c
+++ b/drivers/firewire/core-card.c
@@ -240,7 +240,7 @@ static void br_work(struct work_struct *work)
/* Delay for 2s after last reset per IEEE 1394 clause 8.2.1. */
if (card->reset_jiffies != 0 &&
- time_before64(get_jiffies_64(), card->reset_jiffies + secs_to_jiffies(2))) {
+ time_is_after_jiffies64(card->reset_jiffies + secs_to_jiffies(2))) {
trace_bus_reset_postpone(card->index, card->generation, card->br_short);
if (!queue_delayed_work(fw_workqueue, &card->br_work, secs_to_jiffies(2)))
@@ -308,7 +308,7 @@ static void bm_work(struct work_struct *work)
irm_id = card->irm_node->node_id;
local_id = card->local_node->node_id;
- grace = time_after64(get_jiffies_64(), card->reset_jiffies + msecs_to_jiffies(125));
+ grace = time_is_before_jiffies64(card->reset_jiffies + msecs_to_jiffies(125));
if ((is_next_generation(generation, card->bm_generation) &&
!card->bm_abdicate) ||
diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
index 9e90c79becdb..1be8f5eb3e17 100644
--- a/drivers/firewire/core-cdev.c
+++ b/drivers/firewire/core-cdev.c
@@ -1324,7 +1324,7 @@ static void iso_resource_work(struct work_struct *work)
todo = r->todo;
// Allow 1000ms grace period for other reallocations.
if (todo == ISO_RES_ALLOC &&
- time_before64(get_jiffies_64(), client->device->card->reset_jiffies + secs_to_jiffies(1))) {
+ time_is_after_jiffies64(client->device->card->reset_jiffies + secs_to_jiffies(1))) {
schedule_iso_resource(r, msecs_to_jiffies(333));
skip = true;
} else {
diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
index 7d5821cd9b37..457a0da024a7 100644
--- a/drivers/firewire/core-device.c
+++ b/drivers/firewire/core-device.c
@@ -855,8 +855,7 @@ static void fw_device_shutdown(struct work_struct *work)
{
struct fw_device *device = from_work(device, work, work.work);
- if (time_before64(get_jiffies_64(),
- device->card->reset_jiffies + SHUTDOWN_DELAY)
+ if (time_is_after_jiffies64(device->card->reset_jiffies + SHUTDOWN_DELAY)
&& !list_empty(&device->card->link)) {
fw_schedule_device_work(device, SHUTDOWN_DELAY);
return;
--
2.48.1
^ permalink raw reply related [flat|nested] 4+ messages in thread