[MINOR] slightly optimize time calculation for rbtree
The new rbtree-based scheduler makes heavy use of tv_cmp2(), and
this function becomes a huge CPU eater. Refine it a little bit in
order to slightly reduce CPU usage.
diff --git a/include/common/time.h b/include/common/time.h
index 1546921..36c5ca5 100644
--- a/include/common/time.h
+++ b/include/common/time.h
@@ -48,10 +48,17 @@
REGPRM2 int tv_cmp_ms(const struct timeval *tv1, const struct timeval *tv2);
/*
+ * compares <tv1> and <tv2> : returns 0 if tv1 < tv2, 1 if tv1 >= tv2,
+ * considering that 0 is the eternity.
+ */
+REGPRM2 int tv_cmp_ge2(const struct timeval *tv1, const struct timeval *tv2);
+
+/*
* compares <tv1> and <tv2> : returns 0 if equal, -1 if tv1 < tv2, 1 if tv1 > tv2,
* considering that 0 is the eternity.
*/
REGPRM2 int tv_cmp2(const struct timeval *tv1, const struct timeval *tv2);
+
/*
* compares <tv1> and <tv2> modulo 1 ms: returns 0 if equal, -1 if tv1 < tv2, 1 if tv1 > tv2,
* considering that 0 is the eternity.
@@ -90,6 +97,20 @@
return 1;
else
return 0;
+}
+
+/*
+ * compares <tv1> and <tv2> : returns 0 if tv1 < tv2, 1 if tv1 >= tv2
+ */
+REGPRM2 static inline int tv_cmp_ge(const struct timeval *tv1, const struct timeval *tv2)
+{
+ if (tv1->tv_sec > tv2->tv_sec)
+ return 1;
+ if (tv1->tv_sec < tv2->tv_sec)
+ return 0;
+ if (tv1->tv_usec >= tv2->tv_usec)
+ return 1;
+ return 0;
}
/*
@@ -144,7 +165,7 @@
*/
REGPRM1 static inline int tv_iseternity(const struct timeval *tv)
{
- if (tv->tv_sec == 0 && tv->tv_usec == 0)
+ if ((tv->tv_sec | tv->tv_usec) == 0)
return 1;
else
return 0;