tech-kern archive

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

Re: Adding a flag to sysctl_createv() to silence ARM warnings



In article <20171019102654.GH16742%mail.duskware.de@localhost>,
Martin Husemann  <martin%duskware.de@localhost> wrote:
>-=-=-=-=-=-
>
>Hey folks,
>
>at startup all arm machines show a warning:
>
>total memory = 512 MB
>avail memory = 495 MB
>sysctl_createv: sysctl_create(machine_arch) returned 17
>timecounter: Timecounters tick every 10.000 msec
>
>
>This is because sys/arach/arm/arm32/arm32_machdep.c creates the 
>hw.machine_arch sysctl value first (overriding the generic one).
>(Slightly) later kern/sysctl_init_base.c tries to create the same (but
>different) value and (verbosly) fails with EEXIST.
>
>Easy way out: use the sysctl_createv() "cflags" argument to pass in
>an option telling it this is ok, and make it silently fail.
>
>The patch attached does that.
>
>Comments?

I have to say I dislike the "ignore if exists" paradigm and creating
things twice, because who knows which comes first, and which should
come first? Also it opens the gateway to ignore valid error and
abuse. I think it is a lot simpler to just allow MD code to specify
a more dynamic string for machine_arch and gut the MD setup code
in the process (untested but should work)

christos

Index: arch/arm/arm32/arm32_machdep.c
===================================================================
RCS file: /cvsroot/src/sys/arch/arm/arm32/arm32_machdep.c,v
retrieving revision 1.114
diff -u -u -r1.114 arm32_machdep.c
--- arch/arm/arm32/arm32_machdep.c	2 Jul 2017 16:16:44 -0000	1.114
+++ arch/arm/arm32/arm32_machdep.c	19 Oct 2017 13:34:11 -0000
@@ -402,15 +402,6 @@
 	return (0);
 }
 
-static int
-sysctl_hw_machine_arch(SYSCTLFN_ARGS)
-{
-	struct sysctlnode node = *rnode;
-	node.sysctl_data = l->l_proc->p_md.md_march;
-	node.sysctl_size = strlen(l->l_proc->p_md.md_march) + 1;
-	return sysctl_lookup(SYSCTLFN_CALL(&node));
-}
-
 SYSCTL_SETUP(sysctl_machdep_setup, "sysctl machdep subtree setup")
 {
 
@@ -532,18 +523,6 @@
 		       SYSCTL_DESCR("Do SIGBUS for fixed unaligned accesses"),
 		       NULL, 0, &cpu_unaligned_sigbus, 0,
 		       CTL_MACHDEP, CTL_CREATE, CTL_EOL);
-
-
-	/*
-	 * We need override the usual CTL_HW HW_MACHINE_ARCH so we
-	 * return the right machine_arch based on the running executable.
-	 */
-	sysctl_createv(clog, 0, NULL, NULL,
-		       CTLFLAG_PERMANENT|CTLFLAG_READONLY,
-		       CTLTYPE_STRING, "machine_arch",
-		       SYSCTL_DESCR("Machine CPU class"),
-		       sysctl_hw_machine_arch, 0, NULL, 0,
-		       CTL_HW, HW_MACHINE_ARCH, CTL_EOL);
 }
 
 void
Index: arch/arm/include/proc.h
===================================================================
RCS file: /cvsroot/src/sys/arch/arm/include/proc.h,v
retrieving revision 1.17
diff -u -u -r1.17 proc.h
--- arch/arm/include/proc.h	24 Feb 2014 16:57:57 -0000	1.17
+++ arch/arm/include/proc.h	19 Oct 2017 13:34:11 -0000
@@ -59,6 +59,7 @@
 	char	md_march[12];		/* machine arch of executable */
 };
 
+#define	PROC_MACHINE_ARCH (l->l_proc->p_md.md_march)
 #define	PROC0_MD_INITIALIZERS .p_md = { .md_march = MACHINE_ARCH },
 
 #endif /* _ARM_PROC_H_ */
Index: kern/init_sysctl_base.c
===================================================================
RCS file: /cvsroot/src/sys/kern/init_sysctl_base.c,v
retrieving revision 1.7
diff -u -u -r1.7 init_sysctl_base.c
--- kern/init_sysctl_base.c	25 Aug 2015 14:52:31 -0000	1.7
+++ kern/init_sysctl_base.c	19 Oct 2017 13:34:12 -0000
@@ -35,6 +35,7 @@
 #include <sys/types.h>
 #include <sys/param.h>
 #include <sys/sysctl.h>
+#include <sys/proc.h>
 #include <sys/cpu.h>
 #include <sys/kernel.h>
 #include <sys/disklabel.h>
@@ -183,6 +184,18 @@
 		       CTL_KERN, KERN_RAWPARTITION, CTL_EOL);
 }
 
+static int
+sysctl_hw_machine_arch(SYSCTLFN_ARGS)
+{
+	struct sysctlnode node = *rnode;
+#ifndef PROC_MACHINE_ARCH
+#define PROC_MACHINE_ARCH machine_arch
+#endif
+	node.sysctl_data = PROC_MACHINE_ARCH;
+	node.sysctl_size = strlen(PROC_MACHINE_ARCH) + 1;
+	return sysctl_lookup(SYSCTLFN_CALL(&node));
+}
+
 SYSCTL_SETUP(sysctl_hwbase_setup, "sysctl hw subtree base setup")
 {
 	u_int u;
@@ -202,10 +215,10 @@
 		       NULL, 0, machine, 0,
 		       CTL_HW, HW_MACHINE, CTL_EOL);
 	sysctl_createv(clog, 0, NULL, NULL,
-		       CTLFLAG_PERMANENT,
+		       CTLFLAG_PERMANENT|CTLFLAG_READONLY,
 		       CTLTYPE_STRING, "machine_arch",
 		       SYSCTL_DESCR("Machine CPU class"),
-		       NULL, 0, machine_arch, 0,
+		       sysctl_hw_machine_arch, 0, NULL, 0,
 		       CTL_HW, HW_MACHINE_ARCH, CTL_EOL);
 	sysctl_createv(clog, 0, NULL, NULL,
 		       CTLFLAG_PERMANENT,



Home | Main Index | Thread Index | Old Index