/* * Copyright 2019 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. *
*/
int amdgpu_mes_init_microcode(struct amdgpu_device *adev, int pipe); int amdgpu_mes_init(struct amdgpu_device *adev); void amdgpu_mes_fini(struct amdgpu_device *adev);
int amdgpu_mes_suspend(struct amdgpu_device *adev); int amdgpu_mes_resume(struct amdgpu_device *adev);
int amdgpu_mes_doorbell_process_slice(struct amdgpu_device *adev);
/* * MES lock can be taken in MMU notifiers. * * A bit more detail about why to set no-FS reclaim with MES lock: * * The purpose of the MMU notifier is to stop GPU access to memory so * that the Linux VM subsystem can move pages around safely. This is * done by preempting user mode queues for the affected process. When * MES is used, MES lock needs to be taken to preempt the queues. * * The MMU notifier callback entry point in the driver is * amdgpu_mn_invalidate_range_start_hsa. The relevant call chain from * there is: * amdgpu_amdkfd_evict_userptr -> kgd2kfd_quiesce_mm -> * kfd_process_evict_queues -> pdd->dev->dqm->ops.evict_process_queues * * The last part of the chain is a function pointer where we take the * MES lock. * * The problem with taking locks in the MMU notifier is, that MMU * notifiers can be called in reclaim-FS context. That's where the * kernel frees up pages to make room for new page allocations under * memory pressure. While we are running in reclaim-FS context, we must * not trigger another memory reclaim operation because that would * recursively reenter the reclaim code and cause a deadlock. The * memalloc_nofs_save/restore calls guarantee that. * * In addition we also need to avoid lock dependencies on other locks taken * under the MES lock, for example reservation locks. Here is a possible * scenario of a deadlock: * Thread A: takes and holds reservation lock | triggers reclaim-FS | * MMU notifier | blocks trying to take MES lock * Thread B: takes and holds MES lock | blocks trying to take reservation lock * * In this scenario Thread B gets involved in a deadlock even without * triggering a reclaim-FS operation itself. * To fix this and break the lock dependency chain you'd need to either: * 1. protect reservation locks with memalloc_nofs_save/restore, or * 2. avoid taking reservation locks under the MES lock. * * Reservation locks are taken all over the kernel in different subsystems, we * have no control over them and their lock dependencies.So the only workable * solution is to avoid taking other locks under the MES lock. * As a result, make sure no reclaim-FS happens while holding this lock anywhere * to prevent deadlocks when an MMU notifier runs in reclaim-FS context.
*/ staticinlinevoid amdgpu_mes_lock(struct amdgpu_mes *mes)
{
mutex_lock(&mes->mutex_hidden);
mes->saved_flags = memalloc_noreclaim_save();
}
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.