From 9e269cfc83fa2568b1424192a69064ccef2a8903 Mon Sep 17 00:00:00 2001 From: Yury Khmel Date: Thu, 18 May 2023 14:31:05 -0700 Subject: arc: Fix CTS tests for grunt Waiting loop has 1us delay waiting for requested changes are propagated. This is too aggressive and Grunt and other low-end devices may have no chance to react in specific timeout. Bug: 265675811 Test: cts-tradefed run commandAndExit cts -m CtsSimpleperfTestCases Most tests are now passing: Total Tests : 540 PASSED : 528 FAILED : 12 Change-Id: Ida041674c2fea425e6d267ee6a973208da00ed71 --- simpleperf/environment.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/simpleperf/environment.cpp b/simpleperf/environment.cpp index 5b2fcaa8..4cc47914 100644 --- a/simpleperf/environment.cpp +++ b/simpleperf/environment.cpp @@ -388,9 +388,10 @@ bool SetPerfEventLimits(uint64_t sample_freq, size_t cpu_percent, uint64_t mlock } // Wait for init process to change perf event limits based on properties. const size_t max_wait_us = 3 * 1000000; + const size_t interval_us = 10000; int finish_mask = 0; - for (size_t i = 0; i < max_wait_us && finish_mask != 7; ++i) { - usleep(1); // Wait 1us to avoid busy loop. + for (size_t i = 0; i < max_wait_us && finish_mask != 7; i += interval_us) { + usleep(interval_us); // Wait 10ms to avoid busy loop. if ((finish_mask & 1) == 0) { uint64_t freq; if (!GetMaxSampleFrequency(&freq) || freq == sample_freq) { -- cgit v1.2.3 From 1bc8ecbb9b94634f8e0f5960e79c3c21c941fa58 Mon Sep 17 00:00:00 2001 From: Yabin Cui Date: Thu, 22 Jul 2021 13:33:24 -0700 Subject: simpleperf: replace InCloudAndroid() with runtime check. On x86 and x86_64, it's likely to run on an emulator or vm without hardware perf counters. It's hard to enumerate them all. So check if hardware perf counters are available at runtime. Bug: 284801306 Test: run simpleperf_unit_test Change-Id: I38cc89bc7f81f8d6d6165a4b8f344c0660c10364 (cherry picked from commit 1f6f51aee77235b1fb374a917f0b46c9c09f0933) --- simpleperf/cmd_record_test.cpp | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/simpleperf/cmd_record_test.cpp b/simpleperf/cmd_record_test.cpp index 50730e22..ffaf649b 100644 --- a/simpleperf/cmd_record_test.cpp +++ b/simpleperf/cmd_record_test.cpp @@ -269,24 +269,10 @@ bool IsInNativeAbi() { return in_native_abi == 1; } -static bool InCloudAndroid() { -#if defined(__i386__) || defined(__x86_64__) -#if defined(__ANDROID__) - std::string prop_value = android::base::GetProperty("ro.build.flavor", ""); - if (android::base::StartsWith(prop_value, "cf_x86_phone") || - android::base::StartsWith(prop_value, "aosp_cf_x86_phone")) { - return true; - } -#endif -#endif - return false; -} - bool HasTracepointEvents() { static int has_tracepoint_events = -1; if (has_tracepoint_events == -1) { - // Cloud Android doesn't support tracepoint events. - has_tracepoint_events = InCloudAndroid() ? 0 : 1; + has_tracepoint_events = (GetTraceFsDir() != nullptr) ? 1 : 0; } return has_tracepoint_events == 1; } @@ -294,9 +280,15 @@ bool HasTracepointEvents() { bool HasHardwareCounter() { static int has_hw_counter = -1; if (has_hw_counter == -1) { - // Cloud Android doesn't have hardware counters. - has_hw_counter = InCloudAndroid() ? 0 : 1; -#if defined(__arm__) + has_hw_counter = 1; +#if defined(__x86__) || defined(__x86_64__) + // On x86 and x86_64, it's likely to run on an emulator or vm without hardware perf counters. + // It's hard to enumerate them all. So check the support at runtime. + const EventType* type = FindEventTypeByName("cpu-cycles", false); + CHECK(type != nullptr); + perf_event_attr attr = CreateDefaultPerfEventAttr(*type); + has_hw_counter = IsEventAttrSupported(attr, "cpu-cycles") ? 1 : 0; +#elif defined(__arm__) std::string cpu_info; if (android::base::ReadFileToString("/proc/cpuinfo", &cpu_info)) { std::string hardware = GetHardwareFromCpuInfo(cpu_info); @@ -307,7 +299,7 @@ bool HasHardwareCounter() { has_hw_counter = 0; } } -#endif +#endif // defined(__arm__) } return has_hw_counter == 1; } -- cgit v1.2.3 From f232ffbd6f4d97dd6d086bc96d0f0075c83d0fa9 Mon Sep 17 00:00:00 2001 From: Yabin Cui Date: Thu, 8 Jun 2023 16:26:42 -0700 Subject: simpleperf: Check hardware counter dynamically in non-native ABIs ARM64 CtsSimpleperfTestCases may run via binary translation on a x86_64 environment, which may run on a VM not supporting hardware counters. Bug: 284801306 Test: run CtsSimpleperfTestCases Change-Id: Icc08d3639459c2c671f57c96860db085e8b7f8b9 --- simpleperf/cmd_record_test.cpp | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/simpleperf/cmd_record_test.cpp b/simpleperf/cmd_record_test.cpp index ffaf649b..7583bc50 100644 --- a/simpleperf/cmd_record_test.cpp +++ b/simpleperf/cmd_record_test.cpp @@ -281,25 +281,27 @@ bool HasHardwareCounter() { static int has_hw_counter = -1; if (has_hw_counter == -1) { has_hw_counter = 1; -#if defined(__x86__) || defined(__x86_64__) - // On x86 and x86_64, it's likely to run on an emulator or vm without hardware perf counters. - // It's hard to enumerate them all. So check the support at runtime. - const EventType* type = FindEventTypeByName("cpu-cycles", false); - CHECK(type != nullptr); - perf_event_attr attr = CreateDefaultPerfEventAttr(*type); - has_hw_counter = IsEventAttrSupported(attr, "cpu-cycles") ? 1 : 0; -#elif defined(__arm__) - std::string cpu_info; - if (android::base::ReadFileToString("/proc/cpuinfo", &cpu_info)) { - std::string hardware = GetHardwareFromCpuInfo(cpu_info); - if (std::regex_search(hardware, std::regex(R"(i\.MX6.*Quad)")) || - std::regex_search(hardware, std::regex(R"(SC7731e)")) || - std::regex_search(hardware, std::regex(R"(Qualcomm Technologies, Inc MSM8909)")) || - std::regex_search(hardware, std::regex(R"(Broadcom STB \(Flattened Device Tree\))"))) { - has_hw_counter = 0; + auto arch = GetBuildArch(); + if (arch == ARCH_X86_64 || arch == ARCH_X86_32 || !IsInNativeAbi()) { + // On x86 and x86_64, or when we are not in native abi, it's likely to run on an emulator or + // vm without hardware perf counters. It's hard to enumerate them all. So check the support + // at runtime. + const EventType* type = FindEventTypeByName("cpu-cycles", false); + CHECK(type != nullptr); + perf_event_attr attr = CreateDefaultPerfEventAttr(*type); + has_hw_counter = IsEventAttrSupported(attr, "cpu-cycles") ? 1 : 0; + } else if (arch == ARCH_ARM) { + std::string cpu_info; + if (android::base::ReadFileToString("/proc/cpuinfo", &cpu_info)) { + std::string hardware = GetHardwareFromCpuInfo(cpu_info); + if (std::regex_search(hardware, std::regex(R"(i\.MX6.*Quad)")) || + std::regex_search(hardware, std::regex(R"(SC7731e)")) || + std::regex_search(hardware, std::regex(R"(Qualcomm Technologies, Inc MSM8909)")) || + std::regex_search(hardware, std::regex(R"(Broadcom STB \(Flattened Device Tree\))"))) { + has_hw_counter = 0; + } } } -#endif // defined(__arm__) } return has_hw_counter == 1; } -- cgit v1.2.3