Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys As with turnstiles, don't bother allocating sleepq locks...



details:   https://anonhg.NetBSD.org/src/rev/fd9b18fc53b7
branches:  trunk
changeset: 847281:fd9b18fc53b7
user:      ad <ad%NetBSD.org@localhost>
date:      Mon Dec 16 19:43:36 2019 +0000

description:
As with turnstiles, don't bother allocating sleepq locks with mutex_obj_alloc(),
and avoid the indirect reference.

diffstat:

 sys/kern/kern_sleepq.c |   8 ++++----
 sys/sys/sleepq.h       |  16 +++++++++++-----
 2 files changed, 15 insertions(+), 9 deletions(-)

diffs (94 lines):

diff -r e63c4171f45a -r fd9b18fc53b7 sys/kern/kern_sleepq.c
--- a/sys/kern/kern_sleepq.c    Mon Dec 16 19:22:15 2019 +0000
+++ b/sys/kern/kern_sleepq.c    Mon Dec 16 19:43:36 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_sleepq.c,v 1.54 2019/12/06 21:36:10 ad Exp $      */
+/*     $NetBSD: kern_sleepq.c,v 1.55 2019/12/16 19:43:36 ad Exp $      */
 
 /*-
  * Copyright (c) 2006, 2007, 2008, 2009, 2019 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_sleepq.c,v 1.54 2019/12/06 21:36:10 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_sleepq.c,v 1.55 2019/12/16 19:43:36 ad Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -66,7 +66,7 @@
 
 /* General purpose sleep table, used by mtsleep() and condition variables. */
 sleeptab_t     sleeptab __cacheline_aligned;
-kmutex_t       *sleepq_locks[SLEEPTAB_HASH_SIZE] __read_mostly;
+sleepqlock_t   sleepq_locks[SLEEPTAB_HASH_SIZE] __cacheline_aligned;
 
 /*
  * sleeptab_init:
@@ -79,7 +79,7 @@
        int i;
 
        for (i = 0; i < SLEEPTAB_HASH_SIZE; i++) {
-               sleepq_locks[i] = mutex_obj_alloc(MUTEX_DEFAULT, IPL_SCHED);
+               mutex_init(&sleepq_locks[i].lock, MUTEX_DEFAULT, IPL_SCHED);
                sleepq_init(&st->st_queue[i]);
        }
 }
diff -r e63c4171f45a -r fd9b18fc53b7 sys/sys/sleepq.h
--- a/sys/sys/sleepq.h  Mon Dec 16 19:22:15 2019 +0000
+++ b/sys/sys/sleepq.h  Mon Dec 16 19:43:36 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sleepq.h,v 1.26 2019/11/21 18:56:55 ad Exp $   */
+/*     $NetBSD: sleepq.h,v 1.27 2019/12/16 19:43:36 ad Exp $   */
 
 /*-
  * Copyright (c) 2002, 2006, 2007, 2008, 2009, 2019 The NetBSD Foundation, Inc.
@@ -38,6 +38,7 @@
 #include <sys/queue.h>
 #include <sys/sched.h>
 #include <sys/syncobj.h>
+#include <sys/param.h>
 
 /*
  * Generic sleep queues.
@@ -72,6 +73,11 @@
 extern sleeptab_t      sleeptab;
 
 #ifdef _KERNEL
+typedef union {
+       kmutex_t        lock;
+       uint8_t         pad[COHERENCY_UNIT];
+} sleepqlock_t;
+
 /*
  * Return non-zero if it is unsafe to sleep.
  *
@@ -92,13 +98,13 @@
 static __inline sleepq_t *
 sleeptab_lookup(sleeptab_t *st, wchan_t wchan, kmutex_t **mp)
 {
-       extern kmutex_t *sleepq_locks[SLEEPTAB_HASH_SIZE];
+       extern sleepqlock_t sleepq_locks[SLEEPTAB_HASH_SIZE];
        sleepq_t *sq;
        u_int hash;
 
        hash = SLEEPTAB_HASH(wchan);
        sq = &st->st_queue[hash];
-       *mp = sleepq_locks[hash];
+       *mp = &sleepq_locks[hash].lock;
        mutex_spin_enter(*mp);
        return sq;
 }
@@ -106,10 +112,10 @@
 static __inline kmutex_t *
 sleepq_hashlock(wchan_t wchan)
 {
-       extern kmutex_t *sleepq_locks[SLEEPTAB_HASH_SIZE];
+       extern sleepqlock_t sleepq_locks[SLEEPTAB_HASH_SIZE];
        kmutex_t *mp;
 
-       mp = sleepq_locks[SLEEPTAB_HASH(wchan)];
+       mp = &sleepq_locks[SLEEPTAB_HASH(wchan)].lock;
        mutex_spin_enter(mp);
        return mp;
 }



Home | Main Index | Thread Index | Old Index