From nobody Fri Nov 29 17:36:40 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 EFBFB1990C2; Tue, 17 Sep 2024 22:29:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726612154; cv=none; b=lt2ZtfozZYIWBn6wr7hVuuNuK+Li0G593dFXGmEcDsrxkpqhBx+yRWkWZ7E7X1gTlwZXfzQ/98HWSqf0uDwb8AUjTuIaaum7fk8RQJ64y3bkyEg8dYE/LJv7A/EbMe0WW2DidIr26AlhBrW9733/evQ0eCDpbTP9SLEnQEtusbA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726612154; c=relaxed/simple; bh=QoToNYKM5P+hCZzBsqEar3hV8ugDLwq+6nZGBAtQAu8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CZ9Ba/vhxkcTr+OYmFbOxZJO7rEHRSA4b2F0Wo8dZEkiDXDB8XZus4AXGS/nQFWGcleEBMQP/vmgfrUdRQrlcLULUmhSsHMHZt02hima5OFg+KGpaf2RM6EyT5LFyR/aystDHeNDpHQ47iBWyfFazXjazOUlmBpjwm9tGwp1vKY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qIVYGCcB; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="qIVYGCcB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 592FCC4CECF; Tue, 17 Sep 2024 22:29:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1726612153; bh=QoToNYKM5P+hCZzBsqEar3hV8ugDLwq+6nZGBAtQAu8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qIVYGCcB75U5Gz5wc/R6uqc8b1dH88tHEAaXrWzrWLyWPfqop0OdQjz2f0s17uURR X9UGyfDkRzATb23NAcmd8Ou6PL8kHBExqYkBh5W/DYtrx1heIu+T2XGAialS3ieZ9E vIguVsWPQjMFtzx3eV7EEL9xs6MA84xYdLnOo9mQuQ1EOEf4zfItECCBVpadTkIHQ0 JJ/9E5cMGzphYk90To9bEAz0cCa7BBaoyEcABvfxx6DtRKN4RGGy+bQ0KAwFoz39mx IxS2EZPNVYeplv/ggkKQuO6nyCFXiTIX7sYuneZP3vyVnCS+n/cN6Wwcy8mWYS7tIL FatqICA+lCJdQ== From: Andreas Hindborg To: Miguel Ojeda , Alex Gaynor , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner Cc: Lyude Paul , Andreas Hindborg , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Alice Ryhl , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 01/14] rust: time: Add Ktime::from_ns() Date: Wed, 18 Sep 2024 00:27:25 +0200 Message-ID: <20240917222739.1298275-2-a.hindborg@kernel.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240917222739.1298275-1-a.hindborg@kernel.org> References: <20240917222739.1298275-1-a.hindborg@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1319; i=a.hindborg@kernel.org; h=from:subject; bh=7NIyQ7Ry9zbDnUQEZUNPDU6fCOWXJskfOgDh+J4/n6I=; b=LS0tLS1CRUdJTiBQR1AgTUVTU0FHRS0tLS0tCgpvd0o0bkFGdEFwT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z2RjNIQ2o2ZElKU2NKRUgwaDR rZ3VwSmVZYVpLV3Fna3VhMFpyYmxBaXlwVXVnZ0NwCmR3dnhqYmo1YWhZaHNRPT0KPS9IWDAKLS 0tLS1FTkQgUEdQIE1FU1NBR0UtLS0tLQo= X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Lyude Paul A simple function to turn the provided value in nanoseconds into a Ktime value. We allow any type which implements Into, which resolves to Into. This is useful for some of the older DRM APIs that never got moved to Ktime Signed-off-by: Lyude Paul Signed-off-by: Andreas Hindborg --- rust/kernel/time.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/rust/kernel/time.rs b/rust/kernel/time.rs index e3bb5e89f88d..1e02eee09f22 100644 --- a/rust/kernel/time.rs +++ b/rust/kernel/time.rs @@ -8,6 +8,8 @@ //! C header: [`include/linux/jiffies.h`](srctree/include/linux/jiffies.h). //! C header: [`include/linux/ktime.h`](srctree/include/linux/ktime.h). =20 +use core::convert::Into; + /// The number of nanoseconds per millisecond. pub const NSEC_PER_MSEC: i64 =3D bindings::NSEC_PER_MSEC as i64; =20 @@ -63,6 +65,12 @@ pub fn to_ns(self) -> i64 { pub fn to_ms(self) -> i64 { self.divns_constant::() } + + /// Creates a new Ktime from the given duration in nanoseconds + #[inline] + pub fn from_ns(ns: impl Into) -> Self { + Self { inner: ns.into() } + } } =20 /// Returns the number of milliseconds between two ktimes. --=20 2.46.0