Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp6238331rdb; Thu, 14 Dec 2023 12:05:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IE0M9svZM0nQ7mwOPReZTZLwFm2pSCwktkXB+B0lER2zB0tzPP295L6aUFTJfGI+UDZpjrT X-Received: by 2002:a17:902:8696:b0:1cf:ef92:18f3 with SMTP id g22-20020a170902869600b001cfef9218f3mr9807430plo.58.1702584331462; Thu, 14 Dec 2023 12:05:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702584331; cv=none; d=google.com; s=arc-20160816; b=oj7HUnPOZAwWdNJnEYeu2cioVvtslSt8przMo6ulctJlu0iPCGjhuWOOjUX1gYblTA C14aeW4UEIk9WfAJnsct95nrqtqo36aRlBGC3AsRfL5VYX8J2Gm3aXnljhJe8PZZtqbi GW0jYzXtJq5Fnfiq6jaaWWQhD9HISQblXGpPKiSa04SvBJGXHafpdC7eyylpFn52ZtKT mR2wi8/ueJNStOVir+lgg3SSdNvJtYD+8HYuMyXDJ1JllRW1qtQmr9Iqbu5GYvf0qpMz zlpWS3ewKy42wezKsxULHJsVAgD/HqQhvodBl7yBgKva9MqU72u61dTHbdPUOC9V1DgX zgcA== ARC-Message-Signature: i=1; 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=eS37CR7+TgFqv3CfKfPzO9kSVywAUrgFAe0aN8vgnU8=; fh=UigP6MqHZ0LBIqcOmEE/BxYs50kTteRRJPeW7hAD7lM=; b=M4e0TokVf+nghtqv812L5no7PK09Sz6O1qRR39LYGaDGOUJPCtAdRJedJ1erQFFYlU kmwLGotGoBd77qPl2Jl/HV6FSwjucCj5DBC2b2JjW98rvqvnlUopgqurWqSHBMpP9snw flZso9cERdXma66QcT0xSBFDdHJStAegEzwehZuZAj22+kZSRE0M+QvEmuLvhnBtFKDN yMD0zo1JMO6+KVmoYnMNEUDqvCz8jHs8QmDQ7TwRXjhZE+9ib6paJM4fWD5brJgjAEjp Y6/9RBTaNMH+Rwo1UQAdbANvYk3kRsWn1fWxdQueEjtRDoE4uOHK8Sr4PZiNZM9x5Io3 sTlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=GuExpyrx; spf=pass (google.com: domain of linux-kernel+bounces-48-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48-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. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id a15-20020a170902eccf00b001cfbf025320si12261779plh.346.2023.12.14.12.05.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 12:05:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-48-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=GuExpyrx; spf=pass (google.com: domain of linux-kernel+bounces-48-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48-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 ED701282477 for ; Thu, 14 Dec 2023 20:04:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 424CB6A02A; Thu, 14 Dec 2023 20:04:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GuExpyrx" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-qk1-f169.google.com (mail-qk1-f169.google.com [209.85.222.169]) (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 A07EE6A014; Thu, 14 Dec 2023 20:04:33 +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-f169.google.com with SMTP id af79cd13be357-77f50307a1fso430786785a.3; Thu, 14 Dec 2023 12:04:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702584272; x=1703189072; 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=eS37CR7+TgFqv3CfKfPzO9kSVywAUrgFAe0aN8vgnU8=; b=GuExpyrxeZEriSoJjrkbKxkiKi/OrYWSTMmfeoguXjRULLcKflbiGcyLhg+J5zN5XE 5HMrS3D1ucpzmuBAaAnmBFEdBI5HEnnWCwuRCFqU4qMRY2/OdYD7qDWaBNVkiuJ5Hpy4 ux1ckwuX8tuM3RhLeVCfQ7GBfj+cPZOR6XmnCr2xEyaaLYQit90mzzZ+9KjNU8IwaB/3 EUsn2JBUD4xqwizROElWNBk9dP6QrGzXh3E9OW7oS214jGDNSh8eFg2jx95rYRS9liPK tXoIV13Je0FBFKBTCr1ANYMttbcEAjjlsloiu0/v3uF6GlqW+Wi/PhTQMOsKG5/a12tZ 0i0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702584272; x=1703189072; 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=eS37CR7+TgFqv3CfKfPzO9kSVywAUrgFAe0aN8vgnU8=; b=XJJn0wIfIGuS/PPXvwhVEfEOAqyG28v9LAITjePiLQyOSDqnNsml941iL7v7GONrWW XpK9c0JtgmLho5P0ocUvXSuqHYq+pLOE71jmyavC0Fnx7hJwUr0gs4wNmX1p7lzewhTk 5u7bVN/gX03TkJ7G6SlYYyuk+EiNvZvx5CL0k0kxhJRyWayQWgnbwtbv1klidoIXqzS5 r3FYPC/DoQMvteBAEZaprGpc1dR0ZGesYWXvy9XssQf5UqCmKbSbmpcKkxaUHF8YsCDs GeAC69gsz+19ia4j5DctjGZmRRjV1rVz+DI/hn2iY2lA4eyTxw0xRccI+Kev9T5neS4W al+Q== X-Gm-Message-State: AOJu0YzirAAAqGZAeoa7liy1gQra8vtopX4BKZQ4IPaWYATuF97hbRPy 7cL74rDXVwXddaQVDnu/CsY= X-Received: by 2002:a37:e10c:0:b0:77f:2cad:7122 with SMTP id c12-20020a37e10c000000b0077f2cad7122mr11895872qkm.77.1702584272305; Thu, 14 Dec 2023 12:04:32 -0800 (PST) Received: from auth1-smtp.messagingengine.com (auth1-smtp.messagingengine.com. [66.111.4.227]) by smtp.gmail.com with ESMTPSA id qg1-20020a05620a664100b0077f01c11e3bsm5567151qkn.61.2023.12.14.12.04.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 12:04:32 -0800 (PST) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailauth.nyi.internal (Postfix) with ESMTP id 84F3727C0054; Thu, 14 Dec 2023 15:04:31 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 14 Dec 2023 15:04:31 -0500 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrudelledgudefudcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeeuohhq uhhnucfhvghnghcuoegsohhquhhnrdhfvghnghesghhmrghilhdrtghomheqnecuggftrf grthhtvghrnhepgeeljeeitdehvdehgefgjeevfeejjeekgfevffeiueejhfeuiefggeeu heeggefgnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomh epsghoqhhunhdomhgvshhmthhprghuthhhphgvrhhsohhnrghlihhthidqieelvdeghedt ieegqddujeejkeehheehvddqsghoqhhunhdrfhgvnhhgpeepghhmrghilhdrtghomhesfh higihmvgdrnhgrmhgv X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 14 Dec 2023 15:04:30 -0500 (EST) From: Boqun Feng To: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Tiago Lam , Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Alice Ryhl , Benno Lossin , Andreas Hindborg , Peter Zijlstra , Ingo Molnar , Will Deacon , Waiman Long , Martin Rodriguez Reboredo , Boqun Feng Subject: [PATCH] rust: sync: Makes `CondVar::wait()` an uninterruptible wait Date: Thu, 14 Dec 2023 12:04:21 -0800 Message-ID: <20231214200421.690629-1-boqun.feng@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Currently, `CondVar::wait()` is an interruptible wait, and this is different than `wait_event()` in include/linux/wait.h (which is an uninterruptible wait). To avoid confusion between different APIs on the interruptible/uninterruptible, make `CondVar::wait()` an uninterruptible wait same as `wait_event()`, also rename the old `wait()` to `CondVar::wait_interruptible()`. Spotted-by: Tiago Lam Signed-off-by: Boqun Feng --- rust/kernel/sync/condvar.rs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/rust/kernel/sync/condvar.rs b/rust/kernel/sync/condvar.rs index b679b6f6dbeb..8630faa29b78 100644 --- a/rust/kernel/sync/condvar.rs +++ b/rust/kernel/sync/condvar.rs @@ -50,7 +50,7 @@ macro_rules! new_condvar { /// fn wait_for_value(e: &Example, v: u32) { /// let mut guard = e.value.lock(); /// while *guard != v { -/// e.value_changed.wait_uninterruptible(&mut guard); +/// e.value_changed.wait(&mut guard); /// } /// } /// @@ -120,28 +120,28 @@ fn wait_internal(&self, wait_state: u32, guard: &mut Guar unsafe { bindings::finish_wait(self.wait_list.get(), wait.get()) }; } - /// Releases the lock and waits for a notification in interruptible mode. + /// Releases the lock and waits for a notification in uninterruptible mode. /// /// Atomically releases the given lock (whose ownership is proven by the guard) and puts the /// thread to sleep, reacquiring the lock on wake up. It wakes up when notified by - /// [`CondVar::notify_one`] or [`CondVar::notify_all`], or when the thread receives a signal. - /// It may also wake up spuriously. + /// [`CondVar::notify_one`] or [`CondVar::notify_all`]. Note that it may also wake up + /// spuriously. + pub fn wait(&self, guard: &mut Guard<'_, T, B>) { + self.wait_internal(bindings::TASK_UNINTERRUPTIBLE, guard); + } + + /// Releases the lock and waits for a notification in interruptible mode. + /// + /// Similar to [`CondVar::wait`], except that the wait is interruptible. That is, the thread may + /// wake up due to signals. It may also wake up spuriously. /// /// Returns whether there is a signal pending. - #[must_use = "wait returns if a signal is pending, so the caller must check the return value"] - pub fn wait(&self, guard: &mut Guard<'_, T, B>) -> bool { + #[must_use = "wait_interruptible returns if a signal is pending, so the caller must check the return value"] + pub fn wait_interruptible(&self, guard: &mut Guard<'_, T, B>) -> bool { self.wait_internal(bindings::TASK_INTERRUPTIBLE, guard); crate::current!().signal_pending() } - /// Releases the lock and waits for a notification in uninterruptible mode. - /// - /// Similar to [`CondVar::wait`], except that the wait is not interruptible. That is, the - /// thread won't wake up due to signals. It may, however, wake up supirously. - pub fn wait_uninterruptible(&self, guard: &mut Guard<'_, T, B>) { - self.wait_internal(bindings::TASK_UNINTERRUPTIBLE, guard) - } - /// Calls the kernel function to notify the appropriate number of threads with the given flags. fn notify(&self, count: i32, flags: u32) { // SAFETY: `wait_list` points to valid memory. -- 2.43.0