Received: by 2002:a05:7412:8598:b0:f9:33c2:5753 with SMTP id n24csp111597rdh; Mon, 18 Dec 2023 13:15:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IGcvhphcI4SunWz/BdnuU+WXB9f74iE8OY2624xxj+JP55SOSuvWPrVjynD6ANuW5OovaQt X-Received: by 2002:a05:6871:3409:b0:203:d7a8:b4ff with SMTP id nh9-20020a056871340900b00203d7a8b4ffmr1328382oac.33.1702934137538; Mon, 18 Dec 2023 13:15:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702934137; cv=none; d=google.com; s=arc-20160816; b=xBp2E9vZdxXWNl1TppFhCzu+pV7zJzsDAO3Ea6KlhwY1a3WAnBP5TgUe8p2VbySpJs w0hQNN2WcSHDwY1CPBRXDtK1Zi0b/1YrDrJ6Pg4iNmoSCnEddVuV8kPv7a05vbaFeZwh ujtvVdV6Bs6UJ3cXNjx9V1t3JAFL/HO5J7PIzRUIlkB4weydxr9IS3NjmDOajGc1orYP OqZoVutd45LKHiSjsT56ar6KjEYfRCTVBbCjOW8cyF0oRsTg6J24EzEpvzUlLCmrQehD qEWPdJgaHVcLTpDoJPhQNAh2/kF/078SXaJR23tec5Pt+58D0wLLLOzi9Qo+7bQycykn xliA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:feedback-id:dkim-signature; bh=ZAFj55iGA/fI8jzbFo5VrB8O4OpZy+ghswsZ8iOlJEs=; fh=d1mr+x7lUW+LsFabym15sf5XRq8f2wpmTm6zHJ0iGkQ=; b=Dm5RkNEsEb7JIkQUkRsipyrkHRHHlkgKCrXJqMTYMaHJMNPVTenrm5MGROzH3uphtP 1Ol4/GUELtpXKXFAZlldo3aVMHK2XwUdieJAPJgE+lzHSrrVh5QzbYFm7XsHoXktOoS4 C6lLqZk/bSrvLud4Dwq7xQZSbAuRabe0a4TvwSHxTV6VL6Hczatq96pdYoJtWu/8ZCIq j3Nj38QK9cF3wdQW39cp9/aLYdFj8kpRUjV86quBXnPWPXjQ/lOcdbzLduPPB3yOIXmP dMDGmzEpw/9qguVC2wiZFxix7z6LIqGaiSoKVg+d+FFeTM9xLLdsxEVhGoHxAOE/HWy2 wD+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ITbsrZSL; spf=pass (google.com: domain of linux-kernel+bounces-4399-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4399-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id o14-20020a63e34e000000b005c1b30b1b65si18737142pgj.648.2023.12.18.13.15.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 13:15:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-4399-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ITbsrZSL; spf=pass (google.com: domain of linux-kernel+bounces-4399-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4399-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 13A932875E0 for ; Mon, 18 Dec 2023 21:15:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B2B387408F; Mon, 18 Dec 2023 21:15:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ITbsrZSL" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-qk1-f171.google.com (mail-qk1-f171.google.com [209.85.222.171]) (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 938AD73465; Mon, 18 Dec 2023 21:15:26 +0000 (UTC) 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-f171.google.com with SMTP id af79cd13be357-77f8e4702a6so315703485a.1; Mon, 18 Dec 2023 13:15:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702934125; x=1703538925; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:feedback-id:from:to:cc:subject:date :message-id:reply-to; bh=ZAFj55iGA/fI8jzbFo5VrB8O4OpZy+ghswsZ8iOlJEs=; b=ITbsrZSLt4d0YNokKzmYP1YIjwTiKjKHxHjB4V4pd4/p/7XaY5JjgF41h/3qrgW0O6 bcl4xIVG8fhXuUzt1WZHsTKGTshxi7pTbz5y2/7KB1aUrTrCGyFmGZXoR1o8PDRPzv2H NrIzexStJMSxL6BvtAFazmzLZ6kDWUZZejSFwcf2nn4sBXgc7Kw0ZlDPxnHAmh8rCwBJ Va98TnSKdllwM2A/Y9u9asmxLXDcFRf4fz+SvY1jpjPdsDT3rsf1dqis3dV5TIsFX2IO bGwnETH266ev3/LNxMCSDvI8qDhJS0UT6ak3Z3oYVwcsGgdJVtBOo8uxPcm+6UTZrOpM 8OIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702934125; x=1703538925; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:feedback-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZAFj55iGA/fI8jzbFo5VrB8O4OpZy+ghswsZ8iOlJEs=; b=Fosna+a+T3wW9ARC0RTY+UUOcZLH+4TpsCoWyomUF9+HTlGPCt3LL56+KSxUbYFKhL pDbEFW2ZNGMDmW8ETtn2FxVY435sjNyYvJAmCqsw/asEHZCyFK8l+kw0oHeaqPwSjNoA riVuny1yyMHQFBApaczxXCy8GDzZ72Aoutagc7ORT76j05zBlq+DnJCwXn8KDWP6uXaq fqFW5WuvC3y6CKKTBa6J/O6rqfTy0lUY5akYf0L0t6Vzb/pfg7owpFt9xWRgo73415k4 /8FKiWmsYHZdkycHTNp7wgJBJlksUW6AsOtRWhtWL2h+8T2vK1HgVPnmn+g2RPe5o9Km WsyQ== X-Gm-Message-State: AOJu0YwYBOhYznaksGJnmS3RmIVu73LNMpCPMvMGopv4Is8jin1hg6i7 ZqQX6tL83cDFE9/+cUcPrjg= X-Received: by 2002:a05:620a:640c:b0:77f:2cae:c6aa with SMTP id pz12-20020a05620a640c00b0077f2caec6aamr21304147qkn.119.1702934125533; Mon, 18 Dec 2023 13:15:25 -0800 (PST) Received: from auth2-smtp.messagingengine.com (auth2-smtp.messagingengine.com. [66.111.4.228]) by smtp.gmail.com with ESMTPSA id wa2-20020a05620a4d0200b007788dac6b24sm8599541qkn.41.2023.12.18.13.15.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 13:15:25 -0800 (PST) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailauth.nyi.internal (Postfix) with ESMTP id C682A27C005A; Mon, 18 Dec 2023 16:15:24 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Mon, 18 Dec 2023 16:15:24 -0500 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrvddtkedgudeghecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpeeuohhq uhhnucfhvghnghcuoegsohhquhhnrdhfvghnghesghhmrghilhdrtghomheqnecuggftrf grthhtvghrnhephedugfduffffteeutddvheeuveelvdfhleelieevtdeguefhgeeuveei udffiedvnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomh epsghoqhhunhdomhgvshhmthhprghuthhhphgvrhhsohhnrghlihhthidqieelvdeghedt ieegqddujeejkeehheehvddqsghoqhhunhdrfhgvnhhgpeepghhmrghilhdrtghomhesfh higihmvgdrnhgrmhgv X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 18 Dec 2023 16:15:23 -0500 (EST) Date: Mon, 18 Dec 2023 13:15:07 -0800 From: Boqun Feng To: Alice Ryhl Cc: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Gary Guo , =?iso-8859-1?Q?Bj=F6rn?= Roy Baron , Benno Lossin , Andreas Hindborg , Peter Zijlstra , Ingo Molnar , Will Deacon , Waiman Long , Tiago Lam , Thomas Gleixner , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 3/4] rust: sync: add `CondVar::wait_timeout` Message-ID: References: <20231216-rb-new-condvar-methods-v2-0-b05ab61e6d5b@google.com> <20231216-rb-new-condvar-methods-v2-3-b05ab61e6d5b@google.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-Disposition: inline In-Reply-To: <20231216-rb-new-condvar-methods-v2-3-b05ab61e6d5b@google.com> On Sat, Dec 16, 2023 at 03:31:41PM +0000, Alice Ryhl wrote: > Sleep on a condition variable with a timeout. > > This is used by Rust Binder for process freezing. There, we want to > sleep until the freeze operation completes, but we want to be able to > abort the process freezing if it doesn't complete within some timeout. > > Signed-off-by: Alice Ryhl > --- > rust/kernel/sync/condvar.rs | 59 ++++++++++++++++++++++++++++++++++++++++----- > rust/kernel/sync/lock.rs | 4 +-- > 2 files changed, 55 insertions(+), 8 deletions(-) > > diff --git a/rust/kernel/sync/condvar.rs b/rust/kernel/sync/condvar.rs > index 9331eb606738..0176cdfced6c 100644 > --- a/rust/kernel/sync/condvar.rs > +++ b/rust/kernel/sync/condvar.rs > @@ -6,7 +6,8 @@ > //! variable. > > use super::{lock::Backend, lock::Guard, LockClassKey}; > -use crate::{bindings, init::PinInit, pin_init, str::CStr, types::Opaque}; > +use crate::{bindings, init::PinInit, pin_init, str::CStr, time::Jiffies, types::Opaque}; > +use core::ffi::c_long; > use core::marker::PhantomPinned; > use macros::pin_data; > > @@ -18,6 +19,8 @@ macro_rules! new_condvar { > }; > } > > +const MAX_SCHEDULE_TIMEOUT: c_long = c_long::MAX; > + I'd like to put this in rust/kernel/time.rs or rust/kernel/task.rs, but it's not a blocker. > /// A conditional variable. > /// > /// Exposes the kernel's [`struct wait_queue_head`] as a condition variable. It allows the caller to > @@ -102,7 +105,12 @@ pub fn new(name: &'static CStr, key: &'static LockClassKey) -> impl PinInit }) > } > > - fn wait_internal(&self, wait_state: u32, guard: &mut Guard<'_, T, B>) { > + fn wait_internal( > + &self, > + wait_state: u32, > + guard: &mut Guard<'_, T, B>, > + timeout: c_long, Nit: maybe `timeout_in_jiffies` instead of `timeout`? Or we have another data type: pub type DeltaJiffies = c_long; or pub type JiffyDelta = c_long; because a "c_long timeout" really hurts the readability. Regards, Boqun > + ) -> c_long { > let wait = Opaque::::uninit(); > > // SAFETY: `wait` points to valid memory. > @@ -113,11 +121,13 @@ fn wait_internal(&self, wait_state: u32, guard: &mut Guar > bindings::prepare_to_wait_exclusive(self.wait_list.get(), wait.get(), wait_state as _) > }; > [...]