Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp3476939lqp; Tue, 26 Mar 2024 10:05:49 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWsMCnf0LuvRlpBIVn+EPeqIP4kOUc/vbDGbTMcY0YGjq2irWCZAZJM9plMMM1MShY6hvZMn3GvtIbI/+mfdkCxmrHJWWecbVpZ5ltE+Q== X-Google-Smtp-Source: AGHT+IGVSIQPtvJOdZwGmynf1aPhlDUGVmog62rWZv1kywwKWilkIES53A1FsK2/DZyvvdNSnmzD X-Received: by 2002:a17:906:2846:b0:a46:954a:aa14 with SMTP id s6-20020a170906284600b00a46954aaa14mr7571723ejc.67.1711472748950; Tue, 26 Mar 2024 10:05:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711472748; cv=pass; d=google.com; s=arc-20160816; b=Lwgt8G5AMkCWMolvsSYJP72aiRh+5Tyv6UKcQlEZgtoPx533cnKwAmFxBEmGeNyKLm kjWafxdjV7yAHZXyhvcUuOWZ0Wz70VGsoVtWReKrb3PtfLKN9s8MeP55V7zH7dGJzeMo 0c4dPGtWg55CU9fZuj6ZAdOteXBDc9T2HJLnnGE+UIOEp87sQEI1Uk1plmTT3N5T/kN8 ms/Xh216vK8/VzYozce7zhadJSoQX0QngKjVuYLzaIUrYJ67keLal4rXNPQ+tWTxvasT cKzfZpMU1uZKpqSKxz6+d8nus1kXSlpvDf2ZQnMgCFgssJpVhszM2EWWTBZmXUSnR3Vy hJNg== 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:feedback-id:references :in-reply-to:message-id:subject:cc:from:to:date:dkim-signature; bh=rtXdk3BS/YRFaYMhxgJIWorIJjeDwKo7k6/Ds/zUnk4=; fh=6w4G9LgDrc0wGmF4gz6L02UDi66UhJm+aeDXAs5EOUU=; b=Dga3N4mIiJFDiJA9Dl6Fgt8OnuvXbF7/+i1oUwBMfAhhivaup5AsGWRRmQmPRKpMcL K0vpeTY5dpBilKTJr7AeJlCtXtp36cUdhFwbCfmqeXC4hIiv9UrlNgp+BMBUG3iWXxHY tSioT25uD1JhDLMlLVxY4FXdWTcKK/YyQwyOgcwsro94UyEdNZU//x5RSIitJfoi1J+s ScXeDeNTwit644VV8lwiD8oPuelQZwixw+4SBj/1HH0ayZGIFShbNaZ8huBYcKqNtWJw 2mLU6qL2IsqWpJcRz9nlLJhtjHhViwaax/CV8lEiGA0iYCRixoAzhHwECQToh6isUEX+ acqg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@proton.me header.s=4q2uozfqpzck3c7isjb5szza2i.protonmail header.b=IhThkzkP; arc=pass (i=1 spf=pass spfdomain=proton.me dkim=pass dkdomain=proton.me dmarc=pass fromdomain=proton.me); spf=pass (google.com: domain of linux-kernel+bounces-119541-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-119541-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id o16-20020a17090637d000b00a462acefc47si3714591ejc.871.2024.03.26.10.05.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 10:05:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-119541-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@proton.me header.s=4q2uozfqpzck3c7isjb5szza2i.protonmail header.b=IhThkzkP; arc=pass (i=1 spf=pass spfdomain=proton.me dkim=pass dkdomain=proton.me dmarc=pass fromdomain=proton.me); spf=pass (google.com: domain of linux-kernel+bounces-119541-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-119541-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 80FD11F81F65 for ; Tue, 26 Mar 2024 17:05:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 997FB1D555; Tue, 26 Mar 2024 17:03:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b="IhThkzkP" Received: from mail-4316.protonmail.ch (mail-4316.protonmail.ch [185.70.43.16]) (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 0443C1CA95 for ; Tue, 26 Mar 2024 17:03:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.70.43.16 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711472631; cv=none; b=Dn+s1YTvkljIzIRQaMiDz650iGFt0Q0JZ1h1dZfOHnaCoBXfOS6RVhTdzvsf3lWBSkkHV/29/JYlxYZRmKgUllMS7d9x6oNFCnfRvASTU0uFu8OMEzBJof9d7Ii405YxjHCE/Zw2of0gq6+KHpxwrCXvCenJXSucaMtr5SX0ioE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711472631; c=relaxed/simple; bh=wOZNZfomGTf09846FMrd2stSkyFpKdRYfI18SIaqofY=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Wtj0RzV+ZNcXzDz2gCHtvVjjzf4GooxJZJs484k7VBiZnXbqFWRlweMTmu3wEoBkpOpu8geoMWa3fO7sPYZQkJbJ1gTdKl907eZodyaDe6r+VtAxAIEP1wqsaHVjKEs0hcV+xsg2saDPefGGdUw0jI8ma9X+NCLwCDGI7bSnCz8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me; spf=pass smtp.mailfrom=proton.me; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b=IhThkzkP; arc=none smtp.client-ip=185.70.43.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=proton.me DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=4q2uozfqpzck3c7isjb5szza2i.protonmail; t=1711472627; x=1711731827; bh=rtXdk3BS/YRFaYMhxgJIWorIJjeDwKo7k6/Ds/zUnk4=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=IhThkzkPWttmF06bgJPyLmmbKIqfLs4Zv341oKnGjka7RHSUH/HQZjg/luJtpzB9T fF1exY1cbkHThksDlYw6h8S4FpzfWNjaqlwNE6gcJtgmqaWMo+NVuDBG/F749L8+5p oj9NWhBK4yghTgxnS2HImZ2Nhga68jn0jyVWZcP71+xdTj4DI/4rZYhuPysNDaPqnF 7zGCvUYTUW54gP8EzHDVvdt8RXBZ7369ItneM1kovMPmLtw6ERps8AtBfpKPygzaS8 2R3EWjZBE0MRZQzdTWiq4UTAaRFTVQ4JV0m/QyMyM4LIZkoCnuISBfxZC3r8mJ9zpc lsXT3t3PY6WCA== Date: Tue, 26 Mar 2024 17:03:41 +0000 To: Boqun Feng From: Benno Lossin Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Thomas Gleixner , Alice Ryhl , Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Gary Guo , =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= , Andreas Hindborg , John Stultz , Stephen Boyd , Valentin Obst , Heghedus Razvan , Asahi Lina Subject: Re: [PATCH 4/5] rust: time: Support reading CLOCK_MONOTONIC Message-ID: <4wFCQqSgpLIPmdFau6MTL1XLLB73d9Tuv5y-VFnXTDc1DFuTnmNV-GLtF582V5yz8s9ogWP_4U0NK3ei6sZlD1oLl929f8ADoT5K9bO6uKs=@proton.me> In-Reply-To: <20240324223339.971934-5-boqun.feng@gmail.com> References: <20240324223339.971934-1-boqun.feng@gmail.com> <20240324223339.971934-5-boqun.feng@gmail.com> Feedback-ID: 71780778:user:proton Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 24.03.24 23:33, Boqun Feng wrote: > Rust Binder will need to read CLOCK_MONOTONIC to compute how many > milliseconds a transaction has been active for when dumping the current > state of the Binder driver. This replicates the logic in C Binder [1]. >=20 > For a usage example in Rust Binder, see [2]. >=20 > Hence add the support for CLOCK_MONOTONIC read. >=20 > The `ktime_get` method cannot be safely called in NMI context. This > requirement is not checked by these abstractions, but it is intended > that klint [3] or a similar tool will be used to check it in the future. >=20 > Link: https://lore.kernel.org/lkml/5ac8c0d09392290be789423f0dd78a520b830f= ab.1682333709.git.zhangchuang3@xiaomi.com/ [1] > Link: https://r.android.com/3004103 [2] > Link: https://rust-for-linux.com/klint [3] > Co-developed-by: Heghedus Razvan > Signed-off-by: Heghedus Razvan > Co-developed-by: Asahi Lina > Signed-off-by: Asahi Lina > Co-developed-by: Alice Ryhl > Signed-off-by: Alice Ryhl > Signed-off-by: Boqun Feng With the nit fixed: Reviewed-by: Benno Lossin > --- > @Alice, I still put the link to the usage of Android binder here, if you > want to remove that, please let me know. >=20 > rust/kernel/time.rs | 19 +++++++++++++++++++ > 1 file changed, 19 insertions(+) >=20 > diff --git a/rust/kernel/time.rs b/rust/kernel/time.rs > index 0f9f5605ed48..5cd669cbea01 100644 > --- a/rust/kernel/time.rs > +++ b/rust/kernel/time.rs > @@ -113,3 +113,22 @@ fn sub(self, other: Self) -> Self::Output { > Duration::new(self.inner.wrapping_sub(other.inner)) > } > } > + > +/// Contains the various clock source types available to the kernel. > +pub mod clock { > + use super::*; > + > + /// A clock representing the default kernel time source (`CLOCK_MONO= TONIC`). > + pub struct KernelTime; > + > + /// `CLOCK_MONOTONIC` is monotonic. > + impl Monotonic for KernelTime {} > + > + impl Clock for KernelTime { > + #[inline] > + fn now() -> Instant { > + // SAFETY: It is always safe to call `ktime_get` outside of = NMI context. > + Instant::::new(unsafe { bindings::ktime_get() }) I don't think the turbofish syntax (the `::` part) is needed here. --=20 Cheers, Benno > + } > + } > +} > -- > 2.44.0 >