On Fri, 2009-08-07 at 13:20 +0200, Fabio M. Di Nitto wrote:
> Hi Steven,
> 
> pretty much self explanatory. A patch for flatiron will follow shortly
> (due to some whitespace cleanup in trunk, I haven't been able to cherry
> pick directly).
> 
> Fabio

Patch for flatiron in attachment. Contains the 3 posted before.

Cheers
Fabio
Index: exec/logsys.c
===================================================================
--- exec/logsys.c	(revision 2381)
+++ exec/logsys.c	(working copy)
@@ -131,6 +131,10 @@
 
 static int logsys_system_needs_init = LOGSYS_LOGGER_NEEDS_INIT;
 
+static int logsys_sched_param_queued = 0;
+static int logsys_sched_policy;
+static struct sched_param logsys_sched_param;
+
 static int logsys_after_log_ops_yield = 10;
 
 /*
@@ -783,14 +787,31 @@
 	pthread_mutex_init (&logsys_cond_mutex, NULL);
 	pthread_cond_init (&logsys_cond, NULL);
 	pthread_mutex_lock (&logsys_cond_mutex);
+
+	/*
+	 * TODO: propagate pthread_create errors back to the caller
+	 */
 	res = pthread_create (&logsys_thread_id, NULL,
 		logsys_worker_thread, NULL);
 
-
-	/*
-	 * Wait for thread to be started
-	 */
-	wthread_wait_locked ();
+	if (res == 0) {
+		/*
+		 * Wait for thread to be started
+		 */
+		wthread_wait_locked ();
+		if (logsys_sched_param_queued == 1) {
+			/*
+			 * TODO: propagate logsys_thread_priority_set errors back to
+			 * the caller
+			 */
+			res = logsys_thread_priority_set (logsys_sched_policy,
+						    &logsys_sched_param,
+						    logsys_after_log_ops_yield);
+			logsys_sched_param_queued = 0;
+		}
+	} else {
+		wthread_active = 0;
+	}
 }
 
 static int _logsys_config_subsys_get_unlocked (const char *subsys)
@@ -1610,15 +1631,20 @@
 	int res = 0;
 
 #if defined(HAVE_PTHREAD_SETSCHEDPARAM) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
-	if (policy != SCHED_OTHER) {
+	if (wthread_active == 0) {
+		logsys_sched_policy = policy;
+		memcpy(&logsys_sched_param, &param, sizeof(struct sched_param));
+		logsys_sched_param_queued = 1;
+	} else {
 		res = pthread_setschedparam (logsys_thread_id, policy, param);
 	}
 #endif
+
 	if (after_log_ops_yield > 0) {
 		logsys_after_log_ops_yield = after_log_ops_yield;
 	}
+
 	return (res);
-
 }
 
 int logsys_log_rec_store (const char *filename)
Index: exec/main.c
===================================================================
--- exec/main.c	(revision 2381)
+++ exec/main.c	(working copy)
@@ -700,11 +700,24 @@
 			global_sched_param.sched_priority = 0;
 			log_printf (LOGSYS_LEVEL_WARNING, "Could not set SCHED_RR at priority %d: %s\n",
 				global_sched_param.sched_priority, strerror (errno));
+
+			logsys_thread_priority_set (SCHED_OTHER, NULL, 1);
 		} else {
 			/*
 			 * Turn on SCHED_RR in ipc system
 			 */
 			ipc_init_state.sched_policy = SCHED_RR;
+
+			/*
+			 * Turn on SCHED_RR in logsys system
+			 */
+			res = logsys_thread_priority_set (SCHED_RR, &global_sched_param, 10);
+			if (res == -1) {
+				log_printf (LOGSYS_LEVEL_ERROR,
+					    "Could not set logsys thread priority."
+					    "  Can't continue because of priority inversions.");
+				corosync_exit_error (AIS_DONE_LOGSETUP);
+			}
 		}
 	} else {
 		log_printf (LOGSYS_LEVEL_WARNING, "Could not get maximum scheduler priority: %s\n", strerror (errno));
@@ -762,9 +775,6 @@
 		}
 	}
 
-	if (background)
-		corosync_tty_detach ();
-
 	/*
 	 * Set round robin realtime scheduling with priority 99
 	 * Lock all memory to avoid page faults which may interrupt
@@ -878,17 +888,6 @@
 		syslog (LOGSYS_LEVEL_ERROR, "%s", error_string);
 		corosync_exit_error (AIS_DONE_MAINCONFIGREAD);
 	}
-	logsys_fork_completed();
-	if (setprio) {
-		res = logsys_thread_priority_set (SCHED_RR, &global_sched_param, 10);
-		if (res == -1) {
-			log_printf (LOGSYS_LEVEL_ERROR,
-				"Could not set logsys thread priority.  Can't continue because of priority inversions.");
-			corosync_exit_error (AIS_DONE_LOGSETUP);
-		}
-	} else {
-		res = logsys_thread_priority_set (SCHED_OTHER, NULL, 1);
-	}
 
 	/*
 	 * Make sure required directory is present
@@ -1037,6 +1036,15 @@
 	coroipcs_ipc_init (&ipc_init_state);
 
 	/*
+	 * Now we are fully initialized
+	 */
+	if (background) {
+		corosync_tty_detach ();
+	}
+
+	logsys_fork_completed();
+
+	/*
 	 * Start main processing loop
 	 */
 	poll_run (corosync_poll_handle);
_______________________________________________
Openais mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/openais

Reply via email to