I got frusted a bit by this problem (smsd using incredible much cpu
even when idle) so I ran smsd through valgrind (well, callgrind).
It looks like tons of time is spend in an usleep(100); (yes, hundred).
I always thought that Linux would just round it up to the next
scheduling interval but it looks like that is a busy loop these days?
I changed it from 100us to 10ms and now the cpu usage dropped from on
average > 8% to < 1%. And that is on a "Intel(R) Core(TM) i7-3930K CPU
@ 3.20GHz".
Really something that communicates with a device at 19.2kBps should
not use that much cpu.
So please apply.
Thanks.
Oh and I think there maybe other possibilities of optimizing smsd left.



Regards,


Folkert van Heusden

www.smartwinning.info
diff -uNrBbd smstools-3.1.15.org/src/extras.c smstools-3.1.15/src/extras.c
--- smstools-3.1.15.org/src/extras.c    2013-11-08 10:16:02.000000000 +0100
+++ smstools-3.1.15/src/extras.c        2014-11-17 14:01:44.915072505 +0100
@@ -1436,7 +1436,7 @@
   struct timezone tz;
   unsigned long long now;
 
-  do
+  for(;;)
   {
     gettimeofday(&tv, &tz);
     now = (unsigned long long)tv.tv_sec *1000000 +tv.tv_usec;
@@ -1444,10 +1444,11 @@
     if (terminate == 1)
       return 1;
 
-    if (now < target_time)
-      usleep(100);
+    if (now >= target_time)
+      break;
+
+    usleep(10000);
   }
-  while (now < target_time);
 
   return 0;
 }

Reply via email to