OveruseFrameDetector: complete removal of mac rules kill switch.

Finally remove bogus code after a year of no feedback on the matter.

Bug: webrtc:14138
Change-Id: I8083c9e1986e3779c9023a7d8935b717f63f0d86
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/306180
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Commit-Queue: Markus Handell <handellm@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#40115}
This commit is contained in:
Markus Handell 2023-05-22 17:16:21 +02:00 committed by WebRTC LUCI CQ
parent 06130548fc
commit f67d1fd42c
6 changed files with 46 additions and 108 deletions

View File

@ -429,62 +429,6 @@ class OverdoseInjector : public OveruseFrameDetector::ProcessingUsage {
} // namespace
CpuOveruseOptions::CpuOveruseOptions(const FieldTrialsView& field_trials)
: high_encode_usage_threshold_percent(85),
frame_timeout_interval_ms(1500),
min_frame_samples(120),
min_process_count(3),
high_threshold_consecutive_count(2),
// Disabled by default.
filter_time_ms(0) {
#if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS)
// Kill switch for re-enabling special adaptation rules for macOS.
// TODO(bugs.webrtc.org/14138): Remove once removal is deemed safe.
if (field_trials.IsEnabled(
"WebRTC-MacSpecialOveruseRulesRemovalKillSwitch")) {
// This is proof-of-concept code for letting the physical core count affect
// the interval into which we attempt to scale. For now, the code is Mac OS
// specific, since that's the platform were we saw most problems.
// TODO(torbjorng): Enhance SystemInfo to return this metric.
mach_port_t mach_host = mach_host_self();
host_basic_info hbi = {};
mach_msg_type_number_t info_count = HOST_BASIC_INFO_COUNT;
kern_return_t kr =
host_info(mach_host, HOST_BASIC_INFO,
reinterpret_cast<host_info_t>(&hbi), &info_count);
mach_port_deallocate(mach_task_self(), mach_host);
int n_physical_cores;
if (kr != KERN_SUCCESS) {
// If we couldn't get # of physical CPUs, don't panic. Assume we have 1.
n_physical_cores = 1;
RTC_LOG(LS_ERROR)
<< "Failed to determine number of physical cores, assuming 1";
} else {
n_physical_cores = hbi.physical_cpu;
RTC_LOG(LS_INFO) << "Number of physical cores:" << n_physical_cores;
}
// Change init list default for few core systems. The assumption here is
// that encoding, which we measure here, takes about 1/4 of the processing
// of a two-way call. This is roughly true for x86 using both vp8 and vp9
// without hardware encoding. Since we don't affect the incoming stream
// here, we only control about 1/2 of the total processing needs, but this
// is not taken into account.
if (n_physical_cores == 1)
high_encode_usage_threshold_percent = 20; // Roughly 1/4 of 100%.
else if (n_physical_cores == 2)
high_encode_usage_threshold_percent = 40; // Roughly 1/4 of 200%.
}
#endif // defined(WEBRTC_MAC) && !defined(WEBRTC_IOS)
// Note that we make the interval 2x+epsilon wide, since libyuv scaling steps
// are close to that (when squared). This wide interval makes sure that
// scaling up or down does not jump all the way across the interval.
low_encode_usage_threshold_percent =
(high_encode_usage_threshold_percent - 1) / 2;
}
std::unique_ptr<OveruseFrameDetector::ProcessingUsage>
OveruseFrameDetector::CreateProcessingUsage(const CpuOveruseOptions& options) {
std::unique_ptr<ProcessingUsage> instance;
@ -521,10 +465,8 @@ OveruseFrameDetector::CreateProcessingUsage(const CpuOveruseOptions& options) {
}
OveruseFrameDetector::OveruseFrameDetector(
CpuOveruseMetricsObserver* metrics_observer,
const FieldTrialsView& field_trials)
: options_(field_trials),
metrics_observer_(metrics_observer),
CpuOveruseMetricsObserver* metrics_observer)
: metrics_observer_(metrics_observer),
num_process_times_(0),
// TODO(bugs.webrtc.org/9078): Use absl::optional
last_capture_time_us_(-1),

View File

@ -30,21 +30,29 @@ namespace webrtc {
class VideoFrame;
struct CpuOveruseOptions {
explicit CpuOveruseOptions(const FieldTrialsView& field_trials);
int low_encode_usage_threshold_percent; // Threshold for triggering underuse.
int high_encode_usage_threshold_percent; // Threshold for triggering overuse.
// Threshold for triggering overuse.
int high_encode_usage_threshold_percent = 85;
// Threshold for triggering underuse.
// Note that we make the interval 2x+epsilon wide, since libyuv scaling steps
// are close to that (when squared). This wide interval makes sure that
// scaling up or down does not jump all the way across the interval.
int low_encode_usage_threshold_percent =
(high_encode_usage_threshold_percent - 1) / 2;
// General settings.
int frame_timeout_interval_ms; // The maximum allowed interval between two
// frames before resetting estimations.
int min_frame_samples; // The minimum number of frames required.
int min_process_count; // The number of initial process times required before
// triggering an overuse/underuse.
int high_threshold_consecutive_count; // The number of consecutive checks
// above the high threshold before
// triggering an overuse.
// The maximum allowed interval between two frames before resetting
// estimations.
int frame_timeout_interval_ms = 1500;
// The minimum number of frames required.
int min_frame_samples = 120;
// The number of initial process times required before
// triggering an overuse/underuse.
int min_process_count = 3;
// The number of consecutive checks above the high threshold before triggering
// an overuse.
int high_threshold_consecutive_count = 2;
// New estimator enabled if this is set non-zero.
int filter_time_ms; // Time constant for averaging
int filter_time_ms = 0; // Time constant for averaging
};
class OveruseFrameDetectorObserverInterface {
@ -65,8 +73,7 @@ class OveruseFrameDetectorObserverInterface {
// check for overuse.
class OveruseFrameDetector {
public:
explicit OveruseFrameDetector(CpuOveruseMetricsObserver* metrics_observer,
const FieldTrialsView& field_trials);
explicit OveruseFrameDetector(CpuOveruseMetricsObserver* metrics_observer);
virtual ~OveruseFrameDetector();
OveruseFrameDetector(const OveruseFrameDetector&) = delete;

View File

@ -12,7 +12,6 @@
#include <memory>
#include "api/field_trials_view.h"
#include "api/video/encoded_image.h"
#include "api/video/i420_buffer.h"
#include "api/video/video_adaptation_reason.h"
@ -36,7 +35,6 @@ const int kHeight = 480;
// Corresponds to load of 15%
const int kFrameIntervalUs = 33 * rtc::kNumMicrosecsPerMillisec;
const int kProcessTimeUs = 5 * rtc::kNumMicrosecsPerMillisec;
const test::ScopedKeyValueConfig kFieldTrials;
} // namespace
class MockCpuOveruseObserver : public OveruseFrameDetectorObserverInterface {
@ -64,7 +62,7 @@ class OveruseFrameDetectorUnderTest : public OveruseFrameDetector {
public:
explicit OveruseFrameDetectorUnderTest(
CpuOveruseMetricsObserver* metrics_observer)
: OveruseFrameDetector(metrics_observer, kFieldTrials) {}
: OveruseFrameDetector(metrics_observer) {}
~OveruseFrameDetectorUnderTest() {}
using OveruseFrameDetector::CheckForOveruse;
@ -74,8 +72,6 @@ class OveruseFrameDetectorUnderTest : public OveruseFrameDetector {
class OveruseFrameDetectorTest : public ::testing::Test,
public CpuOveruseMetricsObserver {
protected:
OveruseFrameDetectorTest() : options_(kFieldTrials) {}
void SetUp() override {
observer_ = &mock_observer_;
options_.min_process_count = 0;

View File

@ -672,7 +672,7 @@ CpuOveruseOptions VideoStreamEncoderResourceManager::GetCpuOveruseOptions()
// This is already ensured by the only caller of this method:
// StartResourceAdaptation().
RTC_DCHECK(encoder_settings_.has_value());
CpuOveruseOptions options(field_trials_);
CpuOveruseOptions options;
// Hardware accelerated encoders are assumed to be pipelined; give them
// additional overuse time.
if (encoder_settings_->encoder_info().is_hardware_accelerated) {

View File

@ -122,7 +122,7 @@ std::unique_ptr<VideoStreamEncoder> CreateVideoStreamEncoder(
TaskQueueBase* encoder_queue_ptr = encoder_queue.get();
return std::make_unique<VideoStreamEncoder>(
clock, num_cpu_cores, stats_proxy, encoder_settings,
std::make_unique<OveruseFrameDetector>(stats_proxy, field_trials),
std::make_unique<OveruseFrameDetector>(stats_proxy),
FrameCadenceAdapterInterface::Create(clock, encoder_queue_ptr,
field_trials),
std::move(encoder_queue), bitrate_allocation_callback_type, field_trials,

View File

@ -222,9 +222,8 @@ class FakeNV12NativeBuffer : public webrtc::VideoFrameBuffer {
class CpuOveruseDetectorProxy : public OveruseFrameDetector {
public:
CpuOveruseDetectorProxy(CpuOveruseMetricsObserver* metrics_observer,
const FieldTrialsView& field_trials)
: OveruseFrameDetector(metrics_observer, field_trials),
explicit CpuOveruseDetectorProxy(CpuOveruseMetricsObserver* metrics_observer)
: OveruseFrameDetector(metrics_observer),
last_target_framerate_fps_(-1),
framerate_updated_event_(true /* manual_reset */,
false /* initially_signaled */) {}
@ -383,18 +382,17 @@ class VideoStreamEncoderUnderTest : public VideoStreamEncoder {
allocation_callback_type,
const FieldTrialsView& field_trials,
int num_cores)
: VideoStreamEncoder(
time_controller->GetClock(),
num_cores,
stats_proxy,
settings,
std::unique_ptr<OveruseFrameDetector>(
overuse_detector_proxy_ =
new CpuOveruseDetectorProxy(stats_proxy, field_trials)),
std::move(cadence_adapter),
std::move(encoder_queue),
allocation_callback_type,
field_trials),
: VideoStreamEncoder(time_controller->GetClock(),
num_cores,
stats_proxy,
settings,
std::unique_ptr<OveruseFrameDetector>(
overuse_detector_proxy_ =
new CpuOveruseDetectorProxy(stats_proxy)),
std::move(cadence_adapter),
std::move(encoder_queue),
allocation_callback_type,
field_trials),
time_controller_(time_controller),
fake_cpu_resource_(FakeResource::Create("FakeResource[CPU]")),
fake_quality_resource_(FakeResource::Create("FakeResource[QP]")),
@ -700,8 +698,7 @@ class SimpleVideoStreamEncoderFactory {
/*number_of_cores=*/1,
/*stats_proxy=*/stats_proxy_.get(), encoder_settings_,
std::make_unique<CpuOveruseDetectorProxy>(
/*stats_proxy=*/nullptr,
field_trials ? *field_trials : field_trials_),
/*stats_proxy=*/nullptr),
std::move(zero_hertz_adapter), std::move(encoder_queue),
VideoStreamEncoder::BitrateAllocationCallbackType::
kVideoBitrateAllocation,
@ -7060,8 +7057,7 @@ TEST_F(VideoStreamEncoderTest,
DefaultCpuAdaptationThresholdsForSoftwareEncoder) {
const int kFrameWidth = 1280;
const int kFrameHeight = 720;
const test::ScopedKeyValueConfig kFieldTrials;
const CpuOveruseOptions default_options(kFieldTrials);
const CpuOveruseOptions default_options;
video_stream_encoder_->OnBitrateUpdatedAndWaitForManagedResources(
kTargetBitrate, kTargetBitrate, kTargetBitrate, 0, 0, 0);
video_source_.IncomingCapturedFrame(
@ -7080,8 +7076,7 @@ TEST_F(VideoStreamEncoderTest,
HigherCpuAdaptationThresholdsForHardwareEncoder) {
const int kFrameWidth = 1280;
const int kFrameHeight = 720;
const test::ScopedKeyValueConfig kFieldTrials;
CpuOveruseOptions hardware_options(kFieldTrials);
CpuOveruseOptions hardware_options;
hardware_options.low_encode_usage_threshold_percent = 150;
hardware_options.high_encode_usage_threshold_percent = 200;
fake_encoder_.SetIsHardwareAccelerated(true);
@ -7105,8 +7100,7 @@ TEST_F(VideoStreamEncoderTest,
const int kFrameWidth = 1280;
const int kFrameHeight = 720;
const test::ScopedKeyValueConfig kFieldTrials;
const CpuOveruseOptions default_options(kFieldTrials);
const CpuOveruseOptions default_options;
video_stream_encoder_->OnBitrateUpdatedAndWaitForManagedResources(
kTargetBitrate, kTargetBitrate, kTargetBitrate, 0, 0, 0);
video_source_.IncomingCapturedFrame(
@ -7119,7 +7113,7 @@ TEST_F(VideoStreamEncoderTest,
.high_encode_usage_threshold_percent,
default_options.high_encode_usage_threshold_percent);
CpuOveruseOptions hardware_options(kFieldTrials);
CpuOveruseOptions hardware_options;
hardware_options.low_encode_usage_threshold_percent = 150;
hardware_options.high_encode_usage_threshold_percent = 200;
fake_encoder_.SetIsHardwareAccelerated(true);
@ -9237,8 +9231,7 @@ TEST(VideoStreamEncoderSimpleTest, CreateDestroy) {
// the posted init task will simply be deleted.
auto encoder = std::make_unique<VideoStreamEncoder>(
time_controller.GetClock(), 1, stats_proxy.get(), encoder_settings,
std::make_unique<CpuOveruseDetectorProxy>(stats_proxy.get(),
field_trials),
std::make_unique<CpuOveruseDetectorProxy>(stats_proxy.get()),
std::move(adapter), std::move(encoder_queue),
VideoStreamEncoder::BitrateAllocationCallbackType::
kVideoBitrateAllocation,