From 6b157a67c296e5f651ba2025acddd2f967b45929 Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Fri, 1 Aug 2008 18:11:20 -0700 Subject: Make log message lookup function use const tables Message tables should be unaltered. --- lib/log.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/log.h') diff --git a/lib/log.h b/lib/log.h index 691368c0..6f96c149 100644 --- a/lib/log.h +++ b/lib/log.h @@ -144,7 +144,7 @@ extern int zlog_rotate (struct zlog *); /* For hackey massage lookup and check */ #define LOOKUP(x, y) mes_lookup(x, x ## _max, y, "(no item found)") -extern const char *lookup (struct message *, int); +extern const char *lookup (const struct message *, int); extern const char *mes_lookup (struct message *meslist, int max, int index, const char *no_item); -- cgit v1.2.3 From 952444c56eff77b6c5f5785c0c55879282a23dc5 Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Fri, 8 Aug 2008 15:15:23 -0700 Subject: Add gcc printf format checks --- lib/log.h | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'lib/log.h') diff --git a/lib/log.h b/lib/log.h index 6f96c149..b08ae4c2 100644 --- a/lib/log.h +++ b/lib/log.h @@ -111,7 +111,8 @@ extern void closezlog (struct zlog *zl); #endif /* __GNUC__ */ /* Generic function for zlog. */ -extern void zlog (struct zlog *zl, int priority, const char *format, ...) PRINTF_ATTRIBUTE(3, 4); +extern void zlog (struct zlog *zl, int priority, const char *format, ...) + PRINTF_ATTRIBUTE(3, 4); /* Handy zlog functions. */ extern void zlog_err (const char *format, ...) PRINTF_ATTRIBUTE(1, 2); @@ -121,11 +122,16 @@ extern void zlog_notice (const char *format, ...) PRINTF_ATTRIBUTE(1, 2); extern void zlog_debug (const char *format, ...) PRINTF_ATTRIBUTE(1, 2); /* For bgpd's peer oriented log. */ -extern void plog_err (struct zlog *, const char *format, ...); -extern void plog_warn (struct zlog *, const char *format, ...); -extern void plog_info (struct zlog *, const char *format, ...); -extern void plog_notice (struct zlog *, const char *format, ...); -extern void plog_debug (struct zlog *, const char *format, ...); +extern void plog_err (struct zlog *, const char *format, ...) + PRINTF_ATTRIBUTE(2, 3); +extern void plog_warn (struct zlog *, const char *format, ...) + PRINTF_ATTRIBUTE(2, 3); +extern void plog_info (struct zlog *, const char *format, ...) + PRINTF_ATTRIBUTE(2, 3); +extern void plog_notice (struct zlog *, const char *format, ...) + PRINTF_ATTRIBUTE(2, 3); +extern void plog_debug (struct zlog *, const char *format, ...) + PRINTF_ATTRIBUTE(2, 3); /* Set logging level for the given destination. If the log_level argument is ZLOG_DISABLED, then the destination is disabled. -- cgit v1.2.3 From ebc04ce20a871c99dbb116a4fbada967dd750c43 Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Fri, 8 Aug 2008 15:35:10 -0700 Subject: Add compiler directive to mark code paths that log as cold This causes compiler to naturally favor faster path through code. Anything that logs a message is not fast path. --- lib/log.h | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) (limited to 'lib/log.h') diff --git a/lib/log.h b/lib/log.h index b08ae4c2..5411fa6b 100644 --- a/lib/log.h +++ b/lib/log.h @@ -105,33 +105,48 @@ extern void closezlog (struct zlog *zl); /* GCC have printf type attribute check. */ #ifdef __GNUC__ -#define PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b))) +#define PRINTF_ATTRIBUTE(a,b) __attribute__ ((format (printf, a, b))) #else #define PRINTF_ATTRIBUTE(a,b) #endif /* __GNUC__ */ +#if !(__GNUC__ == 4) +/* Mark functions as cold. gcc will assume any path leading to a call + to them will be unlikely. This means a lot of paths leading up + to log messages are easily marked as not likely. +*/ +#define COLD_ATTRIBUTE __attribute__((__cold__)) +#else +#define COLD_ATTRIBUTE +#endif + /* Generic function for zlog. */ extern void zlog (struct zlog *zl, int priority, const char *format, ...) PRINTF_ATTRIBUTE(3, 4); /* Handy zlog functions. */ -extern void zlog_err (const char *format, ...) PRINTF_ATTRIBUTE(1, 2); -extern void zlog_warn (const char *format, ...) PRINTF_ATTRIBUTE(1, 2); -extern void zlog_info (const char *format, ...) PRINTF_ATTRIBUTE(1, 2); -extern void zlog_notice (const char *format, ...) PRINTF_ATTRIBUTE(1, 2); -extern void zlog_debug (const char *format, ...) PRINTF_ATTRIBUTE(1, 2); +extern void zlog_err (const char *format, ...) + PRINTF_ATTRIBUTE(1, 2) COLD_ATTRIBUTE; +extern void zlog_warn (const char *format, ...) + PRINTF_ATTRIBUTE(1, 2) COLD_ATTRIBUTE; +extern void zlog_info (const char *format, ...) + PRINTF_ATTRIBUTE(1, 2) COLD_ATTRIBUTE; +extern void zlog_notice (const char *format, ...) + PRINTF_ATTRIBUTE(1, 2) COLD_ATTRIBUTE; +extern void zlog_debug (const char *format, ...) + PRINTF_ATTRIBUTE(1, 2) COLD_ATTRIBUTE; /* For bgpd's peer oriented log. */ extern void plog_err (struct zlog *, const char *format, ...) - PRINTF_ATTRIBUTE(2, 3); + PRINTF_ATTRIBUTE(2, 3) COLD_ATTRIBUTE; extern void plog_warn (struct zlog *, const char *format, ...) - PRINTF_ATTRIBUTE(2, 3); + PRINTF_ATTRIBUTE(2, 3) COLD_ATTRIBUTE; extern void plog_info (struct zlog *, const char *format, ...) - PRINTF_ATTRIBUTE(2, 3); + PRINTF_ATTRIBUTE(2, 3) COLD_ATTRIBUTE; extern void plog_notice (struct zlog *, const char *format, ...) - PRINTF_ATTRIBUTE(2, 3); + PRINTF_ATTRIBUTE(2, 3) COLD_ATTRIBUTE; extern void plog_debug (struct zlog *, const char *format, ...) - PRINTF_ATTRIBUTE(2, 3); + PRINTF_ATTRIBUTE(2, 3) COLD_ATTRIBUTE; /* Set logging level for the given destination. If the log_level argument is ZLOG_DISABLED, then the destination is disabled. -- cgit v1.2.3