Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1083972rbb; Sun, 25 Feb 2024 19:28:55 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUT1xSiTKn2h2umYJ0+rdFn82eT/9fCPt2c5llsdL1uOppBFLbJOXLOtLogSBUc+v5f13cuUH5dzk45rWED8Xl35y6z+1DhSqE+ldiAew== X-Google-Smtp-Source: AGHT+IGBL5KgNGO16B3UyFaz7bSIqoDop6FP41fv/1jFSiz8TVX+8w4+p8FMQtcRemn8+mUqaPyu X-Received: by 2002:a17:90a:b112:b0:299:58a4:4a90 with SMTP id z18-20020a17090ab11200b0029958a44a90mr7275041pjq.22.1708918135019; Sun, 25 Feb 2024 19:28:55 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708918135; cv=pass; d=google.com; s=arc-20160816; b=eHnTM2foW9vQVNbG3F1grIaHeiBaqfgGRtEGzoTwb5g826oWvB2vpyDHbk8ythlN1o 1q+9REOWA1Q/CG/ivCzy5QRR+00cKTPgiB2sPVXLEQ8ry6tbn0CKVTkqljKzRi8qLzTq mjPfaXEaIL8aJcJTXwiWuU7f2N/0SApMUsfCU+yd353wTZRk7HV0Wi+gylvRwLim+ntd 22ibpd77lYjQKTyPQbey5VcRbqGlDXgNdSKFqJGJwuXSorqgYQnfA2oT5GkmQPHJ8HOs Q7FGKxvLpPk5jM51QBxL8ZL+7y4Fg3jEIbGzDd3ZPD78E3/YLB9jMnGRK9Oj6h+XzaT+ ljJA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:date:message-id; bh=Y+06ZIuYAqU0l1vhVeGy864M6R57dehrNcKBkxS6Z48=; fh=ne3JQoL99tLIKSG9j3UvuQFSN84KlNaztbSEvMFzsNQ=; b=b81cPbnt0YAbBmuxj74lMqaNAFJDS7LZF3v/3qq1WyVea7DGEoLzl0/pcUeo4mQKAw geTpNhCYS4eol/2T5MzKoij3+4fzf/WdpyTIDX9w2PN5075C8/2AY1N8s0pCf456pUMb AybUFzzwfY0807c5hxJg/cGpLqnsq3e+7jDWgUekDeA3f1JnFYSXPHQyxPPtgbiKV1cK 2O4YaQ7Kjs4edVgNd7Q+Oi90EK/OUfxDgRcFCGVF6xBOaje74o5yWFti0waRk9FO4tMW 0a9X72Gs8oa7tyl/wwG/xx2FTSZk9tY09rvYhOZSxiZGxnVNmI5BcZ0B8hFDpmWowIKP N99w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-80468-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80468-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id j15-20020a63594f000000b005cdf992367csi2944506pgm.691.2024.02.25.19.28.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Feb 2024 19:28:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80468-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-80468-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80468-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id B3B8B2821A0 for ; Mon, 26 Feb 2024 03:28:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 530EC14263; Mon, 26 Feb 2024 03:28:49 +0000 (UTC) Received: from szxga07-in.huawei.com (szxga07-in.huawei.com [45.249.212.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BE72BC8C7 for ; Mon, 26 Feb 2024 03:28:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.35 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708918128; cv=none; b=ESS47M1B80rNFqjtxvrvLIN1/MWZBcUh2FfTcfOMkkUT3XzMJdO+CZmdexcIB7JBAdvs5cZeTY0xACmXxA8RydBpMS8LUTrBpCwHyUGU+aSPXccXiT9OIWioVMr2ECDmFwzIn3QrFJY70hIVMEkG/Oed2k2/GlvRZ633a974stw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708918128; c=relaxed/simple; bh=Q9IMP5W6DExwGPIPuDXfsAR4MKCV2Ob7P/qKfk3D3tQ=; h=Message-ID:Date:MIME-Version:Subject:To:CC:References:From: In-Reply-To:Content-Type; b=T14duZddQ18L3zohsXcLJqA6V2hIsmP7MuS/24io2Z6wtBkli3IZ20sXn9UTpz2giZsoy+KIDL9rdjekKgWrxG02zle91o0XTQsTjr23jhUc1bqiJM5t0G2y2INyGLYsgknLrt6Hpb4fst2eKP4qSoU/8smSpMIWpBU4Eqz0Li0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.35 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.44]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4TjmHT5l5Cz1X3QC; Mon, 26 Feb 2024 11:26:29 +0800 (CST) Received: from kwepemd500003.china.huawei.com (unknown [7.221.188.36]) by mail.maildlp.com (Postfix) with ESMTPS id 212891400D4; Mon, 26 Feb 2024 11:28:43 +0800 (CST) Received: from kwepemd200013.china.huawei.com (7.221.188.133) by kwepemd500003.china.huawei.com (7.221.188.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.28; Mon, 26 Feb 2024 11:28:42 +0800 Received: from [10.67.110.108] (10.67.110.108) by kwepemd200013.china.huawei.com (7.221.188.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1258.28; Mon, 26 Feb 2024 11:28:42 +0800 Message-ID: <4bc9df7f-ea00-ad5e-02f0-d4cae6f005ad@huawei.com> Date: Mon, 26 Feb 2024 11:28:41 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.11.2 Subject: Re: [PATCH] time: Use div64_long() instead of do_div() To: Thorsten Blum , CC: Thomas Gleixner , Anna-Maria Behnsen , Frederic Weisbecker , "Peter Zijlstra" , John Stultz References: <20240225232541.17659-2-thorsten.blum@toblux.com> From: "Liao, Chang" In-Reply-To: <20240225232541.17659-2-thorsten.blum@toblux.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemd200013.china.huawei.com (7.221.188.133) Thorsten, 在 2024/2/26 7:25, Thorsten Blum 写道: > Fixes Coccinelle/coccicheck warning reported by do_div.cocci. > > Compared to do_div(), div64_long() does not implicitly cast the divisor and > does not unnecessarily calculate the remainder. > > Signed-off-by: Thorsten Blum > --- > kernel/time/jiffies.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/kernel/time/jiffies.c b/kernel/time/jiffies.c > index bc4db9e5ab70..9d23178e2b6a 100644 > --- a/kernel/time/jiffies.c > +++ b/kernel/time/jiffies.c > @@ -91,7 +91,7 @@ int register_refined_jiffies(long cycles_per_second) > /* shift_hz stores hz<<8 for extra accuracy */ > shift_hz = (u64)cycles_per_second << 8; > shift_hz += cycles_per_tick/2; > - do_div(shift_hz, cycles_per_tick); > + shift_hz = div64_long(shift_hz, cycles_per_tick); I am considering using div64_ul() to calculate the result. as shift_hz is unsigned long, assume the sign bit of divisor cycles_per_tick never be set in this context,then div64_long() will do a extra sign extension for result. Or are there other recommendations? Thanks. > /* Calculate nsec_per_tick using shift_hz */ > nsec_per_tick = (u64)NSEC_PER_SEC << 8; > nsec_per_tick += (u32)shift_hz/2; -- BR Liao, Chang