[libbsd 19/22] Move VFS BIO initialization

Sebastian Huber sebastian.huber at embedded-brains.de
Fri Jun 24 06:33:47 UTC 2022


rtems_bsd_initialize() should initialize the bare minimum.

Update #4475.
---
 freebsd/sys/kern/vfs_bio.c                    | 24 ++++++++++++++++++-
 .../machine/rtems-bsd-kernel-namespace.h      |  1 -
 rtemsbsd/rtems/rtems-kernel-init.c            | 20 ----------------
 3 files changed, 23 insertions(+), 22 deletions(-)

diff --git a/freebsd/sys/kern/vfs_bio.c b/freebsd/sys/kern/vfs_bio.c
index 7be96690..594f878c 100644
--- a/freebsd/sys/kern/vfs_bio.c
+++ b/freebsd/sys/kern/vfs_bio.c
@@ -95,7 +95,14 @@ __FBSDID("$FreeBSD$");
 #include <rtems/bsd/local/opt_swap.h>
 
 #ifdef __rtems__
+#include <rtems/malloc.h>
+#include <rtems/bsd/bsd.h>
+
+#include <machine/rtems-bsd-page.h>
+
 int bio_transient_maxcnt = 1024;
+long maxbcache;
+static caddr_t unmapped_base;
 #endif /* __rtems__ */
 static MALLOC_DEFINE(M_BIOBUF, "biobuf", "BIO buffer");
 
@@ -1201,7 +1208,6 @@ bufinit(void)
 #ifndef __rtems__
 	unmapped_buf = (caddr_t)kva_alloc(MAXPHYS);
 #else /* __rtems__ */
-	extern caddr_t unmapped_base;
 	unmapped_buf = (caddr_t)unmapped_base;
 #endif /* __rtems__ */
 
@@ -1332,6 +1338,22 @@ bufinit(void)
 	bufdefragcnt = counter_u64_alloc(M_WAITOK);
 	bufkvaspace = counter_u64_alloc(M_WAITOK);
 }
+#ifdef __rtems__
+static void
+vfs_bio_init(void *dummy)
+{
+
+	maxbcache = rtems_bsd_get_allocator_domain_size(
+	    RTEMS_BSD_ALLOCATOR_DOMAIN_BIO);
+	unmapped_base = (caddr_t)rtems_heap_allocate_aligned_with_boundary(
+	    maxbcache, CACHE_LINE_SIZE, 0);
+	BSD_ASSERT(unmapped_base != NULL);
+	kern_vfs_bio_buffer_alloc(unmapped_base, maxbcache);
+	bufinit();
+	vm_pager_bufferinit();
+}
+SYSINIT(cpu, SI_SUB_CPU, SI_ORDER_FIRST, vfs_bio_init, NULL);
+#endif /* __rtems__ */
 
 #ifdef INVARIANTS
 static inline void
diff --git a/rtemsbsd/include/machine/rtems-bsd-kernel-namespace.h b/rtemsbsd/include/machine/rtems-bsd-kernel-namespace.h
index 9a7b0c09..0b5fa321 100644
--- a/rtemsbsd/include/machine/rtems-bsd-kernel-namespace.h
+++ b/rtemsbsd/include/machine/rtems-bsd-kernel-namespace.h
@@ -6381,7 +6381,6 @@
 #define	uma_zone_set_zinit _bsd_uma_zone_set_zinit
 #define	uma_zsecond_create _bsd_uma_zsecond_create
 #define	uma_zwait _bsd_uma_zwait
-#define	unmapped_base _bsd_unmapped_base
 #define	unmapped_buf _bsd_unmapped_buf
 #define	unmapped_buf_allowed _bsd_unmapped_buf_allowed
 #define	unp_copy_peercred _bsd_unp_copy_peercred
diff --git a/rtemsbsd/rtems/rtems-kernel-init.c b/rtemsbsd/rtems/rtems-kernel-init.c
index 9b24ba6d..af563c81 100644
--- a/rtemsbsd/rtems/rtems-kernel-init.c
+++ b/rtemsbsd/rtems/rtems-kernel-init.c
@@ -67,7 +67,6 @@
 #include <limits.h>
 #include <rtems/bsd/bsd.h>
 #include <rtems/libio_.h>
-#include <rtems/malloc.h>
 #include <uuid/uuid.h>
 
 SYSINIT_REFERENCE(configure1);
@@ -108,8 +107,6 @@ sbintime_t tc_tick_sbt;
 int tc_precexp;
 int maxproc;
 int ngroups_max;
-caddr_t unmapped_base;
-long maxbcache;
 struct sx allproc_lock;
 struct vmem *rtems_bsd_transient_arena;
 int nbuf;   /* The number of buffer headers */
@@ -128,15 +125,6 @@ SYSCTL_INT(_kern_smp, OID_AUTO, maxid, CTLFLAG_RD | CTLFLAG_CAPRD,
 SYSCTL_INT(_kern_smp, OID_AUTO, maxcpus, CTLFLAG_RD | CTLFLAG_CAPRD,
     &maxid_maxcpus, 0, "Max number of CPUs that the system was compiled for.");
 
-static void
-cpu_startup(void *dummy)
-{
-	kern_vfs_bio_buffer_alloc(unmapped_base, maxbcache);
-	bufinit();
-	vm_pager_bufferinit();
-}
-SYSINIT(cpu, SI_SUB_CPU, SI_ORDER_FIRST, cpu_startup, NULL);
-
 static struct filedesc p_fd = {
     .fd_cmask = CMASK
 };
@@ -211,14 +199,6 @@ rtems_bsd_initialize(void)
 	maxproc = 16;
 	ngroups_max = 4;
 
-	maxbcache = rtems_bsd_get_allocator_domain_size(
-	    RTEMS_BSD_ALLOCATOR_DOMAIN_BIO);
-	unmapped_base = (caddr_t)rtems_heap_allocate_aligned_with_boundary(
-	    maxbcache, CACHE_LINE_SIZE, 0);
-	if (unmapped_base == NULL) {
-		return RTEMS_UNSATISFIED;
-	}
-
 	mkdir("/etc", S_IRWXU | S_IRWXG | S_IRWXO);
 
 	sc = rtems_timer_initiate_server(rtems_bsd_get_task_priority(name),
-- 
2.35.3



More information about the devel mailing list