xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Wei Liu <wei.liu2@citrix.com>
To: xen-devel@lists.xen.org, konrad.wilk@oracle.com
Cc: Wei Liu <wei.liu2@citrix.com>,
	ian.campbell@citrix.com, jbeulich@suse.com,
	david.vrabel@citrix.com
Subject: [RFC PATCH V5 08/14] xen: dynamically allocate cpu_evtchn_mask
Date: Tue, 19 Mar 2013 15:22:02 +0000	[thread overview]
Message-ID: <1363706528-27141-9-git-send-email-wei.liu2@citrix.com> (raw)
In-Reply-To: <1363706528-27141-1-git-send-email-wei.liu2@citrix.com>

The size of cpu_evtchn_mask can change, use dynamic allocation to cope with
this. To save space, cpu_evtchn_mask is not allocated for offline cpus. It
will get allocated as soon as a cpu goes online.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
 drivers/xen/events.c |   57 ++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 53 insertions(+), 4 deletions(-)

diff --git a/drivers/xen/events.c b/drivers/xen/events.c
index 217efb2..ee35ff9 100644
--- a/drivers/xen/events.c
+++ b/drivers/xen/events.c
@@ -30,6 +30,7 @@
 #include <linux/slab.h>
 #include <linux/irqnr.h>
 #include <linux/pci.h>
+#include <linux/cpu.h>
 
 #ifdef CONFIG_X86
 #include <asm/desc.h>
@@ -156,8 +157,7 @@ static bool (*pirq_needs_eoi)(unsigned irq);
 /* Find the first set bit in a evtchn mask */
 #define EVTCHN_FIRST_BIT(w) find_first_bit(BM(&(w)), BITS_PER_EVTCHN_WORD)
 
-static DEFINE_PER_CPU(xen_ulong_t [NR_EVENT_CHANNELS_L2/BITS_PER_EVTCHN_WORD],
-		      cpu_evtchn_mask);
+static DEFINE_PER_CPU(xen_ulong_t *, cpu_evtchn_mask);
 
 /* Xen will never allocate port zero for any purpose. */
 #define VALID_EVTCHN(chn)	((chn) != 0)
@@ -356,6 +356,9 @@ static void bind_evtchn_to_cpu(unsigned int chn, unsigned int cpu)
 static void init_evtchn_cpu_bindings(void)
 {
 	int i;
+	unsigned int nr = xen_nr_event_channels / BITS_PER_EVTCHN_WORD;
+	unsigned int nr_bytes = nr * sizeof(xen_ulong_t);
+
 #ifdef CONFIG_SMP
 	struct irq_info *info;
 
@@ -366,9 +369,9 @@ static void init_evtchn_cpu_bindings(void)
 	}
 #endif
 
-	for_each_possible_cpu(i)
+	for_each_online_cpu(i)
 		memset(per_cpu(cpu_evtchn_mask, i),
-		       (i == 0) ? ~0 : 0, sizeof(*per_cpu(cpu_evtchn_mask, i)));
+		       (i == 0) ? ~0 : 0, nr_bytes);
 }
 
 static inline void clear_evtchn(int port)
@@ -1867,6 +1870,41 @@ const struct evtchn_ops evtchn_l2_ops = {
 	.do_upcall = __xen_evtchn_do_upcall_l2
 };
 
+static int __cpuinit xen_events_notifier_cb(struct notifier_block *self,
+					    unsigned long action,
+					    void *hcpu)
+{
+	int cpu = (long)hcpu;
+	int rc = NOTIFY_OK;
+	void *p;
+	unsigned int nr = xen_nr_event_channels / BITS_PER_EVTCHN_WORD;
+	unsigned int nr_bytes = nr * sizeof(xen_ulong_t);
+
+	switch (action) {
+	case CPU_UP_PREPARE:
+		if (!per_cpu(cpu_evtchn_mask, cpu)) {
+			p = kzalloc_node(sizeof(xen_ulong_t) * nr,
+					 GFP_KERNEL, cpu_to_node(cpu));
+			if (!p)
+				rc = NOTIFY_BAD;
+			else {
+				per_cpu(cpu_evtchn_mask, cpu) = p;
+				memset(per_cpu(cpu_evtchn_mask, cpu),
+				       (cpu == 0) ? ~0 : 0, nr_bytes);
+				rc = NOTIFY_OK;
+			}
+		}
+		break;
+	default:
+		break;
+	}
+	return rc;
+}
+
+static struct notifier_block xen_events_notifier __cpuinitdata = {
+	.notifier_call = xen_events_notifier_cb,
+};
+
 void __init xen_init_IRQ(void)
 {
 	int i;
@@ -1890,6 +1928,17 @@ void __init xen_init_IRQ(void)
 	for (i = 0; i < xen_nr_event_channels; i++)
 		evtchn_to_irq[i] = -1;
 
+	for_each_online_cpu(cpu) {
+		void *p;
+		unsigned int nr = xen_nr_event_channels / BITS_PER_EVTCHN_WORD;
+
+		p = kzalloc_node(sizeof(xen_ulong_t) * nr,
+				 GFP_KERNEL, cpu_to_node(cpu));
+		BUG_ON(!p);
+		per_cpu(cpu_evtchn_mask, cpu) = p;
+	}
+	register_cpu_notifier(&xen_events_notifier);
+
 	init_evtchn_cpu_bindings();
 
 	/* No event channels are 'live' right now. */
-- 
1.7.10.4

  parent reply	other threads:[~2013-03-19 15:22 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-19 15:21 [RFC PATCH V5] Implement 3-level event channel ABI in Linux Wei Liu
2013-03-19 15:21 ` [RFC PATCH V5 01/14] xen: remove typedef in event_channel.h Wei Liu
2013-03-19 15:21 ` [RFC PATCH V5 02/14] xen: add KERN_DEBUG in printk Wei Liu
2013-03-19 15:21 ` [RFC PATCH V5 03/14] xen: fix output of xen_debug_interrupt Wei Liu
2013-03-19 15:21 ` [RFC PATCH V5 04/14] xen: sync public headers Wei Liu
2013-03-19 15:21 ` [RFC PATCH V5 05/14] xen: introduce test_and_set_mask Wei Liu
2013-03-19 15:22 ` [RFC PATCH V5 06/14] xen: replace raw bit ops with functions Wei Liu
2013-03-19 15:22 ` [RFC PATCH V5 07/14] xen: generalized event channel operations Wei Liu
2013-03-19 15:22 ` Wei Liu [this message]
2013-03-19 15:22 ` [RFC PATCH V5 09/14] xen: implement 3-level event channel routines Wei Liu
2013-03-19 15:22 ` [RFC PATCH V5 10/14] xen: document 2/3-level event channel ABI Wei Liu
2013-03-19 15:22 ` [RFC PATCH V5 11/14] xen: introduce xen_event_channel_query_extended_abis Wei Liu
2013-03-19 15:22 ` [RFC PATCH V5 12/14] xen: introduce xen_event_channel_register_3level Wei Liu
2013-03-19 15:22 ` [RFC PATCH V5 13/14] xen: introduce xen_event_channel_register_extended Wei Liu
2013-03-19 15:22 ` [RFC PATCH V5 14/14] xen: register 3-level event channel Wei 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=1363706528-27141-9-git-send-email-wei.liu2@citrix.com \
    --to=wei.liu2@citrix.com \
    --cc=david.vrabel@citrix.com \
    --cc=ian.campbell@citrix.com \
    --cc=jbeulich@suse.com \
    --cc=konrad.wilk@oracle.com \
    --cc=xen-devel@lists.xen.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).