Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Add EX_EARLY flag for extent_create, which skips locking...
details: https://anonhg.NetBSD.org/src/rev/cd22a6a5432b
branches: trunk
changeset: 355957:cd22a6a5432b
user: jmcneill <jmcneill%NetBSD.org@localhost>
date: Thu Aug 24 11:33:28 2017 +0000
description:
Add EX_EARLY flag for extent_create, which skips locking. Required for
using extent subsystem in early bootstrap code, before caches are enabled.
>From skrll@
diffstat:
sys/arch/evbarm/fdt/fdt_machdep.c | 6 ++--
sys/kern/subr_extent.c | 45 ++++++++++++++++++++++++++------------
sys/sys/extent.h | 6 +++-
3 files changed, 38 insertions(+), 19 deletions(-)
diffs (199 lines):
diff -r d079a9999229 -r cd22a6a5432b sys/arch/evbarm/fdt/fdt_machdep.c
--- a/sys/arch/evbarm/fdt/fdt_machdep.c Thu Aug 24 11:26:32 2017 +0000
+++ b/sys/arch/evbarm/fdt/fdt_machdep.c Thu Aug 24 11:33:28 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fdt_machdep.c,v 1.12 2017/08/20 21:00:01 jakllsch Exp $ */
+/* $NetBSD: fdt_machdep.c,v 1.13 2017/08/24 11:33:28 jmcneill Exp $ */
/*-
* Copyright (c) 2015-2017 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fdt_machdep.c,v 1.12 2017/08/20 21:00:01 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdt_machdep.c,v 1.13 2017/08/24 11:33:28 jmcneill Exp $");
#include "opt_machdep.h"
#include "opt_ddb.h"
@@ -230,7 +230,7 @@
int index, error;
fdt_memory_ext = extent_create("FDT Memory", mem_addr, max_addr,
- fdt_memory_ext_storage, sizeof(fdt_memory_ext_storage), 0);
+ fdt_memory_ext_storage, sizeof(fdt_memory_ext_storage), EX_EARLY);
for (index = 0;
fdtbus_get_reg64(memory, index, &addr, &size) == 0;
diff -r d079a9999229 -r cd22a6a5432b sys/kern/subr_extent.c
--- a/sys/kern/subr_extent.c Thu Aug 24 11:26:32 2017 +0000
+++ b/sys/kern/subr_extent.c Thu Aug 24 11:33:28 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_extent.c,v 1.81 2017/07/24 19:56:07 skrll Exp $ */
+/* $NetBSD: subr_extent.c,v 1.82 2017/08/24 11:33:28 jmcneill Exp $ */
/*-
* Copyright (c) 1996, 1998, 2007 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_extent.c,v 1.81 2017/07/24 19:56:07 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_extent.c,v 1.82 2017/08/24 11:33:28 jmcneill Exp $");
#ifdef _KERNEL
#ifdef _KERNEL_OPT
@@ -131,6 +131,7 @@
if (ex->ex_flags & EXF_FIXED) {
struct extent_fixed *fex = (struct extent_fixed *)ex;
+ if (!(ex->ex_flags & EXF_EARLY))
mutex_enter(&ex->ex_lock);
for (;;) {
if ((rp = LIST_FIRST(&fex->fex_freelist)) != NULL) {
@@ -141,17 +142,21 @@
* need to remember that information.
*/
LIST_REMOVE(rp, er_link);
- mutex_exit(&ex->ex_lock);
+ if (!(ex->ex_flags & EXF_EARLY))
+ mutex_exit(&ex->ex_lock);
return (rp);
}
if (flags & EX_MALLOCOK) {
- mutex_exit(&ex->ex_lock);
+ if (!(ex->ex_flags & EXF_EARLY))
+ mutex_exit(&ex->ex_lock);
goto alloc;
}
if ((flags & EX_WAITOK) == 0) {
- mutex_exit(&ex->ex_lock);
+ if (!(ex->ex_flags & EXF_EARLY))
+ mutex_exit(&ex->ex_lock);
return (NULL);
}
+ KASSERT(mutex_owned(&ex->ex_lock));
ex->ex_flwanted = true;
if ((flags & EX_CATCH) != 0)
error = cv_wait_sig(&ex->ex_cv, &ex->ex_lock);
@@ -206,8 +211,10 @@
}
wake_em_up:
- ex->ex_flwanted = false;
- cv_broadcast(&ex->ex_cv);
+ if (!(ex->ex_flags & EXF_EARLY)) {
+ ex->ex_flwanted = false;
+ cv_broadcast(&ex->ex_cv);
+ }
return;
}
@@ -297,6 +304,8 @@
ex->ex_flags |= EXF_FIXED;
if (flags & EX_NOCOALESCE)
ex->ex_flags |= EXF_NOCOALESCE;
+ if (flags & EX_EARLY)
+ ex->ex_flags |= EXF_EARLY;
return (ex);
}
@@ -507,7 +516,8 @@
return (ENOMEM);
}
- mutex_enter(&ex->ex_lock);
+ if (!(ex->ex_flags & EXF_EARLY))
+ mutex_enter(&ex->ex_lock);
alloc_start:
/*
@@ -545,6 +555,7 @@
* do so.
*/
if (flags & EX_WAITSPACE) {
+ KASSERT(!(ex->ex_flags & EXF_EARLY));
if ((flags & EX_CATCH) != 0)
error = cv_wait_sig(&ex->ex_cv,
&ex->ex_lock);
@@ -556,7 +567,8 @@
goto alloc_start;
mutex_exit(&ex->ex_lock);
} else {
- mutex_exit(&ex->ex_lock);
+ if (!(ex->ex_flags & EXF_EARLY))
+ mutex_exit(&ex->ex_lock);
error = EAGAIN;
}
extent_free_region_descriptor(ex, myrp);
@@ -576,7 +588,8 @@
* at the beginning of the region list. Insert ourselves.
*/
extent_insert_and_optimize(ex, start, size, flags, last, myrp);
- mutex_exit(&ex->ex_lock);
+ if (!(ex->ex_flags & EXF_EARLY))
+ mutex_exit(&ex->ex_lock);
return (0);
}
@@ -1042,7 +1055,8 @@
return (ENOMEM);
}
- mutex_enter(&ex->ex_lock);
+ if (!(ex->ex_flags & EXF_EARLY))
+ mutex_enter(&ex->ex_lock);
/*
* Find region and deallocate. Several possibilities:
@@ -1125,7 +1139,8 @@
}
/* Region not found, or request otherwise invalid. */
- mutex_exit(&ex->ex_lock);
+ if (!(ex->ex_flags & EXF_EARLY))
+ mutex_exit(&ex->ex_lock);
extent_print(ex);
printf("extent_free: start 0x%lx, end 0x%lx\n", start, end);
panic("extent_free: region not found");
@@ -1133,8 +1148,10 @@
done:
if (nrp != NULL)
extent_free_region_descriptor(ex, nrp);
- cv_broadcast(&ex->ex_cv);
- mutex_exit(&ex->ex_lock);
+ if (!(ex->ex_flags & EXF_EARLY)) {
+ cv_broadcast(&ex->ex_cv);
+ mutex_exit(&ex->ex_lock);
+ }
return (0);
}
diff -r d079a9999229 -r cd22a6a5432b sys/sys/extent.h
--- a/sys/sys/extent.h Thu Aug 24 11:26:32 2017 +0000
+++ b/sys/sys/extent.h Thu Aug 24 11:33:28 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: extent.h,v 1.25 2017/07/27 10:04:28 skrll Exp $ */
+/* $NetBSD: extent.h,v 1.26 2017/08/24 11:33:28 jmcneill Exp $ */
/*-
* Copyright (c) 1996, 1998 The NetBSD Foundation, Inc.
@@ -73,8 +73,9 @@
/* ex_flags; for internal use only */
#define EXF_FIXED __BIT(0) /* extent uses fixed storage */
#define EXF_NOCOALESCE __BIT(1) /* coalescing of regions not allowed */
+#define EXF_EARLY __BIT(2) /* no need to lock */
-#define EXF_BITS "\20\2NOCOALESCE\1FIXED"
+#define EXF_BITS "\20\3EARLY\2NOCOALESCE\1FIXED"
/* misc. flags passed to extent functions */
#define EX_NOWAIT 0 /* not safe to sleep */
@@ -85,6 +86,7 @@
#define EX_MALLOCOK __BIT(4) /* safe to call kmem_alloc() */
#define EX_WAITSPACE __BIT(5) /* wait for space to become free */
#define EX_BOUNDZERO __BIT(6) /* boundary lines start at 0 */
+#define EX_EARLY __BIT(7) /* safe for early kernel bootstrap */
/*
* Special place holders for "alignment" and "boundary" arguments,
Home |
Main Index |
Thread Index |
Old Index