CVS commit: src/lib/libc/stdlib

2023-10-14 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Oct 14 19:39:34 UTC 2023

Modified Files:
src/lib/libc/stdlib: jemalloc.c

Log Message:
A few more branch hints.


To generate a diff of this commit:
cvs rdiff -u -r1.62 -r1.63 src/lib/libc/stdlib/jemalloc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/stdlib/jemalloc.c
diff -u src/lib/libc/stdlib/jemalloc.c:1.62 src/lib/libc/stdlib/jemalloc.c:1.63
--- src/lib/libc/stdlib/jemalloc.c:1.62	Sat Oct 14 19:38:51 2023
+++ src/lib/libc/stdlib/jemalloc.c	Sat Oct 14 19:39:33 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: jemalloc.c,v 1.62 2023/10/14 19:38:51 ad Exp $	*/
+/*	$NetBSD: jemalloc.c,v 1.63 2023/10/14 19:39:33 ad Exp $	*/
 
 /*-
  * Copyright (C) 2006,2007 Jason Evans .
@@ -111,7 +111,7 @@
 
 #include 
 /* __FBSDID("$FreeBSD: src/lib/libc/stdlib/malloc.c,v 1.147 2007/06/15 22:00:16 jasone Exp $"); */
-__RCSID("$NetBSD: jemalloc.c,v 1.62 2023/10/14 19:38:51 ad Exp $");
+__RCSID("$NetBSD: jemalloc.c,v 1.63 2023/10/14 19:39:33 ad Exp $");
 
 #include "namespace.h"
 #include 
@@ -3699,7 +3699,7 @@ calloc(size_t num, size_t size)
 	ret = icalloc(num_size);
 
 RETURN:
-	if (ret == NULL) {
+	if (__predict_false(ret == NULL)) {
 		if (OPT(xmalloc)) {
 			_malloc_message(getprogname(),
 			": (malloc) Error in calloc(): out of memory\n", "",
@@ -3734,7 +3734,7 @@ realloc(void *ptr, size_t size)
 
 		ret = iralloc(ptr, size);
 
-		if (ret == NULL) {
+		if (__predict_false(ret == NULL)) {
 			if (OPT(xmalloc)) {
 _malloc_message(getprogname(),
 ": (malloc) Error in realloc(): out of "
@@ -3749,7 +3749,7 @@ realloc(void *ptr, size_t size)
 		else
 			ret = imalloc(size);
 
-		if (ret == NULL) {
+		if (__predict_false(ret == NULL)) {
 			if (OPT(xmalloc)) {
 _malloc_message(getprogname(),
 ": (malloc) Error in realloc(): out of "
@@ -3770,7 +3770,7 @@ free(void *ptr)
 {
 
 	UTRACE(ptr, 0, 0);
-	if (ptr != NULL) {
+	if (__predict_true(ptr != NULL)) {
 		assert(malloc_initialized);
 
 		idalloc(ptr);



CVS commit: src/lib/libc/stdlib

2023-10-14 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Oct 14 19:39:34 UTC 2023

Modified Files:
src/lib/libc/stdlib: jemalloc.c

Log Message:
A few more branch hints.


To generate a diff of this commit:
cvs rdiff -u -r1.62 -r1.63 src/lib/libc/stdlib/jemalloc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/lib/libc/stdlib

2023-10-14 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Oct 14 19:38:51 UTC 2023

Modified Files:
src/lib/libc/stdlib: jemalloc.c

Log Message:
Cherry pick a fix from FreeBSD:

commit 80bc871bdd4a8254ce19a65a54c8c918dd3ddd11
Author: Konstantin Belousov 
Date:   Sat Sep 12 18:16:46 2009 +

MFC r196861:
Handle zero size for posix_memalign. Return NULL or unique address
according to the 'V' option.


To generate a diff of this commit:
cvs rdiff -u -r1.61 -r1.62 src/lib/libc/stdlib/jemalloc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/stdlib/jemalloc.c
diff -u src/lib/libc/stdlib/jemalloc.c:1.61 src/lib/libc/stdlib/jemalloc.c:1.62
--- src/lib/libc/stdlib/jemalloc.c:1.61	Sat Oct 14 19:37:24 2023
+++ src/lib/libc/stdlib/jemalloc.c	Sat Oct 14 19:38:51 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: jemalloc.c,v 1.61 2023/10/14 19:37:24 ad Exp $	*/
+/*	$NetBSD: jemalloc.c,v 1.62 2023/10/14 19:38:51 ad Exp $	*/
 
 /*-
  * Copyright (C) 2006,2007 Jason Evans .
@@ -111,7 +111,7 @@
 
 #include 
 /* __FBSDID("$FreeBSD: src/lib/libc/stdlib/malloc.c,v 1.147 2007/06/15 22:00:16 jasone Exp $"); */
-__RCSID("$NetBSD: jemalloc.c,v 1.61 2023/10/14 19:37:24 ad Exp $");
+__RCSID("$NetBSD: jemalloc.c,v 1.62 2023/10/14 19:38:51 ad Exp $");
 
 #include "namespace.h"
 #include 
@@ -3632,6 +3632,15 @@ posix_memalign(void **memptr, size_t ali
 			goto RETURN;
 		}
 
+		if (size == 0) {
+			if (NOT_OPT(sysv))
+size = 1;
+			else {
+result = NULL;
+ret = 0;
+goto RETURN;
+			}
+		}
 		result = ipalloc(alignment, size);
 	}
 



CVS commit: src/lib/libc/stdlib

2023-10-14 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Oct 14 19:38:51 UTC 2023

Modified Files:
src/lib/libc/stdlib: jemalloc.c

Log Message:
Cherry pick a fix from FreeBSD:

commit 80bc871bdd4a8254ce19a65a54c8c918dd3ddd11
Author: Konstantin Belousov 
Date:   Sat Sep 12 18:16:46 2009 +

MFC r196861:
Handle zero size for posix_memalign. Return NULL or unique address
according to the 'V' option.


To generate a diff of this commit:
cvs rdiff -u -r1.61 -r1.62 src/lib/libc/stdlib/jemalloc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/lib/libc/stdlib

2023-10-14 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Oct 14 19:37:24 UTC 2023

Modified Files:
src/lib/libc/stdlib: jemalloc.c

Log Message:
Cherry pick a fix from FreeBSD:

commit 52d7a117c0fe8bd0226d964f4272131700035f12
Author: Jason Evans 
Date:   Thu Aug 14 17:03:29 2008 +

Re-order the terms of an expression in arena_run_reg_dalloc() to correctly
detect whether the integer division table is large enough to handle the
divisor.  Before this change, the last two table elements were never used,
thus causing the slow path to be used for those divisors.


To generate a diff of this commit:
cvs rdiff -u -r1.60 -r1.61 src/lib/libc/stdlib/jemalloc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/stdlib/jemalloc.c
diff -u src/lib/libc/stdlib/jemalloc.c:1.60 src/lib/libc/stdlib/jemalloc.c:1.61
--- src/lib/libc/stdlib/jemalloc.c:1.60	Sat Oct 14 19:36:17 2023
+++ src/lib/libc/stdlib/jemalloc.c	Sat Oct 14 19:37:24 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: jemalloc.c,v 1.60 2023/10/14 19:36:17 ad Exp $	*/
+/*	$NetBSD: jemalloc.c,v 1.61 2023/10/14 19:37:24 ad Exp $	*/
 
 /*-
  * Copyright (C) 2006,2007 Jason Evans .
@@ -111,7 +111,7 @@
 
 #include 
 /* __FBSDID("$FreeBSD: src/lib/libc/stdlib/malloc.c,v 1.147 2007/06/15 22:00:16 jasone Exp $"); */
-__RCSID("$NetBSD: jemalloc.c,v 1.60 2023/10/14 19:36:17 ad Exp $");
+__RCSID("$NetBSD: jemalloc.c,v 1.61 2023/10/14 19:37:24 ad Exp $");
 
 #include "namespace.h"
 #include 
@@ -1685,8 +1685,8 @@ arena_run_reg_dalloc(arena_run_t *run, a
 			 */
 			regind = (unsigned)(diff / size);
 		}
-	} else if (size <= ((sizeof(size_invs) / sizeof(unsigned))
-	<< QUANTUM_2POW_MIN) + 2) {
+	} else if (size <= (((sizeof(size_invs) / sizeof(unsigned)) + 2)
+	<< QUANTUM_2POW_MIN)) {
 		regind = size_invs[(size >> QUANTUM_2POW_MIN) - 3] * diff;
 		regind >>= SIZE_INV_SHIFT;
 	} else {



CVS commit: src/lib/libc/stdlib

2023-10-14 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Oct 14 19:37:24 UTC 2023

Modified Files:
src/lib/libc/stdlib: jemalloc.c

Log Message:
Cherry pick a fix from FreeBSD:

commit 52d7a117c0fe8bd0226d964f4272131700035f12
Author: Jason Evans 
Date:   Thu Aug 14 17:03:29 2008 +

Re-order the terms of an expression in arena_run_reg_dalloc() to correctly
detect whether the integer division table is large enough to handle the
divisor.  Before this change, the last two table elements were never used,
thus causing the slow path to be used for those divisors.


To generate a diff of this commit:
cvs rdiff -u -r1.60 -r1.61 src/lib/libc/stdlib/jemalloc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/lib/libc/stdlib

2023-10-14 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Oct 14 19:36:17 UTC 2023

Modified Files:
src/lib/libc/stdlib: jemalloc.c

Log Message:
Fix a bug in the rbtree conversion.


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 src/lib/libc/stdlib/jemalloc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/stdlib/jemalloc.c
diff -u src/lib/libc/stdlib/jemalloc.c:1.59 src/lib/libc/stdlib/jemalloc.c:1.60
--- src/lib/libc/stdlib/jemalloc.c:1.59	Sat Oct 14 06:29:10 2023
+++ src/lib/libc/stdlib/jemalloc.c	Sat Oct 14 19:36:17 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: jemalloc.c,v 1.59 2023/10/14 06:29:10 mrg Exp $	*/
+/*	$NetBSD: jemalloc.c,v 1.60 2023/10/14 19:36:17 ad Exp $	*/
 
 /*-
  * Copyright (C) 2006,2007 Jason Evans .
@@ -111,7 +111,7 @@
 
 #include 
 /* __FBSDID("$FreeBSD: src/lib/libc/stdlib/malloc.c,v 1.147 2007/06/15 22:00:16 jasone Exp $"); */
-__RCSID("$NetBSD: jemalloc.c,v 1.59 2023/10/14 06:29:10 mrg Exp $");
+__RCSID("$NetBSD: jemalloc.c,v 1.60 2023/10/14 19:36:17 ad Exp $");
 
 #include "namespace.h"
 #include 
@@ -174,10 +174,10 @@ static inline int
 ptrcmp(const void *pa, const void *pb)
 {
 #ifdef _LP64
-	const intptr_t a = (intptr_t)pa, b = (intptr_t)pb;
-	const intptr_t diff = a - b;
+	const uintptr_t a = (uintptr_t)pa, b = (uintptr_t)pb;
+	const uintptr_t diff = a - b;
 	assert(((a | b) & 1) == 0);
-	return (int)(diff >> 32) | ((int)diff >> 1);
+	return (int)(diff >> 32) | ((unsigned)diff >> 1);
 #else
 	return (intptr_t)pa - (intptr_t)pb;
 #endif



CVS commit: src/lib/libc/stdlib

2023-10-14 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Oct 14 19:36:17 UTC 2023

Modified Files:
src/lib/libc/stdlib: jemalloc.c

Log Message:
Fix a bug in the rbtree conversion.


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 src/lib/libc/stdlib/jemalloc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/lib/libc/stdlib

2023-10-13 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Fri Oct 13 20:57:30 UTC 2023

Modified Files:
src/lib/libc/stdlib: jemalloc.c

Log Message:
Convert to use Matt Thomas's rbtree, which the env code probably already
pulls into libc.  amd64 object size before and after:

   textdata bss dec hex filename
  21001  88 365   2145453ce jemalloc.po
  14991 184 429   156043cf4 jemalloc.po

libmicro on AMD Athlon Silver 3050e comparing this and the revision before
previous (i.e. the old code, versus arena changes + rbtree changes):

exit_10_nolibc  135.168300  128.07790[   +5.5%]
fork_100180.539040  149.63721[  +20.7%]
fork_1000   200.421650  167.09660[  +19.9%]
mallocT2_10 0.1329200.13317[   -0.2%]
mallocT2_1000.1363500.13635[   +0.0%]
mallocT2_100k   0.2586900.26641[   -3.0%]
mallocT2_10k0.2233400.22733[   -1.8%]
mallocT2_1k 0.1371700.14254[   -3.9%]
malloc_10   0.1005400.10849[   -7.9%]
malloc_100  0.1072900.10753[   -0.2%]
malloc_100k 0.1935600.19355[   +0.0%]
malloc_10k  0.1732500.17454[   -0.7%]
malloc_1k   0.1134900.11335[   +0.1%]


To generate a diff of this commit:
cvs rdiff -u -r1.57 -r1.58 src/lib/libc/stdlib/jemalloc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/stdlib/jemalloc.c
diff -u src/lib/libc/stdlib/jemalloc.c:1.57 src/lib/libc/stdlib/jemalloc.c:1.58
--- src/lib/libc/stdlib/jemalloc.c:1.57	Fri Oct 13 19:30:28 2023
+++ src/lib/libc/stdlib/jemalloc.c	Fri Oct 13 20:57:30 2023
@@ -1,7 +1,8 @@
-/*	$NetBSD: jemalloc.c,v 1.57 2023/10/13 19:30:28 ad Exp $	*/
+/*	$NetBSD: jemalloc.c,v 1.58 2023/10/13 20:57:30 ad Exp $	*/
 
 /*-
  * Copyright (C) 2006,2007 Jason Evans .
+ * Copyright (C) 2023 Andrew Doran .
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -110,7 +111,7 @@
 
 #include 
 /* __FBSDID("$FreeBSD: src/lib/libc/stdlib/malloc.c,v 1.147 2007/06/15 22:00:16 jasone Exp $"); */
-__RCSID("$NetBSD: jemalloc.c,v 1.57 2023/10/13 19:30:28 ad Exp $");
+__RCSID("$NetBSD: jemalloc.c,v 1.58 2023/10/13 20:57:30 ad Exp $");
 
 #include "namespace.h"
 #include 
@@ -118,7 +119,7 @@ __RCSID("$NetBSD: jemalloc.c,v 1.57 2023
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include  /* Must come after several other sys/ includes. */
 
@@ -161,6 +162,27 @@ __RCSID("$NetBSD: jemalloc.c,v 1.57 2023
 #  define inline
 #endif
 
+/*
+ * Compare two pointers of 64/32 bit width and produce a ternary 32-bit
+ * indicator without using conditionals that maintains the expected
+ * ordering: [negative, equal, positive].
+ *
+ * XXX it depends on twos complement arithemetic.
+ * XXX maybe should be a built-in for rbtree?
+ */
+static inline int
+ptrcmp(const void *pa, const void *pb)
+{
+#ifdef _LP64
+	const intptr_t a = (intptr_t)pa, b = (intptr_t)pb;
+	const intptr_t diff = a - b;
+	assert(((a | b) & 1) == 0);
+	return (int)(diff >> 32) | ((int)diff >> 1);
+#else
+	return (intptr_t)a - (intptr_t)b;
+#endif
+}
+
 /* Size of stack-allocated buffer passed to strerror_r(). */
 #define	STRERROR_BUF		64
 
@@ -412,7 +434,7 @@ struct chunk_stats_s {
 typedef struct chunk_node_s chunk_node_t;
 struct chunk_node_s {
 	/* Linkage for the chunk tree. */
-	RB_ENTRY(chunk_node_s) link;
+	rb_node_t link;
 
 	/*
 	 * Pointer to the chunk that this tree node is responsible for.  In some
@@ -426,7 +448,14 @@ struct chunk_node_s {
 	size_t	size;
 };
 typedef struct chunk_tree_s chunk_tree_t;
-RB_HEAD(chunk_tree_s, chunk_node_s);
+
+static int chunk_comp(void *, const void *, const void *);
+
+static const rb_tree_ops_t chunk_tree_ops = {
+	.rbto_compare_nodes = chunk_comp,
+	.rbto_compare_key = chunk_comp,
+	.rbto_node_offset = offsetof(struct chunk_node_s, link),
+};
 
 /**/
 /*
@@ -455,12 +484,12 @@ struct arena_chunk_map_s {
 /* Arena chunk header. */
 typedef struct arena_chunk_s arena_chunk_t;
 struct arena_chunk_s {
+	/* Linkage for the arena's chunk tree. */
+	rb_node_t link;
+
 	/* Arena that owns the chunk. */
 	arena_t *arena;
 
-	/* Linkage for the arena's chunk tree. */
-	RB_ENTRY(arena_chunk_s) link;
-
 	/*
 	 * Number of pages in use.  This is maintained in order to make
 	 * detection of empty chunks fast.
@@ -490,12 +519,19 @@ struct arena_chunk_s {
 	arena_chunk_map_t map[1]; /* Dynamically sized. */
 };
 typedef struct arena_chunk_tree_s arena_chunk_tree_t;
-RB_HEAD(arena_chunk_tree_s, arena_chunk_s);
+
+static int arena_chunk_comp(void *, const void *, const void *);
+
+static const rb_tree_ops_t

CVS commit: src/lib/libc/stdlib

2023-10-13 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Fri Oct 13 20:57:30 UTC 2023

Modified Files:
src/lib/libc/stdlib: jemalloc.c

Log Message:
Convert to use Matt Thomas's rbtree, which the env code probably already
pulls into libc.  amd64 object size before and after:

   textdata bss dec hex filename
  21001  88 365   2145453ce jemalloc.po
  14991 184 429   156043cf4 jemalloc.po

libmicro on AMD Athlon Silver 3050e comparing this and the revision before
previous (i.e. the old code, versus arena changes + rbtree changes):

exit_10_nolibc  135.168300  128.07790[   +5.5%]
fork_100180.539040  149.63721[  +20.7%]
fork_1000   200.421650  167.09660[  +19.9%]
mallocT2_10 0.1329200.13317[   -0.2%]
mallocT2_1000.1363500.13635[   +0.0%]
mallocT2_100k   0.2586900.26641[   -3.0%]
mallocT2_10k0.2233400.22733[   -1.8%]
mallocT2_1k 0.1371700.14254[   -3.9%]
malloc_10   0.1005400.10849[   -7.9%]
malloc_100  0.1072900.10753[   -0.2%]
malloc_100k 0.1935600.19355[   +0.0%]
malloc_10k  0.1732500.17454[   -0.7%]
malloc_1k   0.1134900.11335[   +0.1%]


To generate a diff of this commit:
cvs rdiff -u -r1.57 -r1.58 src/lib/libc/stdlib/jemalloc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/lib/libc/stdlib

2023-10-13 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Fri Oct 13 19:30:28 UTC 2023

Modified Files:
src/lib/libc/stdlib: jemalloc.c

Log Message:
Minor changes to jemalloc100 (the old one that only vax etc currently uses).

- Don't use TLS nor pretend to hash out arenas to reduce lock contention,
  because NetBSD uses thr_curcpu() to choose arena (i.e. per-CPU arenas).

- In a single threaded process, don't prepare "ncpus" worth of arenas,
  allocate only one.

- Use getpagesize() since it caches the return.

- Sprinkle branch hints.

- Make MALLOC_TRACE and MALLOC_DEBUG work again.


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 src/lib/libc/stdlib/jemalloc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/stdlib/jemalloc.c
diff -u src/lib/libc/stdlib/jemalloc.c:1.56 src/lib/libc/stdlib/jemalloc.c:1.57
--- src/lib/libc/stdlib/jemalloc.c:1.56	Sun May  7 12:41:47 2023
+++ src/lib/libc/stdlib/jemalloc.c	Fri Oct 13 19:30:28 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: jemalloc.c,v 1.56 2023/05/07 12:41:47 skrll Exp $	*/
+/*	$NetBSD: jemalloc.c,v 1.57 2023/10/13 19:30:28 ad Exp $	*/
 
 /*-
  * Copyright (C) 2006,2007 Jason Evans .
@@ -97,13 +97,6 @@
 
 /* LINTLIBRARY */
 
-#ifdef __NetBSD__
-#  define xutrace(a, b)		utrace("malloc", (a), (b))
-#  define __DECONST(x, y)	((x)__UNCONST(y))
-#else
-#  define xutrace(a, b)		utrace((a), (b))
-#endif	/* __NetBSD__ */
-
 /*
  * MALLOC_PRODUCTION disables assertions and statistics gathering.  It also
  * defaults the A and J runtime options to off.  These settings are appropriate
@@ -117,21 +110,11 @@
 
 #include 
 /* __FBSDID("$FreeBSD: src/lib/libc/stdlib/malloc.c,v 1.147 2007/06/15 22:00:16 jasone Exp $"); */
-__RCSID("$NetBSD: jemalloc.c,v 1.56 2023/05/07 12:41:47 skrll Exp $");
+__RCSID("$NetBSD: jemalloc.c,v 1.57 2023/10/13 19:30:28 ad Exp $");
 
-#ifdef __FreeBSD__
-#include "libc_private.h"
-#ifdef MALLOC_DEBUG
-#  define _LOCK_DEBUG
-#endif
-#include "spinlock.h"
-#endif
 #include "namespace.h"
 #include 
 #include 
-#ifdef __FreeBSD__
-#include 
-#endif
 #include 
 #include 
 #include 
@@ -139,12 +122,6 @@ __RCSID("$NetBSD: jemalloc.c,v 1.56 2023
 #include 
 #include  /* Must come after several other sys/ includes. */
 
-#ifdef __FreeBSD__
-#include 
-#include 
-#include 
-#endif
-
 #include 
 #include 
 #include 
@@ -158,17 +135,10 @@ __RCSID("$NetBSD: jemalloc.c,v 1.56 2023
 #include 
 #include 
 
-#ifdef __NetBSD__
-#  include 
-#  include "extern.h"
+#include 
+#include "extern.h"
 
 #define STRERROR_R(a, b, c)	strerror_r_ss(a, b, c);
-#endif
-
-#ifdef __FreeBSD__
-#define STRERROR_R(a, b, c)	strerror_r(a, b, c);
-#include "un-namespace.h"
-#endif
 
 /* MALLOC_STATS enables statistics calculation. */
 #ifndef MALLOC_PRODUCTION
@@ -260,7 +230,6 @@ __RCSID("$NetBSD: jemalloc.c,v 1.56 2023
 #  define QUANTUM_2POW_MIN	4
 #  define SIZEOF_PTR_2POW	2
 #  define USE_BRK
-#  define NO_TLS
 #endif
 #ifdef __sh__
 #  define QUANTUM_2POW_MIN	4
@@ -271,9 +240,6 @@ __RCSID("$NetBSD: jemalloc.c,v 1.56 2023
 #  define QUANTUM_2POW_MIN	4
 #  define SIZEOF_PTR_2POW	2
 #  define USE_BRK
-#  ifdef __mc68010__
-#define NO_TLS
-#  endif
 #endif
 #if defined(__mips__)
 #  ifdef _LP64
@@ -284,9 +250,6 @@ __RCSID("$NetBSD: jemalloc.c,v 1.56 2023
 #  endif
 #  define QUANTUM_2POW_MIN	4
 #  define USE_BRK
-#  if defined(__mips__)
-#define NO_TLS
-#  endif
 #endif
 #if defined(__riscv__)
 #  ifdef _LP64
@@ -297,7 +260,6 @@ __RCSID("$NetBSD: jemalloc.c,v 1.56 2023
 #  endif
 #  define QUANTUM_2POW_MIN	4
 #  define USE_BRK
-#  define NO_TLS
 #endif
 #ifdef __hppa__
 #  define QUANTUM_2POW_MIN	4
@@ -367,21 +329,6 @@ __RCSID("$NetBSD: jemalloc.c,v 1.56 2023
 
 /**/
 
-#ifdef __FreeBSD__
-/*
- * Mutexes based on spinlocks.  We can't use normal pthread mutexes, because
- * they require malloc()ed memory.
- */
-typedef struct {
-	spinlock_t	lock;
-} malloc_mutex_t;
-
-/* Set to true once the allocator has been initialized. */
-static bool malloc_initialized = false;
-
-/* Used to avoid initialization races. */
-static malloc_mutex_t init_lock = {_SPINLOCK_INITIALIZER};
-#else
 #define	malloc_mutex_t	mutex_t
 
 /* Set to true once the allocator has been initialized. */
@@ -391,7 +338,6 @@ static bool malloc_initialized = false;
 /* Used to avoid initialization races. */
 static mutex_t init_lock = MUTEX_INITIALIZER;
 #endif
-#endif
 
 /**/
 /*
@@ -774,71 +720,10 @@ static size_t		base_mapped;
  * arenas array are necessarily used; arenas are created lazily as needed.
  */
 static arena_t		**arenas;
-static unsigned		narenas;
-static unsigned		next_arena;
 #ifdef _REENTRANT
 static malloc_mutex_t	arenas_mtx; /* Protects arenas initialization. */
 #endif
 
-/*
- * Map of pthread_self() --> arenas[???], used for 

CVS commit: src/lib/libc/stdlib

2023-10-13 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Fri Oct 13 19:30:28 UTC 2023

Modified Files:
src/lib/libc/stdlib: jemalloc.c

Log Message:
Minor changes to jemalloc100 (the old one that only vax etc currently uses).

- Don't use TLS nor pretend to hash out arenas to reduce lock contention,
  because NetBSD uses thr_curcpu() to choose arena (i.e. per-CPU arenas).

- In a single threaded process, don't prepare "ncpus" worth of arenas,
  allocate only one.

- Use getpagesize() since it caches the return.

- Sprinkle branch hints.

- Make MALLOC_TRACE and MALLOC_DEBUG work again.


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 src/lib/libc/stdlib/jemalloc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src

2023-10-13 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Fri Oct 13 19:07:09 UTC 2023

Modified Files:
src/sys/ddb: db_command.c db_interface.h db_xxx.c
src/sys/kern: sys_pipe.c
src/sys/sys: pipe.h
src/usr.bin/fstat: fstat.c

Log Message:
Simplify/streamline pipes a little bit:

- Allocate only one struct pipe not two (no need to be bidirectional here).
- Then use f_flag (FREAD/FWRITE) to figure out what to do in the fileops.
- Never wake the other side or acquire long-term (I/O) lock unless needed.
- Whenever possible, defer wakeups until after locks have been released.
- Do some things locklessly in pipe_ioctl() and pipe_poll().

Some notable results:

- -30% latency on a 486DX2/66 doing 1 byte ping-pong within a single process.
- 2.5x less lock contention during "make cleandir" of src on a 48 CPU machine.
- 1.5x bandwith with 1kB messages on the same 48 CPU machine (8kB: same b/w).


To generate a diff of this commit:
cvs rdiff -u -r1.186 -r1.187 src/sys/ddb/db_command.c
cvs rdiff -u -r1.41 -r1.42 src/sys/ddb/db_interface.h
cvs rdiff -u -r1.77 -r1.78 src/sys/ddb/db_xxx.c
cvs rdiff -u -r1.164 -r1.165 src/sys/kern/sys_pipe.c
cvs rdiff -u -r1.39 -r1.40 src/sys/sys/pipe.h
cvs rdiff -u -r1.118 -r1.119 src/usr.bin/fstat/fstat.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ddb/db_command.c
diff -u src/sys/ddb/db_command.c:1.186 src/sys/ddb/db_command.c:1.187
--- src/sys/ddb/db_command.c:1.186	Sat Oct  7 20:27:20 2023
+++ src/sys/ddb/db_command.c	Fri Oct 13 19:07:08 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: db_command.c,v 1.186 2023/10/07 20:27:20 ad Exp $	*/
+/*	$NetBSD: db_command.c,v 1.187 2023/10/13 19:07:08 ad Exp $	*/
 
 /*
  * Copyright (c) 1996, 1997, 1998, 1999, 2002, 2009, 2019
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: db_command.c,v 1.186 2023/10/07 20:27:20 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_command.c,v 1.187 2023/10/13 19:07:08 ad Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_aio.h"
@@ -301,6 +301,8 @@ static const struct db_command db_show_c
 	0 ,"List all used memory pages.",NULL,NULL) },
 	{ DDB_ADD_CMD("panic",	db_show_panic,	0,
 	"Print the current panic string",NULL,NULL) },
+	{ DDB_ADD_CMD("pipe", db_show_pipe,
+	0 ,"Show the contents of a pipe.",NULL,NULL) },
 	{ DDB_ADD_CMD("pool",	db_pool_print_cmd,	0,
 	"Print the pool at address.", "[/clp] address",NULL) },
 	/* added from all sub cmds */

Index: src/sys/ddb/db_interface.h
diff -u src/sys/ddb/db_interface.h:1.41 src/sys/ddb/db_interface.h:1.42
--- src/sys/ddb/db_interface.h:1.41	Sat Oct  7 20:27:20 2023
+++ src/sys/ddb/db_interface.h	Fri Oct 13 19:07:08 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: db_interface.h,v 1.41 2023/10/07 20:27:20 ad Exp $	*/
+/*	$NetBSD: db_interface.h,v 1.42 2023/10/13 19:07:08 ad Exp $	*/
 
 /*-
  * Copyright (c) 1995, 2023 The NetBSD Foundation, Inc.
@@ -86,6 +86,9 @@ void		db_show_sleepq(db_expr_t, bool, db
 /* kern/kern_condvar.c */
 void		db_show_condvar(db_expr_t, bool, db_expr_t, const char *);
 
+/* kern/sys_pipe.c */
+void		db_show_pipe(db_expr_t, bool, db_expr_t, const char *);
+
 /* kern/sys_select.c */
 void		db_show_selinfo(db_expr_t, bool, db_expr_t, const char *);
 

Index: src/sys/ddb/db_xxx.c
diff -u src/sys/ddb/db_xxx.c:1.77 src/sys/ddb/db_xxx.c:1.78
--- src/sys/ddb/db_xxx.c:1.77	Sun Oct  8 15:03:16 2023
+++ src/sys/ddb/db_xxx.c	Fri Oct 13 19:07:08 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: db_xxx.c,v 1.77 2023/10/08 15:03:16 martin Exp $	*/
+/*	$NetBSD: db_xxx.c,v 1.78 2023/10/13 19:07:08 ad Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1991, 1993
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: db_xxx.c,v 1.77 2023/10/08 15:03:16 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_xxx.c,v 1.78 2023/10/13 19:07:08 ad Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_kgdb.h"
@@ -72,6 +72,7 @@ __KERNEL_RCSID(0, "$NetBSD: db_xxx.c,v 1
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -366,6 +367,51 @@ db_show_sleepq(db_expr_t addr, bool hadd
 }
 
 void
+db_show_pipe(db_expr_t addr, bool haddr, db_expr_t count, const char *modif)
+{
+	struct pipe pipe, *ppipe = (struct pipe *)addr;
+
+	db_read_bytes(addr, sizeof(pipe), (char *));
+
+	db_printf("pipe_lock\t\t%p\n", pipe.pipe_lock);
+
+	db_printf("pipe_read\t\t");
+	db_show_condvar((db_addr_t)>pipe_read, false, 0, modif);
+
+	db_printf("pipe_write\t\t");
+	db_show_condvar((db_addr_t)>pipe_write, false, 0, modif);
+
+	db_printf("pipe_busy\t\t");
+	db_show_condvar((db_addr_t)>pipe_busy, false, 0, modif);
+
+	db_printf("pipe_buffer.cnt\t\t%ld\n", (long)pipe.pipe_buffer.cnt);
+	db_printf("pipe_buffer.in\t\t%d\n", pipe.pipe_buffer.in);
+	db_printf("pipe_buffer.out\t\t%d\n", pipe.pipe_buffer.out);
+	db_printf("pipe_buffer.size\t%ld\n", (long)pipe.pipe_buffer.size);
+	db_printf("pipe_buffer.buffer\t%p\n", pipe.pipe_buffer.buffer);
+
+	db_printf("pipe_wrsel\t\t");
+	

CVS commit: src

2023-10-13 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Fri Oct 13 19:07:09 UTC 2023

Modified Files:
src/sys/ddb: db_command.c db_interface.h db_xxx.c
src/sys/kern: sys_pipe.c
src/sys/sys: pipe.h
src/usr.bin/fstat: fstat.c

Log Message:
Simplify/streamline pipes a little bit:

- Allocate only one struct pipe not two (no need to be bidirectional here).
- Then use f_flag (FREAD/FWRITE) to figure out what to do in the fileops.
- Never wake the other side or acquire long-term (I/O) lock unless needed.
- Whenever possible, defer wakeups until after locks have been released.
- Do some things locklessly in pipe_ioctl() and pipe_poll().

Some notable results:

- -30% latency on a 486DX2/66 doing 1 byte ping-pong within a single process.
- 2.5x less lock contention during "make cleandir" of src on a 48 CPU machine.
- 1.5x bandwith with 1kB messages on the same 48 CPU machine (8kB: same b/w).


To generate a diff of this commit:
cvs rdiff -u -r1.186 -r1.187 src/sys/ddb/db_command.c
cvs rdiff -u -r1.41 -r1.42 src/sys/ddb/db_interface.h
cvs rdiff -u -r1.77 -r1.78 src/sys/ddb/db_xxx.c
cvs rdiff -u -r1.164 -r1.165 src/sys/kern/sys_pipe.c
cvs rdiff -u -r1.39 -r1.40 src/sys/sys/pipe.h
cvs rdiff -u -r1.118 -r1.119 src/usr.bin/fstat/fstat.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



Re: CVS commit: src/sys

2023-10-13 Thread Andrew Doran
On Thu, Oct 12, 2023 at 11:55:46AM +0200, J. Hannken-Illjes wrote:
> > On 10. Oct 2023, at 20:58, Andrew Doran  wrote:
> > 
> > On Tue, Oct 10, 2023 at 06:00:57PM +0200, J. Hannken-Illjes wrote:
> > 
> >>> cvs rdiff -u -r1.63 -r1.64 src/sys/kern/sys_select.c
> >> 
> >> -sleepq_unsleep(l, false);
> >> +sleepq_remove(l->l_sleepq, l, true);
> >>}
> >>   }
> >>   mutex_spin_exit(lock);
> >> 
> >> Looks like sleepq_remove() unlocks l->l_mutex == lock and
> >> then mutex_spin_exit(lock) will unlock an unlocked mutex.
> > 
> > lock is held before the call to sleepq_remove() and this is also true at the
> > time: l->l_mutex == lock.
> > 
> > After the call lock is still held, but now l->l_mutex != lock, because l has
> > changed state (e.g LSSLEEP -> LSRUN) which causes l_mutex to change in
> > concert.  There is a rough overview here:
> > 
> > https://nxr.netbsd.org/xref/src/sys/kern/kern_lwp.c#156
> > 
> > Did you encounter a problem?
> 
> This is not true for RUMP.  Hero you added sleepq_remove() as
> "sleepq_unsleep(l, true)".  This will unlock l_mutex without changing.
> 
> Just poking around and using sleepq_unsleep(l, false) here makes the
> NFS tests using rump_server pass.

Ah, now I see, thank you.  I committed a fix and will do a test run once my
build completes.

Cheers,
Andrew


CVS commit: src/sys

2023-10-13 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Fri Oct 13 18:50:39 UTC 2023

Modified Files:
src/sys/kern: uipc_socket.c uipc_syscalls.c
src/sys/sys: socketvar.h

Log Message:
Use cv_fdrestart() to implement fo_restart.


To generate a diff of this commit:
cvs rdiff -u -r1.305 -r1.306 src/sys/kern/uipc_socket.c
cvs rdiff -u -r1.208 -r1.209 src/sys/kern/uipc_syscalls.c
cvs rdiff -u -r1.165 -r1.166 src/sys/sys/socketvar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/uipc_socket.c
diff -u src/sys/kern/uipc_socket.c:1.305 src/sys/kern/uipc_socket.c:1.306
--- src/sys/kern/uipc_socket.c:1.305	Wed Oct  4 22:17:09 2023
+++ src/sys/kern/uipc_socket.c	Fri Oct 13 18:50:39 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: uipc_socket.c,v 1.305 2023/10/04 22:17:09 ad Exp $	*/
+/*	$NetBSD: uipc_socket.c,v 1.306 2023/10/13 18:50:39 ad Exp $	*/
 
 /*
  * Copyright (c) 2002, 2007, 2008, 2009, 2023 The NetBSD Foundation, Inc.
@@ -71,7 +71,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.305 2023/10/04 22:17:09 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.306 2023/10/13 18:50:39 ad Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -895,7 +895,6 @@ sosend(struct socket *so, struct sockadd
 	struct mbuf **mp, *m;
 	long space, len, resid, clen, mlen;
 	int error, s, dontroute, atomic;
-	short wakeup_state = 0;
 
 	clen = 0;
 
@@ -968,17 +967,11 @@ sosend(struct socket *so, struct sockadd
 goto release;
 			}
 			sbunlock(>so_snd);
-			if (wakeup_state & SS_RESTARTSYS) {
-error = ERESTART;
-goto out;
-			}
 			error = sbwait(>so_snd);
 			if (error)
 goto out;
-			wakeup_state = so->so_state;
 			goto restart;
 		}
-		wakeup_state = 0;
 		mp = 
 		space -= clen;
 		do {
@@ -1160,7 +1153,6 @@ soreceive(struct socket *so, struct mbuf
 	struct mbuf *nextrecord;
 	int mbuf_removed = 0;
 	const struct domain *dom;
-	short wakeup_state = 0;
 
 	pr = so->so_proto;
 	atomic = pr->pr_flags & PR_ATOMIC;
@@ -1271,16 +1263,12 @@ restart:
 		SBLASTRECORDCHK(>so_rcv, "soreceive sbwait 1");
 		SBLASTMBUFCHK(>so_rcv, "soreceive sbwait 1");
 		sbunlock(>so_rcv);
-		if (wakeup_state & SS_RESTARTSYS)
-			error = ERESTART;
-		else
-			error = sbwait(>so_rcv);
+		error = sbwait(>so_rcv);
 		if (error != 0) {
 			sounlock(so);
 			splx(s);
 			return error;
 		}
-		wakeup_state = so->so_state;
 		goto restart;
 	}
 
@@ -1457,7 +1445,6 @@ dontblock:
 #endif
 
 		so->so_state &= ~SS_RCVATMARK;
-		wakeup_state = 0;
 		len = uio->uio_resid;
 		if (so->so_oobmark && len > so->so_oobmark - offset)
 			len = so->so_oobmark - offset;
@@ -1600,10 +1587,7 @@ dontblock:
 (*pr->pr_usrreqs->pr_rcvd)(so, flags, l);
 			SBLASTRECORDCHK(>so_rcv, "soreceive sbwait 2");
 			SBLASTMBUFCHK(>so_rcv, "soreceive sbwait 2");
-			if (wakeup_state & SS_RESTARTSYS)
-error = ERESTART;
-			else
-error = sbwait(>so_rcv);
+			error = sbwait(>so_rcv);
 			if (error != 0) {
 sbunlock(>so_rcv);
 sounlock(so);
@@ -1612,7 +1596,6 @@ dontblock:
 			}
 			if ((m = so->so_rcv.sb_mb) != NULL)
 nextrecord = m->m_nextpkt;
-			wakeup_state = so->so_state;
 		}
 	}
 
@@ -1680,6 +1663,7 @@ soshutdown(struct socket *so, int how)
 void
 sorestart(struct socket *so)
 {
+
 	/*
 	 * An application has called close() on an fd on which another
 	 * of its threads has called a socket system call.
@@ -1689,10 +1673,9 @@ sorestart(struct socket *so)
 	 * Any other fd will block again on the 2nd syscall.
 	 */
 	solock(so);
-	so->so_state |= SS_RESTARTSYS;
-	cv_broadcast(>so_cv);
-	cv_broadcast(>so_snd.sb_cv);
-	cv_broadcast(>so_rcv.sb_cv);
+	cv_fdrestart(>so_cv);
+	cv_fdrestart(>so_snd.sb_cv);
+	cv_fdrestart(>so_rcv.sb_cv);
 	sounlock(so);
 }
 

Index: src/sys/kern/uipc_syscalls.c
diff -u src/sys/kern/uipc_syscalls.c:1.208 src/sys/kern/uipc_syscalls.c:1.209
--- src/sys/kern/uipc_syscalls.c:1.208	Wed Oct  4 22:17:09 2023
+++ src/sys/kern/uipc_syscalls.c	Fri Oct 13 18:50:39 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: uipc_syscalls.c,v 1.208 2023/10/04 22:17:09 ad Exp $	*/
+/*	$NetBSD: uipc_syscalls.c,v 1.209 2023/10/13 18:50:39 ad Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009, 2023 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uipc_syscalls.c,v 1.208 2023/10/04 22:17:09 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_syscalls.c,v 1.209 2023/10/13 18:50:39 ad Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_pipe.h"
@@ -175,7 +175,6 @@ do_sys_accept(struct lwp *l, int sock, s
 	file_t		*fp, *fp2;
 	int		error, fd;
 	struct socket	*so, *so2;
-	short		wakeup_state = 0;
 
 	if ((fp = fd_getfile(sock)) == NULL)
 		return EBADF;
@@ -211,15 +210,10 @@ do_sys_accept(struct lwp *l, int sock, s
 			so->so_error = ECONNABORTED;
 			break;
 		}
-		if (wakeup_state & SS_RESTARTSYS) {
-			error = ERESTART;
-			goto bad;
-		}
 		error = sowait(so, true, 0);
 		if (error) {
 			goto bad;
 		

CVS commit: src/sys

2023-10-13 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Fri Oct 13 18:48:56 UTC 2023

Modified Files:
src/sys/kern: kern_condvar.c kern_sleepq.c
src/sys/rump/librump/rumpkern: locks.c locks_up.c
src/sys/sys: condvar.h lwp.h

Log Message:
Add cv_fdrestart() (better name suggestions welcome):

Like cv_broadcast(), but make any LWPs that share the same file descriptor
table as the caller return ERESTART when resuming.  Used to dislodge LWPs
waiting for I/O that prevent a file descriptor from being closed, without
upsetting access to the file (not descriptor) made from another direction.


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 src/sys/kern/kern_condvar.c
cvs rdiff -u -r1.83 -r1.84 src/sys/kern/kern_sleepq.c
cvs rdiff -u -r1.86 -r1.87 src/sys/rump/librump/rumpkern/locks.c
cvs rdiff -u -r1.12 -r1.13 src/sys/rump/librump/rumpkern/locks_up.c
cvs rdiff -u -r1.17 -r1.18 src/sys/sys/condvar.h
cvs rdiff -u -r1.227 -r1.228 src/sys/sys/lwp.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_condvar.c
diff -u src/sys/kern/kern_condvar.c:1.59 src/sys/kern/kern_condvar.c:1.60
--- src/sys/kern/kern_condvar.c:1.59	Thu Oct 12 23:51:05 2023
+++ src/sys/kern/kern_condvar.c	Fri Oct 13 18:48:56 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_condvar.c,v 1.59 2023/10/12 23:51:05 ad Exp $	*/
+/*	$NetBSD: kern_condvar.c,v 1.60 2023/10/13 18:48:56 ad Exp $	*/
 
 /*-
  * Copyright (c) 2006, 2007, 2008, 2019, 2020, 2023
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_condvar.c,v 1.59 2023/10/12 23:51:05 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_condvar.c,v 1.60 2023/10/13 18:48:56 ad Exp $");
 
 #include 
 #include 
@@ -543,6 +543,43 @@ cv_wakeup_all(kcondvar_t *cv)
 }
 
 /*
+ * cv_fdrestart:
+ *
+ *	Like cv_broadcast(), but make any LWPs that share the same file
+ *	descriptor table as the caller return ERESTART when resuming.  Used
+ *	to dislodge LWPs waiting for I/O that prevent a file descriptor from
+ *	being closed, without upsetting access to the file (not descriptor)
+ *	made from another direction.  Rarely used thus no fast path
+ *	provided.
+ */
+void
+cv_fdrestart(kcondvar_t *cv)
+{
+	sleepq_t *sq;
+	kmutex_t *mp;
+	lwp_t *l;
+
+	KASSERT(cv_is_valid(cv));
+
+	if (LIST_EMPTY(CV_SLEEPQ(cv)))
+		return;
+
+	mp = sleepq_hashlock(cv);
+	sq = CV_SLEEPQ(cv);
+	while ((l = LIST_FIRST(sq)) != NULL) {
+		KASSERT(l->l_sleepq == sq);
+		KASSERT(l->l_mutex == mp);
+		KASSERT(l->l_wchan == cv);
+		/* l_fd stable at this point so no special locking needed. */
+		if (l->l_fd == curlwp->l_fd) {
+			l->l_flag |= LW_RESTART;
+			sleepq_remove(sq, l, false);
+		}
+	}
+	mutex_spin_exit(mp);
+}
+
+/*
  * cv_has_waiters:
  *
  *	For diagnostic assertions: return non-zero if a condition

Index: src/sys/kern/kern_sleepq.c
diff -u src/sys/kern/kern_sleepq.c:1.83 src/sys/kern/kern_sleepq.c:1.84
--- src/sys/kern/kern_sleepq.c:1.83	Sun Oct  8 13:37:26 2023
+++ src/sys/kern/kern_sleepq.c	Fri Oct 13 18:48:56 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_sleepq.c,v 1.83 2023/10/08 13:37:26 ad Exp $	*/
+/*	$NetBSD: kern_sleepq.c,v 1.84 2023/10/13 18:48:56 ad Exp $	*/
 
 /*-
  * Copyright (c) 2006, 2007, 2008, 2009, 2019, 2020, 2023
@@ -36,7 +36,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_sleepq.c,v 1.83 2023/10/08 13:37:26 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_sleepq.c,v 1.84 2023/10/13 18:48:56 ad Exp $");
 
 #include 
 #include 
@@ -341,7 +341,7 @@ sleepq_uncatch(lwp_t *l)
 int
 sleepq_block(int timo, bool catch_p, syncobj_t *syncobj, int nlocks)
 {
-	const int mask = LW_CANCELLED|LW_WEXIT|LW_WCORE|LW_PENDSIG;
+	const int mask = LW_CANCELLED|LW_WEXIT|LW_WCORE|LW_PENDSIG|LW_RESTART;
 	int error = 0, sig, flag;
 	struct proc *p;
 	lwp_t *l = curlwp;
@@ -358,16 +358,20 @@ sleepq_block(int timo, bool catch_p, syn
 	 * while we are sleeping.  It is independent from LW_SINTR because
 	 * we don't want to leave LW_SINTR set when the LWP is not asleep.
 	 */
+	flag = l->l_flag;
 	if (catch_p) {
-		if ((l->l_flag & (LW_CANCELLED|LW_WEXIT|LW_WCORE)) != 0) {
-			l->l_flag &= ~LW_CANCELLED;
-			error = EINTR;
-			early = true;
-		} else if ((l->l_flag & LW_PENDSIG) != 0 && sigispending(l, 0))
-			early = true;
-		l->l_flag |= LW_CATCHINTR;
+		if ((flag & mask) != 0) {
+			if ((flag & (LW_CANCELLED|LW_WEXIT|LW_WCORE)) != 0) {
+l->l_flag = flag & ~LW_CANCELLED;
+error = EINTR;
+early = true;
+			} else if ((flag & LW_PENDSIG) != 0 &&
+			sigispending(l, 0))
+early = true;
+		}
+		l->l_flag = (flag | LW_CATCHINTR) & ~LW_RESTART;
 	} else
-		l->l_flag &= ~LW_CATCHINTR;
+		l->l_flag = flag & ~(LW_CATCHINTR | LW_RESTART);
 
 	if (early) {
 		/* lwp_unsleep() will release the lock */
@@ -435,7 +439,8 @@ sleepq_block(int timo, bool catch_p, syn
 			(sig = issignal(l)) != 0)
 error = sleepq_sigtoerror(l, sig);
 			mutex_exit(p->p_lock);
-		}
+		} else if ((flag & 

CVS commit: src/sys

2023-10-13 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Fri Oct 13 18:50:39 UTC 2023

Modified Files:
src/sys/kern: uipc_socket.c uipc_syscalls.c
src/sys/sys: socketvar.h

Log Message:
Use cv_fdrestart() to implement fo_restart.


To generate a diff of this commit:
cvs rdiff -u -r1.305 -r1.306 src/sys/kern/uipc_socket.c
cvs rdiff -u -r1.208 -r1.209 src/sys/kern/uipc_syscalls.c
cvs rdiff -u -r1.165 -r1.166 src/sys/sys/socketvar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys

2023-10-13 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Fri Oct 13 18:48:56 UTC 2023

Modified Files:
src/sys/kern: kern_condvar.c kern_sleepq.c
src/sys/rump/librump/rumpkern: locks.c locks_up.c
src/sys/sys: condvar.h lwp.h

Log Message:
Add cv_fdrestart() (better name suggestions welcome):

Like cv_broadcast(), but make any LWPs that share the same file descriptor
table as the caller return ERESTART when resuming.  Used to dislodge LWPs
waiting for I/O that prevent a file descriptor from being closed, without
upsetting access to the file (not descriptor) made from another direction.


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 src/sys/kern/kern_condvar.c
cvs rdiff -u -r1.83 -r1.84 src/sys/kern/kern_sleepq.c
cvs rdiff -u -r1.86 -r1.87 src/sys/rump/librump/rumpkern/locks.c
cvs rdiff -u -r1.12 -r1.13 src/sys/rump/librump/rumpkern/locks_up.c
cvs rdiff -u -r1.17 -r1.18 src/sys/sys/condvar.h
cvs rdiff -u -r1.227 -r1.228 src/sys/sys/lwp.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/regress/sys/kern/dislodgefd

2023-10-13 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Fri Oct 13 18:46:22 UTC 2023

Added Files:
src/regress/sys/kern/dislodgefd: Makefile dislodgefd.c

Log Message:
A dumb test that calling close() on a pipe/socket fd dislodges another
thread in the same process waiting for I/O on the fd.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/regress/sys/kern/dislodgefd/Makefile \
src/regress/sys/kern/dislodgefd/dislodgefd.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Added files:

Index: src/regress/sys/kern/dislodgefd/Makefile
diff -u /dev/null src/regress/sys/kern/dislodgefd/Makefile:1.1
--- /dev/null	Fri Oct 13 18:46:22 2023
+++ src/regress/sys/kern/dislodgefd/Makefile	Fri Oct 13 18:46:22 2023
@@ -0,0 +1,9 @@
+#	$NetBSD: Makefile,v 1.1 2023/10/13 18:46:22 ad Exp $
+
+NOMAN=		# defined
+
+PROG=		dislodgefd
+WARNS?=		4
+LDADD=		-lpthread
+
+.include 
Index: src/regress/sys/kern/dislodgefd/dislodgefd.c
diff -u /dev/null src/regress/sys/kern/dislodgefd/dislodgefd.c:1.1
--- /dev/null	Fri Oct 13 18:46:22 2023
+++ src/regress/sys/kern/dislodgefd/dislodgefd.c	Fri Oct 13 18:46:22 2023
@@ -0,0 +1,80 @@
+/*	$NetBSD: dislodgefd.c,v 1.1 2023/10/13 18:46:22 ad Exp $	*/
+
+/*-
+ * Copyright (c) 2023 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+pthread_barrier_t	barrier;
+int			fds[2];
+
+static void *
+reader(void *cookie)
+{
+	char buf[1];
+
+	(void)pthread_barrier_wait();
+	printf("reader(): commencing read, this should error out... after 1s\n");
+	if (read(fds[0], buf, sizeof(buf)) == -1)
+		err(1, "read");
+
+	printf("reader(): read terminated without error??\n");
+	return NULL;
+}
+
+int
+main(int argc, char *argv[])
+{
+	pthread_t pt;
+
+	if (argc > 1 && strcmp(argv[1], "pipe") == 0) {
+		if (pipe(fds))
+			err(1, "pipe");
+	} else {
+		if (socketpair(PF_LOCAL, SOCK_STREAM, 0, fds) < 0)
+			err(1, "socketpair");
+	}
+	pthread_barrier_init(, NULL, 2);
+	if (pthread_create(, NULL, reader, NULL)) {
+		errx(1, "pthread_create failed");
+	}
+	(void)pthread_barrier_wait();
+	sleep(1);
+	printf("main(): closing the reader side fd..\n");
+	close(fds[0]);
+	printf("main(): sleeping again for a bit..\n");
+	sleep(1);
+	printf("main(): exiting.\n");
+	return 0;
+}



CVS commit: src/regress/sys/kern/dislodgefd

2023-10-13 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Fri Oct 13 18:46:22 UTC 2023

Added Files:
src/regress/sys/kern/dislodgefd: Makefile dislodgefd.c

Log Message:
A dumb test that calling close() on a pipe/socket fd dislodges another
thread in the same process waiting for I/O on the fd.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/regress/sys/kern/dislodgefd/Makefile \
src/regress/sys/kern/dislodgefd/dislodgefd.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/rump/librump/rumpkern

2023-10-13 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Fri Oct 13 18:23:54 UTC 2023

Modified Files:
src/sys/rump/librump/rumpkern: sleepq.c

Log Message:
Rump: sleepq_remove(): don't unlock the sleepq.  Spotted by hannken@.


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sys/rump/librump/rumpkern/sleepq.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/librump/rumpkern/sleepq.c
diff -u src/sys/rump/librump/rumpkern/sleepq.c:1.27 src/sys/rump/librump/rumpkern/sleepq.c:1.28
--- src/sys/rump/librump/rumpkern/sleepq.c:1.27	Sun Oct  8 13:23:05 2023
+++ src/sys/rump/librump/rumpkern/sleepq.c	Fri Oct 13 18:23:54 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: sleepq.c,v 1.27 2023/10/08 13:23:05 ad Exp $	*/
+/*	$NetBSD: sleepq.c,v 1.28 2023/10/13 18:23:54 ad Exp $	*/
 
 /*
  * Copyright (c) 2008 Antti Kantee.  All Rights Reserved.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sleepq.c,v 1.27 2023/10/08 13:23:05 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sleepq.c,v 1.28 2023/10/13 18:23:54 ad Exp $");
 
 #include 
 #include 
@@ -150,7 +150,7 @@ void
 sleepq_remove(sleepq_t *sq, struct lwp *l, bool wakeup)
 {
 
-	sleepq_unsleep(l, true);
+	sleepq_unsleep(l, false);
 }
 
 /*



CVS commit: src/sys/rump/librump/rumpkern

2023-10-13 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Fri Oct 13 18:23:54 UTC 2023

Modified Files:
src/sys/rump/librump/rumpkern: sleepq.c

Log Message:
Rump: sleepq_remove(): don't unlock the sleepq.  Spotted by hannken@.


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sys/rump/librump/rumpkern/sleepq.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/kern

2023-10-12 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Thu Oct 12 23:51:06 UTC 2023

Modified Files:
src/sys/kern: kern_condvar.c

Log Message:
Comments.


To generate a diff of this commit:
cvs rdiff -u -r1.58 -r1.59 src/sys/kern/kern_condvar.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_condvar.c
diff -u src/sys/kern/kern_condvar.c:1.58 src/sys/kern/kern_condvar.c:1.59
--- src/sys/kern/kern_condvar.c:1.58	Sun Oct  8 13:23:05 2023
+++ src/sys/kern/kern_condvar.c	Thu Oct 12 23:51:05 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_condvar.c,v 1.58 2023/10/08 13:23:05 ad Exp $	*/
+/*	$NetBSD: kern_condvar.c,v 1.59 2023/10/12 23:51:05 ad Exp $	*/
 
 /*-
  * Copyright (c) 2006, 2007, 2008, 2019, 2020, 2023
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_condvar.c,v 1.58 2023/10/08 13:23:05 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_condvar.c,v 1.59 2023/10/12 23:51:05 ad Exp $");
 
 #include 
 #include 
@@ -451,8 +451,9 @@ cv_timedwaitbt_sig(kcondvar_t *cv, kmute
 /*
  * cv_signal:
  *
- *	Wake the highest priority LWP waiting on a condition variable.
- *	Must be called with the interlocking mutex held.
+ *	Wake the highest priority LWP waiting on a condition variable.  Must
+ *	be called with the interlocking mutex held or just after it has been
+ *	released (so the awoken LWP will see the changed condition).
  */
 void
 cv_signal(kcondvar_t *cv)
@@ -460,8 +461,13 @@ cv_signal(kcondvar_t *cv)
 
 	KASSERT(cv_is_valid(cv));
 
-	if (__predict_false(!LIST_EMPTY(CV_SLEEPQ(cv
+	if (__predict_false(!LIST_EMPTY(CV_SLEEPQ(cv {
+		/*
+		 * Compiler turns into a tail call usually, i.e. jmp,
+		 * because the arguments are the same and no locals.
+		 */
 		cv_wakeup_one(cv);
+	}
 }
 
 /*
@@ -492,8 +498,9 @@ cv_wakeup_one(kcondvar_t *cv)
 /*
  * cv_broadcast:
  *
- *	Wake all LWPs waiting on a condition variable.  Must be called
- *	with the interlocking mutex held.
+ *	Wake all LWPs waiting on a condition variable.  Must be called with
+ *	the interlocking mutex held or just after it has been released (so
+ *	the awoken LWP will see the changed condition).
  */
 void
 cv_broadcast(kcondvar_t *cv)
@@ -501,8 +508,13 @@ cv_broadcast(kcondvar_t *cv)
 
 	KASSERT(cv_is_valid(cv));
 
-	if (__predict_false(!LIST_EMPTY(CV_SLEEPQ(cv  
+	if (__predict_false(!LIST_EMPTY(CV_SLEEPQ(cv {
+		/*
+		 * Compiler turns into a tail call usually, i.e. jmp,
+		 * because the arguments are the same and no locals.
+		 */
 		cv_wakeup_all(cv);
+	}
 }
 
 /*



CVS commit: src/sys/kern

2023-10-12 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Thu Oct 12 23:51:06 UTC 2023

Modified Files:
src/sys/kern: kern_condvar.c

Log Message:
Comments.


To generate a diff of this commit:
cvs rdiff -u -r1.58 -r1.59 src/sys/kern/kern_condvar.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



Re: CVS commit: src/sys

2023-10-10 Thread Andrew Doran
On Tue, Oct 10, 2023 at 06:00:57PM +0200, J. Hannken-Illjes wrote:

> > cvs rdiff -u -r1.63 -r1.64 src/sys/kern/sys_select.c
> 
> -sleepq_unsleep(l, false);
> +sleepq_remove(l->l_sleepq, l, true);
> }
>}
>mutex_spin_exit(lock);
> 
> Looks like sleepq_remove() unlocks l->l_mutex == lock and
> then mutex_spin_exit(lock) will unlock an unlocked mutex.

lock is held before the call to sleepq_remove() and this is also true at the
time: l->l_mutex == lock.

After the call lock is still held, but now l->l_mutex != lock, because l has
changed state (e.g LSSLEEP -> LSRUN) which causes l_mutex to change in
concert.  There is a rough overview here:

https://nxr.netbsd.org/xref/src/sys/kern/kern_lwp.c#156

Did you encounter a problem?

Cheers,
Andrew


CVS commit: src/sys/kern

2023-10-08 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sun Oct  8 13:37:26 UTC 2023

Modified Files:
src/sys/kern: kern_sleepq.c

Log Message:
Oops, fix inverted test.


To generate a diff of this commit:
cvs rdiff -u -r1.82 -r1.83 src/sys/kern/kern_sleepq.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_sleepq.c
diff -u src/sys/kern/kern_sleepq.c:1.82 src/sys/kern/kern_sleepq.c:1.83
--- src/sys/kern/kern_sleepq.c:1.82	Sun Oct  8 13:23:05 2023
+++ src/sys/kern/kern_sleepq.c	Sun Oct  8 13:37:26 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_sleepq.c,v 1.82 2023/10/08 13:23:05 ad Exp $	*/
+/*	$NetBSD: kern_sleepq.c,v 1.83 2023/10/08 13:37:26 ad Exp $	*/
 
 /*-
  * Copyright (c) 2006, 2007, 2008, 2009, 2019, 2020, 2023
@@ -36,7 +36,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_sleepq.c,v 1.82 2023/10/08 13:23:05 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_sleepq.c,v 1.83 2023/10/08 13:37:26 ad Exp $");
 
 #include 
 #include 
@@ -416,7 +416,7 @@ sleepq_block(int timo, bool catch_p, syn
 	 */
 	flag = atomic_load_relaxed(>l_flag);
 	if (__predict_false((flag & mask) != 0)) {
-		if ((flag & LW_CATCHINTR) == 0 && error != 0)
+		if ((flag & LW_CATCHINTR) == 0 || error != 0)
 			/* nothing */;
 		else if ((flag & (LW_CANCELLED | LW_WEXIT | LW_WCORE)) != 0)
 			error = EINTR;



CVS commit: src/sys/kern

2023-10-08 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sun Oct  8 13:37:26 UTC 2023

Modified Files:
src/sys/kern: kern_sleepq.c

Log Message:
Oops, fix inverted test.


To generate a diff of this commit:
cvs rdiff -u -r1.82 -r1.83 src/sys/kern/kern_sleepq.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys

2023-10-08 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sun Oct  8 13:23:05 UTC 2023

Modified Files:
src/sys/kern: kern_condvar.c kern_sleepq.c kern_timeout.c
kern_turnstile.c sys_lwp.c sys_select.c
src/sys/rump/librump/rumpkern: sleepq.c
src/sys/sys: sleepq.h syncobj.h

Log Message:
Ensure that an LWP that has taken a legitimate wakeup never produces an
error code from sleepq_block().  Then, it's possible to make cv_signal()
work as expected and only ever wake a singular LWP.


To generate a diff of this commit:
cvs rdiff -u -r1.57 -r1.58 src/sys/kern/kern_condvar.c
cvs rdiff -u -r1.81 -r1.82 src/sys/kern/kern_sleepq.c
cvs rdiff -u -r1.78 -r1.79 src/sys/kern/kern_timeout.c
cvs rdiff -u -r1.52 -r1.53 src/sys/kern/kern_turnstile.c
cvs rdiff -u -r1.86 -r1.87 src/sys/kern/sys_lwp.c
cvs rdiff -u -r1.63 -r1.64 src/sys/kern/sys_select.c
cvs rdiff -u -r1.26 -r1.27 src/sys/rump/librump/rumpkern/sleepq.c
cvs rdiff -u -r1.39 -r1.40 src/sys/sys/sleepq.h
cvs rdiff -u -r1.16 -r1.17 src/sys/sys/syncobj.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_condvar.c
diff -u src/sys/kern/kern_condvar.c:1.57 src/sys/kern/kern_condvar.c:1.58
--- src/sys/kern/kern_condvar.c:1.57	Wed Oct  4 20:29:18 2023
+++ src/sys/kern/kern_condvar.c	Sun Oct  8 13:23:05 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_condvar.c,v 1.57 2023/10/04 20:29:18 ad Exp $	*/
+/*	$NetBSD: kern_condvar.c,v 1.58 2023/10/08 13:23:05 ad Exp $	*/
 
 /*-
  * Copyright (c) 2006, 2007, 2008, 2019, 2020, 2023
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_condvar.c,v 1.57 2023/10/04 20:29:18 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_condvar.c,v 1.58 2023/10/08 13:23:05 ad Exp $");
 
 #include 
 #include 
@@ -478,27 +478,13 @@ cv_wakeup_one(kcondvar_t *cv)
 	kmutex_t *mp;
 	lwp_t *l;
 
-	/*
-	 * Keep waking LWPs until a non-interruptable waiter is found.  An
-	 * interruptable waiter could fail to do something useful with the
-	 * wakeup due to an error return from cv_[timed]wait_sig(), and the
-	 * caller of cv_signal() may not expect such a scenario.
-	 *
-	 * This isn't a problem for non-interruptable waits (untimed and
-	 * timed), because if such a waiter is woken here it will not return
-	 * an error.
-	 */
 	mp = sleepq_hashlock(cv);
 	sq = CV_SLEEPQ(cv);
-	while ((l = LIST_FIRST(sq)) != NULL) {
+	if (__predict_true((l = LIST_FIRST(sq)) != NULL)) {
 		KASSERT(l->l_sleepq == sq);
 		KASSERT(l->l_mutex == mp);
 		KASSERT(l->l_wchan == cv);
-		if ((l->l_flag & LW_SINTR) == 0) {
-			sleepq_remove(sq, l);
-			break;
-		} else
-			sleepq_remove(sq, l);
+		sleepq_remove(sq, l, true);
 	}
 	mutex_spin_exit(mp);
 }
@@ -539,7 +525,7 @@ cv_wakeup_all(kcondvar_t *cv)
 		KASSERT(l->l_sleepq == sq);
 		KASSERT(l->l_mutex == mp);
 		KASSERT(l->l_wchan == cv);
-		sleepq_remove(sq, l);
+		sleepq_remove(sq, l, true);
 	}
 	mutex_spin_exit(mp);
 }

Index: src/sys/kern/kern_sleepq.c
diff -u src/sys/kern/kern_sleepq.c:1.81 src/sys/kern/kern_sleepq.c:1.82
--- src/sys/kern/kern_sleepq.c:1.81	Sun Oct  8 11:12:47 2023
+++ src/sys/kern/kern_sleepq.c	Sun Oct  8 13:23:05 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_sleepq.c,v 1.81 2023/10/08 11:12:47 ad Exp $	*/
+/*	$NetBSD: kern_sleepq.c,v 1.82 2023/10/08 13:23:05 ad Exp $	*/
 
 /*-
  * Copyright (c) 2006, 2007, 2008, 2009, 2019, 2020, 2023
@@ -36,7 +36,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_sleepq.c,v 1.81 2023/10/08 11:12:47 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_sleepq.c,v 1.82 2023/10/08 13:23:05 ad Exp $");
 
 #include 
 #include 
@@ -105,10 +105,17 @@ sleepq_init(sleepq_t *sq)
 /*
  * sleepq_remove:
  *
- *	Remove an LWP from a sleep queue and wake it up.
+ *	Remove an LWP from a sleep queue and wake it up.  Distinguish
+ *	between deliberate wakeups (which are a valuable information) and
+ *	"unsleep" (an out-of-band action must be taken).
+ *
+ *	For wakeup, convert any interruptable wait into non-interruptable
+ *	one before waking the LWP.  Otherwise, if only one LWP is awoken it
+ *	could fail to do something useful with the wakeup due to an error
+ *	return and the caller of e.g. cv_signal() may not expect this.
  */
 void
-sleepq_remove(sleepq_t *sq, lwp_t *l)
+sleepq_remove(sleepq_t *sq, lwp_t *l, bool wakeup)
 {
 	struct schedstate_percpu *spc;
 	struct cpu_info *ci;
@@ -125,7 +132,7 @@ sleepq_remove(sleepq_t *sq, lwp_t *l)
 	l->l_syncobj = _syncobj;
 	l->l_wchan = NULL;
 	l->l_sleepq = NULL;
-	l->l_flag &= ~LW_SINTR;
+	l->l_flag &= wakeup ? ~(LW_SINTR|LW_CATCHINTR|LW_STIMO) : ~LW_SINTR;
 
 	ci = l->l_cpu;
 	spc = >ci_schedstate;
@@ -409,7 +416,6 @@ sleepq_block(int timo, bool catch_p, syn
 	 */
 	flag = atomic_load_relaxed(>l_flag);
 	if (__predict_false((flag & mask) != 0)) {
-		p = l->l_proc;
 		if ((flag & LW_CATCHINTR) == 0 && error != 0)
 			/* nothing */;
 		else if ((flag & (LW_CANCELLED | LW_WEXIT | LW_WCORE)) != 0)
@@ -422,6 +428,7 

CVS commit: src/sys

2023-10-08 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sun Oct  8 13:23:05 UTC 2023

Modified Files:
src/sys/kern: kern_condvar.c kern_sleepq.c kern_timeout.c
kern_turnstile.c sys_lwp.c sys_select.c
src/sys/rump/librump/rumpkern: sleepq.c
src/sys/sys: sleepq.h syncobj.h

Log Message:
Ensure that an LWP that has taken a legitimate wakeup never produces an
error code from sleepq_block().  Then, it's possible to make cv_signal()
work as expected and only ever wake a singular LWP.


To generate a diff of this commit:
cvs rdiff -u -r1.57 -r1.58 src/sys/kern/kern_condvar.c
cvs rdiff -u -r1.81 -r1.82 src/sys/kern/kern_sleepq.c
cvs rdiff -u -r1.78 -r1.79 src/sys/kern/kern_timeout.c
cvs rdiff -u -r1.52 -r1.53 src/sys/kern/kern_turnstile.c
cvs rdiff -u -r1.86 -r1.87 src/sys/kern/sys_lwp.c
cvs rdiff -u -r1.63 -r1.64 src/sys/kern/sys_select.c
cvs rdiff -u -r1.26 -r1.27 src/sys/rump/librump/rumpkern/sleepq.c
cvs rdiff -u -r1.39 -r1.40 src/sys/sys/sleepq.h
cvs rdiff -u -r1.16 -r1.17 src/sys/sys/syncobj.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/kern

2023-10-08 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sun Oct  8 12:38:58 UTC 2023

Modified Files:
src/sys/kern: kern_exec.c kern_exit.c

Log Message:
Defer some wakeups till lock release.


To generate a diff of this commit:
cvs rdiff -u -r1.520 -r1.521 src/sys/kern/kern_exec.c
cvs rdiff -u -r1.297 -r1.298 src/sys/kern/kern_exit.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/kern

2023-10-08 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sun Oct  8 12:38:58 UTC 2023

Modified Files:
src/sys/kern: kern_exec.c kern_exit.c

Log Message:
Defer some wakeups till lock release.


To generate a diff of this commit:
cvs rdiff -u -r1.520 -r1.521 src/sys/kern/kern_exec.c
cvs rdiff -u -r1.297 -r1.298 src/sys/kern/kern_exit.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_exec.c
diff -u src/sys/kern/kern_exec.c:1.520 src/sys/kern/kern_exec.c:1.521
--- src/sys/kern/kern_exec.c:1.520	Wed Oct  4 22:17:09 2023
+++ src/sys/kern/kern_exec.c	Sun Oct  8 12:38:58 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_exec.c,v 1.520 2023/10/04 22:17:09 ad Exp $	*/
+/*	$NetBSD: kern_exec.c,v 1.521 2023/10/08 12:38:58 ad Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2019, 2020 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.520 2023/10/04 22:17:09 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.521 2023/10/08 12:38:58 ad Exp $");
 
 #include "opt_exec.h"
 #include "opt_execfmt.h"
@@ -1314,7 +1314,6 @@ execve_runproc(struct lwp *l, struct exe
 		lp = p->p_vforklwp;
 		p->p_vforklwp = NULL;
 		l->l_lwpctl = NULL; /* was on loan from blocked parent */
-		cv_broadcast(>l_waitcv);
 
 		/* Clear flags after cv_broadcast() (scheduler needs them). */
 		p->p_lflag &= ~PL_PPWAIT;
@@ -1322,6 +1321,7 @@ execve_runproc(struct lwp *l, struct exe
 
 		/* If parent is still on same CPU, teleport curlwp elsewhere. */
 		samecpu = (lp->l_cpu == curlwp->l_cpu);
+		cv_broadcast(>l_waitcv);
 		mutex_exit(_lock);
 
 		/* Give the parent its CPU back - find a new home. */

Index: src/sys/kern/kern_exit.c
diff -u src/sys/kern/kern_exit.c:1.297 src/sys/kern/kern_exit.c:1.298
--- src/sys/kern/kern_exit.c:1.297	Wed Oct  4 20:48:13 2023
+++ src/sys/kern/kern_exit.c	Sun Oct  8 12:38:58 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_exit.c,v 1.297 2023/10/04 20:48:13 ad Exp $	*/
+/*	$NetBSD: kern_exit.c,v 1.298 2023/10/08 12:38:58 ad Exp $	*/
 
 /*-
  * Copyright (c) 1998, 1999, 2006, 2007, 2008, 2020, 2023
@@ -68,7 +68,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_exit.c,v 1.297 2023/10/04 20:48:13 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_exit.c,v 1.298 2023/10/08 12:38:58 ad Exp $");
 
 #include "opt_ktrace.h"
 #include "opt_dtrace.h"
@@ -548,9 +548,6 @@ exit1(struct lwp *l, int exitcode, int s
 	calcru(p, >p_stats->p_ru.ru_utime, >p_stats->p_ru.ru_stime,
 	NULL, NULL);
 
-	if (wakeinit)
-		cv_broadcast(>p_waitcv);
-
 	callout_destroy(>l_timeout_ch);
 
 	/*
@@ -558,7 +555,6 @@ exit1(struct lwp *l, int exitcode, int s
 	 */
 	pcu_discard_all(l);
 
-	mutex_enter(p->p_lock);
 	/*
 	 * Notify other processes tracking us with a knote that
 	 * we're exiting.
@@ -568,6 +564,7 @@ exit1(struct lwp *l, int exitcode, int s
 	 * knote_proc_exit() expects that p->p_lock is already
 	 * held (and will assert so).
 	 */
+	mutex_enter(p->p_lock);
 	if (!SLIST_EMPTY(>p_klist)) {
 		knote_proc_exit(p);
 	}
@@ -592,9 +589,11 @@ exit1(struct lwp *l, int exitcode, int s
 	 * Signal the parent to collect us, and drop the proclist lock.
 	 * Drop debugger/procfs lock; no new references can be gained.
 	 */
-	cv_broadcast(>p_pptr->p_waitcv);
 	rw_exit(>p_reflock);
+	cv_broadcast(>p_pptr->p_waitcv);
 	mutex_exit(_lock);
+	if (wakeinit)
+		cv_broadcast(>p_waitcv);
 
 	/*
 	 * NOTE: WE ARE NO LONGER ALLOWED TO SLEEP!



CVS commit: src/sys/kern

2023-10-08 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sun Oct  8 11:12:47 UTC 2023

Modified Files:
src/sys/kern: kern_sleepq.c

Log Message:
sleepq_block(): slightly reduce number of test+branch in the common case.


To generate a diff of this commit:
cvs rdiff -u -r1.80 -r1.81 src/sys/kern/kern_sleepq.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_sleepq.c
diff -u src/sys/kern/kern_sleepq.c:1.80 src/sys/kern/kern_sleepq.c:1.81
--- src/sys/kern/kern_sleepq.c:1.80	Sat Oct  7 20:48:50 2023
+++ src/sys/kern/kern_sleepq.c	Sun Oct  8 11:12:47 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_sleepq.c,v 1.80 2023/10/07 20:48:50 ad Exp $	*/
+/*	$NetBSD: kern_sleepq.c,v 1.81 2023/10/08 11:12:47 ad Exp $	*/
 
 /*-
  * Copyright (c) 2006, 2007, 2008, 2009, 2019, 2020, 2023
@@ -36,7 +36,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_sleepq.c,v 1.80 2023/10/07 20:48:50 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_sleepq.c,v 1.81 2023/10/08 11:12:47 ad Exp $");
 
 #include 
 #include 
@@ -334,7 +334,8 @@ sleepq_uncatch(lwp_t *l)
 int
 sleepq_block(int timo, bool catch_p, syncobj_t *syncobj, int nlocks)
 {
-	int error = 0, sig;
+	const int mask = LW_CANCELLED|LW_WEXIT|LW_WCORE|LW_PENDSIG;
+	int error = 0, sig, flag;
 	struct proc *p;
 	lwp_t *l = curlwp;
 	bool early = false;
@@ -406,11 +407,14 @@ sleepq_block(int timo, bool catch_p, syn
 	 * considering it is only meaningful here inside this function,
 	 * and is set to reflect intent upon entry.
 	 */
-	if ((l->l_flag & LW_CATCHINTR) != 0 && error == 0) {
+	flag = atomic_load_relaxed(>l_flag);
+	if (__predict_false((flag & mask) != 0)) {
 		p = l->l_proc;
-		if ((l->l_flag & (LW_CANCELLED | LW_WEXIT | LW_WCORE)) != 0)
+		if ((flag & LW_CATCHINTR) == 0 && error != 0)
+			/* nothing */;
+		else if ((flag & (LW_CANCELLED | LW_WEXIT | LW_WCORE)) != 0)
 			error = EINTR;
-		else if ((l->l_flag & LW_PENDSIG) != 0) {
+		else if ((flag & LW_PENDSIG) != 0) {
 			/*
 			 * Acquiring p_lock may cause us to recurse
 			 * through the sleep path and back into this



CVS commit: src/sys/kern

2023-10-08 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sun Oct  8 11:12:47 UTC 2023

Modified Files:
src/sys/kern: kern_sleepq.c

Log Message:
sleepq_block(): slightly reduce number of test+branch in the common case.


To generate a diff of this commit:
cvs rdiff -u -r1.80 -r1.81 src/sys/kern/kern_sleepq.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/kern

2023-10-07 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Oct  7 20:48:50 UTC 2023

Modified Files:
src/sys/kern: kern_sleepq.c

Log Message:
sleepq_uncatch(): fix typo that's been there since 2020, hello @thorpej lol:

-   l->l_flag = ~(LW_SINTR | LW_CATCHINTR | LW_STIMO);
+   l->l_flag &= ~(LW_SINTR | LW_CATCHINTR | LW_STIMO);


To generate a diff of this commit:
cvs rdiff -u -r1.79 -r1.80 src/sys/kern/kern_sleepq.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_sleepq.c
diff -u src/sys/kern/kern_sleepq.c:1.79 src/sys/kern/kern_sleepq.c:1.80
--- src/sys/kern/kern_sleepq.c:1.79	Sat Oct  7 14:12:29 2023
+++ src/sys/kern/kern_sleepq.c	Sat Oct  7 20:48:50 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_sleepq.c,v 1.79 2023/10/07 14:12:29 ad Exp $	*/
+/*	$NetBSD: kern_sleepq.c,v 1.80 2023/10/07 20:48:50 ad Exp $	*/
 
 /*-
  * Copyright (c) 2006, 2007, 2008, 2009, 2019, 2020, 2023
@@ -36,7 +36,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_sleepq.c,v 1.79 2023/10/07 14:12:29 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_sleepq.c,v 1.80 2023/10/07 20:48:50 ad Exp $");
 
 #include 
 #include 
@@ -319,7 +319,7 @@ void
 sleepq_uncatch(lwp_t *l)
 {
 
-	l->l_flag = ~(LW_SINTR | LW_CATCHINTR | LW_STIMO);
+	l->l_flag &= ~(LW_SINTR | LW_CATCHINTR | LW_STIMO);
 }
 
 /*



CVS commit: src/sys/kern

2023-10-07 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Oct  7 20:48:50 UTC 2023

Modified Files:
src/sys/kern: kern_sleepq.c

Log Message:
sleepq_uncatch(): fix typo that's been there since 2020, hello @thorpej lol:

-   l->l_flag = ~(LW_SINTR | LW_CATCHINTR | LW_STIMO);
+   l->l_flag &= ~(LW_SINTR | LW_CATCHINTR | LW_STIMO);


To generate a diff of this commit:
cvs rdiff -u -r1.79 -r1.80 src/sys/kern/kern_sleepq.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/ddb

2023-10-07 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Oct  7 20:27:20 UTC 2023

Modified Files:
src/sys/ddb: db_command.c db_interface.h db_xxx.c

Log Message:
Add some simple DDB show commands: condvar, selinfo, sleepq


To generate a diff of this commit:
cvs rdiff -u -r1.185 -r1.186 src/sys/ddb/db_command.c
cvs rdiff -u -r1.40 -r1.41 src/sys/ddb/db_interface.h
cvs rdiff -u -r1.75 -r1.76 src/sys/ddb/db_xxx.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ddb/db_command.c
diff -u src/sys/ddb/db_command.c:1.185 src/sys/ddb/db_command.c:1.186
--- src/sys/ddb/db_command.c:1.185	Mon Jul 17 12:55:03 2023
+++ src/sys/ddb/db_command.c	Sat Oct  7 20:27:20 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: db_command.c,v 1.185 2023/07/17 12:55:03 riastradh Exp $	*/
+/*	$NetBSD: db_command.c,v 1.186 2023/10/07 20:27:20 ad Exp $	*/
 
 /*
  * Copyright (c) 1996, 1997, 1998, 1999, 2002, 2009, 2019
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: db_command.c,v 1.185 2023/07/17 12:55:03 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_command.c,v 1.186 2023/10/07 20:27:20 ad Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_aio.h"
@@ -249,6 +249,8 @@ static const struct db_command db_show_c
 	/* added from all sub cmds */
 	{ DDB_ADD_CMD("callout",  db_show_callout,
 	0 ,"List all used callout functions.",NULL,NULL) },
+	{ DDB_ADD_CMD("condvar", db_show_condvar,
+	0 ,"Show the contents of a condition variable.",NULL,NULL) },
 	{ DDB_ADD_CMD("devices", db_show_all_devices,	0,NULL,NULL,NULL) },
 	{ DDB_ADD_CMD("event",	db_event_print_cmd,	0,
 	"Print all the non-zero evcnt(9) event counters.", "[/fitm]",NULL) },
@@ -317,6 +319,10 @@ static const struct db_command db_show_c
 	{ DDB_ADD_CMD("sched_qs",	db_show_sched_qs,	0,
 	"Print the state of the scheduler's run queues.",
 	NULL,NULL) },
+	{ DDB_ADD_CMD("selinfo", db_show_selinfo,
+	0 ,"Show the contents of a selinfo.",NULL,NULL) },
+	{ DDB_ADD_CMD("sleepq", db_show_sleepq,
+	0 ,"Show the contents of a sleep queue.",NULL,NULL) },
 	{ DDB_ADD_CMD("socket",	db_socket_print_cmd,	0,NULL,NULL,NULL) },
 	{ DDB_ADD_CMD("tstiles", db_show_all_tstiles,
 	0, "Show who's holding up tstiles", "[/t]", NULL) },

Index: src/sys/ddb/db_interface.h
diff -u src/sys/ddb/db_interface.h:1.40 src/sys/ddb/db_interface.h:1.41
--- src/sys/ddb/db_interface.h:1.40	Sun Apr 18 01:28:50 2021
+++ src/sys/ddb/db_interface.h	Sat Oct  7 20:27:20 2023
@@ -1,7 +1,7 @@
-/*	$NetBSD: db_interface.h,v 1.40 2021/04/18 01:28:50 mrg Exp $	*/
+/*	$NetBSD: db_interface.h,v 1.41 2023/10/07 20:27:20 ad Exp $	*/
 
 /*-
- * Copyright (c) 1995 The NetBSD Foundation, Inc.
+ * Copyright (c) 1995, 2023 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -52,7 +52,7 @@ void		db_show_all_procs(db_expr_t, bool,
 void		db_show_all_pools(db_expr_t, bool, db_expr_t, const char *);
 void		db_show_sched_qs(db_expr_t, bool, db_expr_t, const char *);
 
-/* kern/kern_clock.c */
+/* kern/kern_timeout.c */
 void		db_show_callout(db_expr_t, bool, db_expr_t, const char *);
 
 /* kern/subr_log.c */
@@ -80,6 +80,15 @@ void		db_show_all_device(db_expr_t, bool
 /* kern/subr_disk.c, dev/dksubr.c */
 void		db_show_disk(db_expr_t, bool, db_expr_t, const char *);
 
+/* kern/kern_sleepq.c */
+void		db_show_sleepq(db_expr_t, bool, db_expr_t, const char *);
+
+/* kern/kern_condvar.c */
+void		db_show_condvar(db_expr_t, bool, db_expr_t, const char *);
+
+/* kern/sys_select.c */
+void		db_show_selinfo(db_expr_t, bool, db_expr_t, const char *);
+
 /* The db_stacktrace_print macro may be overridden by an MD macro */
 #ifndef db_stacktrace_print
 #define	db_stacktrace_print(prfunc) \

Index: src/sys/ddb/db_xxx.c
diff -u src/sys/ddb/db_xxx.c:1.75 src/sys/ddb/db_xxx.c:1.76
--- src/sys/ddb/db_xxx.c:1.75	Sat May 23 23:42:42 2020
+++ src/sys/ddb/db_xxx.c	Sat Oct  7 20:27:20 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: db_xxx.c,v 1.75 2020/05/23 23:42:42 ad Exp $	*/
+/*	$NetBSD: db_xxx.c,v 1.76 2023/10/07 20:27:20 ad Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1991, 1993
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: db_xxx.c,v 1.75 2020/05/23 23:42:42 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_xxx.c,v 1.76 2023/10/07 20:27:20 ad Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_kgdb.h"
@@ -69,6 +69,9 @@ __KERNEL_RCSID(0, "$NetBSD: db_xxx.c,v 1
 #include 
 #include 
 #include 
+#include 
+#include 
+#include 
 
 #include 
 #include 
@@ -325,3 +328,52 @@ db_show_panic(db_expr_t addr, bool haddr
 	(void)splx(s);
 #endif
 }
+
+void
+db_show_condvar(db_expr_t addr, bool haddr, db_expr_t count, const char *modif)
+{
+	kcondvar_t *cv = (kcondvar_t *)addr;
+	char buf[9], *wmesg;
+
+	/* XXX messing with kcondvar_t guts without defs */
+	db_read_bytes((db_addr_t)>cv_opaque[1], sizeof(wmesg),
+	(char *));
+	

CVS commit: src/sys/ddb

2023-10-07 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Oct  7 20:27:20 UTC 2023

Modified Files:
src/sys/ddb: db_command.c db_interface.h db_xxx.c

Log Message:
Add some simple DDB show commands: condvar, selinfo, sleepq


To generate a diff of this commit:
cvs rdiff -u -r1.185 -r1.186 src/sys/ddb/db_command.c
cvs rdiff -u -r1.40 -r1.41 src/sys/ddb/db_interface.h
cvs rdiff -u -r1.75 -r1.76 src/sys/ddb/db_xxx.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/ddb

2023-10-07 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Oct  7 20:22:53 UTC 2023

Modified Files:
src/sys/ddb: db_output.c db_output.h

Log Message:
Oops, fix crash(8) build


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/sys/ddb/db_output.c
cvs rdiff -u -r1.23 -r1.24 src/sys/ddb/db_output.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ddb/db_output.c
diff -u src/sys/ddb/db_output.c:1.37 src/sys/ddb/db_output.c:1.38
--- src/sys/ddb/db_output.c:1.37	Sat Oct  7 20:00:39 2023
+++ src/sys/ddb/db_output.c	Sat Oct  7 20:22:53 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: db_output.c,v 1.37 2023/10/07 20:00:39 ad Exp $	*/
+/*	$NetBSD: db_output.c,v 1.38 2023/10/07 20:22:53 ad Exp $	*/
 
 /*
  * Mach Operating System
@@ -35,11 +35,12 @@
 #endif
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: db_output.c,v 1.37 2023/10/07 20:00:39 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_output.c,v 1.38 2023/10/07 20:22:53 ad Exp $");
 
 #include 
 #include 
 #include 
+#include 
 
 #include 
 

Index: src/sys/ddb/db_output.h
diff -u src/sys/ddb/db_output.h:1.23 src/sys/ddb/db_output.h:1.24
--- src/sys/ddb/db_output.h:1.23	Sat Oct  7 20:00:39 2023
+++ src/sys/ddb/db_output.h	Sat Oct  7 20:22:53 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: db_output.h,v 1.23 2023/10/07 20:00:39 ad Exp $	*/
+/*	$NetBSD: db_output.h,v 1.24 2023/10/07 20:22:53 ad Exp $	*/
 
 /*
  * Mach Operating System
@@ -34,6 +34,8 @@
 
 #include 
 
+struct timespec;
+
 /*
  * Printing routines for kernel debugger.
  */



CVS commit: src/sys/ddb

2023-10-07 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Oct  7 20:22:53 UTC 2023

Modified Files:
src/sys/ddb: db_output.c db_output.h

Log Message:
Oops, fix crash(8) build


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/sys/ddb/db_output.c
cvs rdiff -u -r1.23 -r1.24 src/sys/ddb/db_output.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/ddb

2023-10-07 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Oct  7 20:00:40 UTC 2023

Modified Files:
src/sys/ddb: db_output.c db_output.h

Log Message:
Add db_print_timespec().


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/sys/ddb/db_output.c
cvs rdiff -u -r1.22 -r1.23 src/sys/ddb/db_output.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ddb/db_output.c
diff -u src/sys/ddb/db_output.c:1.36 src/sys/ddb/db_output.c:1.37
--- src/sys/ddb/db_output.c:1.36	Sun Jan 26 01:42:55 2020
+++ src/sys/ddb/db_output.c	Sat Oct  7 20:00:39 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: db_output.c,v 1.36 2020/01/26 01:42:55 uwe Exp $	*/
+/*	$NetBSD: db_output.c,v 1.37 2023/10/07 20:00:39 ad Exp $	*/
 
 /*
  * Mach Operating System
@@ -35,7 +35,7 @@
 #endif
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: db_output.c,v 1.36 2020/01/26 01:42:55 uwe Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_output.c,v 1.37 2023/10/07 20:00:39 ad Exp $");
 
 #include 
 #include 
@@ -254,3 +254,13 @@ db_format_hex(char *buf, size_t bufsiz, 
 
 	snprintf(buf, bufsiz, fmt, val);
 }
+
+/*
+ * Print out a timespec value.
+ */
+void
+db_print_timespec(struct timespec *ts)
+{
+
+	db_printf("%" PRIu64 ".%09ld", (uint64_t)ts->tv_sec, ts->tv_nsec);
+}

Index: src/sys/ddb/db_output.h
diff -u src/sys/ddb/db_output.h:1.22 src/sys/ddb/db_output.h:1.23
--- src/sys/ddb/db_output.h:1.22	Sun Jun 28 04:06:14 2020
+++ src/sys/ddb/db_output.h	Sat Oct  7 20:00:39 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: db_output.h,v 1.22 2020/06/28 04:06:14 simonb Exp $	*/
+/*	$NetBSD: db_output.h,v 1.23 2023/10/07 20:00:39 ad Exp $	*/
 
 /*
  * Mach Operating System
@@ -45,6 +45,7 @@ void	db_vprintf(const char *, va_list) _
 void	db_format_radix(char *, size_t, quad_t, int);
 void	db_format_hex(char *, size_t, quad_t, int);
 void	db_end_line(void);
+void	db_print_timespec(struct timespec *);
 
 extern int	db_max_line;
 extern int	db_max_width;



CVS commit: src/sys/ddb

2023-10-07 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Oct  7 20:00:40 UTC 2023

Modified Files:
src/sys/ddb: db_output.c db_output.h

Log Message:
Add db_print_timespec().


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/sys/ddb/db_output.c
cvs rdiff -u -r1.22 -r1.23 src/sys/ddb/db_output.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/kern

2023-10-07 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Oct  7 14:12:29 UTC 2023

Modified Files:
src/sys/kern: kern_sleepq.c

Log Message:
sleepq_uncatch(): clear LW_STIMO too, so that there's no possibility that
the newly non-interruptable sleep could produce EWOULDBLOCK (paranoia).


To generate a diff of this commit:
cvs rdiff -u -r1.78 -r1.79 src/sys/kern/kern_sleepq.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_sleepq.c
diff -u src/sys/kern/kern_sleepq.c:1.78 src/sys/kern/kern_sleepq.c:1.79
--- src/sys/kern/kern_sleepq.c:1.78	Thu Oct  5 19:28:30 2023
+++ src/sys/kern/kern_sleepq.c	Sat Oct  7 14:12:29 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_sleepq.c,v 1.78 2023/10/05 19:28:30 ad Exp $	*/
+/*	$NetBSD: kern_sleepq.c,v 1.79 2023/10/07 14:12:29 ad Exp $	*/
 
 /*-
  * Copyright (c) 2006, 2007, 2008, 2009, 2019, 2020, 2023
@@ -36,7 +36,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_sleepq.c,v 1.78 2023/10/05 19:28:30 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_sleepq.c,v 1.79 2023/10/07 14:12:29 ad Exp $");
 
 #include 
 #include 
@@ -318,7 +318,8 @@ sleepq_transfer(lwp_t *l, sleepq_t *from
 void
 sleepq_uncatch(lwp_t *l)
 {
-	l->l_flag = ~(LW_SINTR | LW_CATCHINTR);
+
+	l->l_flag = ~(LW_SINTR | LW_CATCHINTR | LW_STIMO);
 }
 
 /*



CVS commit: src/sys/kern

2023-10-07 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Oct  7 14:12:29 UTC 2023

Modified Files:
src/sys/kern: kern_sleepq.c

Log Message:
sleepq_uncatch(): clear LW_STIMO too, so that there's no possibility that
the newly non-interruptable sleep could produce EWOULDBLOCK (paranoia).


To generate a diff of this commit:
cvs rdiff -u -r1.78 -r1.79 src/sys/kern/kern_sleepq.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/kern

2023-10-05 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Thu Oct  5 19:44:26 UTC 2023

Modified Files:
src/sys/kern: sys_pipe.c

Log Message:
Update comments to match reality


To generate a diff of this commit:
cvs rdiff -u -r1.163 -r1.164 src/sys/kern/sys_pipe.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/kern

2023-10-05 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Thu Oct  5 19:44:26 UTC 2023

Modified Files:
src/sys/kern: sys_pipe.c

Log Message:
Update comments to match reality


To generate a diff of this commit:
cvs rdiff -u -r1.163 -r1.164 src/sys/kern/sys_pipe.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/sys_pipe.c
diff -u src/sys/kern/sys_pipe.c:1.163 src/sys/kern/sys_pipe.c:1.164
--- src/sys/kern/sys_pipe.c:1.163	Wed Oct  4 22:41:56 2023
+++ src/sys/kern/sys_pipe.c	Thu Oct  5 19:44:26 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: sys_pipe.c,v 1.163 2023/10/04 22:41:56 ad Exp $	*/
+/*	$NetBSD: sys_pipe.c,v 1.164 2023/10/05 19:44:26 ad Exp $	*/
 
 /*-
  * Copyright (c) 2003, 2007, 2008, 2009, 2023 The NetBSD Foundation, Inc.
@@ -52,23 +52,10 @@
  * This file contains a high-performance replacement for the socket-based
  * pipes scheme originally used.  It does not support all features of
  * sockets, but does do everything that pipes normally do.
- *
- * This code has two modes of operation, a small write mode and a large
- * write mode.  The small write mode acts like conventional pipes with
- * a kernel buffer.  If the buffer is less than PIPE_MINDIRECT, then the
- * "normal" pipe buffering is done.  If the buffer is between PIPE_MINDIRECT
- * and PIPE_SIZE in size it is mapped read-only into the kernel address space
- * using the UVM page loan facility from where the receiving process can copy
- * the data directly from the pages in the sending process.
- *
- * The constant PIPE_MINDIRECT is chosen to make sure that buffering will
- * happen for small transfers so that the system will not spend all of
- * its time context switching.  PIPE_SIZE is constrained by the
- * amount of kernel virtual memory.
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sys_pipe.c,v 1.163 2023/10/04 22:41:56 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_pipe.c,v 1.164 2023/10/05 19:44:26 ad Exp $");
 
 #include 
 #include 
@@ -746,8 +733,6 @@ pipe_write(file_t *fp, off_t *offset, st
 
 	/*
 	 * We have something to offer, wake up select/poll.
-	 * wmap->cnt is always 0 in this point (direct write
-	 * is only done synchronously), so check only wpipe->pipe_buffer.cnt
 	 */
 	if (bp->cnt)
 		pipeselwakeup(wpipe, wpipe, POLL_IN);



CVS commit: src/sys

2023-10-05 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Thu Oct  5 19:41:07 UTC 2023

Modified Files:
src/sys/arch/aarch64/aarch64: aarch32_syscall.c syscall.c
src/sys/arch/alpha/alpha: linux_syscall.c syscall.c trap.c
src/sys/arch/amd64/amd64: linux32_syscall.c linux_syscall.c
netbsd32_syscall.c trap.c
src/sys/arch/amiga/amiga: trap.c
src/sys/arch/arm/arm: syscall.c undefined.c
src/sys/arch/arm/arm32: fault.c
src/sys/arch/atari/atari: trap.c
src/sys/arch/cesfic/cesfic: trap.c
src/sys/arch/hp300/hp300: trap.c
src/sys/arch/hppa/hppa: trap.c
src/sys/arch/i386/i386: linux_syscall.c trap.c
src/sys/arch/ia64/ia64: trap.c
src/sys/arch/luna68k/luna68k: trap.c
src/sys/arch/m68k/m68k: m68k_syscall.c
src/sys/arch/mac68k/mac68k: trap.c
src/sys/arch/mips/mips: syscall.c trap.c
src/sys/arch/mvme68k/mvme68k: trap.c
src/sys/arch/news68k/news68k: trap.c
src/sys/arch/next68k/next68k: trap.c
src/sys/arch/powerpc/ibm4xx: trap.c
src/sys/arch/powerpc/powerpc: syscall.c trap.c
src/sys/arch/riscv/riscv: syscall.c
src/sys/arch/sh3/sh3: exception.c
src/sys/arch/sparc/sparc: syscall.c trap.c
src/sys/arch/sparc64/sparc64: syscall.c trap.c
src/sys/arch/sun2/sun2: trap.c
src/sys/arch/sun3/sun3: trap.c
src/sys/arch/usermode/usermode: syscall.c
src/sys/arch/vax/vax: syscall.c trap.c
src/sys/arch/x68k/x68k: trap.c
src/sys/arch/x86/x86: syscall.c
src/sys/compat/freebsd: freebsd_syscall.c
src/sys/kern: kern_lwp.c kern_proc.c
src/sys/rump/librump/rumpkern: lwproc.c rump.c scheduler.c
src/sys/sys: lwp.h

Log Message:
Arrange to update cached LWP credentials in userret() rather than during
syscall/trap entry, eliminating a test+branch on every syscall/trap.

This wasn't possible in the 3.99.x timeframe when l->l_cred came about
because there wasn't a reliable/timely way to force an ONPROC LWP running on
a remote CPU into the kernel (which is just about the only new thing in
this scheme).


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/aarch64/aarch64/aarch32_syscall.c
cvs rdiff -u -r1.12 -r1.13 src/sys/arch/aarch64/aarch64/syscall.c
cvs rdiff -u -r1.33 -r1.34 src/sys/arch/alpha/alpha/linux_syscall.c
cvs rdiff -u -r1.44 -r1.45 src/sys/arch/alpha/alpha/syscall.c
cvs rdiff -u -r1.138 -r1.139 src/sys/arch/alpha/alpha/trap.c
cvs rdiff -u -r1.32 -r1.33 src/sys/arch/amd64/amd64/linux32_syscall.c \
src/sys/arch/amd64/amd64/linux_syscall.c
cvs rdiff -u -r1.33 -r1.34 src/sys/arch/amd64/amd64/netbsd32_syscall.c
cvs rdiff -u -r1.128 -r1.129 src/sys/arch/amd64/amd64/trap.c
cvs rdiff -u -r1.139 -r1.140 src/sys/arch/amiga/amiga/trap.c
cvs rdiff -u -r1.68 -r1.69 src/sys/arch/arm/arm/syscall.c
cvs rdiff -u -r1.74 -r1.75 src/sys/arch/arm/arm/undefined.c
cvs rdiff -u -r1.116 -r1.117 src/sys/arch/arm/arm32/fault.c
cvs rdiff -u -r1.118 -r1.119 src/sys/arch/atari/atari/trap.c
cvs rdiff -u -r1.61 -r1.62 src/sys/arch/cesfic/cesfic/trap.c
cvs rdiff -u -r1.157 -r1.158 src/sys/arch/hp300/hp300/trap.c
cvs rdiff -u -r1.122 -r1.123 src/sys/arch/hppa/hppa/trap.c
cvs rdiff -u -r1.54 -r1.55 src/sys/arch/i386/i386/linux_syscall.c
cvs rdiff -u -r1.308 -r1.309 src/sys/arch/i386/i386/trap.c
cvs rdiff -u -r1.15 -r1.16 src/sys/arch/ia64/ia64/trap.c
cvs rdiff -u -r1.77 -r1.78 src/sys/arch/luna68k/luna68k/trap.c
cvs rdiff -u -r1.54 -r1.55 src/sys/arch/m68k/m68k/m68k_syscall.c
cvs rdiff -u -r1.152 -r1.153 src/sys/arch/mac68k/mac68k/trap.c
cvs rdiff -u -r1.50 -r1.51 src/sys/arch/mips/mips/syscall.c
cvs rdiff -u -r1.263 -r1.264 src/sys/arch/mips/mips/trap.c
cvs rdiff -u -r1.113 -r1.114 src/sys/arch/mvme68k/mvme68k/trap.c
cvs rdiff -u -r1.75 -r1.76 src/sys/arch/news68k/news68k/trap.c
cvs rdiff -u -r1.93 -r1.94 src/sys/arch/next68k/next68k/trap.c
cvs rdiff -u -r1.101 -r1.102 src/sys/arch/powerpc/ibm4xx/trap.c
cvs rdiff -u -r1.57 -r1.58 src/sys/arch/powerpc/powerpc/syscall.c
cvs rdiff -u -r1.163 -r1.164 src/sys/arch/powerpc/powerpc/trap.c
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/riscv/riscv/syscall.c
cvs rdiff -u -r1.74 -r1.75 src/sys/arch/sh3/sh3/exception.c
cvs rdiff -u -r1.32 -r1.33 src/sys/arch/sparc/sparc/syscall.c
cvs rdiff -u -r1.200 -r1.201 src/sys/arch/sparc/sparc/trap.c
cvs rdiff -u -r1.48 -r1.49 src/sys/arch/sparc64/sparc64/syscall.c
cvs rdiff -u -r1.194 -r1.195 src/sys/arch/sparc64/sparc64/trap.c
cvs rdiff -u -r1.46 -r1.47 src/sys/arch/sun2/sun2/trap.c
cvs rdiff -u -r1.147 -r1.148 src/sys/arch/sun3/sun3/trap.c
cvs rdiff -u -r1.26 -r1.27 src/sys/arch/usermode/usermode/syscall.c
cvs rdiff -u -r1.26 -r1.27 src/sys/arch/vax/vax/syscall.c
cvs rdiff -u -r1.137 -r1.138 src/sys/arch/vax/vax/trap.c
cvs rdiff -u -r1.111 -r1.112 src/sys/arch/x68k/x68k/trap.c
cvs rdiff -u -r1.21 -r1.22 src/sys/arch/x86/x86/syscall.c
cvs rdiff -u -r1.6 -r1.7 

CVS commit: src/sys

2023-10-05 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Thu Oct  5 19:41:07 UTC 2023

Modified Files:
src/sys/arch/aarch64/aarch64: aarch32_syscall.c syscall.c
src/sys/arch/alpha/alpha: linux_syscall.c syscall.c trap.c
src/sys/arch/amd64/amd64: linux32_syscall.c linux_syscall.c
netbsd32_syscall.c trap.c
src/sys/arch/amiga/amiga: trap.c
src/sys/arch/arm/arm: syscall.c undefined.c
src/sys/arch/arm/arm32: fault.c
src/sys/arch/atari/atari: trap.c
src/sys/arch/cesfic/cesfic: trap.c
src/sys/arch/hp300/hp300: trap.c
src/sys/arch/hppa/hppa: trap.c
src/sys/arch/i386/i386: linux_syscall.c trap.c
src/sys/arch/ia64/ia64: trap.c
src/sys/arch/luna68k/luna68k: trap.c
src/sys/arch/m68k/m68k: m68k_syscall.c
src/sys/arch/mac68k/mac68k: trap.c
src/sys/arch/mips/mips: syscall.c trap.c
src/sys/arch/mvme68k/mvme68k: trap.c
src/sys/arch/news68k/news68k: trap.c
src/sys/arch/next68k/next68k: trap.c
src/sys/arch/powerpc/ibm4xx: trap.c
src/sys/arch/powerpc/powerpc: syscall.c trap.c
src/sys/arch/riscv/riscv: syscall.c
src/sys/arch/sh3/sh3: exception.c
src/sys/arch/sparc/sparc: syscall.c trap.c
src/sys/arch/sparc64/sparc64: syscall.c trap.c
src/sys/arch/sun2/sun2: trap.c
src/sys/arch/sun3/sun3: trap.c
src/sys/arch/usermode/usermode: syscall.c
src/sys/arch/vax/vax: syscall.c trap.c
src/sys/arch/x68k/x68k: trap.c
src/sys/arch/x86/x86: syscall.c
src/sys/compat/freebsd: freebsd_syscall.c
src/sys/kern: kern_lwp.c kern_proc.c
src/sys/rump/librump/rumpkern: lwproc.c rump.c scheduler.c
src/sys/sys: lwp.h

Log Message:
Arrange to update cached LWP credentials in userret() rather than during
syscall/trap entry, eliminating a test+branch on every syscall/trap.

This wasn't possible in the 3.99.x timeframe when l->l_cred came about
because there wasn't a reliable/timely way to force an ONPROC LWP running on
a remote CPU into the kernel (which is just about the only new thing in
this scheme).


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/aarch64/aarch64/aarch32_syscall.c
cvs rdiff -u -r1.12 -r1.13 src/sys/arch/aarch64/aarch64/syscall.c
cvs rdiff -u -r1.33 -r1.34 src/sys/arch/alpha/alpha/linux_syscall.c
cvs rdiff -u -r1.44 -r1.45 src/sys/arch/alpha/alpha/syscall.c
cvs rdiff -u -r1.138 -r1.139 src/sys/arch/alpha/alpha/trap.c
cvs rdiff -u -r1.32 -r1.33 src/sys/arch/amd64/amd64/linux32_syscall.c \
src/sys/arch/amd64/amd64/linux_syscall.c
cvs rdiff -u -r1.33 -r1.34 src/sys/arch/amd64/amd64/netbsd32_syscall.c
cvs rdiff -u -r1.128 -r1.129 src/sys/arch/amd64/amd64/trap.c
cvs rdiff -u -r1.139 -r1.140 src/sys/arch/amiga/amiga/trap.c
cvs rdiff -u -r1.68 -r1.69 src/sys/arch/arm/arm/syscall.c
cvs rdiff -u -r1.74 -r1.75 src/sys/arch/arm/arm/undefined.c
cvs rdiff -u -r1.116 -r1.117 src/sys/arch/arm/arm32/fault.c
cvs rdiff -u -r1.118 -r1.119 src/sys/arch/atari/atari/trap.c
cvs rdiff -u -r1.61 -r1.62 src/sys/arch/cesfic/cesfic/trap.c
cvs rdiff -u -r1.157 -r1.158 src/sys/arch/hp300/hp300/trap.c
cvs rdiff -u -r1.122 -r1.123 src/sys/arch/hppa/hppa/trap.c
cvs rdiff -u -r1.54 -r1.55 src/sys/arch/i386/i386/linux_syscall.c
cvs rdiff -u -r1.308 -r1.309 src/sys/arch/i386/i386/trap.c
cvs rdiff -u -r1.15 -r1.16 src/sys/arch/ia64/ia64/trap.c
cvs rdiff -u -r1.77 -r1.78 src/sys/arch/luna68k/luna68k/trap.c
cvs rdiff -u -r1.54 -r1.55 src/sys/arch/m68k/m68k/m68k_syscall.c
cvs rdiff -u -r1.152 -r1.153 src/sys/arch/mac68k/mac68k/trap.c
cvs rdiff -u -r1.50 -r1.51 src/sys/arch/mips/mips/syscall.c
cvs rdiff -u -r1.263 -r1.264 src/sys/arch/mips/mips/trap.c
cvs rdiff -u -r1.113 -r1.114 src/sys/arch/mvme68k/mvme68k/trap.c
cvs rdiff -u -r1.75 -r1.76 src/sys/arch/news68k/news68k/trap.c
cvs rdiff -u -r1.93 -r1.94 src/sys/arch/next68k/next68k/trap.c
cvs rdiff -u -r1.101 -r1.102 src/sys/arch/powerpc/ibm4xx/trap.c
cvs rdiff -u -r1.57 -r1.58 src/sys/arch/powerpc/powerpc/syscall.c
cvs rdiff -u -r1.163 -r1.164 src/sys/arch/powerpc/powerpc/trap.c
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/riscv/riscv/syscall.c
cvs rdiff -u -r1.74 -r1.75 src/sys/arch/sh3/sh3/exception.c
cvs rdiff -u -r1.32 -r1.33 src/sys/arch/sparc/sparc/syscall.c
cvs rdiff -u -r1.200 -r1.201 src/sys/arch/sparc/sparc/trap.c
cvs rdiff -u -r1.48 -r1.49 src/sys/arch/sparc64/sparc64/syscall.c
cvs rdiff -u -r1.194 -r1.195 src/sys/arch/sparc64/sparc64/trap.c
cvs rdiff -u -r1.46 -r1.47 src/sys/arch/sun2/sun2/trap.c
cvs rdiff -u -r1.147 -r1.148 src/sys/arch/sun3/sun3/trap.c
cvs rdiff -u -r1.26 -r1.27 src/sys/arch/usermode/usermode/syscall.c
cvs rdiff -u -r1.26 -r1.27 src/sys/arch/vax/vax/syscall.c
cvs rdiff -u -r1.137 -r1.138 src/sys/arch/vax/vax/trap.c
cvs rdiff -u -r1.111 -r1.112 src/sys/arch/x68k/x68k/trap.c
cvs rdiff -u -r1.21 -r1.22 src/sys/arch/x86/x86/syscall.c
cvs rdiff -u -r1.6 -r1.7 

Re: CVS commit: src/sys

2023-10-05 Thread Andrew Doran
On Thu, Oct 05, 2023 at 12:15:23PM +0200, Martin Husemann wrote:

> On Thu, Oct 05, 2023 at 09:59:49AM +0000, Andrew Doran wrote:
> > Yes that makes sense and is what I plan to do after work today if nobody
> > beats me to it.  MULTIPROCESSOR is long overdue removal from the MI kernel,
> > IMO.
> 
> Hey, this is a tiny landisk kernel, do not bloat it :-)

And I thought I had more of a reputation for tearing things out of the OS..

> Unfortunately it is not trivial to make that zeroing happen in the
> macros that we have now (gcc is pretty picky with warnings, would love
> to have c++ templates here).

I rearranged things so it shouldn't be necessary.. At least a pmax kernel
builds for me now.  Sorry about the interruption.

Andrew


CVS commit: src/sys

2023-10-05 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Thu Oct  5 19:28:30 UTC 2023

Modified Files:
src/sys/kern: kern_sleepq.c kern_synch.c
src/sys/rump/librump/rumpkern: sleepq.c

Log Message:
Resolve !MULTIPROCESSOR build problem with the nasty kernel lock macros.


To generate a diff of this commit:
cvs rdiff -u -r1.77 -r1.78 src/sys/kern/kern_sleepq.c
cvs rdiff -u -r1.362 -r1.363 src/sys/kern/kern_synch.c
cvs rdiff -u -r1.25 -r1.26 src/sys/rump/librump/rumpkern/sleepq.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_sleepq.c
diff -u src/sys/kern/kern_sleepq.c:1.77 src/sys/kern/kern_sleepq.c:1.78
--- src/sys/kern/kern_sleepq.c:1.77	Wed Oct  4 20:29:18 2023
+++ src/sys/kern/kern_sleepq.c	Thu Oct  5 19:28:30 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_sleepq.c,v 1.77 2023/10/04 20:29:18 ad Exp $	*/
+/*	$NetBSD: kern_sleepq.c,v 1.78 2023/10/05 19:28:30 ad Exp $	*/
 
 /*-
  * Copyright (c) 2006, 2007, 2008, 2009, 2019, 2020, 2023
@@ -36,7 +36,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_sleepq.c,v 1.77 2023/10/04 20:29:18 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_sleepq.c,v 1.78 2023/10/05 19:28:30 ad Exp $");
 
 #include 
 #include 
@@ -222,13 +222,19 @@ sleepq_enter(sleepq_t *sq, lwp_t *l, kmu
 {
 	int nlocks;
 
+	KASSERT((sq != NULL) == (mp != NULL));
+
 	/*
 	 * Acquire the per-LWP mutex and lend it our sleep queue lock.
 	 * Once interlocked, we can release the kernel lock.
 	 */
 	lwp_lock(l);
-	lwp_unlock_to(l, mp);
-	KERNEL_UNLOCK_ALL(NULL, );
+	if (mp != NULL) {
+		lwp_unlock_to(l, mp);
+	}
+	if (__predict_false((nlocks = l->l_blcnt) != 0)) {
+		KERNEL_UNLOCK_ALL(NULL, NULL);
+	}
 	return nlocks;
 }
 

Index: src/sys/kern/kern_synch.c
diff -u src/sys/kern/kern_synch.c:1.362 src/sys/kern/kern_synch.c:1.363
--- src/sys/kern/kern_synch.c:1.362	Wed Oct  4 20:29:18 2023
+++ src/sys/kern/kern_synch.c	Thu Oct  5 19:28:30 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_synch.c,v 1.362 2023/10/04 20:29:18 ad Exp $	*/
+/*	$NetBSD: kern_synch.c,v 1.363 2023/10/05 19:28:30 ad Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2004, 2006, 2007, 2008, 2009, 2019, 2020, 2023
@@ -69,7 +69,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_synch.c,v 1.362 2023/10/04 20:29:18 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_synch.c,v 1.363 2023/10/05 19:28:30 ad Exp $");
 
 #include "opt_kstack.h"
 #include "opt_ddb.h"
@@ -251,8 +251,7 @@ kpause(const char *wmesg, bool intr, int
 
 	if (mtx != NULL)
 		mutex_exit(mtx);
-	lwp_lock(l);
-	KERNEL_UNLOCK_ALL(NULL, );
+	nlocks = sleepq_enter(NULL, l, NULL);
 	sleepq_enqueue(NULL, l, wmesg, _syncobj, intr);
 	error = sleepq_block(timo, intr, _syncobj, nlocks);
 	if (mtx != NULL)

Index: src/sys/rump/librump/rumpkern/sleepq.c
diff -u src/sys/rump/librump/rumpkern/sleepq.c:1.25 src/sys/rump/librump/rumpkern/sleepq.c:1.26
--- src/sys/rump/librump/rumpkern/sleepq.c:1.25	Wed Oct  4 20:29:18 2023
+++ src/sys/rump/librump/rumpkern/sleepq.c	Thu Oct  5 19:28:30 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: sleepq.c,v 1.25 2023/10/04 20:29:18 ad Exp $	*/
+/*	$NetBSD: sleepq.c,v 1.26 2023/10/05 19:28:30 ad Exp $	*/
 
 /*
  * Copyright (c) 2008 Antti Kantee.  All Rights Reserved.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sleepq.c,v 1.25 2023/10/04 20:29:18 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sleepq.c,v 1.26 2023/10/05 19:28:30 ad Exp $");
 
 #include 
 #include 
@@ -62,8 +62,12 @@ sleepq_enter(sleepq_t *sq, lwp_t *l, kmu
 	int nlocks;
 
 	lwp_lock(l);
-	lwp_unlock_to(l, mp);
-	KERNEL_UNLOCK_ALL(NULL, );
+	if (mp != NULL) {
+		lwp_unlock_to(l, mp);
+	}
+	if ((nlocks = l->l_blcnt) != 0) {
+		KERNEL_UNLOCK_ALL(NULL, NULL);
+	}
 	return nlocks;
 }
 



CVS commit: src/sys

2023-10-05 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Thu Oct  5 19:28:30 UTC 2023

Modified Files:
src/sys/kern: kern_sleepq.c kern_synch.c
src/sys/rump/librump/rumpkern: sleepq.c

Log Message:
Resolve !MULTIPROCESSOR build problem with the nasty kernel lock macros.


To generate a diff of this commit:
cvs rdiff -u -r1.77 -r1.78 src/sys/kern/kern_sleepq.c
cvs rdiff -u -r1.362 -r1.363 src/sys/kern/kern_synch.c
cvs rdiff -u -r1.25 -r1.26 src/sys/rump/librump/rumpkern/sleepq.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/kern

2023-10-05 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Thu Oct  5 19:10:18 UTC 2023

Modified Files:
src/sys/kern: kern_idle.c

Log Message:
The idle LWP doesn't need to care about kernel_lock.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/sys/kern/kern_idle.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_idle.c
diff -u src/sys/kern/kern_idle.c:1.34 src/sys/kern/kern_idle.c:1.35
--- src/sys/kern/kern_idle.c:1.34	Sat Sep  5 16:30:12 2020
+++ src/sys/kern/kern_idle.c	Thu Oct  5 19:10:18 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_idle.c,v 1.34 2020/09/05 16:30:12 riastradh Exp $	*/
+/*	$NetBSD: kern_idle.c,v 1.35 2023/10/05 19:10:18 ad Exp $	*/
 
 /*-
  * Copyright (c)2002, 2006, 2007 YAMAMOTO Takashi,
@@ -28,7 +28,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: kern_idle.c,v 1.34 2020/09/05 16:30:12 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_idle.c,v 1.35 2023/10/05 19:10:18 ad Exp $");
 
 #include 
 #include 
@@ -48,6 +48,8 @@ idle_loop(void *dummy)
 	struct schedstate_percpu *spc;
 	struct lwp *l = curlwp;
 
+	KASSERT(l->l_blcnt == 0);
+
 	lwp_lock(l);
 	spc = >ci_schedstate;
 	KASSERT(lwp_locked(l, spc->spc_lwplock));
@@ -65,7 +67,6 @@ idle_loop(void *dummy)
 	 * in which case we took an odd route to get here.
 	 */
 	spl0();
-	KERNEL_UNLOCK_ALL(l, NULL);
 
 	for (;;) {
 		LOCKDEBUG_BARRIER(NULL, 0);



CVS commit: src/sys/kern

2023-10-05 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Thu Oct  5 19:10:18 UTC 2023

Modified Files:
src/sys/kern: kern_idle.c

Log Message:
The idle LWP doesn't need to care about kernel_lock.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/sys/kern/kern_idle.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/kern

2023-10-05 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Thu Oct  5 19:06:30 UTC 2023

Modified Files:
src/sys/kern: kern_sig.c

Log Message:
kern_sig.c: remove problematic kernel_lock handling which is unneeded in 2023.


To generate a diff of this commit:
cvs rdiff -u -r1.407 -r1.408 src/sys/kern/kern_sig.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_sig.c
diff -u src/sys/kern/kern_sig.c:1.407 src/sys/kern/kern_sig.c:1.408
--- src/sys/kern/kern_sig.c:1.407	Wed Oct  4 20:42:38 2023
+++ src/sys/kern/kern_sig.c	Thu Oct  5 19:06:30 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_sig.c,v 1.407 2023/10/04 20:42:38 ad Exp $	*/
+/*	$NetBSD: kern_sig.c,v 1.408 2023/10/05 19:06:30 ad Exp $	*/
 
 /*-
  * Copyright (c) 2006, 2007, 2008, 2019, 2023 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.407 2023/10/04 20:42:38 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.408 2023/10/05 19:06:30 ad Exp $");
 
 #include "opt_execfmt.h"
 #include "opt_ptrace.h"
@@ -1776,7 +1776,6 @@ static void
 sigswitch_unlock_and_switch_away(struct lwp *l)
 {
 	struct proc *p;
-	int nlocks;
 
 	p = l->l_proc;
 
@@ -1785,9 +1784,8 @@ sigswitch_unlock_and_switch_away(struct 
 
 	KASSERT(l->l_stat == LSONPROC);
 	KASSERT(p->p_nrlwps > 0);
+	KASSERT(l->l_blcnt == 0);
 
-	/* XXXAD in 2023 kernel_lock should not be held here, audit it... */
-	KERNEL_UNLOCK_ALL(l, );
 	if (p->p_stat == SSTOP || (p->p_sflag & PS_STOPPING) != 0) {
 		p->p_nrlwps--;
 		lwp_lock(l);
@@ -1800,7 +1798,6 @@ sigswitch_unlock_and_switch_away(struct 
 	lwp_lock(l);
 	spc_lock(l->l_cpu);
 	mi_switch(l);
-	KERNEL_LOCK(nlocks, l);
 }
 
 /*
@@ -2255,7 +2252,7 @@ sigexit(struct lwp *l, int signo)
 	p = l->l_proc;
 
 	KASSERT(mutex_owned(p->p_lock));
-	KERNEL_UNLOCK_ALL(l, NULL);
+	KASSERT(l->l_blcnt == 0);
 
 	/*
 	 * Don't permit coredump() multiple times in the same process.



CVS commit: src/sys/kern

2023-10-05 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Thu Oct  5 19:06:30 UTC 2023

Modified Files:
src/sys/kern: kern_sig.c

Log Message:
kern_sig.c: remove problematic kernel_lock handling which is unneeded in 2023.


To generate a diff of this commit:
cvs rdiff -u -r1.407 -r1.408 src/sys/kern/kern_sig.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



Re: CVS commit: src/sys

2023-10-05 Thread Andrew Doran
Martin,

On Thu, Oct 05, 2023 at 11:42:03AM +0200, Martin Husemann wrote:

> On Thu, Oct 05, 2023 at 11:36:23AM +0200, Martin Husemann wrote:
> > No, I was confused by the #ifdef maze - it breaks the build for 
> > non-MULTIPROCESSOR kernels only, and I am not actually sure what "use"
> > gcc sees for the "nlocks" variable at all in that case.
> 
> Scratch that too, I'll get coffee.
> 
> Andrew, should we make the non-MULTIPROCESSOR variant of
> 
>   KERNEL_UNLOCK(all, lwp, ptr)
> 
> set *(ptr) = 0 ?

Yes that makes sense and is what I plan to do after work today if nobody
beats me to it.  MULTIPROCESSOR is long overdue removal from the MI kernel,
IMO.

Andrew


CVS commit: src/sys/kern

2023-10-04 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Wed Oct  4 22:41:56 UTC 2023

Modified Files:
src/sys/kern: sys_pipe.c

Log Message:
pipe1(): call getnanotime() once not twice.


To generate a diff of this commit:
cvs rdiff -u -r1.162 -r1.163 src/sys/kern/sys_pipe.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/kern

2023-10-04 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Wed Oct  4 22:41:56 UTC 2023

Modified Files:
src/sys/kern: sys_pipe.c

Log Message:
pipe1(): call getnanotime() once not twice.


To generate a diff of this commit:
cvs rdiff -u -r1.162 -r1.163 src/sys/kern/sys_pipe.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/sys_pipe.c
diff -u src/sys/kern/sys_pipe.c:1.162 src/sys/kern/sys_pipe.c:1.163
--- src/sys/kern/sys_pipe.c:1.162	Wed Oct  4 22:19:58 2023
+++ src/sys/kern/sys_pipe.c	Wed Oct  4 22:41:56 2023
@@ -1,7 +1,7 @@
-/*	$NetBSD: sys_pipe.c,v 1.162 2023/10/04 22:19:58 ad Exp $	*/
+/*	$NetBSD: sys_pipe.c,v 1.163 2023/10/04 22:41:56 ad Exp $	*/
 
 /*-
- * Copyright (c) 2003, 2007, 2008, 2009 The NetBSD Foundation, Inc.
+ * Copyright (c) 2003, 2007, 2008, 2009, 2023 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -68,7 +68,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sys_pipe.c,v 1.162 2023/10/04 22:19:58 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_pipe.c,v 1.163 2023/10/04 22:41:56 ad Exp $");
 
 #include 
 #include 
@@ -131,7 +131,7 @@ static const struct fileops pipeops = {
  * Limit the number of "big" pipes
  */
 #define	LIMITBIGPIPES	32
-static u_int	maxbigpipes = LIMITBIGPIPES;
+static u_int	maxbigpipes __read_mostly = LIMITBIGPIPES;
 static u_int	nbigpipe = 0;
 
 /*
@@ -141,7 +141,7 @@ static u_int	amountpipekva = 0;
 
 static void	pipeclose(struct pipe *);
 static void	pipe_free_kmem(struct pipe *);
-static int	pipe_create(struct pipe **, pool_cache_t);
+static int	pipe_create(struct pipe **, pool_cache_t, struct timespec *);
 static int	pipelock(struct pipe *, bool);
 static inline void pipeunlock(struct pipe *);
 static void	pipeselwakeup(struct pipe *, struct pipe *, int);
@@ -220,6 +220,7 @@ int
 pipe1(struct lwp *l, int *fildes, int flags)
 {
 	struct pipe *rpipe, *wpipe;
+	struct timespec nt;
 	file_t *rf, *wf;
 	int fd, error;
 	proc_t *p;
@@ -228,8 +229,9 @@ pipe1(struct lwp *l, int *fildes, int fl
 		return EINVAL;
 	p = curproc;
 	rpipe = wpipe = NULL;
-	if ((error = pipe_create(, pipe_rd_cache)) ||
-	(error = pipe_create(, pipe_wr_cache))) {
+	getnanotime();
+	if ((error = pipe_create(, pipe_rd_cache, )) ||
+	(error = pipe_create(, pipe_wr_cache, ))) {
 		goto free2;
 	}
 	rpipe->pipe_lock = mutex_obj_alloc(MUTEX_DEFAULT, IPL_NONE);
@@ -312,7 +314,7 @@ pipespace(struct pipe *pipe, int size)
  * Initialize and allocate VM and memory for pipe.
  */
 static int
-pipe_create(struct pipe **pipep, pool_cache_t cache)
+pipe_create(struct pipe **pipep, pool_cache_t cache, struct timespec *nt)
 {
 	struct pipe *pipe;
 	int error;
@@ -321,8 +323,7 @@ pipe_create(struct pipe **pipep, pool_ca
 	KASSERT(pipe != NULL);
 	*pipep = pipe;
 	error = 0;
-	getnanotime(>pipe_btime);
-	pipe->pipe_atime = pipe->pipe_mtime = pipe->pipe_btime;
+	pipe->pipe_atime = pipe->pipe_mtime = pipe->pipe_btime = *nt;
 	pipe->pipe_lock = NULL;
 	if (cache == pipe_rd_cache) {
 		error = pipespace(pipe, PIPE_SIZE);



CVS commit: src/sys

2023-10-04 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Wed Oct  4 22:19:58 UTC 2023

Modified Files:
src/sys/kern: sys_pipe.c
src/sys/sys: pipe.h

Log Message:
pipe->pipe_waiters isn't needed on NetBSD, kernel condvars do this for free.


To generate a diff of this commit:
cvs rdiff -u -r1.161 -r1.162 src/sys/kern/sys_pipe.c
cvs rdiff -u -r1.38 -r1.39 src/sys/sys/pipe.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/sys_pipe.c
diff -u src/sys/kern/sys_pipe.c:1.161 src/sys/kern/sys_pipe.c:1.162
--- src/sys/kern/sys_pipe.c:1.161	Wed Oct  4 22:12:23 2023
+++ src/sys/kern/sys_pipe.c	Wed Oct  4 22:19:58 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: sys_pipe.c,v 1.161 2023/10/04 22:12:23 ad Exp $	*/
+/*	$NetBSD: sys_pipe.c,v 1.162 2023/10/04 22:19:58 ad Exp $	*/
 
 /*-
  * Copyright (c) 2003, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sys_pipe.c,v 1.161 2023/10/04 22:12:23 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_pipe.c,v 1.162 2023/10/04 22:19:58 ad Exp $");
 
 #include 
 #include 
@@ -348,19 +348,13 @@ pipelock(struct pipe *pipe, bool catch_p
 	KASSERT(mutex_owned(pipe->pipe_lock));
 
 	while (pipe->pipe_state & PIPE_LOCKFL) {
-		pipe->pipe_waiters++;
-		KASSERT(pipe->pipe_waiters != 0); /* just in case */
 		if (catch_p) {
 			error = cv_wait_sig(>pipe_lkcv, pipe->pipe_lock);
 			if (error != 0) {
-KASSERT(pipe->pipe_waiters > 0);
-pipe->pipe_waiters--;
 return error;
 			}
 		} else
 			cv_wait(>pipe_lkcv, pipe->pipe_lock);
-		KASSERT(pipe->pipe_waiters > 0);
-		pipe->pipe_waiters--;
 	}
 
 	pipe->pipe_state |= PIPE_LOCKFL;
@@ -378,9 +372,7 @@ pipeunlock(struct pipe *pipe)
 	KASSERT(pipe->pipe_state & PIPE_LOCKFL);
 
 	pipe->pipe_state &= ~PIPE_LOCKFL;
-	if (pipe->pipe_waiters > 0) {
-		cv_signal(>pipe_lkcv);
-	}
+	cv_signal(>pipe_lkcv);
 }
 
 /*

Index: src/sys/sys/pipe.h
diff -u src/sys/sys/pipe.h:1.38 src/sys/sys/pipe.h:1.39
--- src/sys/sys/pipe.h:1.38	Mon Jan 25 19:21:11 2021
+++ src/sys/sys/pipe.h	Wed Oct  4 22:19:58 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: pipe.h,v 1.38 2021/01/25 19:21:11 dholland Exp $ */
+/* $NetBSD: pipe.h,v 1.39 2023/10/04 22:19:58 ad Exp $ */
 
 /*
  * Copyright (c) 1996 John S. Dyson
@@ -98,9 +98,8 @@ struct pipe {
 	struct	timespec pipe_atime;	/* time of last access */
 	struct	timespec pipe_mtime;	/* time of last modify */
 	struct	timespec pipe_btime;	/* time of creation */
-	pid_t	pipe_pgid;		/* process group for sigio */
-	u_int	pipe_waiters;		/* number of waiters pending */
 	struct	pipe *pipe_peer;	/* link with other direction */
+	pid_t	pipe_pgid;		/* process group for sigio */
 	u_int	pipe_state;		/* pipe status info */
 	int	pipe_busy;		/* busy flag, to handle rundown */
 	vaddr_t	pipe_kmem;		/* preallocated PIPE_SIZE buffer */



CVS commit: src/sys

2023-10-04 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Wed Oct  4 22:19:58 UTC 2023

Modified Files:
src/sys/kern: sys_pipe.c
src/sys/sys: pipe.h

Log Message:
pipe->pipe_waiters isn't needed on NetBSD, kernel condvars do this for free.


To generate a diff of this commit:
cvs rdiff -u -r1.161 -r1.162 src/sys/kern/sys_pipe.c
cvs rdiff -u -r1.38 -r1.39 src/sys/sys/pipe.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src

2023-10-04 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Wed Oct  4 22:17:10 UTC 2023

Modified Files:
src/share/man/man9: kauth.9
src/sys/kern: kern_auth.c kern_core.c kern_descrip.c kern_exec.c
kern_lwp.c kern_proc.c uipc_socket.c uipc_syscalls.c
src/sys/sys: kauth.h

Log Message:
kauth_cred_hold(): return cred verbatim so that donating a reference to
another data structure can be done more elegantly.


To generate a diff of this commit:
cvs rdiff -u -r1.113 -r1.114 src/share/man/man9/kauth.9
cvs rdiff -u -r1.83 -r1.84 src/sys/kern/kern_auth.c
cvs rdiff -u -r1.38 -r1.39 src/sys/kern/kern_core.c
cvs rdiff -u -r1.261 -r1.262 src/sys/kern/kern_descrip.c
cvs rdiff -u -r1.519 -r1.520 src/sys/kern/kern_exec.c
cvs rdiff -u -r1.262 -r1.263 src/sys/kern/kern_lwp.c
cvs rdiff -u -r1.272 -r1.273 src/sys/kern/kern_proc.c
cvs rdiff -u -r1.304 -r1.305 src/sys/kern/uipc_socket.c
cvs rdiff -u -r1.207 -r1.208 src/sys/kern/uipc_syscalls.c
cvs rdiff -u -r1.89 -r1.90 src/sys/sys/kauth.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/share/man/man9/kauth.9
diff -u src/share/man/man9/kauth.9:1.113 src/share/man/man9/kauth.9:1.114
--- src/share/man/man9/kauth.9:1.113	Sat Aug  7 03:28:42 2021
+++ src/share/man/man9/kauth.9	Wed Oct  4 22:17:10 2023
@@ -1,4 +1,4 @@
-.\" $NetBSD: kauth.9,v 1.113 2021/08/07 03:28:42 isaki Exp $
+.\" $NetBSD: kauth.9,v 1.114 2023/10/04 22:17:10 ad Exp $
 .\"
 .\" Copyright (c) 2005, 2006 Elad Efrat 
 .\" All rights reserved.
@@ -25,7 +25,7 @@
 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd August 7, 2021
+.Dd October 4, 2023
 .Dt KAUTH 9
 .Os
 .Sh NAME
@@ -1746,10 +1746,12 @@ LWPs, files, etc.) reference it.
 The following routines are available for managing credentials reference
 counting:
 .Bl -tag -width compact
-.It Ft void Fn kauth_cred_hold "kauth_cred_t cred"
+.It Ft kauth_cred_t Fn kauth_cred_hold "kauth_cred_t cred"
 Increases reference count to
 .Ar cred
-by one.
+by one and returns
+.Ar cred
+verbatim.
 .It Ft void Fn kauth_cred_free "kauth_cred_t cred"
 Decreases the reference count to
 .Ar cred

Index: src/sys/kern/kern_auth.c
diff -u src/sys/kern/kern_auth.c:1.83 src/sys/kern/kern_auth.c:1.84
--- src/sys/kern/kern_auth.c:1.83	Mon Oct  2 20:59:12 2023
+++ src/sys/kern/kern_auth.c	Wed Oct  4 22:17:09 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_auth.c,v 1.83 2023/10/02 20:59:12 ad Exp $ */
+/* $NetBSD: kern_auth.c,v 1.84 2023/10/04 22:17:09 ad Exp $ */
 
 /*-
  * Copyright (c) 2005, 2006 Elad Efrat 
@@ -28,7 +28,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_auth.c,v 1.83 2023/10/02 20:59:12 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_auth.c,v 1.84 2023/10/04 22:17:09 ad Exp $");
 
 #include 
 #include 
@@ -122,7 +122,7 @@ kauth_cred_alloc(void)
 }
 
 /* Increment reference count to cred. */
-void
+kauth_cred_t
 kauth_cred_hold(kauth_cred_t cred)
 {
 	KASSERT(cred != NULL);
@@ -131,6 +131,7 @@ kauth_cred_hold(kauth_cred_t cred)
 	KASSERT(cred->cr_refcnt > 0);
 
 	atomic_inc_uint(>cr_refcnt);
+	return cred;
 }
 
 /* Decrease reference count to cred. If reached zero, free it. */
@@ -237,8 +238,7 @@ kauth_proc_fork(struct proc *parent, str
 {
 
 	mutex_enter(parent->p_lock);
-	kauth_cred_hold(parent->p_cred);
-	child->p_cred = parent->p_cred;
+	child->p_cred = kauth_cred_hold(parent->p_cred);
 	mutex_exit(parent->p_lock);
 
 	/* XXX: relies on parent process stalling during fork() */

Index: src/sys/kern/kern_core.c
diff -u src/sys/kern/kern_core.c:1.38 src/sys/kern/kern_core.c:1.39
--- src/sys/kern/kern_core.c:1.38	Tue Jul 11 09:48:56 2023
+++ src/sys/kern/kern_core.c	Wed Oct  4 22:17:09 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_core.c,v 1.38 2023/07/11 09:48:56 riastradh Exp $	*/
+/*	$NetBSD: kern_core.c,v 1.39 2023/10/04 22:17:09 ad Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1991, 1993
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_core.c,v 1.38 2023/07/11 09:48:56 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_core.c,v 1.39 2023/10/04 22:17:09 ad Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_execfmt.h"
@@ -153,8 +153,7 @@ coredump(struct lwp *l, const char *patt
 	 * It may well not be curproc, so grab a reference to its current
 	 * credentials.
 	 */
-	kauth_cred_hold(p->p_cred);
-	cred = p->p_cred;
+	cred = kauth_cred_hold(p->p_cred);
 
 	/*
 	 * Make sure the process has not set-id, to prevent data leaks,

Index: src/sys/kern/kern_descrip.c
diff -u src/sys/kern/kern_descrip.c:1.261 src/sys/kern/kern_descrip.c:1.262
--- src/sys/kern/kern_descrip.c:1.261	Sat Sep 23 18:21:11 2023
+++ src/sys/kern/kern_descrip.c	Wed Oct  4 22:17:09 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_descrip.c,v 1.261 2023/09/23 18:21:11 ad Exp $	*/
+/*	$NetBSD: kern_descrip.c,v 1.262 2023/10/04 22:17:09 ad Exp $	*/
 
 /*-
  * Copyright (c) 

CVS commit: src

2023-10-04 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Wed Oct  4 22:17:10 UTC 2023

Modified Files:
src/share/man/man9: kauth.9
src/sys/kern: kern_auth.c kern_core.c kern_descrip.c kern_exec.c
kern_lwp.c kern_proc.c uipc_socket.c uipc_syscalls.c
src/sys/sys: kauth.h

Log Message:
kauth_cred_hold(): return cred verbatim so that donating a reference to
another data structure can be done more elegantly.


To generate a diff of this commit:
cvs rdiff -u -r1.113 -r1.114 src/share/man/man9/kauth.9
cvs rdiff -u -r1.83 -r1.84 src/sys/kern/kern_auth.c
cvs rdiff -u -r1.38 -r1.39 src/sys/kern/kern_core.c
cvs rdiff -u -r1.261 -r1.262 src/sys/kern/kern_descrip.c
cvs rdiff -u -r1.519 -r1.520 src/sys/kern/kern_exec.c
cvs rdiff -u -r1.262 -r1.263 src/sys/kern/kern_lwp.c
cvs rdiff -u -r1.272 -r1.273 src/sys/kern/kern_proc.c
cvs rdiff -u -r1.304 -r1.305 src/sys/kern/uipc_socket.c
cvs rdiff -u -r1.207 -r1.208 src/sys/kern/uipc_syscalls.c
cvs rdiff -u -r1.89 -r1.90 src/sys/sys/kauth.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/kern

2023-10-04 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Wed Oct  4 22:12:23 UTC 2023

Modified Files:
src/sys/kern: sys_pipe.c

Log Message:
pipe_read(): try to skip locking the pipe if a non-blocking fd is used, as
is very often the case with BSD make (from FreeBSD/mjg@).


To generate a diff of this commit:
cvs rdiff -u -r1.160 -r1.161 src/sys/kern/sys_pipe.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/kern

2023-10-04 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Wed Oct  4 22:12:23 UTC 2023

Modified Files:
src/sys/kern: sys_pipe.c

Log Message:
pipe_read(): try to skip locking the pipe if a non-blocking fd is used, as
is very often the case with BSD make (from FreeBSD/mjg@).


To generate a diff of this commit:
cvs rdiff -u -r1.160 -r1.161 src/sys/kern/sys_pipe.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/sys_pipe.c
diff -u src/sys/kern/sys_pipe.c:1.160 src/sys/kern/sys_pipe.c:1.161
--- src/sys/kern/sys_pipe.c:1.160	Sat Apr 22 13:53:02 2023
+++ src/sys/kern/sys_pipe.c	Wed Oct  4 22:12:23 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: sys_pipe.c,v 1.160 2023/04/22 13:53:02 riastradh Exp $	*/
+/*	$NetBSD: sys_pipe.c,v 1.161 2023/10/04 22:12:23 ad Exp $	*/
 
 /*-
  * Copyright (c) 2003, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sys_pipe.c,v 1.160 2023/04/22 13:53:02 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_pipe.c,v 1.161 2023/10/04 22:12:23 ad Exp $");
 
 #include 
 #include 
@@ -434,6 +434,23 @@ pipe_read(file_t *fp, off_t *offset, str
 	size_t ocnt;
 	unsigned int wakeup_state = 0;
 
+	/*
+	 * Try to avoid locking the pipe if we have nothing to do.
+	 *
+	 * There are programs which share one pipe amongst multiple processes
+	 * and perform non-blocking reads in parallel, even if the pipe is
+	 * empty.  This in particular is the case with BSD make, which when
+	 * spawned with a high -j number can find itself with over half of the
+	 * calls failing to find anything.
+	 */
+	if ((fp->f_flag & FNONBLOCK) != 0) {
+		if (__predict_false(uio->uio_resid == 0))
+			return (0);
+		if (atomic_load_relaxed(>cnt) == 0 &&
+		(atomic_load_relaxed(>pipe_state) & PIPE_EOF) == 0)
+			return (EAGAIN);
+	}
+
 	mutex_enter(lock);
 	++rpipe->pipe_busy;
 	ocnt = bp->cnt;



CVS commit: src/sys/rump/librump/rumpkern

2023-10-04 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Wed Oct  4 21:56:16 UTC 2023

Modified Files:
src/sys/rump/librump/rumpkern: threads.c

Log Message:
rump now needs lwp_need_userret()


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sys/rump/librump/rumpkern/threads.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/librump/rumpkern/threads.c
diff -u src/sys/rump/librump/rumpkern/threads.c:1.27 src/sys/rump/librump/rumpkern/threads.c:1.28
--- src/sys/rump/librump/rumpkern/threads.c:1.27	Sat Aug  1 22:30:57 2020
+++ src/sys/rump/librump/rumpkern/threads.c	Wed Oct  4 21:56:15 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: threads.c,v 1.27 2020/08/01 22:30:57 riastradh Exp $	*/
+/*	$NetBSD: threads.c,v 1.28 2023/10/04 21:56:15 ad Exp $	*/
 
 /*
  * Copyright (c) 2007-2009 Antti Kantee.  All Rights Reserved.
@@ -29,7 +29,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: threads.c,v 1.27 2020/08/01 22:30:57 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: threads.c,v 1.28 2023/10/04 21:56:15 ad Exp $");
 
 #include 
 #include 
@@ -377,3 +377,10 @@ lwp_userret(struct lwp *l)
 	rump_unschedule();
 	rumpuser_thread_exit();
 }
+
+void
+lwp_need_userret(struct lwp *l)
+{
+
+	/* do what? */
+}



CVS commit: src/sys/rump/librump/rumpkern

2023-10-04 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Wed Oct  4 21:56:16 UTC 2023

Modified Files:
src/sys/rump/librump/rumpkern: threads.c

Log Message:
rump now needs lwp_need_userret()


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sys/rump/librump/rumpkern/threads.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/sys

2023-10-04 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Wed Oct  4 20:52:07 UTC 2023

Modified Files:
src/sys/sys: proc.h

Log Message:
p->p_stat is actually locked by proc_lock so document it that way and
shuffle some fields around so it's not next to p->p_trace_enabled (that
needs some attention too, in a later change).


To generate a diff of this commit:
cvs rdiff -u -r1.372 -r1.373 src/sys/sys/proc.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/sys/proc.h
diff -u src/sys/sys/proc.h:1.372 src/sys/sys/proc.h:1.373
--- src/sys/sys/proc.h:1.372	Tue Jul 11 09:48:56 2023
+++ src/sys/sys/proc.h	Wed Oct  4 20:52:07 2023
@@ -1,7 +1,7 @@
-/*	$NetBSD: proc.h,v 1.372 2023/07/11 09:48:56 riastradh Exp $	*/
+/*	$NetBSD: proc.h,v 1.373 2023/10/04 20:52:07 ad Exp $	*/
 
 /*-
- * Copyright (c) 2006, 2007, 2008, 2020 The NetBSD Foundation, Inc.
+ * Copyright (c) 2006, 2007, 2008, 2020, 2023 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -252,12 +252,12 @@ struct proc {
 	int		p_exitsig;	/* l: signal to send to parent on exit */
 	int		p_flag;		/* p: PK_* flags */
 	int		p_sflag;	/* p: PS_* flags */
-	int		p_slflag;	/* p, l: PSL_* flags */
-	int		p_lflag;	/* l: PL_* flags */
 	int		p_stflag;	/* t: PST_* flags */
-	char		p_stat;		/* p: S* process status. */
+	short		p_slflag;	/* l, p: PSL_* flags */
+	char		p_stat;		/* l: S* process status. */
+	char		p_lflag;	/* l: PL_* flags */
 	char		p_trace_enabled;/* p: cached by syscall_intern() */
-	char		p_pad1[2];	/*  unused */
+	char		p_pad1[3];	/*  unused */
 
 	pid_t		p_pid;		/* :: Process identifier. */
 	LIST_ENTRY(proc) p_pglist;	/* l: List of processes in pgrp. */
@@ -414,11 +414,11 @@ struct proc {
 #define	PSL_TRACEPOSIX_SPAWN	\
 			0x0020 /* traced process wants posix_spawn events */
 
-#define	PSL_TRACED	0x0800 /* Debugged process being traced */
-#define	PSL_TRACEDCHILD 0x1000 /* Report process birth */
-#define	PSL_CHTRACED	0x0040 /* Child has been traced & reparented */
-#define	PSL_SYSCALL	0x0400 /* process has PT_SYSCALL enabled */
-#define	PSL_SYSCALLEMU	0x0800 /* cancel in-progress syscall */
+#define	PSL_TRACED	0x0040 /* Debugged process being traced */
+#define	PSL_TRACEDCHILD 0x0080 /* Report process birth */
+#define	PSL_CHTRACED	0x0100 /* Child has been traced & reparented */
+#define	PSL_SYSCALL	0x0200 /* process has PT_SYSCALL enabled */
+#define	PSL_SYSCALLEMU	0x0400 /* cancel in-progress syscall */
 
 /*
  * Kept in p_stflag and protected by p_stmutex.
@@ -429,10 +429,10 @@ struct proc {
  * Kept in p_lflag and protected by the proc_lock.  Access
  * from process context only.
  */
-#define	PL_CONTROLT	0x0002 /* Has a controlling terminal */
-#define	PL_PPWAIT	0x0010 /* Parent is waiting for child exec/exit */
-#define	PL_SIGCOMPAT	0x0200 /* Has used compat signal trampoline */
-#define	PL_ORPHANPG	0x2000 /* Member of an orphaned pgrp */
+#define	PL_CONTROLT	0x0001 /* Has a controlling terminal */
+#define	PL_PPWAIT	0x0002 /* Parent is waiting for child exec/exit */
+#define	PL_SIGCOMPAT	0x0004 /* Has used compat signal trampoline */
+#define	PL_ORPHANPG	0x0008 /* Member of an orphaned pgrp */
 
 #if defined(_KMEMUSER) || defined(_KERNEL)
 



CVS commit: src/sys/sys

2023-10-04 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Wed Oct  4 20:52:07 UTC 2023

Modified Files:
src/sys/sys: proc.h

Log Message:
p->p_stat is actually locked by proc_lock so document it that way and
shuffle some fields around so it's not next to p->p_trace_enabled (that
needs some attention too, in a later change).


To generate a diff of this commit:
cvs rdiff -u -r1.372 -r1.373 src/sys/sys/proc.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/kern

2023-10-04 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Wed Oct  4 20:46:33 UTC 2023

Modified Files:
src/sys/kern: kern_lwp.c

Log Message:
Do cv_broadcast(>p_lwpcv) after dropping p->p_lock in a few places, to
reduce contention.


To generate a diff of this commit:
cvs rdiff -u -r1.261 -r1.262 src/sys/kern/kern_lwp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_lwp.c
diff -u src/sys/kern/kern_lwp.c:1.261 src/sys/kern/kern_lwp.c:1.262
--- src/sys/kern/kern_lwp.c:1.261	Wed Oct  4 20:45:13 2023
+++ src/sys/kern/kern_lwp.c	Wed Oct  4 20:46:33 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_lwp.c,v 1.261 2023/10/04 20:45:13 ad Exp $	*/
+/*	$NetBSD: kern_lwp.c,v 1.262 2023/10/04 20:46:33 ad Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2006, 2007, 2008, 2009, 2019, 2020, 2023
@@ -217,7 +217,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.261 2023/10/04 20:45:13 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.262 2023/10/04 20:46:33 ad Exp $");
 
 #include "opt_ddb.h"
 #include "opt_lockdebug.h"
@@ -1219,10 +1219,10 @@ lwp_exit(struct lwp *l)
 	}
 	lwp_unlock(l);
 	p->p_nrlwps--;
-	cv_broadcast(>p_lwpcv);
 	if (l->l_lwpctl != NULL)
 		l->l_lwpctl->lc_curcpu = LWPCTL_CPU_EXITED;
 	mutex_exit(p->p_lock);
+	cv_broadcast(>p_lwpcv);
 
 	/*
 	 * We can no longer block.  At this point, lwp_free() may already
@@ -1311,13 +1311,13 @@ lwp_free(struct lwp *l, bool recycle, bo
 		p->p_nzlwps--;
 		if ((l->l_prflag & LPR_DETACHED) != 0)
 			p->p_ndlwps--;
+		mutex_exit(p->p_lock);
 
 		/*
 		 * Have any LWPs sleeping in lwp_wait() recheck for
 		 * deadlock.
 		 */
 		cv_broadcast(>p_lwpcv);
-		mutex_exit(p->p_lock);
 
 		/* Free the LWP ID. */
 		mutex_enter(_lock);
@@ -1759,11 +1759,11 @@ lwp_userret(struct lwp *l)
 			pcu_save_all(l);
 			mutex_enter(p->p_lock);
 			p->p_nrlwps--;
-			cv_broadcast(>p_lwpcv);
 			lwp_lock(l);
 			l->l_stat = LSSUSPENDED;
 			lwp_unlock(l);
 			mutex_exit(p->p_lock);
+			cv_broadcast(>p_lwpcv);
 			lwp_lock(l);
 			spc_lock(l->l_cpu);
 			mi_switch(l);



CVS commit: src/sys/kern

2023-10-04 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Wed Oct  4 20:48:13 UTC 2023

Modified Files:
src/sys/kern: kern_exit.c

Log Message:
match_process(): most of the fields being inspected are covered by proc_lock
so don't grab p->p_lock so much.


To generate a diff of this commit:
cvs rdiff -u -r1.296 -r1.297 src/sys/kern/kern_exit.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_exit.c
diff -u src/sys/kern/kern_exit.c:1.296 src/sys/kern/kern_exit.c:1.297
--- src/sys/kern/kern_exit.c:1.296	Wed Oct  4 20:42:38 2023
+++ src/sys/kern/kern_exit.c	Wed Oct  4 20:48:13 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_exit.c,v 1.296 2023/10/04 20:42:38 ad Exp $	*/
+/*	$NetBSD: kern_exit.c,v 1.297 2023/10/04 20:48:13 ad Exp $	*/
 
 /*-
  * Copyright (c) 1998, 1999, 2006, 2007, 2008, 2020, 2023
@@ -68,7 +68,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_exit.c,v 1.296 2023/10/04 20:42:38 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_exit.c,v 1.297 2023/10/04 20:48:13 ad Exp $");
 
 #include "opt_ktrace.h"
 #include "opt_dtrace.h"
@@ -836,50 +836,57 @@ match_process(const struct proc *pp, str
 	struct proc *p = *q;
 	int rv = 1;
 
-	mutex_enter(p->p_lock);
 	switch (idtype) {
 	case P_ALL:
+		mutex_enter(p->p_lock);
 		break;
 	case P_PID:
 		if (p->p_pid != (pid_t)id) {
-			mutex_exit(p->p_lock);
 			p = *q = proc_find_raw((pid_t)id);
 			if (p == NULL || p->p_stat == SIDL || p->p_pptr != pp) {
 *q = NULL;
 return -1;
 			}
-			mutex_enter(p->p_lock);
 		}
+		mutex_enter(p->p_lock);
 		rv++;
 		break;
 	case P_PGID:
 		if (p->p_pgid != (pid_t)id)
-			goto out;
+			return 0;
+		mutex_enter(p->p_lock);
 		break;
 	case P_SID:
 		if (p->p_session->s_sid != (pid_t)id)
-			goto out;
+			return 0;
+		mutex_enter(p->p_lock);
 		break;
 	case P_UID:
-		if (kauth_cred_geteuid(p->p_cred) != (uid_t)id)
-			goto out;
+		mutex_enter(p->p_lock);
+		if (kauth_cred_geteuid(p->p_cred) != (uid_t)id) {
+			mutex_exit(p->p_lock);
+			return 0;
+		}
 		break;
 	case P_GID:
-		if (kauth_cred_getegid(p->p_cred) != (gid_t)id)
-			goto out;
+		mutex_enter(p->p_lock);
+		if (kauth_cred_getegid(p->p_cred) != (gid_t)id) {
+			mutex_exit(p->p_lock);
+			return 0;
+		}
 		break;
 	case P_CID:
 	case P_PSETID:
 	case P_CPUID:
 		/* XXX: Implement me */
 	default:
-	out:
-		mutex_exit(p->p_lock);
 		return 0;
 	}
 
-	if ((options & WEXITED) == 0 && p->p_stat == SZOMB)
-		goto out;
+	if ((options & WEXITED) == 0 && p->p_stat == SZOMB) {
+		mutex_exit(p->p_lock);
+		return 0;
+	}
 
 	if (siginfo != NULL) {
 		siginfo->si_errno = 0;
@@ -1024,9 +1031,7 @@ find_stopped_child(struct proc *parent, 
 	}
 
 	if ((pid_t)id == WAIT_MYPGRP && (idtype == P_PID || idtype == P_PGID)) {
-		mutex_enter(parent->p_lock);
 		id = (id_t)parent->p_pgid;
-		mutex_exit(parent->p_lock);
 		idtype = P_PGID;
 	}
 



CVS commit: src/sys/kern

2023-10-04 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Wed Oct  4 20:46:33 UTC 2023

Modified Files:
src/sys/kern: kern_lwp.c

Log Message:
Do cv_broadcast(>p_lwpcv) after dropping p->p_lock in a few places, to
reduce contention.


To generate a diff of this commit:
cvs rdiff -u -r1.261 -r1.262 src/sys/kern/kern_lwp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/kern

2023-10-04 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Wed Oct  4 20:48:13 UTC 2023

Modified Files:
src/sys/kern: kern_exit.c

Log Message:
match_process(): most of the fields being inspected are covered by proc_lock
so don't grab p->p_lock so much.


To generate a diff of this commit:
cvs rdiff -u -r1.296 -r1.297 src/sys/kern/kern_exit.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/kern

2023-10-04 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Wed Oct  4 20:44:15 UTC 2023

Modified Files:
src/sys/kern: kern_lwp.c

Log Message:
Sprinkle a bunch more calls to lwp_need_userret().  There should be no
functional change but it does get rid of a bunch of assumptions about how
mi_userret() works making it easier to adjust in that in the future, and
works as a kind of documentation too.


To generate a diff of this commit:
cvs rdiff -u -r1.259 -r1.260 src/sys/kern/kern_lwp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_lwp.c
diff -u src/sys/kern/kern_lwp.c:1.259 src/sys/kern/kern_lwp.c:1.260
--- src/sys/kern/kern_lwp.c:1.259	Wed Oct  4 20:42:38 2023
+++ src/sys/kern/kern_lwp.c	Wed Oct  4 20:44:15 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_lwp.c,v 1.259 2023/10/04 20:42:38 ad Exp $	*/
+/*	$NetBSD: kern_lwp.c,v 1.260 2023/10/04 20:44:15 ad Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2006, 2007, 2008, 2009, 2019, 2020, 2023
@@ -217,7 +217,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.259 2023/10/04 20:42:38 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.260 2023/10/04 20:44:15 ad Exp $");
 
 #include "opt_ddb.h"
 #include "opt_lockdebug.h"
@@ -1003,6 +1003,7 @@ lwp_start(lwp_t *l, int flags)
 	if ((flags & LWP_SUSPENDED) != 0) {
 		/* It'll suspend itself in lwp_userret(). */
 		l->l_flag |= LW_WSUSPEND;
+		lwp_need_userret(l);
 	}
 	if (p->p_stat == SSTOP || (p->p_sflag & PS_STOPPING) != 0) {
 		KASSERT(l->l_wchan == NULL);



CVS commit: src/sys/kern

2023-10-04 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Wed Oct  4 20:45:14 UTC 2023

Modified Files:
src/sys/kern: kern_lwp.c

Log Message:
lwp_wait(): restart the loop if p->p_lock dropped to reap zombie (paranoid).


To generate a diff of this commit:
cvs rdiff -u -r1.260 -r1.261 src/sys/kern/kern_lwp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_lwp.c
diff -u src/sys/kern/kern_lwp.c:1.260 src/sys/kern/kern_lwp.c:1.261
--- src/sys/kern/kern_lwp.c:1.260	Wed Oct  4 20:44:15 2023
+++ src/sys/kern/kern_lwp.c	Wed Oct  4 20:45:13 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_lwp.c,v 1.260 2023/10/04 20:44:15 ad Exp $	*/
+/*	$NetBSD: kern_lwp.c,v 1.261 2023/10/04 20:45:13 ad Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2006, 2007, 2008, 2009, 2019, 2020, 2023
@@ -217,7 +217,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.260 2023/10/04 20:44:15 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.261 2023/10/04 20:45:13 ad Exp $");
 
 #include "opt_ddb.h"
 #include "opt_lockdebug.h"
@@ -612,10 +612,11 @@ lwp_wait(struct lwp *l, lwpid_t lid, lwp
 		 * First off, drain any detached LWP that is waiting to be
 		 * reaped.
 		 */
-		while ((l2 = p->p_zomblwp) != NULL) {
+		if ((l2 = p->p_zomblwp) != NULL) {
 			p->p_zomblwp = NULL;
 			lwp_free(l2, false, false);/* releases proc mutex */
 			mutex_enter(p->p_lock);
+			continue;
 		}
 
 		/*



CVS commit: src/sys/kern

2023-10-04 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Wed Oct  4 20:45:14 UTC 2023

Modified Files:
src/sys/kern: kern_lwp.c

Log Message:
lwp_wait(): restart the loop if p->p_lock dropped to reap zombie (paranoid).


To generate a diff of this commit:
cvs rdiff -u -r1.260 -r1.261 src/sys/kern/kern_lwp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/kern

2023-10-04 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Wed Oct  4 20:44:15 UTC 2023

Modified Files:
src/sys/kern: kern_lwp.c

Log Message:
Sprinkle a bunch more calls to lwp_need_userret().  There should be no
functional change but it does get rid of a bunch of assumptions about how
mi_userret() works making it easier to adjust in that in the future, and
works as a kind of documentation too.


To generate a diff of this commit:
cvs rdiff -u -r1.259 -r1.260 src/sys/kern/kern_lwp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/kern

2023-10-04 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Wed Oct  4 20:42:38 UTC 2023

Modified Files:
src/sys/kern: kern_exit.c kern_lwp.c kern_sig.c sys_sig.c

Log Message:
Sprinkle a bunch more calls to lwp_need_userret().  There should be no
functional change but it does get rid of a bunch of assumptions about how
mi_userret() works making it easier to adjust in that in the future, and
works as a kind of documentation too.


To generate a diff of this commit:
cvs rdiff -u -r1.295 -r1.296 src/sys/kern/kern_exit.c
cvs rdiff -u -r1.258 -r1.259 src/sys/kern/kern_lwp.c
cvs rdiff -u -r1.406 -r1.407 src/sys/kern/kern_sig.c
cvs rdiff -u -r1.56 -r1.57 src/sys/kern/sys_sig.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_exit.c
diff -u src/sys/kern/kern_exit.c:1.295 src/sys/kern/kern_exit.c:1.296
--- src/sys/kern/kern_exit.c:1.295	Wed Oct  4 20:29:18 2023
+++ src/sys/kern/kern_exit.c	Wed Oct  4 20:42:38 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_exit.c,v 1.295 2023/10/04 20:29:18 ad Exp $	*/
+/*	$NetBSD: kern_exit.c,v 1.296 2023/10/04 20:42:38 ad Exp $	*/
 
 /*-
  * Copyright (c) 1998, 1999, 2006, 2007, 2008, 2020, 2023
@@ -68,7 +68,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_exit.c,v 1.295 2023/10/04 20:29:18 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_exit.c,v 1.296 2023/10/04 20:42:38 ad Exp $");
 
 #include "opt_ktrace.h"
 #include "opt_dtrace.h"
@@ -632,6 +632,7 @@ retry:
 			continue;
 		lwp_lock(l2);
 		l2->l_flag |= LW_WEXIT;
+		lwp_need_userret(l2);
 		if ((l2->l_stat == LSSLEEP && (l2->l_flag & LW_SINTR)) ||
 		l2->l_stat == LSSUSPENDED || l2->l_stat == LSSTOP) {
 			l2->l_flag &= ~LW_DBGSUSPEND;
@@ -639,7 +640,6 @@ retry:
 			setrunnable(l2);
 			continue;
 		}
-		lwp_need_userret(l2);
 		lwp_unlock(l2);
 	}
 

Index: src/sys/kern/kern_lwp.c
diff -u src/sys/kern/kern_lwp.c:1.258 src/sys/kern/kern_lwp.c:1.259
--- src/sys/kern/kern_lwp.c:1.258	Wed Oct  4 20:28:06 2023
+++ src/sys/kern/kern_lwp.c	Wed Oct  4 20:42:38 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_lwp.c,v 1.258 2023/10/04 20:28:06 ad Exp $	*/
+/*	$NetBSD: kern_lwp.c,v 1.259 2023/10/04 20:42:38 ad Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2006, 2007, 2008, 2009, 2019, 2020, 2023
@@ -217,7 +217,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.258 2023/10/04 20:28:06 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.259 2023/10/04 20:42:38 ad Exp $");
 
 #include "opt_ddb.h"
 #include "opt_lockdebug.h"
@@ -468,6 +468,7 @@ lwp_suspend(struct lwp *curl, struct lwp
 
 	case LSSLEEP:
 		t->l_flag |= LW_WSUSPEND;
+		lwp_need_userret(t);
 
 		/*
 		 * Kick the LWP and try to get it to the kernel boundary
@@ -486,6 +487,7 @@ lwp_suspend(struct lwp *curl, struct lwp
 
 	case LSSTOP:
 		t->l_flag |= LW_WSUSPEND;
+		lwp_need_userret(t);
 		setrunnable(t);
 		break;
 
@@ -962,6 +964,11 @@ lwp_create(lwp_t *l1, proc_t *p2, vaddr_
 		lwp_unlock(l1);
 	}
 
+	/* Ensure a trip through lwp_userret() if needed. */
+	if ((l2->l_flag & LW_USERRET) != 0) {
+		lwp_need_userret(l2);
+	}
+
 	/* This marks the end of the "must be atomic" section. */
 	mutex_exit(p2->p_lock);
 
@@ -1794,7 +1801,7 @@ lwp_need_userret(struct lwp *l)
 {
 
 	KASSERT(!cpu_intr_p());
-	KASSERT(lwp_locked(l, NULL));
+	KASSERT(lwp_locked(l, NULL) || l->l_stat == LSIDL);
 
 	/*
 	 * If the LWP is in any state other than LSONPROC, we know that it

Index: src/sys/kern/kern_sig.c
diff -u src/sys/kern/kern_sig.c:1.406 src/sys/kern/kern_sig.c:1.407
--- src/sys/kern/kern_sig.c:1.406	Wed Oct  4 20:29:18 2023
+++ src/sys/kern/kern_sig.c	Wed Oct  4 20:42:38 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_sig.c,v 1.406 2023/10/04 20:29:18 ad Exp $	*/
+/*	$NetBSD: kern_sig.c,v 1.407 2023/10/04 20:42:38 ad Exp $	*/
 
 /*-
  * Copyright (c) 2006, 2007, 2008, 2019, 2023 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.406 2023/10/04 20:29:18 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.407 2023/10/04 20:42:38 ad Exp $");
 
 #include "opt_execfmt.h"
 #include "opt_ptrace.h"
@@ -2266,6 +2266,7 @@ sigexit(struct lwp *l, int signo)
 	if ((p->p_sflag & PS_WCORE) != 0) {
 		lwp_lock(l);
 		l->l_flag |= (LW_WCORE | LW_WEXIT | LW_WSUSPEND);
+		lwp_need_userret(l);
 		lwp_unlock(l);
 		mutex_exit(p->p_lock);
 		lwp_userret(l);
@@ -2297,6 +2298,7 @@ sigexit(struct lwp *l, int signo)
 	continue;
 }
 t->l_flag |= (LW_WCORE | LW_WEXIT);
+lwp_need_userret(t);
 lwp_suspend(l, t);
 			}
 

Index: src/sys/kern/sys_sig.c
diff -u src/sys/kern/sys_sig.c:1.56 src/sys/kern/sys_sig.c:1.57
--- src/sys/kern/sys_sig.c:1.56	Thu Apr 21 21:31:11 2022
+++ src/sys/kern/sys_sig.c	Wed Oct  4 20:42:38 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: sys_sig.c,v 1.56 2022/04/21 21:31:11 andvar Exp $	*/
+/*	$NetBSD: sys_sig.c,v 1.57 2023/10/04 20:42:38 ad Exp $	*/
 
 /*-
  * Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ 

CVS commit: src/sys/kern

2023-10-04 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Wed Oct  4 20:42:38 UTC 2023

Modified Files:
src/sys/kern: kern_exit.c kern_lwp.c kern_sig.c sys_sig.c

Log Message:
Sprinkle a bunch more calls to lwp_need_userret().  There should be no
functional change but it does get rid of a bunch of assumptions about how
mi_userret() works making it easier to adjust in that in the future, and
works as a kind of documentation too.


To generate a diff of this commit:
cvs rdiff -u -r1.295 -r1.296 src/sys/kern/kern_exit.c
cvs rdiff -u -r1.258 -r1.259 src/sys/kern/kern_lwp.c
cvs rdiff -u -r1.406 -r1.407 src/sys/kern/kern_sig.c
cvs rdiff -u -r1.56 -r1.57 src/sys/kern/sys_sig.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/kern

2023-10-04 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Wed Oct  4 20:39:35 UTC 2023

Modified Files:
src/sys/kern: kern_rwlock.c kern_turnstile.c

Log Message:
Turnstiles: use the syncobj name for ps/top wmesg when sleeping since it's
more informative than "tstile".


To generate a diff of this commit:
cvs rdiff -u -r1.73 -r1.74 src/sys/kern/kern_rwlock.c
cvs rdiff -u -r1.51 -r1.52 src/sys/kern/kern_turnstile.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_rwlock.c
diff -u src/sys/kern/kern_rwlock.c:1.73 src/sys/kern/kern_rwlock.c:1.74
--- src/sys/kern/kern_rwlock.c:1.73	Sat Sep 23 18:48:04 2023
+++ src/sys/kern/kern_rwlock.c	Wed Oct  4 20:39:35 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_rwlock.c,v 1.73 2023/09/23 18:48:04 ad Exp $	*/
+/*	$NetBSD: kern_rwlock.c,v 1.74 2023/10/04 20:39:35 ad Exp $	*/
 
 /*-
  * Copyright (c) 2002, 2006, 2007, 2008, 2009, 2019, 2020, 2023
@@ -45,7 +45,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_rwlock.c,v 1.73 2023/09/23 18:48:04 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_rwlock.c,v 1.74 2023/10/04 20:39:35 ad Exp $");
 
 #include "opt_lockdebug.h"
 
@@ -125,7 +125,7 @@ lockops_t rwlock_lockops = {
  * direct handoff.  XXX To be revisited.
  */
 syncobj_t rw_syncobj = {
-	.sobj_name	= "rw",
+	.sobj_name	= "rwlock",
 	.sobj_flag	= SOBJ_SLEEPQ_SORTED,
 	.sobj_boostpri  = PRI_KTHREAD,
 	.sobj_unsleep	= turnstile_unsleep,

Index: src/sys/kern/kern_turnstile.c
diff -u src/sys/kern/kern_turnstile.c:1.51 src/sys/kern/kern_turnstile.c:1.52
--- src/sys/kern/kern_turnstile.c:1.51	Wed Oct  4 20:29:18 2023
+++ src/sys/kern/kern_turnstile.c	Wed Oct  4 20:39:35 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_turnstile.c,v 1.51 2023/10/04 20:29:18 ad Exp $	*/
+/*	$NetBSD: kern_turnstile.c,v 1.52 2023/10/04 20:39:35 ad Exp $	*/
 
 /*-
  * Copyright (c) 2002, 2006, 2007, 2009, 2019, 2020, 2023
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_turnstile.c,v 1.51 2023/10/04 20:29:18 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_turnstile.c,v 1.52 2023/10/04 20:39:35 ad Exp $");
 
 #include 
 #include 
@@ -417,7 +417,7 @@ turnstile_block(turnstile_t *ts, int q, 
 	ts->ts_waiters[q]++;
 	nlocks = sleepq_enter(sq, l, lock);
 	LOCKDEBUG_BARRIER(lock, 1);
-	sleepq_enqueue(sq, obj, "tstile", sobj, false);
+	sleepq_enqueue(sq, obj, sobj->sobj_name, sobj, false);
 
 	/*
 	 * Disable preemption across this entire block, as we may drop



CVS commit: src/sys/kern

2023-10-04 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Wed Oct  4 20:39:35 UTC 2023

Modified Files:
src/sys/kern: kern_rwlock.c kern_turnstile.c

Log Message:
Turnstiles: use the syncobj name for ps/top wmesg when sleeping since it's
more informative than "tstile".


To generate a diff of this commit:
cvs rdiff -u -r1.73 -r1.74 src/sys/kern/kern_rwlock.c
cvs rdiff -u -r1.51 -r1.52 src/sys/kern/kern_turnstile.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/uvm

2023-10-04 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Wed Oct  4 20:34:19 UTC 2023

Modified Files:
src/sys/uvm: uvm_glue.c

Log Message:
Remove unneeded test of ci->ci_want_resched.


To generate a diff of this commit:
cvs rdiff -u -r1.181 -r1.182 src/sys/uvm/uvm_glue.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/uvm/uvm_glue.c
diff -u src/sys/uvm/uvm_glue.c:1.181 src/sys/uvm/uvm_glue.c:1.182
--- src/sys/uvm/uvm_glue.c:1.181	Sun Jun 14 21:41:42 2020
+++ src/sys/uvm/uvm_glue.c	Wed Oct  4 20:34:19 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_glue.c,v 1.181 2020/06/14 21:41:42 ad Exp $	*/
+/*	$NetBSD: uvm_glue.c,v 1.182 2023/10/04 20:34:19 ad Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_glue.c,v 1.181 2020/06/14 21:41:42 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_glue.c,v 1.182 2023/10/04 20:34:19 ad Exp $");
 
 #include "opt_kgdb.h"
 #include "opt_kstack.h"
@@ -529,6 +529,5 @@ uvm_idle(void)
 
 	KASSERT(kpreempt_disabled());
 
-	if (!ci->ci_want_resched)
-		uvmpdpol_idle(ucpu);
+	uvmpdpol_idle(ucpu);
 }



CVS commit: src/sys/uvm

2023-10-04 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Wed Oct  4 20:34:19 UTC 2023

Modified Files:
src/sys/uvm: uvm_glue.c

Log Message:
Remove unneeded test of ci->ci_want_resched.


To generate a diff of this commit:
cvs rdiff -u -r1.181 -r1.182 src/sys/uvm/uvm_glue.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/sys

2023-10-04 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Wed Oct  4 20:29:59 UTC 2023

Modified Files:
src/sys/sys: param.h

Log Message:
NetBSD 10.99.10: struct lwp and related things changed.


To generate a diff of this commit:
cvs rdiff -u -r1.732 -r1.733 src/sys/sys/param.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/sys/param.h
diff -u src/sys/sys/param.h:1.732 src/sys/sys/param.h:1.733
--- src/sys/sys/param.h:1.732	Sat Sep 23 18:49:16 2023
+++ src/sys/sys/param.h	Wed Oct  4 20:29:59 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: param.h,v 1.732 2023/09/23 18:49:16 ad Exp $	*/
+/*	$NetBSD: param.h,v 1.733 2023/10/04 20:29:59 ad Exp $	*/
 
 /*-
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -67,7 +67,7 @@
  *	2.99.9		(299000900)
  */
 
-#define	__NetBSD_Version__	1099000900	/* NetBSD 10.99.9 */
+#define	__NetBSD_Version__	1099001000	/* NetBSD 10.99.10 */
 
 #define __NetBSD_Prereq__(M,m,p) (M) * 1) + \
 (m) * 100) + (p) * 100) <= __NetBSD_Version__)



CVS commit: src/sys/sys

2023-10-04 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Wed Oct  4 20:29:59 UTC 2023

Modified Files:
src/sys/sys: param.h

Log Message:
NetBSD 10.99.10: struct lwp and related things changed.


To generate a diff of this commit:
cvs rdiff -u -r1.732 -r1.733 src/sys/sys/param.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys

2023-10-04 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Wed Oct  4 20:29:18 UTC 2023

Modified Files:
src/sys/kern: kern_condvar.c kern_exec.c kern_exit.c kern_sig.c
kern_sleepq.c kern_synch.c kern_timeout.c kern_turnstile.c
sys_lwp.c sys_select.c
src/sys/rump/librump/rumpkern: lwproc.c sleepq.c
src/sys/sys: lwp.h sleepq.h

Log Message:
Eliminate l->l_biglocks.  Originally I think it had a use but these days a
local variable will do.


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 src/sys/kern/kern_condvar.c
cvs rdiff -u -r1.518 -r1.519 src/sys/kern/kern_exec.c
cvs rdiff -u -r1.294 -r1.295 src/sys/kern/kern_exit.c
cvs rdiff -u -r1.405 -r1.406 src/sys/kern/kern_sig.c
cvs rdiff -u -r1.76 -r1.77 src/sys/kern/kern_sleepq.c
cvs rdiff -u -r1.361 -r1.362 src/sys/kern/kern_synch.c
cvs rdiff -u -r1.77 -r1.78 src/sys/kern/kern_timeout.c
cvs rdiff -u -r1.50 -r1.51 src/sys/kern/kern_turnstile.c
cvs rdiff -u -r1.85 -r1.86 src/sys/kern/sys_lwp.c
cvs rdiff -u -r1.62 -r1.63 src/sys/kern/sys_select.c
cvs rdiff -u -r1.55 -r1.56 src/sys/rump/librump/rumpkern/lwproc.c
cvs rdiff -u -r1.24 -r1.25 src/sys/rump/librump/rumpkern/sleepq.c
cvs rdiff -u -r1.225 -r1.226 src/sys/sys/lwp.h
cvs rdiff -u -r1.38 -r1.39 src/sys/sys/sleepq.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys

2023-10-04 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Wed Oct  4 20:29:18 UTC 2023

Modified Files:
src/sys/kern: kern_condvar.c kern_exec.c kern_exit.c kern_sig.c
kern_sleepq.c kern_synch.c kern_timeout.c kern_turnstile.c
sys_lwp.c sys_select.c
src/sys/rump/librump/rumpkern: lwproc.c sleepq.c
src/sys/sys: lwp.h sleepq.h

Log Message:
Eliminate l->l_biglocks.  Originally I think it had a use but these days a
local variable will do.


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 src/sys/kern/kern_condvar.c
cvs rdiff -u -r1.518 -r1.519 src/sys/kern/kern_exec.c
cvs rdiff -u -r1.294 -r1.295 src/sys/kern/kern_exit.c
cvs rdiff -u -r1.405 -r1.406 src/sys/kern/kern_sig.c
cvs rdiff -u -r1.76 -r1.77 src/sys/kern/kern_sleepq.c
cvs rdiff -u -r1.361 -r1.362 src/sys/kern/kern_synch.c
cvs rdiff -u -r1.77 -r1.78 src/sys/kern/kern_timeout.c
cvs rdiff -u -r1.50 -r1.51 src/sys/kern/kern_turnstile.c
cvs rdiff -u -r1.85 -r1.86 src/sys/kern/sys_lwp.c
cvs rdiff -u -r1.62 -r1.63 src/sys/kern/sys_select.c
cvs rdiff -u -r1.55 -r1.56 src/sys/rump/librump/rumpkern/lwproc.c
cvs rdiff -u -r1.24 -r1.25 src/sys/rump/librump/rumpkern/sleepq.c
cvs rdiff -u -r1.225 -r1.226 src/sys/sys/lwp.h
cvs rdiff -u -r1.38 -r1.39 src/sys/sys/sleepq.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_condvar.c
diff -u src/sys/kern/kern_condvar.c:1.56 src/sys/kern/kern_condvar.c:1.57
--- src/sys/kern/kern_condvar.c:1.56	Sat Sep 23 18:48:04 2023
+++ src/sys/kern/kern_condvar.c	Wed Oct  4 20:29:18 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_condvar.c,v 1.56 2023/09/23 18:48:04 ad Exp $	*/
+/*	$NetBSD: kern_condvar.c,v 1.57 2023/10/04 20:29:18 ad Exp $	*/
 
 /*-
  * Copyright (c) 2006, 2007, 2008, 2019, 2020, 2023
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_condvar.c,v 1.56 2023/09/23 18:48:04 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_condvar.c,v 1.57 2023/10/04 20:29:18 ad Exp $");
 
 #include 
 #include 
@@ -119,11 +119,12 @@ cv_destroy(kcondvar_t *cv)
  *	Look up and lock the sleep queue corresponding to the given
  *	condition variable, and increment the number of waiters.
  */
-static inline void
+static inline int
 cv_enter(kcondvar_t *cv, kmutex_t *mtx, lwp_t *l, bool catch_p)
 {
 	sleepq_t *sq;
 	kmutex_t *mp;
+	int nlocks;
 
 	KASSERT(cv_is_valid(cv));
 	KASSERT(!cpu_intr_p());
@@ -131,10 +132,11 @@ cv_enter(kcondvar_t *cv, kmutex_t *mtx, 
 
 	mp = sleepq_hashlock(cv);
 	sq = CV_SLEEPQ(cv);
-	sleepq_enter(sq, l, mp);
+	nlocks = sleepq_enter(sq, l, mp);
 	sleepq_enqueue(sq, cv, CV_WMESG(cv), _syncobj, catch_p);
 	mutex_exit(mtx);
 	KASSERT(cv_has_waiters(cv));
+	return nlocks;
 }
 
 /*
@@ -169,11 +171,12 @@ void
 cv_wait(kcondvar_t *cv, kmutex_t *mtx)
 {
 	lwp_t *l = curlwp;
+	int nlocks;
 
 	KASSERT(mutex_owned(mtx));
 
-	cv_enter(cv, mtx, l, false);
-	(void)sleepq_block(0, false, _syncobj);
+	nlocks = cv_enter(cv, mtx, l, false);
+	(void)sleepq_block(0, false, _syncobj, nlocks);
 	mutex_enter(mtx);
 }
 
@@ -189,12 +192,12 @@ int
 cv_wait_sig(kcondvar_t *cv, kmutex_t *mtx)
 {
 	lwp_t *l = curlwp;
-	int error;
+	int error, nlocks;
 
 	KASSERT(mutex_owned(mtx));
 
-	cv_enter(cv, mtx, l, true);
-	error = sleepq_block(0, true, _syncobj);
+	nlocks = cv_enter(cv, mtx, l, true);
+	error = sleepq_block(0, true, _syncobj, nlocks);
 	mutex_enter(mtx);
 	return error;
 }
@@ -212,12 +215,12 @@ int
 cv_timedwait(kcondvar_t *cv, kmutex_t *mtx, int timo)
 {
 	lwp_t *l = curlwp;
-	int error;
+	int error, nlocks;
 
 	KASSERT(mutex_owned(mtx));
 
-	cv_enter(cv, mtx, l, false);
-	error = sleepq_block(timo, false, _syncobj);
+	nlocks = cv_enter(cv, mtx, l, false);
+	error = sleepq_block(timo, false, _syncobj, nlocks);
 	mutex_enter(mtx);
 	return error;
 }
@@ -237,12 +240,12 @@ int
 cv_timedwait_sig(kcondvar_t *cv, kmutex_t *mtx, int timo)
 {
 	lwp_t *l = curlwp;
-	int error;
+	int error, nlocks;
 
 	KASSERT(mutex_owned(mtx));
 
-	cv_enter(cv, mtx, l, true);
-	error = sleepq_block(timo, true, _syncobj);
+	nlocks = cv_enter(cv, mtx, l, true);
+	error = sleepq_block(timo, true, _syncobj, nlocks);
 	mutex_enter(mtx);
 	return error;
 }

Index: src/sys/kern/kern_exec.c
diff -u src/sys/kern/kern_exec.c:1.518 src/sys/kern/kern_exec.c:1.519
--- src/sys/kern/kern_exec.c:1.518	Fri Jul  1 01:05:31 2022
+++ src/sys/kern/kern_exec.c	Wed Oct  4 20:29:18 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_exec.c,v 1.518 2022/07/01 01:05:31 riastradh Exp $	*/
+/*	$NetBSD: kern_exec.c,v 1.519 2023/10/04 20:29:18 ad Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2019, 2020 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.518 2022/07/01 01:05:31 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.519 2023/10/04 20:29:18 ad Exp $");
 
 #include "opt_exec.h"
 #include "opt_execfmt.h"
@@ -1408,7 +1408,7 @@ execve_runproc(struct lwp *l, struct 

CVS commit: src/sys

2023-10-04 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Wed Oct  4 20:28:06 UTC 2023

Modified Files:
src/sys/arch/aarch64/aarch64: trap.c
src/sys/arch/amd64/amd64: cpufunc.S genassym.cf
src/sys/arch/arm/arm: arm_machdep.c
src/sys/arch/i386/i386: cpufunc.S genassym.cf
src/sys/arch/mips/mips: cpu_subr.c
src/sys/arch/sparc64/sparc64: machdep.c
src/sys/arch/usermode/dev: cpu.c
src/sys/arch/x86/include: pmap_private.h
src/sys/arch/x86/x86: pmap.c x86_machdep.c
src/sys/kern: kern_cctr.c kern_entropy.c kern_exit.c kern_lock.c
kern_lwp.c kern_proc.c kern_resource.c kern_synch.c
subr_pserialize.c
src/sys/rump/librump/rumpkern: lwproc.c scheduler.c
src/sys/sys: lwp.h

Log Message:
Eliminate l->l_ncsw and l->l_nivcsw.  From memory think they were added
before we had per-LWP struct rusage; the same is now tracked there.


To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 src/sys/arch/aarch64/aarch64/trap.c
cvs rdiff -u -r1.65 -r1.66 src/sys/arch/amd64/amd64/cpufunc.S
cvs rdiff -u -r1.96 -r1.97 src/sys/arch/amd64/amd64/genassym.cf
cvs rdiff -u -r1.67 -r1.68 src/sys/arch/arm/arm/arm_machdep.c
cvs rdiff -u -r1.49 -r1.50 src/sys/arch/i386/i386/cpufunc.S
cvs rdiff -u -r1.134 -r1.135 src/sys/arch/i386/i386/genassym.cf
cvs rdiff -u -r1.63 -r1.64 src/sys/arch/mips/mips/cpu_subr.c
cvs rdiff -u -r1.306 -r1.307 src/sys/arch/sparc64/sparc64/machdep.c
cvs rdiff -u -r1.83 -r1.84 src/sys/arch/usermode/dev/cpu.c
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/x86/include/pmap_private.h
cvs rdiff -u -r1.425 -r1.426 src/sys/arch/x86/x86/pmap.c
cvs rdiff -u -r1.153 -r1.154 src/sys/arch/x86/x86/x86_machdep.c
cvs rdiff -u -r1.12 -r1.13 src/sys/kern/kern_cctr.c
cvs rdiff -u -r1.65 -r1.66 src/sys/kern/kern_entropy.c
cvs rdiff -u -r1.293 -r1.294 src/sys/kern/kern_exit.c
cvs rdiff -u -r1.186 -r1.187 src/sys/kern/kern_lock.c
cvs rdiff -u -r1.257 -r1.258 src/sys/kern/kern_lwp.c
cvs rdiff -u -r1.271 -r1.272 src/sys/kern/kern_proc.c
cvs rdiff -u -r1.194 -r1.195 src/sys/kern/kern_resource.c
cvs rdiff -u -r1.360 -r1.361 src/sys/kern/kern_synch.c
cvs rdiff -u -r1.23 -r1.24 src/sys/kern/subr_pserialize.c
cvs rdiff -u -r1.54 -r1.55 src/sys/rump/librump/rumpkern/lwproc.c
cvs rdiff -u -r1.53 -r1.54 src/sys/rump/librump/rumpkern/scheduler.c
cvs rdiff -u -r1.224 -r1.225 src/sys/sys/lwp.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/aarch64/aarch64/trap.c
diff -u src/sys/arch/aarch64/aarch64/trap.c:1.49 src/sys/arch/aarch64/aarch64/trap.c:1.50
--- src/sys/arch/aarch64/aarch64/trap.c:1.49	Sun Jul 16 21:36:40 2023
+++ src/sys/arch/aarch64/aarch64/trap.c	Wed Oct  4 20:28:05 2023
@@ -1,7 +1,7 @@
-/* $NetBSD: trap.c,v 1.49 2023/07/16 21:36:40 riastradh Exp $ */
+/* $NetBSD: trap.c,v 1.50 2023/10/04 20:28:05 ad Exp $ */
 
 /*-
- * Copyright (c) 2014 The NetBSD Foundation, Inc.
+ * Copyright (c) 2014, 2023 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -31,7 +31,7 @@
 
 #include 
 
-__KERNEL_RCSID(1, "$NetBSD: trap.c,v 1.49 2023/07/16 21:36:40 riastradh Exp $");
+__KERNEL_RCSID(1, "$NetBSD: trap.c,v 1.50 2023/10/04 20:28:05 ad Exp $");
 
 #include "opt_arm_intr_impl.h"
 #include "opt_compat_netbsd32.h"
@@ -1034,8 +1034,8 @@ do_trapsignal1(
 bool
 cpu_intr_p(void)
 {
-	uint64_t ncsw;
 	int idepth;
+	long pctr;
 	lwp_t *l;
 
 #ifdef __HAVE_PIC_FAST_SOFTINTS
@@ -1050,11 +1050,9 @@ cpu_intr_p(void)
 		return false;
 	}
 	do {
-		ncsw = l->l_ncsw;
-		__insn_barrier();
+		pctr = lwp_pctr();
 		idepth = l->l_cpu->ci_intr_depth;
-		__insn_barrier();
-	} while (__predict_false(ncsw != l->l_ncsw));
+	} while (__predict_false(pctr != lwp_pctr()));
 
 	return idepth > 0;
 }

Index: src/sys/arch/amd64/amd64/cpufunc.S
diff -u src/sys/arch/amd64/amd64/cpufunc.S:1.65 src/sys/arch/amd64/amd64/cpufunc.S:1.66
--- src/sys/arch/amd64/amd64/cpufunc.S:1.65	Mon Nov 30 17:02:27 2020
+++ src/sys/arch/amd64/amd64/cpufunc.S	Wed Oct  4 20:28:05 2023
@@ -1,7 +1,7 @@
-/*	$NetBSD: cpufunc.S,v 1.65 2020/11/30 17:02:27 bouyer Exp $	*/
+/*	$NetBSD: cpufunc.S,v 1.66 2023/10/04 20:28:05 ad Exp $	*/
 
 /*
- * Copyright (c) 1998, 2007, 2008, 2020 The NetBSD Foundation, Inc.
+ * Copyright (c) 1998, 2007, 2008, 2020, 2023 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -234,12 +234,13 @@ END(x86_hotpatch)
 #define CPU_COUNTER_FENCE(counter, fence)	\
 ENTRY(cpu_ ## counter ## _ ## fence)		;\
 	movq	CPUVAR(CURLWP), %rcx		;\
+	leaq	L_RU+RU_NIVCSW(%rcx), %rcx	;\
 1:		;\
-	movq	L_NCSW(%rcx), %rdi		;\
+	movq	(%rcx), %rdi			;\
 	SERIALIZE_ ## fence			;\
 	rdtsc	;\
 	ADD_ ## counter;\
-	cmpq	%rdi, L_NCSW(%rcx)		;\
+	cmpq	%rdi, (%rcx)			;\
 	jne	2f;\
 	KMSAN_INIT_RET(RSIZE_ ## counter)	;\
 	ret	

CVS commit: src/sys

2023-10-04 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Wed Oct  4 20:28:06 UTC 2023

Modified Files:
src/sys/arch/aarch64/aarch64: trap.c
src/sys/arch/amd64/amd64: cpufunc.S genassym.cf
src/sys/arch/arm/arm: arm_machdep.c
src/sys/arch/i386/i386: cpufunc.S genassym.cf
src/sys/arch/mips/mips: cpu_subr.c
src/sys/arch/sparc64/sparc64: machdep.c
src/sys/arch/usermode/dev: cpu.c
src/sys/arch/x86/include: pmap_private.h
src/sys/arch/x86/x86: pmap.c x86_machdep.c
src/sys/kern: kern_cctr.c kern_entropy.c kern_exit.c kern_lock.c
kern_lwp.c kern_proc.c kern_resource.c kern_synch.c
subr_pserialize.c
src/sys/rump/librump/rumpkern: lwproc.c scheduler.c
src/sys/sys: lwp.h

Log Message:
Eliminate l->l_ncsw and l->l_nivcsw.  From memory think they were added
before we had per-LWP struct rusage; the same is now tracked there.


To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 src/sys/arch/aarch64/aarch64/trap.c
cvs rdiff -u -r1.65 -r1.66 src/sys/arch/amd64/amd64/cpufunc.S
cvs rdiff -u -r1.96 -r1.97 src/sys/arch/amd64/amd64/genassym.cf
cvs rdiff -u -r1.67 -r1.68 src/sys/arch/arm/arm/arm_machdep.c
cvs rdiff -u -r1.49 -r1.50 src/sys/arch/i386/i386/cpufunc.S
cvs rdiff -u -r1.134 -r1.135 src/sys/arch/i386/i386/genassym.cf
cvs rdiff -u -r1.63 -r1.64 src/sys/arch/mips/mips/cpu_subr.c
cvs rdiff -u -r1.306 -r1.307 src/sys/arch/sparc64/sparc64/machdep.c
cvs rdiff -u -r1.83 -r1.84 src/sys/arch/usermode/dev/cpu.c
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/x86/include/pmap_private.h
cvs rdiff -u -r1.425 -r1.426 src/sys/arch/x86/x86/pmap.c
cvs rdiff -u -r1.153 -r1.154 src/sys/arch/x86/x86/x86_machdep.c
cvs rdiff -u -r1.12 -r1.13 src/sys/kern/kern_cctr.c
cvs rdiff -u -r1.65 -r1.66 src/sys/kern/kern_entropy.c
cvs rdiff -u -r1.293 -r1.294 src/sys/kern/kern_exit.c
cvs rdiff -u -r1.186 -r1.187 src/sys/kern/kern_lock.c
cvs rdiff -u -r1.257 -r1.258 src/sys/kern/kern_lwp.c
cvs rdiff -u -r1.271 -r1.272 src/sys/kern/kern_proc.c
cvs rdiff -u -r1.194 -r1.195 src/sys/kern/kern_resource.c
cvs rdiff -u -r1.360 -r1.361 src/sys/kern/kern_synch.c
cvs rdiff -u -r1.23 -r1.24 src/sys/kern/subr_pserialize.c
cvs rdiff -u -r1.54 -r1.55 src/sys/rump/librump/rumpkern/lwproc.c
cvs rdiff -u -r1.53 -r1.54 src/sys/rump/librump/rumpkern/scheduler.c
cvs rdiff -u -r1.224 -r1.225 src/sys/sys/lwp.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/kern

2023-10-02 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Mon Oct  2 21:50:18 UTC 2023

Modified Files:
src/sys/kern: vfs_cache.c

Log Message:
Tweak a couple of comments.


To generate a diff of this commit:
cvs rdiff -u -r1.155 -r1.156 src/sys/kern/vfs_cache.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/vfs_cache.c
diff -u src/sys/kern/vfs_cache.c:1.155 src/sys/kern/vfs_cache.c:1.156
--- src/sys/kern/vfs_cache.c:1.155	Sat Sep  9 18:27:59 2023
+++ src/sys/kern/vfs_cache.c	Mon Oct  2 21:50:18 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_cache.c,v 1.155 2023/09/09 18:27:59 ad Exp $	*/
+/*	$NetBSD: vfs_cache.c,v 1.156 2023/10/02 21:50:18 ad Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2019, 2020, 2023 The NetBSD Foundation, Inc.
@@ -164,11 +164,11 @@
  *	held.  See definition of "struct namecache" in src/sys/namei.src,
  *	and the definition of "struct vnode" for the particulars.
  *
- *	Per-CPU statistics, and LRU list totals are read unlocked, since
- *	an approximate value is OK.  We maintain 32-bit sized per-CPU
- *	counters and 64-bit global counters under the theory that 32-bit
- *	sized counters are less likely to be hosed by nonatomic increment
- *	(on 32-bit platforms).
+ *	Per-CPU statistics, and LRU list totals are read unlocked, since an
+ *	approximate value is OK.  We maintain 32-bit sized per-CPU counters
+ *	and 64-bit global counters since 32-bit sized counters can be
+ *	observed locklessly while the global counters are protected by a
+ *	mutex.
  *
  *	The lock order is:
  *
@@ -182,7 +182,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_cache.c,v 1.155 2023/09/09 18:27:59 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_cache.c,v 1.156 2023/10/02 21:50:18 ad Exp $");
 
 #define __NAMECACHE_PRIVATE
 #ifdef _KERNEL_OPT
@@ -437,8 +437,8 @@ cache_lookup_entry(struct vnode *dvp, co
 
 	/*
 	 * Search the RB tree for the key.  This is an inlined lookup
-	 * tailored for exactly what's needed here (64-bit key and so on)
-	 * that is quite a bit faster than using rb_tree_find_node().
+	 * tailored for exactly what's needed here that turns out to be
+	 * quite a bit faster than using rb_tree_find_node().
 	 *
 	 * For a matching key memcmp() needs to be called once to confirm
 	 * that the correct name has been found.  Very rarely there will be



CVS commit: src/sys/kern

2023-10-02 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Mon Oct  2 21:50:18 UTC 2023

Modified Files:
src/sys/kern: vfs_cache.c

Log Message:
Tweak a couple of comments.


To generate a diff of this commit:
cvs rdiff -u -r1.155 -r1.156 src/sys/kern/vfs_cache.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/kern

2023-10-02 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Mon Oct  2 21:03:55 UTC 2023

Modified Files:
src/sys/kern: kern_mutex_obj.c kern_rwlock_obj.c

Log Message:
Use kmem_intr_*() variants for lock objects since aiodoned was done away
with and we process these I/Os in soft interrupt context now.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/kern/kern_mutex_obj.c
cvs rdiff -u -r1.12 -r1.13 src/sys/kern/kern_rwlock_obj.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/kern

2023-10-02 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Mon Oct  2 21:03:55 UTC 2023

Modified Files:
src/sys/kern: kern_mutex_obj.c kern_rwlock_obj.c

Log Message:
Use kmem_intr_*() variants for lock objects since aiodoned was done away
with and we process these I/Os in soft interrupt context now.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/kern/kern_mutex_obj.c
cvs rdiff -u -r1.12 -r1.13 src/sys/kern/kern_rwlock_obj.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_mutex_obj.c
diff -u src/sys/kern/kern_mutex_obj.c:1.14 src/sys/kern/kern_mutex_obj.c:1.15
--- src/sys/kern/kern_mutex_obj.c:1.14	Sat Sep 23 18:21:11 2023
+++ src/sys/kern/kern_mutex_obj.c	Mon Oct  2 21:03:55 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_mutex_obj.c,v 1.14 2023/09/23 18:21:11 ad Exp $	*/
+/*	$NetBSD: kern_mutex_obj.c,v 1.15 2023/10/02 21:03:55 ad Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2019, 2023 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_mutex_obj.c,v 1.14 2023/09/23 18:21:11 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_mutex_obj.c,v 1.15 2023/10/02 21:03:55 ad Exp $");
 
 #include 
 #include 
@@ -57,7 +57,7 @@ mutex_obj_alloc(kmutex_type_t type, int 
 {
 	struct kmutexobj *mo;
 
-	mo = kmem_alloc(sizeof(*mo), KM_SLEEP);
+	mo = kmem_intr_alloc(sizeof(*mo), KM_SLEEP);
 	KASSERT(ALIGNED_POINTER(mo, coherency_unit));
 	_mutex_init(>mo_lock, type, ipl,
 	(uintptr_t)__builtin_return_address(0));
@@ -77,7 +77,7 @@ mutex_obj_tryalloc(kmutex_type_t type, i
 {
 	struct kmutexobj *mo;
 
-	mo = kmem_alloc(sizeof(*mo), KM_NOSLEEP);
+	mo = kmem_intr_alloc(sizeof(*mo), KM_NOSLEEP);
 	KASSERT(ALIGNED_POINTER(mo, coherency_unit));
 	if (__predict_true(mo != NULL)) {
 		_mutex_init(>mo_lock, type, ipl,
@@ -134,7 +134,7 @@ mutex_obj_free(kmutex_t *lock)
 	}
 	membar_acquire();
 	mutex_destroy(>mo_lock);
-	kmem_free(mo, sizeof(*mo));
+	kmem_intr_free(mo, sizeof(*mo));
 	return true;
 }
 

Index: src/sys/kern/kern_rwlock_obj.c
diff -u src/sys/kern/kern_rwlock_obj.c:1.12 src/sys/kern/kern_rwlock_obj.c:1.13
--- src/sys/kern/kern_rwlock_obj.c:1.12	Sat Sep 23 18:21:11 2023
+++ src/sys/kern/kern_rwlock_obj.c	Mon Oct  2 21:03:55 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_rwlock_obj.c,v 1.12 2023/09/23 18:21:11 ad Exp $	*/
+/*	$NetBSD: kern_rwlock_obj.c,v 1.13 2023/10/02 21:03:55 ad Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009, 2019, 2023 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_rwlock_obj.c,v 1.12 2023/09/23 18:21:11 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_rwlock_obj.c,v 1.13 2023/10/02 21:03:55 ad Exp $");
 
 #include 
 #include 
@@ -57,7 +57,7 @@ rw_obj_alloc(void)
 {
 	struct krwobj *ro;
 
-	ro = kmem_alloc(sizeof(*ro), KM_SLEEP);
+	ro = kmem_intr_alloc(sizeof(*ro), KM_SLEEP);
 	KASSERT(ALIGNED_POINTER(ro, coherency_unit));
 	_rw_init(>ro_lock, (uintptr_t)__builtin_return_address(0));
 	ro->ro_magic = RW_OBJ_MAGIC;
@@ -76,7 +76,7 @@ rw_obj_tryalloc(void)
 {
 	struct krwobj *ro;
 
-	ro = kmem_alloc(sizeof(*ro), KM_NOSLEEP);
+	ro = kmem_intr_alloc(sizeof(*ro), KM_NOSLEEP);
 	KASSERT(ALIGNED_POINTER(ro, coherency_unit));
 	if (__predict_true(ro != NULL)) {
 		_rw_init(>ro_lock, (uintptr_t)__builtin_return_address(0));
@@ -124,7 +124,7 @@ rw_obj_free(krwlock_t *lock)
 	}
 	membar_acquire();
 	rw_destroy(>ro_lock);
-	kmem_free(ro, sizeof(*ro));
+	kmem_intr_free(ro, sizeof(*ro));
 	return true;
 }
 



CVS commit: src/sys/kern

2023-10-02 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Mon Oct  2 20:59:12 UTC 2023

Modified Files:
src/sys/kern: kern_auth.c

Log Message:
kauth_cred_groupmember(): check egid before a tedious scan of groups.


To generate a diff of this commit:
cvs rdiff -u -r1.82 -r1.83 src/sys/kern/kern_auth.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_auth.c
diff -u src/sys/kern/kern_auth.c:1.82 src/sys/kern/kern_auth.c:1.83
--- src/sys/kern/kern_auth.c:1.82	Fri Feb 24 11:02:27 2023
+++ src/sys/kern/kern_auth.c	Mon Oct  2 20:59:12 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_auth.c,v 1.82 2023/02/24 11:02:27 riastradh Exp $ */
+/* $NetBSD: kern_auth.c,v 1.83 2023/10/02 20:59:12 ad Exp $ */
 
 /*-
  * Copyright (c) 2005, 2006 Elad Efrat 
@@ -28,7 +28,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_auth.c,v 1.82 2023/02/24 11:02:27 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_auth.c,v 1.83 2023/10/02 20:59:12 ad Exp $");
 
 #include 
 #include 
@@ -409,14 +409,14 @@ kauth_cred_groupmember(kauth_cred_t cred
 	KASSERT(cred != NOCRED);
 	KASSERT(cred != FSCRED);
 
+	if (kauth_cred_getegid(cred) == gid)
+		return 0;
+
 	error = kauth_cred_ismember_gid(cred, gid, );
 	if (error)
 		return error;
 
-	if (kauth_cred_getegid(cred) == gid || ismember)
-		return 0;
-
-	return -1;
+	return ismember ? 0 : -1;
 }
 
 u_int



CVS commit: src/sys/kern

2023-10-02 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Mon Oct  2 20:59:12 UTC 2023

Modified Files:
src/sys/kern: kern_auth.c

Log Message:
kauth_cred_groupmember(): check egid before a tedious scan of groups.


To generate a diff of this commit:
cvs rdiff -u -r1.82 -r1.83 src/sys/kern/kern_auth.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys

2023-09-23 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Sep 23 20:23:07 UTC 2023

Modified Files:
src/sys/kern: kern_lwp.c kern_sleepq.c kern_synch.c
src/sys/sys: lwp.h

Log Message:
Sigh..  Adjust previous to work as intended.  The boosted LWP priority
didn't persist as far as the run queue because l_syncobj gets reset
earlier than I recalled.


To generate a diff of this commit:
cvs rdiff -u -r1.256 -r1.257 src/sys/kern/kern_lwp.c
cvs rdiff -u -r1.75 -r1.76 src/sys/kern/kern_sleepq.c
cvs rdiff -u -r1.359 -r1.360 src/sys/kern/kern_synch.c
cvs rdiff -u -r1.221 -r1.222 src/sys/sys/lwp.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_lwp.c
diff -u src/sys/kern/kern_lwp.c:1.256 src/sys/kern/kern_lwp.c:1.257
--- src/sys/kern/kern_lwp.c:1.256	Sat Sep 23 18:48:04 2023
+++ src/sys/kern/kern_lwp.c	Sat Sep 23 20:23:07 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_lwp.c,v 1.256 2023/09/23 18:48:04 ad Exp $	*/
+/*	$NetBSD: kern_lwp.c,v 1.257 2023/09/23 20:23:07 ad Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2006, 2007, 2008, 2009, 2019, 2020, 2023
@@ -217,7 +217,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.256 2023/09/23 18:48:04 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.257 2023/09/23 20:23:07 ad Exp $");
 
 #include "opt_ddb.h"
 #include "opt_lockdebug.h"
@@ -851,7 +851,13 @@ lwp_create(lwp_t *l1, proc_t *p2, vaddr_
 		return EAGAIN;
 	}
 
-	l2->l_priority = l1->l_priority;
+	/*
+	 * If vfork(), we want the LWP to run fast and on the same CPU
+	 * as its parent, so that it can reuse the VM context and cache
+	 * footprint on the local CPU.
+	 */
+	l2->l_boostpri = ((flags & LWP_VFORK) ? PRI_KERNEL : PRI_USER);
+ 	l2->l_priority = l1->l_priority;
 	l2->l_inheritedprio = -1;
 	l2->l_protectprio = -1;
 	l2->l_auxprio = -1;
@@ -1666,7 +1672,6 @@ lwp_lendpri(lwp_t *l, pri_t pri)
 pri_t
 lwp_eprio(lwp_t *l)
 {
-	pri_t boostpri = l->l_syncobj->sobj_boostpri;
 	pri_t pri = l->l_priority;
 
 	KASSERT(mutex_owned(l->l_mutex));
@@ -1681,8 +1686,8 @@ lwp_eprio(lwp_t *l)
 	 * boost and could be preempted very quickly by another LWP but that
 	 * won't happen often enough to be a annoyance.
 	 */
-	if (pri <= MAXPRI_USER && boostpri > PRI_USER)
-		pri = (pri >> 1) + boostpri;
+	if (pri <= MAXPRI_USER && l->l_boostpri > MAXPRI_USER)
+		pri = (pri >> 1) + l->l_boostpri;
 
 	return MAX(l->l_auxprio, pri);
 }

Index: src/sys/kern/kern_sleepq.c
diff -u src/sys/kern/kern_sleepq.c:1.75 src/sys/kern/kern_sleepq.c:1.76
--- src/sys/kern/kern_sleepq.c:1.75	Sat Sep 23 18:48:04 2023
+++ src/sys/kern/kern_sleepq.c	Sat Sep 23 20:23:07 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_sleepq.c,v 1.75 2023/09/23 18:48:04 ad Exp $	*/
+/*	$NetBSD: kern_sleepq.c,v 1.76 2023/09/23 20:23:07 ad Exp $	*/
 
 /*-
  * Copyright (c) 2006, 2007, 2008, 2009, 2019, 2020, 2023
@@ -36,7 +36,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_sleepq.c,v 1.75 2023/09/23 18:48:04 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_sleepq.c,v 1.76 2023/09/23 20:23:07 ad Exp $");
 
 #include 
 #include 
@@ -368,6 +368,7 @@ sleepq_block(int timo, bool catch_p, syn
 			l->l_flag &= ~LW_STIMO;
 			callout_schedule(>l_timeout_ch, timo);
 		}
+		l->l_boostpri = l->l_syncobj->sobj_boostpri;
 		spc_lock(l->l_cpu);
 		mi_switch(l);
 

Index: src/sys/kern/kern_synch.c
diff -u src/sys/kern/kern_synch.c:1.359 src/sys/kern/kern_synch.c:1.360
--- src/sys/kern/kern_synch.c:1.359	Sat Sep 23 18:48:04 2023
+++ src/sys/kern/kern_synch.c	Sat Sep 23 20:23:07 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_synch.c,v 1.359 2023/09/23 18:48:04 ad Exp $	*/
+/*	$NetBSD: kern_synch.c,v 1.360 2023/09/23 20:23:07 ad Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2004, 2006, 2007, 2008, 2009, 2019, 2020, 2023
@@ -69,7 +69,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_synch.c,v 1.359 2023/09/23 18:48:04 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_synch.c,v 1.360 2023/09/23 20:23:07 ad Exp $");
 
 #include "opt_kstack.h"
 #include "opt_ddb.h"
@@ -561,6 +561,7 @@ nextlwp(struct cpu_info *ci, struct sche
 		KASSERT(newl->l_cpu == ci);
 		newl->l_stat = LSONPROC;
 		newl->l_pflag |= LP_RUNNING;
+		newl->l_boostpri = PRI_NONE;
 		spc->spc_curpriority = lwp_eprio(newl);
 		spc->spc_flags &= ~(SPCF_SWITCHCLEAR | SPCF_IDLE);
 		lwp_setlock(newl, spc->spc_lwplock);

Index: src/sys/sys/lwp.h
diff -u src/sys/sys/lwp.h:1.221 src/sys/sys/lwp.h:1.222
--- src/sys/sys/lwp.h:1.221	Sat Sep 23 18:48:05 2023
+++ src/sys/sys/lwp.h	Sat Sep 23 20:23:07 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: lwp.h,v 1.221 2023/09/23 18:48:05 ad Exp $	*/
+/*	$NetBSD: lwp.h,v 1.222 2023/09/23 20:23:07 ad Exp $	*/
 
 /*
  * Copyright (c) 2001, 2006, 2007, 2008, 2009, 2010, 2019, 2020, 2023
@@ -112,6 +112,7 @@ struct lwp {
 	u_int		l_slpticksum;	/* l: Sum of ticks spent sleeping */
 	int		l_biglocks;	/* l: biglock count before sleep */
 	int		l_class;	/* l: scheduling class */
+	pri_t		l_boostpri;	/* l: 

CVS commit: src/sys

2023-09-23 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Sep 23 20:23:07 UTC 2023

Modified Files:
src/sys/kern: kern_lwp.c kern_sleepq.c kern_synch.c
src/sys/sys: lwp.h

Log Message:
Sigh..  Adjust previous to work as intended.  The boosted LWP priority
didn't persist as far as the run queue because l_syncobj gets reset
earlier than I recalled.


To generate a diff of this commit:
cvs rdiff -u -r1.256 -r1.257 src/sys/kern/kern_lwp.c
cvs rdiff -u -r1.75 -r1.76 src/sys/kern/kern_sleepq.c
cvs rdiff -u -r1.359 -r1.360 src/sys/kern/kern_synch.c
cvs rdiff -u -r1.221 -r1.222 src/sys/sys/lwp.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/common/lib/libc/gen

2023-09-23 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Sep 23 19:17:38 UTC 2023

Modified Files:
src/common/lib/libc/gen: radixtree.c

Log Message:
kmem_free() -> kmem_intr_free().  Spotted by rin@.


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/common/lib/libc/gen/radixtree.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/common/lib/libc/gen/radixtree.c
diff -u src/common/lib/libc/gen/radixtree.c:1.32 src/common/lib/libc/gen/radixtree.c:1.33
--- src/common/lib/libc/gen/radixtree.c:1.32	Sat Sep 23 18:21:11 2023
+++ src/common/lib/libc/gen/radixtree.c	Sat Sep 23 19:17:38 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: radixtree.c,v 1.32 2023/09/23 18:21:11 ad Exp $	*/
+/*	$NetBSD: radixtree.c,v 1.33 2023/09/23 19:17:38 ad Exp $	*/
 
 /*-
  * Copyright (c)2011,2012,2013 YAMAMOTO Takashi,
@@ -112,7 +112,7 @@
 #include 
 
 #if defined(_KERNEL) || defined(_STANDALONE)
-__KERNEL_RCSID(0, "$NetBSD: radixtree.c,v 1.32 2023/09/23 18:21:11 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: radixtree.c,v 1.33 2023/09/23 19:17:38 ad Exp $");
 #include 
 #include 
 #include 
@@ -122,7 +122,7 @@ __KERNEL_RCSID(0, "$NetBSD: radixtree.c,
 #include 
 #endif /* defined(_STANDALONE) */
 #else /* defined(_KERNEL) || defined(_STANDALONE) */
-__RCSID("$NetBSD: radixtree.c,v 1.32 2023/09/23 18:21:11 ad Exp $");
+__RCSID("$NetBSD: radixtree.c,v 1.33 2023/09/23 19:17:38 ad Exp $");
 #include 
 #include 
 #include 
@@ -335,7 +335,7 @@ radix_tree_await_memory(void)
 		KM_SLEEP);
 	}
 	while (--i >= 0) {
-		kmem_free(nodes[i], sizeof(struct radix_tree_node));
+		kmem_intr_free(nodes[i], sizeof(struct radix_tree_node));
 	}
 }
 



CVS commit: src/common/lib/libc/gen

2023-09-23 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Sep 23 19:17:38 UTC 2023

Modified Files:
src/common/lib/libc/gen: radixtree.c

Log Message:
kmem_free() -> kmem_intr_free().  Spotted by rin@.


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/common/lib/libc/gen/radixtree.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



Re: CVS commit: src

2023-09-23 Thread Andrew Doran
On Sun, Sep 24, 2023 at 03:51:07AM +0900, Rin Okuyama wrote:
> Hi,
> 
> On 2023/09/24 3:21, Andrew Doran wrote:
> > Index: src/common/lib/libc/gen/radixtree.c
> > diff -u src/common/lib/libc/gen/radixtree.c:1.31 
> > src/common/lib/libc/gen/radixtree.c:1.32
> > --- src/common/lib/libc/gen/radixtree.c:1.31Tue Sep 12 16:17:21 2023
> > +++ src/common/lib/libc/gen/radixtree.c Sat Sep 23 18:21:11 2023
> ...
> > @@ -346,10 +331,11 @@ radix_tree_await_memory(void)
> > int i;
> > for (i = 0; i < __arraycount(nodes); i++) {
> > -   nodes[i] = pool_cache_get(radix_tree_node_cache, PR_WAITOK);
> > +   nodes[i] = kmem_intr_alloc(sizeof(struct radix_tree_node),
> > +   KM_SLEEP);
> > }
> > while (--i >= 0) {
> > -   pool_cache_put(radix_tree_node_cache, nodes[i]);
> > +   kmem_free(nodes[i], sizeof(struct radix_tree_node));
> > }
> >   }
> 
> kmem_intr_free() here?

Good catch! Thank you.

Andrew


CVS commit: src/sys/sys

2023-09-23 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Sep 23 18:49:16 UTC 2023

Modified Files:
src/sys/sys: param.h

Log Message:
NetBSD 10.99.9 - struct lwp changed


To generate a diff of this commit:
cvs rdiff -u -r1.731 -r1.732 src/sys/sys/param.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/sys/param.h
diff -u src/sys/sys/param.h:1.731 src/sys/sys/param.h:1.732
--- src/sys/sys/param.h:1.731	Wed Sep  6 12:31:49 2023
+++ src/sys/sys/param.h	Sat Sep 23 18:49:16 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: param.h,v 1.731 2023/09/06 12:31:49 riastradh Exp $	*/
+/*	$NetBSD: param.h,v 1.732 2023/09/23 18:49:16 ad Exp $	*/
 
 /*-
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -67,7 +67,7 @@
  *	2.99.9		(299000900)
  */
 
-#define	__NetBSD_Version__	1099000800	/* NetBSD 10.99.8 */
+#define	__NetBSD_Version__	1099000900	/* NetBSD 10.99.9 */
 
 #define __NetBSD_Prereq__(M,m,p) (M) * 1) + \
 (m) * 100) + (p) * 100) <= __NetBSD_Version__)



  1   2   3   4   >