Commit Graph

26 Commits

Author SHA1 Message Date
Marek Olšák b4afe25ebf util/queue: use simple_mtx_t for finish_lock
Acked-By: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
Reviewed-by: Kristian H. Kristensen <hoegsberg@google.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13152>
2021-10-05 23:46:14 +00:00
Pierre-Eric Pelloux-Prayer 3713dc6b2a util/u_queue: add UTIL_QUEUE_INIT_SCALE_THREADS flag
This flag allow to create a single thread initially, but set
max_thread to the request thread count.

If the queue is full and num_threads is lower than max_threads,
we spawn a new thread to help process the queue faster.

This avoid creating N threads at queue creation time.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11296>
2021-06-17 09:11:59 +02:00
Mike Blumenkrantz a3a6611e96 util/queue: add a global data pointer for the queue object
this better enables object-specific (e.g., context) queues where the owner
of the queue will always be needed and various pointers will be passed in
for tasks

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11312>
2021-06-16 15:10:09 -04:00
Witold Baryluk 65ef4a2e02 util: Use explicit relaxed reads for u_queue
These are no-op, but make clang thread sanitizer happy.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8230>
2021-01-28 18:07:09 +00:00
Jan Beich 46c368907f util: enable futex usage on BSDs after 7dc2f47882
Reviewed-by: Eric Engestrom <eric@engestrom.ch>
Cc: mesa-stable
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5460>
2020-06-16 21:44:35 +00:00
Timothy Arceri 896885025f util/u_queue: track job size and limit the size of queue growth
When both UTIL_QUEUE_INIT_RESIZE_IF_FULL and
UTIL_QUEUE_INIT_USE_MINIMUM_PRIORITY are set, we can get into a
situation where the queue never executes and grows to a huge size
due to all other threads being busy.

This is the case with the shader cache when attempting to compile a
huge number of shaders up front. If all threads are busy compiling
shaders the cache queues memory use can climb into the many GBs
very fast.

The use of these two flags with the shader cache is intended to
allow shaders compiled at runtime to be compiled as fast as possible.
To avoid huge memory use but still allow the queue to perform
optimally in the run time compilation case, we now add the ability
to track memory consumed by the jobs in the queue and limit it to
a hardcoded 256MB which should be more than enough.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
2019-09-19 15:03:27 +10:00
Marek Olšák 050fae3983 util/queue: add util_queue_adjust_num_threads
for ARB_parallel_shader_compile

Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2019-04-01 12:37:52 -04:00
Marek Olšák bb111559f2 util/queue: add ability to kill a subset of threads
for ARB_parallel_shader_compile
2019-04-01 12:37:52 -04:00
Marek Olšák d877451b48 util/u_queue: add UTIL_QUEUE_INIT_SET_FULL_THREAD_AFFINITY
Initial version discussed with Rob Clark under a different patch name.
This approach leaves his driver unaffected.
2018-10-06 22:05:58 -04:00
Marek Olšák b238e33bc9 kutil/queue: add a process name into a thread name
v2: simplifications

Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com> (v1)
Reviewed-by: Eric Engestrom <eric.engestrom@intel.com> (v1)
2018-07-04 21:54:39 -04:00
Marek Olšák 7083ac7290 util/u_queue: fix a deadlock in util_queue_finish
Cc: 18.0 18.1 <mesa-stable@lists.freedesktop.org>
Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
2018-04-27 13:28:17 -04:00
Nicolai Hähnle 81aabb20f3 util/u_queue: really use futex-based fences
The relevant define changed in the final revision of the simple mutex
patch.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
2017-11-20 18:15:53 +01:00
Nicolai Hähnle f53570a7a6 util/u_queue: handle OS_TIMEOUT_INFINITE in util_queue_fence_wait_timeout
Fixes e.g. piglit/bin/bufferstorage-persistent read -auto

Fixes: e6dbc804a8 ("winsys/amdgpu: handle cs_add_fence_dependency for deferred/unsubmitted fences")
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
2017-11-10 16:37:47 +01:00
Nicolai Hähnle e3a8013de8 util/u_queue: add util_queue_fence_wait_timeout
v2:
- style fixes
- fix missing timeout handling in futex path

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
2017-11-09 13:58:10 +01:00
Nicolai Hähnle 185061aef4 u_queue: add util_queue_finish for waiting for previously added jobs
Schedule one job for every thread, and wait on a barrier inside the job
execution function.

v2: avoid alloca (fixes Windows build error)

Reviewed-by: Marek Olšák <marek.olsak@amd.com> (v1)
2017-11-09 11:53:19 +01:00
Nicolai Hähnle d1ff082637 u_queue: add a futex-based implementation of fences
Fences are now 4 bytes instead of 96 bytes (on my 64-bit system).

Signaling a fence is a single atomic operation in the fast case plus a
syscall in the slow case.

Testing if a fence is signaled is the same as before (a simple comparison),
but waiting on a fence is now no more expensive than just testing it in
the fast (already signaled) case.

v2:
- style fixes
- use p_atomic_xxx macros with the right barriers

Acked-by: Marek Olšák <marek.olsak@amd.com>
2017-11-09 11:37:39 +01:00
Nicolai Hähnle 574c59d4f9 u_queue: add util_queue_fence_reset
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
2017-11-09 11:37:39 +01:00
Nicolai Hähnle 1b9d5ece55 u_queue: export util_queue_fence_signal
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
2017-11-09 11:37:38 +01:00
Nicolai Hähnle b20f955bc1 u_queue: group fence functions together
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
2017-11-09 11:37:38 +01:00
Marek Olšák 59ad769770 util/u_queue: add an option to resize the queue when it's full
Consider the following situation:
  mtx_lock(mutex);
  do_something();
  util_queue_add_job(...);
  mtx_unlock(mutex);

If the queue is full, util_queue_add_job will wait for a free slot.
If the job which is currently being executed tries to lock the mutex,
it will be stuck forever, because util_queue_add_job is stuck.

The deadlock can be trivially resolved by increasing the queue size
(reallocating the queue) in util_queue_add_job if the queue is full.
Then util_queue_add_job becomes wait-free.

radeonsi will use it.

Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
2017-07-17 10:57:20 -04:00
Marek Olšák 5fa69be3c8 mesa/glthread: add glthread "perf" counters and pass them to gallium HUD
for HUD integration in following commits. This valuable profiling data
will allow us to see on the HUD how well glthread is able to utilize
parallelism. This is better than benchmarking, because you can see
exactly what's happening and you don't have to be CPU-bound.

u_threaded_context has the same counters.

Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
2017-06-26 02:17:03 +02:00
Marek Olšák e93a141f64 util/u_queue: fix a use-before-initialization race for queue->threads
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
2017-06-07 23:19:30 +02:00
Marek Olšák 89b6c93ae3 util/u_queue: add an option to set the minimum thread priority
Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
2017-06-07 18:43:42 +02:00
Marek Olšák 33e507ec23 util/u_queue: add a way to remove a job when we just want to destroy it
Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
2017-06-07 18:43:42 +02:00
Timothy Arceri 13d69a8519 util/u_queue: make u_queue accessible to cpp
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
2017-03-13 09:50:26 +11:00
Timothy Arceri b822d9dd67 gallium/util: move u_queue.{c,h} to src/util
This will allow us to use it outside of gallium for things like
compressing shader cache entries.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
2017-03-12 17:49:03 +11:00
Renamed from src/gallium/auxiliary/util/u_queue.h (Browse further)