From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from fout-a8-smtp.messagingengine.com (fout-a8-smtp.messagingengine.com [103.168.172.151]) (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 29D4C54A7C5; Tue, 22 Sep 2026 14:23:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.151 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790087013; cv=none; b=XBS23bMRRX+zwmOwZGSA/iDCT1BcmoAbbVXSoSiUUcokR7YFL7Lny0fJ6aI8VufSN+ZWOLz7vs2Ff5yCKKaSUDRdMpFf6n4joCtrBTCbsRfzdxDTPEOyB94NrvAt71u3yiXbct0FfLYXXQef4WkDSJ/bTO7T69/kv0lq4Gulwho= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790087013; c=relaxed/simple; bh=1WKltNj3bFDrgEz9P/aKVfd4rrHoohpi19d8Td3ILlA=; h=Date:Message-Id:To:Cc:Subject:From:In-Reply-To:References: Mime-Version:Content-Type; b=odPlqywAj4abHMtFpw8WdNzQfbesfzeyOrmHsEe8Qeox6sl5KGZtucoEijfEcW85RgZdOIuWOXV+i0oKC7FTjA31eFeoKpQgbzxcdozEyX2mqNUBSykXfl5ZRRIsGYyAHp/0F19C0/hPhqIFXLmUSM+YK5u+HDywXuUP4sMWVe4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=flapping.org; spf=pass smtp.mailfrom=flapping.org; dkim=pass (2048-bit key) header.d=flapping.org header.i=@flapping.org header.b=hKIQ+b69; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Ph5vUBWg; arc=none smtp.client-ip=103.168.172.151 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=flapping.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flapping.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=flapping.org header.i=@flapping.org header.b="hKIQ+b69"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Ph5vUBWg" Received: from phl-compute-06.internal (phl-compute-06.internal [10.202.2.46]) by mailfout.phl.internal (Postfix) with ESMTP id 32113EC0255; Tue, 22 Sep 2026 10:23:31 -0400 (EDT) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-06.internal (MEProxy); Tue, 22 Sep 2026 10:23:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=flapping.org; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1790087011; x=1790173411; bh=vP9NCCO9GuK9qooVOCyuEm5uZhDmllxHIjo/78tO+Pw=; b= hKIQ+b69lR/QRXxYIMhN3io8jvGqegQYkf+3KfmtuXmHwvr1d4DjG9nQ8gwoPrLH t7tEf5xGSFklaJUZt4Gy0WN+sAxqAJDmWH9yF+w/97Py/EiSSU57WKYSwcG0nqWR g1Tu9GUexW8diP8C9ufusBxWHmXEFUeMQCQbFnwIHiDq/+zQNwXxD0+ue9rIUWfo 29QiX6ZEFWwqTP1RZSCxG74pdwV4SHeP+Up2cflBJX6ebZ0sqUIiijdAfarTrAKP PdM5ePnLaIEcwDRWUu7x+vGjyBIBXe8XpeMP5o9lLMQic5uCkH+F4iyTVK587JxA NufaDHWtXpbOIsGhFlh7JQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1790087011; x= 1790173411; bh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/dN+8SVQo8oMvrg4bDqJEg2KvvnyoeQHDu+PxcKm2tQ X-ME-Proxy: Feedback-ID: i51fe4b43:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 22 Sep 2026 10:23:24 -0400 (EDT) Date: Tue, 22 Sep 2026 23:23:19 +0900 (JST) Message-Id: <20260922.232319.1364383574405174986.tomo@flapping.org> To: laura.nao@collabora.com Cc: dakr@kernel.org, aliceryhl@google.com, daniel.almeida@collabora.com, airlied@gmail.com, simona@ffwll.ch, ojeda@kernel.org, boqun@kernel.org, gary@garyguo.net, bjorn3_gh@protonmail.com, lossin@kernel.org, a.hindborg@kernel.org, tmgross@umich.edu, tamird@kernel.org, acourbot@nvidia.com, work@onurozkan.dev, fujita.tomonori@gmail.com, frederic@kernel.org, lyude@redhat.com, tglx@kernel.org, anna-maria@linutronix.de, jstultz@google.com, sboyd@kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, driver-core@lists.linux.dev, rust-for-linux@vger.kernel.org, kernel@collabora.com, deborah.brouwer@collabora.com Subject: Re: [PATCH 7/9] rust: time: add arch_timer_get_rate wrapper From: FUJITA Tomonori In-Reply-To: <20260915-tyr-interfaces-v1-7-5d28f1f75aca@collabora.com> References: <20260915-tyr-interfaces-v1-0-5d28f1f75aca@collabora.com> <20260915-tyr-interfaces-v1-7-5d28f1f75aca@collabora.com> 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=us-ascii Content-Transfer-Encoding: 7bit On Tue, 15 Sep 2026 12:57:40 +0200 Laura Nao wrote: > From: Deborah Brouwer > > Provide a safe Rust wrapper for arch_timer_get_rate(). > > The Rust binding calls a C helper that returns 0 when the ARM > architectural timer is not available or not yet initialized. Map this to > Option to make the absence of a valid rate explicit to Rust callers. > > This allows Rust drivers to query the system timer frequency and > select appropriate time sources when programming hardware timeouts. > > Signed-off-by: Deborah Brouwer > Signed-off-by: Laura Nao > --- > rust/helpers/time.c | 6 ++++++ > rust/kernel/time.rs | 30 ++++++++++++++++++++++++++++++ > 2 files changed, 36 insertions(+) (snip) > +/// Returns the ARM architecture timer frequency in Hz, if available. > +/// > +/// This function queries the system-wide ARM architecture timer frequency. > +/// The architecture timer provides a consistent time source across all CPU cores. > +/// > +/// Returns `None` if: > +/// - The ARM architecture timer is not available (`CONFIG_ARM_ARCH_TIMER` not enabled) > +/// - The timer rate is zero (not initialized) > +/// > +/// # Examples > +/// > +/// ``` > +/// use kernel::time::arch_timer_get_rate; > +/// > +/// if let Some(rate) = arch_timer_get_rate() { > +/// // Use `rate`. > +/// } > +/// ``` > +pub fn arch_timer_get_rate() -> Option { > + // SAFETY: The C helper is available in all configs; it calls > + // `arch_timer_get_rate()`, which falls back to an inline stub returning 0 > + // when CONFIG_ARM_ARCH_TIMER is disabled. A SAFETY comment states why the unsafe call is sound. This one explains why the helper is available in all configs. How about: // SAFETY: It is always safe to call `arch_timer_get_rate()`. It just returns a variable without any lock. rust/kernel/time.rs already does this for `ktime_get()` and `ktime_to_us()`. > + let rate = unsafe { bindings::arch_timer_get_rate() }; > + if rate == 0 { > + None > + } else { > + Some(rate) > + } > +} > + > impl Delta { > /// A span of time equal to zero. > pub const ZERO: Self = Self { value: 0 }; > This puts the new function between `impl ops::Div for Delta` and `impl Delta`, so it splits the `Delta` blocks. `msecs_to_jiffies()` is the only other free function in this file and it is at the top, next to the type aliases. Please put `arch_timer_get_rate()` there,