From 1f1c894deb1f48bbd94a8b38f3f4738992f1b1f8 Mon Sep 17 00:00:00 2001 From: Serhei Makarov Date: Thu, 9 May 2019 16:47:22 -0400 Subject: [PATCH] stapbpf/stapbpf.cxx :: fix perf_fds packing code for non-contiguous CPUs Spotted an error, not the same error that Coverity thinks is happening. Validity of perf_fds[cpu] (not perf_fds[i]) is indicated by cpus_active[cpu]. There are some additional issues I missed in new code since I first fixed the code to work with noncontiguous CPUs. * stapbpf/stapbpf.cxx (perf_event_loop): assign perf_fds[cpu], not perf_fds[i] !!, maintain i -> cpu mapping to retrieve correct perf_header and transport_context. --- stapbpf/stapbpf.cxx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/stapbpf/stapbpf.cxx b/stapbpf/stapbpf.cxx index e745485b7..03873219c 100644 --- a/stapbpf/stapbpf.cxx +++ b/stapbpf/stapbpf.cxx @@ -1577,6 +1577,7 @@ perf_event_loop(pthread_t main_thread) = count_active_cpus(); struct pollfd *pmu_fds = (struct pollfd *)malloc(n_active_cpus * sizeof(struct pollfd)); + vector cpuids; assert(ncpus == perf_fds.size()); unsigned i = 0; @@ -1584,10 +1585,12 @@ perf_event_loop(pthread_t main_thread) { if (!cpu_online[cpu]) continue; // -- skip inactive CPUs. - pmu_fds[i].fd = perf_fds[i]; + pmu_fds[i].fd = perf_fds[cpu]; pmu_fds[i].events = POLLIN; + cpuids.push_back(cpu); i++; } + assert(n_active_cpus == cpuids.size()); // Avoid multiple warnings about errors reading from an fd: std::set already_warned; @@ -1609,12 +1612,13 @@ perf_event_loop(pthread_t main_thread) fprintf(stderr, "Saw perf_event on fd %d\n", pmu_fds[i].fd); ready --; + unsigned cpu == cpuids[i]; ret = bpf_perf_event_read_simple - (perf_headers[i], + (perf_headers[cpu], perf_event_page_count * perf_event_page_size, perf_event_page_size, &data, &len, - perf_event_handle, transport_contexts[i]); + perf_event_handle, transport_contexts[cpu]); if (ret == LIBBPF_PERF_EVENT_DONE) { -- 2.43.5