diff options
author | Yabin Cui <yabinc@google.com> | 2024-04-05 19:18:33 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2024-04-05 19:18:33 +0000 |
commit | 57bad062b4c3047075cc80b69987d5572e88db12 (patch) | |
tree | 43dadef17508628430c0990b7d21ef8e88001707 | |
parent | c67e0b07edfd87617282c68dd01a60e71a1adff9 (diff) | |
parent | 2c928d6e89e6767a729540181a68a57e484813a0 (diff) | |
download | extras-57bad062b4c3047075cc80b69987d5572e88db12.tar.gz |
Merge "simpleperf: Suppress kernel module read warnings" into main
-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 |