svn commit: r246282 - in head/sys: conf kern

Andriy Gapon avg at FreeBSD.org
Sun Feb 3 09:57:40 UTC 2013


Author: avg
Date: Sun Feb  3 09:57:39 2013
New Revision: 246282
URL: http://svnweb.freebsd.org/changeset/base/246282

Log:
  allow for large KTR_ENTRIES values by allocating ktr_buf using malloc(9)
  
  Only during very early boot, before malloc(9) is functional (SI_SUB_KMEM),
  the static ktr_buf_init is used.  Size of the static buffer is determined
  by a new kernel option KTR_BOOT_ENTRIES.  Its default value is 1024.
  
  This commit builds on top of r243046.
  
  Reviewed by:	alc
  MFC after:	17 days

Modified:
  head/sys/conf/NOTES
  head/sys/conf/options
  head/sys/kern/kern_ktr.c

Modified: head/sys/conf/NOTES
==============================================================================
--- head/sys/conf/NOTES	Sun Feb  3 03:46:16 2013	(r246281)
+++ head/sys/conf/NOTES	Sun Feb  3 09:57:39 2013	(r246282)
@@ -446,6 +446,8 @@ options 	KTRACE_REQUEST_POOL=101
 # KTR is a kernel tracing facility imported from BSD/OS.  It is
 # enabled with the KTR option.  KTR_ENTRIES defines the number of
 # entries in the circular trace buffer; it may be an arbitrary number.
+# KTR_BOOT_ENTRIES defines the number of entries during the early boot,
+# before malloc(9) is functional.
 # KTR_COMPILE defines the mask of events to compile into the kernel as
 # defined by the KTR_* constants in <sys/ktr.h>.  KTR_MASK defines the
 # initial value of the ktr_mask variable which determines at runtime
@@ -459,7 +461,8 @@ options 	KTRACE_REQUEST_POOL=101
 # if KTR_VERBOSE is not defined.  See ktr(4) and ktrdump(8) for details.
 #
 options 	KTR
-options 	KTR_ENTRIES=1024
+options 	KTR_BOOT_ENTRIES=1024
+options 	KTR_ENTRIES=(128 * 1024)
 options 	KTR_COMPILE=(KTR_INTR|KTR_PROC)
 options 	KTR_MASK=KTR_INTR
 options 	KTR_CPUMASK=0x3

Modified: head/sys/conf/options
==============================================================================
--- head/sys/conf/options	Sun Feb  3 03:46:16 2013	(r246281)
+++ head/sys/conf/options	Sun Feb  3 09:57:39 2013	(r246282)
@@ -669,6 +669,7 @@ KTR_ALQ			opt_ktr.h
 KTR_MASK		opt_ktr.h
 KTR_CPUMASK		opt_ktr.h
 KTR_COMPILE		opt_global.h
+KTR_BOOT_ENTRIES	opt_global.h
 KTR_ENTRIES		opt_global.h
 KTR_VERBOSE		opt_ktr.h
 WITNESS			opt_global.h

Modified: head/sys/kern/kern_ktr.c
==============================================================================
--- head/sys/kern/kern_ktr.c	Sun Feb  3 03:46:16 2013	(r246281)
+++ head/sys/kern/kern_ktr.c	Sun Feb  3 09:57:39 2013	(r246282)
@@ -66,6 +66,10 @@ __FBSDID("$FreeBSD$");
 #include <ddb/db_output.h>
 #endif
 
+#ifndef KTR_BOOT_ENTRIES
+#define	KTR_BOOT_ENTRIES	1024
+#endif
+
 #ifndef KTR_ENTRIES
 #define	KTR_ENTRIES	1024
 #endif
@@ -96,9 +100,9 @@ FEATURE(ktr, "Kernel support for KTR ker
 volatile int	ktr_idx = 0;
 int	ktr_mask = KTR_MASK;
 int	ktr_compile = KTR_COMPILE;
-int	ktr_entries = KTR_ENTRIES;
+int	ktr_entries = KTR_BOOT_ENTRIES;
 int	ktr_version = KTR_VERSION;
-struct	ktr_entry ktr_buf_init[KTR_ENTRIES];
+struct	ktr_entry ktr_buf_init[KTR_BOOT_ENTRIES];
 struct	ktr_entry *ktr_buf = ktr_buf_init;
 cpuset_t ktr_cpumask = CPUSET_T_INITIALIZER(KTR_CPUMASK);
 static char ktr_cpumask_str[CPUSETBUFSIZ];
@@ -194,6 +198,28 @@ SYSCTL_PROC(_debug_ktr, OID_AUTO, mask, 
     sysctl_debug_ktr_mask, "IU",
     "Bitmask of KTR event classes for which logging is enabled");
 
+#if KTR_ENTRIES != KTR_BOOT_ENTRIES
+/*
+ * A simplified version of sysctl_debug_ktr_entries.
+ * No need to care about SMP, scheduling, etc.
+ */
+static void
+ktr_entries_initializer(void *dummy __unused)
+{
+	int mask;
+
+	/* Temporarily disable ktr in case malloc() is being traced. */
+	mask = ktr_mask;
+	ktr_mask = 0;
+	ktr_buf = malloc(sizeof(*ktr_buf) * KTR_ENTRIES, M_KTR,
+	    M_WAITOK | M_ZERO);
+	ktr_entries = KTR_ENTRIES;
+	ktr_mask = mask;
+}
+SYSINIT(ktr_entries_initializer, SI_SUB_KMEM, SI_ORDER_ANY,
+    ktr_entries_initializer, NULL);
+#endif
+
 static int
 sysctl_debug_ktr_entries(SYSCTL_HANDLER_ARGS)
 {


More information about the svn-src-head mailing list