daemon: Fix counters initialisation
authorWade Cherry <wade.cherry@arm.com>
Thu, 23 Feb 2012 09:56:29 +0000 (09:56 +0000)
committerJon Medhurst <tixy@linaro.org>
Thu, 23 Feb 2012 11:44:19 +0000 (11:44 +0000)
In certain circumstances counter were not enabled correctly. Fixed.

Signed-off-by: Wade Cherry <wade.cherry@arm.com>
Signed-off-by: Pawel Moll <pawel.moll@arm.com>
Signed-off-by: Jon Medhurst <tixy@linaro.org>
daemon/Child.cpp
daemon/Collector.cpp
daemon/Collector.h

index fe5a1f061f9bd3ae943355a77b747df74e057fc0..ddf105b8d315d4b475f2106308218836bf268898 100644 (file)
@@ -226,7 +226,7 @@ void Child::run() {
        }
 
        // Write configuration into the driver
-       collector->enablePerfCounters();
+       collector->setupPerfCounters();
 
        // Create user-space buffers
        int fifoBufferSize = collector->getBufferSize();
index c6f837628f14b30e174bc33ec6471e93390f68d3..7a41198e5cb4e1a7d0a96ea198d076e6ed384698 100644 (file)
@@ -46,10 +46,14 @@ Collector::Collector() {
 
        getCoreName();
 
+       enablePerfCounters();
+
        // Read unchanging keys from driver which are created at insmod'ing of gator.ko
        for (int i = 0; i < MAX_PERFORMANCE_COUNTERS; i++) {
-               snprintf(text, sizeof(text), "events/%s/key", gSessionData->mPerfCounterType[i]);
-               readIntDriver(text, &gSessionData->mPerfCounterKey[i]);
+               if (gSessionData->mPerfCounterEnabled[i]) {
+                       snprintf(text, sizeof(text), "events/%s/key", gSessionData->mPerfCounterType[i]);
+                       readIntDriver(text, &gSessionData->mPerfCounterKey[i]);
+               }
        }
 }
 
@@ -64,6 +68,21 @@ Collector::~Collector() {
 }
 
 void Collector::enablePerfCounters() {
+       char text[sizeof(gSessionData->mPerfCounterType[0]) + 30]; // sufficiently large to hold all /dev/gator/events/<types>/enabled
+       for (int i=0; i<MAX_PERFORMANCE_COUNTERS; i++) {
+               if (!gSessionData->mPerfCounterEnabled[i]) {
+                       continue;
+               }
+               snprintf(text, sizeof(text), "events/%s/enabled", gSessionData->mPerfCounterType[i]);
+               if (writeReadDriver(text, &gSessionData->mPerfCounterEnabled[i])) {
+                       // Disable those events that don't exist on this hardware platform even though they exist in configuration.xml
+                       gSessionData->mPerfCounterEnabled[i] = 0;
+                       continue;
+               }
+       }
+}
+
+void Collector::setupPerfCounters() {
        char base[sizeof(gSessionData->mPerfCounterType[0]) + 10]; // sufficiently large to hold all events/<types>
        char text[sizeof(gSessionData->mPerfCounterType[0]) + 20]; // sufficiently large to hold all events/<types>/<file>
 
@@ -86,10 +105,6 @@ void Collector::enablePerfCounters() {
                                handleException();
                        }
                }
-               snprintf(text, sizeof(text), "%s/enabled", base);
-               if (writeReadDriver(text, &gSessionData->mPerfCounterEnabled[i])) {
-                       gSessionData->mPerfCounterEnabled[i] = 0;
-               }
        }
 }
 
index 1cfe84e1b976d0a04f51fb403f8bad571a29c8e7..6c80725ad94bdfb1af0652fc60565132a0e992e1 100644 (file)
@@ -19,6 +19,7 @@ public:
        void stop();
        int collect(char* buffer);
        void enablePerfCounters();
+       void setupPerfCounters();
        int getBufferSize() {return bufferSize;}
 private:
        int bufferSize;