Message ID | 20240225232541.17659-2-thorsten.blum@toblux.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-80346-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1833082dyb; Sun, 25 Feb 2024 18:34:41 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX/sxfF1oBqkI4tPQqmuHdIo8XXQ1e2uUxnhx9dG5Vu12fJp4dQAJcuHTZl5J60ElNYgBdJcWaEHubKrMdhfs/WZLJbuQ== X-Google-Smtp-Source: AGHT+IGW4b/QEHcasI+qZpqHHNc6tK/JdGUfm7ILObk1XdjEcmZrTDyzhV8WN0M2cYGWM0gA7Sjg X-Received: by 2002:a05:6870:498d:b0:21f:c38d:81c6 with SMTP id ho13-20020a056870498d00b0021fc38d81c6mr8201571oab.48.1708914880877; Sun, 25 Feb 2024 18:34:40 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708914880; cv=pass; d=google.com; s=arc-20160816; b=Ir38d4o+5G/aC0gtLCuSuJyd2W+GsKMaTs2vN9YJqTX71tOClXs67fGUj0bMe7pUHP yfMPdewVBfldZWDgaeMRqSMVHX91z3jHzzFb50v5kFzsOJ2Ekh1UmdpsCwE25Jic5QvZ bHIsvhgmWPC0Lb6SeYxgK0USLbwSUnqLDILReOv1ZuNiXmALurKz2LhsioXFVff6BN97 i3HjNOb5YW3h+slj9vqYnSYMu60Be6sd+LG/k/GgG9ukY0if2GhyN0H7p/fnfQ1rPZ3Q DUXCKlaL9JwT/zweFJaW9D3y67l+WlEW4patP/MTlqYA6EiJSbvpkueg0J5GmgtcSs0G SEvw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=mOoug/fJ1o4Ds1BQ7HtXxre7Wl3jDmckcXaES65Kt2E=; fh=rTndupTQ5teKKZ6sK/N42aaaLkNjWf4u/zC4GJfHVoQ=; b=amnH6rdI4JA99LPFuuZFma+B7b1SNHTcdkKFqkwuZ8Y3N0P4SwPNVvKOh4l69pEgOX 2UiPe10QfwQ4fCu3Kmz4ewz1lAetO1i7qgtr109WxKZPKNeXJXcpCZBjYTw7xI+Urz+q a9uzBtM0xApUAn88qR0nwBKPcqDn78HHqt4cuQF1PYB8uhCLfjHLKrls9Si/ZFPvKjt7 OOydDAfJfNyic8NFur+y0ubktiTrq4p0SsRJm8vbrZplYoB/+xAqKtFYlUVm3AoNmURI QTvei3tJ56bfTnBpomBC0GWhyuxfYH0Y1qqB/+xWWGaxh0Xw8kVKZSiv/oKUDjujTGE0 8dpA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@toblux-com.20230601.gappssmtp.com header.s=20230601 header.b=IvgDWFzv; arc=pass (i=1 dkim=pass dkdomain=toblux-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-80346-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80346-ouuuleilei=gmail.com@vger.kernel.org" Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id i27-20020a63585b000000b005dc8368c55esi3014665pgm.633.2024.02.25.18.34.40 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Feb 2024 18:34:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80346-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@toblux-com.20230601.gappssmtp.com header.s=20230601 header.b=IvgDWFzv; arc=pass (i=1 dkim=pass dkdomain=toblux-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-80346-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80346-ouuuleilei=gmail.com@vger.kernel.org" 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 0D899B210B8 for <ouuuleilei@gmail.com>; Sun, 25 Feb 2024 23:29:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D84941BDDB; Sun, 25 Feb 2024 23:29:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toblux-com.20230601.gappssmtp.com header.i=@toblux-com.20230601.gappssmtp.com header.b="IvgDWFzv" Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5BCE328EC for <linux-kernel@vger.kernel.org>; Sun, 25 Feb 2024 23:28:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708903740; cv=none; b=GPosqtJ68NPgixRL/wJnZA45nfAwKs+ZgQakOMsqzq+zWrNh1ALHjVven9VhtoSYP1obxxkAHgQMg6m3+q2HEw4eRhQ08Bu1eFhTQzW1R1gtx2T8y7QElVMbUVa7Zy1krA3KpETNAJVBYvCY7hswpQpcTDYg5J4I1UuTq5BsE0M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708903740; c=relaxed/simple; bh=JYqDb+EWiG9lGhTTrSezJxj3tBLURMYEVMB73IGVPWw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=LYm/86nmc0RRhlfranHC3uHT/TLELy0z6Zpd3206LTebDbOxCzIDNwJV8M6kdY3x71tuwLLK6BU6lu8Kc1Pc0ifL/czlh67v0IjuB02ZWWgHlOkwWJHu4gznVX+OwArRrRih9v6MjRPKSBsf5qDpIABAbT+Fj0i0Jh7PKlxWjso= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toblux.com; spf=none smtp.mailfrom=toblux.com; dkim=pass (2048-bit key) header.d=toblux-com.20230601.gappssmtp.com header.i=@toblux-com.20230601.gappssmtp.com header.b=IvgDWFzv; arc=none smtp.client-ip=209.85.128.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toblux.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toblux.com Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-412949fd224so11397425e9.1 for <linux-kernel@vger.kernel.org>; Sun, 25 Feb 2024 15:28:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toblux-com.20230601.gappssmtp.com; s=20230601; t=1708903737; x=1709508537; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=mOoug/fJ1o4Ds1BQ7HtXxre7Wl3jDmckcXaES65Kt2E=; b=IvgDWFzvxdL1TlQuu4r1TslkduAxt6M1Kcfst2WfHSpVvKCojfRvYP11E3jwcvsMlS vgjkkXDzGBNGt57nSGpajZV/NSDkPAStR3DcNdtaSrq/M8ptR1ESOkc8+lcfDuLCfFTr T37nqa3a+G9pqpp6qsMwfj8LZClI3HzcIbfJxXMyzqY6dvYMUEMo+36j+7yH6g7g5v2/ pNkR9skTR14eYsT4ptBl8eJoP9YmEufq+UnP62k7y4Of9eGNGMt/zY1P6PJbFw1ES2DW ABOjfWGXGg6GbX+44padguTef+hdplGO2h36SCyyBpxpV4Y3oMc9tBc867jhNhGqXWoI MZMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708903737; x=1709508537; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=mOoug/fJ1o4Ds1BQ7HtXxre7Wl3jDmckcXaES65Kt2E=; b=sqn8YzXmf8ahtVbEzqSqPghuALfsinrdZLxyrpw2Az9PnJ80QcVWJ2eCZWu7ZJF2cC uye7kXrslHhqnkchBfu8xJBbO1Ex0iK4/xELtHydIW82OdgxQqWiARu9JDsmx1M01GkY zE0Zj9mDlqtrv7n4g9fYf+Xpyo0Utpqx/YW+gtVSpW9ZNMpd7nlHU+Wb535J9qQIHt7Z 7XNhEzmIDHUfZCS1y58OCCjjd/U2FXa+yqcYRQ5U1JB3bfJ5ishPjxCPLNdNUn+YwTFx Xw1J7gpCHwyYDuSp6eCj2ytv4GJk7h6QyDo3hC6F9GXj/y0FJV20crGE2sEPqA0u5S7S 7oxw== X-Gm-Message-State: AOJu0Yya1yHnpjzbNoFcXFjmzXRzYWv0tRCwYe6L7H1omgZKO6nZTo41 8ZB2hCm3ukxKgrQCgeHB3YuwigQ9qhvpnLRxCSmU/qYqyOWEN5gQBaoSqTVa9kLF1n40JuZsL8E l7BUntg== X-Received: by 2002:a5d:634f:0:b0:33d:39db:a0f8 with SMTP id b15-20020a5d634f000000b0033d39dba0f8mr5078147wrw.7.1708903736554; Sun, 25 Feb 2024 15:28:56 -0800 (PST) Received: from fedora.fritz.box (aftr-82-135-80-35.dynamic.mnet-online.de. [82.135.80.35]) by smtp.gmail.com with ESMTPSA id z6-20020a5d4d06000000b0033d873f08d4sm6279675wrt.98.2024.02.25.15.28.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Feb 2024 15:28:56 -0800 (PST) From: Thorsten Blum <thorsten.blum@toblux.com> To: linux-kernel@vger.kernel.org Cc: Thomas Gleixner <tglx@linutronix.de>, Anna-Maria Behnsen <anna-maria@linutronix.de>, Frederic Weisbecker <frederic@kernel.org>, Peter Zijlstra <peterz@infradead.org>, John Stultz <jstultz@google.com>, Thorsten Blum <thorsten.blum@toblux.com> Subject: [PATCH] time: Use div64_long() instead of do_div() Date: Mon, 26 Feb 2024 00:25:42 +0100 Message-ID: <20240225232541.17659-2-thorsten.blum@toblux.com> X-Mailer: git-send-email 2.43.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791927129810171186 X-GMAIL-MSGID: 1791927129810171186 |
Series |
time: Use div64_long() instead of do_div()
|
|
Commit Message
Thorsten Blum
Feb. 25, 2024, 11:25 p.m. UTC
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 <thorsten.blum@toblux.com>
---
kernel/time/jiffies.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
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 <thorsten.blum@toblux.com> > --- > 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;
> On Feb 26, 2024, at 04:28, Liao, Chang <liaochang1@huawei.com> wrote: > > 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. Yes, div64_ul() is better and also removes the warning. I'll submit a v2 shortly. Thanks, Thorsten
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); /* Calculate nsec_per_tick using shift_hz */ nsec_per_tick = (u64)NSEC_PER_SEC << 8; nsec_per_tick += (u32)shift_hz/2;