aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlistair Delva <adelva@google.com>2021-03-02 00:12:23 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2021-03-02 00:12:23 +0000
commite07d35590c95154c9b702fe01f097534ef0dae3b (patch)
tree8e3c0b12af3dba793b45072b470074127bff80d4
parent90b4e926efb3251bc307a9bd0345328ddd4e6910 (diff)
parent5b0cf33d7fbb7e7bdedb3e41fa06784174f2a00d (diff)
downloadcuttlefish-e07d35590c95154c9b702fe01f097534ef0dae3b.tar.gz
Add SMT flag and disable by default am: 5b0cf33d7f
Original change: https://android-review.googlesource.com/c/device/google/cuttlefish/+/1612003 MUST ONLY BE SUBMITTED BY AUTOMERGER Change-Id: I6e5930f90cead377fe300d52168ed083e2ff59b6
-rw-r--r--host/commands/assemble_cvd/flags.cc7
-rw-r--r--host/libs/config/cuttlefish_config.cpp9
-rw-r--r--host/libs/config/cuttlefish_config.h3
-rw-r--r--host/libs/vm_manager/crosvm_manager.cpp4
-rw-r--r--host/libs/vm_manager/qemu_manager.cpp13
5 files changed, 34 insertions, 2 deletions
diff --git a/host/commands/assemble_cvd/flags.cc b/host/commands/assemble_cvd/flags.cc
index 72fc86a46..1705c51cf 100644
--- a/host/commands/assemble_cvd/flags.cc
+++ b/host/commands/assemble_cvd/flags.cc
@@ -270,6 +270,8 @@ DEFINE_bool(record_screen, false, "Enable screen recording. "
DEFINE_bool(ethernet, false, "Enable Ethernet network interface");
+DEFINE_bool(smt, false, "Enable simultaneous multithreading (SMT/HT)");
+
DEFINE_int32(vsock_guest_cid,
cuttlefish::GetDefaultVsockCid(),
"vsock_guest_cid is used to determine the guest vsock cid as well as all the ports"
@@ -401,7 +403,11 @@ CuttlefishConfig InitializeCuttlefishConfiguration(
" does not work with vm_manager=" << FLAGS_vm_manager;
}
+ CHECK(!FLAGS_smt || FLAGS_cpus % 2 == 0)
+ << "CPUs must be a multiple of 2 in SMT mode";
tmp_config_obj.set_cpus(FLAGS_cpus);
+ tmp_config_obj.set_smt(FLAGS_smt);
+
tmp_config_obj.set_memory_mb(FLAGS_memory_mb);
tmp_config_obj.set_setupwizard_mode(FLAGS_setupwizard_mode);
@@ -591,6 +597,7 @@ CuttlefishConfig InitializeCuttlefishConfiguration(
tmp_config_obj.set_enable_minimal_mode(FLAGS_enable_minimal_mode);
tmp_config_obj.set_vhost_net(FLAGS_vhost_net);
+
tmp_config_obj.set_record_screen(FLAGS_record_screen);
tmp_config_obj.set_ethernet(FLAGS_ethernet);
diff --git a/host/libs/config/cuttlefish_config.cpp b/host/libs/config/cuttlefish_config.cpp
index 52bd4fcb0..7eabb8fc5 100644
--- a/host/libs/config/cuttlefish_config.cpp
+++ b/host/libs/config/cuttlefish_config.cpp
@@ -175,6 +175,8 @@ const char* kRecordScreen = "record_screen";
const char* kEthernet = "ethernet";
+const char* kSmt = "smt";
+
} // namespace
const char* const kGpuModeAuto = "auto";
@@ -872,6 +874,13 @@ bool CuttlefishConfig::record_screen() const {
return (*dictionary_)[kRecordScreen].asBool();
}
+void CuttlefishConfig::set_smt(bool smt) {
+ (*dictionary_)[kSmt] = smt;
+}
+bool CuttlefishConfig::smt() const {
+ return (*dictionary_)[kSmt].asBool();
+}
+
// Creates the (initially empty) config object and populates it with values from
// the config file if the CUTTLEFISH_CONFIG_FILE env variable is present.
// Returns nullptr if there was an error loading from file
diff --git a/host/libs/config/cuttlefish_config.h b/host/libs/config/cuttlefish_config.h
index 2a09b53b3..42b366bac 100644
--- a/host/libs/config/cuttlefish_config.h
+++ b/host/libs/config/cuttlefish_config.h
@@ -341,6 +341,9 @@ class CuttlefishConfig {
void set_record_screen(bool record_screen);
bool record_screen() const;
+ void set_smt(bool smt);
+ bool smt() const;
+
class InstanceSpecific;
class MutableInstanceSpecific;
diff --git a/host/libs/vm_manager/crosvm_manager.cpp b/host/libs/vm_manager/crosvm_manager.cpp
index 95bb5b198..77c49bc25 100644
--- a/host/libs/vm_manager/crosvm_manager.cpp
+++ b/host/libs/vm_manager/crosvm_manager.cpp
@@ -160,6 +160,10 @@ std::vector<Command> CrosvmManager::StartCommands(
});
crosvm_cmd.AddParameter("run");
+ if (!config.smt()) {
+ crosvm_cmd.AddParameter("--no-smt");
+ }
+
if (config.vhost_net()) {
crosvm_cmd.AddParameter("--vhost-net");
}
diff --git a/host/libs/vm_manager/qemu_manager.cpp b/host/libs/vm_manager/qemu_manager.cpp
index 376562c2d..db2a7a63b 100644
--- a/host/libs/vm_manager/qemu_manager.cpp
+++ b/host/libs/vm_manager/qemu_manager.cpp
@@ -175,9 +175,18 @@ std::vector<Command> QemuManager::StartCommands(
qemu_cmd.AddParameter("-overcommit");
qemu_cmd.AddParameter("mem-lock=off");
+ // Assume SMT is always 2 threads per core, which is how most hardware
+ // today is configured, and the way crosvm does it
qemu_cmd.AddParameter("-smp");
- qemu_cmd.AddParameter(config.cpus(), ",sockets=", config.cpus(),
- ",cores=1,threads=1");
+ if (config.smt()) {
+ CHECK(config.cpus() % 2 == 0)
+ << "CPUs must be a multiple of 2 in SMT mode";
+ qemu_cmd.AddParameter(config.cpus(), ",cores=",
+ config.cpus() / 2, ",threads=2");
+ } else {
+ qemu_cmd.AddParameter(config.cpus(), ",cores=",
+ config.cpus(), ",threads=1");
+ }
qemu_cmd.AddParameter("-uuid");
qemu_cmd.AddParameter(instance.uuid());