Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1752009ybl; Thu, 30 Jan 2020 05:27:15 -0800 (PST) X-Google-Smtp-Source: APXvYqyUIFrzJP/577kRy2E3xQ/w+UA4dxWgWbrkt4WUP9Xl9sUkoyCn3uolV9tJ3XZh6wQSXhIK X-Received: by 2002:a9d:69ce:: with SMTP id v14mr3616686oto.248.1580390835655; Thu, 30 Jan 2020 05:27:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580390835; cv=none; d=google.com; s=arc-20160816; b=ZO7Yw9E0H5nxljAoUSF/a+2UxtR+dJi5jrtxYqz5RmH99hP7gI+8FUyD4/iVnckkba u+5ZLXZl+izuL64dKCx0a9H8a6uOCQzsH2vcekr/A092xZRGXqiYOueWYDixiAFpx4fj eDOhF7xAw6kYFJEnNbaReF+liMAFfgk95zFpZiHUaJa/it8IOpHMAcnDUSqqciOus59C /fvx6W8Vbf2L6QrNGpzyDSJRgYhzk8A/1G2uA+8lmZZQ8ra4M+Ch1GALHxbQEmAnBMaD f+Lymk176ecv7mdiGy+FGW/tFBo8H+EYONyLE9APl0qpXIsdcUZxU9ohbwluXv8UNCw4 lUBA== 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 :message-id:date:subject:cc:to:from; bh=C9EWq/D1POwz2GH6+XHgq57p+Nj3AQuwyt0ny++tYlo=; b=DZbCMXPnxAQdEzvvopdmxEebWe4XfQxzeYdkkU2ecdRcgeIDBbEuC/auLHeRrDrJnB uCv+fDQBcnBWRV7n0PjMyWZBI1QtUKDHuYjumH02+ZVdq49C6Hzv+tabrK8Ndsu+xWEQ I3aRLoxC7rT7DntGfH3rkelePpxhvsd/C4vdWkFIt9MbJGkPZkFdQzHKEqb1MdI78qDO LLUFrqlHK6jsrRJkSv5hfIb5bfeyBwRYWrGu3PWEHeqdImEP4mxF1HrXlBA1Inyscekf 5YTVVjOA5RdhTBJDouMc8B2eRxrynH8T2xg8OKE3K9q62XOsZHwJXAMHYXAvZAtGJxBG 5PuQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f89si2971081otf.231.2020.01.30.05.27.02; Thu, 30 Jan 2020 05:27:15 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727315AbgA3NJJ (ORCPT + 99 others); Thu, 30 Jan 2020 08:09:09 -0500 Received: from out30-132.freemail.mail.aliyun.com ([115.124.30.132]:51125 "EHLO out30-132.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726980AbgA3NJI (ORCPT ); Thu, 30 Jan 2020 08:09:08 -0500 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R101e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e07484;MF=wenyang@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0TomDHZ2_1580389719; Received: from localhost(mailfrom:wenyang@linux.alibaba.com fp:SMTPD_---0TomDHZ2_1580389719) by smtp.aliyun-inc.com(127.0.0.1); Thu, 30 Jan 2020 21:08:46 +0800 From: Wen Yang To: Thomas Gleixner , Borislav Petkov , hpa@zytor.com, Ingo Molnar Cc: Wen Yang , x86@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] x86/tsc: improve arithmetic division Date: Thu, 30 Jan 2020 21:08:38 +0800 Message-Id: <20200130130838.29157-1-wenyang@linux.alibaba.com> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org do_div() does a 64-by-32 division. Use div64_ul64() or div64_ul() instead of it if the divisor is 'ul64' or 'unsigned long', to avoid truncation to lower 32-bit. And as a nice side effect also cleans up the function a bit. Signed-off-by: Wen Yang Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: "H. Peter Anvin" Cc: x86@kernel.org Cc: linux-kernel@vger.kernel.org --- arch/x86/kernel/tsc.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c index 7e322e2daaf5..4c0320e68699 100644 --- a/arch/x86/kernel/tsc.c +++ b/arch/x86/kernel/tsc.c @@ -357,9 +357,7 @@ static unsigned long calc_pmtimer_ref(u64 deltatsc, u64 pm1, u64 pm2) pm2 -= pm1; tmp = pm2 * 1000000000LL; do_div(tmp, PMTMR_TICKS_PER_SEC); - do_div(deltatsc, tmp); - - return (unsigned long) deltatsc; + return (unsigned long) div64_u64(deltatsc, tmp); } #define CAL_MS 10 @@ -778,8 +776,7 @@ static unsigned long pit_hpet_ptimer_calibrate_cpu(void) tsc_ref_min = min(tsc_ref_min, (unsigned long) tsc2); /* Check the reference deviation */ - delta = ((u64) tsc_pit_min) * 100; - do_div(delta, tsc_ref_min); + delta = div64_ul(((u64) tsc_pit_min) * 100, tsc_ref_min); /* * If both calibration results are inside a 10% window -- 2.23.0