Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 24 Oct 2013 14:05:42 +0300
From:      Andriy Gapon <avg@FreeBSD.org>
To:        dtrace@FreeBSD.org
Subject:   lockstat
Message-ID:  <5268FF06.2000304@FreeBSD.org>

next in thread | raw e-mail | index | archive | help

I see that there is a certain discrepancy between what userland lockstat expects
and what kernel lockstat provides.

1. Right now the reports are produced only for spinlocks and mutexes.  Userland
lockstat does know about sx locks and has incorrect expectations about rw locks.

2. Kernel lockstat does not cover rm locks and lockmgr locks.

3. Spinning statistic is provided in units of spin loop count.  In illumos it
seems to be provided in nanoseconds just like for blocking.

4. lockstat(1) manual pages is not installed.  I guess that this is because it
is not in compliance with FreeBSD manual page formatting.

Some thoughts.

First, regarding #3.  It is certainly hard comparing apples to oranges,
especially when adaptive behavior is enabled, so there is some spinning and some
blocking for the same locks.
On the other hand, maintaining a loop count is very cheap.  Always doing some
timing would incur some overhead.

Would it be worth while switching to nanoseconds report for spinning?
Perhaps there is some way to apply the DTrace principle of not introducing
overhead unless a probe is actually used to the lockstat probes?
Currently, it is not so - the measurement are taken regardless of whether they
will be going anywhere.

Regarding #1.
I came up with the following patch.  It is WIP.  If you'd have any improvements
or suggestions for it, please share.
Please note that some things like lock upgrades and downgrades are still not
reported at all.

commit d4bbb4e9a2a2fc071676ac356f1b7ab5678d1784
Author: Andriy Gapon <avg@icyb.net.ua>
Date:   Sun Oct 20 13:16:44 2013 +0300

    [wip] lockstat: teach about freebsd sx and rw locks

    Consider preserving original solaris/illumos code under ifdef.

diff --git a/cddl/contrib/opensolaris/cmd/lockstat/lockstat.c
b/cddl/contrib/opensolaris/cmd/lockstat/lockstat.c
index 0a609d7..8b9e956 100644
--- a/cddl/contrib/opensolaris/cmd/lockstat/lockstat.c
+++ b/cddl/contrib/opensolaris/cmd/lockstat/lockstat.c
@@ -142,26 +142,30 @@ typedef struct ls_event_info {
 } ls_event_info_t;

 static ls_event_info_t g_event_info[LS_MAX_EVENTS] = {
-	{ 'C',	"Lock",	"Adaptive mutex spin",			"nsec",
+	{ 'C',	"Lock",	"Adaptive mutex spin",			"count",
 	    "lockstat:::adaptive-spin" },
 	{ 'C',	"Lock",	"Adaptive mutex block",			"nsec",
 	    "lockstat:::adaptive-block" },
-	{ 'C',	"Lock",	"Spin lock spin",			"nsec",
+	{ 'C',	"Lock",	"Spin lock spin",			"count",
 	    "lockstat:::spin-spin" },
-	{ 'C',	"Lock",	"Thread lock spin",			"nsec",
+	{ 'C',	"Lock",	"Thread lock spin",			"count",
 	    "lockstat:::thread-spin" },
-	{ 'C',	"Lock",	"R/W writer blocked by writer",		"nsec",
-	    "lockstat:::rw-block", "arg2 == 0 && arg3 == 1" },
-	{ 'C',	"Lock",	"R/W writer blocked by readers",	"nsec",
-	    "lockstat:::rw-block", "arg2 == 0 && arg3 == 0 && arg4" },
-	{ 'C',	"Lock",	"R/W reader blocked by writer",		"nsec",
-	    "lockstat:::rw-block", "arg2 != 0 && arg3 == 1" },
-	{ 'C',	"Lock",	"R/W reader blocked by write wanted",	"nsec",
-	    "lockstat:::rw-block", "arg2 != 0 && arg3 == 0 && arg4" },
-	{ 'C',	"Lock",	"Unknown event (type 8)",		"units"	},
-	{ 'C',	"Lock",	"Unknown event (type 9)",		"units"	},
-	{ 'C',	"Lock",	"Unknown event (type 10)",		"units"	},
-	{ 'C',	"Lock",	"Unknown event (type 11)",		"units"	},
+	{ 'C',	"Lock",	"R/W writer spin",			"count",
+	    "lockstat::rw_wlock:rw-spin" },
+	{ 'C',	"Lock",	"R/W writer block",			"nsec",
+	    "lockstat::rw_wlock:rw-block" },
+	{ 'C',	"Lock",	"R/W reader spin",			"count",
+	    "lockstat::rw_rlock:rw-spin" },
+	{ 'C',	"Lock",	"R/W reader block",			"nsec",
+	    "lockstat::rw_rlock:rw-block" },
+	{ 'C',	"Lock",	"SX shared spin",			"count",
+	    "lockstat::sx_slock:sx-spin" },
+	{ 'C',	"Lock",	"SX shared block",			"nsec",
+	    "lockstat::sx_slock:sx-block" },
+	{ 'C',	"Lock",	"SX exclsuive spin",			"count",
+	    "lockstat::sx_xlock:sx-spin" },
+	{ 'C',	"Lock",	"SX exclsuive block",			"nsec",
+	    "lockstat::sx_xlock:sx-block" },
 	{ 'C',	"Lock",	"Unknown event (type 12)",		"units"	},
 	{ 'C',	"Lock",	"Unknown event (type 13)",		"units"	},
 	{ 'C',	"Lock",	"Unknown event (type 14)",		"units"	},
@@ -189,13 +193,17 @@ static ls_event_info_t g_event_info[LS_MAX_EVENTS] = {
 	    "lockstat:::spin-release", NULL,
 	    "lockstat:::spin-acquire" },
 	{ 'H',	"Lock",	"R/W writer hold",			"nsec",
-	    "lockstat:::rw-release", "arg1 == 0",
-	    "lockstat:::rw-acquire" },
+	    "lockstat::rw_wunlock:rw-release", NULL,
+	    "lockstat::rw_wlock:rw-acquire" },
 	{ 'H',	"Lock",	"R/W reader hold",			"nsec",
-	    "lockstat:::rw-release", "arg1 != 0",
-	    "lockstat:::rw-acquire" },
-	{ 'H',	"Lock",	"Unknown event (type 36)",		"units"	},
-	{ 'H',	"Lock",	"Unknown event (type 37)",		"units"	},
+	    "lockstat::rw_runlock:rw-release", NULL,
+	    "lockstat::rw_rlock:rw-acquire" },
+	{ 'H',	"Lock",	"SX shared hold",			"nsec",
+	    "lockstat::sx_sunlock:sx-release", NULL,
+	    "lockstat::sx_slock:sx-acquire" },
+	{ 'H',	"Lock",	"SX exclusive hold",			"nsec",
+	    "lockstat::sx_xunlock:sx-release", NULL,
+	    "lockstat::sx_xlock:sx-acquire" },
 	{ 'H',	"Lock",	"Unknown event (type 38)",		"units"	},
 	{ 'H',	"Lock",	"Unknown event (type 39)",		"units"	},
 	{ 'H',	"Lock",	"Unknown event (type 40)",		"units"	},

-- 
Andriy Gapon



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?5268FF06.2000304>