From nobody Fri Dec 26 13:18:05 2025 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.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 132D4224E5 for ; Thu, 4 Jan 2024 14:03:21 +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="IqnZVKpq" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-5f53b4554b6so7868797b3.3 for ; Thu, 04 Jan 2024 06:03:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1704377001; x=1704981801; 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=4nl5Laek/JeiZg0YNg3sqHOoYp0ay3yEIwnurgk1eRc=; b=IqnZVKpqUiv4a36hQho72wHsmN/A2nmYPZrihEr74aZ4Ea7svlPWa0YdLzRIkBQnMx XJmWGcFJKttADMlRxkwN2aCmZdicoH3iSdn1AdLJKE7nhkoZt6BJtGeD0qsR2rUYr+TL ftQeJmMfqFZWSqzMkPXt6OAoJNJYoOmMUsGJDn+ahBO9629G9LKlgQ7zD1YeZbvNdQCI LgsA3D99PpbqaYy57cVxZ8IUOoDP6lDyAv9eg2lX4Hw5aULlMf0j0G3Sv8tQtFjP4DnZ 3tB43mUBEFylsmTU11BFqdQLlwgq2puGQVEfdtOba/FaVaPld4jWHMi+0lf78otrHO9U Wsrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704377001; x=1704981801; 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=4nl5Laek/JeiZg0YNg3sqHOoYp0ay3yEIwnurgk1eRc=; b=bH1aSgdVQjZIKR5uE9SAh+jTpQNe96lX2uJqkTpW2WcHmIt1uZ6Ts/fZK14HacENeD LGfvAZWyJzi4Z9G5vzZX3NyOxhpuat6kaafELaMyoK/PtNWLM3uwIJPbvsCLGRV3Nikm F9Y9TpiIUKyoaxgjj6mjz6BSd9117vgQO50XFTVEOE3ubZZwyXoBb4vOvFxm/oX16LEP txysg8n3vb5VImlchkQ/5JVjtXoB7B4TXO5H5x7kWsFVV4gvvlUiFo+XwjSp4Bd5iJYV hjuxokf7Z12IuD52YB7Y/PshcywlpNbW70tvx1Y1JY4svSon93lXBo3pP6tuG02cLUwC mBQw== X-Gm-Message-State: AOJu0YxaGBYPhDGlRfrSXFMMHKHLs7SDz3+NuXMGG42IfVBCe8v2Xxpn il+JseAo3TIHdcMC6725Q1mdoe3OhGDOoschE+c4mg== X-Google-Smtp-Source: AGHT+IFCnEuWSYcZWrzrOXwmm/NSIujkJ0d97NZXEeul8y+RyFZTh/7iS2+ieRyAOMuskBkMJEe5L0fwKdlbUYk= X-Received: from aliceryhl2.c.googlers.com ([fda3:e722:ac3:cc00:68:949d:c0a8:572]) (user=aliceryhl job=sendgmr) by 2002:a05:690c:3505:b0:5e6:1070:44e0 with SMTP id fq5-20020a05690c350500b005e6107044e0mr232456ywb.5.1704377001008; Thu, 04 Jan 2024 06:03:21 -0800 (PST) Date: Thu, 04 Jan 2024 14:02:41 +0000 In-Reply-To: <20240104-rb-new-condvar-methods-v3-0-70b514fcbe52@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240104-rb-new-condvar-methods-v3-0-70b514fcbe52@google.com> X-Developer-Key: i=aliceryhl@google.com; a=openpgp; fpr=49F6C1FAA74960F43A5B86A1EE7A392FDE96209F X-Developer-Signature: v=1; a=openpgp-sha256; l=1496; i=aliceryhl@google.com; h=from:subject:message-id; bh=AT+BWoH+O+fDVD5OmEd/gQgAkotIyd1eZrCsi0lUVI8=; b=owEBbQKS/ZANAwAKAQRYvu5YxjlGAcsmYgBllrqgh7qNEkMwomO40RdnkMaEmWiZlj97O2VAw KuwHwb/tveJAjMEAAEKAB0WIQSDkqKUTWQHCvFIvbIEWL7uWMY5RgUCZZa6oAAKCRAEWL7uWMY5 RgadD/9vwDNTS6iwH8e2XVzK5UYrNoHqg15+9X7+1OrMmdn3IlNLu0r7TIEzRcW4ZPfUtOkh92a XxI82/EtpEdPqm3h/OGdMjlEhaDn7vgmUyjQ9jqSQxqThOJGQ3VyIVP2PGO5m3F0dPYvYZPxmdq Vavfv4g208DOFcFXGLQCkwEDsxoeSzfysBO14wkzGvEgSkmqimDDN/b5mWvjUXJVcoZ+Qv9f5l9 jDi8JY0ys/OKrLMnAEry0/HHd+J+S5RVAyaCO8Az5IaVZh1dnKR5JcHncg7Qb55JUOdyKWMvqkp GQqajBg8cHRkORAcqPttcZLmjEc6hXnVQc+AQ1eMAqd59FzIAQjKr3NpLYexyHlj2dSEzMv8U9G Ck5fYS+kRO7tx6QlefDOWkK4MyQvVmVrSijMg7KMItapUH/BsGsrkrSOkhnN35g+jR89ZScyKs+ 3WV2HsvOIkMJjwH8wFBSMH0X0OJxUQ5iBtGbM+W2Peu8vCR5W87U8sqt3L/g7akymLzuWxwt4kd 1dg11wG6sOpWpj1N2TJkCOHSVICkhgfv0G/j8hY4s/rmF1GX3AfPbBuoKtZaUBLYYqCsCDf1TWJ jU7Q3Kt4Qiqktw6ES/Nkf6JqiZneVcYDKOONOmDAHzZfCv4r2j4WuQPy37dPFI9qC00BO9IF2z9 G33ogm6qgGBCSPA== X-Mailer: b4 0.13-dev-26615 Message-ID: <20240104-rb-new-condvar-methods-v3-1-70b514fcbe52@google.com> Subject: [PATCH v3 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 Signed-off-by: Alice Ryhl Reviewed-by: Boqun Feng --- rust/kernel/sync/condvar.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/rust/kernel/sync/condvar.rs b/rust/kernel/sync/condvar.rs index f65e19d5a37c..1a3f7b8e03dc 100644 --- a/rust/kernel/sync/condvar.rs +++ b/rust/kernel/sync/condvar.rs @@ -155,6 +155,12 @@ fn notify(&self, count: i32, flags: u32) { }; } =20 + /// Calls the kernel function to notify one thread synchronously. + 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 26 13:18:05 2025 Received: from mail-lj1-f202.google.com (mail-lj1-f202.google.com [209.85.208.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 290F822EF6 for ; Thu, 4 Jan 2024 14:03:25 +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="tC9ORHNy" Received: by mail-lj1-f202.google.com with SMTP id 38308e7fff4ca-2cd03f1b24bso5539481fa.0 for ; Thu, 04 Jan 2024 06:03:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1704377004; x=1704981804; 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=tC9ORHNy6QoR6B4TYQt9gNqVlmQs1ACK4sGo09SZWQai8RvV7jScTv/UiPplMbzZNW 7sYyu5sN3wjUTPNK9Czml5/Jh7qFo6TPTjU/CbWKhmL7DeveUlZVRn7xPEdYzctnbcg6 IeBpuvpB3O3R49g4szniHihILXy6BuT2cGmwsDS02A3J8S/4IkCq+a0XMbenkcDoytML 5xZMVOBl5WdiUC8Q6PF7QWvTD0UsutIXBDYpyfb4NTTT5E4punH6TfvA/DxKNz8h/s7X aGVgo1fD4Kmz/ZT3cnNhzuGJLzp5RaITCuAfwhORKdRrAWTGIhYc7UOjQh9w7FfcOK77 F8yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704377004; x=1704981804; 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=EQwckqWVzZK/7OtJ5HenRDGRhDnu24GtBh/8kQam1UpqxYfmXMCgOQ0N7ii8GNUZ7T RH/Hh9t5OhW40NZOuVjh+WOQ3Z2P1Ob5M4CL5ZUgg9JnYJlQfh2N+wfDbpMfom8hW+k1 RrFo8crUHfKEt8ALThIAY6ktIoZCZGgCfYpMmgb0vBRH9MsqrzWDuGdJI6TK6kmI3Sfo /+BtV8v5vcDFVc+ZO495K53giUMa21x98I8+y+8wWRA4aesBxWUpb/AYo5rfb9WP2Lk5 YXszu932Lg3IG4T3JpC9gHbqnVNXJoI0Wb91a+oSk0jkjY4N+zYNQ2y0i8vqGtqXbhMv r71w== X-Gm-Message-State: AOJu0YwGrRj1IQxnpAbSVoiOSUHHIum3zDxQqCF2aD30E/PoPS80KRRM mL1GTz16HnMNYpapROZDXCyppZ9rkMFLtS9BkwdmSg== X-Google-Smtp-Source: AGHT+IELjFaDM7ROjJaxp18Ms8IfQA7iRjeQ9qHX1i3T0MNVzQ4ejL88pbznMOE5OdBX0g7vTGq6MfKXN7GuOsI= X-Received: from aliceryhl2.c.googlers.com ([fda3:e722:ac3:cc00:68:949d:c0a8:572]) (user=aliceryhl job=sendgmr) by 2002:a2e:97ce:0:b0:2cc:e8cd:c15e with SMTP id m14-20020a2e97ce000000b002cce8cdc15emr1111ljj.4.1704377003781; Thu, 04 Jan 2024 06:03:23 -0800 (PST) Date: Thu, 04 Jan 2024 14:02:42 +0000 In-Reply-To: <20240104-rb-new-condvar-methods-v3-0-70b514fcbe52@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240104-rb-new-condvar-methods-v3-0-70b514fcbe52@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/ZANAwAKAQRYvu5YxjlGAcsmYgBllrqhTED+RqzR3DGEktEueQ+JDDTTkuSAC7YXM 8GqPGpOWRWJAjMEAAEKAB0WIQSDkqKUTWQHCvFIvbIEWL7uWMY5RgUCZZa6oQAKCRAEWL7uWMY5 RvdLD/95YfRPjzU4C6ejj3MZZi1uOUQ5JEy8zAgsnwEwRg7KjRm41K7YtnKhlSKDOYCYd2ujRQ4 MUQGC3KDpZeKiqZBSDvWBFGZ9f+5Drjm4BQm7zcvFKqgP/JGSQByEzvv8Tq1aqad8YBsHT1WNk1 TmUtuWFY3bWmxQF8rcKksMmSo4sqipN+3nGMeKPHN4li4Ubq39P/mpYJ3BWPf7wpR4Lozvvtlkj UC4fvQIjxi7YketJEDrtJzOAPB7Og65RaakngKqBabtEzmH+gOl/mzowmbhmPV02CJ/WJ8/Q6m+ xaPg10C0xKvwUjVvQDs/M95CX1RLjD92e6fGhaGOVVCbisqRJdSm3VPK6bjZKdctrfcfMNxHOxP wjS8H34nu+6R/c55v1aznjQXFXcFVZhLhZQjFXSOspWwzWxkChAT98aBCs7V8dTHcZKKm+bR4L4 A8kEpD97vAx/c/bG25K3sNRP+wzenJfYLFjrSenTmXI9UkFHHF+07GdCR1Tb9SrVtHpTDHaVfvt Nh4/4q/lBojDMVaXNKHBMhcwhWnQYbddNNqX4QDk0fiYN6k0wHQhAhFN0y5F7W806x8VbXEV8lS /HJIell9u/uNHy8GHm8owOr3AksMeQRm1oXaLv2sMU1u/Rwoh7Egz3lKlB8Quupqpz8UHHi9/94 348GYEmm7Am6CDA== X-Mailer: b4 0.13-dev-26615 Message-ID: <20240104-rb-new-condvar-methods-v3-2-70b514fcbe52@google.com> Subject: [PATCH v3 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 26 13:18:05 2025 Received: from mail-lj1-f202.google.com (mail-lj1-f202.google.com [209.85.208.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 C225422EE7 for ; Thu, 4 Jan 2024 14:03:28 +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="onSKsSN0" Received: by mail-lj1-f202.google.com with SMTP id 38308e7fff4ca-2cd0f4797cdso2722561fa.1 for ; Thu, 04 Jan 2024 06:03:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1704377007; x=1704981807; 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=o+8R7E0UuNwfrBBYP/dG/kUfPLmOpivCqqMG1y8N3o0=; b=onSKsSN0j/jWCfhTN7+v3yH5U4kReR2psLx5u/qTnMKiJo3n4kFoX7Xe0TeCOA01rh xUKVUVfZI+yNOKRm0z2TOSj6ylLYqKSqCTJ57M6cXhpo5VuyzugtMzzaJuUsECvzP2O3 xPGu78OOoPSShqUv+hsFTgirwdoUiN8LVMU5fmelzjGH0Y0TCXKQDKJB3xjZlP6SQXmm dX6fANfX8bICw3f/m7UFj1j6Eb4cZthpL0lq6DWGc/sSVKX1urs/0nQLNQXD5zyBHPmI ShRMqUNDuRqjgO6yZzxU0Mb0LmqMi1NZ9RbrBsdhCGSLMJKHT6Os4RUbw3a7nGD0Me3J EbVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704377007; x=1704981807; 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=o+8R7E0UuNwfrBBYP/dG/kUfPLmOpivCqqMG1y8N3o0=; b=m6Xux0MzlB5UNKUhQU2cY3/nZyQYNTeEOsdjEVe0i8RDbYuszgeniVsapER85ioArH IoaMmqrGUQyx/PQVx+JepJ7puqXbrw/QqNrRoMGKWCy7IO6EWqqVru/THv4f2NBOBGTU KZQGUYh3o1HvMnMxiSNWt/UpqJrSQ2DPp9bHHjtDETaVRn+zWp27Ni1RJcpg5uzZexBd DEHlwbGcQTGPz3/hVfmJBYaoiSpfqi7eD/ie0FCATzgFxU0h6Bodc6MFKvveBvLqn0UB vbV4y27fi5IjlOJAXQM58wdRHgOgJebeqyExa7qTjefeQblhP4mO1Tr/2vzFFFaz5cGc NUQg== X-Gm-Message-State: AOJu0YzNm9oGzDdbky3mNuMuK2PlwrFyksu3GuggTewadivTwAi5VYET xPiLLnwYAQ11K09t3j4CJjJZ401+GlNejmWYeEbpdA== X-Google-Smtp-Source: AGHT+IGl8A1p6fQqCDJweCOEeVljqninDIWiz53o44skQh4YSsN808QlJ3heLl7DnPzqnm/Yltfo2k2a1PmmlNc= X-Received: from aliceryhl2.c.googlers.com ([fda3:e722:ac3:cc00:68:949d:c0a8:572]) (user=aliceryhl job=sendgmr) by 2002:a05:651c:b2c:b0:2cc:b7b8:6912 with SMTP id b44-20020a05651c0b2c00b002ccb7b86912mr1171ljr.5.1704377006845; Thu, 04 Jan 2024 06:03:26 -0800 (PST) Date: Thu, 04 Jan 2024 14:02:43 +0000 In-Reply-To: <20240104-rb-new-condvar-methods-v3-0-70b514fcbe52@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240104-rb-new-condvar-methods-v3-0-70b514fcbe52@google.com> X-Developer-Key: i=aliceryhl@google.com; a=openpgp; fpr=49F6C1FAA74960F43A5B86A1EE7A392FDE96209F X-Developer-Signature: v=1; a=openpgp-sha256; l=6876; i=aliceryhl@google.com; h=from:subject:message-id; bh=+euJGe7tQyr0UpWz9qxwACBNwq68zsUCsYl+apHRTR8=; b=owEBbQKS/ZANAwAKAQRYvu5YxjlGAcsmYgBllrqhRcxqCWg+sbH2Q+HwYBPYNNu6EQC9UX6Hj l27pWaBmlaJAjMEAAEKAB0WIQSDkqKUTWQHCvFIvbIEWL7uWMY5RgUCZZa6oQAKCRAEWL7uWMY5 RnfYD/0ZGcdbch+1hwTs+W6fnN2Ly2KlTvkeaLl/vKw8Q0b0iqb5W5CceJ2DyMVQW9KFK3aWRLx d81P5BPtHyqHrNO8LPcDp+UIEz+aAcCrBWRNvn0mf2REz5u0+TJgNOOWoTATYes3Q9JuqXcAaS7 bw+4qGu+YZJUHPnhcWpvZO0lRYwpGQDLF/38/VJAkRaU6AvP6Toal5MWhXlBj22EZW0VwUaBZJy fLUa5qRROXHnnc7zIeFlsuggUUaESUeV7Pyf5r7lb3qe0+Mi5t0HQxoPYOAXwUdMEHcI0BlaXmz iFYk/MTN5oWAEhurBpiRIOAciBWDHrYFeenEvCj+Oc5H5XB5gdkBO45saC6qI6WVCBpBbrxrX+t Xm1PPQZgDcwEUZFd0kI+t/TL0LQzJIQHiKUDJBUaFti0wtZDFNXHynOguAEFHlys6smx2spAYMR RI24PHwHyxeRdeCLH+oqI4GXY9Zahdi0B3sUB3im8MQdGHrynCjfV7sh8YXWfiGnxXjL49Fbl4P VCQNdAG98tUcKfvQsbFcq8uOEm3ED+8Yp/nwNYAOWq9jP+020p44079RVh4udTgqE4xED6Vt7ne Is7xNlup1fGOMMyvlhD3y+MGKMi4Zv7yuqXgNTuoSnjLYK6srSgpuFcC36dZRCqiyfophW/pjVE v9xwlWn6THL2gIw== X-Mailer: b4 0.13-dev-26615 Message-ID: <20240104-rb-new-condvar-methods-v3-3-70b514fcbe52@google.com> Subject: [PATCH v3 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. Reviewed-by: Martin Rodriguez Reboredo Reviewed-by: Tiago Lam Signed-off-by: Alice Ryhl Reviewed-by: Boqun Feng --- rust/kernel/sync/condvar.rs | 60 ++++++++++++++++++++++++++++++++++++++++-= ---- rust/kernel/sync/lock.rs | 4 +-- rust/kernel/task.rs | 3 +++ 3 files changed, 59 insertions(+), 8 deletions(-) diff --git a/rust/kernel/sync/condvar.rs b/rust/kernel/sync/condvar.rs index 1a3f7b8e03dc..45ba57468717 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. @@ -177,3 +209,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..ffb4a51eb898 100644 --- a/rust/kernel/task.rs +++ b/rust/kernel/task.rs @@ -7,6 +7,9 @@ use crate::{bindings, types::Opaque}; use core::{marker::PhantomData, ops::Deref, ptr}; =20 +/// A sentinal value used for infinite timeouts. +pub const MAX_SCHEDULE_TIMEOUT: c_long =3D c_long::MAX; + /// Returns the currently running task. #[macro_export] macro_rules! current { --=20 2.43.0.472.g3155946c3a-goog From nobody Fri Dec 26 13:18:05 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 0B67F22EF6 for ; Thu, 4 Jan 2024 14:03:30 +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="MpP3uNpy" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dbdb69bc114so809165276.0 for ; Thu, 04 Jan 2024 06:03:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1704377010; x=1704981810; 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=t6X31kCDRUI3uFJo9bDSt6/FKb89NCMlltC27QfJIK4=; b=MpP3uNpySokGBerNjKuVTNbgmzid66IjEIqAmgXYitR3URei8WyDPFdekGf/h6zGP3 2Og6+gtrZXot5nv5f6tOKHg2QgVQygLNxpiAW76LlHtNxIb0tIsVONPwrctTRrEj+pBG gd88G8jcKhf+6AtMBNT1KLGn9pbaW5gDH1CGP7zisJAkyvv2XNwqCSG57uAfQh0Ye4VA zhMjLWcNgF/+QpnB2Li37xpyuXFbCUA2jkNB7+MJFbRmkuWwJbYcS/T6CN4J7vXPltnq bv04UxivIRhppOlivykUP2fKTMImULOkp9bf87p55riqDQqB5TYJXUS21rbazv+VMfLI V0sA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704377010; x=1704981810; 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=t6X31kCDRUI3uFJo9bDSt6/FKb89NCMlltC27QfJIK4=; b=ooZeX58AHF4+lFGYljIyRXI2qoCykHWezvoOnUHvkGGWHEFaig3m3ytDgcnC+TDZ07 ym/I7UmbhbbkV2C21EdfIP7hluFMvkJqeK2XwKXBV9lMRrbXaImo15ktfZmaGNj1UDZR qRVCatueaCt6CDYjDIBzHyXU98WaxwjZx8yCNZ46cz4neDyCQiYWyr+pzihem+NfNPUb qslQyuiDbO+ebITrWFDUHtIDzFiN347zgvIwF8d66ty75wmYpvX64NsfgoB8JlEjX0aH rBRsZ4C/zxLEo/3pOL0kmiuWT8aZiv7lDCQvgypqvG3ZDiB0SHnbQrWMQGa7BA1OjN0X Bgug== X-Gm-Message-State: AOJu0Yxsfx/0Io6BJK+m4NXoAFHDK5M9Z5LLU9Y9BButcNHmIK32EZPy B+8SbMuvPivdHlbYhdH5UAgdV3EawZTmQec0NuZcmw== X-Google-Smtp-Source: AGHT+IFyREhyOLKDNIEFYR9igaI9vjoUzPvyJ2L6d+OthJuiM7QhSGYrkrRzSIJEAA6v0viMhrEctUiX3M8cfvw= X-Received: from aliceryhl2.c.googlers.com ([fda3:e722:ac3:cc00:68:949d:c0a8:572]) (user=aliceryhl job=sendgmr) by 2002:a05:6902:1364:b0:dbe:4fc2:d6ef with SMTP id bt4-20020a056902136400b00dbe4fc2d6efmr205897ybb.12.1704377010105; Thu, 04 Jan 2024 06:03:30 -0800 (PST) Date: Thu, 04 Jan 2024 14:02:44 +0000 In-Reply-To: <20240104-rb-new-condvar-methods-v3-0-70b514fcbe52@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240104-rb-new-condvar-methods-v3-0-70b514fcbe52@google.com> X-Developer-Key: i=aliceryhl@google.com; a=openpgp; fpr=49F6C1FAA74960F43A5B86A1EE7A392FDE96209F X-Developer-Signature: v=1; a=openpgp-sha256; l=7330; i=aliceryhl@google.com; h=from:subject:message-id; bh=/7G4uhSpkApL3X8eWwX+diaXLDCkphXHPBdKHlkE0d8=; b=owEBbQKS/ZANAwAKAQRYvu5YxjlGAcsmYgBllrqi/dK4HMDso4VA0cdG9aelE29vaXIPUyDtV j+q/4tnKcKJAjMEAAEKAB0WIQSDkqKUTWQHCvFIvbIEWL7uWMY5RgUCZZa6ogAKCRAEWL7uWMY5 RgmtEACEy93s/x8XRXsLSAzoAyPzaFsQetb6R3p71mQveVzGmcM7fJxTfWxdwWvkuxZGCTq8biG Cfqv+9Rtdz9rwZ7CzoDRjFIkmjHEQTAXuovqmlkIOdB7+hoE+P+ZD49Ti5YWDJ973hchfmWwLHr oZw6UhdDVsNwtkn8rRc2jo/cqEcFXYyJSnno3EoUgFJ+kTcIsdJrsXBYaX0ef8hkVWzgrhQkliO ue409rw08E+4VjXSFP28IEF7+9ZsW9fgZAzugMRgk2bnWEDOwOIW3VJ7WYzhbfxD0xaTeqdgc8V NfOylH+Nue68iujCWh8naySF6ghRCWh5O2ImZOKb6eybgzuehis5fDfjkMg25WHxqtA4kg09SUY bty05vkJUFN7RxE3r9qdxS/Rijzcn9O97tJkqwV8o0ojwOrh75yZbTqXT/g737xnlcAfEoLVjA5 nVTPavvDpQOkOwYAgxeYw79ugElPjmMU/6qr2xxOti8Qqe+JXmJZIouzmWm86Ba9/RGO1/ir7rI g5UHkD3hUIpTBQ5YtJgSmsXbbWNUcynADUfU+lzDtAlfk9bHCB682Bp3xId8wzdpmmTsgeGtpe6 m64o8gvhvOT9g3x9sSjo3jehsfyRO9GoA65HoIJ6oDkiXVX1xtn2eCcDSrHIgrHjxni3smO4Ssr SxHJ5yP11+BkMaQ== X-Mailer: b4 0.13-dev-26615 Message-ID: <20240104-rb-new-condvar-methods-v3-4-70b514fcbe52@google.com> Subject: [PATCH v3 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 Signed-off-by: Alice Ryhl Reviewed-by: Martin Rodriguez Reboredo --- rust/kernel/sync/condvar.rs | 38 ++++++++++++++++++-------------------- rust/kernel/task.rs | 8 ++++++++ 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/rust/kernel/sync/condvar.rs b/rust/kernel/sync/condvar.rs index 45ba57468717..d907b8cb29eb 100644 --- a/rust/kernel/sync/condvar.rs +++ b/rust/kernel/sync/condvar.rs @@ -7,10 +7,15 @@ =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, c_uint}; use core::marker::PhantomPinned; use macros::pin_data; =20 @@ -108,7 +113,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 +124,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 +143,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 +154,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 +170,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,23 +179,16 @@ 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. 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. @@ -198,7 +196,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. @@ -206,7 +204,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 ffb4a51eb898..37468613ac0d 100644 --- a/rust/kernel/task.rs +++ b/rust/kernel/task.rs @@ -10,6 +10,14 @@ /// 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