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

Commit 88ad33ef authored by Jin Qian's avatar Jin Qian
Browse files

storaged: remove task io code

Bug: 34612499
Change-Id: Id0599ee2ae025a186259e95363c1ddd0feae8079
parent 3790f5bf
Loading
Loading
Loading
Loading
+0 −33
Original line number Diff line number Diff line
@@ -123,28 +123,6 @@ public:
    }
};

class tasks_t {
private:
    FRIEND_TEST(storaged_test, tasks_t);
    sem_t mSem;
    // hashmap for all running tasks w/ pid as key
    std::unordered_map<uint32_t, struct task_info> mRunning;
    // hashmap for all tasks that have been killed (categorized by cmd) w/ cmd as key
    std::unordered_map<std::string, struct task_info> mOld;
    std::unordered_map<std::uint32_t, struct task_info> get_running_tasks();
public:
    tasks_t() {
        sem_init(&mSem, 0, 1); // TODO: constructor don't have a return value, what if sem_init fails
    }

    ~tasks_t() {
        sem_destroy(&mSem);
    }

    void update_running_tasks(void);
    std::vector<struct task_info> get_tasks(void);
};

class stream_stats {
private:
    double mSum;
@@ -282,7 +260,6 @@ struct storaged_config {
    int periodic_chores_interval_disk_stats_publish;
    int periodic_chores_interval_emmc_info_publish;
    int periodic_chores_interval_uid_io;
    bool proc_taskio_readable;  // are /proc/[pid]/{io, comm, cmdline, stat} all readable
    bool proc_uid_io_available;      // whether uid_io is accessible
    bool emmc_available;        // whether eMMC est_csd file is readable
    bool diskstats_available;   // whether diskstats is accessible
@@ -296,7 +273,6 @@ private:
    disk_stats_publisher mDiskStats;
    disk_stats_monitor mDsm;
    emmc_info_t mEmmcInfo;
    tasks_t mTasks;
    uid_monitor mUidm;
    time_t mStarttime;
public:
@@ -307,15 +283,6 @@ public:
    void pause(void) {
        sleep(mConfig.periodic_chores_interval_unit);
    }
    std::vector<struct task_info> get_tasks(void) {
        // There could be a race when get_tasks() and the main thread is updating at the same time
        // While update_running_tasks() is updating the critical sections at the end of the function
        // all together atomically, the final state of task_t can only be either the main thread's
        // update or this update. Since the race can only occur when both threads are updating
        // "simultaneously", either final state is acceptable.
        mTasks.update_running_tasks();
        return mTasks.get_tasks();
    }

    void set_privileged_fds(int fd_emmc) {
        mEmmcInfo.set_emmc_fd(fd_emmc);
+1 −5
Original line number Diff line number Diff line
@@ -30,11 +30,9 @@ using namespace android;
class IStoraged : public IInterface {
public:
    enum {
        DUMPTASKS = IBinder::FIRST_CALL_TRANSACTION,
        DUMPUIDS  = IBinder::FIRST_CALL_TRANSACTION + 1,
        DUMPUIDS  = IBinder::FIRST_CALL_TRANSACTION,
    };
    // Request the service to run the test function
    virtual std::vector<struct task_info> dump_tasks(const char* option) = 0;
    virtual std::vector<struct uid_info> dump_uids(const char* option) = 0;

    DECLARE_META_INTERFACE(Storaged);
@@ -44,7 +42,6 @@ public:
class BpStoraged : public BpInterface<IStoraged> {
public:
    BpStoraged(const sp<IBinder>& impl) : BpInterface<IStoraged>(impl){};
    virtual std::vector<struct task_info> dump_tasks(const char* option);
    virtual std::vector<struct uid_info> dump_uids(const char* option);
};

@@ -54,7 +51,6 @@ class BnStoraged : public BnInterface<IStoraged> {
};

class Storaged : public BnStoraged {
    virtual std::vector<struct task_info> dump_tasks(const char* option);
    virtual std::vector<struct uid_info> dump_uids(const char* option);
};

+0 −4
Original line number Diff line number Diff line
@@ -31,14 +31,10 @@ struct disk_stats get_inc_disk_stats(struct disk_stats* prev, struct disk_stats*
void add_disk_stats(struct disk_stats* src, struct disk_stats* dst);
bool parse_emmc_ecsd(int ext_csd_fd, struct emmc_info* info);

// Task I/O
bool parse_task_info(uint32_t pid, struct task_info* info);
void sort_running_tasks_info(std::vector<struct task_info> &tasks);
// UID I/O
void sort_running_uids_info(std::vector<struct uid_info> &uids);

// Logging
void log_console_running_tasks_info(std::vector<struct task_info> tasks);
void log_console_running_uids_info(std::vector<struct uid_info> uids);

void log_debug_disk_perf(struct disk_perf* perf, const char* type);
+2 −41
Original line number Diff line number Diff line
@@ -61,8 +61,7 @@ static int drop_privs() {
    if (cap_clear(caps.get()) < 0) return -1;
    cap_value_t cap_value[] = {
        CAP_SETGID,
        CAP_SETUID,
        CAP_SYS_PTRACE // allow access to proc/<pid>/io as non-root user
        CAP_SETUID
    };
    if (cap_set_flag(caps.get(), CAP_PERMITTED,
                     arraysize(cap_value), cap_value,
@@ -73,10 +72,6 @@ static int drop_privs() {
    if (cap_set_proc(caps.get()) < 0)
        return -1;

    gid_t groups[] = { AID_READPROC };

    if (setgroups(sizeof(groups) / sizeof(groups[0]), groups) == -1) return -1;

    if (setgid(AID_SYSTEM) != 0) return -1;

    if (setuid(AID_SYSTEM) != 0) return -1;
@@ -104,7 +99,6 @@ void* storaged_main(void* s) {

static void help_message(void) {
    printf("usage: storaged [OPTION]\n");
    printf("  -d    --dump                  Dump task I/O usage to stdout\n");
    printf("  -u    --uid                   Dump uid I/O usage to stdout\n");
    printf("  -s    --start                 Start storaged (default)\n");
    fflush(stdout);
@@ -115,7 +109,6 @@ static void help_message(void) {

int main(int argc, char** argv) {
    int flag_main_service = 0;
    int flag_dump_task = 0;
    int flag_dump_uid = 0;
    int fd_emmc = -1;
    int opt;
@@ -125,7 +118,6 @@ int main(int argc, char** argv) {
        static struct option long_options[] = {
            {"start",       no_argument,        0, 's'},
            {"kill",        no_argument,        0, 'k'},
            {"dump",        no_argument,        0, 'd'},
            {"uid",         no_argument,        0, 'u'},
            {"help",        no_argument,        0, 'h'}
        };
@@ -138,9 +130,6 @@ int main(int argc, char** argv) {
        case 's':
            flag_main_service = 1;
            break;
        case 'd':
            flag_dump_task = 1;
            break;
        case 'u':
            flag_dump_uid = 1;
            break;
@@ -159,7 +148,7 @@ int main(int argc, char** argv) {
        flag_main_service = 1;
    }

    if (flag_main_service && flag_dump_task) {
    if (flag_main_service && flag_dump_uid) {
        fprintf(stderr, "Invalid arguments. Option \"start\" and \"dump\" cannot be used together.\n");
        help_message();
        return -1;
@@ -195,34 +184,6 @@ int main(int argc, char** argv) {
        return 0;
    }

    if (flag_dump_task) {
        sp<IStoraged> storaged_service = get_storaged_service();
        if (storaged_service == NULL) {
            fprintf(stderr, "Cannot find storaged service.\nMaybe run storaged --start first?\n");
            return -1;
        }
        std::vector<struct task_info> res = storaged_service->dump_tasks(NULL);

        if (res.size() == 0) {
            fprintf(stderr, "Task I/O is not readable in this version of kernel.\n");
            return 0;
        }

        time_t starttime = storaged.get_starttime();

        if (starttime == (time_t)-1) {
            fprintf(stderr, "Unknown start time\n");
        } else {
            char* time_str = ctime(&starttime);
            printf("Application I/O was collected by storaged since %s", time_str);
        }

        sort_running_tasks_info(res);
        log_console_running_tasks_info(res);

        return 0;
    }

    if (flag_dump_uid) {
        sp<IStoraged> storaged_service = get_storaged_service();
        if (storaged_service == NULL) {
+0 −15
Original line number Diff line number Diff line
@@ -166,15 +166,6 @@ storaged_t::storaged_t(void) {
        mConfig.diskstats_available = true;
    }

    mConfig.proc_taskio_readable = true;
    const char* test_paths[] = {"/proc/1/io", "/proc/1/comm", "/proc/1/cmdline", "/proc/1/stat"};
    for (uint i = 0; i < sizeof(test_paths) / sizeof(const char*); ++i) {
        if (access(test_paths[i], R_OK) < 0) {
            mConfig.proc_taskio_readable = false;
            break;
        }
    }

    mConfig.proc_uid_io_available = (access(UID_IO_STATS_PATH, R_OK) == 0);

    mConfig.periodic_chores_interval_unit =
@@ -205,12 +196,6 @@ void storaged_t::event(void) {
        }
    }

#ifdef DEBUG
    if (mConfig.proc_taskio_readable) {
        mTasks.update_running_tasks();
    }
#endif

    if (mConfig.emmc_available && mTimer &&
            (mTimer % mConfig.periodic_chores_interval_emmc_info_publish) == 0) {
        mEmmcInfo.update();
Loading