2018-11-02 11:38:46 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright 2018 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "rtc_base/experiments/cpu_speed_experiment.h"
|
|
|
|
|
|
2018-11-28 16:47:49 +01:00
|
|
|
#include <stdio.h>
|
2019-07-05 19:08:33 +02:00
|
|
|
|
2020-07-28 12:49:49 +02:00
|
|
|
#include "rtc_base/experiments/field_trial_list.h"
|
2018-11-02 11:38:46 +01:00
|
|
|
#include "rtc_base/logging.h"
|
|
|
|
|
#include "system_wrappers/include/field_trial.h"
|
|
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
namespace {
|
|
|
|
|
constexpr char kFieldTrial[] = "WebRTC-VP8-CpuSpeed-Arm";
|
|
|
|
|
constexpr int kMinSetting = -16;
|
|
|
|
|
constexpr int kMaxSetting = -1;
|
|
|
|
|
|
2020-07-28 12:49:49 +02:00
|
|
|
std::vector<CpuSpeedExperiment::Config> GetValidOrEmpty(
|
|
|
|
|
const std::vector<CpuSpeedExperiment::Config>& configs) {
|
|
|
|
|
if (configs.empty()) {
|
|
|
|
|
return {};
|
2018-11-02 11:38:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (const auto& config : configs) {
|
|
|
|
|
if (config.cpu_speed < kMinSetting || config.cpu_speed > kMaxSetting) {
|
|
|
|
|
RTC_LOG(LS_WARNING) << "Unsupported cpu speed setting, value ignored.";
|
2020-07-28 12:49:49 +02:00
|
|
|
return {};
|
2018-11-02 11:38:46 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (size_t i = 1; i < configs.size(); ++i) {
|
|
|
|
|
if (configs[i].pixels < configs[i - 1].pixels ||
|
|
|
|
|
configs[i].cpu_speed > configs[i - 1].cpu_speed) {
|
|
|
|
|
RTC_LOG(LS_WARNING) << "Invalid parameter value provided.";
|
2020-07-28 12:49:49 +02:00
|
|
|
return {};
|
2018-11-02 11:38:46 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-28 12:49:49 +02:00
|
|
|
return configs;
|
|
|
|
|
}
|
2020-09-21 14:57:04 +02:00
|
|
|
|
|
|
|
|
bool HasLeCores(const std::vector<CpuSpeedExperiment::Config>& configs) {
|
|
|
|
|
for (const auto& config : configs) {
|
|
|
|
|
if (config.cpu_speed_le_cores == 0)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2020-07-28 12:49:49 +02:00
|
|
|
} // namespace
|
|
|
|
|
|
2020-09-21 14:57:04 +02:00
|
|
|
CpuSpeedExperiment::CpuSpeedExperiment() : cores_("cores") {
|
2020-07-28 12:49:49 +02:00
|
|
|
FieldTrialStructList<Config> configs(
|
|
|
|
|
{FieldTrialStructMember("pixels", [](Config* c) { return &c->pixels; }),
|
|
|
|
|
FieldTrialStructMember("cpu_speed",
|
2020-09-21 14:57:04 +02:00
|
|
|
[](Config* c) { return &c->cpu_speed; }),
|
|
|
|
|
FieldTrialStructMember(
|
|
|
|
|
"cpu_speed_le_cores",
|
|
|
|
|
[](Config* c) { return &c->cpu_speed_le_cores; })},
|
2020-07-28 12:49:49 +02:00
|
|
|
{});
|
2020-09-21 14:57:04 +02:00
|
|
|
ParseFieldTrial({&configs, &cores_}, field_trial::FindFullName(kFieldTrial));
|
2020-07-28 12:49:49 +02:00
|
|
|
|
|
|
|
|
configs_ = GetValidOrEmpty(configs.Get());
|
2018-11-02 11:38:46 +01:00
|
|
|
}
|
|
|
|
|
|
2020-07-28 12:49:49 +02:00
|
|
|
CpuSpeedExperiment::~CpuSpeedExperiment() {}
|
|
|
|
|
|
2020-09-21 14:57:04 +02:00
|
|
|
absl::optional<int> CpuSpeedExperiment::GetValue(int pixels,
|
|
|
|
|
int num_cores) const {
|
2020-07-28 12:49:49 +02:00
|
|
|
if (configs_.empty())
|
|
|
|
|
return absl::nullopt;
|
|
|
|
|
|
2020-09-21 14:57:04 +02:00
|
|
|
bool use_le = HasLeCores(configs_) && cores_ && num_cores <= cores_.Value();
|
|
|
|
|
|
2020-07-28 12:49:49 +02:00
|
|
|
for (const auto& config : configs_) {
|
2018-11-02 11:38:46 +01:00
|
|
|
if (pixels <= config.pixels)
|
2020-09-21 14:57:04 +02:00
|
|
|
return use_le ? absl::optional<int>(config.cpu_speed_le_cores)
|
|
|
|
|
: absl::optional<int>(config.cpu_speed);
|
2018-11-02 11:38:46 +01:00
|
|
|
}
|
2020-07-28 12:49:49 +02:00
|
|
|
return absl::optional<int>(kMinSetting);
|
2018-11-02 11:38:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|