Åsa Persson | f8ba95e | 2018-11-02 11:38:46 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #include "rtc_base/experiments/cpu_speed_experiment.h" |
| 12 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 13 | #include <stdio.h> |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 14 | |
Åsa Persson | 869e9fb | 2020-07-28 12:49:49 +0200 | [diff] [blame] | 15 | #include "rtc_base/experiments/field_trial_list.h" |
Åsa Persson | f8ba95e | 2018-11-02 11:38:46 +0100 | [diff] [blame] | 16 | #include "rtc_base/logging.h" |
| 17 | #include "system_wrappers/include/field_trial.h" |
| 18 | |
| 19 | namespace webrtc { |
| 20 | namespace { |
| 21 | constexpr char kFieldTrial[] = "WebRTC-VP8-CpuSpeed-Arm"; |
| 22 | constexpr int kMinSetting = -16; |
| 23 | constexpr int kMaxSetting = -1; |
Åsa Persson | f8ba95e | 2018-11-02 11:38:46 +0100 | [diff] [blame] | 24 | |
Åsa Persson | 869e9fb | 2020-07-28 12:49:49 +0200 | [diff] [blame] | 25 | std::vector<CpuSpeedExperiment::Config> GetValidOrEmpty( |
| 26 | const std::vector<CpuSpeedExperiment::Config>& configs) { |
| 27 | if (configs.empty()) { |
Åsa Persson | 869e9fb | 2020-07-28 12:49:49 +0200 | [diff] [blame] | 28 | return {}; |
Åsa Persson | f8ba95e | 2018-11-02 11:38:46 +0100 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | for (const auto& config : configs) { |
| 32 | if (config.cpu_speed < kMinSetting || config.cpu_speed > kMaxSetting) { |
| 33 | RTC_LOG(LS_WARNING) << "Unsupported cpu speed setting, value ignored."; |
Åsa Persson | 869e9fb | 2020-07-28 12:49:49 +0200 | [diff] [blame] | 34 | return {}; |
Åsa Persson | f8ba95e | 2018-11-02 11:38:46 +0100 | [diff] [blame] | 35 | } |
| 36 | } |
| 37 | |
| 38 | for (size_t i = 1; i < configs.size(); ++i) { |
| 39 | if (configs[i].pixels < configs[i - 1].pixels || |
| 40 | configs[i].cpu_speed > configs[i - 1].cpu_speed) { |
| 41 | RTC_LOG(LS_WARNING) << "Invalid parameter value provided."; |
Åsa Persson | 869e9fb | 2020-07-28 12:49:49 +0200 | [diff] [blame] | 42 | return {}; |
Åsa Persson | f8ba95e | 2018-11-02 11:38:46 +0100 | [diff] [blame] | 43 | } |
| 44 | } |
| 45 | |
Åsa Persson | 869e9fb | 2020-07-28 12:49:49 +0200 | [diff] [blame] | 46 | return configs; |
| 47 | } |
Åsa Persson | ceab754 | 2020-09-21 14:57:04 +0200 | [diff] [blame] | 48 | |
| 49 | bool HasLeCores(const std::vector<CpuSpeedExperiment::Config>& configs) { |
| 50 | for (const auto& config : configs) { |
| 51 | if (config.cpu_speed_le_cores == 0) |
| 52 | return false; |
| 53 | } |
| 54 | return true; |
| 55 | } |
Åsa Persson | 869e9fb | 2020-07-28 12:49:49 +0200 | [diff] [blame] | 56 | } // namespace |
| 57 | |
Åsa Persson | ceab754 | 2020-09-21 14:57:04 +0200 | [diff] [blame] | 58 | CpuSpeedExperiment::CpuSpeedExperiment() : cores_("cores") { |
Åsa Persson | 869e9fb | 2020-07-28 12:49:49 +0200 | [diff] [blame] | 59 | FieldTrialStructList<Config> configs( |
| 60 | {FieldTrialStructMember("pixels", [](Config* c) { return &c->pixels; }), |
| 61 | FieldTrialStructMember("cpu_speed", |
Åsa Persson | ceab754 | 2020-09-21 14:57:04 +0200 | [diff] [blame] | 62 | [](Config* c) { return &c->cpu_speed; }), |
| 63 | FieldTrialStructMember( |
| 64 | "cpu_speed_le_cores", |
| 65 | [](Config* c) { return &c->cpu_speed_le_cores; })}, |
Åsa Persson | 869e9fb | 2020-07-28 12:49:49 +0200 | [diff] [blame] | 66 | {}); |
Åsa Persson | ceab754 | 2020-09-21 14:57:04 +0200 | [diff] [blame] | 67 | ParseFieldTrial({&configs, &cores_}, field_trial::FindFullName(kFieldTrial)); |
Åsa Persson | 869e9fb | 2020-07-28 12:49:49 +0200 | [diff] [blame] | 68 | |
| 69 | configs_ = GetValidOrEmpty(configs.Get()); |
Åsa Persson | f8ba95e | 2018-11-02 11:38:46 +0100 | [diff] [blame] | 70 | } |
| 71 | |
Åsa Persson | 869e9fb | 2020-07-28 12:49:49 +0200 | [diff] [blame] | 72 | CpuSpeedExperiment::~CpuSpeedExperiment() {} |
| 73 | |
Åsa Persson | ceab754 | 2020-09-21 14:57:04 +0200 | [diff] [blame] | 74 | absl::optional<int> CpuSpeedExperiment::GetValue(int pixels, |
| 75 | int num_cores) const { |
Åsa Persson | 869e9fb | 2020-07-28 12:49:49 +0200 | [diff] [blame] | 76 | if (configs_.empty()) |
| 77 | return absl::nullopt; |
| 78 | |
Åsa Persson | ceab754 | 2020-09-21 14:57:04 +0200 | [diff] [blame] | 79 | bool use_le = HasLeCores(configs_) && cores_ && num_cores <= cores_.Value(); |
| 80 | |
Åsa Persson | 869e9fb | 2020-07-28 12:49:49 +0200 | [diff] [blame] | 81 | for (const auto& config : configs_) { |
Åsa Persson | f8ba95e | 2018-11-02 11:38:46 +0100 | [diff] [blame] | 82 | if (pixels <= config.pixels) |
Åsa Persson | ceab754 | 2020-09-21 14:57:04 +0200 | [diff] [blame] | 83 | return use_le ? absl::optional<int>(config.cpu_speed_le_cores) |
| 84 | : absl::optional<int>(config.cpu_speed); |
Åsa Persson | f8ba95e | 2018-11-02 11:38:46 +0100 | [diff] [blame] | 85 | } |
Åsa Persson | 869e9fb | 2020-07-28 12:49:49 +0200 | [diff] [blame] | 86 | return absl::optional<int>(kMinSetting); |
Åsa Persson | f8ba95e | 2018-11-02 11:38:46 +0100 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | } // namespace webrtc |