linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiang Liu <jiang.liu@linux.intel.com>
To: Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
	"Rafael J. Wysocki" <rjw@rjwysocki.net>,
	Bjorn Helgaas <bhelgaas@google.com>,
	Randy Dunlap <rdunlap@infradead.org>,
	Yinghai Lu <yinghai@kernel.org>, Borislav Petkov <bp@alien8.de>,
	Grant Likely <grant.likely@linaro.org>
Cc: Jiang Liu <jiang.liu@linux.intel.com>,
	Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Tony Luck <tony.luck@intel.com>, Joerg Roedel <joro@8bytes.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	x86@kernel.org, linux-kernel@vger.kernel.org,
	linux-pci@vger.kernel.org, linux-acpi@vger.kernel.org,
	Daniel J Blueman <daniel@numascale.com>
Subject: [RFC v1 27/28] x86, irq: Introduce mechanism to support different vector allocation policies
Date: Fri, 26 Sep 2014 22:57:57 +0800	[thread overview]
Message-ID: <1411743478-31435-28-git-send-email-jiang.liu@linux.intel.com> (raw)
In-Reply-To: <1411743478-31435-1-git-send-email-jiang.liu@linux.intel.com>

Introduce mechanism to support different vector allocation policies,
so platform or user may choose the best suitable CPU vector allocation
policy. Currently two policies are supported:
1) allocate CPU vector from cpumask_of_node(dev_to_node(dev))
2) allocate from apic->target_cpus(), this is the default policy

Platform driver may call set_vector_alloc_policy() to choose the
preferred policies.

This mechanism may be used to support NumaConnect systems to allocate
CPU vectors from device local node.

We may also enhance to support per-cpu vector allocation if it's needed.

Signed-off-by: Jiang Liu <jiang.liu@linux.intel.com>
Cc: Daniel J Blueman <daniel@numascale.com>
---
 arch/x86/include/asm/hw_irq.h |   12 ++++++++
 arch/x86/kernel/apic/vector.c |   66 +++++++++++++++++++++++++++++++++++------
 2 files changed, 69 insertions(+), 9 deletions(-)

diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
index 6c6002e386d4..9e811d9b147b 100644
--- a/arch/x86/include/asm/hw_irq.h
+++ b/arch/x86/include/asm/hw_irq.h
@@ -162,6 +162,17 @@ struct irq_alloc_info {
 	};
 };
 
+enum {
+	/* Allocate vector from cpumask_of_node(dev_to_node(dev)) */
+	X86_VECTOR_POL_NODE = 0x1,
+	/* Allocate vector from apic->target_cpus() */
+	X86_VECTOR_POL_DEFAULT = 0x2,
+	/* Allocate vector from cpumask assigned by caller */
+	X86_VECTOR_POL_CALLER = 0x4,
+	X86_VECTOR_POL_MIN = X86_VECTOR_POL_NODE,
+	X86_VECTOR_POL_MAX = X86_VECTOR_POL_CALLER,
+};
+
 struct irq_cfg {
 	cpumask_var_t		domain;
 	cpumask_var_t		old_domain;
@@ -180,6 +191,7 @@ extern struct irq_cfg *irq_cfg(unsigned int irq);
 extern struct irq_cfg *irqd_cfg(struct irq_data *irq_data);
 extern void lock_vector_lock(void);
 extern void unlock_vector_lock(void);
+extern void set_vector_alloc_policy(unsigned int policy);
 extern void setup_vector_irq(int cpu);
 extern void send_cleanup_vector(struct irq_cfg *);
 extern void irq_complete_move(struct irq_cfg *cfg);
diff --git a/arch/x86/kernel/apic/vector.c b/arch/x86/kernel/apic/vector.c
index 01311ddec2de..4a16e0a5ae0f 100644
--- a/arch/x86/kernel/apic/vector.c
+++ b/arch/x86/kernel/apic/vector.c
@@ -21,6 +21,8 @@
 #include <asm/desc.h>
 #include <asm/irq_remapping.h>
 
+static unsigned int x86_vector_alloc_policy = X86_VECTOR_POL_DEFAULT |
+					      X86_VECTOR_POL_CALLER;
 struct irq_domain *x86_vector_domain;
 static DEFINE_RAW_SPINLOCK(vector_lock);
 static struct irq_chip vector_chip;
@@ -57,6 +59,12 @@ struct irq_cfg *irqd_cfg(struct irq_data *irq_data)
 	return irq_data->chip_data;
 }
 
+void set_vector_alloc_policy(unsigned int policy)
+{
+	if (!WARN_ON((policy & (X86_VECTOR_POL_MAX - 1)) == 0))
+		x86_vector_alloc_policy = policy | X86_VECTOR_POL_CALLER;
+}
+
 static struct irq_cfg *alloc_irq_cfg(int node)
 {
 	struct irq_cfg *cfg;
@@ -245,12 +253,6 @@ void copy_irq_alloc_info(struct irq_alloc_info *dst, struct irq_alloc_info *src)
 		memset(dst, 0, sizeof(*dst));
 }
 
-static inline const struct cpumask *
-irq_alloc_info_get_mask(struct irq_alloc_info *info)
-{
-	return (!info || !info->mask) ? apic->target_cpus() : info->mask;
-}
-
 static void x86_vector_free_irqs(struct irq_domain *domain,
 				 unsigned int virq, unsigned int nr_irqs)
 {
@@ -271,18 +273,64 @@ static void x86_vector_free_irqs(struct irq_domain *domain,
 	}
 }
 
+static int assign_irq_vector_policy(int irq, int node, struct irq_cfg *cfg,
+				    struct irq_alloc_info *info)
+{
+	int err = -EBUSY;
+	unsigned int policy;
+	const struct cpumask *mask;
+
+	if (info && info->mask) {
+		policy = X86_VECTOR_POL_CALLER;
+	} else {
+		policy = X86_VECTOR_POL_MIN;
+	}
+
+	for (; policy <= X86_VECTOR_POL_MAX; policy <<= 1) {
+		if (!(x86_vector_alloc_policy & policy))
+			continue;
+
+		switch (policy) {
+		case X86_VECTOR_POL_NODE:
+			if (node >= 0)
+				mask = cpumask_of_node(node);
+			else
+				mask = NULL;
+			break;
+		case X86_VECTOR_POL_DEFAULT:
+			mask = apic->target_cpus();
+			break;
+		case X86_VECTOR_POL_CALLER:
+			if (info && info->mask)
+				mask = info->mask;
+			else
+				mask = NULL;
+			break;
+		default:
+			mask = NULL;
+			break;
+		}
+		if (mask) {
+			err = assign_irq_vector(irq, cfg, mask);
+			if (!err)
+				return 0;
+		}
+	}
+
+	return err;
+}
+
 static int x86_vector_alloc_irqs(struct irq_domain *domain, unsigned int virq,
 				 unsigned int nr_irqs, void *arg)
 {
 	int i, err;
 	struct irq_cfg *cfg;
 	struct irq_data *irq_data;
-	const struct cpumask *mask;
+	struct irq_alloc_info *info = arg;
 
 	if (disable_apic)
 		return -ENXIO;
 
-	mask = irq_alloc_info_get_mask(arg);
 	for (i = 0; i < nr_irqs; i++) {
 		irq_data = irq_domain_get_irq_data(domain, virq + i);
 		BUG_ON(!irq_data);
@@ -299,7 +347,7 @@ static int x86_vector_alloc_irqs(struct irq_domain *domain, unsigned int virq,
 		irq_data->chip = &vector_chip;
 		irq_data->chip_data = cfg;
 		irq_data->hwirq = virq + i;
-		err = assign_irq_vector(virq, cfg, mask);
+		err = assign_irq_vector_policy(virq, irq_data->node, cfg, info);
 		if (err)
 			goto error;
 	}
-- 
1.7.10.4


  parent reply	other threads:[~2014-09-26 14:57 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-26 14:57 [RFC Part3 v1 00/28] Enable hierarchy irqdomian on x86 platforms Jiang Liu
2014-09-26 14:57 ` [RFC v1 01/28] x86, irq: Kill unused setup_timer_IRQ0_pin() Jiang Liu
2014-10-09  2:16   ` Jiang Liu
2014-09-26 14:57 ` [RFC v1 02/28] x86, irq: Prepare IOAPIC interfaces to support hierarchy irqdomain Jiang Liu
2014-09-26 14:57 ` [RFC v1 03/28] x86, irq: Implement callbacks to enable hierarchy irqdomain on IOAPICs Jiang Liu
2014-09-26 14:57 ` [RFC v1 04/28] x86, irq: Refine the way to allocate irq_cfg for legacy IRQs Jiang Liu
2014-09-26 14:57 ` [RFC v1 05/28] x86, irq: Convert IOAPIC to use hierarchy irqdomain interfaces Jiang Liu
2014-09-26 14:57 ` [RFC v1 06/28] x86, irq: Kill unused old IOAPIC " Jiang Liu
2014-09-26 14:57 ` [RFC v1 07/28] x86, irq: Kill x86_io_apic_ops.print_entries and related interfaces Jiang Liu
2014-09-26 14:57 ` [RFC v1 08/28] x86, irq: Kill x86_io_apic_ops.setup_entry " Jiang Liu
2014-09-26 14:57 ` [RFC v1 09/28] x86, irq: Kill x86_io_apic_ops.set_affinity " Jiang Liu
2014-09-26 14:57 ` [RFC v1 10/28] x86, irq: Kill x86_io_apic_ops.eoi_ioapic_pin " Jiang Liu
2014-09-26 14:57 ` [RFC v1 11/28] x86, irq: Kill GENERIC_IRQ_LEGACY_ALLOC_HWIRQ Jiang Liu
2014-09-26 14:57 ` [RFC v1 12/28] x86: Clean up unused forward declarations in x86_init.h Jiang Liu
2014-09-26 14:57 ` [RFC v1 13/28] x86: irq_remapping: Clean up unsued code Jiang Liu
2014-09-26 14:57 ` [RFC v1 14/28] iommu/vt-d: " Jiang Liu
2014-09-26 14:57 ` [RFC v1 15/28] iommu/amd: " Jiang Liu
2014-09-26 14:57 ` [RFC v1 16/28] x86: irq_remapping: Clean up unused interfaces Jiang Liu
2014-09-26 14:57 ` [RFC v1 17/28] x86, irq: Kill irq_cfg.irq_remapped Jiang Liu
2014-09-26 14:57 ` [RFC v1 18/28] iommu/vt-d: Move struct irq_2_iommu into intel_irq_remapping.c Jiang Liu
2014-09-26 14:57 ` [RFC v1 19/28] iommu/amd: Move struct irq_2_irte into amd_iommu.c Jiang Liu
2014-09-26 14:57 ` [RFC v1 20/28] x86, irq: Move irq_cfg.irq_2_pin into io_apic.c Jiang Liu
2014-09-26 14:57 ` [RFC v1 21/28] x86, irq: Kill struct io_apic_irq_attr Jiang Liu
2014-09-26 14:57 ` [RFC v1 22/28] x86, irq: Kill x86_io_apic_ops.write and x86_io_apic_ops.modify Jiang Liu
2014-09-26 14:57 ` [RFC v1 23/28] x86, irq: Clean up io_apic.h Jiang Liu
2014-09-26 14:57 ` [RFC v1 24/28] x86, irq: Kill unused alloc_irq_and_cfg_at() Jiang Liu
2014-09-26 14:57 ` [RFC v1 25/28] x86, irq: Change functions only used in vector.c as static Jiang Liu
2014-09-26 14:57 ` [RFC v1 26/28] x86, irq: Kill function apic_set_affinity() Jiang Liu
2014-09-26 14:57 ` Jiang Liu [this message]
2014-09-26 14:57 ` [RFC v1 28/28] x86, irq: Add kernel parameter vector_alloc to set CPU vector allocation policy Jiang Liu

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=1411743478-31435-28-git-send-email-jiang.liu@linux.intel.com \
    --to=jiang.liu@linux.intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=benh@kernel.crashing.org \
    --cc=bhelgaas@google.com \
    --cc=bp@alien8.de \
    --cc=daniel@numascale.com \
    --cc=grant.likely@linaro.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=hpa@zytor.com \
    --cc=joro@8bytes.org \
    --cc=konrad.wilk@oracle.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=rdunlap@infradead.org \
    --cc=rjw@rjwysocki.net \
    --cc=tglx@linutronix.de \
    --cc=tony.luck@intel.com \
    --cc=x86@kernel.org \
    --cc=yinghai@kernel.org \
    /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).