]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MEDIUM] use regparm on a few tv_* functions
authorWilly Tarreau <w@1wt.eu>
Sun, 15 Oct 2006 13:38:50 +0000 (15:38 +0200)
committerWilly Tarreau <w@1wt.eu>
Sun, 15 Oct 2006 13:38:50 +0000 (15:38 +0200)
Some of the tv_* functions are called very often. Passing their
arguments as registers is quite faster. This can be disabled
by setting CONFIG_HAP_DISABLE_REGPARM.

include/common/config.h
include/common/time.h
src/log.c
src/time.c

index 3ab879fc599b570b26af99fba99898a05fb8d4dd..f4676419319172702f584f2492459fcc17c595aa 100644 (file)
  */
 //#undef  CONFIG_HAP_INLINE_FD_SET
 
+/* CONFIG_HAP_DISABLE_REGPARM
+ * This disables the use of register parameters for some functions which
+ * use it by default to increase performance.
+ */
+#ifdef CONFIG_HAP_DISABLE_REGPARM
+#define REGPRM1
+#define REGPRM2
+#define REGPRM3
+#else
+#define REGPRM1 __attribute__((regparm(1)))
+#define REGPRM2 __attribute__((regparm(2)))
+#define REGPRM3 __attribute__((regparm(3)))
+#endif
 
 #endif /* _COMMON_CONFIG_H */
index 7a68a1549780ed65c1c9c77d44733a5a8eeafd60..1546921e98459093914a8bd9ac618801cf5d5c1d 100644 (file)
@@ -39,35 +39,35 @@ extern struct timeval start_date;       /* the process's start date */
 /*
  * adds <ms> ms to <from>, set the result to <tv> and returns a pointer <tv>
  */
-struct timeval *tv_delayfrom(struct timeval *tv, const struct timeval *from, int ms);
+REGPRM3 struct timeval *tv_delayfrom(struct timeval *tv, const struct timeval *from, int ms);
 
 /*
  * compares <tv1> and <tv2> modulo 1ms: returns 0 if equal, -1 if tv1 < tv2, 1 if tv1 > tv2
  * Must not be used when either argument is eternity. Use tv_cmp2_ms() for that.
  */
-int tv_cmp_ms(const struct timeval *tv1, const struct timeval *tv2);
+REGPRM2 int tv_cmp_ms(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.
  */
-int tv_cmp2(const struct timeval *tv1, const struct timeval *tv2);
+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.
  */
-int tv_cmp2_ms(const struct timeval *tv1, const struct timeval *tv2);
+REGPRM2 int tv_cmp2_ms(const struct timeval *tv1, const struct timeval *tv2);
 
 /*
  * returns the remaining time between tv1=now and event=tv2
  * if tv2 is passed, 0 is returned.
  * Returns TIME_ETERNITY if tv2 is eternity.
  */
-unsigned long tv_remain2(const struct timeval *tv1, const struct timeval *tv2);
+REGPRM2 unsigned long tv_remain2(const struct timeval *tv1, const struct timeval *tv2);
 
 
 /* sets <tv> to the current time */
-static inline struct timeval *tv_now(struct timeval *tv)
+REGPRM1 static inline struct timeval *tv_now(struct timeval *tv)
 {
        if (tv)
                gettimeofday(tv, NULL);
@@ -78,7 +78,7 @@ static inline struct timeval *tv_now(struct timeval *tv)
  * compares <tv1> and <tv2> : returns 0 if equal, -1 if tv1 < tv2, 1 if tv1 > tv2
  * Must not be used when either argument is eternity. Use tv_cmp2() for that.
  */
-static inline int tv_cmp(const struct timeval *tv1, const struct timeval *tv2)
+REGPRM2 static inline int tv_cmp(const struct timeval *tv1, const struct timeval *tv2)
 {
        if (tv1->tv_sec < tv2->tv_sec)
                return -1;
@@ -96,7 +96,7 @@ static inline int tv_cmp(const struct timeval *tv1, const struct timeval *tv2)
  * returns the difference, in ms, between tv1 and tv2
  * Must not be used when either argument is eternity.
  */
-static inline unsigned long tv_diff(const struct timeval *tv1, const struct timeval *tv2)
+REGPRM2 static inline unsigned long tv_diff(const struct timeval *tv1, const struct timeval *tv2)
 {
        unsigned long ret;
   
@@ -113,7 +113,7 @@ static inline unsigned long tv_diff(const struct timeval *tv1, const struct time
  * if tv2 is passed, 0 is returned.
  * Must not be used when either argument is eternity.
  */
-static inline unsigned long tv_remain(const struct timeval *tv1, const struct timeval *tv2)
+REGPRM2 static inline unsigned long tv_remain(const struct timeval *tv1, const struct timeval *tv2)
 {
        unsigned long ret;
   
@@ -133,7 +133,7 @@ static inline unsigned long tv_remain(const struct timeval *tv1, const struct ti
  * zeroes a struct timeval
  */
 
-static inline struct timeval *tv_eternity(struct timeval *tv)
+REGPRM1 static inline struct timeval *tv_eternity(struct timeval *tv)
 {
        tv->tv_sec = tv->tv_usec = 0;
        return tv;
@@ -142,7 +142,7 @@ static inline struct timeval *tv_eternity(struct timeval *tv)
 /*
  * returns 1 if tv is null, else 0
  */
-static inline int tv_iseternity(const struct timeval *tv)
+REGPRM1 static inline int tv_iseternity(const struct timeval *tv)
 {
        if (tv->tv_sec == 0 && tv->tv_usec == 0)
                return 1;
@@ -154,7 +154,7 @@ static inline int tv_iseternity(const struct timeval *tv)
  * returns the first event between tv1 and tv2 into tvmin.
  * a zero tv is ignored. tvmin is returned.
  */
-static inline const struct timeval *tv_min(struct timeval *tvmin,
+REGPRM3 static inline const struct timeval *tv_min(struct timeval *tvmin,
                                     const struct timeval *tv1,
                                     const struct timeval *tv2)
 {
index 6af34644ea89c5d6deb0dc4e6631cb6aabf9a948..0711c030fb4eb187fd64b774f5a3aeae8cde1388 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -22,6 +22,7 @@
 
 #include <common/config.h>
 #include <common/standard.h>
+#include <common/time.h>
 
 #include <types/backend.h>
 #include <types/global.h>
index 025c87bb895d181fa32ac80fc1c56d3122492eb2..75f385ef812f7f7c77c987dab197f3ef03d25b10 100644 (file)
@@ -21,7 +21,7 @@ struct timeval start_date;      /* the process's start date */
 /*
  * adds <ms> ms to <from>, set the result to <tv> and returns a pointer <tv>
  */
-struct timeval *tv_delayfrom(struct timeval *tv, const struct timeval *from, int ms)
+REGPRM3 struct timeval *tv_delayfrom(struct timeval *tv, const struct timeval *from, int ms)
 {
        if (!tv || !from)
                return NULL;
@@ -38,7 +38,7 @@ struct timeval *tv_delayfrom(struct timeval *tv, const struct timeval *from, int
  * compares <tv1> and <tv2> modulo 1ms: returns 0 if equal, -1 if tv1 < tv2, 1 if tv1 > tv2
  * Must not be used when either argument is eternity. Use tv_cmp2_ms() for that.
  */
-int tv_cmp_ms(const struct timeval *tv1, const struct timeval *tv2)
+REGPRM2 int tv_cmp_ms(const struct timeval *tv1, const struct timeval *tv2)
 {
        if (tv1->tv_sec == tv2->tv_sec) {
                if (tv2->tv_usec >= tv1->tv_usec + 1000)
@@ -62,7 +62,7 @@ int tv_cmp_ms(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.
  */
-int tv_cmp2(const struct timeval *tv1, const struct timeval *tv2)
+REGPRM2 int tv_cmp2(const struct timeval *tv1, const struct timeval *tv2)
 {
        if (tv_iseternity(tv1))
                if (tv_iseternity(tv2))
@@ -88,7 +88,7 @@ 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.
  */
-int tv_cmp2_ms(const struct timeval *tv1, const struct timeval *tv2)
+REGPRM2 int tv_cmp2_ms(const struct timeval *tv1, const struct timeval *tv2)
 {
        if (tv_iseternity(tv1))
                if (tv_iseternity(tv2))
@@ -121,7 +121,7 @@ int tv_cmp2_ms(const struct timeval *tv1, const struct timeval *tv2)
  * if tv2 is passed, 0 is returned.
  * Returns TIME_ETERNITY if tv2 is eternity.
  */
-unsigned long tv_remain2(const struct timeval *tv1, const struct timeval *tv2)
+REGPRM2 unsigned long tv_remain2(const struct timeval *tv1, const struct timeval *tv2)
 {
        unsigned long ret;
 
@@ -144,7 +144,7 @@ unsigned long tv_remain2(const struct timeval *tv1, const struct timeval *tv2)
  * returns the absolute difference, in ms, between tv1 and tv2
  * Must not be used when either argument is eternity.
  */
-unsigned long tv_delta(const struct timeval *tv1, const struct timeval *tv2)
+REGPRM2 unsigned long tv_delta(const struct timeval *tv1, const struct timeval *tv2)
 {
        int cmp;
        unsigned long ret;