speed up gb by fixing excessive calling to

gettimeofday() system call.
This commit is contained in:
Matt 2015-01-20 16:06:01 -07:00
parent 52bf9f1ff0
commit 6e7b329cef
4 changed files with 31 additions and 4 deletions

View File

@ -929,9 +929,10 @@ bool Loop::init ( ) {
m_realInterrupt.it_value.tv_sec = 0;
m_realInterrupt.it_value.tv_usec = 10 * 1000;
// 1000 microseconds in a millisecond
m_realInterrupt.it_value.tv_usec = 1 * 1000;
m_realInterrupt.it_interval.tv_sec = 0;
m_realInterrupt.it_interval.tv_usec = 10 * 1000;
m_realInterrupt.it_interval.tv_usec = 1 * 1000;
m_noInterrupt.it_value.tv_sec = 0;
@ -1148,6 +1149,9 @@ void sigvtalrmHandler ( int x , siginfo_t *info , void *y ) {
void sigalrmHandler ( int x , siginfo_t *info , void *y ) {
// so we don't call gettimeofday() thousands of times a second...
g_clockNeedsUpdate = true;
// stats
g_numAlarms++;
// . see where we are in the code

View File

@ -1438,6 +1438,16 @@ extern int g_inMemcpy;
void
Profiler::getStackFrame(int sig) {
// need to interrupt every 1ms to set this to true
g_clockNeedsUpdate = true;
// profile once every 5ms, not every 1ms
static int32_t s_count = 0;
if ( ++s_count != 5 ) return;
s_count = 0;
// prevent cores.
// TODO: hack this to a function somehow...
// we set this to positive values when calling library functions like
@ -1566,9 +1576,10 @@ Profiler::startRealTimeProfiler() {
//signal(SIGVTALRM, Profiler::getStackFrame);
signal(SIGALRM, Profiler::getStackFrame);
value.it_interval.tv_sec = 0;
value.it_interval.tv_usec = 5000;
// 1000 microseconds is 1 millisecond
value.it_interval.tv_usec = 1000;
value.it_value.tv_sec = 0;
value.it_value.tv_usec = 5000;
value.it_value.tv_usec = 1000;
setitimer( which, &value, &ovalue );
m_realTimeProfilerRunning = true;
}

View File

@ -10,6 +10,8 @@
static bool g_clockInSync = false;
bool g_clockNeedsUpdate = true;
bool isClockInSync() {
if ( g_hostdb.m_initialized && g_hostdb.m_hostId == 0 ) return true;
return g_clockInSync;
@ -1938,6 +1940,14 @@ int64_t gettimeofdayInMilliseconds() {
// a signal handler is underway in the main thread!
if ( g_inSigHandler && ! g_threads.amThread() ) {
char *xx = NULL; *xx = 0; }
// the real tiem sigalrm interrupt in Loop.cpp sets this to
// true once per millisecond
if ( ! g_clockNeedsUpdate )
return g_now;
g_clockNeedsUpdate = false;
// this isn't async signal safe...
struct timeval tv;
//g_loop.disableTimer();

View File

@ -7,6 +7,8 @@
#include <math.h> // floor()
#include "Unicode.h"
extern bool g_clockNeedsUpdate;
// we have to leave this as 32 bits for now because the termlists store
// the hash value as 32 bits in posdb
typedef uint32_t FacetValHash_t;