From e5bb5ade55bfecdc120632e550e3a8ba8dbbc68b Mon Sep 17 00:00:00 2001 From: Thomas Schoebel-Theuer Date: Sun, 10 Dec 2017 22:43:28 +0100 Subject: [PATCH] logger: replace spinlock by rwsem --- kernel/mars_trans_logger.c | 19 +++++++------------ kernel/mars_trans_logger.h | 2 +- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/kernel/mars_trans_logger.c b/kernel/mars_trans_logger.c index 1167438d..0f079a56 100644 --- a/kernel/mars_trans_logger.c +++ b/kernel/mars_trans_logger.c @@ -2708,7 +2708,6 @@ void replay_endio(struct generic_callback *cb) struct trans_logger_mref_aspect *mref_a = cb->cb_private; struct trans_logger_brick *brick; bool ok; - unsigned long flags; _crashme(22, false); @@ -2722,10 +2721,10 @@ void replay_endio(struct generic_callback *cb) MARS_ERR("IO error = %d\n", cb->cb_error); } - traced_lock(&brick->replay_lock, flags); + down_write(&brick->replay_mutex); ok = !list_empty(&mref_a->replay_head); list_del_init(&mref_a->replay_head); - traced_unlock(&brick->replay_lock, flags); + up_write(&brick->replay_mutex); if (likely(ok)) { atomic_dec(&brick->replay_count); @@ -2745,11 +2744,8 @@ bool _has_conflict(struct trans_logger_brick *brick, struct trans_logger_mref_as struct mref_object *mref = mref_a->object; struct list_head *tmp; bool res = false; - unsigned long flags; - // NOTE: replacing this by rwlock_t will not gain anything, because there exists at most 1 reader at any time - - traced_lock(&brick->replay_lock, flags); + down_read(&brick->replay_mutex); for (tmp = brick->replay_list.next; tmp != &brick->replay_list; tmp = tmp->next) { struct trans_logger_mref_aspect *tmp_a; @@ -2763,7 +2759,7 @@ bool _has_conflict(struct trans_logger_brick *brick, struct trans_logger_mref_as } } - traced_unlock(&brick->replay_lock, flags); + up_read(&brick->replay_mutex); return res; } @@ -2774,7 +2770,6 @@ void wait_replay(struct trans_logger_brick *brick, struct trans_logger_mref_aspe int conflicts = 0; bool ok = false; bool was_empty; - unsigned long flags; wait_event_interruptible_timeout(brick->worker_event, atomic_read(&brick->replay_count) < max @@ -2785,7 +2780,7 @@ void wait_replay(struct trans_logger_brick *brick, struct trans_logger_mref_aspe if (conflicts) atomic_inc(&brick->total_replay_conflict_count); - traced_lock(&brick->replay_lock, flags); + down_write(&brick->replay_mutex); was_empty = !!list_empty(&mref_a->replay_head); if (likely(was_empty)) { atomic_inc(&brick->replay_count); @@ -2793,7 +2788,7 @@ void wait_replay(struct trans_logger_brick *brick, struct trans_logger_mref_aspe list_del(&mref_a->replay_head); } list_add(&mref_a->replay_head, &brick->replay_list); - traced_unlock(&brick->replay_lock, flags); + up_write(&brick->replay_mutex); if (unlikely(!was_empty)) { MARS_ERR("replay_head was already used (ok=%d, conflicts=%d, replay_count=%d)\n", ok, conflicts, atomic_read(&brick->replay_count)); @@ -3391,7 +3386,7 @@ int trans_logger_brick_construct(struct trans_logger_brick *brick) } atomic_set(&brick->hash_count, 0); - spin_lock_init(&brick->replay_lock); + init_rwsem(&brick->replay_mutex); INIT_LIST_HEAD(&brick->replay_list); INIT_LIST_HEAD(&brick->group_head); init_waitqueue_head(&brick->worker_event); diff --git a/kernel/mars_trans_logger.h b/kernel/mars_trans_logger.h index 723abab0..9b059153 100644 --- a/kernel/mars_trans_logger.h +++ b/kernel/mars_trans_logger.h @@ -187,7 +187,7 @@ struct trans_logger_brick { struct trans_logger_hash_anchor **hash_table; struct list_head group_head; loff_t old_margin; - spinlock_t replay_lock; + struct rw_semaphore replay_mutex; struct list_head replay_list; struct task_struct *thread; wait_queue_head_t worker_event;