From nobody Fri Dec 19 00:11:53 2025 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (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 78E874779C for ; Mon, 8 Jan 2024 14:50:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="npUwnaWH" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-db402e6f61dso2018074276.3 for ; Mon, 08 Jan 2024 06:50:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1704725406; x=1705330206; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=bnwJONZ3lqNGKjXAo9ka9hqMWO5IxVpynKJIV/pgiEE=; b=npUwnaWHdth44JfRUSJcmbfljZF4S2AeNXRi1PGjdxzN5m1OzFdhrASGJOi5uvTf8I R6b/I8uteGk/9dNYaqVYR8d7irj0riy0lEHrboDy8O7mb30aqFIDnRCDZbySmSZUsdc3 Rqj+VzXI/bp7oKB/gsoONy5nS4FGvlHgrd5mkDJDS0sHwD4lq5GkpYV3b9Dzipo2SlDD aZqGqxbUn48+xLeUwC85fC1Brng8Q5f0msXGE1lP3sdZ80aX4+AOAxNEAJFnpglGa5Hc OK2cGXglh5qz243xInDz2YBeDuz3t6HNPb5hsDFGsFIjAPuPzyp8Cayg/rkK69Wydkt0 yL/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704725406; x=1705330206; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=bnwJONZ3lqNGKjXAo9ka9hqMWO5IxVpynKJIV/pgiEE=; b=Eh9caIjVaAbvQ9dNJ/neOC5eHi+brYsGZv/RgZDvC4/BiTmPLZwsuD5qT6bQF5pP24 8OlJm2QQZATBbX9P4p5chB3coQhM0Eqs7FeBJAU+aEAhcAnKESq5zsMeg/T/eJi5g8LZ hz9DF61YnOzqIPKb9bangpDqDhBXGy8ApjzM4cxisrZwqH+myi2E9D8CWi1yijO0yuh5 B/njmF4NfdKnmE3oJJWv2Q8/ZEN1JBHkwALXgxhZhkHheZvFyAhmQL3fyab2+eJ8LIQH 1vWptF5cXv354zDrQnbvujDL6s3l2qvmlq3uKRR2re3oyDnrNjwUx6mRFs+oBAU9HIc+ XdjQ== X-Gm-Message-State: AOJu0YyVH7KMp16NWsE2mLcr/dogsB/c6sLUx/U51b8nZj9uyzR5/Jkd 4HZLAcCcWYWqihW5JqBeHPLefoiNJPr3SsDEceY1Aw== X-Google-Smtp-Source: AGHT+IHmdP+w7bmx5EPMykFzlMsIrxFehhDztFE298PAMbn4SQjrtVVuX49AEZrgBveT4k9GTPZ7urGKfZDYpNQ= X-Received: from aliceryhl2.c.googlers.com ([fda3:e722:ac3:cc00:68:949d:c0a8:572]) (user=aliceryhl job=sendgmr) by 2002:a05:6902:136d:b0:dbd:b756:983a with SMTP id bt13-20020a056902136d00b00dbdb756983amr1431440ybb.9.1704725406476; Mon, 08 Jan 2024 06:50:06 -0800 (PST) Date: Mon, 08 Jan 2024 14:49:57 +0000 In-Reply-To: <20240108-rb-new-condvar-methods-v4-0-88e0c871cc05@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240108-rb-new-condvar-methods-v4-0-88e0c871cc05@google.com> X-Developer-Key: i=aliceryhl@google.com; a=openpgp; fpr=49F6C1FAA74960F43A5B86A1EE7A392FDE96209F X-Developer-Signature: v=1; a=openpgp-sha256; l=1773; i=aliceryhl@google.com; h=from:subject:message-id; bh=V4luaNSyjxN/VywBe1xxHgUOl/JEebqcSaoMufGn4dg=; b=owEBbQKS/ZANAwAKAQRYvu5YxjlGAcsmYgBlnAuWxfp8qMduMbMX2T2PGs8QR3xSAjwxXpgeG Dswbv5Jvq2JAjMEAAEKAB0WIQSDkqKUTWQHCvFIvbIEWL7uWMY5RgUCZZwLlgAKCRAEWL7uWMY5 Rp2qEACsiZji70Fyhw9whBLl/VPFPDVm+L+rmMqGgu3Ol3E8p/1zVOQPKcMarHJynTIkxIZ/BJz 00x5mlOpb1UwU0miyhSRd7hvTGEV6vYMMpPxQmnt2ufAZHGec8IiSt+6T5UYIM4J+tJ7WVO4qlD /lkGVlBFrTu/HsXqslRm5yuPowIGMcT9Z4e79BqNQ138EVshyosAKB67z5Au+b3zdiHMB/eJu2y zWOWTnDqmqIW27Jomq+hI3WON7JltKkhEc9qnJacsSmXukGUlxrEnlv8xWfNMgB0JMRcFB4iRYP i9YwUTtPgHoJ5NcbHiK94AdUcmW8fmDAL1H6aotymo9E0/QHEo4kVPMNCZxwjVZdVgMVo+oBKuo FsYF+t/4HQfVZhxIu+FP+F2OPL/RRIRR8IsScNfY7EVId+5K92wS2bk/n2e0etBEvcq7Qrqa1l2 QVhabtO9k+q1a9cbbZhoiy3b114SuXFe5CL6F+TWoKs6RE3oJIvNWJbBCmojtP5dlkxuhhLniWi +t5yvTS3o1OW8AHvWDGy+Wc2sABBPGMGCWw0Va/fYcYbG6vRke1xor8Dg4lcrJqtEcfj2ZfTupH bMq5O1WR21V4a6bCJ6QnQlBWjT7poRDxDAYwXNJbZ8ttEGRT+GvBEEjy83qmNERBam2nTqRYFVR 0D8lnfZ2ALcAPXQ== X-Mailer: b4 0.13-dev-26615 Message-ID: <20240108-rb-new-condvar-methods-v4-1-88e0c871cc05@google.com> Subject: [PATCH v4 1/4] rust: sync: add `CondVar::notify_sync` From: Alice Ryhl To: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , "=?utf-8?q?Bj=C3=B6rn_Roy_Baron?=" , Benno Lossin , Andreas Hindborg , Peter Zijlstra , Ingo Molnar , Will Deacon , Waiman Long , Tiago Lam , Thomas Gleixner Cc: Martin Rodriguez Reboredo , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Alice Ryhl Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Wake up another thread synchronously. This method behaves like `notify_one`, except that it hints to the scheduler that the current thread is about to go to sleep, so it should schedule the target thread on the same CPU. This is used by Rust Binder as a performance optimization. When sending a transaction to a different process, we usually know which thread will handle it, so we can schedule that thread for execution next on this CPU for better cache locality. Reviewed-by: Benno Lossin Reviewed-by: Martin Rodriguez Reboredo Reviewed-by: Tiago Lam Reviewed-by: Boqun Feng Signed-off-by: Alice Ryhl --- rust/kernel/sync/condvar.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/rust/kernel/sync/condvar.rs b/rust/kernel/sync/condvar.rs index f65e19d5a37c..b323a0c26513 100644 --- a/rust/kernel/sync/condvar.rs +++ b/rust/kernel/sync/condvar.rs @@ -155,6 +155,16 @@ fn notify(&self, count: i32, flags: u32) { }; } =20 + /// Calls the kernel function to notify one thread synchronously. + /// + /// This method behaves like `notify_one`, except that it hints to the= scheduler that the + /// current thread is about to go to sleep, so it should schedule the = target thread on the same + /// CPU. + pub fn notify_sync(&self) { + // SAFETY: `wait_list` points to valid memory. + unsafe { bindings::__wake_up_sync(self.wait_list.get(), bindings::= TASK_NORMAL) }; + } + /// Wakes a single waiter up, if any. /// /// This is not 'sticky' in the sense that if no thread is waiting, th= e notification is lost --=20 2.43.0.472.g3155946c3a-goog From nobody Fri Dec 19 00:11:53 2025 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (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 4A3A84C605 for ; Mon, 8 Jan 2024 14:50:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Js7/DtjJ" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dbedaa77289so2050479276.0 for ; Mon, 08 Jan 2024 06:50:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1704725409; x=1705330209; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=pY0HtCQNVEDI/Vsc7JQzdf3b/zPkklUdbelm2DZN3NU=; b=Js7/DtjJn/lEf+e0KOJvJaR1gnYra8NEte72OZ0xpzZuTnOmRwj4jdLCZ5Seq0SkMj vhYZ0ruLLi7X2e+ffeKIixZlLGR/RQbWTAMvcM7dBpKhj+Wm0thBU3jISSQxbDXNrtFx oSdCzFDODBh+Nl1kPVypMryDQEffplmNGzbtJ2g7Mjrc8migeLrGYUDJcXXjz1DD22Dl Q33nfx/d03h0ro8TBnxJtTIcDg+NNt03WD1DXtMJZyiuh8ZvBlLdn/P9UM9qnHuoMy/v 6NQ1Bb6w7bZLoBREAifwKjG8kIZL1qEtowfP9WR2v4UrI1fVxAKj4vQWSaHQbg/Zbfm1 w8Hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704725409; x=1705330209; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=pY0HtCQNVEDI/Vsc7JQzdf3b/zPkklUdbelm2DZN3NU=; b=DL5YDJrm2vfrrepHgCHQYQyD6Vs9PvGKNUiaCpUf047Bi7ECWCZbxLcrP6GIxUXzNM C+FZDfN2b8QgK7h9kfgYee+KzHvbLBujKFf4SguRsAW7wuz8qQ5OkLh59+EeAl1j5WAg 7zBfEH4vlahHjTGcsHH6v12+Glw0cclRlMwvYk3Go59K83gThlosz4FsXJ+Dq7ua4w6s Tc/hFtOO6EOnxwHXtiAuWO5OKagMwSIEquGZuE9fCljTnOVClSksp0AfjX3277LOvR2Z 1wUmbFJBRW9CInwU1AygKWRKj5ZKkFIAifCXdxq81xEEWDSu0csvQ/JCKyBuUm/Ke9NM Cniw== X-Gm-Message-State: AOJu0Yxtdermj/qaeil96OxypHtos9K2H0VQgMH6w5CnGUPh0DxbY5vA PEGwXII10T7KwhOmfjw9Xp25hfBdDBDu7DcfAJdtVg== X-Google-Smtp-Source: AGHT+IGJxJ4El1SsQB80UHGXIn9YKxGgM1kwSFmA8mPeiF1/Xo3RC3FFCXswDhgV7dN1lUchDF9BZnUagANvItQ= X-Received: from aliceryhl2.c.googlers.com ([fda3:e722:ac3:cc00:68:949d:c0a8:572]) (user=aliceryhl job=sendgmr) by 2002:a05:6902:27c1:b0:dbe:d5b3:89dc with SMTP id ec1-20020a05690227c100b00dbed5b389dcmr1610560ybb.0.1704725409310; Mon, 08 Jan 2024 06:50:09 -0800 (PST) Date: Mon, 08 Jan 2024 14:49:58 +0000 In-Reply-To: <20240108-rb-new-condvar-methods-v4-0-88e0c871cc05@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240108-rb-new-condvar-methods-v4-0-88e0c871cc05@google.com> X-Developer-Key: i=aliceryhl@google.com; a=openpgp; fpr=49F6C1FAA74960F43A5B86A1EE7A392FDE96209F X-Developer-Signature: v=1; a=openpgp-sha256; l=2768; i=aliceryhl@google.com; h=from:subject:message-id; bh=p9Hjc0DIm01aLLvHmXgxckf25tmtqAjiAqjiP2XhYzQ=; b=owEBbQKS/ZANAwAKAQRYvu5YxjlGAcsmYgBlnAuX80giaQX0FdHju3XER/Jm5Yh4IO0sNQLTH UnHUWhw7CaJAjMEAAEKAB0WIQSDkqKUTWQHCvFIvbIEWL7uWMY5RgUCZZwLlwAKCRAEWL7uWMY5 Rp36D/49UpNyjSWnCBZWXnLo//R/VePqgsn8LBRMySFdg2Qi64hzXFpIHq0tyOYcvQXY21Bx3bU Z/W02lSB30fuwDsu588yG1fHBp/AxV0xSCZeVQHNoCUX5pBGU8sdiNhpEgYGDOkqRHCAwWqOzmO 2hM80yeIQRRVmcpW7PmgDhy9yzM5rTRnvteUpN1hTuijKmSr45grtQqflfjBfIRNQCx7TxN5Cy1 FMqM8v/Ver+FZJa+QphOOPfaL+/logcJTIJXikudNVlAs9HLSFc6dGWEEF0ImNpJbHEOzMcZ4Bi J4Z81+wgcHW22R3S3U95p2PM+cbzcm1qR1jYIsuyAKghgYHJEY/VjWdsdxoOcKDUkOyGvqcHsXQ fUmpOP4Wlo42JB+/OYUp1b5G+sYxOgcyxKfTpIVDDtZwGCzOMfEL9/15UOd70g2hd9FMvKvX3J3 XGfhGTlAxagLlanFXkQeeQZk7QOYNVeLgqLVXI4SqyGYoE/djtRUmnROBuo3g8dEOaY+7oUtqfS umAlMShmZ3uBnBcNrynYe0x/AaEff9hi31fY2fz5qJaUNtHk9+KY/eOq40gmpoyfZD3FofMo1/4 T7LIrDVY5lhYfzBOfApioNDE7a50A/n7LNwlz9PiBoK9pcoMch9hOL6KTC8Fv0ZG72tbHQbcE8f p1fAOZcQ5GN1iQA== X-Mailer: b4 0.13-dev-26615 Message-ID: <20240108-rb-new-condvar-methods-v4-2-88e0c871cc05@google.com> Subject: [PATCH v4 2/4] rust: time: add msecs to jiffies conversion From: Alice Ryhl To: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , "=?utf-8?q?Bj=C3=B6rn_Roy_Baron?=" , Benno Lossin , Andreas Hindborg , Peter Zijlstra , Ingo Molnar , Will Deacon , Waiman Long , Tiago Lam , Thomas Gleixner Cc: Martin Rodriguez Reboredo , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Alice Ryhl Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Defines type aliases and conversions for msecs and jiffies. 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. The freeze timeout is supplied in msecs. Note that we need to convert to jiffies in Binder. It is not enough to introduce a variant of `CondVar::wait_timeout` that takes the timeout in msecs because we need to be able to restart the sleep with the remaining sleep duration if it is interrupted, and if the API takes msecs rather than jiffies, then that would require a conversion roundtrip jiffies-> msecs->jiffies that is best avoided. Suggested-by: Boqun Feng Reviewed-by: Boqun Feng Reviewed-by: Benno Lossin Reviewed-by: Martin Rodriguez Reboredo Reviewed-by: Tiago Lam Signed-off-by: Alice Ryhl --- rust/bindings/bindings_helper.h | 1 + rust/kernel/lib.rs | 1 + rust/kernel/time.rs | 20 ++++++++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_helpe= r.h index b5714fb69fe3..227dc9240f3f 100644 --- a/rust/bindings/bindings_helper.h +++ b/rust/bindings/bindings_helper.h @@ -8,6 +8,7 @@ =20 #include #include +#include #include #include #include diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs index e6aff80b521f..d4f90acdd517 100644 --- a/rust/kernel/lib.rs +++ b/rust/kernel/lib.rs @@ -46,6 +46,7 @@ pub mod str; pub mod sync; pub mod task; +pub mod time; pub mod types; pub mod workqueue; =20 diff --git a/rust/kernel/time.rs b/rust/kernel/time.rs new file mode 100644 index 000000000000..25a896eed468 --- /dev/null +++ b/rust/kernel/time.rs @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: GPL-2.0 + +//! Time related primitives. +//! +//! This module contains the kernel APIs related to time and timers that +//! have been ported or wrapped for usage by Rust code in the kernel. + +/// The time unit of Linux kernel. One jiffy equals (1/HZ) second. +pub type Jiffies =3D core::ffi::c_ulong; + +/// The millisecond time unit. +pub type Msecs =3D core::ffi::c_uint; + +/// Converts milliseconds to jiffies. +#[inline] +pub fn msecs_to_jiffies(msecs: Msecs) -> Jiffies { + // SAFETY: The `__msecs_to_jiffies` function is always safe to call no + // matter what the argument is. + unsafe { bindings::__msecs_to_jiffies(msecs) } +} --=20 2.43.0.472.g3155946c3a-goog From nobody Fri Dec 19 00:11:53 2025 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (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 0ADEF51029 for ; Mon, 8 Jan 2024 14:50:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="t7nPoB6s" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dbce2a8d700so1451672276.1 for ; Mon, 08 Jan 2024 06:50:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1704725412; x=1705330212; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=FC3zSuKOQJ4VOItAZMX3cy9K0P5EzH8kuQgbB61S/9A=; b=t7nPoB6svrrWC3fQ2I1b7eZJArLL61PnOiMz4LslVaUgo51ISuXU3Jbdaa7HwVkqIu naU3tT/vkeJnpBcVbHgpMGAr3LoxR4AQ/FIuS5cotZFO1UxO1LXelcA6ZGyPJlgyTasX D6g6AsllBmZYXXI5Wk5gb1GnTthO1unS7xNxgY2ELwVNKwm6pnLyTwEpg4yw5PAkaGiH SUyq/ClKcIVIhBji8l7PTJSpuhvA5/lUxQPw6jiSZKeC7KE01SIStGxVdyCJp6ys5EzO sGPm1MPv8janwu8tWfB9C1WTFoGV1CcbD5QGdKqqZsvMJA2WJthO7Ih0Lu59hY9tlhCA e/SA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704725412; x=1705330212; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=FC3zSuKOQJ4VOItAZMX3cy9K0P5EzH8kuQgbB61S/9A=; b=b3uGsyIoud9WjxJJAVAi7PoWl8ZMu5ihLrfI62UkwNswuif8+OqrFQ2GKaIaO0rzvH RcY1+08XUdgFNkx0sp3/f3cJN8SmcHlfRQoclsdW71i7rnrcK5Ej/n23kdH/CKXeJA8N hOrVi76F3v7Z16rjlGXL0+UZPrVfgpg8S05iOW5KjbjYchbHdgzv6pctyXvm408ntEKr alyQ24Jn4RfoiTPiD61/hdpyDPng38epd7jaKVcFtPAKH7leKMWirFPlIjSFywbVw4Dc fm6jySorGPdK1XiP7H007QHW/BKrHP8EhMAKWrW2sxa57lPF6QMiqb157luW+v2wYDcN dF0w== X-Gm-Message-State: AOJu0Yy3NeUsOATU2jzQSsg/wTfodlISh5315MuzSb/+JN4cqSwokdT8 W5cwdsHlqE6HEg9C2FpT/OlSpqwcV1d7onE7gQlC6Q== X-Google-Smtp-Source: AGHT+IEPNTj5SK4xnk+K+oSPjZ+cukAEB9mSC2NTVZHULzc5WjngM80a5n1vbGdmDADDneDvpzWjcPGVUHwF17w= X-Received: from aliceryhl2.c.googlers.com ([fda3:e722:ac3:cc00:68:949d:c0a8:572]) (user=aliceryhl job=sendgmr) by 2002:a25:824d:0:b0:dbe:3087:1d22 with SMTP id d13-20020a25824d000000b00dbe30871d22mr116090ybn.13.1704725412185; Mon, 08 Jan 2024 06:50:12 -0800 (PST) Date: Mon, 08 Jan 2024 14:49:59 +0000 In-Reply-To: <20240108-rb-new-condvar-methods-v4-0-88e0c871cc05@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240108-rb-new-condvar-methods-v4-0-88e0c871cc05@google.com> X-Developer-Key: i=aliceryhl@google.com; a=openpgp; fpr=49F6C1FAA74960F43A5B86A1EE7A392FDE96209F X-Developer-Signature: v=1; a=openpgp-sha256; l=7424; i=aliceryhl@google.com; h=from:subject:message-id; bh=7DhaZf4SIHmOZSumn+foJHl61MmWwbMVF8kY96krCxU=; b=owEBbQKS/ZANAwAKAQRYvu5YxjlGAcsmYgBlnAuX2Bw76dgmwZsRUQv2BSOUeYFtlj/bnw3Mt qnMUZmjXuyJAjMEAAEKAB0WIQSDkqKUTWQHCvFIvbIEWL7uWMY5RgUCZZwLlwAKCRAEWL7uWMY5 RrR7EACwCNPW0WeatnTjrXtcg5qPPDvC1cN6wsnV9Zpn5s5UGCcXQuXHILMAL2HtrV69KBbjvcF +RxYCnNShxHWfDYR0U0BYTWKcGIwMTEkbD1Kak/ardDFEf33OUb89Mu29tUw7TUyhKAJi3fi/P7 nMzieT8KQAq8HC/LJpAS53ZkfH7pD6GLuVF8u9d+4zpwnL6DgclZ1pmRMkszsYzINjp8gKElO8C JDmnxmDQhw0fWXOS8ZYeuPq8RWGvqZPHD/xZEHyVVWnV6rcZQ1D9V6P31kKCV+han0X8Jrfxhk9 MIOuw8sQXIvV3M8ekAVcX3hJ61wTdh+G5RdfOjIL04eCln+j7EYmNYOVMp2/HJBTNHIv89i4ZCb sbK9rGA5+SIEEVo5hlxOw3fXD1Uy/V0TptWIB8P3kpGlnsirteOKgf5axWCyv/aiJ+ZjEmClEUI HwXkFE5jWc8BptxfEgTU/g0506pgjXmlYZwAOA/yeXrqjQtvOJbNiJ3B9sc5+9LARJGihVMZeTS Jzr+ropsW+bs76K5Ahfr4xs0QdBpv5BdkytzlaBW+bL61Q4zoMNaG+y3JJ6jnlOwZC3x0ncjqFR DMzCokS4+yurF0+MFG+YKkAAOQ9JceBC1UwfbxQfzdLrpR4XpQoXLB0NPvNGbPdVmF2jcTdhWrX OXHRmN3fP+7m28Q== X-Mailer: b4 0.13-dev-26615 Message-ID: <20240108-rb-new-condvar-methods-v4-3-88e0c871cc05@google.com> Subject: [PATCH v4 3/4] rust: sync: add `CondVar::wait_timeout` From: Alice Ryhl To: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , "=?utf-8?q?Bj=C3=B6rn_Roy_Baron?=" , Benno Lossin , Andreas Hindborg , Peter Zijlstra , Ingo Molnar , Will Deacon , Waiman Long , Tiago Lam , Thomas Gleixner Cc: Martin Rodriguez Reboredo , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Alice Ryhl Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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. Note that it is not enough to avoid jiffies by introducing a variant of `CondVar::wait_timeout` that takes the timeout in msecs because we need to be able to restart the sleep with the remaining sleep duration if it is interrupted, and if the API takes msecs rather than jiffies, then that would require a conversion roundtrip jiffies->msecs->jiffies that is best avoided. Reviewed-by: Martin Rodriguez Reboredo Reviewed-by: Tiago Lam Reviewed-by: Boqun Feng Signed-off-by: Alice Ryhl Reviewed-by: Benno Lossin --- rust/kernel/sync/condvar.rs | 60 ++++++++++++++++++++++++++++++++++++++++-= ---- rust/kernel/sync/lock.rs | 4 +-- rust/kernel/task.rs | 5 +++- 3 files changed, 60 insertions(+), 9 deletions(-) diff --git a/rust/kernel/sync/condvar.rs b/rust/kernel/sync/condvar.rs index b323a0c26513..fa38c095cbe0 100644 --- a/rust/kernel/sync/condvar.rs +++ b/rust/kernel/sync/condvar.rs @@ -6,7 +6,11 @@ //! variable. =20 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, task::MAX_SCHEDULE_TIMEO= UT, time::Jiffies, + types::Opaque, +}; +use core::ffi::c_long; use core::marker::PhantomPinned; use macros::pin_data; =20 @@ -102,7 +106,12 @@ pub fn new(name: &'static CStr, key: &'static LockClas= sKey) -> impl PinInit(&self, wait_state: u32, guard:= &mut Guard<'_, T, B>) { + fn wait_internal( + &self, + wait_state: u32, + guard: &mut Guard<'_, T, B>, + timeout_in_jiffies: c_long, + ) -> c_long { let wait =3D Opaque::::uninit(); =20 // SAFETY: `wait` points to valid memory. @@ -113,11 +122,13 @@ fn wait_internal(&self, wait_s= tate: u32, guard: &mut Guar bindings::prepare_to_wait_exclusive(self.wait_list.get(), wait= .get(), wait_state as _) }; =20 - // SAFETY: No arguments, switches to another thread. - guard.do_unlocked(|| unsafe { bindings::schedule() }); + // SAFETY: Switches to another thread. The timeout can be any numb= er. + let ret =3D guard.do_unlocked(|| unsafe { bindings::schedule_timeo= ut(timeout_in_jiffies) }); =20 // SAFETY: Both `wait` and `wait_list` point to valid memory. unsafe { bindings::finish_wait(self.wait_list.get(), wait.get()) }; + + ret } =20 /// Releases the lock and waits for a notification in uninterruptible = mode. @@ -127,7 +138,7 @@ fn wait_internal(&self, wait_sta= te: u32, guard: &mut Guar /// [`CondVar::notify_one`] or [`CondVar::notify_all`]. Note that it m= ay also wake up /// spuriously. pub fn wait(&self, guard: &mut Guard<'_, T, B>)= { - self.wait_internal(bindings::TASK_UNINTERRUPTIBLE, guard); + self.wait_internal(bindings::TASK_UNINTERRUPTIBLE, guard, MAX_SCHE= DULE_TIMEOUT); } =20 /// Releases the lock and waits for a notification in interruptible mo= de. @@ -138,10 +149,31 @@ pub fn wait(&self, guard: &mut= Guard<'_, T, B>) { /// Returns whether there is a signal pending. #[must_use =3D "wait_interruptible returns if a signal is pending, so = the caller must check the return value"] pub fn wait_interruptible(&self, guard: &mut Gu= ard<'_, T, B>) -> bool { - self.wait_internal(bindings::TASK_INTERRUPTIBLE, guard); + self.wait_internal(bindings::TASK_INTERRUPTIBLE, guard, MAX_SCHEDU= LE_TIMEOUT); crate::current!().signal_pending() } =20 + /// Releases the lock and waits for a notification in interruptible mo= de. + /// + /// Atomically releases the given lock (whose ownership is proven by t= he guard) and puts the + /// thread to sleep. It wakes up when notified by [`CondVar::notify_on= e`] or + /// [`CondVar::notify_all`], or when a timeout occurs, or when the thr= ead receives a signal. + #[must_use =3D "wait_interruptible_timeout returns if a signal is pend= ing, so the caller must check the return value"] + pub fn wait_interruptible_timeout( + &self, + guard: &mut Guard<'_, T, B>, + jiffies: Jiffies, + ) -> CondVarTimeoutResult { + let jiffies =3D jiffies.try_into().unwrap_or(MAX_SCHEDULE_TIMEOUT); + let res =3D self.wait_internal(bindings::TASK_INTERRUPTIBLE, guard= , jiffies); + + match (res as Jiffies, crate::current!().signal_pending()) { + (jiffies, true) =3D> CondVarTimeoutResult::Signal { jiffies }, + (0, false) =3D> CondVarTimeoutResult::Timeout, + (jiffies, false) =3D> CondVarTimeoutResult::Woken { jiffies }, + } + } + /// Calls the kernel function to notify the appropriate number of thre= ads with the given flags. fn notify(&self, count: i32, flags: u32) { // SAFETY: `wait_list` points to valid memory. @@ -181,3 +213,19 @@ pub fn notify_all(&self) { self.notify(0, 0); } } + +/// The return type of `wait_timeout`. +pub enum CondVarTimeoutResult { + /// The timeout was reached. + Timeout, + /// Somebody woke us up. + Woken { + /// Remaining sleep duration. + jiffies: Jiffies, + }, + /// A signal occurred. + Signal { + /// Remaining sleep duration. + jiffies: Jiffies, + }, +} diff --git a/rust/kernel/sync/lock.rs b/rust/kernel/sync/lock.rs index f12a684bc957..149a5259d431 100644 --- a/rust/kernel/sync/lock.rs +++ b/rust/kernel/sync/lock.rs @@ -139,7 +139,7 @@ pub struct Guard<'a, T: ?Sized, B: Backend> { unsafe impl Sync for Guard<'_, T, B> {} =20 impl Guard<'_, T, B> { - pub(crate) fn do_unlocked(&mut self, cb: impl FnOnce()) { + pub(crate) fn do_unlocked(&mut self, cb: impl FnOnce() -> U) -> U { // SAFETY: The caller owns the lock, so it is safe to unlock it. unsafe { B::unlock(self.lock.state.get(), &self.state) }; =20 @@ -147,7 +147,7 @@ pub(crate) fn do_unlocked(&mut self, cb: impl FnOnce())= { let _relock =3D ScopeGuard::new(|| unsafe { B::relock(self.lock.state.get(), &= mut self.state) }); =20 - cb(); + cb() } } =20 diff --git a/rust/kernel/task.rs b/rust/kernel/task.rs index 9451932d5d86..17f14ebb8f48 100644 --- a/rust/kernel/task.rs +++ b/rust/kernel/task.rs @@ -5,7 +5,10 @@ //! C header: [`include/linux/sched.h`](srctree/include/linux/sched.h). =20 use crate::{bindings, types::Opaque}; -use core::{marker::PhantomData, ops::Deref, ptr}; +use core::{ffi::c_long, marker::PhantomData, ops::Deref, ptr}; + +/// A sentinal value used for infinite timeouts. +pub const MAX_SCHEDULE_TIMEOUT: c_long =3D c_long::MAX; =20 /// Returns the currently running task. #[macro_export] --=20 2.43.0.472.g3155946c3a-goog From nobody Fri Dec 19 00:11:53 2025 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (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 E327E51C3D for ; Mon, 8 Jan 2024 14:50:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="f6SSQ91L" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dbeac1f5045so2322317276.1 for ; Mon, 08 Jan 2024 06:50:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1704725415; x=1705330215; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=6SZoYYqOOUlMq4hjr9gywH5xihJLOMWXAYIKnq88z+Q=; b=f6SSQ91L/S/HMh04Aa26IRBAwQY3cGZnnnSOx56sUricJIfUIDSszIFIEbqOQz7QoP UD91edN5stZe+EHlgSKFBH2bERVWNVPqzBHte9Sf2iV9sW6Qf5B4/QwxHIF6sevSwoe+ L38pvWKK19WInT6JGnC3mdhughtWqfdn8jtOYWWploFB5W/htuLgI6/supJSBQdybPXS e/oRdlATG8JQwXZpETh4LTH22qlu0MKATv2Nk4cEKvwBffMfbSc5OVkJfpO9AoiYVKji q5kMhj9katkdJjTL7/yHBAw3JORWboBO+dh2+GvcdpQVMSeNeJ4cEx+PnkldAuCbKiwl t8IA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704725415; x=1705330215; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=6SZoYYqOOUlMq4hjr9gywH5xihJLOMWXAYIKnq88z+Q=; b=RaSCK+9+Agb3fS/Ar+wKcKrtqG9HF+tmfnPoHTf/jjQgMYYpFFV/a5Gx6K2bqsD7+d +j9GSUUDPk6dQKsVnQorxr5enwrzCbWiKOccqU2CqdBadR2u/k4R0ZIMSbVyeX3K6AWS vystzy359eOsXGIlXJogZ2Qwqdrxs2x+DM2gAlzz0yKaIsR4f4/+xWOsXg6UhHJ1Ekp/ 9LoaBgdysu8CpWvnTyJMR4FS+eOsWjG9j+FyRqQRMpoiBIvsHKUr1HjGZNugjqpcAa4Z 2MK6n9/jNcl9/ODEwHKs+0l9yb9MD5HYZp1DArUSlo5Ki1ukL2CH5Cn32hiRjqIVjS/8 XzXQ== X-Gm-Message-State: AOJu0YyVvxhHQXEslZ6ohuD7BVPHzAWIv4P0qvO3Flq6GeX4/B1oyJ9w E50LJCVJ5V9t7tfd4RfvOU857bJ7B9G3k/WtLzQabw== X-Google-Smtp-Source: AGHT+IGoF8enDRleCmZP7Dmc/qRxjrTw5VAhRL9E5ptEbQRiVTHdmIVTFFthzEjgA3zPSvy/xLgsVV/t1bikGlU= X-Received: from aliceryhl2.c.googlers.com ([fda3:e722:ac3:cc00:68:949d:c0a8:572]) (user=aliceryhl job=sendgmr) by 2002:a05:6902:1342:b0:dbd:ee44:8908 with SMTP id g2-20020a056902134200b00dbdee448908mr1432916ybu.0.1704725415044; Mon, 08 Jan 2024 06:50:15 -0800 (PST) Date: Mon, 08 Jan 2024 14:50:00 +0000 In-Reply-To: <20240108-rb-new-condvar-methods-v4-0-88e0c871cc05@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240108-rb-new-condvar-methods-v4-0-88e0c871cc05@google.com> X-Developer-Key: i=aliceryhl@google.com; a=openpgp; fpr=49F6C1FAA74960F43A5B86A1EE7A392FDE96209F X-Developer-Signature: v=1; a=openpgp-sha256; l=7874; i=aliceryhl@google.com; h=from:subject:message-id; bh=p4ziQv4KIkMhpCT+PoV/4ZeXHtEOSN15SNY70QjJ4kk=; b=owEBbQKS/ZANAwAKAQRYvu5YxjlGAcsmYgBlnAuYNVHmKC/whrgPlUF7M5/1PQ7D0IobbMcTZ G0XbqHAVBeJAjMEAAEKAB0WIQSDkqKUTWQHCvFIvbIEWL7uWMY5RgUCZZwLmAAKCRAEWL7uWMY5 RmZ/D/9wxhF2JuR645ZiU06XtSTBT7fKFn5jm6SHcWIrPs1lK/brMEZLknoDDugO0eNDeioMjTY hjO1ZOhWQmgGeKesSTDuolvXpqCbneXSBMAX932Fbk71jk75j1hXxVy/8pSLAKoqp+K/ayRV1vj gcPaVgxN3rFrKg8zI+bM3o9YTl2PSvY0/nugeeb2gEKj/vVD6gbpxm7bpl9nB69BjYJX8eNPskU edI/0ea6H9DEuX6d3Z8K9P4HfSQWYjt8D9r6b3jcdAKqy66TkYqPQHD16fFyYcQBwQBJaHt5gvf DLYDvQVfCf+tLHkN7ZWz4J51Ougi9vHyrOkZbQDvuRm3Wubs/vFUeRkG/CnG0PU0S06DhL3nox0 si6ZAelzmH2u3gwjdH01kSQYEpzG/FjxVlaqc5oM13Rq0f+nYfpB1oYZ60UCVc86SAch6NZ0MVJ nEL6v/Tb1veTV8mdVrF6JTNmWg2zTvMmGrhm02IAN9v4sRWmg51571911mBMuKaiPhqGj7oQbSa 9NqtZYNME1Nhx7Boom4phakBXG6+U3FJMOae4g50WTu7wkUjZ5dVTZjPFHJPgaNIbD5jmxlynQ1 GXldTJ9N8kRiNrgY045lMsvpAt2g2cr28B0r421lIFRYwxWzI9VkD/4bvOrEhw2MaPAR2wPWCzA i1qQlcxdbCLvOHg== X-Mailer: b4 0.13-dev-26615 Message-ID: <20240108-rb-new-condvar-methods-v4-4-88e0c871cc05@google.com> Subject: [PATCH v4 4/4] rust: sync: update integer types in CondVar From: Alice Ryhl To: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , "=?utf-8?q?Bj=C3=B6rn_Roy_Baron?=" , Benno Lossin , Andreas Hindborg , Peter Zijlstra , Ingo Molnar , Will Deacon , Waiman Long , Tiago Lam , Thomas Gleixner Cc: Martin Rodriguez Reboredo , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Alice Ryhl Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Reduce the chances of compilation failures due to integer type mismatches in `CondVar`. When an integer is defined using a #define in C, bindgen doesn't know which integer type it is supposed to be, so it will just use `u32` by default (if it fits in an u32). Whenever the right type is something else, we insert a cast in Rust. However, this means that the code has a lot of extra casts, and sometimes the code will be missing casts if u32 happens to be correct on the developer's machine, even though the type might be something else on a different platform. This patch updates all uses of such constants in `rust/kernel/sync/condvar.rs` to use constants defined with the right type. This allows us to remove various unnecessary casts, while also future-proofing for the case where `unsigned int !=3D u32`. I wrote this patch at the suggestion of Benno in [1]. Link: https://lore.kernel.org/all/nAEg-6vbtX72ZY3oirDhrSEf06TBWmMiTt73EklMz= EAzN4FD4mF3TPEyAOxBZgZtjzoiaBYtYr3s8sa9wp1uYH9vEWRf2M-Lf4I0BY9rAgk=3D@proto= n.me/ [1] Suggested-by: Benno Lossin Reviewed-by: Tiago Lam Reviewed-by: Boqun Feng Reviewed-by: Benno Lossin Reviewed-by: Martin Rodriguez Reboredo Signed-off-by: Alice Ryhl --- rust/kernel/sync/condvar.rs | 39 +++++++++++++++++++-------------------- rust/kernel/task.rs | 15 ++++++++++++++- 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/rust/kernel/sync/condvar.rs b/rust/kernel/sync/condvar.rs index fa38c095cbe0..7f2b78e4abc7 100644 --- a/rust/kernel/sync/condvar.rs +++ b/rust/kernel/sync/condvar.rs @@ -7,11 +7,17 @@ =20 use super::{lock::Backend, lock::Guard, LockClassKey}; use crate::{ - bindings, init::PinInit, pin_init, str::CStr, task::MAX_SCHEDULE_TIMEO= UT, time::Jiffies, + bindings, + init::PinInit, + pin_init, + str::CStr, + task::{MAX_SCHEDULE_TIMEOUT, TASK_INTERRUPTIBLE, TASK_NORMAL, TASK_UNI= NTERRUPTIBLE}, + time::Jiffies, types::Opaque, }; -use core::ffi::c_long; +use core::ffi::{c_int, c_long}; use core::marker::PhantomPinned; +use core::ptr; use macros::pin_data; =20 /// Creates a [`CondVar`] initialiser with the given name and a newly-crea= ted lock class. @@ -108,7 +114,7 @@ pub fn new(name: &'static CStr, key: &'static LockClass= Key) -> impl PinInit( &self, - wait_state: u32, + wait_state: c_int, guard: &mut Guard<'_, T, B>, timeout_in_jiffies: c_long, ) -> c_long { @@ -119,7 +125,7 @@ fn wait_internal( =20 // SAFETY: Both `wait` and `wait_list` point to valid memory. unsafe { - bindings::prepare_to_wait_exclusive(self.wait_list.get(), wait= .get(), wait_state as _) + bindings::prepare_to_wait_exclusive(self.wait_list.get(), wait= .get(), wait_state) }; =20 // SAFETY: Switches to another thread. The timeout can be any numb= er. @@ -138,7 +144,7 @@ fn wait_internal( /// [`CondVar::notify_one`] or [`CondVar::notify_all`]. Note that it m= ay also wake up /// spuriously. pub fn wait(&self, guard: &mut Guard<'_, T, B>)= { - self.wait_internal(bindings::TASK_UNINTERRUPTIBLE, guard, MAX_SCHE= DULE_TIMEOUT); + self.wait_internal(TASK_UNINTERRUPTIBLE, guard, MAX_SCHEDULE_TIMEO= UT); } =20 /// Releases the lock and waits for a notification in interruptible mo= de. @@ -149,7 +155,7 @@ pub fn wait(&self, guard: &mut G= uard<'_, T, B>) { /// Returns whether there is a signal pending. #[must_use =3D "wait_interruptible returns if a signal is pending, so = the caller must check the return value"] pub fn wait_interruptible(&self, guard: &mut Gu= ard<'_, T, B>) -> bool { - self.wait_internal(bindings::TASK_INTERRUPTIBLE, guard, MAX_SCHEDU= LE_TIMEOUT); + self.wait_internal(TASK_INTERRUPTIBLE, guard, MAX_SCHEDULE_TIMEOUT= ); crate::current!().signal_pending() } =20 @@ -165,7 +171,7 @@ pub fn wait_interruptible_timeout( jiffies: Jiffies, ) -> CondVarTimeoutResult { let jiffies =3D jiffies.try_into().unwrap_or(MAX_SCHEDULE_TIMEOUT); - let res =3D self.wait_internal(bindings::TASK_INTERRUPTIBLE, guard= , jiffies); + let res =3D self.wait_internal(TASK_INTERRUPTIBLE, guard, jiffies); =20 match (res as Jiffies, crate::current!().signal_pending()) { (jiffies, true) =3D> CondVarTimeoutResult::Signal { jiffies }, @@ -174,17 +180,10 @@ pub fn wait_interruptible_timeout( } } =20 - /// Calls the kernel function to notify the appropriate number of thre= ads with the given flags. - fn notify(&self, count: i32, flags: u32) { + /// Calls the kernel function to notify the appropriate number of thre= ads. + fn notify(&self, count: c_int) { // SAFETY: `wait_list` points to valid memory. - unsafe { - bindings::__wake_up( - self.wait_list.get(), - bindings::TASK_NORMAL, - count, - flags as _, - ) - }; + unsafe { bindings::__wake_up(self.wait_list.get(), TASK_NORMAL, co= unt, ptr::null_mut()) }; } =20 /// Calls the kernel function to notify one thread synchronously. @@ -194,7 +193,7 @@ fn notify(&self, count: i32, flags: u32) { /// CPU. pub fn notify_sync(&self) { // SAFETY: `wait_list` points to valid memory. - unsafe { bindings::__wake_up_sync(self.wait_list.get(), bindings::= TASK_NORMAL) }; + unsafe { bindings::__wake_up_sync(self.wait_list.get(), TASK_NORMA= L) }; } =20 /// Wakes a single waiter up, if any. @@ -202,7 +201,7 @@ pub fn notify_sync(&self) { /// This is not 'sticky' in the sense that if no thread is waiting, th= e notification is lost /// completely (as opposed to automatically waking up the next waiter). pub fn notify_one(&self) { - self.notify(1, 0); + self.notify(1); } =20 /// Wakes all waiters up, if any. @@ -210,7 +209,7 @@ pub fn notify_one(&self) { /// This is not 'sticky' in the sense that if no thread is waiting, th= e notification is lost /// completely (as opposed to automatically waking up the next waiter). pub fn notify_all(&self) { - self.notify(0, 0); + self.notify(0); } } =20 diff --git a/rust/kernel/task.rs b/rust/kernel/task.rs index 17f14ebb8f48..6072b0de4a3e 100644 --- a/rust/kernel/task.rs +++ b/rust/kernel/task.rs @@ -5,11 +5,24 @@ //! C header: [`include/linux/sched.h`](srctree/include/linux/sched.h). =20 use crate::{bindings, types::Opaque}; -use core::{ffi::c_long, marker::PhantomData, ops::Deref, ptr}; +use core::{ + ffi::{c_int, c_long, c_uint}, + marker::PhantomData, + ops::Deref, + ptr, +}; =20 /// A sentinal value used for infinite timeouts. pub const MAX_SCHEDULE_TIMEOUT: c_long =3D c_long::MAX; =20 +/// Bitmask for tasks that are sleeping in an interruptible state. +pub const TASK_INTERRUPTIBLE: c_int =3D bindings::TASK_INTERRUPTIBLE as c_= int; +/// Bitmask for tasks that are sleeping in an uninterruptible state. +pub const TASK_UNINTERRUPTIBLE: c_int =3D bindings::TASK_UNINTERRUPTIBLE a= s c_int; +/// Convenience constant for waking up tasks regardless of whether they ar= e in interruptible or +/// uninterruptible sleep. +pub const TASK_NORMAL: c_uint =3D bindings::TASK_NORMAL as c_uint; + /// Returns the currently running task. #[macro_export] macro_rules! current { --=20 2.43.0.472.g3155946c3a-goog