git: a0842e69aa5f - main - lockprof: add contested-only profiling

Mateusz Guzik mjg at FreeBSD.org
Sat May 22 19:28:43 UTC 2021


The branch main has been updated by mjg:

URL: https://cgit.FreeBSD.org/src/commit/?id=a0842e69aa5f86d61c072544b540ef21b2015211

commit a0842e69aa5f86d61c072544b540ef21b2015211
Author:     Mateusz Guzik <mjg at FreeBSD.org>
AuthorDate: 2021-05-18 19:07:19 +0000
Commit:     Mateusz Guzik <mjg at FreeBSD.org>
CommitDate: 2021-05-22 19:28:37 +0000

    lockprof: add contested-only profiling
    
    This allows tracking all wait times with much smaller runtime impact.
    
    For example when doing -j 104 buildkernel on tmpfs:
    
    no profiling:   2921.70s user 282.72s system 6598% cpu 48.562 total
    all acquires:   2926.87s user 350.53s system 6656% cpu 49.237 total
    contested only: 2919.64s user 290.31s system 6583% cpu 48.756 total
---
 sys/kern/subr_lock.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/sys/kern/subr_lock.c b/sys/kern/subr_lock.c
index 97b880b54ea2..9c433f683bac 100644
--- a/sys/kern/subr_lock.c
+++ b/sys/kern/subr_lock.c
@@ -272,6 +272,7 @@ DPCPU_DEFINE_STATIC(struct lock_prof_cpu, lp);
 #define	LP_CPU(cpu)	(DPCPU_ID_PTR((cpu), lp))
 
 volatile int __read_mostly lock_prof_enable;
+int __read_mostly lock_contested_only;
 static volatile int lock_prof_resetting;
 
 #define LPROF_SBUF_SIZE		256
@@ -605,6 +606,8 @@ lock_profile_obtain_lock_success(struct lock_object *lo, int contested,
 	/* don't reset the timer when/if recursing */
 	if (!lock_prof_enable || (lo->lo_flags & LO_NOPROFILE))
 		return;
+	if (lock_contested_only && !contested)
+		return;
 	spin = (LOCK_CLASS(lo)->lc_flags & LC_SPINLOCK) ? 1 : 0;
 	if (spin && lock_prof_skipspin == 1)
 		return;
@@ -729,6 +732,8 @@ SYSCTL_INT(_debug_lock_prof, OID_AUTO, skipspin, CTLFLAG_RW,
     &lock_prof_skipspin, 0, "Skip profiling on spinlocks.");
 SYSCTL_INT(_debug_lock_prof, OID_AUTO, rejected, CTLFLAG_RD,
     &lock_prof_rejected, 0, "Number of rejected profiling records");
+SYSCTL_INT(_debug_lock_prof, OID_AUTO, contested_only, CTLFLAG_RW,
+    &lock_contested_only, 0, "Only profile contested acquires");
 SYSCTL_PROC(_debug_lock_prof, OID_AUTO, stats,
     CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, 0,
     dump_lock_prof_stats, "A",


More information about the dev-commits-src-main mailing list