Re: [PATCH RFC 05/11] rust: sync: Add dummy LockClassKey implementation for !CONFIG_LOCKDEP

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 7/14/23 06:13, Asahi Lina wrote:
Lock classes aren't used without lockdep. The C side declares the key
as an empty struct in that case, but let's make it an explicit ZST in
Rust, implemented in a separate module. This allows us to more easily
guarantee that the lockdep code will be trivially optimized out without
CONFIG_LOCKDEP, including LockClassKey arguments that are passed around.

Depending on whether CONFIG_LOCKDEP is enabled or not, we then import
the real lockdep implementation or the dummy one.

Signed-off-by: Asahi Lina <lina@xxxxxxxxxxxxx>
---
  rust/kernel/sync.rs            | 29 ++++++++---------------------
  rust/kernel/sync/lockdep.rs    | 27 +++++++++++++++++++++++++++
  rust/kernel/sync/no_lockdep.rs | 19 +++++++++++++++++++
  3 files changed, 54 insertions(+), 21 deletions(-)

diff --git a/rust/kernel/sync.rs b/rust/kernel/sync.rs
index d219ee518eff..352472c6b77a 100644
--- a/rust/kernel/sync.rs
+++ b/rust/kernel/sync.rs
@@ -5,37 +5,24 @@
  //! This module contains the kernel APIs related to synchronisation that have been ported or
  //! wrapped for usage by Rust code in the kernel.
-use crate::types::Opaque;
-
  mod arc;
  mod condvar;
  pub mod lock;
  mod locked_by;
+#[cfg(CONFIG_LOCKDEP)]
+mod lockdep;
+#[cfg(not(CONFIG_LOCKDEP))]
+mod no_lockdep;

Some care must be taken wrt how is it going to appear in the resulting
documentation, I think it can lead to missing details. `#[cfg(doc)]`
should be considered.

+#[cfg(not(CONFIG_LOCKDEP))]
+use no_lockdep as lockdep;
[...]



[Index of Archives]     [Linux&nblp;USB Development]     [Linux Media]     [Video for Linux]     [Linux Audio Users]     [Yosemite Secrets]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux