Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/lockstat Make makelists() a little bit faster.
details: https://anonhg.NetBSD.org/src/rev/dd0c06a5a510
branches: trunk
changeset: 1008852:dd0c06a5a510
user: ad <ad%NetBSD.org@localhost>
date: Sat Apr 04 16:40:50 2020 +0000
description:
Make makelists() a little bit faster.
diffstat:
usr.sbin/lockstat/main.c | 22 ++++++++++++++++------
1 files changed, 16 insertions(+), 6 deletions(-)
diffs (79 lines):
diff -r a4fafe0d47c7 -r dd0c06a5a510 usr.sbin/lockstat/main.c
--- a/usr.sbin/lockstat/main.c Sat Apr 04 16:25:17 2020 +0000
+++ b/usr.sbin/lockstat/main.c Sat Apr 04 16:40:50 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.19 2013/03/06 11:49:06 yamt Exp $ */
+/* $NetBSD: main.c,v 1.20 2020/04/04 16:40:50 ad Exp $ */
/*-
* Copyright (c) 2006, 2007, 2009 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: main.c,v 1.19 2013/03/06 11:49:06 yamt Exp $");
+__RCSID("$NetBSD: main.c,v 1.20 2020/04/04 16:40:50 ad Exp $");
#endif /* not lint */
#include <sys/types.h>
@@ -70,9 +70,12 @@
typedef struct lock_head locklist_t;
TAILQ_HEAD(buf_head, lsbuf);
typedef struct buf_head buflist_t;
+SLIST_HEAD(bucket, lockstruct);
+typedef struct bucket bucket_t;
typedef struct lockstruct {
TAILQ_ENTRY(lockstruct) chain;
+ SLIST_ENTRY(lockstruct) bucket;
buflist_t bufs;
buflist_t tosort;
uintptr_t lock;
@@ -128,6 +131,9 @@
static locklist_t locklist;
static locklist_t freelist;
static locklist_t sortlist;
+static bucket_t bucket[256];
+
+#define HASH(a) (&bucket[((a) >> 6) & (__arraycount(bucket) - 1)])
static lsbuf_t *bufs;
static lsdisable_t ld;
@@ -604,14 +610,16 @@
{
lsbuf_t *lb, *lb2, *max;
lock_t *l, *l2;
+ bucket_t *bp;
int type;
+ size_t i;
/*
* Recycle lock_t structures from the last run.
*/
- while ((l = TAILQ_FIRST(&locklist)) != NULL) {
- TAILQ_REMOVE(&locklist, l, chain);
- TAILQ_INSERT_HEAD(&freelist, l, chain);
+ TAILQ_CONCAT(&freelist, &locklist, chain);
+ for (i = 0; i < __arraycount(bucket); i++) {
+ SLIST_INIT(&bucket[i]);
}
type = mask & LB_LOCK_MASK;
@@ -626,7 +634,8 @@
* Look for a record descibing this lock, and allocate a
* new one if needed.
*/
- TAILQ_FOREACH(l, &sortlist, chain) {
+ bp = HASH(lb->lb_lock);
+ SLIST_FOREACH(l, bp, bucket) {
if (l->lock == lb->lb_lock)
break;
}
@@ -643,6 +652,7 @@
TAILQ_INIT(&l->tosort);
TAILQ_INIT(&l->bufs);
TAILQ_INSERT_TAIL(&sortlist, l, chain);
+ SLIST_INSERT_HEAD(bp, l, bucket);
}
/*
Home |
Main Index |
Thread Index |
Old Index