Factor out timer::is_deferred() to timer_is_deferred() function.
timer_is_deferred() gets called from timer() constructor and
fills deferred bool member variable. So timer::is_deferred() now
can simply return deferred, w/o any need of file lookup -- which is
performed only once during timer creation, not on every
timer:timer_expire_entry event.


Signed-off-by: Sergey Senozhatsky <sergey.senozhat...@gmail.com>

---

 process/timer.cpp |   45 +++++++++++++++++++++++++--------------------
 process/timer.h   |    1 +
 2 files changed, 26 insertions(+), 20 deletions(-)

diff --git a/process/timer.cpp b/process/timer.cpp
index 9674645..5711b8c 100644
--- a/process/timer.cpp
+++ b/process/timer.cpp
@@ -35,11 +35,35 @@
 
 using namespace std;
 
+static bool timer_is_deferred(const char *handler)
+{
+       FILE    *file;
+       bool    ret = false;
+       char    line[4096];
+
+       file = fopen("/proc/timer_stats", "r"); 
+       if (!file) {
+               return ret;
+       }
+
+       while (!feof(file)) {
+               if (fgets(line, 4096, file) == NULL)
+                       break;
+               if (strstr(line, handler)) {
+                       ret = (strstr(line, "D,") != NULL);
+                       if (ret == true)
+                               break;
+               }
+       }
+       fclose(file);
+       return ret;
+}
 
 timer::timer(unsigned long address) : power_consumer()
 {
        strncpy(handler, kernel_function(address), 31);
        raw_count = 0;
+       deferred = timer_is_deferred(handler);
 }
 
 
@@ -127,24 +151,5 @@ void clear_timers(void)
 
 bool timer::is_deferred(void)
 {
-       FILE    *file;
-       bool    ret = false;
-       char    line[4096];
-
-       file = fopen("/proc/timer_stats", "r"); 
-       if (!file) {
-               return ret;
-       }
-
-       while (!feof(file)) {
-               if (fgets(line, 4096, file) == NULL)
-                       break;
-               if (strstr(line, handler)) {
-                       ret = (strstr(line, "D,") != NULL);
-                       if (ret == true)
-                               break;
-               }
-       }
-       fclose(file);
-       return ret;
+       return deferred;
 }
diff --git a/process/timer.h b/process/timer.h
index 19aa0a7..8e07e69 100644
--- a/process/timer.h
+++ b/process/timer.h
@@ -34,6 +34,7 @@ class timer : public power_consumer {
 public:
        char            handler[32];
        int             raw_count;
+       bool            deferred;
 
        timer(unsigned long timer_func);
 

_______________________________________________
Discuss mailing list
Discuss@lesswatts.org
http://lists.lesswatts.org/listinfo/discuss

Reply via email to