From owner-svn-src-all@freebsd.org Sat Mar 4 06:19:14 2017 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 36256CF8C1F; Sat, 4 Mar 2017 06:19:14 +0000 (UTC) (envelope-from bde@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id EA0DB1A52; Sat, 4 Mar 2017 06:19:13 +0000 (UTC) (envelope-from bde@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v246JD2n003875; Sat, 4 Mar 2017 06:19:13 GMT (envelope-from bde@FreeBSD.org) Received: (from bde@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v246JCYp003872; Sat, 4 Mar 2017 06:19:12 GMT (envelope-from bde@FreeBSD.org) Message-Id: <201703040619.v246JCYp003872@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: bde set sender to bde@FreeBSD.org using -f From: Bruce Evans Date: Sat, 4 Mar 2017 06:19:12 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r314641 - head/sys/dev/syscons X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 04 Mar 2017 06:19:14 -0000 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 #include #include +#include #include #include #include @@ -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