From patchwork Wed Jun 17 09:37:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 11609497 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 69BCD90 for ; Wed, 17 Jun 2020 09:37:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5059B208B3 for ; Wed, 17 Jun 2020 09:37:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="OPihNtag" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726761AbgFQJhq (ORCPT ); Wed, 17 Jun 2020 05:37:46 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:25209 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725773AbgFQJhq (ORCPT ); Wed, 17 Jun 2020 05:37:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592386664; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GALKjCyCx4yfJN/JVX3IxioyMG3hz4NRjecTTDpBoNE=; b=OPihNtagGpj2t0uwTpegTK3VDpr+CmFKEKijlAZgZcYloiKnRJeoAV8W8ZCDRromJkKZBL ep6q4OnbStIopSauAINmxEKeC5XyT9uv1hqThM8c/05jUM/wRW9yfrCYdoq4xFh7ogFBps VGV628V8JKDsSgZ1OGicEK8WI0WaKDY= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-431-k6oO2ez3NvGoZWDkW1VHGw-1; Wed, 17 Jun 2020 05:37:43 -0400 X-MC-Unique: k6oO2ez3NvGoZWDkW1VHGw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D6D41876EE2; Wed, 17 Jun 2020 09:37:41 +0000 (UTC) Received: from localhost (ovpn-114-151.ams2.redhat.com [10.36.114.151]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7731478EE1; Wed, 17 Jun 2020 09:37:34 +0000 (UTC) From: Stefan Hajnoczi To: linux-kernel@vger.kernel.org Cc: Marcelo Tosatti , linux-pci@vger.kernel.org, Thomas Gleixner , Bjorn Helgaas , "Michael S. Tsirkin" , Stefan Hajnoczi Subject: [RFC 1/2] genirq: honor device NUMA node when allocating descs Date: Wed, 17 Jun 2020 10:37:24 +0100 Message-Id: <20200617093725.1725569-2-stefanha@redhat.com> In-Reply-To: <20200617093725.1725569-1-stefanha@redhat.com> References: <20200617093725.1725569-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Use the device's NUMA node instead of the first masked CPUs node when descs are allocated. The mask may include all CPUs and therefore not correspond to the home NUMA node of the device. Signed-off-by: Stefan Hajnoczi --- kernel/irq/irqdesc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/irq/irqdesc.c b/kernel/irq/irqdesc.c index 1a7723604399..b9c4160d72c4 100644 --- a/kernel/irq/irqdesc.c +++ b/kernel/irq/irqdesc.c @@ -488,7 +488,8 @@ static int alloc_descs(unsigned int start, unsigned int cnt, int node, IRQD_MANAGED_SHUTDOWN; } mask = &affinity->mask; - node = cpu_to_node(cpumask_first(mask)); + if (node == NUMA_NO_NODE) + node = cpu_to_node(cpumask_first(mask)); affinity++; } From patchwork Wed Jun 17 09:37:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 11609499 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 418DD90 for ; Wed, 17 Jun 2020 09:37:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 23FEC208B3 for ; Wed, 17 Jun 2020 09:37:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="SuR/U9qP" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725964AbgFQJhv (ORCPT ); Wed, 17 Jun 2020 05:37:51 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:30781 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726798AbgFQJhu (ORCPT ); Wed, 17 Jun 2020 05:37:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592386668; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7MAdMlImgumCZT3LfGm29F+L+iTUaSnuaS5P4ZPaAz4=; b=SuR/U9qPNrwF5QSDM5jfQe+nDE7W+QCFlpvAsqR1FJHdia/AhR/hx/KWWNlyhODi/AUwOs /PSUwd6xeQEMKgNN5Dovm+rEbNpNosy5jxOVriby5wg5VK7yAQH6I5ZFGQqtMFzxb/sgix Fbkjh8GJqtP1gRnse/frykS2v04pJe8= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-481-oikxqi3UO3CV5AoofoRoFg-1; Wed, 17 Jun 2020 05:37:45 -0400 X-MC-Unique: oikxqi3UO3CV5AoofoRoFg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E3D6480B71D; Wed, 17 Jun 2020 09:37:43 +0000 (UTC) Received: from localhost (ovpn-114-151.ams2.redhat.com [10.36.114.151]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7BA5D5C1D2; Wed, 17 Jun 2020 09:37:43 +0000 (UTC) From: Stefan Hajnoczi To: linux-kernel@vger.kernel.org Cc: Marcelo Tosatti , linux-pci@vger.kernel.org, Thomas Gleixner , Bjorn Helgaas , "Michael S. Tsirkin" , Stefan Hajnoczi Subject: [RFC 2/2] genirq/matrix: take NUMA into account for managed IRQs Date: Wed, 17 Jun 2020 10:37:25 +0100 Message-Id: <20200617093725.1725569-3-stefanha@redhat.com> In-Reply-To: <20200617093725.1725569-1-stefanha@redhat.com> References: <20200617093725.1725569-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Select CPUs from the IRQ's NUMA node in preference over other CPUs. This ensures that managed IRQs are assigned to the same NUMA node as the device. Signed-off-by: Stefan Hajnoczi --- include/linux/irq.h | 2 +- arch/x86/kernel/apic/vector.c | 3 ++- kernel/irq/matrix.c | 16 ++++++++++++---- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/include/linux/irq.h b/include/linux/irq.h index 8d5bc2c237d7..bdc3faa3c280 100644 --- a/include/linux/irq.h +++ b/include/linux/irq.h @@ -1202,7 +1202,7 @@ void irq_matrix_assign_system(struct irq_matrix *m, unsigned int bit, bool repla int irq_matrix_reserve_managed(struct irq_matrix *m, const struct cpumask *msk); void irq_matrix_remove_managed(struct irq_matrix *m, const struct cpumask *msk); int irq_matrix_alloc_managed(struct irq_matrix *m, const struct cpumask *msk, - unsigned int *mapped_cpu); + int node, unsigned int *mapped_cpu); void irq_matrix_reserve(struct irq_matrix *m); void irq_matrix_remove_reserved(struct irq_matrix *m); int irq_matrix_alloc(struct irq_matrix *m, const struct cpumask *msk, diff --git a/arch/x86/kernel/apic/vector.c b/arch/x86/kernel/apic/vector.c index 67768e54438b..8eb10b0d981d 100644 --- a/arch/x86/kernel/apic/vector.c +++ b/arch/x86/kernel/apic/vector.c @@ -309,6 +309,7 @@ assign_managed_vector(struct irq_data *irqd, const struct cpumask *dest) { const struct cpumask *affmsk = irq_data_get_affinity_mask(irqd); struct apic_chip_data *apicd = apic_chip_data(irqd); + int node = irq_data_get_node(irqd); int vector, cpu; cpumask_and(vector_searchmask, dest, affmsk); @@ -317,7 +318,7 @@ assign_managed_vector(struct irq_data *irqd, const struct cpumask *dest) if (apicd->vector && cpumask_test_cpu(apicd->cpu, vector_searchmask)) return 0; vector = irq_matrix_alloc_managed(vector_matrix, vector_searchmask, - &cpu); + node, &cpu); trace_vector_alloc_managed(irqd->irq, vector, vector); if (vector < 0) return vector; diff --git a/kernel/irq/matrix.c b/kernel/irq/matrix.c index 30cc217b8631..ee35b6172b64 100644 --- a/kernel/irq/matrix.c +++ b/kernel/irq/matrix.c @@ -148,7 +148,8 @@ static unsigned int matrix_find_best_cpu(struct irq_matrix *m, /* Find the best CPU which has the lowest number of managed IRQs allocated */ static unsigned int matrix_find_best_cpu_managed(struct irq_matrix *m, - const struct cpumask *msk) + const struct cpumask *msk, + int node) { unsigned int cpu, best_cpu, allocated = UINT_MAX; struct cpumap *cm; @@ -156,6 +157,9 @@ static unsigned int matrix_find_best_cpu_managed(struct irq_matrix *m, best_cpu = UINT_MAX; for_each_cpu(cpu, msk) { + if (node != NUMA_NO_NODE && cpu_to_node(cpu) != node) + continue; + cm = per_cpu_ptr(m->maps, cpu); if (!cm->online || cm->managed_allocated > allocated) @@ -280,10 +284,12 @@ void irq_matrix_remove_managed(struct irq_matrix *m, const struct cpumask *msk) /** * irq_matrix_alloc_managed - Allocate a managed interrupt in a CPU map * @m: Matrix pointer - * @cpu: On which CPU the interrupt should be allocated + * @mask: The mask of CPUs on which the interrupt can be allocated + * @node: The preferred NUMA node + * @mapped_cpu: The resulting CPU on which the interrupt should be allocated */ int irq_matrix_alloc_managed(struct irq_matrix *m, const struct cpumask *msk, - unsigned int *mapped_cpu) + int node, unsigned int *mapped_cpu) { unsigned int bit, cpu, end = m->alloc_end; struct cpumap *cm; @@ -291,7 +297,9 @@ int irq_matrix_alloc_managed(struct irq_matrix *m, const struct cpumask *msk, if (cpumask_empty(msk)) return -EINVAL; - cpu = matrix_find_best_cpu_managed(m, msk); + cpu = matrix_find_best_cpu_managed(m, msk, node); + if (cpu == UINT_MAX) + cpu = matrix_find_best_cpu_managed(m, msk, NUMA_NO_NODE); if (cpu == UINT_MAX) return -ENOSPC;