Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2358929lqp; Sun, 24 Mar 2024 15:35:52 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU97KvPcjm5q28O9S7qveQNd/cYZ3OnAXCLWFgjLHInuS21GE//oAtlPOMHubA4idWjtkQzYCchSP9+ySsAHRbrnKekZoGRjdIH8qLNGQ== X-Google-Smtp-Source: AGHT+IGguoqdwTF/Z9qdp1szI0N8F4+o50VG2XMIh/aXIbzOsZxfDxZOcMV3474v2XIxxE2NuwSk X-Received: by 2002:a17:902:fc45:b0:1de:f29e:ac27 with SMTP id me5-20020a170902fc4500b001def29eac27mr6777650plb.66.1711319751871; Sun, 24 Mar 2024 15:35:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711319751; cv=pass; d=google.com; s=arc-20160816; b=s9LbetUcaLdIM7ot5Dyb6CdlYnr+pmlZx4wHE6RhJxi3kjvi7CHJyJD6vVkGOHLvwb OaAlCU6HVk313G+HuOPsw7Ck23GRStlcJNb3cDLI9nao3ZilY9oBWf7mK6rg/0Uxcx/z Sjm9djSoOyLBy3O6bMLEZiFoQdn3mHrldjXCbJeR9af+HMgNYheB/dSpf34CkTsxRAnF Na6af3wCc/BF1UH3iurT54iRZ07AJRNgxgHdVa4lOW2EJh/WdPJXp0VMGPrq9/DIAtAu nKyYzL9FlY1549iyDTIp7Xn3v1jxO5JUtL3KvNXr7Wzx+1Pq9ej4U2nht3lGp5lGIy5X GyiA== 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:references:in-reply-to:message-id :date:subject:cc:to:from:feedback-id:dkim-signature; bh=sdmtxUeccR9mblyOKVx+vdMDj9Zw7MyhLqQWnpnpKTE=; fh=+t4C0YaEmdy+UtsdQ80BQL2fQloZ9YHRo1rDsPC5V2A=; b=eb4mKcJ3vL/qOGuJmqD4GUD0vuYFNxErdfio7nog8KvZ0B21dvr9IQwO9EfoQXXn10 95SQT/Nw1W0woah1WIrN8V312Uc+b5YkQiyAE3sC5kZbbVubRjkq/6louHCd6KdT7QxH Ar8gy18o8jjiulaa9V+vEj7cppE2c30eBD25HC1ZaUGnWOnUV4+QosMFfSnkNjxct4Lm b1Lx3rtW3gcSAiRgF76rADOoGRobt6dAIUmtu0aT7nA2rvGd9g01E9qP/ClNJpbemglC vuz7H2nHB/oGxOWpX+jM7jMyulFvL4SKzE09lbTmXGAdUKoXaYUjoJdj3OrE/La02kxQ uttA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="XcT/QOgL"; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-112885-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112885-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id o16-20020a170902d4d000b001dd63e18e5bsi4185150plg.136.2024.03.24.15.35.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 15:35:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-112885-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="XcT/QOgL"; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-112885-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112885-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 75FACB20F76 for ; Sun, 24 Mar 2024 22:35:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2B2E245BE1; Sun, 24 Mar 2024 22:34:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XcT/QOgL" Received: from mail-qk1-f178.google.com (mail-qk1-f178.google.com [209.85.222.178]) (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 8EFEA43ACC; Sun, 24 Mar 2024 22:34:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711319665; cv=none; b=NT63A3eHlqNTrZg3A2JSXQsAqHRLRRxpGXWjUbayWKfXgQ0ZQLv+c6hDBnvLDl7cY5Mo9lIrdvisR/p3dmPnIXg7wUFvT3akOG4ESK+ielkMiDKjmjv5sMF0oYaDAQtSLpKA22efFHhUbFo8aSppghaQSAADVg4BR2LZRiM4P9Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711319665; c=relaxed/simple; bh=bJ86mbIQjLwbn//NFmnurEsU7QTgkvcp3FVZZRVJCis=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WqE8ABaSuDsxVk2yMoCmdfkL+Mroijz9h97zoEQ16MqCSsSH1AIV1WApN4aSYU66IRpq6FuMGe/mbigXT3mE+IEK9cTHP/a6ht0HwlxZe0XeMlENyJ7Bp7+dSbyeBKkwTVhDIPw07UpujLBahrSCahn0lPyIBdmCpkuhf/6feV8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=XcT/QOgL; arc=none smtp.client-ip=209.85.222.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-qk1-f178.google.com with SMTP id af79cd13be357-78a3bccc420so171560485a.1; Sun, 24 Mar 2024 15:34:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711319662; x=1711924462; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:feedback-id:from:to:cc:subject :date:message-id:reply-to; bh=sdmtxUeccR9mblyOKVx+vdMDj9Zw7MyhLqQWnpnpKTE=; b=XcT/QOgLouX+XbDSUamrw2L1UgLIY3emyDz0iMOsWLpSBaWjC6iMuTq8wvkN/yqUFC TPwbFO4ksYueykT9CHGjELt4NeVzpQfZSu+tgVGTNFNXK9sxqGCRCwh3JmQtHIvqQnpM HVPyIy+BpNZ/hIZ77I67yYZzjwS2X/idCRf9hA5HEajahrv/k5prgdyAwFjjr2IGPo4o pw6QOZw23+cJh4nY9DNYat5wp5+d8BQAVtDhn2+NC6SZwFZ6K7rebDnTyPLIetwcjv/8 uMIKoYzndb9ptybt8iGwlG4hueRAT556nsdyrRA0EqQYrHeyuNZMsSVmoeaFn6V36cvi Xz1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711319662; x=1711924462; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:feedback-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=sdmtxUeccR9mblyOKVx+vdMDj9Zw7MyhLqQWnpnpKTE=; b=VTf/fzQnedF45TgW/jLjz9RAwJnKi1fDwB8mHCiR+wH5ocx0vc/QS1hSia9sTuR81g NOUypzSLaTJAVEKvvXya+7+gfpFI9oOtp2Eclz2MtGBo5u6k3xE7sIqbseWNl50k4yNC 7ZqBlFz751/xP85O4zCd0QnNiyI/07DarmU8+pwkPzQjN2l2rzW1cqw2VFv6JmhYuCyW TJsWjvQmmxzViGcwG00IyTmoIHZ0zdmzHamoWNbQCj3wLnFMFy4DnhOM3oty6VdC4NFH uBvr1sApTJ0/iKVGczGXSIN3OjVfFyyHExecH0GeA4zUPrJbRVoRUyMcuLOor42SFh7X +i5w== X-Forwarded-Encrypted: i=1; AJvYcCVadp1Edc2E/5TmGhTGLUkeaEz5w8fySiql5T0gkBIpmIZOHXOeOCSCISRpLGgTz7L/o2wi2U8dqT7SjjoHjR6UaOu4gxIZb7BFC+8P X-Gm-Message-State: AOJu0YyFToaDUSvo3Nb/hguVuiQS/L8pmwvGl+pX9gy2/+Iu3bNYglqz cWCB50u6z5qFJPHQ8Y9dJuWKWlSRTntL/gTr29OJkNis+yQ1o14q X-Received: by 2002:a05:620a:4c:b0:78a:3326:13f with SMTP id t12-20020a05620a004c00b0078a3326013fmr6094290qkt.58.1711319662549; Sun, 24 Mar 2024 15:34:22 -0700 (PDT) Received: from fauth2-smtp.messagingengine.com (fauth2-smtp.messagingengine.com. [103.168.172.201]) by smtp.gmail.com with ESMTPSA id w14-20020a05620a094e00b00787930320b6sm1652237qkw.70.2024.03.24.15.34.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 15:34:22 -0700 (PDT) Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfauth.nyi.internal (Postfix) with ESMTP id A14901200032; Sun, 24 Mar 2024 18:34:21 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Sun, 24 Mar 2024 18:34:21 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledruddtjedgudeihecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeeuohhq uhhnucfhvghnghcuoegsohhquhhnrdhfvghnghesghhmrghilhdrtghomheqnecuggftrf grthhtvghrnhepjeeftdetjeekjefguefggffgiedvieffleejieejueeugfehiefhhfef geekkedvnecuffhomhgrihhnpehkvghrnhgvlhdrohhrghdprghnughrohhiugdrtghomh dprhhushhtqdhfohhrqdhlihhnuhigrdgtohhmnecuvehluhhsthgvrhfuihiivgeptden ucfrrghrrghmpehmrghilhhfrhhomhepsghoqhhunhdomhgvshhmthhprghuthhhphgvrh hsohhnrghlihhthidqieelvdeghedtieegqddujeejkeehheehvddqsghoqhhunhdrfhgv nhhgpeepghhmrghilhdrtghomhesfhhigihmvgdrnhgrmhgv X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 24 Mar 2024 18:34:20 -0400 (EDT) From: Boqun Feng To: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Thomas Gleixner Cc: Alice Ryhl , Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , benno.lossin@proton.me, Andreas Hindborg , John Stultz , Stephen Boyd , Valentin Obst , Heghedus Razvan , Asahi Lina Subject: [PATCH 4/5] rust: time: Support reading CLOCK_MONOTONIC Date: Sun, 24 Mar 2024 15:33:38 -0700 Message-ID: <20240324223339.971934-5-boqun.feng@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240324223339.971934-1-boqun.feng@gmail.com> References: <20240324223339.971934-1-boqun.feng@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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]. For a usage example in Rust Binder, see [2]. Hence add the support for CLOCK_MONOTONIC read. 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. Link: https://lore.kernel.org/lkml/5ac8c0d09392290be789423f0dd78a520b830fab.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 --- @Alice, I still put the link to the usage of Android binder here, if you want to remove that, please let me know. rust/kernel/time.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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_MONOTONIC`). + 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() }) + } + } +} -- 2.44.0