diff --git a/led/Android.bp b/led/Android.bp new file mode 100644 index 0000000..6e15ac5 --- /dev/null +++ b/led/Android.bp @@ -0,0 +1,18 @@ +package { + default_applicable_licenses: ["Android-Apache-2.0"], +} + +cc_binary { + name: "dump_led", + srcs: ["dump_led.cpp"], + cflags: [ + "-Wall", + "-Wextra", + "-Werror", + ], + shared_libs: [ + "libdump", + ], + vendor: true, + relative_install_path: "dump", +} diff --git a/led/dump_led.cpp b/led/dump_led.cpp new file mode 100644 index 0000000..7ce4846 --- /dev/null +++ b/led/dump_led.cpp @@ -0,0 +1,24 @@ +/* + * Copyright 2022 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. + */ + +#include + +int main() { + dumpFileContent("Green LED Brightness", "/sys/class/leds/green/brightness"); + dumpFileContent("Green LED Max Brightness", "/sys/class/leds/green/max_brightness"); + dumpFileContent("LED Calibration Data", "/mnt/vendor/persist/led/led_calibration_LUT.txt"); + return 0; +} diff --git a/led/led.mk b/led/led.mk new file mode 100644 index 0000000..81d0f33 --- /dev/null +++ b/led/led.mk @@ -0,0 +1,3 @@ +BOARD_VENDOR_SEPOLICY_DIRS += device/google/gs-common/led/sepolicy + +PRODUCT_PACKAGES_DEBUG += dump_led diff --git a/led/sepolicy/dump_led.te b/led/sepolicy/dump_led.te new file mode 100644 index 0000000..b1ba1ef --- /dev/null +++ b/led/sepolicy/dump_led.te @@ -0,0 +1,9 @@ +pixel_bugreport(dump_led) + +allow dump_led mnt_vendor_file:dir search; +allow dump_led persist_file:dir search; +allow dump_led persist_leds_file:dir search; +allow dump_led persist_leds_file:file r_file_perms; +allow dump_led sysfs_leds:dir search; +allow dump_led sysfs_leds:file r_file_perms; + diff --git a/led/sepolicy/file.te b/led/sepolicy/file.te new file mode 100644 index 0000000..7fda883 --- /dev/null +++ b/led/sepolicy/file.te @@ -0,0 +1,2 @@ +type persist_leds_file, file_type, vendor_persist_type; + diff --git a/led/sepolicy/file_contexts b/led/sepolicy/file_contexts new file mode 100644 index 0000000..1b006cf --- /dev/null +++ b/led/sepolicy/file_contexts @@ -0,0 +1,4 @@ +/vendor/bin/dump/dump_led u:object_r:dump_led_exec:s0 + +/mnt/vendor/persist/led(/.*)? u:object_r:persist_leds_file:s0 + diff --git a/powerstats/CpupmStateResidencyDataProvider.cpp b/powerstats/CpupmStateResidencyDataProvider.cpp index c963f78..2adae54 100644 --- a/powerstats/CpupmStateResidencyDataProvider.cpp +++ b/powerstats/CpupmStateResidencyDataProvider.cpp @@ -34,8 +34,14 @@ namespace power { namespace stats { CpupmStateResidencyDataProvider::CpupmStateResidencyDataProvider( - const std::string &path, const Config &config) - : mPath(std::move(path)), mConfig(std::move(config)) {} + const std::string &path, + const Config &config, + const std::string &sleepPath, + const SleepConfig &sleepConfig) + : mPath(std::move(path)), + mConfig(std::move(config)), + mSleepPath(std::move(sleepPath)), + mSleepConfig(std::move(sleepConfig)) {} int32_t CpupmStateResidencyDataProvider::matchState(char const *line) { for (int32_t i = 0; i < mConfig.states.size(); i++) { @@ -78,6 +84,12 @@ bool CpupmStateResidencyDataProvider::getStateResidencies( return false; } + std::unique_ptr sleepFp(fopen(mSleepPath.c_str(), "r"), fclose); + if (!sleepFp) { + PLOG(ERROR) << __func__ << ":Failed to open file " << mSleepPath; + return false; + } + for (int32_t i = 0; i < mConfig.entities.size(); i++) { std::vector stateResidencies(mConfig.states.size()); for (int32_t j = 0; j < stateResidencies.size(); j++) { @@ -90,9 +102,29 @@ bool CpupmStateResidencyDataProvider::getStateResidencies( char *line = nullptr; int32_t temp, entityIndex, stateId = -1; - uint64_t duration, count; + uint64_t duration, count, sleepDurationMs = 0; auto it = residencies->end(); + int32_t sleepIndex = 0; + // Parse state for sleep duration + while (getline(&line, &len, sleepFp.get()) != -1) { + std::string trimedLine = Trim(std::string(line)); + if (StartsWith(trimedLine, mSleepConfig[sleepIndex])) { + if (sleepIndex < mSleepConfig.size() - 1) { + sleepIndex++; + continue; + } else { + std::vector parts = Split(trimedLine, " "); + if (parts.size() == 2) { + ParseUint(parts[1], &sleepDurationMs); + sleepDurationMs /= NS_TO_MS; + } + break; + } + } + } + + // Parse state for CPUPM entities while (getline(&line, &len, fp.get()) != -1) { temp = matchState(line); // Assign new id only when a new valid state is encountered. @@ -109,7 +141,7 @@ bool CpupmStateResidencyDataProvider::getStateResidencies( it = residencies->find(mConfig.entities[entityIndex].first); if (it != residencies->end()) { if (parseState(line, &duration, &count)) { - it->second[stateId].totalTimeInStateMs = duration / US_TO_MS; + it->second[stateId].totalTimeInStateMs = duration / US_TO_MS + sleepDurationMs; it->second[stateId].totalStateEntryCount = count; } else { LOG(ERROR) << "Failed to parse duration and count from [" << std::string(line) diff --git a/powerstats/include/CpupmStateResidencyDataProvider.h b/powerstats/include/CpupmStateResidencyDataProvider.h index c04e11e..be8ee46 100644 --- a/powerstats/include/CpupmStateResidencyDataProvider.h +++ b/powerstats/include/CpupmStateResidencyDataProvider.h @@ -34,10 +34,16 @@ class CpupmStateResidencyDataProvider : public PowerStats::IStateResidencyDataPr std::vector> states; }; + typedef std::vector SleepConfig; + /* * path - path to cpupm sysfs node. */ - CpupmStateResidencyDataProvider(const std::string &path, const Config &config); + CpupmStateResidencyDataProvider( + const std::string &path, + const Config &config, + const std::string &sleepPath, + const SleepConfig &sleepConfig); ~CpupmStateResidencyDataProvider() = default; /* @@ -58,9 +64,13 @@ class CpupmStateResidencyDataProvider : public PowerStats::IStateResidencyDataPr // A constant to represent the number of microseconds in one millisecond. const uint64_t US_TO_MS = 1000; + // A constant to represent the number of nanoseconds in one millisecond. + const uint64_t NS_TO_MS = 1000000; const std::string mPath; const Config mConfig; + const std::string mSleepPath; + const SleepConfig mSleepConfig; }; } // namespace stats diff --git a/soc/Android.bp b/soc/Android.bp index 9600855..57b8577 100644 --- a/soc/Android.bp +++ b/soc/Android.bp @@ -2,6 +2,13 @@ package { default_applicable_licenses: ["Android-Apache-2.0"], } +sh_binary { + name: "dump_memory.sh", + src: "dump_memory.sh", + vendor: true, + sub_dir: "dump", +} + cc_binary { name: "dump_soc", srcs: ["dump_soc.cpp"], diff --git a/soc/dump_memory.sh b/soc/dump_memory.sh new file mode 100644 index 0000000..5f4bde7 --- /dev/null +++ b/soc/dump_memory.sh @@ -0,0 +1,22 @@ +#!/vendor/bin/sh +echo "------ ION HEAPS ------" +for d in $(ls -d /d/ion/*) +do + if [ -f $d ]; then + echo --- $d + cat $d + else + for f in $(ls $d) + do + echo --- $d/$f + cat $d/$f + done + fi +done + +echo "------ dmabuf info ------" +cat "/d/dma_buf/bufinfo" + +echo "------ Page Pinner - longterm pin ------" +cat "/sys/kernel/debug/page_pinner/buffer" + diff --git a/soc/sepolicy/dump_memory.te b/soc/sepolicy/dump_memory.te new file mode 100644 index 0000000..47f9f07 --- /dev/null +++ b/soc/sepolicy/dump_memory.te @@ -0,0 +1,8 @@ +pixel_bugreport(dump_memory) +allow dump_memory vendor_toolbox_exec:file execute_no_trans; +userdebug_or_eng(` + allow dump_memory vendor_dmabuf_debugfs:file r_file_perms; + allow dump_memory vendor_page_pinner_debugfs:dir r_dir_perms; + allow dump_memory vendor_page_pinner_debugfs:file r_file_perms; +') + diff --git a/soc/sepolicy/dumpstate.te b/soc/sepolicy/dumpstate.te new file mode 100644 index 0000000..1d23bb4 --- /dev/null +++ b/soc/sepolicy/dumpstate.te @@ -0,0 +1,2 @@ +dontaudit dumpstate vendor_dmabuf_debugfs:file r_file_perms; + diff --git a/soc/sepolicy/file.te b/soc/sepolicy/file.te new file mode 100644 index 0000000..553825a --- /dev/null +++ b/soc/sepolicy/file.te @@ -0,0 +1,3 @@ +type vendor_dmabuf_debugfs, fs_type, debugfs_type; +type vendor_page_pinner_debugfs, fs_type, debugfs_type; + diff --git a/soc/sepolicy/file_contexts b/soc/sepolicy/file_contexts index 81b1e68..23a91e5 100644 --- a/soc/sepolicy/file_contexts +++ b/soc/sepolicy/file_contexts @@ -1 +1,3 @@ -/vendor/bin/dump/dump_soc u:object_r:dump_soc_exec:s0 +/vendor/bin/dump/dump_soc u:object_r:dump_soc_exec:s0 +/vendor/bin/dump/dump_memory\.sh u:object_r:dump_memory_exec:s0 + diff --git a/soc/sepolicy/genfs_contexts b/soc/sepolicy/genfs_contexts index 07ae4b8..454ab6a 100644 --- a/soc/sepolicy/genfs_contexts +++ b/soc/sepolicy/genfs_contexts @@ -5,3 +5,6 @@ genfscon sysfs /devices/system/chip-id/product_id u:object_r:sysfs_chip_id: genfscon sysfs /devices/system/chip-id/revision u:object_r:sysfs_chip_id:s0 genfscon sysfs /devices/system/chip-id/raw_str u:object_r:sysfs_chip_id:s0 +genfscon debugfs /dma_buf/bufinfo u:object_r:vendor_dmabuf_debugfs:s0 +genfscon debugfs /page_pinner u:object_r:vendor_page_pinner_debugfs:s0 + diff --git a/soc/soc.mk b/soc/soc.mk index 75b134e..b9b6208 100644 --- a/soc/soc.mk +++ b/soc/soc.mk @@ -1,3 +1,5 @@ BOARD_VENDOR_SEPOLICY_DIRS += device/google/gs-common/soc/sepolicy PRODUCT_PACKAGES += dump_soc +PRODUCT_PACKAGES_DEBUG += dump_memory.sh + diff --git a/storage/dumpstate.te b/storage/dumpstate.te new file mode 100644 index 0000000..2c01193 --- /dev/null +++ b/storage/dumpstate.te @@ -0,0 +1 @@ +allow dumpstate sysfs_scsi_devices_0000:file r_file_perms; \ No newline at end of file diff --git a/storage/sepolicy/hal_health_storage_default.te b/storage/sepolicy/hal_health_storage_default.te new file mode 100644 index 0000000..af6593a --- /dev/null +++ b/storage/sepolicy/hal_health_storage_default.te @@ -0,0 +1,3 @@ +# Access to /sys/devices/platform/*ufs/* +allow hal_health_storage_default sysfs_scsi_devices_0000:dir r_dir_perms; +allow hal_health_storage_default sysfs_scsi_devices_0000:file rw_file_perms; diff --git a/storage/sepolicy/init.te b/storage/sepolicy/init.te new file mode 100644 index 0000000..7070318 --- /dev/null +++ b/storage/sepolicy/init.te @@ -0,0 +1 @@ +allow init sysfs_scsi_devices_0000:file w_file_perms; diff --git a/storage/sepolicy/vold.te b/storage/sepolicy/vold.te new file mode 100644 index 0000000..1d743b5 --- /dev/null +++ b/storage/sepolicy/vold.te @@ -0,0 +1,4 @@ +allow vold sysfs_scsi_devices_0000:file rw_file_perms; + +dontaudit vold dumpstate:fifo_file rw_file_perms; +dontaudit vold dumpstate:fd use ;