summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/common
diff options
context:
space:
mode:
authorKonsta Holtta <kholtta@nvidia.com>2018-03-12 04:37:38 -0400
committermobile promotions <svcmobile_promotions@nvidia.com>2018-03-13 05:43:37 -0400
commit86943d3d03953cc88b3e8a85aa232493b729137a (patch)
treef70caf4e93c13c541a33ad0a8f63122715ec8cc6 /drivers/gpu/nvgpu/common
parentc6e8257c445ad7cd3924673ac2e36f9dde796f0f (diff)
gpu: nvgpu: decouple sema and hw sema
struct nvgpu_semaphore represents (mainly) a threshold value that a sema at some index will get and struct nvgpu_semaphore_int (aka "hw_sema") represents the allocation (and write access) of a semaphore index and the next value that the sema at that index can have. The threshold object doesn't need a pointer to the sema allocation that is not even guaranteed to exist for the whole threshold lifetime, so replace the pointer by the position of the sema in the sema pool. This requires some modifications to pass a hw sema around explicitly because it now represents write access more explicitly. Delete also the index field of semaphore_int because it can be directly derived from the offset in the sema location and is thus unnecessary. Jira NVGPU-512 Change-Id: I40be523fd68327e2f9928f10de4f771fe24d49ee Signed-off-by: Konsta Holtta <kholtta@nvidia.com> Reviewed-on: https://git-master.nvidia.com/r/1658102 Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com> Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
Diffstat (limited to 'drivers/gpu/nvgpu/common')
-rw-r--r--drivers/gpu/nvgpu/common/semaphore.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/drivers/gpu/nvgpu/common/semaphore.c b/drivers/gpu/nvgpu/common/semaphore.c
index dfed3588..b2238bb7 100644
--- a/drivers/gpu/nvgpu/common/semaphore.c
+++ b/drivers/gpu/nvgpu/common/semaphore.c
@@ -376,10 +376,10 @@ static int __nvgpu_init_hw_sema(struct channel_gk20a *ch)
376 376
377 ch->hw_sema = hw_sema; 377 ch->hw_sema = hw_sema;
378 hw_sema->ch = ch; 378 hw_sema->ch = ch;
379 hw_sema->p = p; 379 hw_sema->location.pool = p;
380 hw_sema->idx = hw_sema_idx; 380 hw_sema->location.offset = SEMAPHORE_SIZE * hw_sema_idx;
381 hw_sema->offset = SEMAPHORE_SIZE * hw_sema_idx; 381 current_value = nvgpu_mem_rd(ch->g, &p->rw_mem,
382 current_value = nvgpu_mem_rd(ch->g, &p->rw_mem, hw_sema->offset); 382 hw_sema->location.offset);
383 nvgpu_atomic_set(&hw_sema->next_value, current_value); 383 nvgpu_atomic_set(&hw_sema->next_value, current_value);
384 384
385 nvgpu_mutex_release(&p->pool_lock); 385 nvgpu_mutex_release(&p->pool_lock);
@@ -399,15 +399,16 @@ fail:
399void nvgpu_semaphore_free_hw_sema(struct channel_gk20a *ch) 399void nvgpu_semaphore_free_hw_sema(struct channel_gk20a *ch)
400{ 400{
401 struct nvgpu_semaphore_pool *p = ch->vm->sema_pool; 401 struct nvgpu_semaphore_pool *p = ch->vm->sema_pool;
402 struct nvgpu_semaphore_int *hw_sema = ch->hw_sema;
403 int idx = hw_sema->location.offset / SEMAPHORE_SIZE;
402 404
403 BUG_ON(!p); 405 BUG_ON(!p);
404 406
405 nvgpu_mutex_acquire(&p->pool_lock); 407 nvgpu_mutex_acquire(&p->pool_lock);
406 408
407 clear_bit(ch->hw_sema->idx, p->semas_alloced); 409 clear_bit(idx, p->semas_alloced);
408 410
409 /* Make sure that when the ch is re-opened it will get a new HW sema. */ 411 nvgpu_kfree(ch->g, hw_sema);
410 nvgpu_kfree(ch->g, ch->hw_sema);
411 ch->hw_sema = NULL; 412 ch->hw_sema = NULL;
412 413
413 nvgpu_mutex_release(&p->pool_lock); 414 nvgpu_mutex_release(&p->pool_lock);
@@ -435,14 +436,15 @@ struct nvgpu_semaphore *nvgpu_semaphore_alloc(struct channel_gk20a *ch)
435 return NULL; 436 return NULL;
436 437
437 nvgpu_ref_init(&s->ref); 438 nvgpu_ref_init(&s->ref);
438 s->hw_sema = ch->hw_sema; 439 s->g = ch->g;
440 s->location = ch->hw_sema->location;
439 nvgpu_atomic_set(&s->value, 0); 441 nvgpu_atomic_set(&s->value, 0);
440 442
441 /* 443 /*
442 * Take a ref on the pool so that we can keep this pool alive for 444 * Take a ref on the pool so that we can keep this pool alive for
443 * as long as this semaphore is alive. 445 * as long as this semaphore is alive.
444 */ 446 */
445 nvgpu_semaphore_pool_get(s->hw_sema->p); 447 nvgpu_semaphore_pool_get(s->location.pool);
446 448
447 gpu_sema_dbg(ch->g, "Allocated semaphore (c=%d)", ch->chid); 449 gpu_sema_dbg(ch->g, "Allocated semaphore (c=%d)", ch->chid);
448 450
@@ -454,9 +456,9 @@ static void nvgpu_semaphore_free(struct nvgpu_ref *ref)
454 struct nvgpu_semaphore *s = 456 struct nvgpu_semaphore *s =
455 container_of(ref, struct nvgpu_semaphore, ref); 457 container_of(ref, struct nvgpu_semaphore, ref);
456 458
457 nvgpu_semaphore_pool_put(s->hw_sema->p); 459 nvgpu_semaphore_pool_put(s->location.pool);
458 460
459 nvgpu_kfree(s->hw_sema->ch->g, s); 461 nvgpu_kfree(s->g, s);
460} 462}
461 463
462void nvgpu_semaphore_put(struct nvgpu_semaphore *s) 464void nvgpu_semaphore_put(struct nvgpu_semaphore *s)