4
0
Эх сурвалжийг харах

Add logsys yield counter for the logsys thread.

git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@2139 fd59a12c-fef9-0310-b244-a6a79926bd2f
Steven Dake 17 жил өмнө
parent
commit
2505b53703

+ 20 - 3
exec/logsys.c

@@ -62,6 +62,8 @@
 
 #include <corosync/engine/logsys.h>
 
+#define YIELD_AFTER_LOG_OPS 10
+
 /*
  * similar to syslog facilities/priorities tables,
  * make a tag table for internal use
@@ -105,6 +107,8 @@ int flt_data_size;
 
 static int logsys_system_needs_init = LOGSYS_LOGGER_NEEDS_INIT;
 
+static int logsys_after_log_ops_yield = 10;
+
 /*
  * need unlogical order to preserve 64bit alignment
  */
@@ -577,6 +581,8 @@ static void *logsys_worker_thread (void *data)
 		 * Process any pending log messages here
 		 */
 		for (;;) {
+			int yield_counter = 1;
+			
 			logsys_lock();
 			if (log_requests_lost > 0) {
 				printf ("lost %d log requests\n", log_requests_lost);
@@ -598,6 +604,10 @@ static void *logsys_worker_thread (void *data)
 			 */
 			if (log_msg) {
 				record_print (buf);
+				if (yield_counter++ > logsys_after_log_ops_yield) {
+					yield_counter = 0;
+					sched_yield ();
+				}
 			}
 		}
 
@@ -1495,11 +1505,18 @@ const char *logsys_tag_name_get (unsigned int tag)
 
 int logsys_thread_priority_set (
 	int policy,
-	const struct sched_param *param)
+	const struct sched_param *param,
+        unsigned int after_log_ops_yield)
+
 {
-	int res;
+	int res = 0;
 
-	res = pthread_setschedparam (logsys_thread_id, policy, param);
+	if (policy != SCHED_OTHER) {
+		res = pthread_setschedparam (logsys_thread_id, policy, param);
+	}
+	if (after_log_ops_yield > 0) {
+		logsys_after_log_ops_yield = after_log_ops_yield;
+	}
 	return (res);
 
 }

+ 3 - 1
exec/main.c

@@ -856,12 +856,14 @@ int main (int argc, char **argv)
 	}
 	logsys_fork_completed();
 	if (setprio) {
-		res = logsys_thread_priority_set (SCHED_RR, &global_sched_param);
+		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);
 	}
 
 	res = totem_config_read (objdb, &totem_config, &error_string);

+ 2 - 1
include/corosync/engine/logsys.h

@@ -254,7 +254,8 @@ extern const char *logsys_tag_name_get (
 
 extern int logsys_thread_priority_set (
 	int policy,
-	const struct sched_param *param);
+	const struct sched_param *param,
+	unsigned int after_log_ops_yield);
 
 /*
  * External definitions