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

Commit a867efae authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes Id0599ee2,I01f64c84

* changes:
  storaged: remove task io code
  storaged: replace cmd arguments with properties
parents 314bb2fa 88ad33ef
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
ro.storaged.event.interval    # interval storaged scans for IO stats, in seconds
ro.storaged.event.perf_check  # check for time spent in event loop, in microseconds
ro.storaged.disk_stats_pub    # interval storaged publish disk stats, in seconds
ro.storaged.emmc_info_pub     # interval storaged publish emmc info, in seconds
ro.storaged.uid_io.interval   # interval storaged checks Per UID IO usage, in seconds
ro.storaged.uid_io.threshold  # Per UID IO usage limit, in bytes
+12 −46
Original line number Diff line number Diff line
@@ -40,6 +40,12 @@ friend class test_case_name##_##test_name##_Test
#define debuginfo(...)
#endif

#define SECTOR_SIZE ( 512 )
#define SEC_TO_MSEC ( 1000 )
#define MSEC_TO_USEC ( 1000 )
#define USEC_TO_NSEC ( 1000 )
#define SEC_TO_USEC ( 1000000 )

// number of attributes diskstats has
#define DISK_STATS_SIZE ( 11 )
// maximum size limit of a stats file
@@ -117,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;
@@ -266,17 +250,20 @@ public:
#define DEFAULT_PERIODIC_CHORES_INTERVAL_UNIT ( 60 )
#define DEFAULT_PERIODIC_CHORES_INTERVAL_DISK_STATS_PUBLISH ( 3600 )
#define DEFAULT_PERIODIC_CHORES_INTERVAL_EMMC_INFO_PUBLISH ( 86400 )
#define DEFAULT_PERIODIC_CHORES_INTERVAL_UID_IO_ALERT ( 3600 )
#define DEFAULT_PERIODIC_CHORES_INTERVAL_UID_IO ( 3600 )

// UID IO threshold in bytes
#define DEFAULT_PERIODIC_CHORES_UID_IO_THRESHOLD ( 1024 * 1024 * 1024ULL )

struct storaged_config {
    int periodic_chores_interval_unit;
    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
    int event_time_check_usec;  // check how much cputime spent in event loop
};

class storaged_t {
@@ -286,37 +273,16 @@ private:
    disk_stats_publisher mDiskStats;
    disk_stats_monitor mDsm;
    emmc_info_t mEmmcInfo;
    tasks_t mTasks;
    uid_monitor mUidm;
    time_t mStarttime;
public:
    storaged_t(void);
    ~storaged_t() {}
    void event(void);
    void event_checked(void);
    void pause(void) {
        sleep(mConfig.periodic_chores_interval_unit);
    }
    void set_unit_interval(int unit) {
        mConfig.periodic_chores_interval_unit = unit;
    }
    void set_diskstats_interval(int disk_stats) {
        mConfig.periodic_chores_interval_disk_stats_publish = disk_stats;
    }
    void set_emmc_interval(int emmc_info) {
        mConfig.periodic_chores_interval_emmc_info_publish = emmc_info;
    }
    void set_uid_io_interval(int uid_io) {
        mUidm.set_periodic_chores_interval(uid_io);
    }
    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);
};

+3 −2
Original line number Diff line number Diff line
@@ -47,10 +47,11 @@ private:
    std::unordered_map<uint32_t, struct uid_info> last_uids;
    void set_last_uids(std::unordered_map<uint32_t, struct uid_info>&& uids, uint64_t ts);
    int interval;  // monitor interval in seconds
    int threshold; // monitor threshold in bytes
    uint64_t last_report_ts; // timestamp of last report in nsec
public:
    uid_monitor();
    void set_periodic_chores_interval(int t) { interval = t; }
    void set_periodic_chores_params(int intvl, int thold) { interval = intvl; threshold = thold; }
    int get_periodic_chores_interval() { return interval; }
    std::unordered_map<uint32_t, struct uid_info> get_uids();
    void report();
+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);
Loading