BlockEnd * a_block_end; //block end of the block
void * cur_event_pos; //the position of the current event
void * buffer; //the buffer containing the block
- double cycle_per_nsec; //Cycles per nsec
+ double nsec_per_cycle; //Nsec per cycle
+ //LttCycleCount cycles_per_nsec_reciprocal; // Optimisation for speed
unsigned cur_heart_beat_number; //current number of heart beat in the buf
LttCycleCount cur_cycle_count; //current cycle count of the event
void * last_event_pos;
return res;
}
+#define likely(x) __builtin_expect(!!(x), 1)
+#define unlikely(x) __builtin_expect(!!(x), 0)
/* Fastest comparison : t1 > t2 */
static inline int ltt_time_compare(LttTime t1, LttTime t2)
{
int ret=0;
- if(t1.tv_sec > t2.tv_sec) ret = 1;
- else if(t1.tv_sec < t2.tv_sec) ret = -1;
- else if(t1.tv_nsec > t2.tv_nsec) ret = 1;
- else if(t1.tv_nsec < t2.tv_nsec) ret = -1;
+ if(likely(t1.tv_sec > t2.tv_sec)) ret = 1;
+ else if(unlikely(t1.tv_sec < t2.tv_sec)) ret = -1;
+ else if(likely(t1.tv_nsec > t2.tv_nsec)) ret = 1;
+ else if(unlikely(t1.tv_nsec < t2.tv_nsec)) ret = -1;
return ret;
}
void getCyclePerNsec(LttTracefile * t)
{
LttTime lBufTotalTime; /* Total time for this buffer */
- LttCycleCount lBufTotalNSec; /* Total time for this buffer in nsecs */
- LttCycleCount lBufTotalCycle;/* Total cycles for this buffer */
+ double lBufTotalNSec; /* Total time for this buffer in nsecs */
+ double lBufTotalCycle;/* Total cycles for this buffer */
/* Calculate the total time for this buffer */
lBufTotalTime = ltt_time_sub(t->a_block_end->time, t->a_block_start->time);
lBufTotalCycle -= t->a_block_start->cycle_count;
/* Convert the total time to nsecs */
- lBufTotalNSec = lBufTotalTime.tv_sec;
- lBufTotalNSec *= NANOSECONDS_PER_SECOND;
- lBufTotalNSec += lBufTotalTime.tv_nsec;
+ lBufTotalNSec = ltt_time_to_double(lBufTotalTime);
- t->cycle_per_nsec = (double)lBufTotalCycle / (double)lBufTotalNSec;
+ t->nsec_per_cycle = (double)lBufTotalNSec / (double)lBufTotalCycle;
+ /* See : http://www.azillionmonkeys.com/qed/adiv.html */
+ // precalculate the reciprocal, so divisions will be really fast.
+ // 2^32-1 == 0xFFFFFFFFULL
+ //{
+ // double int_res = lBufTotalCycle/lBufTotalNSec;
+ // t->cycles_per_nsec_reciprocal =
+ // ((0xFFFF+int_res)/int_res);
+ //}
+
}
/****************************************************************************
*Function name
* getEventTime : obtain the time of an event
+ * NOTE : this function _really_ is on critical path.
*Input params
* tf : tracefile
*Return value
LttTime time;
LttCycleCount cycle_count; // cycle count for the current event
LttCycleCount lEventTotalCycle; // Total cycles from start for event
- double lEventNSec; // Total nsecs from start for event
+ LttCycleCount lEventNSec; // Total nsecs from start for event
LttTime lTimeOffset; // Time offset in struct LttTime
guint16 evId;
lEventTotalCycle -= tf->a_block_start->cycle_count;
// Convert it to nsecs
- lEventNSec = (double)lEventTotalCycle / (double)tf->cycle_per_nsec;
-
+ lEventNSec = (double)lEventTotalCycle * (double)tf->nsec_per_cycle;
+ //lEventNSec = (tf->cycles_per_nsec_reciprocal * lEventTotalCycle) >> 16;
+
// Determine offset in struct LttTime
lTimeOffset = ltt_time_from_double(lEventNSec);