From cb33d6f71e47198ea3aa8826ec62f5514def0ab7 Mon Sep 17 00:00:00 2001 From: Tengda Wu Date: Wed, 25 Jun 2025 20:23:41 +0800 Subject: [PATCH] debug spinlock --- ...k-Micro-optimize-pending-state-waiti.patch | 64 +++++++++++++++++++ kernel.spec | 8 ++- 2 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 0001-locking-qspinlock-Micro-optimize-pending-state-waiti.patch diff --git a/0001-locking-qspinlock-Micro-optimize-pending-state-waiti.patch b/0001-locking-qspinlock-Micro-optimize-pending-state-waiti.patch new file mode 100644 index 00000000..6f2c97e1 --- /dev/null +++ b/0001-locking-qspinlock-Micro-optimize-pending-state-waiti.patch @@ -0,0 +1,64 @@ +From 2bb647beaedde3107be87418e353bd78e9c97e76 Mon Sep 17 00:00:00 2001 +From: Guo Ren +Date: Wed, 4 Jan 2023 21:19:52 -0500 +Subject: [PATCH] locking/qspinlock: Micro-optimize pending state waiting for + unlock + +mainline inclusion +from mainline-5.10 +commit 4282494a20cdcaf38d553f2c2ff6f252084f979c +category: bugfix +bugzilla: https://gitee.com/openeuler/kernel/issues/IC9OLM + +Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?h=linux-5.10.y&id=4282494a20cdcaf38d553f2c2ff6f252084f979c + +------------------------------- + +When we're pending, we only care about lock value. The xchg_tail +wouldn't affect the pending state. That means the hardware thread +could stay in a sleep state and leaves the rest execution units' +resources of pipeline to other hardware threads. This situation is +the SMT scenarios in the same core. Not an entering low-power state +situation. Of course, the granularity between cores is "cacheline", +but the granularity between SMT hw threads of the same core could +be "byte" which internal LSU handles. For example, when a hw-thread +yields the resources of the core to other hw-threads, this patch +could help the hw-thread stay in the sleep state and prevent it +from being woken up by other hw-threads xchg_tail. + +Signed-off-by: Guo Ren +Signed-off-by: Guo Ren +Signed-off-by: Ingo Molnar +Signed-off-by: cheliequan +Acked-by: Waiman Long +Link: https://lore.kernel.org/r/20230105021952.3090070-1-guoren@kernel.org +Cc: Peter Zijlstra +--- + kernel/locking/qspinlock.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/kernel/locking/qspinlock.c b/kernel/locking/qspinlock.c +index 8c1a21b53913..f75311a8dd16 100644 +--- a/kernel/locking/qspinlock.c ++++ b/kernel/locking/qspinlock.c +@@ -401,7 +401,7 @@ void queued_spin_lock_slowpath(struct qspinlock *lock, u32 val) + /* + * We're pending, wait for the owner to go away. + * +- * 0,1,1 -> 0,1,0 ++ * 0,1,1 -> *,1,0 + * + * this wait loop must be a load-acquire such that we match the + * store-release that clears the locked bit and create lock +@@ -410,7 +410,7 @@ void queued_spin_lock_slowpath(struct qspinlock *lock, u32 val) + * barriers. + */ + if (val & _Q_LOCKED_MASK) +- atomic_cond_read_acquire(&lock->val, !(VAL & _Q_LOCKED_MASK)); ++ smp_cond_load_acquire(&lock->locked, !VAL); + + /* + * take ownership and clear the pending bit. +-- +2.25.1 + diff --git a/kernel.spec b/kernel.spec index ca61740f..18ac73c8 100644 --- a/kernel.spec +++ b/kernel.spec @@ -11,7 +11,7 @@ %global upstream_sublevel 0 %global devel_release 216 %global maintenance_release .0.0 -%global pkg_release .115 +%global pkg_release .666.debug %define with_debuginfo 1 # Do not recompute the build-id of vmlinux in find-debuginfo.sh @@ -79,6 +79,8 @@ Source9002: series.conf Source9998: patches.tar.bz2 %endif +Patch0001: 0001-locking-qspinlock-Micro-optimize-pending-state-waiti.patch + #BuildRequires: BuildRequires: module-init-tools, patch >= 2.5.4, bash >= 2.03, tar BuildRequires: bzip2, xz, findutils, gzip, m4, perl, make >= 3.78, diffutils, gawk @@ -284,6 +286,10 @@ package or when debugging this package.\ tar -xjf %{SOURCE9998} %endif +cd kernel +%patch0001 -p1 +cd - + mv kernel linux-%{KernelVer} cd linux-%{KernelVer} -- Gitee