Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Add smtoff, an rc.d script that disables Simultaneous Multi-...
details: https://anonhg.NetBSD.org/src/rev/ebc4159f602c
branches: trunk
changeset: 451249:ebc4159f602c
user: maxv <maxv%NetBSD.org@localhost>
date: Sat May 11 19:31:03 2019 +0000
description:
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.
diffstat:
distrib/sets/lists/etc/mi | 3 +-
etc/defaults/rc.conf | 5 +-
etc/mtree/special | 3 +-
etc/rc.d/smtoff | 101 +++++++++++++++++++++++++++++++++++++++
share/man/man5/rc.conf.5 | 7 +-
usr.sbin/postinstall/postinstall | 3 +-
6 files changed, 116 insertions(+), 6 deletions(-)
diffs (205 lines):
diff -r f2d9d95e86c5 -r ebc4159f602c distrib/sets/lists/etc/mi
--- a/distrib/sets/lists/etc/mi Sat May 11 17:44:16 2019 +0000
+++ b/distrib/sets/lists/etc/mi Sat May 11 19:31:03 2019 +0000
@@ -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
diff -r f2d9d95e86c5 -r ebc4159f602c etc/defaults/rc.conf
--- a/etc/defaults/rc.conf Sat May 11 17:44:16 2019 +0000
+++ b/etc/defaults/rc.conf Sat May 11 19:31:03 2019 +0000
@@ -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 @@
# Creating / updating of man page index on boot
makemandb=YES
+# Disable Simultaneous Multi-Threading
+smtoff=NO
+
# blacklist daemon, needs npf
blacklistd=NO
diff -r f2d9d95e86c5 -r ebc4159f602c etc/mtree/special
--- a/etc/mtree/special Sat May 11 17:44:16 2019 +0000
+++ b/etc/mtree/special Sat May 11 19:31:03 2019 +0000
@@ -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
diff -r f2d9d95e86c5 -r ebc4159f602c etc/rc.d/smtoff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/etc/rc.d/smtoff Sat May 11 19:31:03 2019 +0000
@@ -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"
diff -r f2d9d95e86c5 -r ebc4159f602c share/man/man5/rc.conf.5
--- a/share/man/man5/rc.conf.5 Sat May 11 17:44:16 2019 +0000
+++ b/share/man/man5/rc.conf.5 Sat May 11 19:31:03 2019 +0000
@@ -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 @@
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 f2d9d95e86c5 -r ebc4159f602c usr.sbin/postinstall/postinstall
--- a/usr.sbin/postinstall/postinstall Sat May 11 17:44:16 2019 +0000
+++ b/usr.sbin/postinstall/postinstall Sat May 11 19:31:03 2019 +0000
@@ -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 @@
savecore
screenblank
securelevel
+smtoff
sshd
staticroute
swap1
Home |
Main Index |
Thread Index |
Old Index