Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp773454lqo; Fri, 17 May 2024 00:38:10 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWagL9FnjbZxBfhEjdaaayOpYjvcOGwbg9yM57ra8MhdWDKdcObzj1/8yHLAsMs46MeSrPrcxVinXM/KLT2E+zkevI7fjwxfCHV71bCeQ== X-Google-Smtp-Source: AGHT+IEmdV8+JyZQPv8dgV/ckZM3QKcq6hOegatrpYmmGxOzjCtf43q6R4Il8TjJHy06pkHK1xt4 X-Received: by 2002:a17:902:b40b:b0:1e2:4c85:82ea with SMTP id d9443c01a7336-1ef43d2a7c2mr160457785ad.24.1715931490346; Fri, 17 May 2024 00:38:10 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715931490; cv=pass; d=google.com; s=arc-20160816; b=yjUluxfgQm0EuLC+LZJIihkcRRsh52fp/reLyZraOAZ/lhr60vF5ZnFXyrECewbLUh QEnSvUKgdu/oO8kE/MeRLGN5wEcYyMfTpzGSjNqy52mrGM/2r4EIK8B1ZZegYw+sWIDa Z62CnURuzYvXzJ+V8uKk9RbBxTjvK1kHwFGZHs7kUqUrx+ummsBOrLiS1Rj43iYwKOiC yCE7poK2IW8pBA/9CI7ET9njaQmfzTWH3zj9EyDtOba5bGTlt+anwnHpKtHBBvw7Uyxz QKnYdvDAfoRLOMU1RlPRBuswWy32g3KfFvT0RvIuqdQoMQkkOXfarJzjeFgKaKuv4BxX h9qg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=VPzon8+wV3b+aDEGHRzIAui3dd2vqZlXk30RBsw01Rg=; fh=NNnouVaHb7mvdsm6qupLAIiSa9heFXqI8RJFjdHeHK0=; b=AHoH2E9ph2HIwbrpJz1IsaAamG2KJTWkSR1cqyARJnc1HzjJinKooossNWc0NDAaLj 6ojlEfNkQe7mxwc7Z8xDI3XY9ZKHBEPFnkIaMOcVXS7Q6P5c6NV7OoCZmu4InfbuYVQE oKtedyVBdgs89fKLbU08FWe1kGznBTLxP3DHdnbLxWBvjIHiMQHv+6UNVDbCXhL5goS7 fQodaox1Wp08738LrqrKhHM/a+BuoZ4D4WxNODnav7quFNiCKK1jL9Qls9Y9FrdMVHK7 gm2/yaWjgNAk70vqJYrhhxcY+5PeZxat15SDd3feIzcjPqGrKZGV/FzoDB4ZRFGaWtTy QI+Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=h0uNjCjU; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-181802-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-181802-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id d9443c01a7336-1f08ea06c1asi56135665ad.212.2024.05.17.00.38.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 May 2024 00:38:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-181802-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=h0uNjCjU; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-181802-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-181802-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 56455B217AC for ; Fri, 17 May 2024 07:38:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A8CE817BAE; Fri, 17 May 2024 07:37:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="h0uNjCjU" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A4EEA17BA7; Fri, 17 May 2024 07:37:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715931476; cv=none; b=sQz/e/Fh8xrTS6MP/TmcYGmfGkgm022Kf4WjvAfGqqYCY6n50fuoIMjyMaDmrqKsvOIXuiO7qJR5UHmmy0l9x/TkYptwcb0FGzGQFwfaweLmzO2khGAk5W8esU7xQtsrsMoyzJNy3XTs/xzr733wNo/NIT1e7PbTx/XLoP5gEEI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715931476; c=relaxed/simple; bh=8xcNtpQ4LncrDhuJ25hPt9wZoKOTAtIcM5tusY56NBo=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=p7LQNwk/GNxIXyfv0r5WDI5XCIp1F9CujD76aeQYYi6RXwUEy7BKwSMQntoAiX1Z6BafbhKb+agHpO0hdURbn2ElBidiXhx1E7bifGdL3QV4BBfB3FETt1N4YgrS4Yfecp8qrkUzHBBYLCY6Z9w3gUo35DvCNCaGMjDrMDkIii0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=h0uNjCjU; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5596EC4AF08; Fri, 17 May 2024 07:37:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715931476; bh=8xcNtpQ4LncrDhuJ25hPt9wZoKOTAtIcM5tusY56NBo=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=h0uNjCjUMQZ0IGVvEutrQZXHC8PUdgFQOzZfnfNpqMqz68oqSFKm+tbxK/mpKycnp 2PIN6cQuhJ1a4pkGfOQr+hzy2q60boSlztx2/If64o2f1AJgjvC2IEbtms4/6/P4nY jVK/k0lkqvLQvpDc6YAfHIvvF5K5gmjneF5Ze65N8Y5XF2OFEVGVgyw+evlPKBgj/c zSvLPVe+ibiymz7dfxjOulhdEG1Ae9ViqsazJLYrctkWnCKC5Bk8B8fltq+8UWEjzW hDYhOV+jMWb85P0lujplI/JZpyPQKoGETIQME7mLTy0KnXSCkiArijjK5wv5t79zav 0MiBaPg73FEfg== Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-572e48f91e9so4781702a12.0; Fri, 17 May 2024 00:37:56 -0700 (PDT) X-Forwarded-Encrypted: i=1; AJvYcCU6CNEbYFfYbq/37FiX0Hn5/4FaOhJHFid/OEtSNfcSCFyMQcHepa4HSac1iBSKeLtjxlvNuuFFwnrm1V8eBDtMQThLD6U7eHwZhFlgu6i13kQNvOhLGfi8ROXfRzA8w6jJzK3+vu0M/Q== X-Gm-Message-State: AOJu0Yyq9y+A4g0DG1cZkx3kKO6o9TEr1XIpRlCTq5malfnNpWjqKoUc Uuky4/6X78UjDCF3/acVyQZp13ucbSggXMh+1N0C8X/EYzqx7oWHY0vBQT7ORgg+pAzkIcvk8yf EWM0GGLi02CJ1sbGfyxaRt/Suctw= X-Received: by 2002:a17:906:a99:b0:a59:aa68:99a0 with SMTP id a640c23a62f3a-a5a2d5819bbmr1385056966b.18.1715931474805; Fri, 17 May 2024 00:37:54 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240514073232.3694867-1-chenhuacai@loongson.cn> In-Reply-To: From: Huacai Chen Date: Fri, 17 May 2024 15:37:43 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] LoongArch: Add irq_work support via self IPIs To: maobibo Cc: Huacai Chen , Arnd Bergmann , loongarch@lists.linux.dev, linux-arch@vger.kernel.org, Xuefeng Li , Guo Ren , Xuerui Wang , Jiaxun Yang , linux-kernel@vger.kernel.org, loongson-kernel@lists.loongnix.cn Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, May 16, 2024 at 8:23=E2=80=AFPM maobibo wrote= : > > > > On 2024/5/14 =E4=B8=8B=E5=8D=883:32, Huacai Chen wrote: > > Add irq_work support for LoongArch via self IPIs. This make it possible > > to run works in hardware interrupt context, which is a prerequisite for > > NOHZ_FULL. > > > > Implement: > > - arch_irq_work_raise() > > - arch_irq_work_has_interrupt() > > > > Signed-off-by: Huacai Chen > > --- > > arch/loongarch/include/asm/hardirq.h | 3 ++- > > arch/loongarch/include/asm/irq_work.h | 10 ++++++++++ > > arch/loongarch/include/asm/smp.h | 2 ++ > > arch/loongarch/kernel/paravirt.c | 6 ++++++ > > arch/loongarch/kernel/smp.c | 14 ++++++++++++++ > > 5 files changed, 34 insertions(+), 1 deletion(-) > > create mode 100644 arch/loongarch/include/asm/irq_work.h > > > > diff --git a/arch/loongarch/include/asm/hardirq.h b/arch/loongarch/incl= ude/asm/hardirq.h > > index d41138abcf26..1d7feb719515 100644 > > --- a/arch/loongarch/include/asm/hardirq.h > > +++ b/arch/loongarch/include/asm/hardirq.h > > @@ -12,11 +12,12 @@ > > extern void ack_bad_irq(unsigned int irq); > > #define ack_bad_irq ack_bad_irq > > > > -#define NR_IPI 2 > > +#define NR_IPI 3 > > > > enum ipi_msg_type { > > IPI_RESCHEDULE, > > IPI_CALL_FUNCTION, > > + IPI_IRQ_WORK, > > }; > > > > typedef struct { > > diff --git a/arch/loongarch/include/asm/irq_work.h b/arch/loongarch/inc= lude/asm/irq_work.h > > new file mode 100644 > > index 000000000000..d63076e9160d > > --- /dev/null > > +++ b/arch/loongarch/include/asm/irq_work.h > > @@ -0,0 +1,10 @@ > > +/* SPDX-License-Identifier: GPL-2.0 */ > > +#ifndef _ASM_LOONGARCH_IRQ_WORK_H > > +#define _ASM_LOONGARCH_IRQ_WORK_H > > + > > +static inline bool arch_irq_work_has_interrupt(void) > > +{ > > + return IS_ENABLED(CONFIG_SMP); > > +} > > + > > +#endif /* _ASM_LOONGARCH_IRQ_WORK_H */ > > diff --git a/arch/loongarch/include/asm/smp.h b/arch/loongarch/include/= asm/smp.h > > index 278700cfee88..50db503f44e3 100644 > > --- a/arch/loongarch/include/asm/smp.h > > +++ b/arch/loongarch/include/asm/smp.h > > @@ -69,9 +69,11 @@ extern int __cpu_logical_map[NR_CPUS]; > > #define ACTION_BOOT_CPU 0 > > #define ACTION_RESCHEDULE 1 > > #define ACTION_CALL_FUNCTION 2 > > +#define ACTION_IRQ_WORK 3 > > #define SMP_BOOT_CPU BIT(ACTION_BOOT_CPU) > > #define SMP_RESCHEDULE BIT(ACTION_RESCHEDULE) > > #define SMP_CALL_FUNCTION BIT(ACTION_CALL_FUNCTION) > > +#define SMP_IRQ_WORK BIT(ACTION_IRQ_WORK) > > > > struct secondary_data { > > unsigned long stack; > > diff --git a/arch/loongarch/kernel/paravirt.c b/arch/loongarch/kernel/p= aravirt.c > > index 1633ed4f692f..4272d2447445 100644 > > --- a/arch/loongarch/kernel/paravirt.c > > +++ b/arch/loongarch/kernel/paravirt.c > > @@ -2,6 +2,7 @@ > > #include > > #include > > #include > > +#include > > #include > > #include > > #include > > @@ -97,6 +98,11 @@ static irqreturn_t pv_ipi_interrupt(int irq, void *d= ev) > > info->ipi_irqs[IPI_CALL_FUNCTION]++; > > } > > > > + if (action & SMP_IRQ_WORK) { > > + irq_work_run(); > > + info->ipi_irqs[IPI_IRQ_WORK]++; > > + } > > + > Would you mind adding common api so that pv ipi handler and hw ipi > handler can call it both? The coming avec MSI interrupt driver has the > same requirement for ipi. We can refactor it after AVEC upstream, if needed. Huacai > > void do_ipi_demux(unsigned int action) > { > irq_cpustat_t *info; > > info =3D this_cpu_ptr(&irq_stat); > if (action & SMP_RESCHEDULE) { > scheduler_ipi(); > info->ipi_irqs[IPI_RESCHEDULE]++; > } > > if (action & SMP_CALL_FUNCTION) { > generic_smp_call_function_interrupt(); > info->ipi_irqs[IPI_CALL_FUNCTION]++; > } > > if (action & SMP_IRQ_WORK) { > irq_work_run(); > info->ipi_irqs[IPI_IRQ_WORK]++; > } > > Regards > Bibo Mao > > return IRQ_HANDLED; > > } > > > > diff --git a/arch/loongarch/kernel/smp.c b/arch/loongarch/kernel/smp.c > > index 0dfe2388ef41..7366de776f6e 100644 > > --- a/arch/loongarch/kernel/smp.c > > +++ b/arch/loongarch/kernel/smp.c > > @@ -13,6 +13,7 @@ > > #include > > #include > > #include > > +#include > > #include > > #include > > #include > > @@ -70,6 +71,7 @@ static DEFINE_PER_CPU(int, cpu_state); > > static const char *ipi_types[NR_IPI] __tracepoint_string =3D { > > [IPI_RESCHEDULE] =3D "Rescheduling interrupts", > > [IPI_CALL_FUNCTION] =3D "Function call interrupts", > > + [IPI_IRQ_WORK] =3D "IRQ work interrupts", > > }; > > > > void show_ipi_list(struct seq_file *p, int prec) > > @@ -217,6 +219,13 @@ void arch_smp_send_reschedule(int cpu) > > } > > EXPORT_SYMBOL_GPL(arch_smp_send_reschedule); > > > > +#ifdef CONFIG_IRQ_WORK > > +void arch_irq_work_raise(void) > > +{ > > + mp_ops.send_ipi_single(smp_processor_id(), ACTION_IRQ_WORK); > > +} > > +#endif > > + > > static irqreturn_t loongson_ipi_interrupt(int irq, void *dev) > > { > > unsigned int action; > > @@ -234,6 +243,11 @@ static irqreturn_t loongson_ipi_interrupt(int irq,= void *dev) > > per_cpu(irq_stat, cpu).ipi_irqs[IPI_CALL_FUNCTION]++; > > } > > > > + if (action & SMP_IRQ_WORK) { > > + irq_work_run(); > > + per_cpu(irq_stat, cpu).ipi_irqs[IPI_IRQ_WORK]++; > > + } > > + > > return IRQ_HANDLED; > > } > > > > > >