Xen: rework NR_EVENT_CHANNELS related stuffs.
Subsystems (3)
RFC PATCH 2/3 Xen: rework NR_EVENT_CHANNELS related stuffs.
Signed-off-by Wei Liu <[email protected]>
--- drivers/xen/events.c | 44 +++++++++++++++++++++++++++++-------------- drivers/xen/evtchn.c | 16 +++++++++------- include/xen/events.h | 3 +++ include/xen/interface/xen.h | 17 ++++++++++++++++- 4 files changed, 58 insertions(+), 22 deletions(-)
drivers/xen/events.c +30 -14
@@ -52,7 +52,8 @@#include <xen/interface/hvm/params.h> /* N-level event channel, starting from 2 */ -static unsigned int evtchn_level =2 ; +unsigned int evtchn_level =2 ; +EXPORT_SYMBOL_GPL (evtchn_level);struct evtchn_ops { unsigned long (*active_evtchns)(unsigned int,
@@ -130,8 +131,7 @@ static int *evtchn_to_irq;static unsigned long *pirq_eoi_map;static bool (*pirq_needs_eoi)(unsigned irq); -static DEFINE_PER_CPU(unsigned long [NR_EVENT_CHANNELS/BITS_PER_LONG], - cpu_evtchn_mask); +static DEFINE_PER_CPU(unsigned long *, cpu_evtchn_mask);/* Xen will never allocate port zero for any purpose. */ #define VALID_EVTCHN (chn) ((chn) != 0)
@@ -913,7 +913,7 @@ static int find_virq(unsigned int virq, unsigned int cpu)int port, rc = -ENOENT ;memset (&status,0 ,sizeof (status)); -for (port =0 ; port <=NR_EVENT_CHANNELS ; port++) { +for (port =0 ; port <=NR_EVENT_CHANNELS (evtchn_level); port++) { status.dom =DOMID_SELF ; status.port = port; rc =HYPERVISOR_event_channel_op (EVTCHNOP_status, &status);
@@ -1138,7 +1138,7 @@ int evtchn_get(unsigned int evtchn)struct irq_info *info;int err = -ENOENT ; -if (evtchn >=NR_EVENT_CHANNELS ) +if (evtchn >=NR_EVENT_CHANNELS (evtchn_level))return -EINVAL ;mutex_lock (&irq_mapping_update_lock);
@@ -1227,7 +1227,7 @@ static irqreturn_t __xen_debug_interrupt_l2(int irq, void *dev_id) i % 8 == 0 ? "\n " : " ");printk ("\nlocal cpu%d mask:\n " , cpu); -for (i = (NR_EVENT_CHANNELS /BITS_PER_LONG )-1 ; i >=0 ; i--) +for (i = (NR_EVENT_CHANNELS (evtchn_level)/BITS_PER_LONG )-1 ; i >=0 ; i--)printk ("%0*lx%s" , (int )(sizeof (cpu_evtchn[0 ])*2 ), cpu_evtchn[i], i %8 ==0 ?"\n " :" " );
@@ -1242,7 +1242,7 @@ static irqreturn_t __xen_debug_interrupt_l2(int irq, void *dev_id) }printk ("\npending list:\n" ); -for (i =0 ; i <NR_EVENT_CHANNELS ; i++) { +for (i =0 ; i <NR_EVENT_CHANNELS (evtchn_level); i++) {if (sync_test_bit (i, sh->evtchn_pending)) {int word_idx = i /BITS_PER_LONG ; printk(" %d: event %d -> irq %d%s%s%s\n",
@@ -1709,14 +1709,14 @@ void xen_irq_resume(void)init_evtchn_cpu_bindings ();/* New event-channel space is not 'live' yet. */ -for (evtchn =0 ; evtchn <NR_EVENT_CHANNELS ; evtchn++) +for (evtchn =0 ; evtchn <NR_EVENT_CHANNELS (evtchn_level); evtchn++) eops->mask_evtchn (evtchn);/* No IRQ <-> event-channel mappings. */ list_for_each_entry (info, &xen_irq_list_head, list) info->evtchn =0 ;/* zap event-channel binding */ -for (evtchn =0 ; evtchn <NR_EVENT_CHANNELS ; evtchn++) +for (evtchn =0 ; evtchn <NR_EVENT_CHANNELS (evtchn_level); evtchn++) evtchn_to_irq[evtchn] =-1 ;for_each_possible_cpu (cpu) {
@@ -1824,21 +1824,37 @@ static struct evtchn_ops evtchn_ops_l2 __read_mostly = {void __init xen_init_IRQ (void ) {int i, rc; +int cpu; - evtchn_level =2 ; +/* Setup 2-level event channel */ eops = &evtchn_ops_l2; + evtchn_level =2 ; -/* Setup 2-level event channel */ - evtchn_to_irq =kcalloc (NR_EVENT_CHANNELS ,sizeof (*evtchn_to_irq), + evtchn_to_irq =kcalloc (NR_EVENT_CHANNELS (evtchn_level), +sizeof (*evtchn_to_irq),GFP_KERNEL );BUG_ON (!evtchn_to_irq); -for (i =0 ; i <NR_EVENT_CHANNELS ; i++) + +for_each_possible_cpu (cpu) { +void *p; +unsigned int nr =NR_EVENT_CHANNELS (evtchn_level)/BITS_PER_LONG ; + p =kzalloc_node (sizeof (unsigned long ) * nr, +GFP_KERNEL , +cpu_to_node (cpu)); +if (!p) + p =kzalloc (sizeof (unsigned long ) * nr, +GFP_KERNEL ); +BUG_ON (!p); +per_cpu (cpu_evtchn_mask, cpu) = p; + } + +for (i =0 ; i <NR_EVENT_CHANNELS (evtchn_level); i++) evtchn_to_irq[i] =-1 ;init_evtchn_cpu_bindings ();/* No event channels are 'live' right now. */ -for (i =0 ; i <NR_EVENT_CHANNELS ; i++) +for (i =0 ; i <NR_EVENT_CHANNELS (evtchn_level); i++) eops->mask_evtchn (i); pirq_needs_eoi = pirq_needs_eoi_flag;
drivers/xen/evtchn.c +9 -7
@@ -232,7 +232,7 @@ static ssize_t evtchn_write(struct file *file, const char __user *buf,for (i =0 ; i < (count/sizeof (evtchn_port_t)); i++) {unsigned port = kbuf[i]; -if (port <NR_EVENT_CHANNELS && +if (port <NR_EVENT_CHANNELS (evtchn_level) &&get_port_user (port) == u && !get_port_enabled (port)) {set_port_enabled (port, true);
@@ -364,7 +364,7 @@ static long evtchn_ioctl(struct file *file,break ; rc = -EINVAL ; -if (unbind.port >=NR_EVENT_CHANNELS ) +if (unbind.port >=NR_EVENT_CHANNELS (evtchn_level))break ;spin_lock_irq (&port_user_lock);
@@ -392,7 +392,7 @@ static long evtchn_ioctl(struct file *file,if (copy_from_user (¬ify, uarg,sizeof (notify)))break ; -if (notify.port >=NR_EVENT_CHANNELS ) { +if (notify.port >=NR_EVENT_CHANNELS (evtchn_level)) { rc = -EINVAL ; }else if (get_port_user (notify.port) != u) { rc = -ENOTCONN ;
@@ -482,7 +482,7 @@ static int evtchn_release(struct inode *inode, struct file *filp)free_page ((unsigned long )u->ring); -for (i =0 ; i <NR_EVENT_CHANNELS ; i++) { +for (i =0 ; i <NR_EVENT_CHANNELS (evtchn_level); i++) {if (get_port_user (i) != u)continue ;
@@ -491,7 +491,7 @@ static int evtchn_release(struct inode *inode, struct file *filp)spin_unlock_irq (&port_user_lock); -for (i =0 ; i <NR_EVENT_CHANNELS ; i++) { +for (i =0 ; i <NR_EVENT_CHANNELS (evtchn_level); i++) {if (get_port_user (i) != u)continue ;
@@ -528,7 +528,8 @@ static int __init evtchn_init(void)if (!xen_domain ())return -ENODEV ; - port_user =kcalloc (NR_EVENT_CHANNELS ,sizeof (*port_user),GFP_KERNEL ); + port_user =kcalloc (NR_EVENT_CHANNELS (evtchn_level), +sizeof (*port_user),GFP_KERNEL );if (port_user ==NULL )return -ENOMEM ;
@@ -541,7 +542,8 @@ static int __init evtchn_init(void)return err; } -printk (KERN_INFO "Event-channel device installed.\n" ); +printk (KERN_INFO "Event-channel device installed." +" Event-channel level: %d\n" , evtchn_level);return 0 ; }
include/xen/events.h +3 -0
@@ -109,4 +109,7 @@ int xen_irq_from_gsi(unsigned gsi);/* Determine whether to ignore this IRQ if it is passed to a guest. */ int xen_test_irq_shared (int irq); +/* N-level event channels */ +extern unsigned int evtchn_level; +#endif /* _XEN_EVENTS_H */
include/xen/interface/xen.h +16 -1
@@ -283,9 +283,24 @@ DEFINE_GUEST_HANDLE_STRUCT(multicall_entry);/* * Event channel endpoints per domain: +* 2-level: * 1024 if a long is 32 bits; 4096 if a long is 64 bits. +* 3-level: +* 32k if a long is 32 bits; 256k if a long is 64 bits. */ -#define NR_EVENT_CHANNELS (sizeof(unsigned long) * sizeof(unsigned long) * 64) +#define NR_EVENT_CHANNELS_L2 (sizeof(unsigned long) * sizeof(unsigned long) * 64) +#define NR_EVENT_CHANNELS_L3 (NR_EVENT_CHANNELS_L2 * sizeof(unsigned long)) +#define NR_EVENT_CHANNELS (x) ({ unsigned int __v = 0; \ + switch (x) { \ + case 2: \ + __v = NR_EVENT_CHANNELS_L2; break; \ + case 3: \ + __v = NR_EVENT_CHANNELS_L3; break; \ + default: \ + BUG(); \ + } \ + __v; }) +struct vcpu_time_info {/*
Signature · 1 line
1.7.10.4
RFC PATCH 3/3 Xen: implement 3-level event channel routines.
Signed-off-by Wei Liu <[email protected]>
--- arch/x86/xen/enlighten.c | 7 + drivers/xen/events.c | 419 +++++++++++++++++++++++++++++++-- include/xen/events.h | 2 + include/xen/interface/event_channel.h | 24 ++ include/xen/interface/xen.h | 2 +- 5 files changed, 437 insertions(+), 17 deletions(-)
arch/x86/xen/enlighten.c +7 -0
@@ -43,6 +43,7 @@#include <xen/hvm.h> #include <xen/hvc-console.h> #include <xen/acpi.h> +#include <xen/events.h> #include <asm/paravirt.h> #include <asm/apic.h>
@@ -195,6 +196,9 @@ void xen_vcpu_restore(void) HYPERVISOR_vcpu_op(VCPUOP_up, cpu, NULL))BUG (); } + +if (evtchn_level_param ==3 ) +xen_event_channel_setup_3level (); }static void __init xen_banner (void )
@@ -1028,6 +1032,9 @@ void xen_setup_vcpu_info_placement(void)for_each_possible_cpu (cpu)xen_vcpu_setup (cpu); +if (evtchn_level_param ==3 ) +xen_event_channel_setup_3level (); +/* xen_vcpu_setup managed to place the vcpu_info within the percpu area for all cpus, so make use of it */ if (have_vcpu_info_placement) {
drivers/xen/events.c +403 -16
548 lines not on this page · raw message
include/xen/events.h +2 -0
@@ -111,5 +111,7 @@ int xen_test_irq_shared(int irq);/* N-level event channels */ extern unsigned int evtchn_level; +extern unsigned int evtchn_level_param; +int xen_event_channel_setup_3level (void );#endif /* _XEN_EVENTS_H */
include/xen/interface/event_channel.h +24 -0
@@ -190,6 +190,30 @@ struct evtchn_reset { };typedef struct evtchn_reset evtchn_reset_t ; +/* +* EVTCHNOP_register_nlevel: Register N level event channels. +* NOTES: +* 1. currently only 3-level is supported. +* 2. should fall back to basic 2-level if this call fails. +*/ +#define EVTCHNOP_register_nlevel 11 +#define MAX_L3_PAGES 8/* 8 pages for 64 bits */ +struct evtchn_register_3level { +unsigned long evtchn_pending[MAX_L3_PAGES ]; +unsigned long evtchn_mask[MAX_L3_PAGES ]; +unsigned long *l2sel_mfn; +unsigned long *l2sel_offset; +unsigned int nr_vcpus; +}; + +struct evtchn_register_nlevel { +uint32_t level; +union { +struct evtchn_register_3level l3; + } u; +}; +typedef struct evtchn_register_nlevel evtchn_register_nlevel_t ; +struct evtchn_op {uint32_t cmd;/* EVTCHNOP_* */ union {
include/xen/interface/xen.h +1 -1
@@ -289,7 +289,7 @@ DEFINE_GUEST_HANDLE_STRUCT(multicall_entry);* 32k if a long is 32 bits; 256k if a long is 64 bits. */ #define NR_EVENT_CHANNELS_L2 (sizeof(unsigned long) * sizeof(unsigned long) * 64) -#define NR_EVENT_CHANNELS_L3 (NR_EVENT_CHANNELS_L2 * sizeof(unsigned long)) +#define NR_EVENT_CHANNELS_L3 (NR_EVENT_CHANNELS_L2 * 64)#define NR_EVENT_CHANNELS (x) ({ unsigned int __v = 0; \ switch (x) { \ case 2: \
Signature · 1 line
1.7.10.4