Skip to content

Commit 743a3ce

Browse files
edumazetgregkh
authored andcommitted
net/mlx4_en: fix overflow in mlx4_en_init_timestamp()
[ Upstream commit 47d3a07528ecbbccf53bc4390d70b4e3d1c04fcf ] The cited commit makes a great job of finding optimal shift/multiplier values assuming a 10 seconds wrap around, but forgot to change the overflow_period computation. It overflows in cyclecounter_cyc2ns(), and the final result is 804 ms, which is silly. Lets simply use 5 seconds, no need to recompute this, given how it is supposed to work. Later, we will use a timer instead of a work queue, since the new RX allocation schem will no longer need mlx4_en_recover_from_oom() and the service_task firing every 250 ms. Fixes: 31c128b66e5b ("net/mlx4_en: Choose time-stamping shift value according to HW frequency") Signed-off-by: Eric Dumazet <edumazet@google.com> Cc: Tariq Toukan <tariqt@mellanox.com> Cc: Eugenia Emantayev <eugenia@mellanox.com> Reviewed-by: Tariq Toukan <tariqt@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Sasha Levin <alexander.levin@verizon.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 7ed668e commit 743a3ce

2 files changed

Lines changed: 8 additions & 11 deletions

File tree

drivers/net/ethernet/mellanox/mlx4/en_clock.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,17 @@ void mlx4_en_remove_timestamp(struct mlx4_en_dev *mdev)
8888
}
8989
}
9090

91+
#define MLX4_EN_WRAP_AROUND_SEC 10UL
92+
/* By scheduling the overflow check every 5 seconds, we have a reasonably
93+
* good chance we wont miss a wrap around.
94+
* TOTO: Use a timer instead of a work queue to increase the guarantee.
95+
*/
96+
#define MLX4_EN_OVERFLOW_PERIOD (MLX4_EN_WRAP_AROUND_SEC * HZ / 2)
97+
9198
void mlx4_en_ptp_overflow_check(struct mlx4_en_dev *mdev)
9299
{
93100
bool timeout = time_is_before_jiffies(mdev->last_overflow_check +
94-
mdev->overflow_period);
101+
MLX4_EN_OVERFLOW_PERIOD);
95102
unsigned long flags;
96103

97104
if (timeout) {
@@ -236,7 +243,6 @@ static const struct ptp_clock_info mlx4_en_ptp_clock_info = {
236243
.enable = mlx4_en_phc_enable,
237244
};
238245

239-
#define MLX4_EN_WRAP_AROUND_SEC 10ULL
240246

241247
/* This function calculates the max shift that enables the user range
242248
* of MLX4_EN_WRAP_AROUND_SEC values in the cycles register.
@@ -258,7 +264,6 @@ void mlx4_en_init_timestamp(struct mlx4_en_dev *mdev)
258264
{
259265
struct mlx4_dev *dev = mdev->dev;
260266
unsigned long flags;
261-
u64 ns, zero = 0;
262267

263268
/* mlx4_en_init_timestamp is called for each netdev.
264269
* mdev->ptp_clock is common for all ports, skip initialization if
@@ -282,13 +287,6 @@ void mlx4_en_init_timestamp(struct mlx4_en_dev *mdev)
282287
ktime_to_ns(ktime_get_real()));
283288
write_unlock_irqrestore(&mdev->clock_lock, flags);
284289

285-
/* Calculate period in seconds to call the overflow watchdog - to make
286-
* sure counter is checked at least once every wrap around.
287-
*/
288-
ns = cyclecounter_cyc2ns(&mdev->cycles, mdev->cycles.mask, zero, &zero);
289-
do_div(ns, NSEC_PER_SEC / 2 / HZ);
290-
mdev->overflow_period = ns;
291-
292290
/* Configure the PHC */
293291
mdev->ptp_clock_info = mlx4_en_ptp_clock_info;
294292
snprintf(mdev->ptp_clock_info.name, 16, "mlx4 ptp");

drivers/net/ethernet/mellanox/mlx4/mlx4_en.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,6 @@ struct mlx4_en_dev {
409409
struct cyclecounter cycles;
410410
struct timecounter clock;
411411
unsigned long last_overflow_check;
412-
unsigned long overflow_period;
413412
struct ptp_clock *ptp_clock;
414413
struct ptp_clock_info ptp_clock_info;
415414
struct notifier_block nb;

0 commit comments

Comments
 (0)