[newlib-cygwin] cygserver: Speed up non-debug scenario

Corinna Vinschen corinna@sourceware.org
Fri Mar 24 17:04:00 GMT 2017


https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=663b4ab8243e56052d72217427bc935b3de2e9de

commit 663b4ab8243e56052d72217427bc935b3de2e9de
Author: Corinna Vinschen <corinna@vinschen.de>
Date:   Fri Mar 24 17:26:37 2017 +0100

    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>

Diff:
---
 winsup/cygserver/bsd_helper.cc |  6 +++---
 winsup/cygserver/bsd_log.cc    |  2 +-
 winsup/cygserver/bsd_log.h     | 22 ++++++++++++++++++----
 winsup/cygserver/bsd_mutex.cc  |  6 +++---
 winsup/cygserver/process.h     |  6 +++---
 winsup/cygserver/sysv_msg.cc   |  2 +-
 winsup/cygserver/woutsup.h     |  2 +-
 7 files changed, 30 insertions(+), 16 deletions(-)

diff --git a/winsup/cygserver/bsd_helper.cc b/winsup/cygserver/bsd_helper.cc
index f4babee..ecc90e1 100644
--- a/winsup/cygserver/bsd_helper.cc
+++ b/winsup/cygserver/bsd_helper.cc
@@ -63,9 +63,9 @@ win_copyout (struct thread *td, const void *server_src,
 static void
 _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);
-  _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__)
@@ -73,7 +73,7 @@ static void
 _leave_critical_section (LPCRITICAL_SECTION pcs, const char *file, int line)
 {
   LeaveCriticalSection (pcs);
-  _log (file, line, LOG_DEBUG, "Left      critical section(%p)", pcs);
+  _debug (file, line, "Left      critical section(%p)", pcs);
 }
 
 CRITICAL_SECTION ipcht_cs;
diff --git a/winsup/cygserver/bsd_log.cc b/winsup/cygserver/bsd_log.cc
index 7c6dcb6..133aa46 100644
--- a/winsup/cygserver/bsd_log.cc
+++ b/winsup/cygserver/bsd_log.cc
@@ -93,7 +93,7 @@ _log (const char *file, int line, int level, const char *fmt, ...)
 void
 _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);
 }
 
diff --git a/winsup/cygserver/bsd_log.h b/winsup/cygserver/bsd_log.h
index 58d0517..5eae634 100644
--- a/winsup/cygserver/bsd_log.h
+++ b/winsup/cygserver/bsd_log.h
@@ -19,12 +19,26 @@ extern tun_bool_t log_stderr;
 void loginit (tun_bool_t, tun_bool_t);
 void _vlog (const char *, int, int, const char *, va_list);
 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 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 panic(f,...) _panic(__FILE__,__LINE__,(f),##__VA_ARGS__)
 
diff --git a/winsup/cygserver/bsd_mutex.cc b/winsup/cygserver/bsd_mutex.cc
index d546a61..8bf0888 100644
--- a/winsup/cygserver/bsd_mutex.cc
+++ b/winsup/cygserver/bsd_mutex.cc
@@ -40,13 +40,13 @@ mtx_init (mtx *m, const char *name, const void *, int)
 void
 _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);
   if (WaitForSingleObject (m->h, INFINITE) != WAIT_OBJECT_0)
     _panic (file, line, "wait for %s in %d failed, %u", m->name, winpid,
 	    GetLastError ());
   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);
 }
 
@@ -89,7 +89,7 @@ _mtx_unlock (mtx *m, const char *file, int line)
 	_panic (file, line, "release of mutex %s failed, %u", m->name,
 		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);
 }
 
diff --git a/winsup/cygserver/process.h b/winsup/cygserver/process.h
index 282586e..a084fb1 100644
--- a/winsup/cygserver/process.h
+++ b/winsup/cygserver/process.h
@@ -82,12 +82,12 @@ public:
   bool is_active () const { return _exit_status == STILL_ACTIVE; }
 
   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);
-    _log (file, line, LOG_DEBUG, "holding (%lu)", _cygpid);
+    _debug (file, line, "holding (%lu)", _cygpid);
   }
   void _release (const char *file, int line) {
-    _log (file, line, LOG_DEBUG, "leaving (%lu)", _cygpid);
+    _debug (file, line, "leaving (%lu)", _cygpid);
     LeaveCriticalSection (&_access);
   }
 
diff --git a/winsup/cygserver/sysv_msg.cc b/winsup/cygserver/sysv_msg.cc
index b3a4990..87ac125 100644
--- a/winsup/cygserver/sysv_msg.cc
+++ b/winsup/cygserver/sysv_msg.cc
@@ -52,7 +52,7 @@ __FBSDID("$FreeBSD: /usr/local/www/cvsroot/FreeBSD/src/sys/kern/sysv_msg.c,v 1.5
 #endif /* __CYGWIN__ */
 
 #ifdef MSG_DEBUG
-#define DPRINTF(a)	debug_printf a
+#define DPRINTF(a)	debug a
 #else
 #define DPRINTF(a)
 #endif
diff --git a/winsup/cygserver/woutsup.h b/winsup/cygserver/woutsup.h
index fbbd4eb..272f978 100644
--- a/winsup/cygserver/woutsup.h
+++ b/winsup/cygserver/woutsup.h
@@ -50,5 +50,5 @@ extern int cygserver_running;
     } while (false)
 
 #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__)



More information about the Cygwin-cvs mailing list