perf_counter tools: remove glib dependency and fix bugs in kerneltop.c, fix poll()
authorPeter Zijlstra <a.p.zijlstra@chello.nl>
Tue, 24 Mar 2009 09:50:24 +0000 (10:50 +0100)
committerIngo Molnar <mingo@elte.hu>
Mon, 6 Apr 2009 07:30:31 +0000 (09:30 +0200)
Paul Mackerras wrote:

> I noticed the poll stuff is bogus - we have a 2D array of struct
> pollfds (MAX_NR_CPUS x MAX_COUNTERS), we fill in a sub-array (with the
> rest being uninitialized, since the array is on the stack) and then
> pass the first nr_cpus elements to poll.  Not what we really meant, I
> suspect. :)  Not even if we only have one counter, since it's the
> counter dimension that varies fastest.

This should fix the most obvious poll fubar.. not enough to fix the
full problem though..

Reported-by: Paul Mackerras <paulus@samba.org>
Reported-by: Mike Galbraith <efault@gmx.de>
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Arjan van de Ven <arjan@linux.intel.com>
Orig-LKML-Reference: <18888.29986.340328.540512@cargo.ozlabs.ibm.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Documentation/perf_counter/kerneltop.c

index ea13e4e6722919d8c9040f9b3debb90e17bf2869..7ebde7a336c62b43747e919b5be062ccd747700c 100644 (file)
@@ -1157,10 +1157,10 @@ static void mmap_read(struct mmap_data *md)
 
 int main(int argc, char *argv[])
 {
-       struct pollfd event_array[MAX_NR_CPUS][MAX_COUNTERS];
+       struct pollfd event_array[MAX_NR_CPUS * MAX_COUNTERS];
        struct mmap_data mmap_array[MAX_NR_CPUS][MAX_COUNTERS];
        struct perf_counter_hw_event hw_event;
-       int i, counter, group_fd;
+       int i, counter, group_fd, nr_poll = 0;
        unsigned int cpu;
        int ret;
 
@@ -1214,8 +1214,9 @@ int main(int argc, char *argv[])
                        if (group && group_fd == -1)
                                group_fd = fd[i][counter];
 
-                       event_array[i][counter].fd = fd[i][counter];
-                       event_array[i][counter].events = POLLIN;
+                       event_array[nr_poll].fd = fd[i][counter];
+                       event_array[nr_poll].events = POLLIN;
+                       nr_poll++;
 
                        mmap_array[i][counter].counter = counter;
                        mmap_array[i][counter].prev = 0;
@@ -1247,7 +1248,7 @@ int main(int argc, char *argv[])
                }
 
                if (hits == events)
-                       ret = poll(event_array[0], nr_cpus, 1000);
+                       ret = poll(event_array, nr_poll, 1000);
                hits = events;
        }