From nobody Fri Dec 19 17:10:45 2025 Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) (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 2963D2147F2; Thu, 10 Apr 2025 22:57:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744325845; cv=none; b=UYLr9L5fqc9sqBwu+mmdpfQwU7YAymPfeiOIPZ8BfGTZe/pmfsjdSXz9uOgn23iMZZUiTguidcanZnmeL70mcsdqO67rxvg7Vb2w396X8rojZc7RpI/VM7h848EOkBGOoWXl7En03G7HZuxNKI75SAgHbuLvHDFN5SjeHlx9CaM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744325845; c=relaxed/simple; bh=44hc9zuqD5c5l3KpyWGERcYfSBH+nS55jrSfL+gj7MA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VolUflNRK1BIG/sjD4GQaZa2o4L+TQImkmAqWaHYKl0xFcaRuEX4Znoa9r+gxLWiXaEBS2WSEAUS9T4kwgByV87pro6G7G1vt0mdoiHt25KE0Jx1UyPhMJCaw7sJAf+oZ0dWXkePCiJXYvGYXD+3nbbuL6eYdyQJHvLKRmhwtXU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=gnXPirEd; arc=none smtp.client-ip=209.85.210.180 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gnXPirEd" Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-736ad42dfd6so1123059b3a.3; Thu, 10 Apr 2025 15:57:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1744325843; x=1744930643; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YZC/8XYUFzMPhY1/PlvlTMwaJN2OFho3U0y3Hj8cMxo=; b=gnXPirEdflVRrwblPqCeXMf8bs8Ba5vcZengozIWJaKk7FspZztvs7l7V5NyEuo1Db 81VboViroaqH/9difeubQ/PO5jrSxFja5WabxaLrKloYFmxuLF3W366Pq/oTM3F9XM2z fQhOc9YJz6ysCyVMRJMvuPs4iwC8226l2z6fNSpD0bmsbi1pCKPi8fPyTq1iLvDvohCP l+DSDnnTUqOkYfLctOMsgKtj84MiDuvDa3iyExfn5E3FSvaxUlYSPAuNdJjktUHp2KeF p5Odm7TFWoMUpGr6bwiwYhx+5oYOPURUb1ZdVqcCbL5hIGH3fJvVqupyA0wtKSXO8pWz l9fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744325843; x=1744930643; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YZC/8XYUFzMPhY1/PlvlTMwaJN2OFho3U0y3Hj8cMxo=; b=i25KxNyUa6ysi8P3Kp19U5xoSe9TkBm7qUSHs+m7sLwNYG/3Z5wwlnslYHHo9nr61L F3ZlYKpCZKFrd71zP0cUsejwhYPXnnIZOWupVCn+Q4j1FuCbNbSsqql00GD7dwbayOzX XZHDuBIgSPEZ1HLBAn89tf5i77QX++IAfLtV5ysLOkFgBdep7WzfGtwQp9LFpVLG+9UV 6o6RqO8TrIZiK7DGaqGve+87sq+GtlKl/eKkGDk6YXsYUq8yPQrapHYOrj/WA3zPK/0Z IWRFP1SPAGNg/CsMDHyNUJpV6W3KajVK5SG/C/4b2JO/+7h2jIyGy63hpzAnqJm5t8S/ arAQ== X-Forwarded-Encrypted: i=1; AJvYcCWbDYmzfK86zMO1jU4/Syqxj0xX+NwrW/wEgWPZWMhHEDJVUe196QDXA4g53/LnlJSVP0b8Q6GLSjG5mI14ow==@vger.kernel.org X-Gm-Message-State: AOJu0YyGCJh8+RwvJKnPnVxqJkWlwPgYo7rQ9VByHxHIsTqENyTlvNd2 L8bYEOgAl2L6eVa5nRtzgvujAjGgEiJkiPfKiCTEyrfjNpCr8Z4OcF52Kmdj X-Gm-Gg: ASbGnctEE8rX+xOAomLbzRzKaZ8/lAHrvph/dL6R4bb+DBhQ3dLzsH+OzD5dyAASo9q 4A33KWOXV5Z8PeMRT3mTqxxHyz2faoLyakqnDMI43e6Ft6zonbcxsaNiw+TLuNY/KY9rrGvo5+X LGvXLuy+OLbB/4LvxDFORjw5MopZEvNEWB6TemvXMxTI4IGHj5rDqrKN5VuX+FFPuSQjP/Oe/Qt /Ku1hPIVjnHC9pFwCPRJKiK+ZXONpNxOUGj25fyBg9ZF4HWnmvGuSFaOPL99hAi+LAAzpFodY97 ktspnHgGns3YRJbgqhqexv+XDUJa9Gt97zn+uEJDJ80zDaLltFjkSJKBGRc3pjdq1xhVoLPazMg eV93qSxrfzqHslGSNSILOyiUZjMLj X-Google-Smtp-Source: AGHT+IHfyN0izXPCScO0Wr5me+oHiguigL9HGscPJd/AwlucwwI4JrxrXiSNV2QtdprpUOSL674sDA== X-Received: by 2002:a05:6a21:1512:b0:1fd:e9c8:cf3b with SMTP id adf61e73a8af0-20179972e20mr1063116637.30.1744325843095; Thu, 10 Apr 2025 15:57:23 -0700 (PDT) Received: from mew.. (p4204131-ipxg22701hodogaya.kanagawa.ocn.ne.jp. [153.160.176.131]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-b02a2d3a5e5sm3583310a12.54.2025.04.10.15.57.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Apr 2025 15:57:22 -0700 (PDT) From: FUJITA Tomonori To: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org Cc: Daniel Almeida , Alice Ryhl , Boqun Feng , ojeda@kernel.org, alex.gaynor@gmail.com, gary@garyguo.net, bjorn3_gh@protonmail.com, benno.lossin@proton.me, a.hindborg@samsung.com, tmgross@umich.edu, dakr@kernel.org, mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, vschneid@redhat.com, pmladek@suse.com Subject: [PATCH v2 1/2] sched/core: Add __might_sleep_precision() Date: Fri, 11 Apr 2025 07:56:22 +0900 Message-ID: <20250410225623.152616-2-fujita.tomonori@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250410225623.152616-1-fujita.tomonori@gmail.com> References: <20250410225623.152616-1-fujita.tomonori@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add __might_sleep_precision(), Rust friendly version of __might_sleep(), which takes a pointer to a string with the length instead of a null-terminated string. Rust's core::panic::Location::file(), which gives the file name of a caller, doesn't provide a null-terminated string. __might_sleep_precision() uses a precision specifier in the printk format, which specifies the length of a string; a string doesn't need to be a null-terminated. Modify __might_sleep() to call __might_sleep_precision() but the impact should be negligible. When printing the error (sleeping function called from invalid context), the precision string format is used instead of the simple string format; the precision specifies the the maximum length of the displayed string. Note that Location::file() providing a null-terminated string for better C interoperability is under discussion [1]. [1]: https://github.com/rust-lang/libs-team/issues/466 Tested-by: Daniel Almeida Reviewed-by: Alice Ryhl Co-developed-by: Boqun Feng Signed-off-by: Boqun Feng Signed-off-by: FUJITA Tomonori --- include/linux/kernel.h | 2 ++ kernel/sched/core.c | 62 ++++++++++++++++++++++++++++-------------- 2 files changed, 43 insertions(+), 21 deletions(-) diff --git a/include/linux/kernel.h b/include/linux/kernel.h index be2e8c0a187e..086ee1dc447e 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -87,6 +87,7 @@ extern int dynamic_might_resched(void); #ifdef CONFIG_DEBUG_ATOMIC_SLEEP extern void __might_resched(const char *file, int line, unsigned int offse= ts); extern void __might_sleep(const char *file, int line); +extern void __might_sleep_precision(const char *file, int len, int line); extern void __cant_sleep(const char *file, int line, int preempt_offset); extern void __cant_migrate(const char *file, int line); =20 @@ -145,6 +146,7 @@ extern void __cant_migrate(const char *file, int line); static inline void __might_resched(const char *file, int line, unsigned int offsets) { } static inline void __might_sleep(const char *file, int line) { } +static inline void __might_sleep_precision(const char *file, int len, int = line) { } # define might_sleep() do { might_resched(); } while (0) # define cant_sleep() do { } while (0) # define cant_migrate() do { } while (0) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index c81cf642dba0..6e87d997d03a 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -8730,24 +8730,6 @@ void __init sched_init(void) =20 #ifdef CONFIG_DEBUG_ATOMIC_SLEEP =20 -void __might_sleep(const char *file, int line) -{ - unsigned int state =3D get_current_state(); - /* - * Blocking primitives will set (and therefore destroy) current->state, - * since we will exit with TASK_RUNNING make sure we enter with it, - * otherwise we will destroy state. - */ - WARN_ONCE(state !=3D TASK_RUNNING && current->task_state_change, - "do not call blocking ops when !TASK_RUNNING; " - "state=3D%x set at [<%p>] %pS\n", state, - (void *)current->task_state_change, - (void *)current->task_state_change); - - __might_resched(file, line, 0); -} -EXPORT_SYMBOL(__might_sleep); - static void print_preempt_disable_ip(int preempt_offset, unsigned long ip) { if (!IS_ENABLED(CONFIG_DEBUG_PREEMPT)) @@ -8769,7 +8751,8 @@ static inline bool resched_offsets_ok(unsigned int of= fsets) return nested =3D=3D offsets; } =20 -void __might_resched(const char *file, int line, unsigned int offsets) +static void __might_resched_precision(const char *file, int file_len, int = line, + unsigned int offsets) { /* Ratelimiting timestamp: */ static unsigned long prev_jiffy; @@ -8792,8 +8775,8 @@ void __might_resched(const char *file, int line, unsi= gned int offsets) /* Save this before calling printk(), since that will clobber it: */ preempt_disable_ip =3D get_preempt_disable_ip(current); =20 - pr_err("BUG: sleeping function called from invalid context at %s:%d\n", - file, line); + pr_err("BUG: sleeping function called from invalid context at %.*s:%d\n", + file_len, file, line); pr_err("in_atomic(): %d, irqs_disabled(): %d, non_block: %d, pid: %d, nam= e: %s\n", in_atomic(), irqs_disabled(), current->non_block_count, current->pid, current->comm); @@ -8818,8 +8801,45 @@ void __might_resched(const char *file, int line, uns= igned int offsets) dump_stack(); add_taint(TAINT_WARN, LOCKDEP_STILL_OK); } + +/* + * The precision in vsnprintf() specifies the maximum length of the + * displayed string. The precision needs to be larger than the actual + * length of the string, so a sufficiently large value should be used + * for the filename length. + */ +#define MAX_FILENAME_LEN (1<<14) + +void __might_resched(const char *file, int line, unsigned int offsets) +{ + __might_resched_precision(file, MAX_FILENAME_LEN, line, offsets); +} EXPORT_SYMBOL(__might_resched); =20 +void __might_sleep_precision(const char *file, int len, int line) +{ + unsigned int state =3D get_current_state(); + /* + * Blocking primitives will set (and therefore destroy) current->state, + * since we will exit with TASK_RUNNING make sure we enter with it, + * otherwise we will destroy state. + */ + WARN_ONCE(state !=3D TASK_RUNNING && current->task_state_change, + "do not call blocking ops when !TASK_RUNNING; " + "state=3D%x set at [<%p>] %pS\n", state, + (void *)current->task_state_change, + (void *)current->task_state_change); + + __might_resched_precision(file, len, line, 0); +} +EXPORT_SYMBOL_GPL(__might_sleep_precision); + +void __might_sleep(const char *file, int line) +{ + __might_sleep_precision(file, MAX_FILENAME_LEN, line); +} +EXPORT_SYMBOL(__might_sleep); + void __cant_sleep(const char *file, int line, int preempt_offset) { static unsigned long prev_jiffy; --=20 2.43.0 From nobody Fri Dec 19 17:10:45 2025 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) (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 E70162147F8; Thu, 10 Apr 2025 22:57:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744325850; cv=none; b=QOlYbJtWcXwi6R7VxXb3DYg9Ow2qx9lUAJ5Wt6m8AdaB4XP+oKI5pOAuTG2FQphshDGnHaFyaGWEMMS/SltVlm2sHJkxO5mx/0AhPcV4ONO4nXi1hXG3u8V4qDb3x9qUQAf4pFq65VDPm7P9r60BDi80SpLIkTJUpc0PlwrFC38= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744325850; c=relaxed/simple; bh=uUChC6aPedVbKyzSDiXONrNtk2WsfGQ3jMuQEgpC1ZE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KZHqB0O1u10+9eKaMWGxdvR6+wjF/zQlch+SF0OSuzu/Xr5jN6ayq17qJ9a3L7X5eWYdig1pPAbv3cUH67BqZnIJwXZZ3VtcYR2fm0zF6uZ1FpiTDsqXuLoFKnCvo44W9Lp7DTl1fA5VgGRJZdLegQus/kuYhF/CBfE0jbtKLG4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ndRhp6F8; arc=none smtp.client-ip=209.85.210.178 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ndRhp6F8" Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-736c277331eso2397075b3a.1; Thu, 10 Apr 2025 15:57:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1744325848; x=1744930648; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fDaI71ukgOzKfgXg3PENYNxKpxCB71oqs08Zj0uR+HI=; b=ndRhp6F83OnallbAjHVtjCNRvcRjm+/uRVYFwo5CvMJ2K2O3z0l4HiAfM4WHHrjOk1 d3YCKk3ZpHVdcSMKgFfeWMx+1IllGDtUfmIq6W2fhsEFZ328iHpJ+GzZbs0pn7i0lIlf APZnNkeAXfAkFfzoJ1f+oUduNewDAcp/zf9Y3Zlr935qEfUooKHbBb3QpM29At1fwYpQ zf8QI6LHvCgegyOCCnRW/bk/ji10KuCNpH22/qtzl3gsYDYgQ6Imywjoxc9UMkkBXKnm t5S3TjLB1TRXXvDGgc3iIerEWhn1cmw1AiLqBs/xqSTd6B6PK3FJHBZWWyYnQCN7jY7Z hMqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744325848; x=1744930648; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fDaI71ukgOzKfgXg3PENYNxKpxCB71oqs08Zj0uR+HI=; b=AN3CktsFGD3B0YZkOQTUB/Aa4dTUV+xrpUC2E56L3hRw6zODx0BHi7I7txYcmiOn1K 8PKRaexeZbxbJaxxvV0J8aD49Cyhr4T+R6Xez2ysWxzGsNIAw+ELu5KD9roxPU85yTPB MQfcI2mBtovtNGfo292s18meokXf1TAP7kfChP+PinOT2W8Xo8qJmPUfc7fDMb35LqyK qvHPldS98hUr9mXH6eE4U3BC00WyZOAMs69Pun1pvXYxV/t8l5+OPn0KRt6Uf3L7tUmg i2XlgbKtlMAP0i9Mb6a9mDXbEf4r6EGJ/PBRHI+hPcfkdbj5cQVNlwrG2j94EuIjmurq BRFQ== X-Forwarded-Encrypted: i=1; AJvYcCWR2xzg3+bM8T8swlmFD2GYDuXceHsVobqB99l0eCsGpsmSqYlzhzX74xRhI45NoeKYFBzlYwFlGSOp1MmYSg==@vger.kernel.org X-Gm-Message-State: AOJu0Yzz9fEdONGigUZr/LJ/GcAH2dHXNrRT8M2XHb99mduAwUiP5oiE jY+UDIJpU712ieAGBA0BlvlvU7Yb6CSLxStYebAFYCHD/NM//0QpF9e+To73 X-Gm-Gg: ASbGncv+PSfATE7exmBvUVoUVC9RVq46rSeGtpnsCgAVkOdXKl3JxA1FE5m5+OvWKMk kHOPpBVJornC7oQeOdHE19GLNULvLtiLFuSN5Or4OhsCCe0jdtVJIvABEkbnhQ+hrAWpllsDNMx +jcGxx9XO/H0oJV0WDBWzSPRttgv4CqHF/L3HuX+OT/m4xkiVc49lzMeWUUXv/xSAVAUCPLB0H3 hcVCKqPaIpKqntk/lfLUe5u1jdWADhKNIfVW2Vt4qWPCo85bub2EMhqbdNU0AthYchIKOnHdOaJ QEBgHWBYuUYvJl/EUisL0VAX9A2gkD5jxDRXxaWVkP6T2LPTELFEV9Ai5S61da5ZaTenBm9mkF9 9xd5Br66TdUKmx2KCKw== X-Google-Smtp-Source: AGHT+IH8q3ZGmd1kwt5qEP9Rbm+ZNhvGO6seXqKH5UCkW/KlOVFiqskOAizEDU0ptgB5pG/CXKDGBA== X-Received: by 2002:a05:6a00:2e29:b0:736:bced:f4cf with SMTP id d2e1a72fcca58-73bd0a0df56mr1042450b3a.0.1744325847824; Thu, 10 Apr 2025 15:57:27 -0700 (PDT) Received: from mew.. (p4204131-ipxg22701hodogaya.kanagawa.ocn.ne.jp. [153.160.176.131]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-b02a2d3a5e5sm3583310a12.54.2025.04.10.15.57.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Apr 2025 15:57:27 -0700 (PDT) From: FUJITA Tomonori To: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org Cc: boqun.feng@gmail.com, ojeda@kernel.org, alex.gaynor@gmail.com, gary@garyguo.net, bjorn3_gh@protonmail.com, benno.lossin@proton.me, a.hindborg@samsung.com, aliceryhl@google.com, tmgross@umich.edu, dakr@kernel.org, mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, vschneid@redhat.com, pmladek@suse.com Subject: [PATCH v2 2/2] rust: task: add Rust version of might_sleep() Date: Fri, 11 Apr 2025 07:56:23 +0900 Message-ID: <20250410225623.152616-3-fujita.tomonori@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250410225623.152616-1-fujita.tomonori@gmail.com> References: <20250410225623.152616-1-fujita.tomonori@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Adds a helper function equivalent to the C's might_sleep(), which serves as a debugging aid and a potential scheduling point. Note that this function can only be used in a nonatomic context. This will be used by Rust version of read_poll_timeout(). Signed-off-by: FUJITA Tomonori Reviewed-by: Alice Ryhl --- rust/helpers/task.c | 6 ++++++ rust/kernel/task.rs | 28 ++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/rust/helpers/task.c b/rust/helpers/task.c index 31c33ea2dce6..2c85bbc2727e 100644 --- a/rust/helpers/task.c +++ b/rust/helpers/task.c @@ -1,7 +1,13 @@ // SPDX-License-Identifier: GPL-2.0 =20 +#include #include =20 +void rust_helper_might_resched(void) +{ + might_resched(); +} + struct task_struct *rust_helper_get_current(void) { return current; diff --git a/rust/kernel/task.rs b/rust/kernel/task.rs index 9e6f6854948d..bb1102f6cc02 100644 --- a/rust/kernel/task.rs +++ b/rust/kernel/task.rs @@ -380,3 +380,31 @@ fn eq(&self, other: &Kuid) -> bool { } =20 impl Eq for Kuid {} + +/// Annotation for functions that can sleep. +/// +/// Equivalent to the C side [`might_sleep()`], this function serves as +/// a debugging aid and a potential scheduling point. +/// +/// This function can only be used in a nonatomic context. +#[track_caller] +#[inline] +pub fn might_sleep() { + #[cfg(CONFIG_DEBUG_ATOMIC_SLEEP)] + { + let loc =3D core::panic::Location::caller(); + let file =3D loc.file(); + + // SAFETY: `file.as_ptr()` is valid for reading for `file.len()` b= ytes. + unsafe { + crate::bindings::__might_sleep_precision( + file.as_ptr().cast(), + file.len() as i32, + loc.line() as i32, + ) + } + } + + // SAFETY: Always safe to call. + unsafe { crate::bindings::might_resched() } +} --=20 2.43.0