Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 4 Mar 2017 06:19:12 +0000 (UTC)
From:      Bruce Evans <bde@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r314641 - head/sys/dev/syscons
Message-ID:  <201703040619.v246JCYp003872@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: bde
Date: Sat Mar  4 06:19:12 2017
New Revision: 314641
URL: https://svnweb.freebsd.org/changeset/base/314641

Log:
  Colorize syscons kernel console output according to a table indexed
  by the CPU number.
  
  This was originally for debugging near-deadlock conditions where
  multiple CPUs either deadlock or scramble each other's output trying
  to report the problem, but I found it interesting and sometimes
  useful for ordinary kernel messages.  Ordinary kernel messages
  shouldn't be interleaved, but if they are then the colorization
  makes them readable even if the interleaving is for every character
  (provided the CPU printing each message doesn't change).
  
  The default colors are 8-15 starting at 15 (bright white on black)
  for CPU 0 and repeating every 8 CPUs.  This works best with 8 CPUs.
  Non-bright colors and nonzero background colors need special
  configuration to avoid unreadable and ugly combinations so are not
  configured by default.  The next bright color after 15 is 8 (bright
  black = dark gray) is not very readable but is the only other color
  used with 2 CPUs.  After that the next bright color is 9 (bright
  blue) which is not much brighter than bright black, but is used with
  3+ CPUs.  Other bright colors are brighter.
  
  Colorization is configured by default so that it gets tested.  It can
  only be turned off by configuring SC_KERNEL_CONS_ATTR to anything other
  than FG_WHITE.  After booting, all colors can be changed using the
  syscons.kattr sysctl.  This is a SYSCTL_OPAQUE, and no utility is
  provided to change it (sysctl only displays it).
  
  The default colors work in all VGA modes that I could test.  In 2-color
  graphics modes, all 8 bright colors are displayed as bright white, so
  the colorization has no effect, but anything with a nonzero background
  gives white on white unless the foreground is zero.  I don't have an
  mono or VGA grayscale hardware to test on.  Support for mono mode seems
  to have never worked right in syscons (I think bright white gives white
  underline with either bold or bright), but VGA grayscale should work
  better than 2-color graphics.

Modified:
  head/sys/dev/syscons/scterm-teken.c
  head/sys/dev/syscons/syscons.c
  head/sys/dev/syscons/syscons.h

Modified: head/sys/dev/syscons/scterm-teken.c
==============================================================================
--- head/sys/dev/syscons/scterm-teken.c	Sat Mar  4 04:06:33 2017	(r314640)
+++ head/sys/dev/syscons/scterm-teken.c	Sat Mar  4 06:19:12 2017	(r314641)
@@ -176,7 +176,7 @@ scteken_puts(scr_stat *scp, u_char *buf,
 	if (kernel) {
 		/* Use special colors for kernel messages. */
 		backup = *teken_get_curattr(&ts->ts_teken);
-		scteken_revattr(SC_KERNEL_CONS_ATTR, &kattr);
+		scteken_revattr(sc_kattr(), &kattr);
 		teken_set_curattr(&ts->ts_teken, &kattr);
 		teken_input(&ts->ts_teken, buf, len);
 		teken_set_curattr(&ts->ts_teken, &backup);

Modified: head/sys/dev/syscons/syscons.c
==============================================================================
--- head/sys/dev/syscons/syscons.c	Sat Mar  4 04:06:33 2017	(r314640)
+++ head/sys/dev/syscons/syscons.c	Sat Mar  4 06:19:12 2017	(r314641)
@@ -51,6 +51,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/lock.h>
 #include <sys/malloc.h>
 #include <sys/mutex.h>
+#include <sys/pcpu.h>
 #include <sys/priv.h>
 #include <sys/proc.h>
 #include <sys/random.h>
@@ -100,6 +101,8 @@ static default_attr user_default = {
     SC_NORM_REV_ATTR,
 };
 
+static	u_char		sc_kattrtab[MAXCPU];
+
 static	int		sc_console_unit = -1;
 static	int		sc_saver_keyb_only = 1;
 static  scr_stat    	*sc_console;
@@ -141,6 +144,8 @@ static	int		sc_no_suspend_vtswitch = 0;
 static	int		sc_susp_scr;
 
 static SYSCTL_NODE(_hw, OID_AUTO, syscons, CTLFLAG_RD, 0, "syscons");
+SYSCTL_OPAQUE(_hw_syscons, OID_AUTO, kattr, CTLFLAG_RW,
+    &sc_kattrtab, sizeof(sc_kattrtab), "CU", "kernel console attributes");
 static SYSCTL_NODE(_hw_syscons, OID_AUTO, saver, CTLFLAG_RD, 0, "saver");
 SYSCTL_INT(_hw_syscons_saver, OID_AUTO, keybonly, CTLFLAG_RW,
     &sc_saver_keyb_only, 0, "screen saver interrupted by input only");
@@ -2994,8 +2999,16 @@ scinit(int unit, int flags)
     int i;
 
     /* one time initialization */
-    if (init_done == COLD)
+    if (init_done == COLD) {
 	sc_get_bios_values(&bios_value);
+	for (i = 0; i < nitems(sc_kattrtab); i++) {
+#if SC_KERNEL_CONS_ATTR == FG_WHITE
+	    sc_kattrtab[i] = 8 + (i + FG_WHITE) % 8U;
+#else
+	    sc_kattrtab[i] = SC_KERNEL_CONS_ATTR;
+#endif
+	}
+    }
     init_done = WARM;
 
     /*
@@ -4008,6 +4021,12 @@ sc_bell(scr_stat *scp, int pitch, int du
     }
 }
 
+int
+sc_kattr(void)
+{
+    return (sc_kattrtab[PCPU_GET(cpuid) % nitems(sc_kattrtab)]);
+}
+
 static void
 blink_screen(void *arg)
 {

Modified: head/sys/dev/syscons/syscons.h
==============================================================================
--- head/sys/dev/syscons/syscons.h	Sat Mar  4 04:06:33 2017	(r314640)
+++ head/sys/dev/syscons/syscons.h	Sat Mar  4 06:19:12 2017	(r314641)
@@ -581,6 +581,7 @@ void		sc_paste(scr_stat *scp, const u_ch
 void		sc_respond(scr_stat *scp, const u_char *p,
 			   int count, int wakeup);
 void		sc_bell(scr_stat *scp, int pitch, int duration);
+int		sc_kattr(void);
 
 /* schistory.c */
 #ifndef SC_NO_HISTORY



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201703040619.v246JCYp003872>