Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp2516416lqo; Tue, 14 May 2024 00:33:03 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVNQjcJg4FFloqOITaGe1yWHBuFqZvYaowSL0DFPV9i0rxZuUX8KXI94rqIMn8ggWbqlkRsKUmTwcV2Q6cQqdR7ah1iYfOSpE+Yu30ASA== X-Google-Smtp-Source: AGHT+IEdDskk0tFSo77gQX3FM3epO7vsHhY9vZepR7GOej0rPjLXefA7WnuY6xP5HaHaHCcHUPB3 X-Received: by 2002:a50:cd42:0:b0:570:5b71:4859 with SMTP id 4fb4d7f45d1cf-5734d704dc8mr7739073a12.41.1715671983263; Tue, 14 May 2024 00:33:03 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715671983; cv=pass; d=google.com; s=arc-20160816; b=VKhiShOAfTwvEOGkeVvomzV7lZq6Ih1Cotz0XNYDH0NxVE4+FDm5OdMYLnq7I9wCNR u5r7H6laXv3iwjtZeNDL5qQyTd3EJYwF3X+93iY1qMJp97CYC4Arjd+y5JUajH1F9bT0 bjT+HeI0H9e00X9/ZCSirdaouGewZxoeAR74QVXpz+c0z+loZLF4dETx43OPagb/hXHf 949+ZNO61b8BpMz/JuHrnZpCbnbR4Hk7ZWEROaUj94rcwmhccrwpHMdmkJjjPJCdrDEY Ds12ncJPYeYfkoqv/QDWmkHx8nU2EgzMqJTFtUsJQFcJjS5AxSqu3yADM+h+eumaza/7 N/Jw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=vOvROm5keX0hU17S+I8QG8r42aKIu0ybluyrQGeEmh4=; fh=YAiB8IhU/xhVSMzxrXyzmIKQXraNA5ZCXdhpkDqJpf8=; b=DTu6ublK3XzDE7npmi+jRgXX0G7sHlIFJuNUxDXQ+QBDkb3yGeaQ45xecbZw5tM/Pj KTjiXMhW0kBeh3DUmexjW5MexITfPL4yKcUZgiraGYOF8u1iPzg+/d7gMOXJBvipf4sn 4r3eSzg+3S0Snb/dhGOQGvR5jG8AVvI9drSwuUrFF0dqUQoKsfpgKauaDeVQt9gpxGmh ht/vWUf/hD+7z4LCXa4U/gd7K7DmJ1C3bgGtVwy/LwEvAXLVWgmZwyaEHeFSJe+bFBPD u9jpwnYrFzKrpVpsuA2UOtOb/a+OfoDc3yygBc1cfohkQrX16igIYQmjVhcdAyD9ZZLZ I0RA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-178401-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-178401-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-5733d36caa6si5794187a12.546.2024.05.14.00.33.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 May 2024 00:33:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-178401-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-178401-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-178401-linux.lists.archive=gmail.com@vger.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 am.mirrors.kernel.org (Postfix) with ESMTPS id CEC2C1F2268D for ; Tue, 14 May 2024 07:33:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B774714F6C; Tue, 14 May 2024 07:32:54 +0000 (UTC) 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 2B5FA12E48; Tue, 14 May 2024 07:32:53 +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=1715671974; cv=none; b=cHVYIRm6UTl6rHLvA6dAwSyNPZFu2i3DeJzhB7HxTNrM17LExxzV7+WWRfeITGwP0i/7E9acIBkLqDimWdEiiH4efSI0XxOXK8zMPIDfdslVJbv4PzTmV7bMSP9Ocm8upc7AlMZnkYGtJsvwxXUKc3W5LjAW1Gz5SJ+pDo7Go2Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715671974; c=relaxed/simple; bh=nEwTX0iq0hxDEaH0PHgIzKUAcr2jYaPliEDdZ2C90bs=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=FUDLz7CloVwHWtTAEWPu6C+DFXwtkKMafQVZQ9Ys7g8T2NxCG+YHRmHa1neD5TdeFejK5EfO9lcrQaSV8TbuXobIe+myjmJl8EQG7Eu4RTZctjBMCjwF4bgMiyd04noXyQ9AvAIjy46paCp6ZKBM9ECl9Uom5zhfsW6zdU8EBbY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 33C89C2BD10; Tue, 14 May 2024 07:32:51 +0000 (UTC) From: Huacai Chen To: Arnd Bergmann , Huacai Chen Cc: 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, Huacai Chen Subject: [PATCH] LoongArch: Add irq_work support via self IPIs Date: Tue, 14 May 2024 15:32:32 +0800 Message-ID: <20240514073232.3694867-1-chenhuacai@loongson.cn> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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/include/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/include/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/paravirt.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 *dev) info->ipi_irqs[IPI_CALL_FUNCTION]++; } + if (action & SMP_IRQ_WORK) { + irq_work_run(); + info->ipi_irqs[IPI_IRQ_WORK]++; + } + 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 = { [IPI_RESCHEDULE] = "Rescheduling interrupts", [IPI_CALL_FUNCTION] = "Function call interrupts", + [IPI_IRQ_WORK] = "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; } -- 2.43.0