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

Commit 25b3a6f0 authored by Veerendranath Jakkam's avatar Veerendranath Jakkam Committed by Sunil Ravi
Browse files

Synchronize on_ring_buffer_data_callback and writeRingbufferFiles

on_ring_buffer_data_callback callback is invoked on getting the
corresponding driver/firmware ringbuffer logs. This callback further
stores the ringbuffer data locally in cur_buffer. While the data is
getting updated through this callback, writeRingbufferFilesInternal
can get triggered from a different context which accesses the same buffer
-cur_buffer.
Synchronization is missing between these two contexts while accessing the
buffer and this commit attempts the same.

Bug: 153970986
Test: Manual - collect the bugreport and check the ring buffer logs.
Change-Id: Id99a517f4d72872b84b48c3df75dd29743f3e9b2
parent cedd3f38
Loading
Loading
Loading
Loading
+33 −24
Original line number Original line Diff line number Diff line
@@ -1314,7 +1314,10 @@ WifiStatus WifiChip::registerDebugRingBufferCallback() {
                LOG(ERROR) << "Error converting ring buffer status";
                LOG(ERROR) << "Error converting ring buffer status";
                return;
                return;
            }
            }
            const auto& target = shared_ptr_this->ringbuffer_map_.find(name);
            {
                std::unique_lock<std::mutex> lk(shared_ptr_this->lock_t);
                const auto& target =
                    shared_ptr_this->ringbuffer_map_.find(name);
                if (target != shared_ptr_this->ringbuffer_map_.end()) {
                if (target != shared_ptr_this->ringbuffer_map_.end()) {
                    Ringbuffer& cur_buffer = target->second;
                    Ringbuffer& cur_buffer = target->second;
                    cur_buffer.append(data);
                    cur_buffer.append(data);
@@ -1322,6 +1325,8 @@ WifiStatus WifiChip::registerDebugRingBufferCallback() {
                    LOG(ERROR) << "Ringname " << name << " not found";
                    LOG(ERROR) << "Ringname " << name << " not found";
                    return;
                    return;
                }
                }
                // unlock
            }
        };
        };
    legacy_hal::wifi_error legacy_status =
    legacy_hal::wifi_error legacy_status =
        legacy_hal_.lock()->registerRingBufferCallbackHandler(
        legacy_hal_.lock()->registerRingBufferCallbackHandler(
@@ -1595,6 +1600,8 @@ bool WifiChip::writeRingbufferFilesInternal() {
        return false;
        return false;
    }
    }
    // write ringbuffers to file
    // write ringbuffers to file
    {
        std::unique_lock<std::mutex> lk(lock_t);
        for (const auto& item : ringbuffer_map_) {
        for (const auto& item : ringbuffer_map_) {
            const Ringbuffer& cur_buffer = item.second;
            const Ringbuffer& cur_buffer = item.second;
            if (cur_buffer.getData().empty()) {
            if (cur_buffer.getData().empty()) {
@@ -1615,6 +1622,8 @@ bool WifiChip::writeRingbufferFilesInternal() {
                }
                }
            }
            }
        }
        }
        // unlock
    }
    return true;
    return true;
}
}


+2 −0
Original line number Original line Diff line number Diff line
@@ -19,6 +19,7 @@


#include <list>
#include <list>
#include <map>
#include <map>
#include <mutex>


#include <android-base/macros.h>
#include <android-base/macros.h>
#include <android/hardware/wifi/1.4/IWifiChip.h>
#include <android/hardware/wifi/1.4/IWifiChip.h>
@@ -272,6 +273,7 @@ class WifiChip : public V1_4::IWifiChip {
    bool is_valid_;
    bool is_valid_;
    // Members pertaining to chip configuration.
    // Members pertaining to chip configuration.
    uint32_t current_mode_id_;
    uint32_t current_mode_id_;
    std::mutex lock_t;
    std::vector<IWifiChip::ChipMode> modes_;
    std::vector<IWifiChip::ChipMode> modes_;
    // The legacy ring buffer callback API has only a global callback
    // The legacy ring buffer callback API has only a global callback
    // registration mechanism. Use this to check if we have already
    // registration mechanism. Use this to check if we have already