[tracker/cpuaffinity] tracker-store: Avoid CPU hopping of main threads
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/cpuaffinity] tracker-store: Avoid CPU hopping of main threads
- Date: Thu, 1 Jul 2010 09:24:10 +0000 (UTC)
commit 80c2fe73175a144d4bc3d9fae748669f935f9a00
Author: Jürg Billeter <j bitron ch>
Date: Thu Jun 24 14:34:45 2010 +0200
tracker-store: Avoid CPU hopping of main threads
This improves update performance on SMP systems.
src/tracker-store/tracker-store.c | 29 +++++++++++++++++++++++++++++
1 files changed, 29 insertions(+), 0 deletions(-)
---
diff --git a/src/tracker-store/tracker-store.c b/src/tracker-store/tracker-store.c
index 729964a..6d9e1d3 100644
--- a/src/tracker-store/tracker-store.c
+++ b/src/tracker-store/tracker-store.c
@@ -21,6 +21,10 @@
#include "config.h"
+#define _GNU_SOURCE
+#include <sched.h>
+#include <pthread.h>
+
#include <unistd.h>
#include <sys/types.h>
@@ -104,6 +108,9 @@ typedef struct {
static GStaticPrivate private_key = G_STATIC_PRIVATE_INIT;
+/* cpu used for mainloop thread and main update/query thread */
+static int main_cpu;
+
static void start_handler (TrackerStorePrivate *private);
static void
@@ -446,6 +453,17 @@ pool_dispatch_cb (gpointer data,
TrackerStoreTask *task;
GThread *running_thread = g_thread_self ();
+ /* special task, only ever sent to main pool */
+ if (GPOINTER_TO_INT (data) == 1) {
+ cpu_set_t cpuset;
+ CPU_ZERO (&cpuset);
+ CPU_SET (main_cpu, &cpuset);
+
+ /* avoid cpu hopping which can lead to significantly worse performance */
+ pthread_setaffinity_np (pthread_self (), sizeof (cpu_set_t), &cpuset);
+ return;
+ }
+
private = user_data;
task = data;
@@ -604,6 +622,7 @@ tracker_store_init (void)
TrackerStorePrivate *private;
gint i;
const char *tmp;
+ cpu_set_t cpuset;
private = g_new0 (TrackerStorePrivate, 1);
@@ -630,6 +649,16 @@ tracker_store_init (void)
g_thread_pool_set_max_idle_time (15 * 1000);
g_thread_pool_set_max_unused_threads (2);
+ main_cpu = sched_getcpu ();
+ CPU_ZERO (&cpuset);
+ CPU_SET (main_cpu, &cpuset);
+
+ /* avoid cpu hopping which can lead to significantly worse performance */
+ pthread_setaffinity_np (pthread_self (), sizeof (cpu_set_t), &cpuset);
+ /* lock main update/query thread to same cpu to improve overall performance
+ main loop thread is essentially idle during query execution */
+ g_thread_pool_push (private->main_pool, GINT_TO_POINTER (1), NULL);
+
g_static_private_set (&private_key,
private,
private_free);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]