Skip to content

Commit

Permalink
fixup: avoid mutex naming unless tracing, remove extra delivery lock …
Browse files Browse the repository at this point in the history
…details
  • Loading branch information
kgiusti committed Aug 24, 2021
1 parent 72d852a commit 7385e53
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 34 deletions.
39 changes: 20 additions & 19 deletions src/posix/threading.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ static inline uint64_t timediff(const struct timespec start,
return stop.tv_nsec + nsecs - start.tv_nsec;
}

#define TRACE_INIT(M) \
#define TRACE_INIT(M, N) \
do { \
(M)->name = qd_strdup((N)); \
(M)->nsec_wait = 0; \
(M)->lock_count = 0; \
(M)->max_wait[0] = 0; \
Expand All @@ -65,15 +66,19 @@ static inline uint64_t timediff(const struct timespec start,
} while (0);

#define TRACE_DUMP(M) \
if ((M)->lock_count) { \
fprintf(stderr, \
"%30s: total(nsec)= %-10"PRIu64 \
" avg= %-10"PRIu64" count= %-6"PRIu64 \
" max= %"PRIu64" %"PRIu64" %"PRIu64"\n", \
(M)->name, (M)->nsec_wait, \
(M)->nsec_wait/(M)->lock_count, (M)->lock_count, \
(M)->max_wait[0], (M)->max_wait[1], (M)->max_wait[2]); \
}
do { \
if ((M)->lock_count) { \
fprintf(stderr, \
"%30s: total(nsec)= %-10"PRIu64 \
" avg= %-10"PRIu64" count= %-6"PRIu64 \
" max= %"PRIu64" %"PRIu64" %"PRIu64"\n", \
(M)->name, (M)->nsec_wait, \
(M)->nsec_wait/(M)->lock_count, (M)->lock_count, \
(M)->max_wait[0], (M)->max_wait[1], \
(M)->max_wait[2]); \
} \
free((M)->name); \
} while (0)

#define TRACE_UPDATE(M,N) \
if ((N) > 1000) { \
Expand All @@ -96,15 +101,15 @@ static inline uint64_t timediff(const struct timespec start,
}

#else
#define TRACE_INIT(M)
#define TRACE_INIT(M, N) (void)(N)
#define TRACE_DUMP(M)
#endif


struct sys_mutex_t {
pthread_mutex_t mutex;
char *name;
#ifdef QD_TRACE_LOCK_CONTENTION
char *name;
uint64_t nsec_wait;
uint64_t lock_count;
uint64_t max_wait[3];
Expand All @@ -117,10 +122,9 @@ sys_mutex_t *sys_mutex(const char *name)
sys_mutex_t *mutex = 0;
NEW_CACHE_ALIGNED(sys_mutex_t, mutex);
_CHECK(mutex != 0);
mutex->name = qd_strdup(name);
int result = pthread_mutex_init(&(mutex->mutex), 0);
_CHECK(result == 0);
TRACE_INIT(mutex);
TRACE_INIT(mutex, name);
return mutex;
}

Expand All @@ -130,7 +134,6 @@ void sys_mutex_free(sys_mutex_t *mutex)
int result = pthread_mutex_destroy(&(mutex->mutex));
_CHECK(result == 0);
TRACE_DUMP(mutex);
free(mutex->name);
free(mutex);
}

Expand Down Expand Up @@ -206,8 +209,8 @@ void sys_cond_signal_all(sys_cond_t *cond)

struct sys_rwlock_t {
pthread_rwlock_t lock;
char *name;
#ifdef QD_TRACE_LOCK_CONTENTION
char *name;
uint64_t nsec_wait;
uint64_t lock_count;
uint64_t max_wait[3];
Expand All @@ -218,10 +221,9 @@ struct sys_rwlock_t {
sys_rwlock_t *sys_rwlock(const char *name)
{
sys_rwlock_t *lock = NEW(sys_rwlock_t);
lock->name = qd_strdup(name);
int result = pthread_rwlock_init(&(lock->lock), 0);
_CHECK(result == 0);
TRACE_INIT(lock);
TRACE_INIT(lock, name);
return lock;
}

Expand All @@ -231,7 +233,6 @@ void sys_rwlock_free(sys_rwlock_t *lock)
int result = pthread_rwlock_destroy(&(lock->lock));
_CHECK(result == 0);
TRACE_DUMP(lock);
free(lock->name);
free(lock);
}

Expand Down
4 changes: 1 addition & 3 deletions src/router_core/core_link_endpoint.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,7 @@ qdr_delivery_t *qdrc_endpoint_delivery_CT(qdr_core_t *core, qdrc_endpoint_t *end
dlv->delivery_id = next_delivery_id();
dlv->link_id = endpoint->link->identity;
dlv->conn_id = endpoint->link->conn_id;
char name[64];
snprintf(name, sizeof(name), "delivery-%"PRIu32, dlv->delivery_id);
dlv->dispo_lock = sys_mutex(name);
dlv->dispo_lock = sys_mutex("dlv-dispo");
qd_log(core->log, QD_LOG_DEBUG, DLV_FMT" Delivery created qdrc_endpoint_delivery_CT", DLV_ARGS(dlv));
return dlv;
}
Expand Down
4 changes: 1 addition & 3 deletions src/router_core/forwarder.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,7 @@ qdr_delivery_t *qdr_forward_new_delivery_CT(qdr_core_t *core, qdr_delivery_t *in
out_dlv->delivery_id = next_delivery_id();
out_dlv->link_id = out_link->identity;
out_dlv->conn_id = out_link->conn_id;
char name[64];
snprintf(name, sizeof(name), "delivery-%"PRIu32, out_dlv->delivery_id);
out_dlv->dispo_lock = sys_mutex(name);
out_dlv->dispo_lock = sys_mutex("dlv-dispo");
qd_log(core->log, QD_LOG_DEBUG, DLV_FMT" Delivery created qdr_forward_new_delivery_CT", DLV_ARGS(out_dlv));

if (in_dlv) {
Expand Down
12 changes: 3 additions & 9 deletions src/router_core/transfer.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ qdr_delivery_t *qdr_link_deliver(qdr_link_t *link, qd_message_t *msg, qd_iterato
dlv->delivery_id = next_delivery_id();
dlv->link_id = link->identity;
dlv->conn_id = link->conn_id;
char name[64];
snprintf(name, sizeof(name), "delivery-%"PRIu32, dlv->delivery_id);
dlv->dispo_lock = sys_mutex(name);
dlv->dispo_lock = sys_mutex("dlv-dispo");
qd_log(link->core->log, QD_LOG_DEBUG, DLV_FMT" Delivery created qdr_link_deliver", DLV_ARGS(dlv));

qdr_delivery_incref(dlv, "qdr_link_deliver - newly created delivery, add to action list");
Expand Down Expand Up @@ -97,9 +95,7 @@ qdr_delivery_t *qdr_link_deliver_to(qdr_link_t *link, qd_message_t *msg,
dlv->delivery_id = next_delivery_id();
dlv->link_id = link->identity;
dlv->conn_id = link->conn_id;
char name[64];
snprintf(name, sizeof(name), "delivery-%"PRIu32, dlv->delivery_id);
dlv->dispo_lock = sys_mutex(name);
dlv->dispo_lock = sys_mutex("dlv-dispo");
qd_log(link->core->log, QD_LOG_DEBUG, DLV_FMT" Delivery created qdr_link_deliver_to", DLV_ARGS(dlv));

qdr_delivery_incref(dlv, "qdr_link_deliver_to - newly created delivery, add to action list");
Expand Down Expand Up @@ -130,9 +126,7 @@ qdr_delivery_t *qdr_link_deliver_to_routed_link(qdr_link_t *link, qd_message_t *
dlv->delivery_id = next_delivery_id();
dlv->link_id = link->identity;
dlv->conn_id = link->conn_id;
char name[64];
snprintf(name, sizeof(name), "delivery-%"PRIu32, dlv->delivery_id);
dlv->dispo_lock = sys_mutex(name);
dlv->dispo_lock = sys_mutex("dlv-dispo");
qd_log(link->core->log, QD_LOG_DEBUG, DLV_FMT" Delivery created qdr_link_deliver_to_routed_link", DLV_ARGS(dlv));

qdr_delivery_incref(dlv, "qdr_link_deliver_to_routed_link - newly created delivery, add to action list");
Expand Down

0 comments on commit 7385e53

Please sign in to comment.