Keywords: Mode: All keywords (AND) |
Tue Feb 11, 2014 14:38
|
hoerup: Or calculate how many small loops are necesarry first and avoid the calls to gettimeofday()
--- extras.c.old 2014-02-11 15:18:58.526777555 +0100
+++ extras.c 2014-02-11 15:37:37.188820157 +0100
@@ -1434,20 +1434,23 @@
{
struct timeval tv;
struct timezone tz;
- unsigned long long now;
+ unsigned long long now,diff;
- do
- {
- gettimeofday(&tv, &tz);
- now = (unsigned long long)tv.tv_sec *1000000 +tv.tv_usec;
+ unsigned long loop_count,i;
+ int left;
+ gettimeofday(&tv, &tz);
+ now = (unsigned long long)tv.tv_sec *1000000 +tv.tv_usec;
+ diff = target_time - now;
+ loop_count = (diff /100);
+ left = (diff % 100);
+
+ for (i=0; i<loop_count; i++) {
if (terminate == 1)
return 1;
-
- if (now < target_time)
- usleep(100);
+ usleep(100);
}
- while (now < target_time);
+ usleep(left);
return 0;
}
|
Tue Feb 11, 2014 14:26
|
hoerup: Hi
I find the current cpu usage a bit high even though smsd only is idling (not moving any messages)- especially on lower spec'ed computers.
After a bit investigation i found that usleep_until() in extras.c only usleeps in intervals of 100 microseconds - which might be a bit too low and sorta creates a pseudo busy loop wait.
This small patch lowered CPU consumption quite a bit:
diff -u extras.c.old extras.c
--- extras.c.old 2014-02-11 15:18:58.526777555 +0100
+++ extras.c 2014-02-11 15:19:46.845312164 +0100
@@ -1445,7 +1445,7 @@
return 1;
if (now < target_time)
- usleep(100);
+ usleep(1000);
}
while (now < target_time);
|
Tue Feb 11, 2014 14:13
|
hoerup: Hi
Have you considered switching to a online code hosting site to gain these benefits
* Online source repository (easier review)
* Possibility of forking and handling patch submissions / pull requests
* Bugtracker
/hoerup
|