cygserver: Speed up non-debug scenario

_log/_vlog were always called so we always had a function call hit even
if we're not debugging.  Expand on the debugging macros so the decision
to call _log/_vlog is done in the caller already.  Also, make a log level
difference between syscall_printf and system_printf.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
Corinna Vinschen 2017-03-24 17:26:37 +01:00
parent 4dbcfeb7d0
commit 663b4ab824
7 changed files with 30 additions and 16 deletions

View File

@ -63,9 +63,9 @@ win_copyout (struct thread *td, const void *server_src,
static void static void
_enter_critical_section (LPCRITICAL_SECTION pcs, const char *file, int line) _enter_critical_section (LPCRITICAL_SECTION pcs, const char *file, int line)
{ {
_log (file, line, LOG_DEBUG, "Try enter critical section(%p)", pcs); _debug (file, line, "Try enter critical section(%p)", pcs);
EnterCriticalSection (pcs); EnterCriticalSection (pcs);
_log (file, line, LOG_DEBUG, "Entered critical section(%p)", pcs); _debug (file, line, "Entered critical section(%p)", pcs);
} }
#define leave_critical_section(c) _leave_critical_section((c),__FILE__,__LINE__) #define leave_critical_section(c) _leave_critical_section((c),__FILE__,__LINE__)
@ -73,7 +73,7 @@ static void
_leave_critical_section (LPCRITICAL_SECTION pcs, const char *file, int line) _leave_critical_section (LPCRITICAL_SECTION pcs, const char *file, int line)
{ {
LeaveCriticalSection (pcs); LeaveCriticalSection (pcs);
_log (file, line, LOG_DEBUG, "Left critical section(%p)", pcs); _debug (file, line, "Left critical section(%p)", pcs);
} }
CRITICAL_SECTION ipcht_cs; CRITICAL_SECTION ipcht_cs;

View File

@ -93,7 +93,7 @@ _log (const char *file, int line, int level, const char *fmt, ...)
void void
_vpanic (const char *file, int line, const char *fmt, va_list ap) _vpanic (const char *file, int line, const char *fmt, va_list ap)
{ {
_vlog (file, line, LOG_CRIT, fmt, ap); _vlog (file, line, LOG_EMERG, fmt, ap);
exit (1); exit (1);
} }

View File

@ -19,12 +19,26 @@ extern tun_bool_t log_stderr;
void loginit (tun_bool_t, tun_bool_t); void loginit (tun_bool_t, tun_bool_t);
void _vlog (const char *, int, int, const char *, va_list); void _vlog (const char *, int, int, const char *, va_list);
void _log (const char *, int, int, const char *, ...); void _log (const char *, int, int, const char *, ...);
void _vpanic (const char *, int, const char *, va_list) __attribute__ ((noreturn));
void _panic (const char *, int, const char *, ...) __attribute__ ((noreturn));
#define vlog(l,f,a) _vlog(NULL,0,(l),(f),(a)) #define vlog(l,f,a) _vlog(NULL,0,(l),(f),(a))
#define log(l,f,...) _log(NULL,0,(l),(f),##__VA_ARGS__) #define log(l,f,...) _log(NULL,0,(l),(f),##__VA_ARGS__)
#define vdebug(f,a) _vlog(__FILE__,__LINE__,LOG_DEBUG,(f),(a))
#define debug(f,...) _log(__FILE__,__LINE__,LOG_DEBUG,(f),##__VA_ARGS__) #define _vdebug(F,L,f,a) \
do { if (log_debug == TUN_TRUE) \
_vlog((F),(L),LOG_DEBUG,(f),(a)) \
} while (0)
#define _debug(F,L,f,...) \
do { if (log_debug == TUN_TRUE) \
_log((F),(L),LOG_DEBUG,(f),##__VA_ARGS__); \
} while (0)
#define vdebug(f,a) _vdebug(__FILE__,__LINE__,(f),(a))
#define debug(f,...) _debug(__FILE__,__LINE__,(f),##__VA_ARGS__)
void _vpanic (const char *, int, const char *, va_list)
__attribute__ ((noreturn));
void _panic (const char *, int, const char *, ...) __attribute__ ((noreturn));
#define vpanic(f,a) _vpanic(__FILE__,__LINE__,(f),(a)) #define vpanic(f,a) _vpanic(__FILE__,__LINE__,(f),(a))
#define panic(f,...) _panic(__FILE__,__LINE__,(f),##__VA_ARGS__) #define panic(f,...) _panic(__FILE__,__LINE__,(f),##__VA_ARGS__)

View File

@ -40,13 +40,13 @@ mtx_init (mtx *m, const char *name, const void *, int)
void void
_mtx_lock (mtx *m, DWORD winpid, const char *file, int line) _mtx_lock (mtx *m, DWORD winpid, const char *file, int line)
{ {
_log (file, line, LOG_DEBUG, "Try locking mutex %s (%u) (hold: %u)", _debug (file, line, "Try locking mutex %s (%u) (hold: %u)",
m->name, winpid, m->owner); m->name, winpid, m->owner);
if (WaitForSingleObject (m->h, INFINITE) != WAIT_OBJECT_0) if (WaitForSingleObject (m->h, INFINITE) != WAIT_OBJECT_0)
_panic (file, line, "wait for %s in %d failed, %u", m->name, winpid, _panic (file, line, "wait for %s in %d failed, %u", m->name, winpid,
GetLastError ()); GetLastError ());
m->owner = winpid; m->owner = winpid;
_log (file, line, LOG_DEBUG, "Locked mutex %s/%u (owner: %u)", _debug (file, line, "Locked mutex %s/%u (owner: %u)",
m->name, ++m->cnt, winpid); m->name, ++m->cnt, winpid);
} }
@ -89,7 +89,7 @@ _mtx_unlock (mtx *m, const char *file, int line)
_panic (file, line, "release of mutex %s failed, %u", m->name, _panic (file, line, "release of mutex %s failed, %u", m->name,
GetLastError ()); GetLastError ());
} }
_log (file, line, LOG_DEBUG, "Unlocked mutex %s/%u (owner: %u)", _debug (file, line, "Unlocked mutex %s/%u (owner: %u)",
m->name, cnt, owner); m->name, cnt, owner);
} }

View File

@ -82,12 +82,12 @@ public:
bool is_active () const { return _exit_status == STILL_ACTIVE; } bool is_active () const { return _exit_status == STILL_ACTIVE; }
void _hold (const char *file, int line) { void _hold (const char *file, int line) {
_log (file, line, LOG_DEBUG, "Try hold(%lu)", _cygpid); _debug (file, line, "Try hold(%lu)", _cygpid);
EnterCriticalSection (&_access); EnterCriticalSection (&_access);
_log (file, line, LOG_DEBUG, "holding (%lu)", _cygpid); _debug (file, line, "holding (%lu)", _cygpid);
} }
void _release (const char *file, int line) { void _release (const char *file, int line) {
_log (file, line, LOG_DEBUG, "leaving (%lu)", _cygpid); _debug (file, line, "leaving (%lu)", _cygpid);
LeaveCriticalSection (&_access); LeaveCriticalSection (&_access);
} }

View File

@ -52,7 +52,7 @@ __FBSDID("$FreeBSD: /usr/local/www/cvsroot/FreeBSD/src/sys/kern/sysv_msg.c,v 1.5
#endif /* __CYGWIN__ */ #endif /* __CYGWIN__ */
#ifdef MSG_DEBUG #ifdef MSG_DEBUG
#define DPRINTF(a) debug_printf a #define DPRINTF(a) debug a
#else #else
#define DPRINTF(a) #define DPRINTF(a)
#endif #endif

View File

@ -50,5 +50,5 @@ extern int cygserver_running;
} while (false) } while (false)
#define debug_printf(f,...) debug((f),##__VA_ARGS__) #define debug_printf(f,...) debug((f),##__VA_ARGS__)
#define syscall_printf(f,...) log(LOG_ERR,(f),##__VA_ARGS__) #define syscall_printf(f,...) log(LOG_INFO,(f),##__VA_ARGS__)
#define system_printf(f,...) log(LOG_ERR,(f),##__VA_ARGS__) #define system_printf(f,...) log(LOG_ERR,(f),##__VA_ARGS__)