[maemo-commits] [maemo-commits] r17437 - in projects/haf/trunk/hildon-thumbnail: . daemon

From: subversion at stage.maemo.org subversion at stage.maemo.org
Date: Mon Feb 16 19:21:55 EET 2009
Author: pvanhoof
Date: 2009-02-16 19:21:54 +0200 (Mon, 16 Feb 2009)
New Revision: 17437

Modified:
   projects/haf/trunk/hildon-thumbnail/ChangeLog
   projects/haf/trunk/hildon-thumbnail/daemon/hildon-thumbnail-daemon.c
   projects/haf/trunk/hildon-thumbnail/daemon/thumbnailer.c
Log:
2009-02-16  Philip Van Hoof  <pvanhoof at codeminded.be>

	daemon/hildon-thumbnail-daemon.c
	daemon/thumbnailer.c: Nicing the process/thread



Modified: projects/haf/trunk/hildon-thumbnail/ChangeLog
===================================================================
--- projects/haf/trunk/hildon-thumbnail/ChangeLog	2009-02-16 13:57:33 UTC (rev 17436)
+++ projects/haf/trunk/hildon-thumbnail/ChangeLog	2009-02-16 17:21:54 UTC (rev 17437)
@@ -1,3 +1,8 @@
+2009-02-16  Philip Van Hoof  <pvanhoof at codeminded.be>
+
+	daemon/hildon-thumbnail-daemon.c
+	daemon/thumbnailer.c: Nicing the process/thread
+	
 2009-02-09  Philip Van Hoof  <pvanhoof at codeminded.be>
 
 	* thumbs/thumber-common.c: Bugfix for Bug# 91639

Modified: projects/haf/trunk/hildon-thumbnail/daemon/hildon-thumbnail-daemon.c
===================================================================
--- projects/haf/trunk/hildon-thumbnail/daemon/hildon-thumbnail-daemon.c	2009-02-16 13:57:33 UTC (rev 17436)
+++ projects/haf/trunk/hildon-thumbnail/daemon/hildon-thumbnail-daemon.c	2009-02-16 17:21:54 UTC (rev 17437)
@@ -23,6 +23,9 @@
  *
  */
 
+#include <linux/sched.h>
+#include <sched.h>
+
 #include <glib.h>
 #include <dbus/dbus-glib-bindings.h>
 #include <gio/gio.h>
@@ -38,7 +41,85 @@
 static GHashTable *outregistrations;
 static gboolean do_shut_down_next_time = TRUE;
 
+
+
+#ifndef __NR_ioprio_set
+
+#if defined(__i386__)
+#define __NR_ioprio_set		289
+#define __NR_ioprio_get		290
+#elif defined(__powerpc__) || defined(__powerpc64__)
+#define __NR_ioprio_set		273
+#define __NR_ioprio_get		274
+#elif defined(__x86_64__)
+#define __NR_ioprio_set		251
+#define __NR_ioprio_get		252
+#elif defined(__ia64__)
+#define __NR_ioprio_set		1274
+#define __NR_ioprio_get		1275
+#elif defined(__alpha__)
+#define __NR_ioprio_set		442
+#define __NR_ioprio_get		443
+#elif defined(__s390x__) || defined(__s390__)
+#define __NR_ioprio_set		282
+#define __NR_ioprio_get		283
+#elif defined(__SH4__)
+#define __NR_ioprio_set		288
+#define __NR_ioprio_get		289
+#elif defined(__SH5__)
+#define __NR_ioprio_set		316
+#define __NR_ioprio_get		317
+#elif defined(__sparc__) || defined(__sparc64__)
+#define __NR_ioprio_set		196
+#define __NR_ioprio_get		218
+#elif defined(__arm__)
+#define __NR_ioprio_set		314
+#define __NR_ioprio_get		315
+#else
+#error "Unsupported architecture!"
+#endif
+
+#endif
+
+enum {
+	IOPRIO_CLASS_NONE,
+	IOPRIO_CLASS_RT,
+	IOPRIO_CLASS_BE,
+	IOPRIO_CLASS_IDLE,
+};
+
+enum {
+	IOPRIO_WHO_PROCESS = 1,
+	IOPRIO_WHO_PGRP,
+	IOPRIO_WHO_USER,
+};
+
+#define IOPRIO_CLASS_SHIFT 13
+
+
+static inline int
+ioprio_set (int which, int who, int ioprio_val)
+{
+	return syscall (__NR_ioprio_set, which, who, ioprio_val);
+}
+
 void
+initialize_priority (void)
+{
+	struct sched_param sp;
+	int ioprio, ioclass;
+
+	ioprio = 7; /* priority is ignored with idle class */
+	ioclass = IOPRIO_CLASS_IDLE << IOPRIO_CLASS_SHIFT;
+
+	ioprio_set (IOPRIO_WHO_PROCESS, 0, ioprio | ioclass);
+
+	nice (19);
+ 	if (sched_getparam (0, &sp) == 0)
+		sched_setscheduler (0, SCHED_IDLE, &sp);
+}
+
+void
 keep_alive (void) 
 {
 	do_shut_down_next_time = FALSE;

Modified: projects/haf/trunk/hildon-thumbnail/daemon/thumbnailer.c
===================================================================
--- projects/haf/trunk/hildon-thumbnail/daemon/thumbnailer.c	2009-02-16 13:57:33 UTC (rev 17436)
+++ projects/haf/trunk/hildon-thumbnail/daemon/thumbnailer.c	2009-02-16 17:21:54 UTC (rev 17437)
@@ -55,8 +55,8 @@
 G_DEFINE_TYPE (Thumbnailer, thumbnailer, G_TYPE_OBJECT)
 
 void keep_alive (void);
+void initialize_priority (void);
 
-
 typedef struct {
 	ThumbnailManager *manager;
 	GHashTable *plugins_perscheme;
@@ -362,6 +362,7 @@
  * canceling currently running requests. Also note that the thread count of the 
  * pool is set to one. We could increase this number to add some parallelism */
 
+
 static void 
 do_the_work (WorkTask *task, gpointer user_data)
 {
@@ -718,6 +719,15 @@
 	return;
 }
 
+
+static void 
+do_the_large_work (WorkTask *task, gpointer user_data)
+{
+	initialize_priority ();
+	do_the_work (task, user_data);
+}
+
+
 void
 thumbnailer_move (Thumbnailer *object, GStrv from_urls, GStrv to_urls, DBusGMethodInvocation *context)
 {
@@ -1021,7 +1031,7 @@
 
 	/* We could increase the amount of threads to add some parallelism */
 
-	priv->large_pool = g_thread_pool_new ((GFunc) do_the_work,NULL,1,TRUE,NULL);
+	priv->large_pool = g_thread_pool_new ((GFunc) do_the_large_work,NULL,1,TRUE,NULL);
 	priv->normal_pool = g_thread_pool_new ((GFunc) do_the_work,NULL,1,TRUE,NULL);
 
 	/* This sort function makes the pool a LIFO */


More information about the maemo-commits mailing list