tracker r2923 - in trunk: . src/libtracker-common src/tracker-indexer src/trackerd



Author: mr
Date: Thu Feb 12 12:52:36 2009
New Revision: 2923
URL: http://svn.gnome.org/viewvc/tracker?rev=2923&view=rev

Log:
	* src/libtracker-common/tracker-ioprio.c:
	* src/tracker-indexer/tracker-main.c: 
	* src/trackerd/tracker-main.c: Use SCHED_IDLE for the process
	scheduling to improve responsiveness of phone calls and other real
	time applications. Fixes NB#95573.


Modified:
   trunk/ChangeLog
   trunk/src/libtracker-common/tracker-ioprio.c
   trunk/src/tracker-indexer/tracker-main.c
   trunk/src/trackerd/tracker-main.c

Modified: trunk/src/libtracker-common/tracker-ioprio.c
==============================================================================
--- trunk/src/libtracker-common/tracker-ioprio.c	(original)
+++ trunk/src/libtracker-common/tracker-ioprio.c	Thu Feb 12 12:52:36 2009
@@ -128,7 +128,7 @@
 void
 tracker_ioprio_init (void)
 {
-	g_message ("Setting IO priority...");
+	g_message ("Setting IO priority");
 
 	if (set_io_priority_idle () == -1) {
 		g_message ("Could not set idle IO priority, attempting best effort of 7");

Modified: trunk/src/tracker-indexer/tracker-main.c
==============================================================================
--- trunk/src/tracker-indexer/tracker-main.c	(original)
+++ trunk/src/tracker-indexer/tracker-main.c	Thu Feb 12 12:52:36 2009
@@ -26,6 +26,8 @@
 #include <errno.h>
 #include <sys/types.h>
 #include <unistd.h>
+#include <linux/sched.h>
+#include <sched.h>
 
 #include <glib.h>
 #include <glib-object.h>
@@ -202,6 +204,53 @@
 #endif
 }
 
+static void
+initialize_priority (void)
+{
+	struct sched_param sp;
+
+	/* Set disk IO priority and scheduling */
+	tracker_ioprio_init ();
+
+	/* Set process priority:
+	 * The nice() function uses attribute "warn_unused_result" and
+	 * so complains if we do not check its returned value. But it
+	 * seems that since glibc 2.2.4, nice() can return -1 on a
+	 * successful call so we have to check value of errno too.
+	 * Stupid... 
+	 */
+	g_message ("Setting process priority");
+
+	if (nice (19) == -1) {
+		const gchar *str = g_strerror (errno);
+
+		g_message ("Couldn't set nice value to 19, %s",
+			   str ? str : "no error given");
+	}
+
+	/* Set process scheduling parameters:
+	 * This is used so we don't steal scheduling priority from
+	 * the most important applications - like the phone
+	 * application which has a real time requirement here. This
+	 * is detailed in Nokia bug #95573 
+	 */
+	g_message ("Setting scheduling priority");
+
+	if (sched_getparam (0, &sp) == 0) {
+		if (sched_setscheduler (0, SCHED_IDLE, &sp) != 0) {
+			const gchar *str = g_strerror (errno);
+			
+			g_message ("Couldn't set scheduler priority, %s",
+				   str ? str : "no error given");
+		}
+	} else {
+		const gchar *str = g_strerror (errno);
+
+		g_message ("Couldn't get scheduler priority, %s",
+			   str ? str : "no error given");
+	}
+}
+
 static gboolean
 quit_timeout_cb (gpointer user_data)
 {
@@ -300,6 +349,9 @@
 		return EXIT_FAILURE;
 	}
 
+	/* This makes sure we don't steal all the system's resources */
+	initialize_priority ();
+
 	/* Initialize logging */
 	config = tracker_config_new ();
 	language = tracker_language_new (config);

Modified: trunk/src/trackerd/tracker-main.c
==============================================================================
--- trunk/src/trackerd/tracker-main.c	(original)
+++ trunk/src/trackerd/tracker-main.c	Thu Feb 12 12:52:36 2009
@@ -33,6 +33,8 @@
 #include <fcntl.h>
 #include <errno.h>
 #include <time.h>
+#include <linux/sched.h>
+#include <sched.h>
 
 #include <glib.h>
 #include <glib/gi18n.h>
@@ -482,6 +484,53 @@
 }
 
 static void
+initialize_priority (void)
+{
+	struct sched_param sp;
+
+	/* Set disk IO priority and scheduling */
+	tracker_ioprio_init ();
+
+	/* Set process priority:
+	 * The nice() function uses attribute "warn_unused_result" and
+	 * so complains if we do not check its returned value. But it
+	 * seems that since glibc 2.2.4, nice() can return -1 on a
+	 * successful call so we have to check value of errno too.
+	 * Stupid... 
+	 */
+	g_message ("Setting process priority");
+
+	if (nice (19) == -1) {
+		const gchar *str = g_strerror (errno);
+
+		g_message ("Couldn't set nice value to 19, %s",
+			   str ? str : "no error given");
+	}
+
+	/* Set process scheduling parameters:
+	 * This is used so we don't steal scheduling priority from
+	 * the most important applications - like the phone
+	 * application which has a real time requirement here. This
+	 * is detailed in Nokia bug #95573 
+	 */
+	g_message ("Setting scheduling priority");
+
+	if (sched_getparam (0, &sp) == 0) {
+		if (sched_setscheduler (0, SCHED_IDLE, &sp) != 0) {
+			const gchar *str = g_strerror (errno);
+			
+			g_message ("Couldn't set scheduler priority, %s",
+				   str ? str : "no error given");
+		}
+	} else {
+		const gchar *str = g_strerror (errno);
+
+		g_message ("Couldn't get scheduler priority, %s",
+			   str ? str : "no error given");
+	}
+}
+
+static void
 initialize_locations (void)
 {
 	TrackerMainPrivate *private;
@@ -950,21 +999,8 @@
 		return EXIT_FAILURE;
 	}
 
-	/* Set IO priority */
-	tracker_ioprio_init ();
-
-	/* nice() uses attribute "warn_unused_result" and so complains
-	 * if we do not check its returned value. But it seems that
-	 * since glibc 2.2.4, nice() can return -1 on a successful
-	 * call so we have to check value of errno too. Stupid...
-	 */
-	if (nice (19) == -1 && errno) {
-		const gchar *str;
-
-		str = g_strerror (errno);
-		g_message ("Couldn't set nice value to 19, %s",
-			   str ? str : "no error given");
-	}
+	/* This makes sure we don't steal all the system's resources */
+	initialize_priority ();
 
 	/* This makes sure we have all the locations like the data
 	 * dir, user data dir, etc all configured.



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