[tracker/SCHED_IDLE: 1/2] libtracker-common: Added functionality for SCHED_IDLE scheduler priority
- From: Martyn James Russell <mr src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/SCHED_IDLE: 1/2] libtracker-common: Added functionality for SCHED_IDLE scheduler priority
- Date: Fri, 23 Sep 2011 11:59:47 +0000 (UTC)
commit 98a7c47a61f79c85893e356096db44a0207eded0
Author: Martyn Russell <martyn lanedo com>
Date: Fri Sep 23 10:20:51 2011 +0100
libtracker-common: Added functionality for SCHED_IDLE scheduler priority
Also added calls the tracker-miner-fs and tracker-extract
src/libtracker-common/Makefile.am | 2 +
src/libtracker-common/tracker-common.h | 1 +
src/libtracker-common/tracker-sched.c | 77 ++++++++++++++++++++++++++++++++
src/libtracker-common/tracker-sched.h | 33 ++++++++++++++
src/miners/fs/tracker-main.c | 16 +++---
src/tracker-extract/tracker-main.c | 14 +++---
6 files changed, 128 insertions(+), 15 deletions(-)
---
diff --git a/src/libtracker-common/Makefile.am b/src/libtracker-common/Makefile.am
index 5bcd345..406ca38 100644
--- a/src/libtracker-common/Makefile.am
+++ b/src/libtracker-common/Makefile.am
@@ -25,6 +25,7 @@ libtracker_common_la_SOURCES = \
tracker-ioprio.c \
tracker-keyfile-object.c \
tracker-log.c \
+ tracker-sched.c \
tracker-type-utils.c \
tracker-utils.c \
tracker-crc32.c \
@@ -43,6 +44,7 @@ noinst_HEADERS = \
tracker-file-utils.h \
tracker-keyfile-object.h \
tracker-ontologies.h \
+ tracker-sched.h \
tracker-type-utils.h \
tracker-utils.h \
tracker-crc32.h \
diff --git a/src/libtracker-common/tracker-common.h b/src/libtracker-common/tracker-common.h
index 1263efc..e5616b0 100644
--- a/src/libtracker-common/tracker-common.h
+++ b/src/libtracker-common/tracker-common.h
@@ -38,6 +38,7 @@
#include "tracker-log.h"
#include "tracker-ontologies.h"
#include "tracker-os-dependant.h"
+#include "tracker-sched.h"
#include "tracker-type-utils.h"
#include "tracker-utils.h"
#include "tracker-locale.h"
diff --git a/src/libtracker-common/tracker-sched.c b/src/libtracker-common/tracker-sched.c
new file mode 100644
index 0000000..acec7a3
--- /dev/null
+++ b/src/libtracker-common/tracker-sched.c
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2011, Nokia <ivan frade nokia com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+
+#ifdef __linux__
+
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+
+#include <errno.h>
+#include <sched.h>
+
+#include <glib.h>
+
+#include "tracker-sched.h"
+
+gboolean
+tracker_sched_idle (void)
+{
+ struct sched_param sp;
+
+ /* 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 scheduler policy to SCHED_IDLE");
+
+ if (sched_getparam (0, &sp) == 0) {
+ if (sched_setscheduler (0, SCHED_IDLE, &sp) != 0) {
+ const gchar *str = g_strerror (errno);
+
+ g_warning ("Could not set scheduler policy, %s",
+ str ? str : "no error given");
+
+ return FALSE;
+ }
+ } else {
+ const gchar *str = g_strerror (errno);
+
+ g_warning ("Could not get scheduler policy, %s",
+ str ? str : "no error given");
+
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+#else /* __linux__ */
+
+gboolean
+tracker_sched_idle (gboolean enable)
+{
+ return TRUE;
+}
+
+#endif /* __linux__ */
diff --git a/src/libtracker-common/tracker-sched.h b/src/libtracker-common/tracker-sched.h
new file mode 100644
index 0000000..a9d8fe7
--- /dev/null
+++ b/src/libtracker-common/tracker-sched.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2011, Nokia <ivan frade nokia com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __LIBTRACKER_COMMON_SCHED_H__
+#define __LIBTRACKER_COMMON_SCHED_H__
+
+G_BEGIN_DECLS
+
+#if !defined (__LIBTRACKER_COMMON_INSIDE__) && !defined (TRACKER_COMPILATION)
+#error "only <libtracker-common/tracker-common.h> must be included directly."
+#endif
+
+gboolean tracker_sched_idle (void);
+
+G_END_DECLS
+
+#endif /* __LIBTRACKER_COMMON_SCHED_H__ */
diff --git a/src/miners/fs/tracker-main.c b/src/miners/fs/tracker-main.c
index 251bf8a..775584e 100644
--- a/src/miners/fs/tracker-main.c
+++ b/src/miners/fs/tracker-main.c
@@ -26,10 +26,6 @@
#include <errno.h>
#include <sys/types.h>
#include <unistd.h>
-#if defined(__linux__)
-#include <linux/sched.h>
-#endif
-#include <sched.h>
#include <glib.h>
#include <glib-object.h>
@@ -39,6 +35,7 @@
#include <libtracker-common/tracker-log.h>
#include <libtracker-common/tracker-ontologies.h>
#include <libtracker-common/tracker-file-utils.h>
+#include <libtracker-common/tracker-sched.h>
#include <libtracker-miner/tracker-miner.h>
@@ -172,8 +169,11 @@ initialize_signal_handler (void)
}
static void
-initialize_priority (void)
+initialize_priority_and_scheduling (void)
{
+ /* Set CPU priority */
+ tracker_sched_idle ();
+
/* Set disk IO priority and scheduling */
tracker_ioprio_init ();
@@ -714,9 +714,6 @@ main (gint argc, gchar *argv[])
initialize_signal_handler ();
- /* This makes sure we don't steal all the system's resources */
- initialize_priority ();
-
/* Initialize logging */
config = tracker_config_new ();
@@ -735,6 +732,9 @@ main (gint argc, gchar *argv[])
sanity_check_option_values (config);
+ /* This makes sure we don't steal all the system's resources */
+ initialize_priority_and_scheduling ();
+
main_loop = g_main_loop_new (NULL, FALSE);
g_message ("Checking if we're running as a daemon:");
diff --git a/src/tracker-extract/tracker-main.c b/src/tracker-extract/tracker-main.c
index e115975..dc94675 100644
--- a/src/tracker-extract/tracker-main.c
+++ b/src/tracker-extract/tracker-main.c
@@ -28,10 +28,6 @@
#include <errno.h>
#include <sys/types.h>
#include <unistd.h>
-#if defined(__linux__)
-#include <linux/sched.h>
-#endif
-#include <sched.h>
#include <glib.h>
#include <glib-object.h>
@@ -47,6 +43,7 @@
#include <libtracker-common/tracker-os-dependant.h>
#include <libtracker-common/tracker-ioprio.h>
#include <libtracker-common/tracker-locale.h>
+#include <libtracker-common/tracker-sched.h>
#include "tracker-albumart.h"
#include "tracker-config.h"
@@ -118,8 +115,11 @@ static GOptionEntry entries[] = {
};
static void
-initialize_priority (void)
+initialize_priority_and_scheduling (void)
{
+ /* Set CPU priority */
+ tracker_sched_idle ();
+
/* Set disk IO priority and scheduling */
tracker_ioprio_init ();
@@ -273,7 +273,7 @@ run_standalone (void)
tracker_albumart_init ();
/* This makes sure we don't steal all the system's resources */
- initialize_priority ();
+ initialize_priority_and_scheduling ();
file = g_file_new_for_commandline_arg (filename);
uri = g_file_get_uri (file);
@@ -398,7 +398,7 @@ main (int argc, char *argv[])
sanity_check_option_values (config);
/* This makes sure we don't steal all the system's resources */
- initialize_priority ();
+ initialize_priority_and_scheduling ();
tracker_memory_setrlimits ();
if (disable_shutdown) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]