Loading storaged/Android.mk +1 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ include $(CLEAR_VARS) LOCAL_SRC_FILES := \ storaged.cpp \ storaged_info.cpp \ storaged_service.cpp \ storaged_utils.cpp \ storaged_uid_monitor.cpp \ Loading storaged/include/storaged.h +7 −33 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ #include <batteryservice/IBatteryPropertiesListener.h> #include "storaged_info.h" #include "storaged_uid_monitor.h" using namespace android; Loading @@ -44,6 +45,8 @@ friend class test_case_name##_##test_name##_Test #define debuginfo(...) #endif #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) #define SECTOR_SIZE ( 512 ) #define SEC_TO_MSEC ( 1000 ) #define MSEC_TO_USEC ( 1000 ) Loading Loading @@ -83,15 +86,7 @@ struct disk_stats { double io_avg; // average io_in_flight for accumulate calculations }; #define MMC_VER_STR_LEN ( 9 ) // maximum length of the MMC version string, including NULL terminator // minimum size of a ext_csd file #define EXT_CSD_FILE_MIN_SIZE ( 1024 ) struct emmc_info { int eol; // pre-eol (end of life) information int lifetime_a; // device life time estimation (type A) int lifetime_b; // device life time estimation (type B) char mmc_ver[MMC_VER_STR_LEN]; // device version string }; struct disk_perf { uint32_t read_perf; // read speed (kbytes/s) Loading Loading @@ -232,26 +227,6 @@ public: void update(void); }; class emmc_info_t { private: struct emmc_info mInfo; bool mValid; int mFdEmmc; public: emmc_info_t(void) : mValid(false), mFdEmmc(-1) { memset(&mInfo, 0, sizeof(struct emmc_info)); } ~emmc_info_t(void) {} void publish(void); void update(void); void set_emmc_fd(int fd) { mFdEmmc = fd; } }; // Periodic chores intervals in seconds #define DEFAULT_PERIODIC_CHORES_INTERVAL_UNIT ( 60 ) #define DEFAULT_PERIODIC_CHORES_INTERVAL_DISK_STATS_PUBLISH ( 3600 ) Loading @@ -268,7 +243,6 @@ struct storaged_config { int periodic_chores_interval_emmc_info_publish; int periodic_chores_interval_uid_io; 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 }; Loading @@ -279,7 +253,7 @@ private: storaged_config mConfig; disk_stats_publisher mDiskStats; disk_stats_monitor mDsm; emmc_info_t mEmmcInfo; storage_info_t *info = nullptr; uid_monitor mUidm; time_t mStarttime; public: Loading @@ -290,8 +264,8 @@ public: void pause(void) { sleep(mConfig.periodic_chores_interval_unit); } void set_privileged_fds(int fd_emmc) { mEmmcInfo.set_emmc_fd(fd_emmc); void set_storage_info(storage_info_t *storage_info) { info = storage_info; } time_t get_starttime(void) { Loading storaged/include/storaged_info.h 0 → 100644 +66 −0 Original line number Diff line number Diff line /* * Copyright (C) 2017 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _STORAGED_INFO_H_ #define _STORAGED_INFO_H_ #include <string.h> #define FRIEND_TEST(test_case_name, test_name) \ 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) string version; // version string public: void publish(); virtual ~storage_info_t() {} virtual bool init() = 0; virtual bool update() = 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" }; public: virtual ~emmc_info_t() {} bool init(); bool update(); }; #endif /* _STORAGED_INFO_H_ */ storaged/main.cpp +4 −9 Original line number Diff line number Diff line Loading @@ -43,6 +43,7 @@ #include <storaged_utils.h> storaged_t storaged; emmc_info_t emmc_info; // Function of storaged's main thread void* storaged_main(void* s) { Loading @@ -69,7 +70,6 @@ static void help_message(void) { int main(int argc, char** argv) { int flag_main_service = 0; int flag_dump_uid = 0; int fd_emmc = -1; int opt; for (;;) { Loading Loading @@ -114,12 +114,9 @@ int main(int argc, char** argv) { } if (flag_main_service) { // start main thread static const char mmc0_ext_csd[] = "/d/mmc0/mmc0:0001/ext_csd"; fd_emmc = android_get_control_file(mmc0_ext_csd); if (fd_emmc < 0) fd_emmc = TEMP_FAILURE_RETRY(open(mmc0_ext_csd, O_RDONLY)); storaged.set_privileged_fds(fd_emmc); if (emmc_info.init()) { storaged.set_storage_info(&emmc_info); } // Start the main thread of storaged pthread_t storaged_main_thread; Loading @@ -134,8 +131,6 @@ int main(int argc, char** argv) { IPCThreadState::self()->joinThreadPool(); pthread_join(storaged_main_thread, NULL); close(fd_emmc); return 0; } Loading storaged/storaged.cpp +4 −19 Original line number Diff line number Diff line Loading @@ -147,19 +147,6 @@ void disk_stats_monitor::update(void) { } } /* emmc_info_t */ void emmc_info_t::publish(void) { if (mValid) { log_event_emmc_info(&mInfo); } } void emmc_info_t::update(void) { if (mFdEmmc >= 0) { mValid = parse_emmc_ecsd(mFdEmmc, &mInfo); } } static sp<IBatteryPropertiesRegistrar> get_battery_properties_service() { sp<IServiceManager> sm = defaultServiceManager(); if (sm == NULL) return NULL; Loading Loading @@ -199,8 +186,6 @@ void storaged_t::init_battery_service() { /* storaged_t */ storaged_t::storaged_t(void) { mConfig.emmc_available = (access(EMMC_ECSD_PATH, R_OK) >= 0); if (access(MMC_DISK_STATS_PATH, R_OK) < 0 && access(SDA_DISK_STATS_PATH, R_OK) < 0) { mConfig.diskstats_available = false; } else { Loading Loading @@ -236,10 +221,10 @@ void storaged_t::event(void) { } } if (mConfig.emmc_available && mTimer && if (info && mTimer && (mTimer % mConfig.periodic_chores_interval_emmc_info_publish) == 0) { mEmmcInfo.update(); mEmmcInfo.publish(); info->update(); info->publish(); } if (mConfig.proc_uid_io_available && mTimer && Loading Loading
storaged/Android.mk +1 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ include $(CLEAR_VARS) LOCAL_SRC_FILES := \ storaged.cpp \ storaged_info.cpp \ storaged_service.cpp \ storaged_utils.cpp \ storaged_uid_monitor.cpp \ Loading
storaged/include/storaged.h +7 −33 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ #include <batteryservice/IBatteryPropertiesListener.h> #include "storaged_info.h" #include "storaged_uid_monitor.h" using namespace android; Loading @@ -44,6 +45,8 @@ friend class test_case_name##_##test_name##_Test #define debuginfo(...) #endif #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) #define SECTOR_SIZE ( 512 ) #define SEC_TO_MSEC ( 1000 ) #define MSEC_TO_USEC ( 1000 ) Loading Loading @@ -83,15 +86,7 @@ struct disk_stats { double io_avg; // average io_in_flight for accumulate calculations }; #define MMC_VER_STR_LEN ( 9 ) // maximum length of the MMC version string, including NULL terminator // minimum size of a ext_csd file #define EXT_CSD_FILE_MIN_SIZE ( 1024 ) struct emmc_info { int eol; // pre-eol (end of life) information int lifetime_a; // device life time estimation (type A) int lifetime_b; // device life time estimation (type B) char mmc_ver[MMC_VER_STR_LEN]; // device version string }; struct disk_perf { uint32_t read_perf; // read speed (kbytes/s) Loading Loading @@ -232,26 +227,6 @@ public: void update(void); }; class emmc_info_t { private: struct emmc_info mInfo; bool mValid; int mFdEmmc; public: emmc_info_t(void) : mValid(false), mFdEmmc(-1) { memset(&mInfo, 0, sizeof(struct emmc_info)); } ~emmc_info_t(void) {} void publish(void); void update(void); void set_emmc_fd(int fd) { mFdEmmc = fd; } }; // Periodic chores intervals in seconds #define DEFAULT_PERIODIC_CHORES_INTERVAL_UNIT ( 60 ) #define DEFAULT_PERIODIC_CHORES_INTERVAL_DISK_STATS_PUBLISH ( 3600 ) Loading @@ -268,7 +243,6 @@ struct storaged_config { int periodic_chores_interval_emmc_info_publish; int periodic_chores_interval_uid_io; 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 }; Loading @@ -279,7 +253,7 @@ private: storaged_config mConfig; disk_stats_publisher mDiskStats; disk_stats_monitor mDsm; emmc_info_t mEmmcInfo; storage_info_t *info = nullptr; uid_monitor mUidm; time_t mStarttime; public: Loading @@ -290,8 +264,8 @@ public: void pause(void) { sleep(mConfig.periodic_chores_interval_unit); } void set_privileged_fds(int fd_emmc) { mEmmcInfo.set_emmc_fd(fd_emmc); void set_storage_info(storage_info_t *storage_info) { info = storage_info; } time_t get_starttime(void) { Loading
storaged/include/storaged_info.h 0 → 100644 +66 −0 Original line number Diff line number Diff line /* * Copyright (C) 2017 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _STORAGED_INFO_H_ #define _STORAGED_INFO_H_ #include <string.h> #define FRIEND_TEST(test_case_name, test_name) \ 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) string version; // version string public: void publish(); virtual ~storage_info_t() {} virtual bool init() = 0; virtual bool update() = 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" }; public: virtual ~emmc_info_t() {} bool init(); bool update(); }; #endif /* _STORAGED_INFO_H_ */
storaged/main.cpp +4 −9 Original line number Diff line number Diff line Loading @@ -43,6 +43,7 @@ #include <storaged_utils.h> storaged_t storaged; emmc_info_t emmc_info; // Function of storaged's main thread void* storaged_main(void* s) { Loading @@ -69,7 +70,6 @@ static void help_message(void) { int main(int argc, char** argv) { int flag_main_service = 0; int flag_dump_uid = 0; int fd_emmc = -1; int opt; for (;;) { Loading Loading @@ -114,12 +114,9 @@ int main(int argc, char** argv) { } if (flag_main_service) { // start main thread static const char mmc0_ext_csd[] = "/d/mmc0/mmc0:0001/ext_csd"; fd_emmc = android_get_control_file(mmc0_ext_csd); if (fd_emmc < 0) fd_emmc = TEMP_FAILURE_RETRY(open(mmc0_ext_csd, O_RDONLY)); storaged.set_privileged_fds(fd_emmc); if (emmc_info.init()) { storaged.set_storage_info(&emmc_info); } // Start the main thread of storaged pthread_t storaged_main_thread; Loading @@ -134,8 +131,6 @@ int main(int argc, char** argv) { IPCThreadState::self()->joinThreadPool(); pthread_join(storaged_main_thread, NULL); close(fd_emmc); return 0; } Loading
storaged/storaged.cpp +4 −19 Original line number Diff line number Diff line Loading @@ -147,19 +147,6 @@ void disk_stats_monitor::update(void) { } } /* emmc_info_t */ void emmc_info_t::publish(void) { if (mValid) { log_event_emmc_info(&mInfo); } } void emmc_info_t::update(void) { if (mFdEmmc >= 0) { mValid = parse_emmc_ecsd(mFdEmmc, &mInfo); } } static sp<IBatteryPropertiesRegistrar> get_battery_properties_service() { sp<IServiceManager> sm = defaultServiceManager(); if (sm == NULL) return NULL; Loading Loading @@ -199,8 +186,6 @@ void storaged_t::init_battery_service() { /* storaged_t */ storaged_t::storaged_t(void) { mConfig.emmc_available = (access(EMMC_ECSD_PATH, R_OK) >= 0); if (access(MMC_DISK_STATS_PATH, R_OK) < 0 && access(SDA_DISK_STATS_PATH, R_OK) < 0) { mConfig.diskstats_available = false; } else { Loading Loading @@ -236,10 +221,10 @@ void storaged_t::event(void) { } } if (mConfig.emmc_available && mTimer && if (info && mTimer && (mTimer % mConfig.periodic_chores_interval_emmc_info_publish) == 0) { mEmmcInfo.update(); mEmmcInfo.publish(); info->update(); info->publish(); } if (mConfig.proc_uid_io_available && mTimer && Loading