Skip to content

Commit 3d5fa81

Browse files
chihchiachenDatabean
authored andcommitted
Launch one vhal_proxy_server for each instance
In case of CF multi-tenancy, switch from shared VHAL server for all instances to independent VHAL server for each instance. Bug: b/440435240
1 parent ac9e5a9 commit 3d5fa81

File tree

9 files changed

+31
-55
lines changed

9 files changed

+31
-55
lines changed

base/cvd/cuttlefish/host/commands/assemble_cvd/assemble_cvd_flags.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,6 @@ DEFINE_bool(enable_automotive_proxy, CF_DEFAULTS_ENABLE_AUTOMOTIVE_PROXY,
166166
DEFINE_vec(enable_vhal_proxy_server,
167167
fmt::format("{}", CF_DEFAULTS_ENABLE_VHAL_PROXY_SERVER),
168168
"Enable the vhal proxy service on the host.");
169-
DEFINE_int32(vhal_proxy_server_instance_num,
170-
CF_DEFAULTS_VHAL_PROXY_SERVER_INSTANCE_NUM,
171-
"If it is greater than 0, use an existing vhal proxy server "
172-
"instance which is "
173-
"launched from cuttlefish instance "
174-
"with vhal_proxy_server_instance_num. Else, launch a new vhal "
175-
"proxy server instance");
176169

177170
/**
178171
* crosvm sandbox feature requires /var/empty and seccomp directory

base/cvd/cuttlefish/host/commands/assemble_cvd/bootconfig_args.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,9 @@ Result<std::unordered_map<std::string, std::string>> BootconfigArgsFromConfig(
228228
? "com.android.hardware.graphics.composer.drm_hwcomposer"
229229
: "com.android.hardware.graphics.composer.ranchu";
230230

231-
if (config.vhal_proxy_server_port()) {
231+
if (instance.vhal_proxy_server_port()) {
232232
bootconfig_args["androidboot.vhal_proxy_server_port"] =
233-
std::to_string(config.vhal_proxy_server_port());
233+
std::to_string(instance.vhal_proxy_server_port());
234234
int32_t instance_id;
235235
CF_EXPECT(android::base::ParseInt(instance.id(), &instance_id),
236236
"instance id: " << instance.id() << " is not a valid int");

base/cvd/cuttlefish/host/commands/assemble_cvd/flags.cc

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,9 @@ Result<CuttlefishConfig> InitializeCuttlefishConfiguration(
460460

461461
tmp_config_obj.set_enable_automotive_proxy(FLAGS_enable_automotive_proxy);
462462

463+
std::vector<bool> enable_vhal_proxy_server_vec =
464+
CF_EXPECT(GET_FLAG_BOOL_VALUE(enable_vhal_proxy_server));
465+
463466
std::vector<std::string> gnss_file_paths =
464467
CF_EXPECT(GET_FLAG_STR_VALUE(gnss_file_path));
465468
std::vector<std::string> fixed_location_file_paths =
@@ -677,22 +680,6 @@ Result<CuttlefishConfig> InitializeCuttlefishConfiguration(
677680
std::set<std::string> straced_set(straced.begin(), straced.end());
678681
tmp_config_obj.set_straced_host_executables(straced_set);
679682

680-
auto vhal_proxy_server_instance_num = *instance_nums.begin() - 1;
681-
if (FLAGS_vhal_proxy_server_instance_num > 0) {
682-
vhal_proxy_server_instance_num = FLAGS_vhal_proxy_server_instance_num - 1;
683-
}
684-
tmp_config_obj.set_vhal_proxy_server_port(
685-
cuttlefish::vhal_proxy_server::kDefaultEthPort +
686-
vhal_proxy_server_instance_num);
687-
std::vector<bool> enable_vhal_proxy_server_vec =
688-
CF_EXPECT(GET_FLAG_BOOL_VALUE(enable_vhal_proxy_server));
689-
bool enable_vhal_proxy_server =
690-
std::any_of(enable_vhal_proxy_server_vec.begin(),
691-
enable_vhal_proxy_server_vec.end(), [](bool e) { return e; });
692-
LOG(DEBUG) << "launch vhal proxy server: "
693-
<< (enable_vhal_proxy_server &&
694-
vhal_proxy_server_instance_num <= 0);
695-
696683
tmp_config_obj.set_kvm_path(FLAGS_kvm_path);
697684
tmp_config_obj.set_vhost_vsock_path(FLAGS_vhost_vsock_path);
698685

@@ -1043,6 +1030,11 @@ Result<CuttlefishConfig> InitializeCuttlefishConfiguration(
10431030
instance.set_adb_ip_and_port("0.0.0.0:" + std::to_string(6520 + num - 1));
10441031
instance.set_fastboot_host_port(const_instance.adb_host_port());
10451032

1033+
instance.set_enable_vhal_proxy_server(
1034+
enable_vhal_proxy_server_vec[instance_index]);
1035+
instance.set_vhal_proxy_server_port(
1036+
cuttlefish::vhal_proxy_server::kDefaultEthPort + num - 1);
1037+
10461038
std::uint8_t ethernet_mac[6] = {};
10471039
std::uint8_t mobile_mac[6] = {};
10481040
std::uint8_t wifi_mac[6] = {};
@@ -1226,9 +1218,6 @@ Result<CuttlefishConfig> InitializeCuttlefishConfiguration(
12261218

12271219
instance.set_start_pica(is_first_instance && any_not_netsim_uwb &&
12281220
FLAGS_pica_instance_num <= 0);
1229-
instance.set_start_vhal_proxy_server(
1230-
is_first_instance && enable_vhal_proxy_server &&
1231-
FLAGS_vhal_proxy_server_instance_num <= 0);
12321221

12331222
// TODO(b/288987294) Remove this when separating environment is done
12341223
bool instance_start_wmediumd = is_first_instance && start_wmediumd;

base/cvd/cuttlefish/host/commands/assemble_cvd/flags_defaults.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,6 @@
193193

194194
// Vhal Proxy Server default parameter
195195
#define CF_DEFAULTS_ENABLE_VHAL_PROXY_SERVER false
196-
#define CF_DEFAULTS_VHAL_PROXY_SERVER_INSTANCE_NUM 0
197196

198197
// Bluetooth default parameters
199198
#define CF_DEFAULTS_ENABLE_HOST_BLUETOOTH true

base/cvd/cuttlefish/host/commands/run_cvd/launch/vhal_proxy_server.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,11 @@
3232
namespace cuttlefish {
3333

3434
std::optional<MonitorCommand> VhalProxyServer(
35-
const CuttlefishConfig& config,
3635
const CuttlefishConfig::InstanceSpecific& instance) {
37-
if (!instance.start_vhal_proxy_server()) {
36+
if (!instance.enable_vhal_proxy_server()) {
3837
return {};
3938
}
40-
int port = config.vhal_proxy_server_port();
39+
int port = instance.vhal_proxy_server_port();
4140
Command command = Command(VhalProxyServerBinary())
4241
.AddParameter(VhalProxyServerConfig())
4342
.AddParameter(fmt::format(

base/cvd/cuttlefish/host/commands/run_cvd/launch/vhal_proxy_server.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
namespace cuttlefish {
2222

2323
std::optional<MonitorCommand> VhalProxyServer(
24-
const CuttlefishConfig& config,
2524
const CuttlefishConfig::InstanceSpecific& instance);
2625

2726
} // namespace cuttlefish

base/cvd/cuttlefish/host/libs/config/cuttlefish_config.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -213,14 +213,6 @@ bool CuttlefishConfig::enable_automotive_proxy() const {
213213
return (*dictionary_)[kEnableAutomotiveProxy].asBool();
214214
}
215215

216-
static constexpr char kVhalProxyServerPort[] = "vhal_proxy_server_port";
217-
void CuttlefishConfig::set_vhal_proxy_server_port(int port) {
218-
(*dictionary_)[kVhalProxyServerPort] = port;
219-
}
220-
int CuttlefishConfig::vhal_proxy_server_port() const {
221-
return (*dictionary_)[kVhalProxyServerPort].asInt();
222-
}
223-
224216
static constexpr char kEnableHostNfc[] = "enable_host_nfc";
225217
void CuttlefishConfig::set_enable_host_nfc(bool enable_host_nfc) {
226218
(*dictionary_)[kEnableHostNfc] = enable_host_nfc;

base/cvd/cuttlefish/host/libs/config/cuttlefish_config.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,6 @@ class CuttlefishConfig {
125125
void set_enable_automotive_proxy(bool enable_automotive_proxy);
126126
bool enable_automotive_proxy() const;
127127

128-
// The vsock port used by vhal_proxy_server
129-
void set_vhal_proxy_server_port(int port);
130-
int vhal_proxy_server_port() const;
131-
132128
void set_enable_host_nfc(bool enable_host_nfc);
133129
bool enable_host_nfc() const;
134130

@@ -624,7 +620,8 @@ class CuttlefishConfig {
624620
std::string filename_encryption_mode() const;
625621
ExternalNetworkMode external_network_mode() const;
626622

627-
bool start_vhal_proxy_server() const;
623+
bool enable_vhal_proxy_server() const;
624+
int vhal_proxy_server_port() const;
628625

629626
int audio_output_streams_count() const;
630627

@@ -852,9 +849,8 @@ class CuttlefishConfig {
852849
void set_filename_encryption_mode(const std::string& filename_encryption_mode);
853850
void set_external_network_mode(ExternalNetworkMode network_mode);
854851

855-
// Whether we should start vhal_proxy_server for the guest-side VHAL to
856-
// connect to.
857-
void set_start_vhal_proxy_server(bool start_vhal_proxy_server);
852+
void set_enable_vhal_proxy_server(bool enable_vhal_proxy_server);
853+
void set_vhal_proxy_server_port(int port);
858854

859855
void set_audio_output_streams_count(int count);
860856

base/cvd/cuttlefish/host/libs/config/cuttlefish_config_instance.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1955,13 +1955,22 @@ void CuttlefishConfig::MutableInstanceSpecific::set_wifi_mac_prefix(
19551955
(*Dictionary())[kWifiMacPrefix] = wifi_mac_prefix;
19561956
}
19571957

1958-
static constexpr char kStartVhalProxyServer[] = "start_vhal_proxy_server";
1959-
void CuttlefishConfig::MutableInstanceSpecific::set_start_vhal_proxy_server(
1960-
bool start_vhal_proxy_server) {
1961-
(*Dictionary())[kStartVhalProxyServer] = start_vhal_proxy_server;
1958+
static constexpr char kEnableVhalProxyServer[] = "enable_vhal_proxy_server";
1959+
void CuttlefishConfig::MutableInstanceSpecific::set_enable_vhal_proxy_server(
1960+
bool enable_vhal_proxy_server) {
1961+
(*Dictionary())[kEnableVhalProxyServer] = enable_vhal_proxy_server;
19621962
}
1963-
bool CuttlefishConfig::InstanceSpecific::start_vhal_proxy_server() const {
1964-
return (*Dictionary())[kStartVhalProxyServer].asBool();
1963+
bool CuttlefishConfig::InstanceSpecific::enable_vhal_proxy_server() const {
1964+
return (*Dictionary())[kEnableVhalProxyServer].asBool();
1965+
}
1966+
1967+
static constexpr char kVhalProxyServerPort[] = "vhal_proxy_server_port";
1968+
void CuttlefishConfig::MutableInstanceSpecific::set_vhal_proxy_server_port(
1969+
int port) {
1970+
(*Dictionary())[kVhalProxyServerPort] = port;
1971+
}
1972+
int CuttlefishConfig::InstanceSpecific::vhal_proxy_server_port() const {
1973+
return (*Dictionary())[kVhalProxyServerPort].asInt();
19651974
}
19661975

19671976
static constexpr char kAudioOutputStreamsCount[] = "audio_output_streams_count";

0 commit comments

Comments
 (0)