]> sourceware.org Git - systemtap.git/commitdiff
stapbpf/stapbpf.cxx :: fix perf_fds packing code for non-contiguous CPUs
authorSerhei Makarov <smakarov@redhat.com>
Thu, 9 May 2019 20:47:22 +0000 (16:47 -0400)
committerSerhei Makarov <smakarov@redhat.com>
Thu, 9 May 2019 20:47:22 +0000 (16:47 -0400)
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

index e745485b7612437d399724548614689410b8b2ac..03873219c7565230ba778a480c17d43cb422e739 100644 (file)
@@ -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<unsigned> 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<int> 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)
             {
This page took 0.029789 seconds and 5 git commands to generate.