/* * Copyright 2022 Advanced Micro Devices, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. *
*/ #include <linux/slab.h> #include <drm/drm_print.h>
if (ring->hw_prio <= AMDGPU_RING_PRIO_DEFAULT)
amdgpu_mux_resubmit_chunks(mux);
e = amdgpu_ring_mux_sw_entry(mux, ring); if (!e) {
DRM_ERROR("cannot find entry for sw ring\n");
spin_unlock(&mux->lock); return;
}
/* We could skip this set wptr as preemption in process. */ if (ring->hw_prio <= AMDGPU_RING_PRIO_DEFAULT && mux->pending_trailing_fence_signaled) {
spin_unlock(&mux->lock); return;
}
e->sw_cptr = e->sw_wptr; /* Update cptr if the package already copied in resubmit functions */ if (ring->hw_prio <= AMDGPU_RING_PRIO_DEFAULT && e->sw_cptr < mux->wptr_resubmit)
e->sw_cptr = mux->wptr_resubmit;
e->sw_wptr = wptr;
e->start_ptr_in_hw_ring = mux->real_ring->wptr;
e = amdgpu_ring_mux_sw_entry(mux, ring); if (!e) {
DRM_ERROR("cannot find entry for sw ring\n"); return 0;
}
return e->sw_wptr;
}
/** * amdgpu_ring_mux_get_rptr - get the readptr of the software ring * @mux: the multiplexer the software rings attach to * @ring: the software ring of which we calculate the readptr * * The return value of the readptr is not precise while the other rings could * write data onto the real ring buffer.After overwriting on the real ring, we * can not decide if our packages have been excuted or not read yet. However, * this function is only called by the tools such as umr to collect the latest * packages for the hang analysis. We assume the hang happens near our latest * submit. Thus we could use the following logic to give the clue: * If the readptr is between start and end, then we return the copy pointer * plus the distance from start to readptr. If the readptr is before start, we * return the copy pointer. Lastly, if the readptr is past end, we return the * write pointer.
*/
u64 amdgpu_ring_mux_get_rptr(struct amdgpu_ring_mux *mux, struct amdgpu_ring *ring)
{ struct amdgpu_mux_entry *e;
u64 readp, offset, start, end;
e = amdgpu_ring_mux_sw_entry(mux, ring); if (!e) {
DRM_ERROR("no sw entry found!\n"); return 0;
}
readp = amdgpu_ring_get_rptr(mux->real_ring);
start = e->start_ptr_in_hw_ring & mux->real_ring->buf_mask;
end = e->end_ptr_in_hw_ring & mux->real_ring->buf_mask; if (start > end) { if (readp <= end)
readp += mux->real_ring->ring_size >> 2;
end += mux->real_ring->ring_size >> 2;
}
/*Scan on low prio rings to have unsignaled fence and high ring has no fence.*/ staticint amdgpu_mcbp_scan(struct amdgpu_ring_mux *mux)
{ struct amdgpu_ring *ring; int i, need_preempt;
need_preempt = 0; for (i = 0; i < mux->num_ring_entries; i++) {
ring = mux->ring_entry[i].ring; if (ring->hw_prio > AMDGPU_RING_PRIO_DEFAULT &&
amdgpu_fence_count_emitted(ring) > 0) return 0; if (ring->hw_prio <= AMDGPU_RING_PRIO_DEFAULT &&
amdgpu_fence_last_unsignaled_time_us(ring) >
AMDGPU_MAX_LAST_UNSIGNALED_THRESHOLD_US)
need_preempt = 1;
} return need_preempt && !mux->s_resubmit;
}
/* Trigger Mid-Command Buffer Preemption (MCBP) and find if we need to resubmit. */ staticint amdgpu_mcbp_trigger_preempt(struct amdgpu_ring_mux *mux)
{ int r;
chunk->start = ring->wptr; /* the initialized value used to check if they are set by the ib submission*/
chunk->cntl_offset = ring->buf_mask + 1;
chunk->de_offset = ring->buf_mask + 1;
chunk->ce_offset = ring->buf_mask + 1;
list_add_tail(&chunk->entry, &e->list);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.