X-Git-Url: https://git.libre-soc.org/?p=mesa.git;a=blobdiff_plain;f=src%2Futil%2Fu_queue.h;h=9666fd9c4b5df12b1c1814b529abb2da0e4df5df;hp=714d9243f00ed043d6d7eb3029751914af9e090c;hb=387176829bcef7058ff2be8f175295e9f80008e5;hpb=b238e33bc9d48b814370da4a9e49c431981053cc diff --git a/src/util/u_queue.h b/src/util/u_queue.h index 714d9243f00..9666fd9c4b5 100644 --- a/src/util/u_queue.h +++ b/src/util/u_queue.h @@ -48,6 +48,7 @@ extern "C" { #define UTIL_QUEUE_INIT_USE_MINIMUM_PRIORITY (1 << 0) #define UTIL_QUEUE_INIT_RESIZE_IF_FULL (1 << 1) +#define UTIL_QUEUE_INIT_SET_FULL_THREAD_AFFINITY (1 << 2) #if defined(__GNUC__) && defined(HAVE_LINUX_FUTEX_H) #define UTIL_QUEUE_FENCE_FUTEX @@ -192,6 +193,7 @@ typedef void (*util_queue_execute_func)(void *job, int thread_index); struct util_queue_job { void *job; + size_t job_size; struct util_queue_fence *fence; util_queue_execute_func execute; util_queue_execute_func cleanup; @@ -200,17 +202,18 @@ struct util_queue_job { /* Put this into your context. */ struct util_queue { char name[14]; /* 13 characters = the thread name without the index */ - mtx_t finish_lock; /* only for util_queue_finish */ + mtx_t finish_lock; /* for util_queue_finish and protects threads/num_threads */ mtx_t lock; cnd_t has_queued_cond; cnd_t has_space_cond; thrd_t *threads; unsigned flags; int num_queued; - unsigned num_threads; - int kill_threads; + unsigned max_threads; + unsigned num_threads; /* decreasing this number will terminate threads */ int max_jobs; int write_idx, read_idx; /* ring buffer pointers */ + size_t total_jobs_size; /* memory use of all jobs in the queue */ struct util_queue_job *jobs; /* for cleanup at exit(), protected by exit_mutex */ @@ -229,12 +232,20 @@ void util_queue_add_job(struct util_queue *queue, void *job, struct util_queue_fence *fence, util_queue_execute_func execute, - util_queue_execute_func cleanup); + util_queue_execute_func cleanup, + const size_t job_size); void util_queue_drop_job(struct util_queue *queue, struct util_queue_fence *fence); void util_queue_finish(struct util_queue *queue); +/* Adjust the number of active threads. The new number of threads can't be + * greater than the initial number of threads at the creation of the queue, + * and it can't be less than 1. + */ +void +util_queue_adjust_num_threads(struct util_queue *queue, unsigned num_threads); + int64_t util_queue_get_thread_time_nano(struct util_queue *queue, unsigned thread_index);