summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorMarek Olšák <marek.olsak@amd.com>2017-05-31 22:04:29 +0200
committerMarek Olšák <marek.olsak@amd.com>2017-06-07 18:43:42 +0200
commit89b6c93ae3135a44b1aa2ce9285502a3898920bc (patch)
treefc4fd8d751b1dd244a40fbca9dc67400ce92999c /src/util
parent6f2947fa79f9480934b17cc913a8bcdfbe9ffe45 (diff)
util/u_queue: add an option to set the minimum thread priority
Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
Diffstat (limited to 'src/util')
-rw-r--r--src/util/disk_cache.c2
-rw-r--r--src/util/u_queue.c19
-rw-r--r--src/util/u_queue.h6
3 files changed, 24 insertions, 3 deletions
diff --git a/src/util/disk_cache.c b/src/util/disk_cache.c
index 138d7ec174f..b2229874e01 100644
--- a/src/util/disk_cache.c
+++ b/src/util/disk_cache.c
@@ -342,7 +342,7 @@ disk_cache_create(const char *gpu_name, const char *timestamp,
* really care about getting things to disk quickly just that it's not
* blocking other tasks.
*/
- util_queue_init(&cache->cache_queue, "disk_cache", 32, 1);
+ util_queue_init(&cache->cache_queue, "disk_cache", 32, 1, 0);
/* Create driver id keys */
size_t ts_size = strlen(timestamp) + 1;
diff --git a/src/util/u_queue.c b/src/util/u_queue.c
index 01c3a96d5f3..94fe2202a2c 100644
--- a/src/util/u_queue.c
+++ b/src/util/u_queue.c
@@ -147,6 +147,21 @@ util_queue_thread_func(void *input)
u_thread_setname(name);
}
+ if (queue->flags & UTIL_QUEUE_INIT_USE_MINIMUM_PRIORITY) {
+#if defined(__linux__)
+ struct sched_param sched_param = {0};
+
+ /* The nice() function can only set a maximum of 19.
+ * SCHED_IDLE is the same as nice = 20.
+ *
+ * Note that Linux only allows decreasing the priority. The original
+ * priority can't be restored.
+ */
+ pthread_setschedparam(queue->threads[thread_index], SCHED_IDLE,
+ &sched_param);
+#endif
+ }
+
while (1) {
struct util_queue_job job;
@@ -197,13 +212,15 @@ bool
util_queue_init(struct util_queue *queue,
const char *name,
unsigned max_jobs,
- unsigned num_threads)
+ unsigned num_threads,
+ unsigned flags)
{
unsigned i;
memset(queue, 0, sizeof(*queue));
queue->name = name;
queue->num_threads = num_threads;
+ queue->flags = flags;
queue->max_jobs = max_jobs;
queue->jobs = (struct util_queue_job*)
diff --git a/src/util/u_queue.h b/src/util/u_queue.h
index 9876865c651..916802c96d1 100644
--- a/src/util/u_queue.h
+++ b/src/util/u_queue.h
@@ -42,6 +42,8 @@
extern "C" {
#endif
+#define UTIL_QUEUE_INIT_USE_MINIMUM_PRIORITY (1 << 0)
+
/* Job completion fence.
* Put this into your job structure.
*/
@@ -69,6 +71,7 @@ struct util_queue {
thrd_t *threads;
int num_queued;
unsigned num_threads;
+ unsigned flags;
int kill_threads;
int max_jobs;
int write_idx, read_idx; /* ring buffer pointers */
@@ -81,7 +84,8 @@ struct util_queue {
bool util_queue_init(struct util_queue *queue,
const char *name,
unsigned max_jobs,
- unsigned num_threads);
+ unsigned num_threads,
+ unsigned flags);
void util_queue_destroy(struct util_queue *queue);
void util_queue_fence_init(struct util_queue_fence *fence);
void util_queue_fence_destroy(struct util_queue_fence *fence);