From 0b70fff5db2ad89368f142a24b51de7560013977 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konsta=20H=C3=B6ltt=C3=A4?= Date: Tue, 14 Apr 2020 16:51:30 +0300 Subject: [PATCH] gpu: nvgpu: fix job count calculation for non-pow2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The CIRC_SPACE and CIRC_CNT macros work as expected when the buffer size is a power of two. The userspace-supplied number of inflight jobs is not necessarily so. Compare the get and put pointers manually. Jira NVGPU-4548 Change-Id: Ifa7bd6d78f82ec8efcac21fcca391053a2f6f311 Signed-off-by: Konsta Hölttä Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2328572 (cherry picked from commit 33dffa1cfb142eea0f28474566c31b632eee04f5) Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2331340 Reviewed-by: automaticguardword Reviewed-by: Automatic_Commit_Validation_User Reviewed-by: svc-mobile-coverity Reviewed-by: svc-mobile-cert Reviewed-by: Alex Waterman Reviewed-by: mobile promotions GVS: Gerrit_Virtual_Submit Tested-by: mobile promotions --- drivers/gpu/nvgpu/common/fifo/job.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/nvgpu/common/fifo/job.c b/drivers/gpu/nvgpu/common/fifo/job.c index 39cde7b0b..8a7d1aae6 100644 --- a/drivers/gpu/nvgpu/common/fifo/job.c +++ b/drivers/gpu/nvgpu/common/fifo/job.c @@ -45,6 +45,8 @@ int nvgpu_channel_alloc_job(struct nvgpu_channel *c, if (nvgpu_channel_is_prealloc_enabled(c)) { 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; /* * ensure all subsequent reads happen after reading get. @@ -53,7 +55,7 @@ int nvgpu_channel_alloc_job(struct nvgpu_channel *c, */ nvgpu_smp_rmb(); - if (CIRC_SPACE(put, get, c->joblist.pre_alloc.length) != 0U) { + if (!full) { *job_out = &c->joblist.pre_alloc.jobs[put]; } else { nvgpu_warn(c->g, @@ -157,7 +159,7 @@ bool nvgpu_channel_joblist_is_empty(struct nvgpu_channel *c) unsigned int get = c->joblist.pre_alloc.get; unsigned int put = c->joblist.pre_alloc.put; - return (CIRC_CNT(put, get, c->joblist.pre_alloc.length) == 0U); + return get == put; } return nvgpu_list_empty(&c->joblist.dynamic.jobs);