Source-Changes-HG archive

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

[src/netbsd-8]: src Pull up following revision(s) (requested by maxv in ticke...



details:   https://anonhg.NetBSD.org/src/rev/61ca42b1701a
branches:  netbsd-8
changeset: 451292:61ca42b1701a
user:      martin <martin%NetBSD.org@localhost>
date:      Tue May 14 11:33:42 2019 +0000

description:
Pull up following revision(s) (requested by maxv in ticket #1265):
        etc/rc.d/smtoff: revision 1.1
        etc/rc.d/smtoff: revision 1.2
        distrib/sets/lists/etc/mi: revision 1.258
        etc/rc.d/smtoff: revision 1.3
        etc/rc.d/smtoff: revision 1.4
        etc/defaults/rc.conf: revision 1.148
        etc/rc.d/Makefile: revision 1.103
        usr.sbin/postinstall/postinstall: revision 1.226
        etc/rc.d/Makefile: revision 1.104
        etc/mtree/special: revision 1.167
        share/man/man5/rc.conf.5: revision 1.180

Add smtoff, an rc.d script that disables Simultaneous Multi-Threading. It
parses the output of cpuctl, and executes "cpuctl offline" for each CPU
that has SmtID!=0.

The default is "smtoff=NO", which means that SMT remains enabled.
Restructure code a little.

Use quoting everywhere possibly useful (always the right way, except
in the few cases where it is wrong...)

Avoid using cut & grep (from /usr/bin) so script could run before /usr
is mounted (pity cpuctl is in /usr/sbin ...).

Use sysctl -n rather than attempting to parse its output.
install rc.d

No change...   Previous log message should have said:
  Install rc.d/smtoff

I should know better!   Don't rely upon the way the shell implements
pipes.   Skip the "error" printf from GetSmtId() as there is no easy
portable way to avoid it occurring (there are complicated ways) - but
we don't need it, there is no logical difference between "error" and ""
so just use the latter (if we get an ID, good, if there is nothing, then
there is none - saying 'error' does not mean anything.)

Remove comment, since there is no parsing anymore.

diffstat:

 distrib/sets/lists/etc/mi        |   3 +-
 etc/defaults/rc.conf             |   5 +-
 etc/mtree/special                |   3 +-
 etc/rc.d/Makefile                |   4 +-
 etc/rc.d/smtoff                  |  99 ++++++++++++++++++++++++++++++++++++++++
 share/man/man5/rc.conf.5         |   7 ++-
 usr.sbin/postinstall/postinstall |   3 +-
 7 files changed, 116 insertions(+), 8 deletions(-)

diffs (221 lines):

diff -r b1ce5802acf3 -r 61ca42b1701a distrib/sets/lists/etc/mi
--- a/distrib/sets/lists/etc/mi Tue May 14 11:24:33 2019 +0000
+++ b/distrib/sets/lists/etc/mi Tue May 14 11:33:42 2019 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.247 2017/05/21 15:28:38 riastradh Exp $
+# $NetBSD: mi,v 1.247.2.1 2019/05/14 11:33:42 martin Exp $
 #
 # Note: end-user configuration files that are moved to another location
 #      should not be marked "obsolete"; they should just be removed from
@@ -283,6 +283,7 @@
 ./etc/rc.d/screenblank                         etc-sys-rc
 ./etc/rc.d/sdpd                                        etc-obsolete            obsolete
 ./etc/rc.d/securelevel                         etc-sys-rc
+./etc/rc.d/smtoff                              etc-sys-rc
 ./etc/rc.d/sshd                                        etc-secsh-rc
 ./etc/rc.d/staticroute                         etc-sys-rc
 ./etc/rc.d/swap1                               etc-sys-rc
diff -r b1ce5802acf3 -r 61ca42b1701a etc/defaults/rc.conf
--- a/etc/defaults/rc.conf      Tue May 14 11:24:33 2019 +0000
+++ b/etc/defaults/rc.conf      Tue May 14 11:33:42 2019 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: rc.conf,v 1.139 2017/01/07 20:00:33 christos Exp $
+#      $NetBSD: rc.conf,v 1.139.6.1 2019/05/14 11:33:42 martin Exp $
 #
 # /etc/defaults/rc.conf --
 #      default configuration of /etc/rc.conf
@@ -380,6 +380,9 @@
 # Creating / updating of man page index on boot
 makemandb=YES
 
+# Disable Simultaneous Multi-Threading
+smtoff=NO
+
 # blacklist daemon, needs npf
 blacklistd=NO
 
diff -r b1ce5802acf3 -r 61ca42b1701a etc/mtree/special
--- a/etc/mtree/special Tue May 14 11:24:33 2019 +0000
+++ b/etc/mtree/special Tue May 14 11:33:42 2019 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: special,v 1.160 2017/02/20 13:45:43 christos Exp $
+#      $NetBSD: special,v 1.160.4.1 2019/05/14 11:33:43 martin Exp $
 #      @(#)special     8.2 (Berkeley) 1/23/94
 #
 # This file may be overwritten on upgrades.
@@ -281,6 +281,7 @@
 ./etc/rc.d/savecore            type=file mode=0555
 ./etc/rc.d/screenblank         type=file mode=0555
 ./etc/rc.d/securelevel         type=file mode=0555
+./etc/rc.d/smtoff              type=file mode=0555
 ./etc/rc.d/sshd                        type=file mode=0555
 ./etc/rc.d/staticroute         type=file mode=0555
 ./etc/rc.d/swap1               type=file mode=0555
diff -r b1ce5802acf3 -r 61ca42b1701a etc/rc.d/Makefile
--- a/etc/rc.d/Makefile Tue May 14 11:24:33 2019 +0000
+++ b/etc/rc.d/Makefile Tue May 14 11:33:42 2019 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.95 2017/01/05 14:39:09 christos Exp $
+# $NetBSD: Makefile,v 1.95.6.1 2019/05/14 11:33:42 martin Exp $
 
 .include <bsd.own.mk>
 
@@ -35,7 +35,7 @@
                racoon rpcbind raidframe raidframeparity random_seed rarpd \
                rbootd resize_root rndctl root route6d routed rtadvd \
                rtclocaltime rwho \
-               savecore screenblank securelevel sshd \
+               savecore screenblank securelevel smtoff sshd \
                staticroute swap1 swap2 sysctl sysdb syslogd \
                timed tpctl ttys \
                veriexec virecover wdogctl wpa_supplicant wscons wsmoused \
diff -r b1ce5802acf3 -r 61ca42b1701a etc/rc.d/smtoff
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/etc/rc.d/smtoff   Tue May 14 11:33:42 2019 +0000
@@ -0,0 +1,99 @@
+#!/bin/sh
+#
+# $NetBSD: smtoff,v 1.4.2.2 2019/05/14 11:33:42 martin Exp $
+#
+# Public Domain.
+#
+
+# PROVIDE: smtoff
+# REQUIRE: root bootconf mountcritlocal tty
+
+$_rc_subr_loaded . /etc/rc.subr
+
+name="smtoff"
+rcvar=$name
+
+start_cmd="smtoff_start"
+stop_cmd="smtoff_stop"
+
+# ------------------------------------------------------------------------------
+
+#
+# The format of the output is:
+#
+#     ...
+#     cpu0: SMT ID 1
+#     ...
+#
+# Return the value.
+#
+GetSmtId() {
+       cpuctl identify "$1" |
+       while read cpuN smt id N junk
+       do
+               test -n "$junk" && continue
+
+               case "${smt} ${id}" in
+               'SMT ID')
+                       case "$N" in
+                       [0-9]|[1-9][0-9]|[1-9][0-9]*[0-9])
+                               printf %s "$N"
+                               return
+                               ;;
+                       esac
+                       ;;
+               esac
+       done
+}
+
+CountCPUs() {
+       sysctl -n hw.ncpu
+}
+
+# ------------------------------------------------------------------------------
+
+#
+# Disable SMT. We skip cpu0.
+#
+smtoff_start()
+{
+       ncpus=$(CountCPUs)
+       i=1
+
+       while [ "$i" -lt "$ncpus" ]
+       do
+               smtid=$(GetSmtId "$i" 2>/dev/null)
+
+               case "$smtid" in
+               '')                     # Didn't get the ID? Then maybe no SMT.
+                       ;;
+
+               0)                      # The first thread is never disabled.
+                       ;;
+
+               *)
+                       cpuctl offline "$i"
+                       ;;
+               esac
+
+               i=$(($i+1))
+       done
+}
+
+#
+# Enable SMT. We basically turn on each CPU.
+#
+smtoff_stop()
+{
+       ncpus=$(CountCPUs)
+       i=1
+
+       while [ "$i" -lt "$ncpus" ]
+       do
+               cpuctl online "$i"
+               i=$(($i+1))
+       done
+}
+
+load_rc_config $name
+run_rc_command "$1"
diff -r b1ce5802acf3 -r 61ca42b1701a share/man/man5/rc.conf.5
--- a/share/man/man5/rc.conf.5  Tue May 14 11:24:33 2019 +0000
+++ b/share/man/man5/rc.conf.5  Tue May 14 11:33:42 2019 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: rc.conf.5,v 1.166 2016/12/17 07:44:59 maya Exp $
+.\"    $NetBSD: rc.conf.5,v 1.166.6.1 2019/05/14 11:33:43 martin Exp $
 .\"
 .\" Copyright (c) 1996 Matthew R. Green
 .\" All rights reserved.
@@ -55,7 +55,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd December 17, 2016
+.Dd May 14, 2019
 .Dt RC.CONF 5
 .Os
 .Sh NAME
@@ -621,6 +621,9 @@
 Flags to pass to the
 .Nm veriexecctl
 command.
+.It Sy smtoff
+Boolean value.
+Disables SMT (Simultaneous Multi-Threading).
 .El
 .Ss Networking startup
 .Bl -tag -width net_interfaces
diff -r b1ce5802acf3 -r 61ca42b1701a usr.sbin/postinstall/postinstall
--- a/usr.sbin/postinstall/postinstall  Tue May 14 11:24:33 2019 +0000
+++ b/usr.sbin/postinstall/postinstall  Tue May 14 11:33:42 2019 +0000
@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# $NetBSD: postinstall,v 1.214.4.1 2017/07/10 13:06:45 martin Exp $
+# $NetBSD: postinstall,v 1.214.4.2 2019/05/14 11:33:43 martin Exp $
 #
 # Copyright (c) 2002-2015 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -1457,6 +1457,7 @@
 savecore
 screenblank
 securelevel
+smtoff
 sshd
 staticroute
 swap1



Home | Main Index | Thread Index | Old Index