kern/148367: [patch] Add loader tunable to override SC_HISTORY_SIZE
Dmitry Pryanishnikov
lynx.ripe at gmail.com
Sun Jul 4 22:30:02 UTC 2010
>Number: 148367
>Category: kern
>Synopsis: [patch] Add loader tunable to override SC_HISTORY_SIZE
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: change-request
>Submitter-Id: current-users
>Arrival-Date: Sun Jul 04 22:30:01 UTC 2010
>Closed-Date:
>Last-Modified:
>Originator: Dmitry Pryanishnikov
>Release: RELENG_8
>Organization:
Home
>Environment:
FreeBSD lynx.homenet 8.1-PRERELEASE FreeBSD 8.1-PRERELEASE #0: Sun Jul 4 20:13:03 EEST 2010 dmitry at lynx.homenet:/databig/obj/databig/ftp/RELENG_8/src.100704/sys/lynx i386
>Description:
It is useful to keep SC_HISTORY_SIZE value high, however it costs kernel memory. So in order to share the same kernel between machines with big and not-so-big RAM, one should be able to tune the size of back scroll buffer. The attached patch makes it possible via the loader tunable hw.syscons.history_size. Patch works with today's RELENG_8, it also applies to HEAD (and should work there, since schistory.c is the same in HEAD and RELENG_8 except __FBSDID line).
>How-To-Repeat:
>Fix:
Patch attached with submission follows:
--- sys/dev/syscons/syscons.h.orig 2010-03-02 03:56:55.000000000 +0200
+++ sys/dev/syscons/syscons.h 2010-07-04 00:43:11.366661343 +0300
@@ -572,6 +572,7 @@
/* schistory.c */
#ifndef SC_NO_HISTORY
+void sc_init_history(void);
int sc_alloc_history_buffer(scr_stat *scp, int lines,
int prev_ysize, int wait);
void sc_free_history_buffer(scr_stat *scp, int prev_ysize);
--- sys/dev/syscons/syscons.c.orig 2010-03-31 18:39:46.000000000 +0300
+++ sys/dev/syscons/syscons.c 2010-07-04 00:43:11.368678117 +0300
@@ -2726,8 +2726,12 @@
int i;
/* one time initialization */
- if (init_done == COLD)
+ if (init_done == COLD) {
sc_get_bios_values(&bios_value);
+#ifndef SC_NO_HISTORY
+ sc_init_history();
+#endif
+ }
init_done = WARM;
/*
--- sys/dev/syscons/schistory.c.orig 2009-08-03 11:13:06.000000000 +0300
+++ sys/dev/syscons/schistory.c 2010-07-04 00:43:11.369673234 +0300
@@ -41,6 +41,7 @@
#include <sys/tty.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
+#include <sys/sysctl.h>
#if defined(__sparc64__) || defined(__powerpc__)
#include <machine/sc_machdep.h>
@@ -77,17 +78,37 @@
static int extra_history_size
= SC_MAX_HISTORY_SIZE - SC_HISTORY_SIZE*MAXCONS;
+static int sc_history_size = SC_HISTORY_SIZE;
+
+SYSCTL_DECL(_hw_syscons);
+SYSCTL_INT(_hw_syscons, OID_AUTO, history_size, CTLFLAG_RDTUN, &sc_history_size, 0,
+ "Number of history buffer lines");
+
/* local functions */
static void copy_history(sc_vtb_t *from, sc_vtb_t *to);
static void history_to_screen(scr_stat *scp);
+/* tune history buffer size */
+void
+sc_init_history(void)
+{
+
+ TUNABLE_INT_FETCH("hw.syscons.history_size", &sc_history_size);
+ if (sc_history_size < ROW * 4)
+ sc_history_size = ROW * 4;
+ extra_history_size =
+ ((sc_history_size * MAXCONS * MAXSC) > SC_MAX_HISTORY_SIZE ?
+ sc_history_size * MAXCONS * MAXSC : SC_MAX_HISTORY_SIZE) -
+ sc_history_size * MAXCONS;
+}
+
/* allocate a history buffer */
int
sc_alloc_history_buffer(scr_stat *scp, int lines, int prev_ysize, int wait)
{
/*
* syscons unconditionally allocates buffers upto
- * SC_HISTORY_SIZE lines or scp->ysize lines, whichever
+ * sc_history_size lines or scp->ysize lines, whichever
* is larger. A value greater than that is allowed,
* subject to extra_history_size.
*/
@@ -98,7 +119,7 @@
int delta; /* lines to put back */
if (lines <= 0)
- lines = SC_HISTORY_SIZE; /* use the default value */
+ lines = sc_history_size; /* use the default value */
/* make it at least as large as the screen size */
lines = imax(lines, scp->ysize);
@@ -111,13 +132,13 @@
delta = 0;
if (prev_history) {
cur_lines = sc_vtb_rows(history);
- min_lines = imax(SC_HISTORY_SIZE, prev_ysize);
+ min_lines = imax(sc_history_size, prev_ysize);
if (cur_lines > min_lines)
delta = cur_lines - min_lines;
}
/* lines upto min_lines are always allowed. */
- min_lines = imax(SC_HISTORY_SIZE, scp->ysize);
+ min_lines = imax(sc_history_size, scp->ysize);
if (lines > min_lines) {
if (lines - min_lines > extra_history_size + delta) {
/* too many lines are requested */
@@ -196,7 +217,7 @@
return;
cur_lines = sc_vtb_rows(history);
- min_lines = imax(SC_HISTORY_SIZE, prev_ysize);
+ min_lines = imax(sc_history_size, prev_ysize);
extra_history_size += (cur_lines > min_lines) ?
cur_lines - min_lines : 0;
--- share/man/man4/syscons.4.orig 2010-03-10 11:38:03.828597000 +0200
+++ share/man/man4/syscons.4 2010-07-04 18:41:03.496277934 +0300
@@ -442,6 +442,20 @@
for a keyboard device if it is not currently attached to one.
Otherwise, the driver only probes for a keyboard once during bootup.
.El
+.Ss Loader Tunables
+Tunables can be set at the
+.Xr loader 8
+prompt before booting the kernel or stored in
+.Pa /boot/loader.conf .
+Some of these tunables also have a matching
+.Xr sysctl 8
+entry for access after boot.
+.Bl -tag -width indent
+.It hw.syscons.history_size
+Override the size of back scroll buffer (specified by the
+.Dv SC_HISTORY_SIZE
+option).
+.El
.Sh FILES
.Bl -tag -width /usr/share/syscons/xxxxyyyyzzz -compact
.It Pa /dev/console
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-bugs
mailing list