All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] irq routing userspace
@ 2009-01-14 13:53 Avi Kivity
  2009-01-14 13:53 ` [PATCH 1/2] kvm: libkvm: support for irq routing Avi Kivity
  2009-01-14 13:53 ` [PATCH 2/2] kvm: qemu: initialize irq routing table Avi Kivity
  0 siblings, 2 replies; 9+ messages in thread
From: Avi Kivity @ 2009-01-14 13:53 UTC (permalink / raw)
  To: Sheng Yang; +Cc: kvm

Following is the userspace support for irq routing.  It is also available
(along with a slightly fixed kernel patch) in the irq-routing-2 branch
on kernel.org.

Avi Kivity (2):
  kvm: libkvm: support for irq routing
  kvm: qemu: initialize irq routing table

 libkvm/kvm-common.h |    4 ++
 libkvm/libkvm.c     |  107 +++++++++++++++++++++++++++++++++++++++++++++++++++
 libkvm/libkvm.h     |   62 +++++++++++++++++++++++++++++
 qemu/qemu-kvm.c     |   24 +++++++++++
 4 files changed, 197 insertions(+), 0 deletions(-)


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/2] kvm: libkvm: support for irq routing
  2009-01-14 13:53 [PATCH 0/2] irq routing userspace Avi Kivity
@ 2009-01-14 13:53 ` Avi Kivity
  2009-01-15  6:17   ` Sheng Yang
  2009-01-14 13:53 ` [PATCH 2/2] kvm: qemu: initialize irq routing table Avi Kivity
  1 sibling, 1 reply; 9+ messages in thread
From: Avi Kivity @ 2009-01-14 13:53 UTC (permalink / raw)
  To: Sheng Yang; +Cc: kvm

Signed-off-by: Avi Kivity <avi@redhat.com>
---
 libkvm/kvm-common.h |    4 ++
 libkvm/libkvm.c     |  107 +++++++++++++++++++++++++++++++++++++++++++++++++++
 libkvm/libkvm.h     |   62 +++++++++++++++++++++++++++++
 3 files changed, 173 insertions(+), 0 deletions(-)

diff --git a/libkvm/kvm-common.h b/libkvm/kvm-common.h
index c5beacc..e09c07c 100644
--- a/libkvm/kvm-common.h
+++ b/libkvm/kvm-common.h
@@ -61,6 +61,10 @@ struct kvm_context {
 	int pit_in_kernel;
 	/// in-kernel coalesced mmio
 	int coalesced_mmio;
+#ifdef KVM_CAP_IRQ_ROUTING
+	struct kvm_irq_routing *irq_routes;
+	int nr_allocated_irq_routes;
+#endif
 };
 
 void init_slots(void);
diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c
index 0408fdb..1004fa6 100644
--- a/libkvm/libkvm.c
+++ b/libkvm/libkvm.c
@@ -381,6 +381,14 @@ int kvm_create_vm(kvm_context_t kvm)
 {
 	int fd = kvm->fd;
 
+#ifdef KVM_CAP_IRQ_ROUTING
+	kvm->irq_routes = malloc(sizeof(*kvm->irq_routes));
+	if (!kvm->irq_routes)
+		return -ENOMEM;
+	memset(kvm->irq_routes, 0, sizeof(*kvm->irq_routes));
+	kvm->nr_allocated_irq_routes = 0;
+#endif
+
 	kvm->vcpu_fd[0] = -1;
 
 	fd = ioctl(fd, KVM_CREATE_VM, 0);
@@ -1164,3 +1172,102 @@ int kvm_reinject_control(kvm_context_t kvm, int pit_reinject)
 #endif
 	return -ENOSYS;
 }
+
+int kvm_has_gsi_routing(kvm_context_t kvm)
+{
+    int r = 0;
+
+#ifdef KVM_CAP_IRQ_ROUTING
+    r = kvm_check_extension(kvm, KVM_CAP_IRQ_ROUTING);
+#endif
+    return r;
+}
+
+int kvm_get_gsi_count(kvm_context_t kvm)
+{
+#ifdef KVM_CAP_IRQ_ROUTING
+	return kvm_check_extension(kvm, KVM_CAP_IRQ_ROUTING);
+#else
+	return -EINVAL;
+#endif
+}
+
+int kvm_clear_gsi_routes(kvm_context_t kvm)
+{
+#ifdef KVM_CAP_IRQ_ROUTING
+	kvm->irq_routes->nr = 0;
+	return 0;
+#else
+	return -EINVAL;
+#endif
+}
+
+int kvm_add_irq_route(kvm_context_t kvm, int gsi, int irqchip, int pin)
+{
+#ifdef KVM_CAP_IRQ_ROUTING
+	struct kvm_irq_routing *z;
+	struct kvm_irq_routing_entry *e;
+	int n, size;
+
+	if (kvm->irq_routes->nr == kvm->nr_allocated_irq_routes) {
+		n = kvm->nr_allocated_irq_routes * 2;
+		if (n < 64)
+			n = 64;
+		size = sizeof(struct kvm_irq_routing);
+		size += n * sizeof(*e);
+		z = realloc(kvm->irq_routes, size);
+		if (!z)
+			return -ENOMEM;
+		kvm->nr_allocated_irq_routes = n;
+		kvm->irq_routes = z;
+	}
+	n = kvm->irq_routes->nr++;
+	e = &kvm->irq_routes->entries[n];
+	memset(e, 0, sizeof(*e));
+	e->gsi = gsi;
+	e->type = KVM_IRQ_ROUTING_IRQCHIP;
+	e->flags = 0;
+	e->u.irqchip.irqchip = irqchip;
+	e->u.irqchip.pin = pin;
+	return 0;
+#else
+	return -ENOSYS;
+#endif
+}
+
+int kvm_del_irq_route(kvm_context_t kvm, int gsi, int irqchip, int pin)
+{
+#ifdef KVM_CAP_IRQ_ROUTING
+	struct kvm_irq_routing_entry *e, *p;
+	int i;
+
+	for (i = 0; i < kvm->irq_routes->nr; ++i) {
+		e = &kvm->irq_routes->entries[i];
+		if (e->type == KVM_IRQ_ROUTING_IRQCHIP
+		    && e->gsi == gsi
+		    && e->u.irqchip.irqchip == irqchip
+		    && e->u.irqchip.pin == pin) {
+			p = &kvm->irq_routes->entries[--kvm->irq_routes->nr];
+			*e = *p;
+			return 0;
+		}
+	}
+	return -ESRCH;
+#else
+	return -ENOSYS;
+#endif
+}
+
+int kvm_commit_irq_routes(kvm_context_t kvm)
+{
+#ifdef KVM_CAP_IRQ_ROUTING
+	int r;
+
+	kvm->irq_routes->flags = 0;
+	r = ioctl(kvm->vm_fd, KVM_SET_GSI_ROUTING, kvm->irq_routes);
+	if (r == -1)
+		r = -errno;
+#else
+	return -ENOSYS;
+#endif
+}
diff --git a/libkvm/libkvm.h b/libkvm/libkvm.h
index ee1ba68..85012ff 100644
--- a/libkvm/libkvm.h
+++ b/libkvm/libkvm.h
@@ -720,4 +720,66 @@ int kvm_assign_irq(kvm_context_t kvm,
  */
 int kvm_destroy_memory_region_works(kvm_context_t kvm);
 #endif
+
+
+/*!
+ * \brief Checks whether the generic irq routing capability is present
+ *
+ * Checks whether kvm can reroute interrupts among the various interrupt
+ * controllers.
+ *
+ * \param kvm Pointer to the current kvm_context
+ */
+int kvm_has_gsi_routing(kvm_context_t kvm);
+
+/*!
+ * \brief Determines the number of gsis that can be routed
+ *
+ * Returns the number of distinct gsis that can be routed by kvm.  This is
+ * also the number of distinct routes (if a gsi has two routes, than another
+ * gsi cannot be used...)
+ *
+ * \param kvm Pointer to the current kvm_context
+ */
+int kvm_get_gsi_count(kvm_context_t kvm);
+
+/*!
+ * \brief Clears the temporary irq routing table
+ *
+ * Clears the temporary irq routing table.  Nothing is committed to the
+ * running VM.
+ *
+ * \param kvm Pointer to the current kvm_context
+ */
+int kvm_clear_gsi_routes(kvm_context_t kvm);
+
+/*!
+ * \brief Adds an irq route to the temporary irq routing table
+ *
+ * Adds an irq route to the temporary irq routing table.  Nothing is
+ * committed to the running VM.
+ *
+ * \param kvm Pointer to the current kvm_context
+ */
+int kvm_add_irq_route(kvm_context_t kvm, int gsi, int irqchip, int pin);
+
+/*!
+ * \brief Removes an irq route from the temporary irq routing table
+ *
+ * Adds an irq route to the temporary irq routing table.  Nothing is
+ * committed to the running VM.
+ *
+ * \param kvm Pointer to the current kvm_context
+ */
+int kvm_del_irq_route(kvm_context_t kvm, int gsi, int irqchip, int pin);
+
+/*!
+ * \brief Commit the temporary irq routing table
+ *
+ * Commit the temporary irq routing table to the running VM.
+ *
+ * \param kvm Pointer to the current kvm_context
+ */
+int kvm_commit_irq_routes(kvm_context_t kvm);
+
 #endif
-- 
1.6.0.6


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/2] kvm: qemu: initialize irq routing table
  2009-01-14 13:53 [PATCH 0/2] irq routing userspace Avi Kivity
  2009-01-14 13:53 ` [PATCH 1/2] kvm: libkvm: support for irq routing Avi Kivity
@ 2009-01-14 13:53 ` Avi Kivity
  1 sibling, 0 replies; 9+ messages in thread
From: Avi Kivity @ 2009-01-14 13:53 UTC (permalink / raw)
  To: Sheng Yang; +Cc: kvm

Signed-off-by: Avi Kivity <avi@redhat.com>
---
 qemu/qemu-kvm.c |   24 ++++++++++++++++++++++++
 1 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/qemu/qemu-kvm.c b/qemu/qemu-kvm.c
index e4fba78..e67b698 100644
--- a/qemu/qemu-kvm.c
+++ b/qemu/qemu-kvm.c
@@ -783,6 +783,8 @@ static int destroy_region_works = 0;
 int kvm_qemu_create_context(void)
 {
     int r;
+    int i;
+
     if (!kvm_irqchip) {
         kvm_disable_irqchip_creation(kvm_context);
     }
@@ -805,6 +807,28 @@ int kvm_qemu_create_context(void)
 #ifdef TARGET_I386
     destroy_region_works = kvm_destroy_memory_region_works(kvm_context);
 #endif
+
+    if (kvm_irqchip && kvm_has_gsi_routing(kvm_context)) {
+        kvm_clear_gsi_routes(kvm_context);
+        for (i = 0; i < 8; ++i) {
+            if (i == 2)
+                continue;
+            r = kvm_add_irq_route(kvm_context, i, KVM_IRQCHIP_PIC_MASTER, i);
+            if (r < 0)
+                return r;
+        }
+        for (i = 8; i < 16; ++i) {
+            r = kvm_add_irq_route(kvm_context, i, KVM_IRQCHIP_PIC_SLAVE, i - 8);
+            if (r < 0)
+                return r;
+        }
+        for (i = 0; i < 24; ++i) {
+            r = kvm_add_irq_route(kvm_context, i, KVM_IRQCHIP_IOAPIC, i);
+            if (r < 0)
+                return r;
+        }
+        kvm_commit_irq_routes(kvm_context);
+    }
     return 0;
 }
 
-- 
1.6.0.6


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/2] kvm: libkvm: support for irq routing
  2009-01-14 13:53 ` [PATCH 1/2] kvm: libkvm: support for irq routing Avi Kivity
@ 2009-01-15  6:17   ` Sheng Yang
  2009-01-15  6:20     ` Sheng Yang
  2009-01-15  9:58     ` Avi Kivity
  0 siblings, 2 replies; 9+ messages in thread
From: Sheng Yang @ 2009-01-15  6:17 UTC (permalink / raw)
  To: Avi Kivity; +Cc: kvm

On Wednesday 14 January 2009 21:53:10 Avi Kivity wrote:
> Signed-off-by: Avi Kivity <avi@redhat.com>

Do we need a lock for the table?

-- 
regards
Yang, Sheng

> ---
>  libkvm/kvm-common.h |    4 ++
>  libkvm/libkvm.c     |  107
> +++++++++++++++++++++++++++++++++++++++++++++++++++ libkvm/libkvm.h     |  
> 62 +++++++++++++++++++++++++++++
>  3 files changed, 173 insertions(+), 0 deletions(-)
>
> diff --git a/libkvm/kvm-common.h b/libkvm/kvm-common.h
> index c5beacc..e09c07c 100644
> --- a/libkvm/kvm-common.h
> +++ b/libkvm/kvm-common.h
> @@ -61,6 +61,10 @@ struct kvm_context {
>  	int pit_in_kernel;
>  	/// in-kernel coalesced mmio
>  	int coalesced_mmio;
> +#ifdef KVM_CAP_IRQ_ROUTING
> +	struct kvm_irq_routing *irq_routes;
> +	int nr_allocated_irq_routes;
> +#endif
>  };
>
>  void init_slots(void);
> diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c
> index 0408fdb..1004fa6 100644
> --- a/libkvm/libkvm.c
> +++ b/libkvm/libkvm.c
> @@ -381,6 +381,14 @@ int kvm_create_vm(kvm_context_t kvm)
>  {
>  	int fd = kvm->fd;
>
> +#ifdef KVM_CAP_IRQ_ROUTING
> +	kvm->irq_routes = malloc(sizeof(*kvm->irq_routes));
> +	if (!kvm->irq_routes)
> +		return -ENOMEM;
> +	memset(kvm->irq_routes, 0, sizeof(*kvm->irq_routes));
> +	kvm->nr_allocated_irq_routes = 0;
> +#endif
> +
>  	kvm->vcpu_fd[0] = -1;
>
>  	fd = ioctl(fd, KVM_CREATE_VM, 0);
> @@ -1164,3 +1172,102 @@ int kvm_reinject_control(kvm_context_t kvm, int
> pit_reinject) #endif
>  	return -ENOSYS;
>  }
> +
> +int kvm_has_gsi_routing(kvm_context_t kvm)
> +{
> +    int r = 0;
> +
> +#ifdef KVM_CAP_IRQ_ROUTING
> +    r = kvm_check_extension(kvm, KVM_CAP_IRQ_ROUTING);
> +#endif
> +    return r;
> +}
> +
> +int kvm_get_gsi_count(kvm_context_t kvm)
> +{
> +#ifdef KVM_CAP_IRQ_ROUTING
> +	return kvm_check_extension(kvm, KVM_CAP_IRQ_ROUTING);
> +#else
> +	return -EINVAL;
> +#endif
> +}
> +
> +int kvm_clear_gsi_routes(kvm_context_t kvm)
> +{
> +#ifdef KVM_CAP_IRQ_ROUTING
> +	kvm->irq_routes->nr = 0;
> +	return 0;
> +#else
> +	return -EINVAL;
> +#endif
> +}
> +
> +int kvm_add_irq_route(kvm_context_t kvm, int gsi, int irqchip, int pin)
> +{
> +#ifdef KVM_CAP_IRQ_ROUTING
> +	struct kvm_irq_routing *z;
> +	struct kvm_irq_routing_entry *e;
> +	int n, size;
> +
> +	if (kvm->irq_routes->nr == kvm->nr_allocated_irq_routes) {
> +		n = kvm->nr_allocated_irq_routes * 2;
> +		if (n < 64)
> +			n = 64;
> +		size = sizeof(struct kvm_irq_routing);
> +		size += n * sizeof(*e);
> +		z = realloc(kvm->irq_routes, size);
> +		if (!z)
> +			return -ENOMEM;
> +		kvm->nr_allocated_irq_routes = n;
> +		kvm->irq_routes = z;
> +	}
> +	n = kvm->irq_routes->nr++;
> +	e = &kvm->irq_routes->entries[n];
> +	memset(e, 0, sizeof(*e));
> +	e->gsi = gsi;
> +	e->type = KVM_IRQ_ROUTING_IRQCHIP;
> +	e->flags = 0;
> +	e->u.irqchip.irqchip = irqchip;
> +	e->u.irqchip.pin = pin;
> +	return 0;
> +#else
> +	return -ENOSYS;
> +#endif
> +}
> +
> +int kvm_del_irq_route(kvm_context_t kvm, int gsi, int irqchip, int pin)
> +{
> +#ifdef KVM_CAP_IRQ_ROUTING
> +	struct kvm_irq_routing_entry *e, *p;
> +	int i;
> +
> +	for (i = 0; i < kvm->irq_routes->nr; ++i) {
> +		e = &kvm->irq_routes->entries[i];
> +		if (e->type == KVM_IRQ_ROUTING_IRQCHIP
> +		    && e->gsi == gsi
> +		    && e->u.irqchip.irqchip == irqchip
> +		    && e->u.irqchip.pin == pin) {
> +			p = &kvm->irq_routes->entries[--kvm->irq_routes->nr];
> +			*e = *p;
> +			return 0;
> +		}
> +	}
> +	return -ESRCH;
> +#else
> +	return -ENOSYS;
> +#endif
> +}
> +
> +int kvm_commit_irq_routes(kvm_context_t kvm)
> +{
> +#ifdef KVM_CAP_IRQ_ROUTING
> +	int r;
> +
> +	kvm->irq_routes->flags = 0;
> +	r = ioctl(kvm->vm_fd, KVM_SET_GSI_ROUTING, kvm->irq_routes);
> +	if (r == -1)
> +		r = -errno;
> +#else
> +	return -ENOSYS;
> +#endif
> +}
> diff --git a/libkvm/libkvm.h b/libkvm/libkvm.h
> index ee1ba68..85012ff 100644
> --- a/libkvm/libkvm.h
> +++ b/libkvm/libkvm.h
> @@ -720,4 +720,66 @@ int kvm_assign_irq(kvm_context_t kvm,
>   */
>  int kvm_destroy_memory_region_works(kvm_context_t kvm);
>  #endif
> +
> +
> +/*!
> + * \brief Checks whether the generic irq routing capability is present
> + *
> + * Checks whether kvm can reroute interrupts among the various interrupt
> + * controllers.
> + *
> + * \param kvm Pointer to the current kvm_context
> + */
> +int kvm_has_gsi_routing(kvm_context_t kvm);
> +
> +/*!
> + * \brief Determines the number of gsis that can be routed
> + *
> + * Returns the number of distinct gsis that can be routed by kvm.  This is
> + * also the number of distinct routes (if a gsi has two routes, than
> another + * gsi cannot be used...)
> + *
> + * \param kvm Pointer to the current kvm_context
> + */
> +int kvm_get_gsi_count(kvm_context_t kvm);
> +
> +/*!
> + * \brief Clears the temporary irq routing table
> + *
> + * Clears the temporary irq routing table.  Nothing is committed to the
> + * running VM.
> + *
> + * \param kvm Pointer to the current kvm_context
> + */
> +int kvm_clear_gsi_routes(kvm_context_t kvm);
> +
> +/*!
> + * \brief Adds an irq route to the temporary irq routing table
> + *
> + * Adds an irq route to the temporary irq routing table.  Nothing is
> + * committed to the running VM.
> + *
> + * \param kvm Pointer to the current kvm_context
> + */
> +int kvm_add_irq_route(kvm_context_t kvm, int gsi, int irqchip, int pin);
> +
> +/*!
> + * \brief Removes an irq route from the temporary irq routing table
> + *
> + * Adds an irq route to the temporary irq routing table.  Nothing is
> + * committed to the running VM.
> + *
> + * \param kvm Pointer to the current kvm_context
> + */
> +int kvm_del_irq_route(kvm_context_t kvm, int gsi, int irqchip, int pin);
> +
> +/*!
> + * \brief Commit the temporary irq routing table
> + *
> + * Commit the temporary irq routing table to the running VM.
> + *
> + * \param kvm Pointer to the current kvm_context
> + */
> +int kvm_commit_irq_routes(kvm_context_t kvm);
> +
>  #endif


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/2] kvm: libkvm: support for irq routing
  2009-01-15  6:17   ` Sheng Yang
@ 2009-01-15  6:20     ` Sheng Yang
  2009-01-15  9:59       ` Avi Kivity
  2009-01-15  9:58     ` Avi Kivity
  1 sibling, 1 reply; 9+ messages in thread
From: Sheng Yang @ 2009-01-15  6:20 UTC (permalink / raw)
  To: kvm; +Cc: Avi Kivity

On Thursday 15 January 2009 14:17:16 Sheng Yang wrote:
> On Wednesday 14 January 2009 21:53:10 Avi Kivity wrote:
> > Signed-off-by: Avi Kivity <avi@redhat.com>
>
> Do we need a lock for the table?

And kvm_add_irq_route/kvm_del_irq_route should be generic used, how about 
transfer a kvm_irq_routing_entry as parameter?

-- 
regards
Yang, Sheng


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/2] kvm: libkvm: support for irq routing
  2009-01-15  6:17   ` Sheng Yang
  2009-01-15  6:20     ` Sheng Yang
@ 2009-01-15  9:58     ` Avi Kivity
  1 sibling, 0 replies; 9+ messages in thread
From: Avi Kivity @ 2009-01-15  9:58 UTC (permalink / raw)
  To: Sheng Yang; +Cc: kvm

Sheng Yang wrote:
> On Wednesday 14 January 2009 21:53:10 Avi Kivity wrote:
>   
>> Signed-off-by: Avi Kivity <avi@redhat.com>
>>     
>
> Do we need a lock for the table?
>   

No, that's up to the caller.  libkvm is just a silly wrapper for the ioctls.

In practice, the table will be protected by qemu_mutex.

-- 
error compiling committee.c: too many arguments to function


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/2] kvm: libkvm: support for irq routing
  2009-01-15  6:20     ` Sheng Yang
@ 2009-01-15  9:59       ` Avi Kivity
  2009-01-15 10:05         ` Sheng Yang
  0 siblings, 1 reply; 9+ messages in thread
From: Avi Kivity @ 2009-01-15  9:59 UTC (permalink / raw)
  To: Sheng Yang; +Cc: kvm

Sheng Yang wrote:
> On Thursday 15 January 2009 14:17:16 Sheng Yang wrote:
>   
>> On Wednesday 14 January 2009 21:53:10 Avi Kivity wrote:
>>     
>>> Signed-off-by: Avi Kivity <avi@redhat.com>
>>>       
>> Do we need a lock for the table?
>>     
>
> And kvm_add_irq_route/kvm_del_irq_route should be generic used, how about 
> transfer a kvm_irq_routing_entry as parameter?
>   

These structures + selectors + unions are clumsy.  For libkvm, I'd 
prefer adding kvm_add_msi() and kvm_del_msi().


-- 
error compiling committee.c: too many arguments to function


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/2] kvm: libkvm: support for irq routing
  2009-01-15  9:59       ` Avi Kivity
@ 2009-01-15 10:05         ` Sheng Yang
  2009-01-15 10:10           ` Avi Kivity
  0 siblings, 1 reply; 9+ messages in thread
From: Sheng Yang @ 2009-01-15 10:05 UTC (permalink / raw)
  To: Avi Kivity; +Cc: kvm

On Thursday 15 January 2009 17:59:43 Avi Kivity wrote:
> Sheng Yang wrote:
> > On Thursday 15 January 2009 14:17:16 Sheng Yang wrote:
> >> On Wednesday 14 January 2009 21:53:10 Avi Kivity wrote:
> >>> Signed-off-by: Avi Kivity <avi@redhat.com>
> >>
> >> Do we need a lock for the table?
> >
> > And kvm_add_irq_route/kvm_del_irq_route should be generic used, how about
> > transfer a kvm_irq_routing_entry as parameter?
>
> These structures + selectors + unions are clumsy.  For libkvm, I'd
> prefer adding kvm_add_msi() and kvm_del_msi().

But...
> +int kvm_add_irq_route(kvm_context_t kvm, int gsi, int irqchip, int pin)
> +{
> +#ifdef KVM_CAP_IRQ_ROUTING
> +       struct kvm_irq_routing *z;
> +       struct kvm_irq_routing_entry *e;
> +       int n, size;
> +
> +       if (kvm->irq_routes->nr == kvm->nr_allocated_irq_routes) {
> +               n = kvm->nr_allocated_irq_routes * 2;
> +               if (n < 64)
> +                       n = 64;
> +               size = sizeof(struct kvm_irq_routing);
> +               size += n * sizeof(*e);
> +               z = realloc(kvm->irq_routes, size);
> +               if (!z)
> +                       return -ENOMEM;
> +               kvm->nr_allocated_irq_routes = n;
> +               kvm->irq_routes = z;
> +       }
> +       n = kvm->irq_routes->nr++;
> +       e = &kvm->irq_routes->entries[n];
> +       memset(e, 0, sizeof(*e));
> +       e->gsi = gsi;
> +       e->type = KVM_IRQ_ROUTING_IRQCHIP;
> +       e->flags = 0;
> +       e->u.irqchip.irqchip = irqchip;
> +       e->u.irqchip.pin = pin;
> +       return 0;
> +#else
> +       return -ENOSYS;
> +#endif
> +}

Besides three lines, all can be reused... I don't see the reason for another 
function...

And the name here is irq_route, I suppose it should be generic used. Can be 
core function which can be wrapped.

-- 
regards
Yang, Sheng


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/2] kvm: libkvm: support for irq routing
  2009-01-15 10:05         ` Sheng Yang
@ 2009-01-15 10:10           ` Avi Kivity
  0 siblings, 0 replies; 9+ messages in thread
From: Avi Kivity @ 2009-01-15 10:10 UTC (permalink / raw)
  To: Sheng Yang; +Cc: kvm

Sheng Yang wrote:
> On Thursday 15 January 2009 17:59:43 Avi Kivity wrote:
>   
>> Sheng Yang wrote:
>>     
>>> On Thursday 15 January 2009 14:17:16 Sheng Yang wrote:
>>>       
>>>> On Wednesday 14 January 2009 21:53:10 Avi Kivity wrote:
>>>>         
>>>>> Signed-off-by: Avi Kivity <avi@redhat.com>
>>>>>           
>>>> Do we need a lock for the table?
>>>>         
>>> And kvm_add_irq_route/kvm_del_irq_route should be generic used, how about
>>> transfer a kvm_irq_routing_entry as parameter?
>>>       
>> These structures + selectors + unions are clumsy.  For libkvm, I'd
>> prefer adding kvm_add_msi() and kvm_del_msi().
>>     
>
> But...
>   
>> +int kvm_add_irq_route(kvm_context_t kvm, int gsi, int irqchip, int pin)
>> +{
>> +#ifdef KVM_CAP_IRQ_ROUTING
>> +       struct kvm_irq_routing *z;
>> +       struct kvm_irq_routing_entry *e;
>> +       int n, size;
>> +
>> +       if (kvm->irq_routes->nr == kvm->nr_allocated_irq_routes) {
>> +               n = kvm->nr_allocated_irq_routes * 2;
>> +               if (n < 64)
>> +                       n = 64;
>> +               size = sizeof(struct kvm_irq_routing);
>> +               size += n * sizeof(*e);
>> +               z = realloc(kvm->irq_routes, size);
>> +               if (!z)
>> +                       return -ENOMEM;
>> +               kvm->nr_allocated_irq_routes = n;
>> +               kvm->irq_routes = z;
>> +       }
>> +       n = kvm->irq_routes->nr++;
>> +       e = &kvm->irq_routes->entries[n];
>> +       memset(e, 0, sizeof(*e));
>> +       e->gsi = gsi;
>> +       e->type = KVM_IRQ_ROUTING_IRQCHIP;
>> +       e->flags = 0;
>> +       e->u.irqchip.irqchip = irqchip;
>> +       e->u.irqchip.pin = pin;
>> +       return 0;
>> +#else
>> +       return -ENOSYS;
>> +#endif
>> +}
>>     
>
> Besides three lines, all can be reused... I don't see the reason for another 
> function...
>
> And the name here is irq_route, I suppose it should be generic used. Can be 
> core function which can be wrapped.
>   

Yes, I guess we can rename it irqchip_route.  When we add msis, both 
this function and the new msi function can share code.

-- 
error compiling committee.c: too many arguments to function


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2009-01-15 10:10 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-01-14 13:53 [PATCH 0/2] irq routing userspace Avi Kivity
2009-01-14 13:53 ` [PATCH 1/2] kvm: libkvm: support for irq routing Avi Kivity
2009-01-15  6:17   ` Sheng Yang
2009-01-15  6:20     ` Sheng Yang
2009-01-15  9:59       ` Avi Kivity
2009-01-15 10:05         ` Sheng Yang
2009-01-15 10:10           ` Avi Kivity
2009-01-15  9:58     ` Avi Kivity
2009-01-14 13:53 ` [PATCH 2/2] kvm: qemu: initialize irq routing table Avi Kivity

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.