From nobody Sun Feb 8 14:11:09 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0689617C21B for ; Wed, 5 Feb 2025 01:24:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738718673; cv=none; b=G62fqKSyOayA0bNXXIob3myJROBLObMDwzRSpPbbYyFT5eRCC3PXAlRq94KlxHZCEOVtL0tPXGQ+ahhRL6KiVEjpS8+f2XSY1rBaHCW2RarEi//4p/MplPh2z/xcmGSU8gOop0VRL5h8FIm0lZrnPfiYmJgdhj7dxVRcKh2BM1s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738718673; c=relaxed/simple; bh=xQnYCBQJlOCqN0QxyY/yXcLZ+NgzI2pqR3+zsf/WQWI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eRaJRBKJ8J4z0Di5Q3AUsLCcxwacHFHOocVFr7cMUc61Fpq1RZPnIFvlu6Eu++15y7eBGm2Xb68saWqlrOWdKfFGCu9UE0zoBg0WWJZTV2oJRg2lETQwVHGtarIJwOEjb1dA0530oIU+ulOqiYVRJ94KwpPxxvKPHSuQKspoGrk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=RSCTDdnf; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="RSCTDdnf" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738718669; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/2qiXC/cNFFNJmD/Jr1WU9cXX6QUwEFoWyQGXl5gh0Q=; b=RSCTDdnfe581fQketCtw2xStbQ6oAgQxb4ivoGNS2PqunUEq2/TfVm39l8gypElb9Irege FTQoJzHWP6pjxrWMIuL+5rg+wobWBGxnrWSY4QJ6rMLLBjnRDEz7YKb5/+Wm/YmARymOKg 1wBaInzNSDhjwwFJbDyTsnbNVkh6DCM= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-645-VTOGUOs_M_-y3ZxivJYLaw-1; Tue, 04 Feb 2025 20:24:24 -0500 X-MC-Unique: VTOGUOs_M_-y3ZxivJYLaw-1 X-Mimecast-MFC-AGG-ID: VTOGUOs_M_-y3ZxivJYLaw Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8273F180034D; Wed, 5 Feb 2025 01:24:23 +0000 (UTC) Received: from llong-thinkpadp16vgen1.westford.csb (unknown [10.22.81.83]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 15EBE19560A7; Wed, 5 Feb 2025 01:24:21 +0000 (UTC) From: Waiman Long To: Peter Zijlstra , Ingo Molnar , Will Deacon , Boqun Feng Cc: linux-kernel@vger.kernel.org, Waiman Long Subject: [PATCH v2 1/2] locking/lock_events: Add locking events for rtmutex slow paths Date: Tue, 4 Feb 2025 20:24:10 -0500 Message-ID: <20250205012411.1010817-2-longman@redhat.com> In-Reply-To: <20250205012411.1010817-1-longman@redhat.com> References: <20250205012411.1010817-1-longman@redhat.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 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" Add locking events for rtlock_slowlock() and rt_mutex_slowlock() for profiling the slow path behavior of rt_spin_lock() and rt_mutex_lock(). Signed-off-by: Waiman Long --- kernel/locking/lock_events_list.h | 21 +++++++++++++++++++++ kernel/locking/rtmutex.c | 29 ++++++++++++++++++++++++----- 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/kernel/locking/lock_events_list.h b/kernel/locking/lock_events= _list.h index 97fb6f3f840a..80b11f194c9f 100644 --- a/kernel/locking/lock_events_list.h +++ b/kernel/locking/lock_events_list.h @@ -67,3 +67,24 @@ LOCK_EVENT(rwsem_rlock_handoff) /* # of read lock handof= fs */ LOCK_EVENT(rwsem_wlock) /* # of write locks acquired */ LOCK_EVENT(rwsem_wlock_fail) /* # of failed write lock acquisitions */ LOCK_EVENT(rwsem_wlock_handoff) /* # of write lock handoffs */ + +/* + * Locking events for rtlock_slowlock() + */ +LOCK_EVENT(rtlock_slowlock) /* # of rtlock_slowlock() calls */ +LOCK_EVENT(rtlock_slow_acq1) /* # of locks acquired after wait_lock */ +LOCK_EVENT(rtlock_slow_acq2) /* # of locks acquired in for loop */ +LOCK_EVENT(rtlock_slow_sleep) /* # of sleeps */ +LOCK_EVENT(rtlock_slow_wake) /* # of wakeup's */ + +/* + * Locking events for rt_mutex_slowlock() + */ +LOCK_EVENT(rtmutex_slowlock) /* # of rt_mutex_slowlock() calls */ +LOCK_EVENT(rtmutex_slow_block) /* # of rt_mutex_slowlock_block() calls */ +LOCK_EVENT(rtmutex_slow_acq1) /* # of locks acquired after wait_lock */ +LOCK_EVENT(rtmutex_slow_acq2) /* # of locks acquired at the end */ +LOCK_EVENT(rtmutex_slow_acq3) /* # of locks acquired in *block() */ +LOCK_EVENT(rtmutex_slow_sleep) /* # of sleeps */ +LOCK_EVENT(rtmutex_slow_wake) /* # of wakeup's */ +LOCK_EVENT(rtmutex_deadlock) /* # of rt_mutex_handle_deadlock()'s */ diff --git a/kernel/locking/rtmutex.c b/kernel/locking/rtmutex.c index 4a8df1800cbb..c80902eacd79 100644 --- a/kernel/locking/rtmutex.c +++ b/kernel/locking/rtmutex.c @@ -27,6 +27,7 @@ #include =20 #include "rtmutex_common.h" +#include "lock_events.h" =20 #ifndef WW_RT # define build_ww_mutex() (false) @@ -1612,10 +1613,13 @@ static int __sched rt_mutex_slowlock_block(struct r= t_mutex_base *lock, struct task_struct *owner; int ret =3D 0; =20 + lockevent_inc(rtmutex_slow_block); for (;;) { /* Try to acquire the lock: */ - if (try_to_take_rt_mutex(lock, current, waiter)) + if (try_to_take_rt_mutex(lock, current, waiter)) { + lockevent_inc(rtmutex_slow_acq3); break; + } =20 if (timeout && !timeout->task) { ret =3D -ETIMEDOUT; @@ -1638,8 +1642,10 @@ static int __sched rt_mutex_slowlock_block(struct rt= _mutex_base *lock, owner =3D NULL; raw_spin_unlock_irq_wake(&lock->wait_lock, wake_q); =20 - if (!owner || !rtmutex_spin_on_owner(lock, waiter, owner)) + if (!owner || !rtmutex_spin_on_owner(lock, waiter, owner)) { + lockevent_inc(rtmutex_slow_sleep); rt_mutex_schedule(); + } =20 raw_spin_lock_irq(&lock->wait_lock); set_current_state(state); @@ -1694,6 +1700,7 @@ static int __sched __rt_mutex_slowlock(struct rt_mute= x_base *lock, int ret; =20 lockdep_assert_held(&lock->wait_lock); + lockevent_inc(rtmutex_slowlock); =20 /* Try to acquire the lock again: */ if (try_to_take_rt_mutex(lock, current, NULL)) { @@ -1701,6 +1708,7 @@ static int __sched __rt_mutex_slowlock(struct rt_mute= x_base *lock, __ww_mutex_check_waiters(rtm, ww_ctx, wake_q); ww_mutex_lock_acquired(ww, ww_ctx); } + lockevent_inc(rtmutex_slow_acq1); return 0; } =20 @@ -1719,10 +1727,12 @@ static int __sched __rt_mutex_slowlock(struct rt_mu= tex_base *lock, __ww_mutex_check_waiters(rtm, ww_ctx, wake_q); ww_mutex_lock_acquired(ww, ww_ctx); } + lockevent_inc(rtmutex_slow_acq2); } else { __set_current_state(TASK_RUNNING); remove_waiter(lock, waiter); rt_mutex_handle_deadlock(ret, chwalk, lock, waiter); + lockevent_inc(rtmutex_deadlock); } =20 /* @@ -1751,6 +1761,7 @@ static inline int __rt_mutex_slowlock_locked(struct r= t_mutex_base *lock, &waiter, wake_q); =20 debug_rt_mutex_free_waiter(&waiter); + lockevent_cond_inc(rtmutex_slow_wake, !wake_q_empty(wake_q)); return ret; } =20 @@ -1823,9 +1834,12 @@ static void __sched rtlock_slowlock_locked(struct rt= _mutex_base *lock, struct task_struct *owner; =20 lockdep_assert_held(&lock->wait_lock); + lockevent_inc(rtlock_slowlock); =20 - if (try_to_take_rt_mutex(lock, current, NULL)) + if (try_to_take_rt_mutex(lock, current, NULL)) { + lockevent_inc(rtlock_slow_acq1); return; + } =20 rt_mutex_init_rtlock_waiter(&waiter); =20 @@ -1838,8 +1852,10 @@ static void __sched rtlock_slowlock_locked(struct rt= _mutex_base *lock, =20 for (;;) { /* Try to acquire the lock again */ - if (try_to_take_rt_mutex(lock, current, &waiter)) + if (try_to_take_rt_mutex(lock, current, &waiter)) { + lockevent_inc(rtlock_slow_acq2); break; + } =20 if (&waiter =3D=3D rt_mutex_top_waiter(lock)) owner =3D rt_mutex_owner(lock); @@ -1847,8 +1863,10 @@ static void __sched rtlock_slowlock_locked(struct rt= _mutex_base *lock, owner =3D NULL; raw_spin_unlock_irq_wake(&lock->wait_lock, wake_q); =20 - if (!owner || !rtmutex_spin_on_owner(lock, &waiter, owner)) + if (!owner || !rtmutex_spin_on_owner(lock, &waiter, owner)) { + lockevent_inc(rtlock_slow_sleep); schedule_rtlock(); + } =20 raw_spin_lock_irq(&lock->wait_lock); set_current_state(TASK_RTLOCK_WAIT); @@ -1865,6 +1883,7 @@ static void __sched rtlock_slowlock_locked(struct rt_= mutex_base *lock, debug_rt_mutex_free_waiter(&waiter); =20 trace_contention_end(lock, 0); + lockevent_cond_inc(rtlock_slow_wake, !wake_q_empty(wake_q)); } =20 static __always_inline void __sched rtlock_slowlock(struct rt_mutex_base *= lock) --=20 2.48.1 From nobody Sun Feb 8 14:11:09 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F1FD32288EC for ; Wed, 5 Feb 2025 01:24:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738718674; cv=none; b=cvZjF/LwTZ3Qt7oDgpTtDdt5krKcf28LEgrINOmUurstbmXbj6Fqs+UXbZSCpjXe+VqtX2BGiFMbPfFa3fIgI3vfB9mc02Vkxi022KcxKCRekf8f9hbChaYZ54UQh0A/hINnZ6J2rYr/ys3ZBBeQhj7bzSESsdI3Uok/MbfnJTc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738718674; c=relaxed/simple; bh=TVEENQAbPwLp6C/o1+q59FDJJdF/TlCGEjdhKfaJLYQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Bq5VI1Lq5N7suw2tuEICJpVCXplxBOrxSilGT8p8j2haHu7c5MjlIF5tpj8IiFn7A25jeCyz9N+uGn5EsIS6qAg9R85sVL0EBifvfKCHUow9ms8CivL8KDMkmrUd5xW5cXG3Ep0acImCTVbOMYdvq8Nm5umSnzXYHNGqXlJmvO0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=eradGjax; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="eradGjax" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738718670; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZFm1KAh5+e0ZWlMGLR27yG0A4EUFGm+Oe3V+3icJKEw=; b=eradGjaxlnUAw7n8IhZrYGgrj9KMKdrxrGGKfMqFQa1aojLKd3qyV9cqR9xNXFKCaAZ26K SuoYZsyh+8brZvsWPG2gRLPWzOllJ1KRtFtU9AdRPk+kopkPNGMyPP9zFmBOeKLCIO7wrB MaoCtzjdjZDP6QWPCMAmpBtGjtseVSY= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-633-a_F49qJaPrS2WDZd9Di-jQ-1; Tue, 04 Feb 2025 20:24:26 -0500 X-MC-Unique: a_F49qJaPrS2WDZd9Di-jQ-1 X-Mimecast-MFC-AGG-ID: a_F49qJaPrS2WDZd9Di-jQ Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6DEB51956052; Wed, 5 Feb 2025 01:24:25 +0000 (UTC) Received: from llong-thinkpadp16vgen1.westford.csb (unknown [10.22.81.83]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id EE9AB19560A7; Wed, 5 Feb 2025 01:24:23 +0000 (UTC) From: Waiman Long To: Peter Zijlstra , Ingo Molnar , Will Deacon , Boqun Feng Cc: linux-kernel@vger.kernel.org, Waiman Long Subject: [PATCH v2 2/2] locking/lockdep: Disable KASAN instrumentation of lockdep.c Date: Tue, 4 Feb 2025 20:24:11 -0500 Message-ID: <20250205012411.1010817-3-longman@redhat.com> In-Reply-To: <20250205012411.1010817-1-longman@redhat.com> References: <20250205012411.1010817-1-longman@redhat.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 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" Both KASAN and LOCKDEP are commonly enabled in building a debug kernel. Each of them can significantly slow down the speed of a debug kernel. Enabling KASAN instrumentation of the LOCKDEP code will further slow thing down. Since LOCKDEP is a high overhead debugging tool, it will never get enabled in a production kernel. The LOCKDEP code is also pretty mature and is unlikely to get major changes. There is also a possibility of recursion similar to KCSAN. As the small advantage of enabling KASAN instrumentation to catch potential memory access error is probably not worth the drawback of further slowing down a debug kernel, disable KASAN instrumentation to enable a debug kernel to gain some performance back. With debug kernels with both LOCKDEP and KASAN enabled running on a 2-socket 128-thread x86-64 system and a 80-core arm64 system, the times (real and sys with the time command) to do a parallel kernel build are shown below. Kernel type Real Time Sys Time ----------- --------- -------- x86-64: Non-debug kernel 9m38.528s 304m17.007s Debug kernel before patch 16m38.765s 1086m34.930s Debug kernel after patch 16m4.758s 1025m26.335s Before/after % change -3.4% -5.6% Non-debug RT kernel 11m32.804s 121m52.835s Debug RT kernel before patch 59m29.618s 1772m30.699s Debug RT kernel after patch 37m47.089s 937m56.856s Before/after % change -36.5% -47.1% arm64: Debug RT kernel before patch 46m9.385s 676m13.605s Debug RT kernel after patcha 33m41.428s 436m3.430s Before/after % change -27.0% -35.5% It looks like the KASAN instrumentation overhead is less on arm64. While the performance benefit for non-RT debug kernel is modest, the performance gain for RT debug kernel is significant. Looking at the RT kernel locking event data for the x86-64 system, we have Event type Non-debug Debug before patch Debug after patch ---------- --------- ------------------ ----------------- rtlock_slowlock 66,593,828 2,868,760,165 2,832,990,386 rtlock_slow_acq1 43,705,130 2,833,575,907 2,800,928,283 rtlock_slow_acq2 22,888,698 35,177,418 32,055,592 rtlock_slow_sleep 22,568,560 29,206,559 27,833,274 rtmutex_slowlock 468,207 560,080 549,080 rtmutex_slow_acq1 11,840 67,208 39,353 rtmutex_slow_block 456,367 492,872 509,727 rtmutex_slow_sleep 258,071 208,019 220,480 The profile of the debug kernel before and after patch are similar. Compared with the non-debug kernel, the number of rtlock_slowlock() has increased significantly by more than 40x. That means the corresponding wait_lock has to be acquired that many more times with the associated lockdep overhead. The average lock nesting depth will also be higher. The non-RT debug kernel doesn't have this extra overhead. Signed-off-by: Waiman Long --- kernel/locking/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/locking/Makefile b/kernel/locking/Makefile index 0db4093d17b8..a114949eeed5 100644 --- a/kernel/locking/Makefile +++ b/kernel/locking/Makefile @@ -5,7 +5,8 @@ KCOV_INSTRUMENT :=3D n =20 obj-y +=3D mutex.o semaphore.o rwsem.o percpu-rwsem.o =20 -# Avoid recursion lockdep -> sanitizer -> ... -> lockdep. +# Avoid recursion lockdep -> sanitizer -> ... -> lockdep & improve perform= ance. +KASAN_SANITIZE_lockdep.o :=3D n KCSAN_SANITIZE_lockdep.o :=3D n =20 ifdef CONFIG_FUNCTION_TRACER --=20 2.48.1