u_trace: reserve chunk space before emitting copies

Some implementations can emit tracepoints when copying u_trace
buffers. It's important to reserve the slots we want to copy into
before emitting the copies so that both processes don't clash with one
another.

Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Cc: mesa-stable
Reviewed-by: Danylo Piliaiev <dpiliaiev@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38199>
This commit is contained in:
Lionel Landwerlin 2025-11-01 23:39:20 +02:00 committed by Marge Bot
parent 2798ef7bfd
commit df5f92d114

View file

@ -887,11 +887,17 @@ u_trace_clone_append(struct u_trace_iterator begin_it,
if (from_chunk == end_it.chunk)
to_copy = MIN2(to_copy, end_it.event_idx - from_idx);
/* Reserve space in the chunk before emitting the copy as it could also
* add its own tracepoints.
*/
unsigned to_chunk_idx = to_chunk->num_traces;
to_chunk->num_traces += to_copy;
copy_buffer(begin_it.ut->utctx, cmdstream,
from_chunk->timestamps,
begin_it.ut->utctx->timestamp_size_bytes * from_idx,
to_chunk->timestamps,
begin_it.ut->utctx->timestamp_size_bytes * to_chunk->num_traces,
begin_it.ut->utctx->timestamp_size_bytes * to_chunk_idx,
begin_it.ut->utctx->timestamp_size_bytes * to_copy);
if (from_chunk->has_indirect) {
@ -899,11 +905,11 @@ u_trace_clone_append(struct u_trace_iterator begin_it,
from_chunk->indirects,
begin_it.ut->utctx->max_indirect_size_bytes * from_idx,
to_chunk->indirects,
begin_it.ut->utctx->max_indirect_size_bytes * to_chunk->num_traces,
begin_it.ut->utctx->max_indirect_size_bytes * to_chunk_idx,
begin_it.ut->utctx->max_indirect_size_bytes * to_copy);
}
memcpy(&to_chunk->traces[to_chunk->num_traces],
memcpy(&to_chunk->traces[to_chunk_idx],
&from_chunk->traces[from_idx],
to_copy * sizeof(struct u_trace_event));
@ -919,7 +925,6 @@ u_trace_clone_append(struct u_trace_iterator begin_it,
}
into->num_traces += to_copy;
to_chunk->num_traces += to_copy;
from_idx += to_copy;
assert(from_idx <= from_chunk->num_traces);