[stgt] [PATCH 2/3] Change per target event_lock to event_rwlock
Chandra Seetharaman
sekharan at us.ibm.com
Tue Sep 28 03:18:07 CEST 2010
Convert the per thread lock events_lock to a read write lock events_rwlock.
This will help with performance as there are more walk-thru the list
than the add/delete operations.
Signed-off-by: Chandra Seetharaman <sekharan at us.ibm.com>
---
usr/iscsi/iscsi_tcp.c | 12 ++++++------
usr/iscsi/iscsid.h | 2 +-
usr/iscsi/target.c | 6 +++---
3 files changed, 10 insertions(+), 10 deletions(-)
Index: tgt-102236c/usr/iscsi/iscsi_tcp.c
===================================================================
--- tgt-102236c.orig/usr/iscsi/iscsi_tcp.c
+++ tgt-102236c/usr/iscsi/iscsi_tcp.c
@@ -171,10 +171,10 @@ static void iscsi_tcp_event_handler(int
if (tcp_conn->pthread) {
struct iscsi_target *target = conn->session->target;
- pthread_mutex_lock(&target->event_lock);
+ pthread_rwlock_wrlock(&target->event_rwlock);
do_tgt_event_del(target->efd, &target->events_list,
tcp_conn->fd);
- pthread_mutex_unlock(&target->event_lock);
+ pthread_rwlock_unlock(&target->event_rwlock);
/* let the main thread handle this */
tcp_conn->pthread = 0;
tgt_event_modify(tcp_conn->fd, EPOLLIN|EPOLLOUT|EPOLLERR);
@@ -289,13 +289,13 @@ static void iscsi_tcp_conn_nexus_init(st
tcp_conn->pthread = 1;
- pthread_mutex_lock(&target->event_lock);
+ pthread_rwlock_wrlock(&target->event_rwlock);
do_tgt_event_add(target->efd, &target->events_list,
tcp_conn->fd, EPOLLIN,
iscsi_tcp_event_handler, conn);
- pthread_mutex_unlock(&target->event_lock);
+ pthread_rwlock_unlock(&target->event_rwlock);
} else
conn->tp->ep_event_modify(conn, EPOLLIN);
}
@@ -376,10 +376,10 @@ static void iscsi_event_modify(struct is
if (tcp_conn->pthread) {
struct iscsi_target *target = conn->session->target;
- pthread_mutex_lock(&target->event_lock);
+ pthread_rwlock_rdlock(&target->event_rwlock);
do_tgt_event_modify(target->efd, &target->events_list,
tcp_conn->fd, events);
- pthread_mutex_unlock(&target->event_lock);
+ pthread_rwlock_unlock(&target->event_rwlock);
} else {
ret = tgt_event_modify(tcp_conn->fd, events);
if (ret)
Index: tgt-102236c/usr/iscsi/iscsid.h
===================================================================
--- tgt-102236c.orig/usr/iscsi/iscsid.h
+++ tgt-102236c/usr/iscsi/iscsid.h
@@ -254,7 +254,7 @@ struct iscsi_target {
struct list_head isns_list;
int efd;
- pthread_mutex_t event_lock;
+ pthread_rwlock_t event_rwlock;
struct list_head events_list;
pthread_t thread;
Index: tgt-102236c/usr/iscsi/target.c
===================================================================
--- tgt-102236c.orig/usr/iscsi/target.c
+++ tgt-102236c/usr/iscsi/target.c
@@ -410,14 +410,14 @@ static void *iscsi_thread_fn(void *arg)
INIT_LIST_HEAD(&t->bsfin.finished_list);
t->bsfin.th_id = syscall(SYS_gettid);
- pthread_mutex_lock(&t->event_lock);
+ pthread_rwlock_wrlock(&t->event_rwlock);
eprintf("Th_id: %d\n", t->bsfin.th_id);
do_tgt_event_add(t->efd, &t->events_list, sig_fd, EPOLLIN,
bs_sig_request_done, &t->bsfin);
- pthread_mutex_unlock(&t->event_lock);
+ pthread_rwlock_unlock(&t->event_rwlock);
retry:
nevent = epoll_wait(t->efd, events, ARRAY_SIZE(events), 1000);
if (nevent < 0) {
@@ -485,7 +485,7 @@ int iscsi_target_create(struct target *t
INIT_LIST_HEAD(&target->sessions_list);
INIT_LIST_HEAD(&target->isns_list);
INIT_LIST_HEAD(&target->events_list);
- pthread_mutex_init(&target->event_lock, NULL);
+ pthread_rwlock_init(&target->event_rwlock, NULL);
target->tid = tid;
list_add_tail(&target->tlist, &iscsi_targets_list);
--
To unsubscribe from this list: send the line "unsubscribe stgt" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
More information about the stgt
mailing list