linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bartosz Golaszewski <brgl@bgdev.pl>
To: "Thomas Gleixner" <tglx@linutronix.de>,
	"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
	"Marc Zyngier" <marc.zyngier@arm.com>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] irq/irq_sim: store multiple interrupt offsets in a bitmap
Date: Tue, 11 Dec 2018 15:02:48 +0100	[thread overview]
Message-ID: <CAMRc=MeY_CbdQDF7UOai5MW3OLF1u+a04AAyq5bsux8_Fv5DVQ@mail.gmail.com> (raw)
In-Reply-To: <20181109172132.30939-1-brgl@bgdev.pl>

pt., 9 lis 2018 o 18:21 Bartosz Golaszewski <brgl@bgdev.pl> napisał(a):
>
> Two threads can try to fire the irq_sim with different offsets and will
> end up fighting for the irq_work asignment. Thomas Gleixner suggested a
> solution based on a bitfield where we set a bit for every offset
> associated with an interrupt that should be fired and then iterate over
> all set bits in the interrupt handler.
>
> This is a slightly modified solution using a bitmap so that we don't
> impose a limit on the number of interrupts one can allocate with
> irq_sim.
>
> Suggested-by: Thomas Gleixner <tglx@linutronix.de>
> Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
> ---
>  include/linux/irq_sim.h |  2 +-
>  kernel/irq/irq_sim.c    | 23 +++++++++++++++++++++--
>  2 files changed, 22 insertions(+), 3 deletions(-)
>
> diff --git a/include/linux/irq_sim.h b/include/linux/irq_sim.h
> index 630a57e55db6..4500d453a63e 100644
> --- a/include/linux/irq_sim.h
> +++ b/include/linux/irq_sim.h
> @@ -16,7 +16,7 @@
>
>  struct irq_sim_work_ctx {
>         struct irq_work         work;
> -       int                     irq;
> +       unsigned long           *pending;
>  };
>
>  struct irq_sim_irq_ctx {
> diff --git a/kernel/irq/irq_sim.c b/kernel/irq/irq_sim.c
> index dd20d0d528d4..98a20e1594ce 100644
> --- a/kernel/irq/irq_sim.c
> +++ b/kernel/irq/irq_sim.c
> @@ -34,9 +34,20 @@ static struct irq_chip irq_sim_irqchip = {
>  static void irq_sim_handle_irq(struct irq_work *work)
>  {
>         struct irq_sim_work_ctx *work_ctx;
> +       unsigned int offset = 0;
> +       struct irq_sim *sim;
> +       int irqnum;
>
>         work_ctx = container_of(work, struct irq_sim_work_ctx, work);
> -       handle_simple_irq(irq_to_desc(work_ctx->irq));
> +       sim = container_of(work_ctx, struct irq_sim, work_ctx);
> +
> +       while (!bitmap_empty(work_ctx->pending, sim->irq_count)) {
> +               offset = find_next_bit(work_ctx->pending,
> +                                      sim->irq_count, offset);
> +               clear_bit(offset, work_ctx->pending);
> +               irqnum = irq_sim_irqnum(sim, offset);
> +               handle_simple_irq(irq_to_desc(irqnum));
> +       }
>  }
>
>  /**
> @@ -63,6 +74,13 @@ int irq_sim_init(struct irq_sim *sim, unsigned int num_irqs)
>                 return sim->irq_base;
>         }
>
> +       sim->work_ctx.pending = bitmap_zalloc(num_irqs, GFP_KERNEL);
> +       if (!sim->work_ctx.pending) {
> +               kfree(sim->irqs);
> +               irq_free_descs(sim->irq_base, num_irqs);
> +               return -ENOMEM;
> +       }
> +
>         for (i = 0; i < num_irqs; i++) {
>                 sim->irqs[i].irqnum = sim->irq_base + i;
>                 sim->irqs[i].enabled = false;
> @@ -89,6 +107,7 @@ EXPORT_SYMBOL_GPL(irq_sim_init);
>  void irq_sim_fini(struct irq_sim *sim)
>  {
>         irq_work_sync(&sim->work_ctx.work);
> +       bitmap_free(sim->work_ctx.pending);
>         irq_free_descs(sim->irq_base, sim->irq_count);
>         kfree(sim->irqs);
>  }
> @@ -143,7 +162,7 @@ EXPORT_SYMBOL_GPL(devm_irq_sim_init);
>  void irq_sim_fire(struct irq_sim *sim, unsigned int offset)
>  {
>         if (sim->irqs[offset].enabled) {
> -               sim->work_ctx.irq = irq_sim_irqnum(sim, offset);
> +               set_bit(offset, sim->work_ctx.pending);
>                 irq_work_queue(&sim->work_ctx.work);
>         }
>  }
> --
> 2.19.1
>

Ping and Cc'ing Marc Zyngier. Any chance of getting this in for 4.21?

Bart

  reply	other threads:[~2018-12-11 14:03 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-09 17:21 [PATCH] irq/irq_sim: store multiple interrupt offsets in a bitmap Bartosz Golaszewski
2018-12-11 14:02 ` Bartosz Golaszewski [this message]
2018-12-11 14:41   ` Marc Zyngier
2018-12-11 15:39     ` Bartosz Golaszewski

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='CAMRc=MeY_CbdQDF7UOai5MW3OLF1u+a04AAyq5bsux8_Fv5DVQ@mail.gmail.com' \
    --to=brgl@bgdev.pl \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marc.zyngier@arm.com \
    --cc=tglx@linutronix.de \
    --cc=u.kleine-koenig@pengutronix.de \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).