+#define CDEBUG_MAX_LIMIT 600
+#define CDEBUG_LIMIT(cdebug_mask, cdebug_format, a...) \
+do { \
+ static unsigned long cdebug_next = 0; \
+ static int cdebug_count = 0, cdebug_delay = 1; \
+ \
+ CHECK_STACK(CDEBUG_STACK); \
+ if (time_after(jiffies, cdebug_next)) { \
+ portals_debug_msg(DEBUG_SUBSYSTEM, cdebug_mask, __FILE__, \
+ __FUNCTION__, __LINE__, CDEBUG_STACK, \
+ cdebug_format, ## a); \
+ if (cdebug_count) { \
+ portals_debug_msg(DEBUG_SUBSYSTEM, cdebug_mask, \
+ __FILE__, __FUNCTION__, __LINE__, \
+ 0, "skipped %d similar messages\n", \
+ cdebug_count); \
+ cdebug_count = 0; \
+ } \
+ if (time_after(jiffies, cdebug_next+(CDEBUG_MAX_LIMIT+10)*HZ))\
+ cdebug_delay = cdebug_delay > 8 ? cdebug_delay/8 : 1; \
+ else \
+ cdebug_delay = cdebug_delay*2 >= CDEBUG_MAX_LIMIT*HZ ?\
+ CDEBUG_MAX_LIMIT*HZ : cdebug_delay*2; \
+ cdebug_next = jiffies + cdebug_delay; \
+ } else { \
+ portals_debug_msg(DEBUG_SUBSYSTEM, \
+ portal_debug & ~(D_EMERG|D_ERROR|D_WARNING),\
+ __FILE__, __FUNCTION__, __LINE__, \
+ CDEBUG_STACK, cdebug_format, ## a); \
+ cdebug_count++; \
+ } \
+} while (0)
+
+#define CWARN(format, a...) CDEBUG_LIMIT(D_WARNING, format, ## a)
+#define CERROR(format, a...) CDEBUG_LIMIT(D_ERROR, format, ## a)