Module Name: src
Committed By: maxv
Date: Sat May 11 19:31:04 UTC 2019
Modified Files:
src/distrib/sets/lists/etc: mi
src/etc/defaults: rc.conf
src/etc/mtree: special
src/share/man/man5: rc.conf.5
src/usr.sbin/postinstall: postinstall
Added Files:
src/etc/rc.d: smtoff
Log Message:
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.
To generate a diff of this commit:
cvs rdiff -u -r1.257 -r1.258 src/distrib/sets/lists/etc/mi
cvs rdiff -u -r1.147 -r1.148 src/etc/defaults/rc.conf
cvs rdiff -u -r1.166 -r1.167 src/etc/mtree/special
cvs rdiff -u -r0 -r1.1 src/etc/rc.d/smtoff
cvs rdiff -u -r1.179 -r1.180 src/share/man/man5/rc.conf.5
cvs rdiff -u -r1.225 -r1.226 src/usr.sbin/postinstall/postinstall
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/distrib/sets/lists/etc/mi
diff -u src/distrib/sets/lists/etc/mi:1.257 src/distrib/sets/lists/etc/mi:1.258
--- src/distrib/sets/lists/etc/mi:1.257 Thu Apr 25 08:56:21 2019
+++ src/distrib/sets/lists/etc/mi Sat May 11 19:31:03 2019
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.257 2019/04/25 08:56:21 roy Exp $
+# $NetBSD: mi,v 1.258 2019/05/11 19:31:03 maxv Exp $
#
# Note: end-user configuration files that are moved to another location
# should not be marked "obsolete"; they should just be removed from
@@ -299,6 +299,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
Index: src/etc/defaults/rc.conf
diff -u src/etc/defaults/rc.conf:1.147 src/etc/defaults/rc.conf:1.148
--- src/etc/defaults/rc.conf:1.147 Sat Jan 12 17:38:36 2019
+++ src/etc/defaults/rc.conf Sat May 11 19:31:03 2019
@@ -1,4 +1,4 @@
-# $NetBSD: rc.conf,v 1.147 2019/01/12 17:38:36 roy Exp $
+# $NetBSD: rc.conf,v 1.148 2019/05/11 19:31:03 maxv Exp $
#
# /etc/defaults/rc.conf --
# default configuration of /etc/rc.conf
@@ -385,6 +385,9 @@ random_seed=YES
# Creating / updating of man page index on boot
makemandb=YES
+# Disable Simultaneous Multi-Threading
+smtoff=NO
+
# blacklist daemon, needs npf
blacklistd=NO
Index: src/etc/mtree/special
diff -u src/etc/mtree/special:1.166 src/etc/mtree/special:1.167
--- src/etc/mtree/special:1.166 Sat May 4 08:26:51 2019
+++ src/etc/mtree/special Sat May 11 19:31:03 2019
@@ -1,4 +1,4 @@
-# $NetBSD: special,v 1.166 2019/05/04 08:26:51 mrg Exp $
+# $NetBSD: special,v 1.167 2019/05/11 19:31:03 maxv Exp $
# @(#)special 8.2 (Berkeley) 1/23/94
#
# This file may be overwritten on upgrades.
@@ -286,6 +286,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
Index: src/share/man/man5/rc.conf.5
diff -u src/share/man/man5/rc.conf.5:1.179 src/share/man/man5/rc.conf.5:1.180
--- src/share/man/man5/rc.conf.5:1.179 Sat Oct 20 08:47:03 2018
+++ src/share/man/man5/rc.conf.5 Sat May 11 19:31:03 2019
@@ -1,4 +1,4 @@
-.\" $NetBSD: rc.conf.5,v 1.179 2018/10/20 08:47:03 wiz Exp $
+.\" $NetBSD: rc.conf.5,v 1.180 2019/05/11 19:31:03 maxv 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 October 19, 2018
+.Dd May 11, 2019
.Dt RC.CONF 5
.Os
.Sh NAME
@@ -673,6 +673,9 @@ A string.
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
Index: src/usr.sbin/postinstall/postinstall
diff -u src/usr.sbin/postinstall/postinstall:1.225 src/usr.sbin/postinstall/postinstall:1.226
--- src/usr.sbin/postinstall/postinstall:1.225 Thu Apr 11 14:45:58 2019
+++ src/usr.sbin/postinstall/postinstall Sat May 11 19:31:03 2019
@@ -1,6 +1,6 @@
#!/bin/sh
#
-# $NetBSD: postinstall,v 1.225 2019/04/11 14:45:58 martin Exp $
+# $NetBSD: postinstall,v 1.226 2019/05/11 19:31:03 maxv Exp $
#
# Copyright (c) 2002-2015 The NetBSD Foundation, Inc.
# All rights reserved.
@@ -1473,6 +1473,7 @@ rwho
savecore
screenblank
securelevel
+smtoff
sshd
staticroute
swap1
Added files:
Index: src/etc/rc.d/smtoff
diff -u /dev/null src/etc/rc.d/smtoff:1.1
--- /dev/null Sat May 11 19:31:04 2019
+++ src/etc/rc.d/smtoff Sat May 11 19:31:03 2019
@@ -0,0 +1,101 @@
+#!/bin/sh
+#
+# $NetBSD: smtoff,v 1.1 2019/05/11 19:31:03 maxv 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() {
+ smtid=$(cpuctl identify $1 | grep "SMT ID" | cut -d " " -f 4)
+ case $smtid in
+ [0-9]*)
+ echo "$smtid" ;;
+ *)
+ echo "error" ;;
+ esac
+}
+
+#
+# The format of the output is:
+#
+# hw.ncpu = 80
+#
+# Return the value.
+#
+CountCPUs() {
+ ncpus=$(sysctl hw.ncpu | cut -d " " -f 3)
+ echo "$ncpus"
+}
+
+# ------------------------------------------------------------------------------
+
+#
+# Disable SMT. We skip cpu0.
+#
+smtoff_start()
+{
+ ncpus=$(CountCPUs)
+ i=1
+
+ while [ $i -lt $ncpus ]
+ do
+ smtid=$(GetSmtId "$i")
+
+ # Didn't get the ID? Then maybe no SMT.
+ if [ "$smtid" = "error" ]; then
+ i=$(($i+1))
+ continue
+ fi
+
+ # The first thread is never disabled.
+ if [ $smtid -eq 0 ]; then
+ i=$(($i+1))
+ continue
+ fi
+
+ cmd="cpuctl offline $i"
+ $cmd
+ i=$(($i+1))
+ done
+}
+
+#
+# Enable SMT. We basically turn on each CPU.
+#
+smtoff_stop()
+{
+ ncpus=$(CountCPUs)
+ i=1
+
+ while [ $i -lt $ncpus ]
+ do
+ cmd="cpuctl online $i"
+ $cmd
+ i=$(($i+1))
+ done
+}
+
+load_rc_config $name
+run_rc_command "$1"