From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 779031A9FB4 for ; Sat, 20 Dec 2025 19:31:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766259088; cv=none; b=Ig/2IsJ9/PnSTQHJVvL6c/omC+QFxCt/Rc+RxTs9E9W/+56wHYM4PuqejE09fOYxvWIUXQDfXD9qoI631qJpnZtU8cuy4F6kewE4hPiEEwHXtUoy788oeGY0aPxY+szc0Q69TzDyOMYHe3pFQRa+tcp6N+wq8M39wupRVrDIK8c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766259088; c=relaxed/simple; bh=p6MFlAs0UQlRzI5yXf/k/PuPTWQdR0NoR+TlQAjqCG0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=gKYYkm4ssJow+wgdftpQ04xLNHZ7eZv66UeRHvmD0UKrfNk+wiILqInW04B6pKzD+HlpviluPahdFzoSUG8mMe3wZ6W94g3DxdfpCvNn3M1fz1C562XEDUZOqF5OcScbRMsrZMnw7Q+Cvt++MV2kXtDsd+89F3xAwTZjsSx1WYc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--lrizzo.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=F2uA18XE; arc=none smtp.client-ip=209.85.128.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--lrizzo.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="F2uA18XE" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-477a1e2b372so20964455e9.2 for ; Sat, 20 Dec 2025 11:31:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1766259085; x=1766863885; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=7Ey6NUQ0ozTVkQWERD6kN0/9KQQkhLLotsXWKnL2aJA=; b=F2uA18XE62PGHdV/WLm+ew5hq5FU00g8xRu5zvMXpukWWuKaLeWx3NaLLKQ0x3n4bg wgAc3i2XGBZzek5m2bWBHjHXd8iLqjc2tbANiQAxu9a2+H0yq6A3WkBcBnRJOfoSDenu PwTU9fgXfCCXDr7Lm+6sA1bUxVx+SQNvHLfoyTLwpF4JrQkmQx5G4a6+1eI930J8C8Kg mJZKw2r0BqrIuUNdKI5ZnK5jFZBvxx+pP7WPrHnP9BdaO57ypbmveXJWO4Y9RkXbu9x3 zsrxcqehYPvVHcKNyYhJiP9t8oJuGXkJyR/1Jiktxa1pz3DHJqIFeG4rs4AQJc9VjhtG 8VdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766259085; x=1766863885; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=7Ey6NUQ0ozTVkQWERD6kN0/9KQQkhLLotsXWKnL2aJA=; b=jD6Iunkxr1ugLomOUCfYjC1pw1725UQz7I6JPC0UL8vZW+3D9bD6VuF/9lhZ4oU+Vy p0es87QTurdnUzf7oG/+U5JZ5lVsqNQRDkgt5z3JEKH2nn6uOzO5t/OYcGAx6LbJbOHX jSKgOL/Nb+JIoJzr4cRYQjBekiSQEOX19+ZfgAerFnkKofCmToEUCI8F4miF2dHDcB2a PZCvXqgq3faPP5kF2EaHVcDazjGwRFVtYBTJnAcIjzTdOpCn+rcAkfOQrnNss5ci/dVi dcyWud0KB6iy/gVh9akZrwpLggXeZvSvdQ9XUtESoQQeB09a1bsG4tcZqggRwhZiJI8h yRHA== X-Forwarded-Encrypted: i=1; AJvYcCWeLp7HOvPmpKP4tpF+kMv/iUJ/dbUpc85l4vdTpgc1C6xiRs7dNe2UQUvqRjE686XAFDjipRuK4VI9Lgw=@vger.kernel.org X-Gm-Message-State: AOJu0YzMaA9ZkZ6W46DnGdOwNzEAVVMHIyBw+MNQL6Vpeckc/t2wSXzW VLjwK3SL2kg2rzvBCDzXIs4GfuMJ0yPHN0M1tu4sV0tfyS0cTRhE9qZeQpGx7nXjV+Z5x6TanFJ jFXoxSA== X-Google-Smtp-Source: AGHT+IE2HhMF6Uq2hmopL9JBMcoxqbro95wis+5+KMD7fLivLSbrrYsQHq1ArnFbGxMH60kj265zffi05y8= X-Received: from wmqo14.prod.google.com ([2002:a05:600c:4fce:b0:477:76c6:3a81]) (user=lrizzo job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:198d:b0:46e:35a0:3587 with SMTP id 5b1f17b1804b1-47d195a06a0mr61912145e9.27.1766259084822; Sat, 20 Dec 2025 11:31:24 -0800 (PST) Date: Sat, 20 Dec 2025 19:31:19 +0000 In-Reply-To: <20250903135433.380783272@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250903135433.380783272@linutronix.de> X-Mailer: git-send-email 2.52.0.322.g1dd061c0dc-goog Message-ID: <20251220193120.3339162-1-lrizzo@google.com> Subject: Re: [patch 1/2] irqchip/msi-lib: Honor the MSI_FLAG_PCI_MSI_MASK_PARENT flag From: Luigi Rizzo To: tglx@linutronix.de Cc: bhelgaas@google.com, linux-kernel@vger.kernel.org, maz@kernel.org, Luigi Rizzo Content-Type: text/plain; charset="UTF-8" There are platforms (including some ARM SoC) where the MSIx writes are a performance killer, because they are exceedingly serializing on the PCIe root port. These platforms are the key motivation for Global Software Interrupt Moderation (GSIM) which relies on actually masking device interrupts so the MSIx writes are not generated. https://lore.kernel.org/all/20251217112128.1401896-1-lrizzo@google.com/ Overriding mask/unmask with irq_chip_mask_parent() makes software moderation ineffective. GSIM works great on ARM platforms before this patch, but becomes ineffective afterwards, e.g. on linux 6.18. The round trip through the PCI endpoint for mask_irq(), caused by the readback to make sure the PCI write has been sent, is almost always (or really always) unnecessary. Masking is inherently racy; waiting that the PCIe write has arrived at the device won't guarantee that an interrupt has arrived in the meantime, so there is really no benefit in the readback (which, for instance, can be conditionally removed with code like the one below). I measured the cost of pci_irq_mask_msix() and it goes from 1000-1500ns with the readl(), down to 40-50ns without it. Once we remove the costly readback, is there any remaining reason to overwrite [un]mask_irq() with irq_chip_[un]mask_parent() ? cheers luigi --- a/drivers/pci/msi/msi.c +++ b/drivers/pci/msi/msi.c @@ -17,6 +17,8 @@ int pci_msi_enable = 1; +DEFINE_PER_CPU(bool, pci_msix_fast_mask); + /** * pci_msi_supported - check whether MSI may be enabled on a device * @dev: pointer to the pci_dev data structure of MSI device function --- a/drivers/pci/msi/msi.h +++ b/drivers/pci/msi/msi.h @@ -40,10 +40,14 @@ static inline void pci_msix_write_vector_ctrl(struct msi_desc *desc, u32 ctrl) writel(ctrl, desc_addr + PCI_MSIX_ENTRY_VECTOR_CTRL); } +DECLARE_PER_CPU(bool, pci_msix_fast_mask); static inline void pci_msix_mask(struct msi_desc *desc) { desc->pci.msix_ctrl |= PCI_MSIX_ENTRY_CTRL_MASKBIT; pci_msix_write_vector_ctrl(desc, desc->pci.msix_ctrl); + /* There are only a few cases when we really need the read back. */ + if (__this_cpu_read(pci_msix_fast_mask)) + return; /* Flush write to device */ readl(desc->pci.mask_base); } --- a/kernel/irq/chip.c +++ b/kernel/irq/chip.c @@ -420,13 +420,20 @@ static inline void mask_ack_irq(struct irq_desc *desc) } } +/* defined in driver/pci/msi/msi.c */ +DECLARE_PER_CPU(bool, pci_msix_fast_mask); + void mask_irq(struct irq_desc *desc) { if (irqd_irq_masked(&desc->irq_data)) return; if (desc->irq_data.chip->irq_mask) { + if (IS_ENABLED(CONFIG_PCI_MSI)) + __this_cpu_write(pci_msix_fast_mask, irqd_has_set(&desc->irq_data, IRQD_IRQ_MODERATED)); desc->irq_data.chip->irq_mask(&desc->irq_data); + if (IS_ENABLED(CONFIG_PCI_MSI)) + __this_cpu_write(pci_msix_fast_mask, false); irq_state_set_masked(desc); } }