All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oded Gabbay <oded.gabbay-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: Felix Kuehling <Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>
Cc: Andres Rodriguez <andres.rodriguez-5C7GfCeVMHo@public.gmane.org>,
	amd-gfx list
	<amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org>
Subject: Re: [PATCH 13/16] drm/amdkfd: use standard kernel kfifo for IH
Date: Wed, 25 Oct 2017 15:15:09 +0300	[thread overview]
Message-ID: <CAFCwf11OJBUGgeYAmY9j7XvurFe-ObEFxVHkewp_PsK1jdN3AQ@mail.gmail.com> (raw)
In-Reply-To: <1508545400-24338-14-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>

On Sat, Oct 21, 2017 at 3:23 AM, Felix Kuehling <Felix.Kuehling@amd.com> wrote:
> From: Andres Rodriguez <andres.rodriguez@amd.com>
>
> Replace our implementation of a lockless ring buffer with the standard
> linux kernel kfifo.
>
> We shouldn't maintain our own version of a standard data structure.
>
> Signed-off-by: Andres Rodriguez <andres.rodriguez@amd.com>
> Signed-off-by: Felix Kuehling <Felix.Kuehling@amd.com>
> ---
>  drivers/gpu/drm/amd/amdkfd/kfd_interrupt.c | 78 ++++++++++--------------------
>  drivers/gpu/drm/amd/amdkfd/kfd_priv.h      |  6 +--
>  2 files changed, 27 insertions(+), 57 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_interrupt.c b/drivers/gpu/drm/amd/amdkfd/kfd_interrupt.c
> index 70b3a99c..ffbb91a 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_interrupt.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_interrupt.c
> @@ -42,25 +42,24 @@
>
>  #include <linux/slab.h>
>  #include <linux/device.h>
> +#include <linux/kfifo.h>
>  #include "kfd_priv.h"
>
> -#define KFD_INTERRUPT_RING_SIZE 1024
> +#define KFD_IH_NUM_ENTRIES 1024
>
>  static void interrupt_wq(struct work_struct *);
>
>  int kfd_interrupt_init(struct kfd_dev *kfd)
>  {
> -       void *interrupt_ring = kmalloc_array(KFD_INTERRUPT_RING_SIZE,
> -                                       kfd->device_info->ih_ring_entry_size,
> -                                       GFP_KERNEL);
> -       if (!interrupt_ring)
> -               return -ENOMEM;
> -
> -       kfd->interrupt_ring = interrupt_ring;
> -       kfd->interrupt_ring_size =
> -               KFD_INTERRUPT_RING_SIZE * kfd->device_info->ih_ring_entry_size;
> -       atomic_set(&kfd->interrupt_ring_wptr, 0);
> -       atomic_set(&kfd->interrupt_ring_rptr, 0);
> +       int r;
> +
> +       r = kfifo_alloc(&kfd->ih_fifo,
> +               KFD_IH_NUM_ENTRIES * kfd->device_info->ih_ring_entry_size,
> +               GFP_KERNEL);
> +       if (r) {
> +               dev_err(kfd_chardev(), "Failed to allocate IH fifo\n");
> +               return r;
> +       }
>
>         spin_lock_init(&kfd->interrupt_lock);
>
> @@ -98,68 +97,41 @@ void kfd_interrupt_exit(struct kfd_dev *kfd)
>          */
>         flush_scheduled_work();
>
> -       kfree(kfd->interrupt_ring);
> +       kfifo_free(&kfd->ih_fifo);
>  }
>
>  /*
> - * This assumes that it can't be called concurrently with itself
> - * but only with dequeue_ih_ring_entry.
> + * Assumption: single reader/writer. This function is not re-entrant
>   */
>  bool enqueue_ih_ring_entry(struct kfd_dev *kfd,        const void *ih_ring_entry)
>  {
> -       unsigned int rptr = atomic_read(&kfd->interrupt_ring_rptr);
> -       unsigned int wptr = atomic_read(&kfd->interrupt_ring_wptr);
> +       int count;
>
> -       if ((rptr - wptr) % kfd->interrupt_ring_size ==
> -                                       kfd->device_info->ih_ring_entry_size) {
> -               /* This is very bad, the system is likely to hang. */
> +       count = kfifo_in(&kfd->ih_fifo, ih_ring_entry,
> +                               kfd->device_info->ih_ring_entry_size);
> +       if (count != kfd->device_info->ih_ring_entry_size) {
>                 dev_err_ratelimited(kfd_chardev(),
> -                       "Interrupt ring overflow, dropping interrupt.\n");
> +                       "Interrupt ring overflow, dropping interrupt %d\n",
> +                       count);
>                 return false;
>         }
>
> -       memcpy(kfd->interrupt_ring + wptr, ih_ring_entry,
> -                       kfd->device_info->ih_ring_entry_size);
> -
> -       wptr = (wptr + kfd->device_info->ih_ring_entry_size) %
> -                       kfd->interrupt_ring_size;
> -       smp_wmb(); /* Ensure memcpy'd data is visible before wptr update. */
> -       atomic_set(&kfd->interrupt_ring_wptr, wptr);
> -
>         return true;
>  }
>
>  /*
> - * This assumes that it can't be called concurrently with itself
> - * but only with enqueue_ih_ring_entry.
> + * Assumption: single reader/writer. This function is not re-entrant
>   */
>  static bool dequeue_ih_ring_entry(struct kfd_dev *kfd, void *ih_ring_entry)
>  {
> -       /*
> -        * Assume that wait queues have an implicit barrier, i.e. anything that
> -        * happened in the ISR before it queued work is visible.
> -        */
> -
> -       unsigned int wptr = atomic_read(&kfd->interrupt_ring_wptr);
> -       unsigned int rptr = atomic_read(&kfd->interrupt_ring_rptr);
> +       int count;
>
> -       if (rptr == wptr)
> -               return false;
> -
> -       memcpy(ih_ring_entry, kfd->interrupt_ring + rptr,
> -                       kfd->device_info->ih_ring_entry_size);
> -
> -       rptr = (rptr + kfd->device_info->ih_ring_entry_size) %
> -                       kfd->interrupt_ring_size;
> +       count = kfifo_out(&kfd->ih_fifo, ih_ring_entry,
> +                               kfd->device_info->ih_ring_entry_size);
>
> -       /*
> -        * Ensure the rptr write update is not visible until
> -        * memcpy has finished reading.
> -        */
> -       smp_mb();
> -       atomic_set(&kfd->interrupt_ring_rptr, rptr);
> +       WARN_ON(count && count != kfd->device_info->ih_ring_entry_size);
>
> -       return true;
> +       return count == kfd->device_info->ih_ring_entry_size;
>  }
>
>  static void interrupt_wq(struct work_struct *work)
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
> index ebae8e1..e8d6c0e 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
> @@ -32,6 +32,7 @@
>  #include <linux/spinlock.h>
>  #include <linux/kfd_ioctl.h>
>  #include <linux/idr.h>
> +#include <linux/kfifo.h>
>  #include <kgd_kfd_interface.h>
>
>  #include "amd_shared.h"
> @@ -182,10 +183,7 @@ struct kfd_dev {
>         unsigned int gtt_sa_num_of_chunks;
>
>         /* Interrupts */
> -       void *interrupt_ring;
> -       size_t interrupt_ring_size;
> -       atomic_t interrupt_ring_rptr;
> -       atomic_t interrupt_ring_wptr;
> +       struct kfifo ih_fifo;
>         struct work_struct interrupt_work;
>         spinlock_t interrupt_lock;
>
> --
> 2.7.4
>

This patch is:
Acked-by: Oded Gabbay <oded.gabbay@gmail.com>
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

  parent reply	other threads:[~2017-10-25 12:15 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-21  0:23 [PATCH 00/16] KFD interrupt and signal event handling improvements Felix Kuehling
     [not found] ` <1508545400-24338-1-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>
2017-10-21  0:23   ` [PATCH 01/16] drm/amdkfd: Add SDMA trap src id to the KFD isr wanted list Felix Kuehling
     [not found]     ` <1508545400-24338-2-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>
2017-10-25  6:13       ` Oded Gabbay
2017-10-21  0:23   ` [PATCH 02/16] drm/amdkfd: Don't dereference kfd_process.mm Felix Kuehling
     [not found]     ` <1508545400-24338-3-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>
2017-10-25  6:45       ` Oded Gabbay
2017-10-26  7:33       ` Christian König
     [not found]         ` <183a1c77-23a2-3015-e019-cb3fc57cdb3c-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-10-26 16:47           ` Felix Kuehling
     [not found]             ` <f42bdbcc-0264-f189-fa6f-9989016b380d-5C7GfCeVMHo@public.gmane.org>
2017-10-26 18:11               ` Christian König
     [not found]                 ` <b04933a4-e585-d1ff-57a3-d9ba1f09c0b0-5C7GfCeVMHo@public.gmane.org>
2017-10-26 18:54                   ` Felix Kuehling
     [not found]                     ` <0ff645b5-1906-2ce3-a9a6-d34c2ce2c516-5C7GfCeVMHo@public.gmane.org>
2017-10-27  7:22                       ` Christian König
     [not found]                         ` <19defd90-bf38-315b-cb4a-eb78e4acafec-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-10-27  7:41                           ` Christian König
     [not found]                             ` <fa2c0104-7a85-f250-bafc-c8096f910d92-5C7GfCeVMHo@public.gmane.org>
2017-10-27 19:09                               ` Felix Kuehling
2017-10-21  0:23   ` [PATCH 03/16] drm/amdkfd: increase limit of signal events to 4096 per process Felix Kuehling
     [not found]     ` <1508545400-24338-4-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>
2017-10-25  8:31       ` Oded Gabbay
2017-10-21  0:23   ` [PATCH 04/16] drm/amdkfd: Short cut for kfd_wait_on_events without waiting Felix Kuehling
     [not found]     ` <1508545400-24338-5-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>
2017-10-25  8:39       ` Oded Gabbay
2017-10-21  0:23   ` [PATCH 05/16] drm/amdkfd: Fix scheduler race in kfd_wait_on_events sleep loop Felix Kuehling
     [not found]     ` <1508545400-24338-6-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>
2017-10-25  8:45       ` Oded Gabbay
2017-10-21  0:23   ` [PATCH 06/16] drm/amdkfd: Clean up kfd_wait_on_events Felix Kuehling
     [not found]     ` <1508545400-24338-7-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>
2017-10-25  8:49       ` Oded Gabbay
2017-10-21  0:23   ` [PATCH 07/16] drm/amdkfd: Fix event destruction with pending waiters Felix Kuehling
     [not found]     ` <1508545400-24338-8-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>
2017-10-25  8:50       ` Oded Gabbay
2017-10-21  0:23   ` [PATCH 08/16] drm/amdkfd: remove redundant kfd_event_waiter.input_index Felix Kuehling
     [not found]     ` <1508545400-24338-9-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>
2017-10-25  8:54       ` Oded Gabbay
2017-10-21  0:23   ` [PATCH 09/16] drm/amdkfd: Use wait_queue_t to implement event waiting Felix Kuehling
     [not found]     ` <1508545400-24338-10-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>
2017-10-25 10:28       ` Oded Gabbay
     [not found]         ` <CAFCwf10QwD3JNz6BGWBC94WHfU2EpDx1CJSkjjwjNt7AnZLpyA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-10-25 16:02           ` Felix Kuehling
2017-10-21  0:23   ` [PATCH 10/16] drm/amdkfd: Simplify events page allocator Felix Kuehling
     [not found]     ` <1508545400-24338-11-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>
2017-10-25 10:40       ` Oded Gabbay
2017-10-21  0:23   ` [PATCH 11/16] drm/amdkfd: Simplify event ID and signal slot management Felix Kuehling
     [not found]     ` <1508545400-24338-12-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>
2017-10-25 10:42       ` Oded Gabbay
2017-10-21  0:23   ` [PATCH 12/16] drm/amdkfd: Use IH context ID for signal lookup Felix Kuehling
     [not found]     ` <1508545400-24338-13-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>
2017-10-25 10:46       ` Oded Gabbay
2017-10-21  0:23   ` [PATCH 13/16] drm/amdkfd: use standard kernel kfifo for IH Felix Kuehling
     [not found]     ` <1508545400-24338-14-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>
2017-10-25 12:15       ` Oded Gabbay [this message]
2017-10-21  0:23   ` [PATCH 14/16] drm/amdkfd: increase IH num entries to 8192 Felix Kuehling
     [not found]     ` <1508545400-24338-15-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>
2017-10-25 12:18       ` Oded Gabbay
2017-10-21  0:23   ` [PATCH 15/16] drm/amdkfd: wait only for IH work on IH exit Felix Kuehling
     [not found]     ` <1508545400-24338-16-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>
2017-10-25 12:20       ` Oded Gabbay
2017-10-21  0:23   ` [PATCH 16/16] drm/amdkfd: use a high priority workqueue for IH work Felix Kuehling
     [not found]     ` <1508545400-24338-17-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>
2017-10-25 12:21       ` Oded Gabbay
2017-10-25  6:57   ` [PATCH 00/16] KFD interrupt and signal event handling improvements Oded Gabbay
     [not found]     ` <CAFCwf11ao-E7Y+LvE6e++74xq+RiH+B1xA9nrk_u_8CTXyUuVQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-10-25  7:31       ` Christian König
2017-10-25 16:04       ` Felix Kuehling

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAFCwf11OJBUGgeYAmY9j7XvurFe-ObEFxVHkewp_PsK1jdN3AQ@mail.gmail.com \
    --to=oded.gabbay-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=Felix.Kuehling-5C7GfCeVMHo@public.gmane.org \
    --cc=amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
    --cc=andres.rodriguez-5C7GfCeVMHo@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.