diff options
author | Jannis Pohlmann <jannis@xfce.org> | 2009-10-08 13:49:01 +0200 |
---|---|---|
committer | Jannis Pohlmann <jannis@xfce.org> | 2009-10-08 13:49:01 +0200 |
commit | 48e0e7aea3baa73f37a29bf4c866a0f9aedc2560 (patch) | |
tree | 7ef266b06bb72335a50c0b313fd59067d1259d42 /tumblerd | |
parent | f583df4a3bf353ad577723c5fce538b872fd9e47 (diff) | |
download | tumbler-48e0e7aea3baa73f37a29bf4c866a0f9aedc2560.tar.gz |
Set background system priority for the group scheduler.
Original commit from Philip Van Hoof. I modified it to only include the
headers we absolutely need.
Conflicts:
tumblerd/tumbler-group-scheduler.c
Diffstat (limited to 'tumblerd')
-rw-r--r-- | tumblerd/tumbler-group-scheduler.c | 16 | ||||
-rw-r--r-- | tumblerd/tumbler-scheduler.c | 67 | ||||
-rw-r--r-- | tumblerd/tumbler-scheduler.h | 2 |
3 files changed, 84 insertions, 1 deletions
diff --git a/tumblerd/tumbler-group-scheduler.c b/tumblerd/tumbler-group-scheduler.c index 8429cfa..f133d90 100644 --- a/tumblerd/tumbler-group-scheduler.c +++ b/tumblerd/tumbler-group-scheduler.c @@ -94,6 +94,7 @@ struct _TumblerGroupScheduler GMutex *mutex; GList *requests; guint group; + gboolean prioritized; gchar *name; }; @@ -150,6 +151,13 @@ tumbler_group_scheduler_init (TumblerGroupScheduler *scheduler) scheduler->mutex = g_mutex_new (); scheduler->requests = NULL; + /* Note that unless we convert this boolean to a TLS (thread-local), that + * we can only do this 'prioritized' flag with a thread-pool that is set to + * exclusive: because then the one thread keeps running until the pool is + * freed. */ + + scheduler->prioritized = FALSE; + /* allocate a pool with one thread for all requests */ scheduler->pool = g_thread_pool_new (tumbler_group_scheduler_thread, scheduler, 1, TRUE, NULL); @@ -360,12 +368,18 @@ tumbler_group_scheduler_thread (gpointer data, GList *thumbnails; GList *lp; guint n; - guint i; gint error_code; g_return_if_fail (TUMBLER_IS_GROUP_SCHEDULER (scheduler)); g_return_if_fail (request != NULL); + /* Set I/O priority for the exclusive ThreadPool's thread */ + if (!scheduler->prioritized) + { + tumbler_scheduler_thread_use_lower_priority (); + scheduler->prioritized = TRUE; + } + /* notify others that we're starting to process this request */ g_signal_emit_by_name (request->scheduler, "started", request->handle); diff --git a/tumblerd/tumbler-scheduler.c b/tumblerd/tumbler-scheduler.c index 897cbaf..2897e3d 100644 --- a/tumblerd/tumbler-scheduler.c +++ b/tumblerd/tumbler-scheduler.c @@ -22,10 +22,46 @@ #include <config.h> #endif +#ifdef HAVE_SCHED_H +#include <sched.h> +#endif +#ifdef HAVE_LINUX_SCHED_H +#include <linux/sched.h> +#endif +#ifdef HAVE_SYSCALL_H +#include <syscall.h> +#endif + #include <tumbler/tumbler.h> #include <tumblerd/tumbler-scheduler.h> + +#define IOPRIO_CLASS_SHIFT 13 + +#ifndef SCHED_IDLE +#define SCHED_IDLE 5 +#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, +}; + /* signal identifiers */ enum { @@ -252,3 +288,34 @@ tumbler_scheduler_request_compare (gconstpointer a, return request_b->handle - request_a->handle; } + +static int +ioprio_set (int which, int who, int ioprio_val) +{ +#if defined(__NR_ioprio_set) && defined(HAVE_SYS_SYSCALL_H) + return syscall (__NR_ioprio_set, which, who, ioprio_val); +#else + return 0; +#endif +} + + +void +tumbler_scheduler_thread_use_lower_priority (void) +{ +#ifdef HAVE_SCHED_H + struct sched_param sp; +#endif + int ioprio; + int ioclass; + + ioprio = 7; /* priority is ignored with idle class */ + ioclass = IOPRIO_CLASS_IDLE << IOPRIO_CLASS_SHIFT; + + ioprio_set (IOPRIO_WHO_PROCESS, 0, ioprio | ioclass); + +#ifdef HAVE_SCHED_H + if (sched_getparam (0, &sp) == 0) + sched_setscheduler (0, SCHED_IDLE, &sp); +#endif +} diff --git a/tumblerd/tumbler-scheduler.h b/tumblerd/tumbler-scheduler.h index 733e5aa..db5445e 100644 --- a/tumblerd/tumbler-scheduler.h +++ b/tumblerd/tumbler-scheduler.h @@ -81,6 +81,8 @@ gint tumbler_scheduler_request_compare (gconstpointer gconstpointer b, gpointer user_data); +void tumbler_scheduler_thread_use_lower_priority (void); + struct _TumblerSchedulerRequest { TumblerThumbnailer **thumbnailers; |