* Re: [dpdk-dev] [PATCH v2 07/16] Add support for VFIO interrupts, add VFIO header
@ 2014-05-27 3:02 Xu, HuilongX
0 siblings, 0 replies; 10+ messages in thread
From: Xu, HuilongX @ 2014-05-27 3:02 UTC (permalink / raw)
To: dev, Burakov, Anatoly
Creating code to handle VFIO interrupts in EAL interrupts, and also
adding a header eal_vfio.h.
This header checks two things:
* checks if CONFIG_RTE_EAL_VFIO was enabled during build time
* checks that kernel version is 3.6+ so that DPDK would still compile
on older kernels despite VFIO compilation being enabled by default.
This header also defines a VFIO_PRESENT macro, which should be used to
conditionally compile all the VFIO code. This is because having
CONFIG_RTE_EAL_VFIO enabled doesn't guarantee that the VFIO support is
compiled in, because we're still dependent on kernel version.
Signed-off-by: Anatoly Burakov <anatoly.burakov at intel.com>
Test-by: HuilongX Xu <huilongx.xu@intel.com>
Compile pass
>>Compile OS: FC20 x86_64
>>Kernel version: 3.13.6-200
>>GCC version: 4.8.2
>>Server: Crownpass
---
lib/librte_eal/linuxapp/eal/eal_interrupts.c | 203 +++++++++++++++++++-
lib/librte_eal/linuxapp/eal/include/eal_vfio.h | 49 +++++
.../linuxapp/eal/include/exec-env/rte_interrupts.h | 3 +
3 files changed, 250 insertions(+), 5 deletions(-)
create mode 100644 lib/librte_eal/linuxapp/eal/include/eal_vfio.h
diff --git a/lib/librte_eal/linuxapp/eal/eal_interrupts.c b/lib/librte_eal/linuxapp/eal/eal_interrupts.c
index 58e1ddf..cb95e2a 100644
--- a/lib/librte_eal/linuxapp/eal/eal_interrupts.c
+++ b/lib/librte_eal/linuxapp/eal/eal_interrupts.c
@@ -36,7 +36,6 @@
#include <stdlib.h>
#include <pthread.h>
#include <sys/queue.h>
-#include <malloc.h>
#include <stdarg.h>
#include <unistd.h>
#include <string.h>
@@ -44,6 +43,7 @@
#include <inttypes.h>
#include <sys/epoll.h>
#include <sys/signalfd.h>
+#include <sys/ioctl.h>
#include <rte_common.h>
#include <rte_interrupts.h>
@@ -66,6 +66,7 @@
#include <rte_spinlock.h>
#include "eal_private.h"
+#include "eal_vfio.h"
#define EAL_INTR_EPOLL_WAIT_FOREVER (-1)
@@ -87,6 +88,7 @@ union intr_pipefds{
*/
union rte_intr_read_buffer {
int uio_intr_count; /* for uio device */
+ uint64_t vfio_intr_count; /* for vfio device */
uint64_t timerfd_num; /* for timerfd */
char charbuf[16]; /* for others */
};
@@ -119,6 +121,173 @@ static struct rte_intr_source_list intr_sources;
/* interrupt handling thread */
static pthread_t intr_thread;
+/* VFIO interrupts */
+#ifdef VFIO_PRESENT
+
+#define IRQ_SET_BUF_LEN (sizeof(struct vfio_irq_set) + sizeof(int))
+
+/* enable legacy (INTx) interrupts */
+static int
+vfio_enable_intx(struct rte_intr_handle *intr_handle) {
+ struct vfio_irq_set * irq_set;
+ char irq_set_buf[IRQ_SET_BUF_LEN];
+ int len, ret;
+ int * fd_ptr;
+
+ len = sizeof(irq_set_buf);
+
+ /* enable INTx */
+ irq_set = (struct vfio_irq_set *) irq_set_buf;
+ irq_set->argsz = len;
+ irq_set->count = 1;
+ irq_set->flags = VFIO_IRQ_SET_DATA_EVENTFD | VFIO_IRQ_SET_ACTION_TRIGGER;
+ irq_set->index = VFIO_PCI_INTX_IRQ_INDEX;
+ irq_set->start = 0;
+ fd_ptr = (int*) &irq_set->data;
+ *fd_ptr = intr_handle->fd;
+
+ ret = ioctl(intr_handle->vfio_dev_fd, VFIO_DEVICE_SET_IRQS, irq_set);
+
+ if (ret) {
+ RTE_LOG(ERR, EAL, "Error enabling INTx interrupts for fd %d\n",
+ intr_handle->fd);
+ return -1;
+ }
+
+ /* unmask INTx after enabling */
+ memset(irq_set, 0, len);
+ len = sizeof(struct vfio_irq_set);
+ irq_set->argsz = len;
+ irq_set->count = 1;
+ irq_set->flags = VFIO_IRQ_SET_DATA_NONE | VFIO_IRQ_SET_ACTION_UNMASK;
+ irq_set->index = VFIO_PCI_INTX_IRQ_INDEX;
+ irq_set->start = 0;
+
+ ret = ioctl(intr_handle->vfio_dev_fd, VFIO_DEVICE_SET_IRQS, irq_set);
+
+ if (ret) {
+ RTE_LOG(ERR, EAL, "Error unmasking INTx interrupts for fd %d\n",
+ intr_handle->fd);
+ return -1;
+ }
+ return 0;
+}
+
+/* disable legacy (INTx) interrupts */
+static int
+vfio_disable_intx(struct rte_intr_handle *intr_handle) {
+ struct vfio_irq_set * irq_set;
+ char irq_set_buf[IRQ_SET_BUF_LEN];
+ int len, ret;
+
+ len = sizeof(struct vfio_irq_set);
+
+ /* mask interrupts before disabling */
+ irq_set = (struct vfio_irq_set *) irq_set_buf;
+ irq_set->argsz = len;
+ irq_set->count = 1;
+ irq_set->flags = VFIO_IRQ_SET_DATA_NONE | VFIO_IRQ_SET_ACTION_UNMASK;
+ irq_set->index = VFIO_PCI_INTX_IRQ_INDEX;
+ irq_set->start = 0;
+
+ ret = ioctl(intr_handle->vfio_dev_fd, VFIO_DEVICE_SET_IRQS, irq_set);
+
+ if (ret) {
+ RTE_LOG(ERR, EAL, "Error unmasking INTx interrupts for fd %d\n",
+ intr_handle->fd);
+ return -1;
+ }
+
+ /* disable INTx*/
+ memset(irq_set, 0, len);
+ irq_set->argsz = len;
+ irq_set->count = 0;
+ irq_set->flags = VFIO_IRQ_SET_DATA_NONE | VFIO_IRQ_SET_ACTION_TRIGGER;
+ irq_set->index = VFIO_PCI_INTX_IRQ_INDEX;
+ irq_set->start = 0;
+
+ ret = ioctl(intr_handle->vfio_dev_fd, VFIO_DEVICE_SET_IRQS, irq_set);
+
+ if (ret) {
+ RTE_LOG(ERR, EAL,
+ "Error disabling INTx interrupts for fd %d\n", intr_handle->fd);
+ return -1;
+ }
+ return 0;
+}
+
+/* enable MSI-X interrupts */
+static int
+vfio_enable_msix(struct rte_intr_handle *intr_handle) {
+ int len, ret;
+ char irq_set_buf[IRQ_SET_BUF_LEN];
+ struct vfio_irq_set * irq_set;
+ int * fd_ptr;
+
+ len = sizeof(irq_set_buf);
+
+ irq_set = (struct vfio_irq_set *) irq_set_buf;
+ irq_set->argsz = len;
+ irq_set->count = 1;
+ irq_set->flags = VFIO_IRQ_SET_DATA_EVENTFD | VFIO_IRQ_SET_ACTION_TRIGGER;
+ irq_set->index = VFIO_PCI_MSIX_IRQ_INDEX;
+ irq_set->start = 0;
+ fd_ptr = (int*) &irq_set->data;
+ *fd_ptr = intr_handle->fd;
+
+ ret = ioctl(intr_handle->vfio_dev_fd, VFIO_DEVICE_SET_IRQS, irq_set);
+
+ if (ret) {
+ RTE_LOG(ERR, EAL, "Error enabling MSI-X interrupts for fd %d\n",
+ intr_handle->fd);
+ return -1;
+ }
+
+ /* manually trigger interrupt to enable it */
+ memset(irq_set, 0, len);
+ len = sizeof(struct vfio_irq_set);
+ irq_set->argsz = len;
+ irq_set->count = 1;
+ irq_set->flags = VFIO_IRQ_SET_DATA_NONE | VFIO_IRQ_SET_ACTION_TRIGGER;
+ irq_set->index = VFIO_PCI_MSIX_IRQ_INDEX;
+ irq_set->start = 0;
+
+ ret = ioctl(intr_handle->vfio_dev_fd, VFIO_DEVICE_SET_IRQS, irq_set);
+
+ if (ret) {
+ RTE_LOG(ERR, EAL, "Error triggering MSI-X interrupts for fd %d\n",
+ intr_handle->fd);
+ return -1;
+ }
+ return 0;
+}
+
+/* disable MSI-X interrupts */
+static int
+vfio_disable_msix(struct rte_intr_handle *intr_handle) {
+ struct vfio_irq_set * irq_set;
+ char irq_set_buf[IRQ_SET_BUF_LEN];
+ int len, ret;
+
+ len = sizeof(struct vfio_irq_set);
+
+ irq_set = (struct vfio_irq_set *) irq_set_buf;
+ irq_set->argsz = len;
+ irq_set->count = 0;
+ irq_set->flags = VFIO_IRQ_SET_DATA_NONE | VFIO_IRQ_SET_ACTION_TRIGGER;
+ irq_set->index = VFIO_PCI_MSIX_IRQ_INDEX;
+ irq_set->start = 0;
+
+ ret = ioctl(intr_handle->vfio_dev_fd, VFIO_DEVICE_SET_IRQS, irq_set);
+
+ if (ret)
+ RTE_LOG(ERR, EAL,
+ "Error disabling MSI-X interrupts for fd %d\n", intr_handle->fd);
+
+ return ret;
+}
+#endif
+
int
rte_intr_callback_register(struct rte_intr_handle *intr_handle,
rte_intr_callback_fn cb, void *cb_arg)
@@ -276,6 +445,16 @@ rte_intr_enable(struct rte_intr_handle *intr_handle)
/* not used at this moment */
case RTE_INTR_HANDLE_ALARM:
return -1;
+#ifdef VFIO_PRESENT
+ case RTE_INTR_HANDLE_VFIO_MSIX:
+ if (vfio_enable_msix(intr_handle))
+ return -1;
+ break;
+ case RTE_INTR_HANDLE_VFIO_LEGACY:
+ if (vfio_enable_intx(intr_handle))
+ return -1;
+ break;
+#endif
/* unknown handle type */
default:
RTE_LOG(ERR, EAL,
@@ -300,7 +479,7 @@ rte_intr_disable(struct rte_intr_handle *intr_handle)
case RTE_INTR_HANDLE_UIO:
if (write(intr_handle->fd, &value, sizeof(value)) < 0){
RTE_LOG(ERR, EAL,
- "Error enabling interrupts for fd %d\n",
+ "Error disabling interrupts for fd %d\n",
intr_handle->fd);
return -1;
}
@@ -308,6 +487,16 @@ rte_intr_disable(struct rte_intr_handle *intr_handle)
/* not used at this moment */
case RTE_INTR_HANDLE_ALARM:
return -1;
+#ifdef VFIO_PRESENT
+ case RTE_INTR_HANDLE_VFIO_MSIX:
+ if (vfio_disable_msix(intr_handle))
+ return -1;
+ break;
+ case RTE_INTR_HANDLE_VFIO_LEGACY:
+ if (vfio_disable_intx(intr_handle))
+ return -1;
+ break;
+#endif
/* unknown handle type */
default:
RTE_LOG(ERR, EAL,
@@ -357,10 +546,14 @@ eal_intr_process_interrupts(struct epoll_event *events, int nfds)
/* set the length to be read dor different handle type */
switch (src->intr_handle.type) {
case RTE_INTR_HANDLE_UIO:
- bytes_read = 4;
+ bytes_read = sizeof(buf.uio_intr_count);
break;
case RTE_INTR_HANDLE_ALARM:
- bytes_read = sizeof(uint64_t);
+ bytes_read = sizeof(buf.timerfd_num);
+ break;
+ case RTE_INTR_HANDLE_VFIO_MSIX:
+ case RTE_INTR_HANDLE_VFIO_LEGACY:
+ bytes_read = sizeof(buf.vfio_intr_count);
break;
default:
bytes_read = 1;
@@ -397,7 +590,7 @@ eal_intr_process_interrupts(struct epoll_event *events, int nfds)
active_cb.cb_fn(&src->intr_handle,
active_cb.cb_arg);
- /*get the lcok back. */
+ /*get the lock back. */
rte_spinlock_lock(&intr_lock);
}
}
diff --git a/lib/librte_eal/linuxapp/eal/include/eal_vfio.h b/lib/librte_eal/linuxapp/eal/include/eal_vfio.h
new file mode 100644
index 0000000..ca4982b
--- /dev/null
+++ b/lib/librte_eal/linuxapp/eal/include/eal_vfio.h
@@ -0,0 +1,49 @@
+/*-
+ * BSD LICENSE
+ *
+ * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef EAL_VFIO_H_
+#define EAL_VFIO_H_
+
+/*
+ * determine if VFIO is present on the system
+ */
+#ifdef RTE_EAL_VFIO
+#include <linux/version.h>
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0)
+#include <linux/vfio.h>
+
+#define VFIO_PRESENT
+#endif /* kernel version */
+#endif /* RTE_EAL_VFIO */
+
+#endif /* EAL_VFIO_H_ */
diff --git a/lib/librte_eal/linuxapp/eal/include/exec-env/rte_interrupts.h b/lib/librte_eal/linuxapp/eal/include/exec-env/rte_interrupts.h
index 6733948..b160efe 100644
--- a/lib/librte_eal/linuxapp/eal/include/exec-env/rte_interrupts.h
+++ b/lib/librte_eal/linuxapp/eal/include/exec-env/rte_interrupts.h
@@ -41,12 +41,15 @@
enum rte_intr_handle_type {
RTE_INTR_HANDLE_UNKNOWN = 0,
RTE_INTR_HANDLE_UIO, /**< uio device handle */
+ RTE_INTR_HANDLE_VFIO_LEGACY, /**< vfio device handle (legacy) */
+ RTE_INTR_HANDLE_VFIO_MSIX, /**< uio device handle (MSIX) */
RTE_INTR_HANDLE_ALARM, /**< alarm handle */
RTE_INTR_HANDLE_MAX
};
/** Handle for interrupts. */
struct rte_intr_handle {
+ int vfio_dev_fd; /**< VFIO device file descriptor */
int fd; /**< file descriptor */
enum rte_intr_handle_type type; /**< handle type */
};
--
1.7.0.7
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [dpdk-dev] [PATCH v2 07/16] Add support for VFIO interrupts, add VFIO header
2014-05-27 14:40 ` Burakov, Anatoly
@ 2014-05-27 14:46 ` Thomas Monjalon
0 siblings, 0 replies; 10+ messages in thread
From: Thomas Monjalon @ 2014-05-27 14:46 UTC (permalink / raw)
To: Burakov, Anatoly; +Cc: dev
2014-05-27 14:40, Burakov, Anatoly:
> > 2014-05-27 14:29, Burakov, Anatoly:
> > > > > I don't know if there is something defined in a Linux header which
> > > > > could help to check if VFIO is supported. But in general, it's
> > > > > better to check for a macro belonging to the feature instead of
> > > > > checking kernel version.
> >
> > > > Not sure VFIO defines any macros anywhere, but I'll look into it,
> > > > thanks.
> > >
> > > There probably isn't. At least I don't see anything in commit log. So
> > > unless there's a way to get config options from kernel at compile-time
> > > in userspace code, I don't think we can do anything else than kernel
> > > version check.
> >
> > Isn't it sufficient to check VFIO_API_VERSION?
>
> I believe you have to #include <linux/vfio.h> before you can get that macro.
> The header file isn't present on kernels earlier than 3.6.
Oh yes, you're right :)
--
Thomas
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [dpdk-dev] [PATCH v2 07/16] Add support for VFIO interrupts, add VFIO header
2014-05-27 14:38 ` Thomas Monjalon
@ 2014-05-27 14:40 ` Burakov, Anatoly
2014-05-27 14:46 ` Thomas Monjalon
0 siblings, 1 reply; 10+ messages in thread
From: Burakov, Anatoly @ 2014-05-27 14:40 UTC (permalink / raw)
To: Thomas Monjalon; +Cc: dev
Hi Thomas,
> 2014-05-27 14:29, Burakov, Anatoly:
> > > > I don't know if there is something defined in a Linux header which
> > > > could help to check if VFIO is supported. But in general, it's
> > > > better to check for a macro belonging to the feature instead of checking
> kernel version.
> > >
> > > Not sure VFIO defines any macros anywhere, but I'll look into it, thanks.
> >
> > There probably isn't. At least I don't see anything in commit log. So
> > unless there's a way to get config options from kernel at compile-time
> > in userspace code, I don't think we can do anything else than kernel
> > version check.
>
> Isn't it sufficient to check VFIO_API_VERSION?
I believe you have to #include <linux/vfio.h> before you can get that macro. The header file isn't present on kernels earlier than 3.6.
Best regards,
Anatoly Burakov
DPDK SW Engineer
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [dpdk-dev] [PATCH v2 07/16] Add support for VFIO interrupts, add VFIO header
2014-05-27 14:29 ` Burakov, Anatoly
@ 2014-05-27 14:38 ` Thomas Monjalon
2014-05-27 14:40 ` Burakov, Anatoly
0 siblings, 1 reply; 10+ messages in thread
From: Thomas Monjalon @ 2014-05-27 14:38 UTC (permalink / raw)
To: Burakov, Anatoly; +Cc: dev
2014-05-27 14:29, Burakov, Anatoly:
> > > I don't know if there is something defined in a Linux header which could
> > > help to check if VFIO is supported. But in general, it's better to check
> > > for a macro belonging to the feature instead of checking kernel version.
> >
> > Not sure VFIO defines any macros anywhere, but I'll look into it, thanks.
>
> There probably isn't. At least I don't see anything in commit log. So unless
> there's a way to get config options from kernel at compile-time in
> userspace code, I don't think we can do anything else than kernel version
> check.
Isn't it sufficient to check VFIO_API_VERSION?
--
Thomas
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [dpdk-dev] [PATCH v2 07/16] Add support for VFIO interrupts, add VFIO header
2014-05-22 12:54 ` Burakov, Anatoly
@ 2014-05-27 14:29 ` Burakov, Anatoly
2014-05-27 14:38 ` Thomas Monjalon
0 siblings, 1 reply; 10+ messages in thread
From: Burakov, Anatoly @ 2014-05-27 14:29 UTC (permalink / raw)
To: Thomas Monjalon; +Cc: dev
Hi Thomas,
> > I don't know if there is something defined in a Linux header which could
> help
> > to check if VFIO is supported. But in general, it's better to check for a macro
> > belonging to the feature instead of checking kernel version.
>
> Not sure VFIO defines any macros anywhere, but I'll look into it, thanks.
>
There probably isn't. At least I don't see anything in commit log. So unless there's a way to get config options from kernel at compile-time in userspace code, I don't think we can do anything else than kernel version check.
Best regards,
Anatoly Burakov
DPDK SW Engineer
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [dpdk-dev] [PATCH v2 07/16] Add support for VFIO interrupts, add VFIO header
2014-05-22 12:49 ` Thomas Monjalon
@ 2014-05-22 12:54 ` Burakov, Anatoly
2014-05-27 14:29 ` Burakov, Anatoly
0 siblings, 1 reply; 10+ messages in thread
From: Burakov, Anatoly @ 2014-05-22 12:54 UTC (permalink / raw)
To: Thomas Monjalon; +Cc: dev
Hi Thomas,
> I don't know if there is something defined in a Linux header which could help
> to check if VFIO is supported. But in general, it's better to check for a macro
> belonging to the feature instead of checking kernel version.
Not sure VFIO defines any macros anywhere, but I'll look into it, thanks.
Best regards,
Anatoly Burakov
DPDK SW Engineer
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [dpdk-dev] [PATCH v2 07/16] Add support for VFIO interrupts, add VFIO header
2014-05-22 12:45 ` Burakov, Anatoly
@ 2014-05-22 12:49 ` Thomas Monjalon
2014-05-22 12:54 ` Burakov, Anatoly
0 siblings, 1 reply; 10+ messages in thread
From: Thomas Monjalon @ 2014-05-22 12:49 UTC (permalink / raw)
To: Burakov, Anatoly; +Cc: dev
2014-05-22 12:45, Burakov, Anatoly:
> > In case VFIO is backported on older kernel, it would be better to check a
> > related macro instead of Linux version.
>
> Not sure I follow. What is the "related macro" you're referring to?
I don't know if there is something defined in a Linux header which could help
to check if VFIO is supported. But in general, it's better to check for a
macro belonging to the feature instead of checking kernel version.
--
Thomas
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [dpdk-dev] [PATCH v2 07/16] Add support for VFIO interrupts, add VFIO header
2014-05-21 16:07 ` Thomas Monjalon
@ 2014-05-22 12:45 ` Burakov, Anatoly
2014-05-22 12:49 ` Thomas Monjalon
0 siblings, 1 reply; 10+ messages in thread
From: Burakov, Anatoly @ 2014-05-22 12:45 UTC (permalink / raw)
To: Thomas Monjalon; +Cc: dev
Hi Thomas,
> In case VFIO is backported on older kernel, it would be better to check a
> related macro instead of Linux version.
Not sure I follow. What is the "related macro" you're referring to?
Best regards,
Anatoly Burakov
DPDK SW Engineer
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [dpdk-dev] [PATCH v2 07/16] Add support for VFIO interrupts, add VFIO header
2014-05-19 15:51 ` [dpdk-dev] [PATCH v2 07/16] Add support for VFIO interrupts, add VFIO header Anatoly Burakov
@ 2014-05-21 16:07 ` Thomas Monjalon
2014-05-22 12:45 ` Burakov, Anatoly
0 siblings, 1 reply; 10+ messages in thread
From: Thomas Monjalon @ 2014-05-21 16:07 UTC (permalink / raw)
To: Anatoly Burakov; +Cc: dev
2014-05-19 16:51, Anatoly Burakov:
> Creating code to handle VFIO interrupts in EAL interrupts, and also
> adding a header eal_vfio.h.
Maybe it's better to have 2 patches here.
> This header checks two things:
> * checks if CONFIG_RTE_EAL_VFIO was enabled during build time
> * checks that kernel version is 3.6+ so that DPDK would still compile
> on older kernels despite VFIO compilation being enabled by default.
In case VFIO is backported on older kernel, it would be better to check a
related macro instead of Linux version.
> This header also defines a VFIO_PRESENT macro, which should be used to
> conditionally compile all the VFIO code. This is because having
> CONFIG_RTE_EAL_VFIO enabled doesn't guarantee that the VFIO support is
> compiled in, because we're still dependent on kernel version.
>
> Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
> + struct vfio_irq_set * irq_set;
There few lines like this one where checkpatch.pl reports an error:
ERROR: "foo * bar" should be "foo *bar"
Thanks
--
Thomas
^ permalink raw reply [flat|nested] 10+ messages in thread
* [dpdk-dev] [PATCH v2 07/16] Add support for VFIO interrupts, add VFIO header
2014-05-01 11:05 [dpdk-dev] [PATCH 00/16] [RFC] [VFIO] Add VFIO support to DPDK Burakov, Anatoly
@ 2014-05-19 15:51 ` Anatoly Burakov
2014-05-21 16:07 ` Thomas Monjalon
0 siblings, 1 reply; 10+ messages in thread
From: Anatoly Burakov @ 2014-05-19 15:51 UTC (permalink / raw)
To: dev
Creating code to handle VFIO interrupts in EAL interrupts, and also
adding a header eal_vfio.h.
This header checks two things:
* checks if CONFIG_RTE_EAL_VFIO was enabled during build time
* checks that kernel version is 3.6+ so that DPDK would still compile
on older kernels despite VFIO compilation being enabled by default.
This header also defines a VFIO_PRESENT macro, which should be used to
conditionally compile all the VFIO code. This is because having
CONFIG_RTE_EAL_VFIO enabled doesn't guarantee that the VFIO support is
compiled in, because we're still dependent on kernel version.
Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
lib/librte_eal/linuxapp/eal/eal_interrupts.c | 203 +++++++++++++++++++-
lib/librte_eal/linuxapp/eal/include/eal_vfio.h | 49 +++++
.../linuxapp/eal/include/exec-env/rte_interrupts.h | 3 +
3 files changed, 250 insertions(+), 5 deletions(-)
create mode 100644 lib/librte_eal/linuxapp/eal/include/eal_vfio.h
diff --git a/lib/librte_eal/linuxapp/eal/eal_interrupts.c b/lib/librte_eal/linuxapp/eal/eal_interrupts.c
index 58e1ddf..cb95e2a 100644
--- a/lib/librte_eal/linuxapp/eal/eal_interrupts.c
+++ b/lib/librte_eal/linuxapp/eal/eal_interrupts.c
@@ -36,7 +36,6 @@
#include <stdlib.h>
#include <pthread.h>
#include <sys/queue.h>
-#include <malloc.h>
#include <stdarg.h>
#include <unistd.h>
#include <string.h>
@@ -44,6 +43,7 @@
#include <inttypes.h>
#include <sys/epoll.h>
#include <sys/signalfd.h>
+#include <sys/ioctl.h>
#include <rte_common.h>
#include <rte_interrupts.h>
@@ -66,6 +66,7 @@
#include <rte_spinlock.h>
#include "eal_private.h"
+#include "eal_vfio.h"
#define EAL_INTR_EPOLL_WAIT_FOREVER (-1)
@@ -87,6 +88,7 @@ union intr_pipefds{
*/
union rte_intr_read_buffer {
int uio_intr_count; /* for uio device */
+ uint64_t vfio_intr_count; /* for vfio device */
uint64_t timerfd_num; /* for timerfd */
char charbuf[16]; /* for others */
};
@@ -119,6 +121,173 @@ static struct rte_intr_source_list intr_sources;
/* interrupt handling thread */
static pthread_t intr_thread;
+/* VFIO interrupts */
+#ifdef VFIO_PRESENT
+
+#define IRQ_SET_BUF_LEN (sizeof(struct vfio_irq_set) + sizeof(int))
+
+/* enable legacy (INTx) interrupts */
+static int
+vfio_enable_intx(struct rte_intr_handle *intr_handle) {
+ struct vfio_irq_set * irq_set;
+ char irq_set_buf[IRQ_SET_BUF_LEN];
+ int len, ret;
+ int * fd_ptr;
+
+ len = sizeof(irq_set_buf);
+
+ /* enable INTx */
+ irq_set = (struct vfio_irq_set *) irq_set_buf;
+ irq_set->argsz = len;
+ irq_set->count = 1;
+ irq_set->flags = VFIO_IRQ_SET_DATA_EVENTFD | VFIO_IRQ_SET_ACTION_TRIGGER;
+ irq_set->index = VFIO_PCI_INTX_IRQ_INDEX;
+ irq_set->start = 0;
+ fd_ptr = (int*) &irq_set->data;
+ *fd_ptr = intr_handle->fd;
+
+ ret = ioctl(intr_handle->vfio_dev_fd, VFIO_DEVICE_SET_IRQS, irq_set);
+
+ if (ret) {
+ RTE_LOG(ERR, EAL, "Error enabling INTx interrupts for fd %d\n",
+ intr_handle->fd);
+ return -1;
+ }
+
+ /* unmask INTx after enabling */
+ memset(irq_set, 0, len);
+ len = sizeof(struct vfio_irq_set);
+ irq_set->argsz = len;
+ irq_set->count = 1;
+ irq_set->flags = VFIO_IRQ_SET_DATA_NONE | VFIO_IRQ_SET_ACTION_UNMASK;
+ irq_set->index = VFIO_PCI_INTX_IRQ_INDEX;
+ irq_set->start = 0;
+
+ ret = ioctl(intr_handle->vfio_dev_fd, VFIO_DEVICE_SET_IRQS, irq_set);
+
+ if (ret) {
+ RTE_LOG(ERR, EAL, "Error unmasking INTx interrupts for fd %d\n",
+ intr_handle->fd);
+ return -1;
+ }
+ return 0;
+}
+
+/* disable legacy (INTx) interrupts */
+static int
+vfio_disable_intx(struct rte_intr_handle *intr_handle) {
+ struct vfio_irq_set * irq_set;
+ char irq_set_buf[IRQ_SET_BUF_LEN];
+ int len, ret;
+
+ len = sizeof(struct vfio_irq_set);
+
+ /* mask interrupts before disabling */
+ irq_set = (struct vfio_irq_set *) irq_set_buf;
+ irq_set->argsz = len;
+ irq_set->count = 1;
+ irq_set->flags = VFIO_IRQ_SET_DATA_NONE | VFIO_IRQ_SET_ACTION_UNMASK;
+ irq_set->index = VFIO_PCI_INTX_IRQ_INDEX;
+ irq_set->start = 0;
+
+ ret = ioctl(intr_handle->vfio_dev_fd, VFIO_DEVICE_SET_IRQS, irq_set);
+
+ if (ret) {
+ RTE_LOG(ERR, EAL, "Error unmasking INTx interrupts for fd %d\n",
+ intr_handle->fd);
+ return -1;
+ }
+
+ /* disable INTx*/
+ memset(irq_set, 0, len);
+ irq_set->argsz = len;
+ irq_set->count = 0;
+ irq_set->flags = VFIO_IRQ_SET_DATA_NONE | VFIO_IRQ_SET_ACTION_TRIGGER;
+ irq_set->index = VFIO_PCI_INTX_IRQ_INDEX;
+ irq_set->start = 0;
+
+ ret = ioctl(intr_handle->vfio_dev_fd, VFIO_DEVICE_SET_IRQS, irq_set);
+
+ if (ret) {
+ RTE_LOG(ERR, EAL,
+ "Error disabling INTx interrupts for fd %d\n", intr_handle->fd);
+ return -1;
+ }
+ return 0;
+}
+
+/* enable MSI-X interrupts */
+static int
+vfio_enable_msix(struct rte_intr_handle *intr_handle) {
+ int len, ret;
+ char irq_set_buf[IRQ_SET_BUF_LEN];
+ struct vfio_irq_set * irq_set;
+ int * fd_ptr;
+
+ len = sizeof(irq_set_buf);
+
+ irq_set = (struct vfio_irq_set *) irq_set_buf;
+ irq_set->argsz = len;
+ irq_set->count = 1;
+ irq_set->flags = VFIO_IRQ_SET_DATA_EVENTFD | VFIO_IRQ_SET_ACTION_TRIGGER;
+ irq_set->index = VFIO_PCI_MSIX_IRQ_INDEX;
+ irq_set->start = 0;
+ fd_ptr = (int*) &irq_set->data;
+ *fd_ptr = intr_handle->fd;
+
+ ret = ioctl(intr_handle->vfio_dev_fd, VFIO_DEVICE_SET_IRQS, irq_set);
+
+ if (ret) {
+ RTE_LOG(ERR, EAL, "Error enabling MSI-X interrupts for fd %d\n",
+ intr_handle->fd);
+ return -1;
+ }
+
+ /* manually trigger interrupt to enable it */
+ memset(irq_set, 0, len);
+ len = sizeof(struct vfio_irq_set);
+ irq_set->argsz = len;
+ irq_set->count = 1;
+ irq_set->flags = VFIO_IRQ_SET_DATA_NONE | VFIO_IRQ_SET_ACTION_TRIGGER;
+ irq_set->index = VFIO_PCI_MSIX_IRQ_INDEX;
+ irq_set->start = 0;
+
+ ret = ioctl(intr_handle->vfio_dev_fd, VFIO_DEVICE_SET_IRQS, irq_set);
+
+ if (ret) {
+ RTE_LOG(ERR, EAL, "Error triggering MSI-X interrupts for fd %d\n",
+ intr_handle->fd);
+ return -1;
+ }
+ return 0;
+}
+
+/* disable MSI-X interrupts */
+static int
+vfio_disable_msix(struct rte_intr_handle *intr_handle) {
+ struct vfio_irq_set * irq_set;
+ char irq_set_buf[IRQ_SET_BUF_LEN];
+ int len, ret;
+
+ len = sizeof(struct vfio_irq_set);
+
+ irq_set = (struct vfio_irq_set *) irq_set_buf;
+ irq_set->argsz = len;
+ irq_set->count = 0;
+ irq_set->flags = VFIO_IRQ_SET_DATA_NONE | VFIO_IRQ_SET_ACTION_TRIGGER;
+ irq_set->index = VFIO_PCI_MSIX_IRQ_INDEX;
+ irq_set->start = 0;
+
+ ret = ioctl(intr_handle->vfio_dev_fd, VFIO_DEVICE_SET_IRQS, irq_set);
+
+ if (ret)
+ RTE_LOG(ERR, EAL,
+ "Error disabling MSI-X interrupts for fd %d\n", intr_handle->fd);
+
+ return ret;
+}
+#endif
+
int
rte_intr_callback_register(struct rte_intr_handle *intr_handle,
rte_intr_callback_fn cb, void *cb_arg)
@@ -276,6 +445,16 @@ rte_intr_enable(struct rte_intr_handle *intr_handle)
/* not used at this moment */
case RTE_INTR_HANDLE_ALARM:
return -1;
+#ifdef VFIO_PRESENT
+ case RTE_INTR_HANDLE_VFIO_MSIX:
+ if (vfio_enable_msix(intr_handle))
+ return -1;
+ break;
+ case RTE_INTR_HANDLE_VFIO_LEGACY:
+ if (vfio_enable_intx(intr_handle))
+ return -1;
+ break;
+#endif
/* unknown handle type */
default:
RTE_LOG(ERR, EAL,
@@ -300,7 +479,7 @@ rte_intr_disable(struct rte_intr_handle *intr_handle)
case RTE_INTR_HANDLE_UIO:
if (write(intr_handle->fd, &value, sizeof(value)) < 0){
RTE_LOG(ERR, EAL,
- "Error enabling interrupts for fd %d\n",
+ "Error disabling interrupts for fd %d\n",
intr_handle->fd);
return -1;
}
@@ -308,6 +487,16 @@ rte_intr_disable(struct rte_intr_handle *intr_handle)
/* not used at this moment */
case RTE_INTR_HANDLE_ALARM:
return -1;
+#ifdef VFIO_PRESENT
+ case RTE_INTR_HANDLE_VFIO_MSIX:
+ if (vfio_disable_msix(intr_handle))
+ return -1;
+ break;
+ case RTE_INTR_HANDLE_VFIO_LEGACY:
+ if (vfio_disable_intx(intr_handle))
+ return -1;
+ break;
+#endif
/* unknown handle type */
default:
RTE_LOG(ERR, EAL,
@@ -357,10 +546,14 @@ eal_intr_process_interrupts(struct epoll_event *events, int nfds)
/* set the length to be read dor different handle type */
switch (src->intr_handle.type) {
case RTE_INTR_HANDLE_UIO:
- bytes_read = 4;
+ bytes_read = sizeof(buf.uio_intr_count);
break;
case RTE_INTR_HANDLE_ALARM:
- bytes_read = sizeof(uint64_t);
+ bytes_read = sizeof(buf.timerfd_num);
+ break;
+ case RTE_INTR_HANDLE_VFIO_MSIX:
+ case RTE_INTR_HANDLE_VFIO_LEGACY:
+ bytes_read = sizeof(buf.vfio_intr_count);
break;
default:
bytes_read = 1;
@@ -397,7 +590,7 @@ eal_intr_process_interrupts(struct epoll_event *events, int nfds)
active_cb.cb_fn(&src->intr_handle,
active_cb.cb_arg);
- /*get the lcok back. */
+ /*get the lock back. */
rte_spinlock_lock(&intr_lock);
}
}
diff --git a/lib/librte_eal/linuxapp/eal/include/eal_vfio.h b/lib/librte_eal/linuxapp/eal/include/eal_vfio.h
new file mode 100644
index 0000000..ca4982b
--- /dev/null
+++ b/lib/librte_eal/linuxapp/eal/include/eal_vfio.h
@@ -0,0 +1,49 @@
+/*-
+ * BSD LICENSE
+ *
+ * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef EAL_VFIO_H_
+#define EAL_VFIO_H_
+
+/*
+ * determine if VFIO is present on the system
+ */
+#ifdef RTE_EAL_VFIO
+#include <linux/version.h>
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0)
+#include <linux/vfio.h>
+
+#define VFIO_PRESENT
+#endif /* kernel version */
+#endif /* RTE_EAL_VFIO */
+
+#endif /* EAL_VFIO_H_ */
diff --git a/lib/librte_eal/linuxapp/eal/include/exec-env/rte_interrupts.h b/lib/librte_eal/linuxapp/eal/include/exec-env/rte_interrupts.h
index 6733948..b160efe 100644
--- a/lib/librte_eal/linuxapp/eal/include/exec-env/rte_interrupts.h
+++ b/lib/librte_eal/linuxapp/eal/include/exec-env/rte_interrupts.h
@@ -41,12 +41,15 @@
enum rte_intr_handle_type {
RTE_INTR_HANDLE_UNKNOWN = 0,
RTE_INTR_HANDLE_UIO, /**< uio device handle */
+ RTE_INTR_HANDLE_VFIO_LEGACY, /**< vfio device handle (legacy) */
+ RTE_INTR_HANDLE_VFIO_MSIX, /**< uio device handle (MSIX) */
RTE_INTR_HANDLE_ALARM, /**< alarm handle */
RTE_INTR_HANDLE_MAX
};
/** Handle for interrupts. */
struct rte_intr_handle {
+ int vfio_dev_fd; /**< VFIO device file descriptor */
int fd; /**< file descriptor */
enum rte_intr_handle_type type; /**< handle type */
};
--
1.7.0.7
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2014-05-27 14:45 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-27 3:02 [dpdk-dev] [PATCH v2 07/16] Add support for VFIO interrupts, add VFIO header Xu, HuilongX
-- strict thread matches above, loose matches on Subject: below --
2014-05-01 11:05 [dpdk-dev] [PATCH 00/16] [RFC] [VFIO] Add VFIO support to DPDK Burakov, Anatoly
2014-05-19 15:51 ` [dpdk-dev] [PATCH v2 07/16] Add support for VFIO interrupts, add VFIO header Anatoly Burakov
2014-05-21 16:07 ` Thomas Monjalon
2014-05-22 12:45 ` Burakov, Anatoly
2014-05-22 12:49 ` Thomas Monjalon
2014-05-22 12:54 ` Burakov, Anatoly
2014-05-27 14:29 ` Burakov, Anatoly
2014-05-27 14:38 ` Thomas Monjalon
2014-05-27 14:40 ` Burakov, Anatoly
2014-05-27 14:46 ` Thomas Monjalon
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).