diff options
author | Yabin Cui <yabinc@google.com> | 2024-04-03 13:46:08 -0700 |
---|---|---|
committer | Yabin Cui <yabinc@google.com> | 2024-04-03 14:55:46 -0700 |
commit | 2c928d6e89e6767a729540181a68a57e484813a0 (patch) | |
tree | 1afffd321797f58cf2b103b4521c24fb7300d3ef /simpleperf | |
parent | 0744f4b1eb07920150f5561dfbcb38fb11b5b89c (diff) | |
download | extras-2c928d6e89e6767a729540181a68a57e484813a0.tar.gz |
simpleperf: Suppress kernel module read warnings
Kernel modules may come from vendor_kernel_ramdisk.img, which isn't
accessed from userspace. Kernel module symbols are also available in
/proc/kallsyms, making read-failure warnings unnecessary.
So suppress warnings when kernel modules can't be read.
Also update kernel module search locations in environment.cpp for
consistency.
Bug: none
Test: run simpleperf_unit_test
Test: run simpleperf manually
Change-Id: I1345cc02582617a24e31908d8b67da884932b24e
Diffstat (limited to 'simpleperf')
-rw-r--r-- | simpleperf/dso.cpp | 8 | ||||
-rw-r--r-- | simpleperf/dso_test.cpp | 3 | ||||
-rw-r--r-- | simpleperf/environment.cpp | 13 |
3 files changed, 18 insertions, 6 deletions
diff --git a/simpleperf/dso.cpp b/simpleperf/dso.cpp index 607bf7d8..1380ada9 100644 --- a/simpleperf/dso.cpp +++ b/simpleperf/dso.cpp @@ -875,8 +875,8 @@ class KernelModuleDso : public Dso { if (elf) { status = elf->ParseSymbols(symbol_callback); } - ReportReadElfSymbolResult(status, path_, GetDebugFilePath(), - symbols_.empty() ? android::base::WARNING : android::base::DEBUG); + // Don't warn when a kernel module is missing. As a backup, we read symbols from /proc/kallsyms. + ReportReadElfSymbolResult(status, path_, GetDebugFilePath(), android::base::DEBUG); SortAndFixSymbols(symbols); return symbols; } @@ -897,6 +897,10 @@ class KernelModuleDso : public Dso { // and its vaddr_in_file from the kernel module file. Then other symbols in .text section can // be mapped in the same way. Below we use the second method. + if (!IsRegularFile(GetDebugFilePath())) { + return; + } + // 1. Select a module symbol in /proc/kallsyms. kernel_dso_->LoadSymbols(); const auto& kernel_symbols = kernel_dso_->GetSymbols(); diff --git a/simpleperf/dso_test.cpp b/simpleperf/dso_test.cpp index f5280d32..f9199e41 100644 --- a/simpleperf/dso_test.cpp +++ b/simpleperf/dso_test.cpp @@ -294,8 +294,9 @@ TEST(dso, kernel_module_CalculateMinVaddr) { ASSERT_TRUE(kernel_dso); const uint64_t module_memory_start = 0xffffffa9bc790000ULL; const uint64_t module_memory_size = 0x8d7000ULL; + TemporaryFile tmpfile; auto module_dso = - Dso::CreateKernelModuleDso("fake_module.ko", module_memory_start, + Dso::CreateKernelModuleDso(tmpfile.path, module_memory_start, module_memory_start + module_memory_size, kernel_dso.get()); ASSERT_TRUE(module_dso); diff --git a/simpleperf/environment.cpp b/simpleperf/environment.cpp index 88587dc3..55074d8a 100644 --- a/simpleperf/environment.cpp +++ b/simpleperf/environment.cpp @@ -75,6 +75,9 @@ std::vector<int> GetOnlineCpus() { static void GetAllModuleFiles(const std::string& path, std::unordered_map<std::string, std::string>* module_file_map) { + if (!IsDir(path)) { + return; + } for (const auto& name : GetEntriesInDir(path)) { std::string entry_path = path + "/" + name; if (IsRegularFile(entry_path) && android::base::EndsWith(name, ".ko")) { @@ -94,9 +97,13 @@ static std::vector<KernelMmap> GetModulesInUse() { } std::unordered_map<std::string, std::string> module_file_map; #if defined(__ANDROID__) - // Search directories listed in "File locations" section in - // https://source.android.com/devices/architecture/kernel/modular-kernels. - for (const auto& path : {"/vendor/lib/modules", "/odm/lib/modules", "/lib/modules"}) { + // On Android, kernel modules are stored in /system/lib/modules, /vendor/lib/modules, + // /odm/lib/modules. + // See https://source.android.com/docs/core/architecture/partitions/gki-partitions and + // https://source.android.com/docs/core/architecture/partitions/vendor-odm-dlkm-partition. + // They can also be stored in vendor_kernel_ramdisk.img, which isn't accessible from userspace. + // See https://source.android.com/docs/core/architecture/kernel/kernel-module-support. + for (const auto& path : {"/system/lib/modules", "/vendor/lib/modules", "/odm/lib/modules"}) { GetAllModuleFiles(path, &module_file_map); } #else |