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

Commit fa578a57 authored by Jin Qian's avatar Jin Qian Committed by android-build-merger
Browse files

storaged: read emmc health data from sysfs

am: 81970934

Change-Id: I728c61fc00de0848243cd002934c4c3a79660e88
parents 13bd93b7 81970934
Loading
Loading
Loading
Loading
+0 −1
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
+0 −6
Original line number Diff line number Diff line
@@ -230,7 +230,6 @@ public:
// Periodic chores intervals in seconds
#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 ( 3600 )
#define DEFAULT_PERIODIC_CHORES_INTERVAL_UID_IO_LIMIT (300)

@@ -240,7 +239,6 @@ public:
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_uid_io_available;      // whether uid_io is accessible
    bool diskstats_available;   // whether diskstats is accessible
@@ -253,7 +251,6 @@ private:
    storaged_config mConfig;
    disk_stats_publisher mDiskStats;
    disk_stats_monitor mDsm;
    storage_info_t *info = nullptr;
    uid_monitor mUidm;
    time_t mStarttime;
public:
@@ -264,9 +261,6 @@ public:
    void pause(void) {
        sleep(mConfig.periodic_chores_interval_unit);
    }
    void set_storage_info(storage_info_t *storage_info) {
        info = storage_info;
    }

    time_t get_starttime(void) {
        return mStarttime;
+15 −24
Original line number Diff line number Diff line
@@ -24,43 +24,34 @@ friend class test_case_name##_##test_name##_Test

using namespace std;

// two characters in string for each byte
struct str_hex {
    char str[2];
};

class storage_info_t {
protected:
    FRIEND_TEST(storaged_test, storage_info_t);
    uint8_t eol;                    // pre-eol (end of life) information
    uint8_t lifetime_a;             // device life time estimation (type A)
    uint8_t lifetime_b;             // device life time estimation (type B)
    uint16_t eol;                   // pre-eol (end of life) information
    uint16_t lifetime_a;            // device life time estimation (type A)
    uint16_t lifetime_b;            // device life time estimation (type B)
    string version;                 // version string
public:
    void publish();
public:
    storage_info_t() : eol(0), lifetime_a(0), lifetime_b(0) {}
    virtual ~storage_info_t() {}
    virtual bool init() = 0;
    virtual bool update() = 0;
    virtual bool report() = 0;
};

class emmc_info_t : public storage_info_t {
private:
    // minimum size of a ext_csd file
    const int EXT_CSD_FILE_MIN_SIZE = 1024;
    // List of interesting offsets
    const size_t EXT_CSD_REV_IDX = 192 * sizeof(str_hex);
    const size_t EXT_PRE_EOL_INFO_IDX = 267 * sizeof(str_hex);
    const size_t EXT_DEVICE_LIFE_TIME_EST_A_IDX = 268 * sizeof(str_hex);
    const size_t EXT_DEVICE_LIFE_TIME_EST_B_IDX = 269 * sizeof(str_hex);

    const char* ext_csd_file = "/d/mmc0/mmc0:0001/ext_csd";
    const char* emmc_ver_str[8] = {
        "4.0", "4.1", "4.2", "4.3", "Obsolete", "4.41", "4.5", "5.0"
    const string emmc_sysfs = "/sys/bus/mmc/devices/mmc0:0001/";
    const string emmc_debugfs = "/d/mmc0/mmc0:0001/ext_csd";
    const char* emmc_ver_str[9] = {
        "4.0", "4.1", "4.2", "4.3", "Obsolete", "4.41", "4.5", "5.0", "5.1"
    };
public:
    virtual ~emmc_info_t() {}
    bool init();
    bool update();
    bool report();
    bool report_sysfs();
    bool report_debugfs();
};

void report_storage_health();

#endif /* _STORAGED_INFO_H_ */
+1 −5
Original line number Diff line number Diff line
@@ -43,7 +43,6 @@
#include <storaged_utils.h>

storaged_t storaged;
emmc_info_t emmc_info;

// Function of storaged's main thread
void* storaged_main(void* s) {
@@ -114,10 +113,7 @@ int main(int argc, char** argv) {
    }

    if (flag_main_service) { // start main thread
        if (emmc_info.init()) {
            storaged.set_storage_info(&emmc_info);
        }

        report_storage_health();
        // Start the main thread of storaged
        pthread_t storaged_main_thread;
        errno = pthread_create(&storaged_main_thread, NULL, storaged_main, &storaged);
+0 −9
Original line number Diff line number Diff line
@@ -203,9 +203,6 @@ storaged_t::storaged_t(void) {
    mConfig.periodic_chores_interval_disk_stats_publish =
        property_get_int32("ro.storaged.disk_stats_pub", DEFAULT_PERIODIC_CHORES_INTERVAL_DISK_STATS_PUBLISH);

    mConfig.periodic_chores_interval_emmc_info_publish =
        property_get_int32("ro.storaged.emmc_info_pub", DEFAULT_PERIODIC_CHORES_INTERVAL_EMMC_INFO_PUBLISH);

    mConfig.periodic_chores_interval_uid_io =
        property_get_int32("ro.storaged.uid_io.interval", DEFAULT_PERIODIC_CHORES_INTERVAL_UID_IO);

@@ -221,12 +218,6 @@ void storaged_t::event(void) {
        }
    }

    if (info && mTimer &&
        (mTimer % mConfig.periodic_chores_interval_emmc_info_publish) == 0) {
        info->update();
        info->publish();
    }

    if (mConfig.proc_uid_io_available && mTimer &&
            (mTimer % mConfig.periodic_chores_interval_uid_io) == 0) {
         mUidm.report();
Loading