Просмотр исходного кода

Make all threads use same scheduling priority even with -p option
specified to avoid deadlock in spinlocks.


git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@1912 fd59a12c-fef9-0310-b244-a6a79926bd2f

Steven Dake 17 лет назад
Родитель
Сommit
e77b1e21ad
6 измененных файлов с 37 добавлено и 10 удалено
  1. 7 0
      exec/coroipcs.c
  2. 1 0
      exec/coroipcs.h
  3. 12 5
      exec/main.c
  4. 11 4
      exec/timer.c
  5. 2 1
      exec/timer.h
  6. 4 0
      lib/coroipcc.c

+ 7 - 0
exec/coroipcs.c

@@ -259,6 +259,13 @@ static void *pthread_ipc_consumer (void *conn)
 	struct res_overlay res_overlay;
 	int send_ok;
 
+	if (api->sched_priority != 0) {
+		struct sched_param sched_param;
+
+		sched_param.sched_priority = api->sched_priority;
+		res = pthread_setschedparam (conn_info->thread, SCHED_RR, &sched_param);
+	}
+
 	for (;;) {
 		sop.sem_num = 0;
 		sop.sem_op = -1;

+ 1 - 0
exec/coroipcs.h

@@ -45,6 +45,7 @@ typedef void (*coroipcs_handler_fn_lvalue) (void *conn, void *msg);
 
 struct coroipcs_init_state {
 	const char *socket_name;
+	int sched_priority;
 	void *(*malloc) (size_t size);
 	void (*free) (void *ptr);
         void (*log_printf) (

+ 12 - 5
exec/main.c

@@ -93,6 +93,8 @@ LOGSYS_DECLARE_SUBSYS ("MAIN", LOG_INFO);
 
 #define SERVER_BACKLOG 5
 
+static int sched_priority = 0;
+
 static unsigned int service_count = 32;
 
 #if defined(HAVE_PTHREAD_SPIN_LOCK)
@@ -364,16 +366,18 @@ static void corosync_setscheduler (void)
 	struct sched_param sched_param;
 	int res;
 
-	res = sched_get_priority_max (SCHED_RR);
-	if (res != -1) {
-		sched_param.sched_priority = 1;//res;
+	sched_priority = sched_get_priority_max (SCHED_RR);
+	if (sched_priority != -1) {
+		sched_param.sched_priority = sched_priority;
 		res = sched_setscheduler (0, SCHED_RR, &sched_param);
 		if (res == -1) {
 			log_printf (LOG_LEVEL_WARNING, "Could not set SCHED_RR at priority %d: %s\n",
 				sched_param.sched_priority, strerror (errno));
 		}
-	} else
+	} else {
 		log_printf (LOG_LEVEL_WARNING, "Could not get maximum scheduler priority: %s\n", strerror (errno));
+		sched_priority = 0;
+	}
 #else
 	log_printf(LOG_LEVEL_WARNING, "Scheduler priority left to default value (no OS support)\n");
 #endif
@@ -730,7 +734,8 @@ int main (int argc, char **argv)
 	
 	corosync_timer_init (
 		serialize_lock,
-		serialize_unlock);
+		serialize_unlock,
+		sched_priority);
 
 	log_printf (LOG_LEVEL_NOTICE, "Corosync Executive Service: started and ready to provide service.\n");
 
@@ -906,6 +911,8 @@ int main (int argc, char **argv)
 
 	ipc_subsys_id = _logsys_subsys_create ("IPC", LOG_INFO);
 
+	ipc_init_state.sched_priority = sched_priority;
+
 	coroipcs_ipc_init (&ipc_init_state);
 
 	/*

+ 11 - 4
exec/timer.c

@@ -90,6 +90,8 @@ static pthread_attr_t thread_attr;
 
 static struct timerlist timers_timerlist;
 
+static int sched_priority = 0;
+
 static void (*timer_serialize_lock_fn) (void);
 
 static void (*timer_serialize_unlock_fn) (void);
@@ -107,11 +109,14 @@ static void *prioritized_timer_thread (void *data)
 	unsigned long long timeout;
 
 #if ! defined(TS_CLASS) && (defined(COROSYNC_BSD) || defined(COROSYNC_LINUX) || defined(COROSYNC_SOLARIS))
-	struct sched_param sched_param;
 	int res;
 
-	sched_param.sched_priority = 2;
-	res = pthread_setschedparam (expiry_thread, SCHED_RR, &sched_param);
+	if (sched_priority != 0) {
+		struct sched_param sched_param;
+
+		sched_param.sched_priority = sched_priority;
+		res = pthread_setschedparam (expiry_thread, SCHED_RR, &sched_param);
+	}
 #endif
 
 	pthread_mutex_unlock (&timer_mutex);
@@ -148,12 +153,14 @@ static void sigusr1_handler (int num) {
 
 int corosync_timer_init (
         void (*serialize_lock_fn) (void),
-        void (*serialize_unlock_fn) (void))
+        void (*serialize_unlock_fn) (void),
+	int sched_priority_in)
 {
 	int res;
 
 	timer_serialize_lock_fn = serialize_lock_fn;
 	timer_serialize_unlock_fn = serialize_unlock_fn;
+	sched_priority = sched_priority_in;
 
 	timerlist_init (&timers_timerlist);
 

+ 2 - 1
exec/timer.h

@@ -39,7 +39,8 @@ typedef void * corosync_timer_handle;
 
 extern void corosync_timer_init (
         void (*serialize_lock) (void),
-        void (*serialize_unlock) (void));
+        void (*serialize_unlock) (void),
+	int sched_priority);
 
 extern int corosync_timer_add_duration (
 	unsigned long long nanoseconds_in_future,

+ 4 - 0
lib/coroipcc.c

@@ -100,6 +100,10 @@ void socket_nosigpipe(int s)
 }
 #endif 
 
+#ifndef MSG_NOSIGNAL
+#define MSG_NOSIGNAL 0
+#endif
+
 static int
 coroipcc_send (
 	int s,