[ntpsec commit] Get rid of ISC_MUTEX_PROFILE.
Eric S. Raymond
esr at ntpsec.org
Tue Sep 29 08:11:57 UTC 2015
Module: ntpsec
Branch: master
Commit: 3af87f7cffe610bbe0fa54f1fd7a48a482dde493
Changeset: http://git.ntpsec.org/ntpsec/commit/?id=3af87f7cffe610bbe0fa54f1fd7a48a482dde493
Author: Eric S. Raymond <esr at thyrsus.com>
Date: Tue Sep 29 04:07:28 2015 -0400
Get rid of ISC_MUTEX_PROFILE.
This is a long step towards replacing the ISC thread/mutex stuff with
bare pthreads. If we're assuming ANSI pthreads the ISC layer is just
unnecessary bulk, and the right way to do profiling is to link a
profiling version of the pthreads library.
Also clean up some guard symbols and a few unnecessary macros.
---
include/ntp_stdlib.h | 2 -
lib/isc/inet_aton.c | 5 -
lib/isc/pthreads/condition.c | 6 -
lib/isc/pthreads/include/isc/condition.h | 6 -
lib/isc/pthreads/include/isc/mutex.h | 70 ----------
lib/isc/pthreads/mutex.c | 207 +----------------------------
lib/isc/win32/include/isc/net.h | 4 -
lib/isc/win32/syslog.h | 2 +-
libntp/msyslog.c | 2 -
libntp/systime.c | 4 -
ntpd/refclock_true.c | 4 -
ports/winnt/include/hopf_PCI_io.h | 6 +-
ports/winnt/include/ntp_iocompletionport.h | 4 +-
13 files changed, 7 insertions(+), 315 deletions(-)
diff --git a/include/ntp_stdlib.h b/include/ntp_stdlib.h
index 66e4c0d..a95c9cb 100644
--- a/include/ntp_stdlib.h
+++ b/include/ntp_stdlib.h
@@ -36,9 +36,7 @@ extern void msyslog(int, const char *, ...) NTP_PRINTF(2, 3);
extern void init_logging (const char *, uint32_t, int);
extern int change_logfile (const char *, int);
extern void setup_logfile (const char *);
-#ifndef errno_to_str
extern void errno_to_str(int, char *, size_t);
-#endif
/*
* When building without OpenSSL, use a few macros of theirs to
diff --git a/lib/isc/inet_aton.c b/lib/isc/inet_aton.c
index 14b4887..7f12582 100644
--- a/lib/isc/inet_aton.c
+++ b/lib/isc/inet_aton.c
@@ -69,11 +69,6 @@
*/
/*! \file */
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)inet_addr.c 8.1 (Berkeley) 6/17/93";
-static char rcsid[] = "$Id: inet_aton.c,v 1.23 2008/12/01 23:47:45 tbox Exp $";
-#endif /* LIBC_SCCS and not lint */
-
#include <config.h>
#include <ctype.h>
diff --git a/lib/isc/pthreads/condition.c b/lib/isc/pthreads/condition.c
index 1f14ea5..63bf733 100644
--- a/lib/isc/pthreads/condition.c
+++ b/lib/isc/pthreads/condition.c
@@ -15,8 +15,6 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
-/* $Id: condition.c,v 1.36 2007/06/19 23:47:18 tbox Exp $ */
-
/*! \file */
#include <config.h>
@@ -52,11 +50,7 @@ isc_condition_waituntil(isc_condition_t *c, isc_mutex_t *m, isc_time_t *t) {
ts.tv_nsec = (long)isc_time_nanoseconds(t);
do {
-#if ISC_MUTEX_PROFILE
- presult = pthread_cond_timedwait(c, &m->mutex, &ts);
-#else
presult = pthread_cond_timedwait(c, m, &ts);
-#endif
if (presult == 0)
return (ISC_R_SUCCESS);
if (presult == ETIMEDOUT)
diff --git a/lib/isc/pthreads/include/isc/condition.h b/lib/isc/pthreads/include/isc/condition.h
index 4c8aa77..7830106 100644
--- a/lib/isc/pthreads/include/isc/condition.h
+++ b/lib/isc/pthreads/include/isc/condition.h
@@ -31,15 +31,9 @@ typedef pthread_cond_t isc_condition_t;
((pthread_cond_init((cp), NULL) == 0) ? \
ISC_R_SUCCESS : ISC_R_UNEXPECTED)
-#if ISC_MUTEX_PROFILE
-#define isc_condition_wait(cp, mp) \
- ((pthread_cond_wait((cp), &((mp)->mutex)) == 0) ? \
- ISC_R_SUCCESS : ISC_R_UNEXPECTED)
-#else
#define isc_condition_wait(cp, mp) \
((pthread_cond_wait((cp), (mp)) == 0) ? \
ISC_R_SUCCESS : ISC_R_UNEXPECTED)
-#endif
#define isc_condition_signal(cp) \
((pthread_cond_signal((cp)) == 0) ? \
diff --git a/lib/isc/pthreads/include/isc/mutex.h b/lib/isc/pthreads/include/isc/mutex.h
index aed1dca..40446a6 100644
--- a/lib/isc/pthreads/include/isc/mutex.h
+++ b/lib/isc/pthreads/include/isc/mutex.h
@@ -42,32 +42,8 @@ extern pthread_mutexattr_t isc__mutex_attrs;
/* XXX We could do fancier error handling... */
-/*!
- * Define ISC_MUTEX_PROFILE to turn on profiling of mutexes by line. When
- * enabled, isc_mutex_stats() can be used to print a table showing the
- * number of times each type of mutex was locked and the amount of time
- * waiting to obtain the lock.
- */
-#ifndef ISC_MUTEX_PROFILE
-#define ISC_MUTEX_PROFILE 0
-#endif
-
-#if ISC_MUTEX_PROFILE
-typedef struct isc_mutexstats isc_mutexstats_t;
-
-typedef struct {
- pthread_mutex_t mutex; /*%< The actual mutex. */
- isc_mutexstats_t * stats; /*%< Mutex statistics. */
-} isc_mutex_t;
-#else
typedef pthread_mutex_t isc_mutex_t;
-#endif
-
-#if ISC_MUTEX_PROFILE
-#define isc_mutex_init(mp) \
- isc_mutex_init_profile((mp), __FILE__, __LINE__)
-#else
#if ISC_MUTEX_DEBUG && defined(PTHREAD_MUTEX_ERRORCHECK)
#define isc_mutex_init(mp) \
isc_mutex_init_errcheck((mp))
@@ -76,68 +52,22 @@ typedef pthread_mutex_t isc_mutex_t;
isc__mutex_init((mp), __FILE__, __LINE__)
isc_result_t isc__mutex_init(isc_mutex_t *mp, const char *file, unsigned int line);
#endif
-#endif
-#if ISC_MUTEX_PROFILE
-#define isc_mutex_lock(mp) \
- isc_mutex_lock_profile((mp), __FILE__, __LINE__)
-#else
#define isc_mutex_lock(mp) \
((pthread_mutex_lock((mp)) == 0) ? \
ISC_R_SUCCESS : ISC_R_UNEXPECTED)
-#endif
-#if ISC_MUTEX_PROFILE
-#define isc_mutex_unlock(mp) \
- isc_mutex_unlock_profile((mp), __FILE__, __LINE__)
-#else
#define isc_mutex_unlock(mp) \
((pthread_mutex_unlock((mp)) == 0) ? \
ISC_R_SUCCESS : ISC_R_UNEXPECTED)
-#endif
-#if ISC_MUTEX_PROFILE
-#define isc_mutex_trylock(mp) \
- ((pthread_mutex_trylock((&(mp)->mutex)) == 0) ? \
- ISC_R_SUCCESS : ISC_R_LOCKBUSY)
-#else
#define isc_mutex_trylock(mp) \
((pthread_mutex_trylock((mp)) == 0) ? \
ISC_R_SUCCESS : ISC_R_LOCKBUSY)
-#endif
-#if ISC_MUTEX_PROFILE
-#define isc_mutex_destroy(mp) \
- ((pthread_mutex_destroy((&(mp)->mutex)) == 0) ? \
- ISC_R_SUCCESS : ISC_R_UNEXPECTED)
-#else
#define isc_mutex_destroy(mp) \
((pthread_mutex_destroy((mp)) == 0) ? \
ISC_R_SUCCESS : ISC_R_UNEXPECTED)
-#endif
-
-#if ISC_MUTEX_PROFILE
-#define isc_mutex_stats(fp) isc_mutex_statsprofile(fp);
-#else
-#define isc_mutex_stats(fp)
-#endif
-
-#if ISC_MUTEX_PROFILE
-
-isc_result_t
-isc_mutex_init_profile(isc_mutex_t *mp, const char * _file, int _line);
-isc_result_t
-isc_mutex_lock_profile(isc_mutex_t *mp, const char * _file, int _line);
-isc_result_t
-isc_mutex_unlock_profile(isc_mutex_t *mp, const char * _file, int _line);
-
-void
-isc_mutex_statsprofile(FILE *fp);
-
-isc_result_t
-isc_mutex_init_errcheck(isc_mutex_t *mp);
-
-#endif /* ISC_MUTEX_PROFILE */
ISC_LANG_ENDDECLS
#endif /* GUARD_ISC_MUTEX_H */
diff --git a/lib/isc/pthreads/mutex.c b/lib/isc/pthreads/mutex.c
index cb1fc51..c72e305 100644
--- a/lib/isc/pthreads/mutex.c
+++ b/lib/isc/pthreads/mutex.c
@@ -15,8 +15,6 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
-/* $Id: mutex.c,v 1.18 2011/01/04 23:47:14 tbox Exp $ */
-
/*! \file */
#include <config.h>
@@ -30,209 +28,6 @@
#include <isc/mutex.h>
#include <isc/util.h>
-#if HAVE_PTHREADS < 5 /* HP-UX 10.20 has 4, needs this */
-# define pthread_mutex_init(m, a) \
- pthread_mutex_init(m, (a) \
- ? *(const pthread_mutexattr_t *)(a) \
- : pthread_mutexattr_default)
-# define PTHREAD_MUTEX_RECURSIVE MUTEX_RECURSIVE_NP
-# define pthread_mutexattr_settype pthread_mutexattr_setkind_np
-#endif
-
-#if ISC_MUTEX_PROFILE
-
-/*@{*/
-/*% Operations on timevals; adapted from FreeBSD's sys/time.h */
-#define timevalclear(tvp) ((tvp)->tv_sec = (tvp)->tv_usec = 0)
-#define timevaladd(vvp, uvp) \
- do { \
- (vvp)->tv_sec += (uvp)->tv_sec; \
- (vvp)->tv_usec += (uvp)->tv_usec; \
- if ((vvp)->tv_usec >= 1000000) { \
- (vvp)->tv_sec++; \
- (vvp)->tv_usec -= 1000000; \
- } \
- } while (0)
-#define timevalsub(vvp, uvp) \
- do { \
- (vvp)->tv_sec -= (uvp)->tv_sec; \
- (vvp)->tv_usec -= (uvp)->tv_usec; \
- if ((vvp)->tv_usec < 0) { \
- (vvp)->tv_sec--; \
- (vvp)->tv_usec += 1000000; \
- } \
- } while (0)
-
-/*@}*/
-
-#define ISC_MUTEX_MAX_LOCKERS 32
-
-typedef struct {
- const char * file;
- int line;
- unsigned count;
- struct timeval locked_total;
- struct timeval wait_total;
-} isc_mutexlocker_t;
-
-struct isc_mutexstats {
- const char * file; /*%< File mutex was created in. */
- int line; /*%< Line mutex was created on. */
- unsigned count;
- struct timeval lock_t;
- struct timeval locked_total;
- struct timeval wait_total;
- isc_mutexlocker_t * cur_locker;
- isc_mutexlocker_t lockers[ISC_MUTEX_MAX_LOCKERS];
-};
-
-#ifndef ISC_MUTEX_PROFTABLESIZE
-#define ISC_MUTEX_PROFTABLESIZE (1024 * 1024)
-#endif
-static isc_mutexstats_t stats[ISC_MUTEX_PROFTABLESIZE];
-static int stats_next = 0;
-static bool stats_init = false;
-static pthread_mutex_t statslock = PTHREAD_MUTEX_INITIALIZER;
-
-
-isc_result_t
-isc_mutex_init_profile(isc_mutex_t *mp, const char *file, int line) {
- int i, err;
-
- err = pthread_mutex_init(&mp->mutex, NULL);
- if (err == ENOMEM)
- return (ISC_R_NOMEMORY);
- if (err != 0)
- return (ISC_R_UNEXPECTED);
-
- RUNTIME_CHECK(pthread_mutex_lock(&statslock) == 0);
-
- if (stats_init == false)
- stats_init = true;
-
- /*
- * If all statistics entries have been used, give up and trigger an
- * assertion failure. There would be no other way to deal with this
- * because we'd like to keep record of all locks for the purpose of
- * debugging and the number of necessary locks is unpredictable.
- * If this failure is triggered while debugging, named should be
- * rebuilt with an increased ISC_MUTEX_PROFTABLESIZE.
- */
- RUNTIME_CHECK(stats_next < ISC_MUTEX_PROFTABLESIZE);
- mp->stats = &stats[stats_next++];
-
- RUNTIME_CHECK(pthread_mutex_unlock(&statslock) == 0);
-
- mp->stats->file = file;
- mp->stats->line = line;
- mp->stats->count = 0;
- timevalclear(&mp->stats->locked_total);
- timevalclear(&mp->stats->wait_total);
- for (i = 0; i < ISC_MUTEX_MAX_LOCKERS; i++) {
- mp->stats->lockers[i].file = NULL;
- mp->stats->lockers[i].line = 0;
- mp->stats->lockers[i].count = 0;
- timevalclear(&mp->stats->lockers[i].locked_total);
- timevalclear(&mp->stats->lockers[i].wait_total);
- }
-
- return (ISC_R_SUCCESS);
-}
-
-isc_result_t
-isc_mutex_lock_profile(isc_mutex_t *mp, const char *file, int line) {
- struct timeval prelock_t;
- struct timeval postlock_t;
- isc_mutexlocker_t *locker = NULL;
- int i;
-
- gettimeofday(&prelock_t, NULL);
-
- if (pthread_mutex_lock(&mp->mutex) != 0)
- return (ISC_R_UNEXPECTED);
-
- gettimeofday(&postlock_t, NULL);
- mp->stats->lock_t = postlock_t;
-
- timevalsub(&postlock_t, &prelock_t);
-
- mp->stats->count++;
- timevaladd(&mp->stats->wait_total, &postlock_t);
-
- for (i = 0; i < ISC_MUTEX_MAX_LOCKERS; i++) {
- if (mp->stats->lockers[i].file == NULL) {
- locker = &mp->stats->lockers[i];
- locker->file = file;
- locker->line = line;
- break;
- } else if (mp->stats->lockers[i].file == file &&
- mp->stats->lockers[i].line == line) {
- locker = &mp->stats->lockers[i];
- break;
- }
- }
-
- if (locker != NULL) {
- locker->count++;
- timevaladd(&locker->wait_total, &postlock_t);
- }
-
- mp->stats->cur_locker = locker;
-
- return (ISC_R_SUCCESS);
-}
-
-isc_result_t
-isc_mutex_unlock_profile(isc_mutex_t *mp, const char *file, int line) {
- struct timeval unlock_t;
-
- UNUSED(file);
- UNUSED(line);
-
- if (mp->stats->cur_locker != NULL) {
- gettimeofday(&unlock_t, NULL);
- timevalsub(&unlock_t, &mp->stats->lock_t);
- timevaladd(&mp->stats->locked_total, &unlock_t);
- timevaladd(&mp->stats->cur_locker->locked_total, &unlock_t);
- mp->stats->cur_locker = NULL;
- }
-
- return ((pthread_mutex_unlock((&mp->mutex)) == 0) ? \
- ISC_R_SUCCESS : ISC_R_UNEXPECTED);
-}
-
-
-void
-isc_mutex_statsprofile(FILE *fp) {
- isc_mutexlocker_t *locker;
- int i, j;
-
- fprintf(fp, "Mutex stats (in us)\n");
- for (i = 0; i < stats_next; i++) {
- fprintf(fp, "%-12s %4d: %10u %lu.%06lu %lu.%06lu %5d\n",
- stats[i].file, stats[i].line, stats[i].count,
- stats[i].locked_total.tv_sec,
- stats[i].locked_total.tv_usec,
- stats[i].wait_total.tv_sec,
- stats[i].wait_total.tv_usec,
- i);
- for (j = 0; j < ISC_MUTEX_MAX_LOCKERS; j++) {
- locker = &stats[i].lockers[j];
- if (locker->file == NULL)
- continue;
- fprintf(fp, " %-11s %4d: %10u %lu.%06lu %lu.%06lu %5d\n",
- locker->file, locker->line, locker->count,
- locker->locked_total.tv_sec,
- locker->locked_total.tv_usec,
- locker->wait_total.tv_sec,
- locker->wait_total.tv_usec,
- i);
- }
- }
-}
-
-#endif /* ISC_MUTEX_PROFILE */
-
#if ISC_MUTEX_DEBUG && defined(PTHREAD_MUTEX_ERRORCHECK)
isc_result_t
isc_mutex_init_errcheck(isc_mutex_t *mp)
@@ -263,7 +58,7 @@ pthread_mutexattr_t isc__mutex_attrs = {
};
#endif
-#if !(ISC_MUTEX_DEBUG && defined(PTHREAD_MUTEX_ERRORCHECK)) && !ISC_MUTEX_PROFILE
+#if !(ISC_MUTEX_DEBUG && defined(PTHREAD_MUTEX_ERRORCHECK))
isc_result_t
isc__mutex_init(isc_mutex_t *mp, const char *file, unsigned int line) {
char strbuf[BUFSIZ];
diff --git a/lib/isc/win32/include/isc/net.h b/lib/isc/win32/include/isc/net.h
index 3f89682..de119ee 100644
--- a/lib/isc/win32/include/isc/net.h
+++ b/lib/isc/win32/include/isc/net.h
@@ -105,10 +105,6 @@
*/
#undef interface
-#ifndef INADDR_LOOPBACK
-#define INADDR_LOOPBACK 0x7f000001UL
-#endif
-
#ifndef ISC_PLATFORM_HAVEIN6PKTINFO
struct in6_pktinfo {
struct in6_addr ipi6_addr; /* src/dst IPv6 address */
diff --git a/lib/isc/win32/syslog.h b/lib/isc/win32/syslog.h
index 7f98b30..b05d611 100644
--- a/lib/isc/win32/syslog.h
+++ b/lib/isc/win32/syslog.h
@@ -15,7 +15,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
-#ifndef GIARD_SYSLOG_H
+#ifndef GUARD_SYSLOG_H
#define GUARD_SYSLOG_H
#include <stdio.h>
diff --git a/libntp/msyslog.c b/libntp/msyslog.c
index 27647cc..ddbb6b1 100644
--- a/libntp/msyslog.c
+++ b/libntp/msyslog.c
@@ -90,7 +90,6 @@ format_errmsg(
* For Windows, we have:
* #define errno_to_str isc_strerror
*/
-#ifndef errno_to_str
void
errno_to_str(
int err,
@@ -109,7 +108,6 @@ errno_to_str(
snprintf(buf, bufsiz, "strerror_r(%d): errno %d",
err, errno);
}
-#endif /* errno_to_str */
/*
diff --git a/libntp/systime.c b/libntp/systime.c
index e8d5b9a..9466082 100644
--- a/libntp/systime.c
+++ b/libntp/systime.c
@@ -508,12 +508,8 @@ step_systime(
*/
tvdiff = abs_tval(sub_tval(timetv, tvlast));
if (tvdiff.tv_sec > 0) {
-#ifndef OTIME_MSG
# define OTIME_MSG "Old NTP time"
-#endif
-#ifndef NTIME_MSG
# define NTIME_MSG "New NTP time"
-#endif
struct utmpx utx;
ZERO(utx);
diff --git a/ntpd/refclock_true.c b/ntpd/refclock_true.c
index ba7ff83..ddd1cd2 100644
--- a/ntpd/refclock_true.c
+++ b/ntpd/refclock_true.c
@@ -176,9 +176,6 @@ struct refclock refclock_true = {
};
-#if !defined(__STDC__)
-# define true_debug (void)
-#else
NTP_PRINTF(2, 3)
static void
true_debug(struct peer *peer, const char *fmt, ...)
@@ -221,7 +218,6 @@ true_debug(struct peer *peer, const char *fmt, ...)
}
va_end(ap);
}
-#endif /*STDC*/
/*
* true_start - open the devices and initialize data for processing
diff --git a/ports/winnt/include/hopf_PCI_io.h b/ports/winnt/include/hopf_PCI_io.h
index 7bca1d3..e4f1b1c 100644
--- a/ports/winnt/include/hopf_PCI_io.h
+++ b/ports/winnt/include/hopf_PCI_io.h
@@ -12,8 +12,8 @@
extern "C"{
#endif
-#ifndef __inpREAD_H
-#define __inpREAD_H
+#ifndef GUARD_HOPF_PCI_IO_H
+#define GUARD_HOPF_PCI_IO_H
typedef struct _CLOCKVER {
@@ -87,5 +87,5 @@ VOID GetDCFAntenne(LPDCFANTENNE Data);
}
#endif
-#endif /* inpREAD_H */
+#endif /* GUARD_HOPF_PCI_IO_H */
diff --git a/ports/winnt/include/ntp_iocompletionport.h b/ports/winnt/include/ntp_iocompletionport.h
index 7d7ff7c..ccec037 100644
--- a/ports/winnt/include/ntp_iocompletionport.h
+++ b/ports/winnt/include/ntp_iocompletionport.h
@@ -1,5 +1,5 @@
-#if !defined __ntp_iocompletionport_h
-# define __ntp_iocompletionport_h
+#if !defined GUARD_NTP_IOCOMPLETIONPORT_H
+# define GUARD_NTP_IOCOMPLETIONPORT_H
#include "ntp_fp.h"
#include "ntp.h"
More information about the vc
mailing list