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

Commit 9aa42182 authored by David Anderson's avatar David Anderson
Browse files

snapuserd: Add diagnostics for debugging races.

Adds calls to pthread_setname_np for each thread.

Clarify error messages from io_uring calls that return -errno.

Add log messages for some failure paths that didn't have any.

Add an ostream overload for MERGE_IO_TRANSITION, and add an INVALID
state for initialization.

Bug: 288273605
Test: builds
Change-Id: Ic0681cbf0017af67bcf52b98db184a9b48752faf
parent 02191dbf
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@

#include "handler_manager.h"

#include <pthread.h>
#include <sys/eventfd.h>

#include <android-base/logging.h>
@@ -132,6 +133,8 @@ bool SnapshotHandlerManager::DeleteHandler(const std::string& misc_name) {
void SnapshotHandlerManager::RunThread(std::shared_ptr<HandlerThread> handler) {
    LOG(INFO) << "Entering thread for handler: " << handler->misc_name();

    pthread_setname_np(pthread_self(), "Handler");

    if (!handler->snapuserd()->Start()) {
        LOG(ERROR) << " Failed to launch all worker threads";
    }
@@ -219,6 +222,7 @@ void SnapshotHandlerManager::WakeupMonitorMergeThread() {
}

void SnapshotHandlerManager::MonitorMerge() {
    pthread_setname_np(pthread_self(), "Merge Monitor");
    while (!stop_monitor_merge_thread_) {
        uint64_t testVal;
        ssize_t ret =
+7 −1
Original line number Diff line number Diff line
@@ -15,6 +15,8 @@
 */
#include "merge_worker.h"

#include <pthread.h>

#include "snapuserd_core.h"
#include "utility.h"

@@ -198,6 +200,7 @@ bool MergeWorker::MergeOrderedOpsAsync() {
        // Wait for RA thread to notify that the merge window
        // is ready for merging.
        if (!snapuserd_->WaitForMergeBegin()) {
            SNAP_LOG(ERROR) << "Failed waiting for merge to begin";
            return false;
        }

@@ -303,7 +306,7 @@ bool MergeWorker::MergeOrderedOpsAsync() {
                    // will fallback to synchronous I/O.
                    ret = io_uring_wait_cqe(ring_.get(), &cqe);
                    if (ret) {
                        SNAP_LOG(ERROR) << "Merge: io_uring_wait_cqe failed: " << ret;
                        SNAP_LOG(ERROR) << "Merge: io_uring_wait_cqe failed: " << strerror(-ret);
                        status = false;
                        break;
                    }
@@ -546,6 +549,9 @@ void MergeWorker::FinalizeIouring() {

bool MergeWorker::Run() {
    SNAP_LOG(DEBUG) << "Waiting for merge begin...";

    pthread_setname_np(pthread_self(), "MergeWorker");

    if (!snapuserd_->WaitForMergeBegin()) {
        SNAP_LOG(ERROR) << "Merge terminated early...";
        return true;
+4 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

#include "read_worker.h"

#include <pthread.h>

#include "snapuserd_core.h"
#include "utility.h"

@@ -209,6 +211,8 @@ bool ReadWorker::Init() {
bool ReadWorker::Run() {
    SNAP_LOG(INFO) << "Processing snapshot I/O requests....";

    pthread_setname_np(pthread_self(), "ReadWorker");

    if (!SetThreadPriority(kNiceValueForMergeThreads)) {
        SNAP_PLOG(ERROR) << "Failed to set thread priority";
    }
+0 −2
Original line number Diff line number Diff line
@@ -295,8 +295,6 @@ bool SnapshotHandler::Start() {
    if (ra_thread_) {
        ra_thread_status =
                std::async(std::launch::async, &ReadAhead::RunThread, read_ahead_thread_.get());

        SNAP_LOG(INFO) << "Read-ahead thread started";
    }

    // Launch worker threads
+6 −2
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@
#include <iostream>
#include <limits>
#include <mutex>
#include <ostream>
#include <string>
#include <thread>
#include <unordered_map>
@@ -68,12 +69,13 @@ static constexpr int kNiceValueForMergeThreads = -5;
#define SNAP_PLOG(level) PLOG(level) << misc_name_ << ": "

enum class MERGE_IO_TRANSITION {
    INVALID,
    MERGE_READY,
    MERGE_BEGIN,
    MERGE_FAILED,
    MERGE_COMPLETE,
    IO_TERMINATED,
    READ_AHEAD_FAILURE,
    READ_AHEAD_FAILURE
};

class MergeWorker;
@@ -220,7 +222,7 @@ class SnapshotHandler : public std::enable_shared_from_this<SnapshotHandler> {
    bool populate_data_from_cow_ = false;
    bool ra_thread_ = false;
    int total_ra_blocks_merged_ = 0;
    MERGE_IO_TRANSITION io_state_;
    MERGE_IO_TRANSITION io_state_ = MERGE_IO_TRANSITION::INVALID;
    std::unique_ptr<ReadAhead> read_ahead_thread_;
    std::unordered_map<uint64_t, void*> read_ahead_buffer_map_;

@@ -246,5 +248,7 @@ class SnapshotHandler : public std::enable_shared_from_this<SnapshotHandler> {
    std::shared_ptr<IBlockServerOpener> block_server_opener_;
};

std::ostream& operator<<(std::ostream& os, MERGE_IO_TRANSITION value);

}  // namespace snapshot
}  // namespace android
Loading