tracker r3186 - in trunk: . src/trackerd
- From: mr svn gnome org
- To: svn-commits-list gnome org
- Subject: tracker r3186 - in trunk: . src/trackerd
- Date: Tue, 7 Apr 2009 13:36:35 +0000 (UTC)
Author: mr
Date: Tue Apr 7 13:36:35 2009
New Revision: 3186
URL: http://svn.gnome.org/viewvc/tracker?rev=3186&view=rev
Log:
* src/trackerd/tracker-main.c:
* src/trackerd/tracker-status.c: Only set nice() to 19 when
crawling the file system, for all other times, we use the value as
set when the process is started (which is controlled by outside
influence of course).
Modified:
trunk/ChangeLog
trunk/src/trackerd/tracker-main.c
trunk/src/trackerd/tracker-status.c
Modified: trunk/src/trackerd/tracker-main.c
==============================================================================
--- trunk/src/trackerd/tracker-main.c (original)
+++ trunk/src/trackerd/tracker-main.c Tue Apr 7 13:36:35 2009
@@ -510,21 +510,10 @@
/* 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...
+ /* NOTE: We only set the nice() value when crawling, for all
+ * other times we don't have a nice() value. Check the
+ * tracker-status code to see where this is done.
*/
- 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");
- }
}
static void
Modified: trunk/src/trackerd/tracker-status.c
==============================================================================
--- trunk/src/trackerd/tracker-status.c (original)
+++ trunk/src/trackerd/tracker-status.c Tue Apr 7 13:36:35 2009
@@ -22,6 +22,10 @@
#include "config.h"
#include <sys/statvfs.h>
+#include <sys/time.h>
+#include <sys/resource.h>
+#include <errno.h>
+#include <unistd.h>
#include "tracker-status.h"
#include "tracker-dbus.h"
@@ -34,6 +38,8 @@
#define THROTTLE_DEFAULT 0
#define THROTTLE_DEFAULT_ON_BATTERY 5
+#define PROCESS_PRIORITY_FOR_BUSY 19
+
typedef struct {
TrackerStatus status;
TrackerStatus status_before_paused;
@@ -41,9 +47,12 @@
guint disk_space_check_id;
+ gint cpu_priority;
+
TrackerConfig *config;
TrackerHal *hal;
+
DBusGProxy *indexer_proxy;
gboolean is_readonly;
@@ -501,6 +510,30 @@
private->is_paused_for_unknown = FALSE;
private->in_merge = FALSE;
+ /* Get process priority on start up:
+ * We use nice() when crawling so we don't steal all
+ * the processor time, for all other states, we return the
+ * nice() value to what it was.
+ *
+ * NOTE: We set errno first because -1 is a valid priority and
+ * we need to check it isn't an error.
+ */
+ errno = 0;
+ private->cpu_priority = getpriority (PRIO_PROCESS, 0);
+
+ if ((private->cpu_priority < 0) && errno) {
+ const gchar *str = g_strerror (errno);
+
+ g_message ("Couldn't get nice value, %s",
+ str ? str : "no error given");
+
+ /* Default to 0 */
+ private->cpu_priority = 0;
+ }
+
+ g_message ("Current process priority is set to %d, this will be used for all non-crawling states",
+ private->cpu_priority);
+
g_static_private_set (&private_key,
private,
private_free);
@@ -638,9 +671,39 @@
* to return to is also PAUSED.
*/
if (private->status_before_paused != new_status) {
+ /* ALWAYS only set this after checking against the
+ * previous value
+ */
private->status_before_paused = private->status;
}
+ if (private->status != new_status) {
+ /* Note, we can't use -1 here, so we use a value
+ * outside the nice values from -20->19
+ */
+ gint new_priority = 100;
+
+ if (new_status == TRACKER_STATUS_PENDING) {
+ new_priority = PROCESS_PRIORITY_FOR_BUSY;
+ } else if (private->status == TRACKER_STATUS_PENDING) {
+ new_priority = private->cpu_priority;
+ }
+
+ if (new_priority != 100) {
+ g_message ("Setting process priority to %d",
+ new_priority);
+
+ if (nice (new_priority) == -1) {
+ const gchar *str = g_strerror (errno);
+
+ g_message ("Couldn't set nice value to %d, %s",
+ new_priority,
+ str ? str : "no error given");
+ }
+ }
+
+ }
+
private->status = new_status;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]