Loading system/gd/hci/hci_layer.cc +25 −5 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ #include "os/alarm.h" #include "os/metrics.h" #include "os/queue.h" #include "os/system_properties.h" #include "osi/include/stack_power_telemetry.h" #include "packet/raw_builder.h" #include "storage/storage_module.h" Loading @@ -57,6 +58,19 @@ using os::Alarm; using os::Handler; using std::unique_ptr; static std::chrono::milliseconds getHciTimeoutMs() { static auto sHciTimeoutMs = std::chrono::milliseconds(bluetooth::os::GetSystemPropertyUint32Base( "bluetooth.hci.timeout_milliseconds", HciLayer::kHciTimeoutMs.count())); return sHciTimeoutMs; } static std::chrono::milliseconds getHciTimeoutRestartMs() { static auto sRestartHciTimeoutMs = std::chrono::milliseconds(bluetooth::os::GetSystemPropertyUint32Base( "bluetooth.hci.restart_timeout_milliseconds", HciLayer::kHciTimeoutRestartMs.count())); return sRestartHciTimeoutMs; } static void fail_if_reset_complete_not_success(CommandCompleteView complete) { auto reset_complete = ResetCompleteView::Create(complete); log::assert_that(reset_complete.IsValid(), "assert failed: reset_complete.IsValid()"); Loading @@ -67,7 +81,10 @@ static void fail_if_reset_complete_not_success(CommandCompleteView complete) { } static void abort_after_time_out(OpCode op_code) { log::fatal("Done waiting for debug information after HCI timeout ({})", OpCodeText(op_code)); log::fatal( "Done waiting for debug information after HCI timeout ({}) for {}ms", OpCodeText(op_code), getHciTimeoutRestartMs().count()); } class CommandQueueEntry { Loading Loading @@ -267,7 +284,7 @@ struct HciLayer::impl { void on_hci_timeout(OpCode op_code) { common::StopWatch::DumpStopWatchLog(); log::error("Timed out waiting for {}", OpCodeText(op_code)); log::error("Timed out waiting for {} for {}ms", OpCodeText(op_code), getHciTimeoutMs().count()); bluetooth::os::LogMetricHciTimeoutEvent(static_cast<uint32_t>(op_code)); Loading @@ -286,7 +303,8 @@ struct HciLayer::impl { } if (hci_abort_alarm_ == nullptr) { hci_abort_alarm_ = new Alarm(module_.GetHandler()); hci_abort_alarm_->Schedule(BindOnce(&abort_after_time_out, op_code), kHciTimeoutRestartMs); hci_abort_alarm_->Schedule( BindOnce(&abort_after_time_out, op_code), getHciTimeoutRestartMs()); } else { log::warn("Unable to schedul abort timer"); } Loading Loading @@ -317,7 +335,8 @@ struct HciLayer::impl { waiting_command_ = op_code; command_credits_ = 0; // Only allow one outstanding command if (hci_timeout_alarm_ != nullptr) { hci_timeout_alarm_->Schedule(BindOnce(&impl::on_hci_timeout, common::Unretained(this), op_code), kHciTimeoutMs); hci_timeout_alarm_->Schedule( BindOnce(&impl::on_hci_timeout, common::Unretained(this), op_code), getHciTimeoutMs()); } else { log::warn("{} sent without an hci-timeout timer", OpCodeText(op_code)); } Loading Loading @@ -386,7 +405,8 @@ struct HciLayer::impl { } if (hci_abort_alarm_ == nullptr) { hci_abort_alarm_ = new Alarm(module_.GetHandler()); hci_abort_alarm_->Schedule(BindOnce(&abort_after_root_inflammation, vse_error_reason), kHciTimeoutRestartMs); hci_abort_alarm_->Schedule( BindOnce(&abort_after_root_inflammation, vse_error_reason), getHciTimeoutRestartMs()); } else { log::warn("Abort timer already scheduled"); } Loading system/gd/hci/hci_layer_unittest.cc +20 −6 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ #include "module.h" #include "os/fake_timer/fake_timerfd.h" #include "os/handler.h" #include "os/system_properties.h" #include "os/thread.h" #include "packet/raw_builder.h" Loading Loading @@ -75,6 +76,19 @@ std::vector<uint8_t> GetPacketBytes(std::unique_ptr<packet::BasePacketBuilder> p return bytes; } static std::chrono::milliseconds getHciTimeoutMs() { static auto sHciTimeoutMs = std::chrono::milliseconds(bluetooth::os::GetSystemPropertyUint32Base( "bluetooth.hci.timeout_milliseconds", HciLayer::kHciTimeoutMs.count())); return sHciTimeoutMs; } static std::chrono::milliseconds getHciTimeoutRestartMs() { static auto sRestartHciTimeoutMs = std::chrono::milliseconds(bluetooth::os::GetSystemPropertyUint32Base( "bluetooth.hci.restart_timeout_milliseconds", HciLayer::kHciTimeoutRestartMs.count())); return sRestartHciTimeoutMs; } class HciLayerTest : public ::testing::Test { protected: void SetUp() override { Loading Loading @@ -132,7 +146,7 @@ TEST_F(HciLayerTest, reset_command_sent_on_start) { TEST_F(HciLayerTest, controller_debug_info_requested_on_hci_timeout) { FailIfResetNotSent(); FakeTimerAdvance(HciLayer::kHciTimeoutMs.count()); FakeTimerAdvance(getHciTimeoutMs().count()); sync_handler(); Loading @@ -144,7 +158,7 @@ TEST_F(HciLayerTest, controller_debug_info_requested_on_hci_timeout) { TEST_F(HciLayerDeathTest, abort_after_hci_restart_timeout) { FailIfResetNotSent(); FakeTimerAdvance(HciLayer::kHciTimeoutMs.count()); FakeTimerAdvance(getHciTimeoutMs().count()); auto sent_command = hal_->GetSentCommand(); ASSERT_TRUE(sent_command.has_value()); Loading @@ -154,7 +168,7 @@ TEST_F(HciLayerDeathTest, abort_after_hci_restart_timeout) { ASSERT_DEATH( { sync_handler(); FakeTimerAdvance(HciLayer::kHciTimeoutRestartMs.count()); FakeTimerAdvance(getHciTimeoutRestartMs().count()); sync_handler(); }, ""); Loading @@ -162,7 +176,7 @@ TEST_F(HciLayerDeathTest, abort_after_hci_restart_timeout) { TEST_F(HciLayerDeathTest, discard_event_after_hci_timeout) { FailIfResetNotSent(); FakeTimerAdvance(HciLayer::kHciTimeoutMs.count()); FakeTimerAdvance(getHciTimeoutMs().count()); auto sent_command = hal_->GetSentCommand(); ASSERT_TRUE(sent_command.has_value()); Loading @@ -175,7 +189,7 @@ TEST_F(HciLayerDeathTest, discard_event_after_hci_timeout) { ASSERT_DEATH( { FakeTimerAdvance(HciLayer::kHciTimeoutRestartMs.count()); FakeTimerAdvance(getHciTimeoutRestartMs().count()); sync_handler(); }, ""); Loading @@ -189,7 +203,7 @@ TEST_F(HciLayerDeathTest, abort_on_root_inflammation_event) { sync_handler(); hal_->InjectEvent(BqrRootInflammationEventBuilder::Create( 0x01, 0x01, std::make_unique<packet::RawBuilder>())); FakeTimerAdvance(HciLayer::kHciTimeoutRestartMs.count()); FakeTimerAdvance(getHciTimeoutRestartMs().count()); sync_handler(); }, ""); Loading Loading
system/gd/hci/hci_layer.cc +25 −5 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ #include "os/alarm.h" #include "os/metrics.h" #include "os/queue.h" #include "os/system_properties.h" #include "osi/include/stack_power_telemetry.h" #include "packet/raw_builder.h" #include "storage/storage_module.h" Loading @@ -57,6 +58,19 @@ using os::Alarm; using os::Handler; using std::unique_ptr; static std::chrono::milliseconds getHciTimeoutMs() { static auto sHciTimeoutMs = std::chrono::milliseconds(bluetooth::os::GetSystemPropertyUint32Base( "bluetooth.hci.timeout_milliseconds", HciLayer::kHciTimeoutMs.count())); return sHciTimeoutMs; } static std::chrono::milliseconds getHciTimeoutRestartMs() { static auto sRestartHciTimeoutMs = std::chrono::milliseconds(bluetooth::os::GetSystemPropertyUint32Base( "bluetooth.hci.restart_timeout_milliseconds", HciLayer::kHciTimeoutRestartMs.count())); return sRestartHciTimeoutMs; } static void fail_if_reset_complete_not_success(CommandCompleteView complete) { auto reset_complete = ResetCompleteView::Create(complete); log::assert_that(reset_complete.IsValid(), "assert failed: reset_complete.IsValid()"); Loading @@ -67,7 +81,10 @@ static void fail_if_reset_complete_not_success(CommandCompleteView complete) { } static void abort_after_time_out(OpCode op_code) { log::fatal("Done waiting for debug information after HCI timeout ({})", OpCodeText(op_code)); log::fatal( "Done waiting for debug information after HCI timeout ({}) for {}ms", OpCodeText(op_code), getHciTimeoutRestartMs().count()); } class CommandQueueEntry { Loading Loading @@ -267,7 +284,7 @@ struct HciLayer::impl { void on_hci_timeout(OpCode op_code) { common::StopWatch::DumpStopWatchLog(); log::error("Timed out waiting for {}", OpCodeText(op_code)); log::error("Timed out waiting for {} for {}ms", OpCodeText(op_code), getHciTimeoutMs().count()); bluetooth::os::LogMetricHciTimeoutEvent(static_cast<uint32_t>(op_code)); Loading @@ -286,7 +303,8 @@ struct HciLayer::impl { } if (hci_abort_alarm_ == nullptr) { hci_abort_alarm_ = new Alarm(module_.GetHandler()); hci_abort_alarm_->Schedule(BindOnce(&abort_after_time_out, op_code), kHciTimeoutRestartMs); hci_abort_alarm_->Schedule( BindOnce(&abort_after_time_out, op_code), getHciTimeoutRestartMs()); } else { log::warn("Unable to schedul abort timer"); } Loading Loading @@ -317,7 +335,8 @@ struct HciLayer::impl { waiting_command_ = op_code; command_credits_ = 0; // Only allow one outstanding command if (hci_timeout_alarm_ != nullptr) { hci_timeout_alarm_->Schedule(BindOnce(&impl::on_hci_timeout, common::Unretained(this), op_code), kHciTimeoutMs); hci_timeout_alarm_->Schedule( BindOnce(&impl::on_hci_timeout, common::Unretained(this), op_code), getHciTimeoutMs()); } else { log::warn("{} sent without an hci-timeout timer", OpCodeText(op_code)); } Loading Loading @@ -386,7 +405,8 @@ struct HciLayer::impl { } if (hci_abort_alarm_ == nullptr) { hci_abort_alarm_ = new Alarm(module_.GetHandler()); hci_abort_alarm_->Schedule(BindOnce(&abort_after_root_inflammation, vse_error_reason), kHciTimeoutRestartMs); hci_abort_alarm_->Schedule( BindOnce(&abort_after_root_inflammation, vse_error_reason), getHciTimeoutRestartMs()); } else { log::warn("Abort timer already scheduled"); } Loading
system/gd/hci/hci_layer_unittest.cc +20 −6 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ #include "module.h" #include "os/fake_timer/fake_timerfd.h" #include "os/handler.h" #include "os/system_properties.h" #include "os/thread.h" #include "packet/raw_builder.h" Loading Loading @@ -75,6 +76,19 @@ std::vector<uint8_t> GetPacketBytes(std::unique_ptr<packet::BasePacketBuilder> p return bytes; } static std::chrono::milliseconds getHciTimeoutMs() { static auto sHciTimeoutMs = std::chrono::milliseconds(bluetooth::os::GetSystemPropertyUint32Base( "bluetooth.hci.timeout_milliseconds", HciLayer::kHciTimeoutMs.count())); return sHciTimeoutMs; } static std::chrono::milliseconds getHciTimeoutRestartMs() { static auto sRestartHciTimeoutMs = std::chrono::milliseconds(bluetooth::os::GetSystemPropertyUint32Base( "bluetooth.hci.restart_timeout_milliseconds", HciLayer::kHciTimeoutRestartMs.count())); return sRestartHciTimeoutMs; } class HciLayerTest : public ::testing::Test { protected: void SetUp() override { Loading Loading @@ -132,7 +146,7 @@ TEST_F(HciLayerTest, reset_command_sent_on_start) { TEST_F(HciLayerTest, controller_debug_info_requested_on_hci_timeout) { FailIfResetNotSent(); FakeTimerAdvance(HciLayer::kHciTimeoutMs.count()); FakeTimerAdvance(getHciTimeoutMs().count()); sync_handler(); Loading @@ -144,7 +158,7 @@ TEST_F(HciLayerTest, controller_debug_info_requested_on_hci_timeout) { TEST_F(HciLayerDeathTest, abort_after_hci_restart_timeout) { FailIfResetNotSent(); FakeTimerAdvance(HciLayer::kHciTimeoutMs.count()); FakeTimerAdvance(getHciTimeoutMs().count()); auto sent_command = hal_->GetSentCommand(); ASSERT_TRUE(sent_command.has_value()); Loading @@ -154,7 +168,7 @@ TEST_F(HciLayerDeathTest, abort_after_hci_restart_timeout) { ASSERT_DEATH( { sync_handler(); FakeTimerAdvance(HciLayer::kHciTimeoutRestartMs.count()); FakeTimerAdvance(getHciTimeoutRestartMs().count()); sync_handler(); }, ""); Loading @@ -162,7 +176,7 @@ TEST_F(HciLayerDeathTest, abort_after_hci_restart_timeout) { TEST_F(HciLayerDeathTest, discard_event_after_hci_timeout) { FailIfResetNotSent(); FakeTimerAdvance(HciLayer::kHciTimeoutMs.count()); FakeTimerAdvance(getHciTimeoutMs().count()); auto sent_command = hal_->GetSentCommand(); ASSERT_TRUE(sent_command.has_value()); Loading @@ -175,7 +189,7 @@ TEST_F(HciLayerDeathTest, discard_event_after_hci_timeout) { ASSERT_DEATH( { FakeTimerAdvance(HciLayer::kHciTimeoutRestartMs.count()); FakeTimerAdvance(getHciTimeoutRestartMs().count()); sync_handler(); }, ""); Loading @@ -189,7 +203,7 @@ TEST_F(HciLayerDeathTest, abort_on_root_inflammation_event) { sync_handler(); hal_->InjectEvent(BqrRootInflammationEventBuilder::Create( 0x01, 0x01, std::make_unique<packet::RawBuilder>())); FakeTimerAdvance(HciLayer::kHciTimeoutRestartMs.count()); FakeTimerAdvance(getHciTimeoutRestartMs().count()); sync_handler(); }, ""); Loading