[PATCH 2/3] Change lock that protects per target events list to rwlock

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 usr/iscsi/iscsi_tcp.c |   12 ++++++------
 usr/iscsi/iscsid.h    |    2 +-
 usr/iscsi/target.c    |    7 ++++---
 3 files changed, 11 insertions(+), 10 deletions(-)

Index: tgt-thread/usr/iscsi/iscsi_tcp.c
===================================================================
--- tgt-thread.orig/usr/iscsi/iscsi_tcp.c
+++ tgt-thread/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_add(tcp_conn->fd, EPOLLIN,
@@ -290,13 +290,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);
 }
@@ -377,10 +377,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-thread/usr/iscsi/iscsid.h
===================================================================
--- tgt-thread.orig/usr/iscsi/iscsid.h
+++ tgt-thread/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-thread/usr/iscsi/target.c
===================================================================
--- tgt-thread.orig/usr/iscsi/target.c
+++ tgt-thread/usr/iscsi/target.c
@@ -385,6 +385,7 @@ void iscsi_target_destroy(int tid)
 
 		pthread_join(target->thread, NULL);
 		pthread_mutex_destroy(&target->bsfin.finished_lock);
+		pthread_rwlock_destroy(&target->event_rwlock);
 	}
 
 	close(target->efd);
@@ -410,14 +411,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 +486,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@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux SCSI]     [Linux RAID]     [Linux Clusters]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]

  Powered by Linux