Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3634849imu; Mon, 28 Jan 2019 08:11:21 -0800 (PST) X-Google-Smtp-Source: ALg8bN7HV1oqXNMToSExlnEMCpQBDwK+kbXWVfhQQIGfc8Mg4xXqbYb0U18oLnuoAMFvjN6c4OcZ X-Received: by 2002:a63:2849:: with SMTP id o70mr13608249pgo.155.1548691881267; Mon, 28 Jan 2019 08:11:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548691881; cv=none; d=google.com; s=arc-20160816; b=enIUCWqhvI4JGEXpzNZurMPgTM7wrEQaovHIiM0hNcjcpiyeHAROEGMwQaXTl7Hkm6 x5M+6qc2+mjSj4wnGGJCEBclpN1PxUHRgTGDI6s8dhfWezXweJGTuqBzCeXCC+y/ZnYP 234vGa5JFSQ1ieZpiYjYvwIV4f08/1N+roPn2y6qZRaRHS+S5QeAmOt2xkLknQksDg6o +jgJ0dbTB4QfFPgJiCfyv+qJX8Gwepls2T62bbs+frg95pEAmcDZoDzi6WtDUC9sz6a0 dSj2gVfQ7x8Asi6we2L/jLtF74/EiFrZEQH2k0NOf4EBdNjLXXGIXDDCXCGD+bxuwUBm ULlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=4L1fPa08NaOjObp4YorlPGxMP9bATxlN05JmOxMAvc0=; b=QDyRqWIN+r86wpJjzwVH2dbKlVtU3Z5yxV5/TNgLD9BxwHxWJHaOlrIQGlTT9tknXP boc3qsiq4sdLjuFFwBd3lcWHiylqZuX+vUdqW6IyyXW5pnAzWE4nhoP++jaeZsR8/fZl YIGqXqf9s6td5W3lPq0/S4ULmrfvAVJk5DPsgZLj91XrBXegP19JME8KMp9oByXMjlWH liH8wZNSDpfYG1F4SL9KWwwUSdHMTR8mhOc0yRS3iSqalV17XcLUXh2XK3B/ihbw8xr8 ufwvjxVX4dzWPXlE51FTLANv6n5fQyaUAop1/dTO7TLwR05OXyPu04Zi4rp/YLgcBYLI FPug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=TYA5VNId; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b11si1080975pfo.240.2019.01.28.08.11.05; Mon, 28 Jan 2019 08:11:21 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=TYA5VNId; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732482AbfA1QIu (ORCPT + 99 others); Mon, 28 Jan 2019 11:08:50 -0500 Received: from mail.kernel.org ([198.145.29.99]:60968 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731323AbfA1QIt (ORCPT ); Mon, 28 Jan 2019 11:08:49 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C8D652171F; Mon, 28 Jan 2019 16:08:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548691728; bh=P/9susO6JXRHQi1Ay1pwjAQT6Xqj82L8fUkhh6zd0Ls=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TYA5VNIdeRoJXONTDvjJ3lZZRTCaDScV0VNNq53HG8JvZ6stBGPtPD9QBeLxZkems SGnFfB0ssXxJ7WX+X4U74dTbd9yt05DGTHXm4KGgxZwjJ5V/H15iuxd/nLkxY2II/G beAYjBBCKHhjwAvJ7bpOs94wORUqHw8xeCSDWkCk= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Miroslav Lichvar , Richard Cochran , Ariel Levkovich , Saeed Mahameed , Sasha Levin , netdev@vger.kernel.org, linux-rdma@vger.kernel.org Subject: [PATCH AUTOSEL 4.19 198/258] mlx5: update timecounter at least twice per counter overflow Date: Mon, 28 Jan 2019 10:58:24 -0500 Message-Id: <20190128155924.51521-198-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190128155924.51521-1-sashal@kernel.org> References: <20190128155924.51521-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Miroslav Lichvar [ Upstream commit 5d8678365c90b9ce1fd2243ff5ea562609f6cec1 ] The timecounter needs to be updated at least once in half of the cyclecounter interval to prevent timecounter_cyc2time() interpreting a new timestamp as an old value and causing a backward jump. This would be an issue if the timecounter multiplier was so small that the update interval would not be limited by the 64-bit overflow in multiplication. Shorten the calculated interval to make sure the timecounter is updated in time even when the system clock is slowed down by up to 10%, the multiplier is increased by up to 10%, and the scheduled overflow check is late by 15%. Cc: Richard Cochran Cc: Ariel Levkovich Cc: Saeed Mahameed Signed-off-by: Miroslav Lichvar Signed-off-by: Saeed Mahameed Signed-off-by: Sasha Levin --- drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c b/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c index 3f767cde4c1d..54f1a40a68ed 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c @@ -511,14 +511,14 @@ void mlx5_init_clock(struct mlx5_core_dev *mdev) ktime_to_ns(ktime_get_real())); /* Calculate period in seconds to call the overflow watchdog - to make - * sure counter is checked at least once every wrap around. + * sure counter is checked at least twice every wrap around. * The period is calculated as the minimum between max HW cycles count * (The clock source mask) and max amount of cycles that can be * multiplied by clock multiplier where the result doesn't exceed * 64bits. */ overflow_cycles = div64_u64(~0ULL >> 1, clock->cycles.mult); - overflow_cycles = min(overflow_cycles, clock->cycles.mask >> 1); + overflow_cycles = min(overflow_cycles, div_u64(clock->cycles.mask, 3)); ns = cyclecounter_cyc2ns(&clock->cycles, overflow_cycles, frac, &frac); -- 2.19.1