Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5cce5ff0 authored by Jack He's avatar Jack He
Browse files

GD: Hold wakelock when starting and stopping the Bluetooth stack

* Hold wakelock when starting and stopping the Bluetooth stack so that it
  can meet the timing requirement
* Rename GD wakelock to bluetooth_gd_timer for easier debugging
* Use native HAL based wakelock in GD

Bug: 184608842
Tag: #gd-refactor
Test: atest bluetooth_test_gd_unit
BYPASS_LONG_LINES_REASON: Bluetooth likes 120 lines

Change-Id: Ib4679782061b82a70a240a2a614f7ee587e5c7c7
parent 091a2019
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ include "common/init_flags.fbs";
include "l2cap/classic/l2cap_classic_module.fbs";
include "hci/hci_acl_manager.fbs";
include "module_unittest.fbs";
include "os/wakelock_manager.fbs";
include "shim/dumpsys.fbs";

namespace bluetooth;
@@ -13,6 +14,7 @@ attribute "privacy";
table DumpsysData {
    title:string;
    init_flags:common.InitFlagsData (privacy:"Any");
    wakelock_manager_data:bluetooth.os.WakelockManagerData (privacy:"Any");
    shim_dumpsys_data:bluetooth.shim.DumpsysModuleData (privacy:"Any");
    l2cap_classic_dumpsys_data:bluetooth.l2cap.classic.L2capClassicModuleData (privacy:"Any");
    hci_acl_manager_dumpsys_data:bluetooth.hci.AclManagerData (privacy:"Any");
+4 −0
Original line number Diff line number Diff line
@@ -18,9 +18,11 @@
#include "module.h"
#include "common/init_flags.h"
#include "dumpsys/init_flags.h"
#include "os/wakelock_manager.h"

using ::bluetooth::os::Handler;
using ::bluetooth::os::Thread;
using ::bluetooth::os::WakelockManager;

namespace bluetooth {

@@ -139,6 +141,7 @@ void ModuleDumper::DumpState(std::string* output) const {
  auto title = builder.CreateString(title_);

  auto init_flags_offset = dumpsys::InitFlags::Dump(&builder);
  auto wakelock_offset = WakelockManager::Get().GetDumpsysData(&builder);

  std::queue<DumpsysDataFinisher> queue;
  for (auto it = module_registry_.start_order_.rbegin(); it != module_registry_.start_order_.rend(); it++) {
@@ -150,6 +153,7 @@ void ModuleDumper::DumpState(std::string* output) const {
  DumpsysDataBuilder data_builder(builder);
  data_builder.add_title(title);
  data_builder.add_init_flags(init_flags_offset);
  data_builder.add_wakelock_manager_data(wakelock_offset);

  while (!queue.empty()) {
    queue.front()(&data_builder);
+6 −5
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@

#include "os/internal/wakelock_native.h"
#include "os/log.h"
#include "wakelock_manager_generated.h"

namespace bluetooth {
namespace os {
@@ -42,7 +41,7 @@ uint64_t now_ms() {
  return (ts.tv_sec * 1000LL) + (ts.tv_nsec / 1000000LL);
}

const std::string WakelockManager::kBtWakelockId = "bluetooth_timer";
const std::string WakelockManager::kBtWakelockId = "bluetooth_gd_timer";

// Wakelock statistics for the "bluetooth_timer"
struct WakelockManager::Stats {
@@ -131,7 +130,8 @@ struct WakelockManager::Stats {
    total_acquired_interval_ms += delta_ms;
  }

  void GetDumpsysData(flatbuffers::FlatBufferBuilder* fb_builder, bool is_native) const {
  flatbuffers::Offset<WakelockManagerData> GetDumpsysData(
      flatbuffers::FlatBufferBuilder* fb_builder, bool is_native) const {
    const uint64_t just_now_ms = now_ms();
    // Compute the last acquired interval if the wakelock is still acquired
    uint64_t delta_ms = 0;
@@ -174,6 +174,7 @@ struct WakelockManager::Stats {
    builder.add_avg_interval_millis(avg_interval_ms);
    builder.add_total_interval_millis(total_interval_ms);
    builder.add_total_time_since_reset_millis(just_now_ms - last_reset_timestamp_ms);
    return builder.Finish();
  }
};

@@ -260,9 +261,9 @@ void WakelockManager::CleanUp() {
  initialized_ = false;
}

void WakelockManager::GetDumpsysData(flatbuffers::FlatBufferBuilder* fb_builder) {
flatbuffers::Offset<WakelockManagerData> WakelockManager::GetDumpsysData(flatbuffers::FlatBufferBuilder* fb_builder) {
  std::lock_guard<std::recursive_mutex> lock_guard(mutex_);
  pstats_->GetDumpsysData(fb_builder, is_native_);
  return pstats_->GetDumpsysData(fb_builder, is_native_);
}

WakelockManager::WakelockManager() : pstats_(std::make_unique<Stats>()) {}
+2 −6
Original line number Diff line number Diff line
@@ -167,9 +167,7 @@ TEST_F(WakelockManagerTest, test_with_os_callouts_in_a_loop_and_dump) {

  {
    flatbuffers::FlatBufferBuilder builder(1024);
    WakelockManager::Get().GetDumpsysData(&builder);
    WakelockManagerDataBuilder specific_builder(builder);
    auto offset = specific_builder.Finish();
    auto offset = WakelockManager::Get().GetDumpsysData(&builder);
    FinishWakelockManagerDataBuffer(builder, offset);
    auto data = GetWakelockManagerData(builder.GetBufferPointer());

@@ -182,9 +180,7 @@ TEST_F(WakelockManagerTest, test_with_os_callouts_in_a_loop_and_dump) {

  {
    flatbuffers::FlatBufferBuilder builder(1024);
    WakelockManager::Get().GetDumpsysData(&builder);
    WakelockManagerDataBuilder specific_builder(builder);
    auto offset = specific_builder.Finish();
    auto offset = WakelockManager::Get().GetDumpsysData(&builder);
    FinishWakelockManagerDataBuffer(builder, offset);
    auto data = GetWakelockManagerData(builder.GetBufferPointer());

+2 −1
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@
#include <flatbuffers/flatbuffers.h>

#include "handler.h"
#include "wakelock_manager_generated.h"

namespace bluetooth {
namespace os {
@@ -72,7 +73,7 @@ class WakelockManager {
  void CleanUp();

  // Dump wakelock-related debug info to a flat buffer defined in wakelock_manager.fbs
  void GetDumpsysData(flatbuffers::FlatBufferBuilder* fb_builder);
  flatbuffers::Offset<WakelockManagerData> GetDumpsysData(flatbuffers::FlatBufferBuilder* fb_builder);

  ~WakelockManager();

Loading