mirror of
git://nv-tegra.nvidia.com/linux-nvgpu.git
synced 2025-12-24 10:34:43 +03:00
As the submit job metadata has been simplified, the fence pool for job tracking fences is now just complex code for very simple purposes, so delete it. It's enough to hold the fence memory in the job struct itself instead of having separately allocated objects with different lifetimes. Each channel is using preallocated job arrays based on the prespecified inflight job count. The fences are used for tracking job completion, and a new job cannot be submitted before a previous wait has completed. This means that even with a ringbuffer with space for only one job, the previous job memory cannot get reclaimed by a new submit because the submits are ordered. Jira NVGPU-5773 Change-Id: I0c777df700aa7cfda6f971efa47aa72c5462b53a Signed-off-by: Konsta Hölttä <kholtta@nvidia.com> Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2392704 Tested-by: mobile promotions <svcmobile_promotions@nvidia.com> Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
159 lines
4.4 KiB
C
159 lines
4.4 KiB
C
/*
|
|
* Copyright (c) 2011-2020, NVIDIA CORPORATION. All rights reserved.
|
|
*
|
|
* 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 AUTHORS OR COPYRIGHT HOLDERS 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 <nvgpu/log.h>
|
|
#include <nvgpu/lock.h>
|
|
#include <nvgpu/kmem.h>
|
|
#include <nvgpu/barrier.h>
|
|
#include <nvgpu/circ_buf.h>
|
|
#include <nvgpu/channel.h>
|
|
#include <nvgpu/job.h>
|
|
#include <nvgpu/priv_cmdbuf.h>
|
|
#include <nvgpu/fence.h>
|
|
|
|
static inline struct nvgpu_channel_job *
|
|
channel_gk20a_job_from_list(struct nvgpu_list_node *node)
|
|
{
|
|
return (struct nvgpu_channel_job *)
|
|
((uintptr_t)node - offsetof(struct nvgpu_channel_job, list));
|
|
};
|
|
|
|
int nvgpu_channel_alloc_job(struct nvgpu_channel *c,
|
|
struct nvgpu_channel_job **job_out)
|
|
{
|
|
unsigned int put = c->joblist.pre_alloc.put;
|
|
unsigned int get = c->joblist.pre_alloc.get;
|
|
unsigned int next = (put + 1) % c->joblist.pre_alloc.length;
|
|
bool full = next == get;
|
|
|
|
if (full) {
|
|
return -EAGAIN;
|
|
}
|
|
|
|
*job_out = &c->joblist.pre_alloc.jobs[put];
|
|
(void) memset(*job_out, 0, sizeof(**job_out));
|
|
|
|
return 0;
|
|
}
|
|
|
|
void nvgpu_channel_free_job(struct nvgpu_channel *c,
|
|
struct nvgpu_channel_job *job)
|
|
{
|
|
/*
|
|
* Nothing needed for now. The job contents are preallocated. The
|
|
* completion fence may briefly outlive the job, but the job memory is
|
|
* reclaimed only when a new submit comes in and the ringbuffer has ran
|
|
* out of space.
|
|
*/
|
|
}
|
|
|
|
void nvgpu_channel_joblist_lock(struct nvgpu_channel *c)
|
|
{
|
|
nvgpu_mutex_acquire(&c->joblist.pre_alloc.read_lock);
|
|
}
|
|
|
|
void nvgpu_channel_joblist_unlock(struct nvgpu_channel *c)
|
|
{
|
|
nvgpu_mutex_release(&c->joblist.pre_alloc.read_lock);
|
|
}
|
|
|
|
struct nvgpu_channel_job *channel_joblist_peek(struct nvgpu_channel *c)
|
|
{
|
|
struct nvgpu_channel_job *job = NULL;
|
|
|
|
if (!nvgpu_channel_joblist_is_empty(c)) {
|
|
unsigned int get = c->joblist.pre_alloc.get;
|
|
|
|
job = &c->joblist.pre_alloc.jobs[get];
|
|
}
|
|
|
|
return job;
|
|
}
|
|
|
|
void channel_joblist_add(struct nvgpu_channel *c,
|
|
struct nvgpu_channel_job *job)
|
|
{
|
|
c->joblist.pre_alloc.put = (c->joblist.pre_alloc.put + 1U) %
|
|
(c->joblist.pre_alloc.length);
|
|
}
|
|
|
|
void channel_joblist_delete(struct nvgpu_channel *c,
|
|
struct nvgpu_channel_job *job)
|
|
{
|
|
c->joblist.pre_alloc.get = (c->joblist.pre_alloc.get + 1U) %
|
|
(c->joblist.pre_alloc.length);
|
|
}
|
|
|
|
bool nvgpu_channel_joblist_is_empty(struct nvgpu_channel *c)
|
|
{
|
|
return c->joblist.pre_alloc.get == c->joblist.pre_alloc.put;
|
|
}
|
|
|
|
int channel_prealloc_resources(struct nvgpu_channel *c, u32 num_jobs)
|
|
{
|
|
int err;
|
|
u32 size;
|
|
|
|
size = (u32)sizeof(struct nvgpu_channel_job);
|
|
if (num_jobs > nvgpu_safe_sub_u32(U32_MAX / size, 1U)) {
|
|
err = -ERANGE;
|
|
goto clean_up;
|
|
}
|
|
|
|
/*
|
|
* The max capacity of this ring buffer is the alloc size minus one (in
|
|
* units of item slot), so allocate a size of (num_jobs + 1) * size
|
|
* bytes.
|
|
*/
|
|
c->joblist.pre_alloc.jobs = nvgpu_vzalloc(c->g,
|
|
nvgpu_safe_mult_u32(
|
|
nvgpu_safe_add_u32(num_jobs, 1U),
|
|
size));
|
|
if (c->joblist.pre_alloc.jobs == NULL) {
|
|
err = -ENOMEM;
|
|
goto clean_up;
|
|
}
|
|
|
|
/*
|
|
* length is the allocation size of the ringbuffer; the number of jobs
|
|
* that fit is one less.
|
|
*/
|
|
c->joblist.pre_alloc.length = nvgpu_safe_add_u32(num_jobs, 1U);
|
|
c->joblist.pre_alloc.put = 0;
|
|
c->joblist.pre_alloc.get = 0;
|
|
|
|
return 0;
|
|
|
|
clean_up:
|
|
nvgpu_vfree(c->g, c->joblist.pre_alloc.jobs);
|
|
(void) memset(&c->joblist.pre_alloc, 0, sizeof(c->joblist.pre_alloc));
|
|
return err;
|
|
}
|
|
|
|
void channel_free_prealloc_resources(struct nvgpu_channel *c)
|
|
{
|
|
if (c->joblist.pre_alloc.jobs != NULL) {
|
|
nvgpu_vfree(c->g, c->joblist.pre_alloc.jobs);
|
|
c->joblist.pre_alloc.jobs = NULL;
|
|
}
|
|
}
|