net/virtio: fix incorrect cast of void *
[dpdk.git] / lib / librte_eal / linuxapp / eal / eal_interrupts.c
index e293728..4b5e6da 100644 (file)
@@ -51,7 +51,6 @@
 #include <rte_common.h>
 #include <rte_interrupts.h>
 #include <rte_memory.h>
-#include <rte_memzone.h>
 #include <rte_launch.h>
 #include <rte_eal.h>
 #include <rte_per_lcore.h>
 #include <rte_branch_prediction.h>
 #include <rte_debug.h>
 #include <rte_log.h>
-#include <rte_pci.h>
 #include <rte_malloc.h>
 #include <rte_errno.h>
 #include <rte_spinlock.h>
+#include <rte_pause.h>
 
 #include "eal_private.h"
 #include "eal_vfio.h"
@@ -279,29 +278,6 @@ vfio_disable_msi(const struct rte_intr_handle *intr_handle) {
        return ret;
 }
 
-static int
-get_max_intr(const struct rte_intr_handle *intr_handle)
-{
-       struct rte_intr_source *src;
-
-       TAILQ_FOREACH(src, &intr_sources, next) {
-               if (src->intr_handle.fd != intr_handle->fd)
-                       continue;
-
-               if (src->intr_handle.max_intr < intr_handle->max_intr)
-                       src->intr_handle.max_intr = intr_handle->max_intr;
-               if (!src->intr_handle.max_intr)
-                       src->intr_handle.max_intr = 1;
-               else if (src->intr_handle.max_intr > RTE_MAX_RXTX_INTR_VEC_ID)
-                       src->intr_handle.max_intr
-                               = RTE_MAX_RXTX_INTR_VEC_ID + 1;
-
-               return src->intr_handle.max_intr;
-       }
-
-       return -1;
-}
-
 /* enable MSI-X interrupts */
 static int
 vfio_enable_msix(const struct rte_intr_handle *intr_handle) {
@@ -314,15 +290,10 @@ vfio_enable_msix(const struct rte_intr_handle *intr_handle) {
 
        irq_set = (struct vfio_irq_set *) irq_set_buf;
        irq_set->argsz = len;
-
-       ret = get_max_intr(intr_handle);
-       if (ret < 0) {
-               RTE_LOG(ERR, EAL, "Invalid number of MSI-X irqs for fd %d\n",
-                       intr_handle->fd);
-               return -1;
-       }
-
-       irq_set->count = ret;
+       /* 0 < irq_set->count < RTE_MAX_RXTX_INTR_VEC_ID + 1 */
+       irq_set->count = intr_handle->max_intr ?
+               (intr_handle->max_intr > RTE_MAX_RXTX_INTR_VEC_ID + 1 ?
+               RTE_MAX_RXTX_INTR_VEC_ID + 1 : intr_handle->max_intr) : 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;
@@ -772,8 +743,7 @@ eal_intr_process_interrupts(struct epoll_event *events, int nfds)
                                rte_spinlock_unlock(&intr_lock);
 
                                /* call the actual callback */
-                               active_cb.cb_fn(&src->intr_handle,
-                                       active_cb.cb_arg);
+                               active_cb.cb_fn(active_cb.cb_arg);
 
                                /*get the lock back. */
                                rte_spinlock_lock(&intr_lock);
@@ -903,7 +873,7 @@ eal_intr_thread_main(__rte_unused void *arg)
 int
 rte_eal_intr_init(void)
 {
-       int ret = 0, ret_1 = 0;
+       int ret = 0;
        char thread_name[RTE_MAX_THREAD_NAME_LEN];
 
        /* init the global interrupt source head */
@@ -919,30 +889,23 @@ rte_eal_intr_init(void)
        }
 
        /* create the host thread to wait/handle the interrupt */
-       ret = pthread_create(&intr_thread, NULL,
+       snprintf(thread_name, sizeof(thread_name), "eal-intr-thread");
+       ret = rte_ctrl_thread_create(&intr_thread, thread_name, NULL,
                        eal_intr_thread_main, NULL);
        if (ret != 0) {
-               rte_errno = ret;
+               rte_errno = -ret;
                RTE_LOG(ERR, EAL,
                        "Failed to create thread for interrupt handling\n");
-       } else {
-               /* Set thread_name for aid in debugging. */
-               snprintf(thread_name, RTE_MAX_THREAD_NAME_LEN,
-                       "eal-intr-thread");
-               ret_1 = rte_thread_setname(intr_thread, thread_name);
-               if (ret_1 != 0)
-                       RTE_LOG(DEBUG, EAL,
-                       "Failed to set thread name for interrupt handling\n");
        }
 
-       return -ret;
+       return ret;
 }
 
 static void
 eal_intr_proc_rxtx_intr(int fd, const struct rte_intr_handle *intr_handle)
 {
        union rte_intr_read_buffer buf;
-       int bytes_read = 1;
+       int bytes_read = 0;
        int nbytes;
 
        switch (intr_handle->type) {
@@ -958,11 +921,9 @@ eal_intr_proc_rxtx_intr(int fd, const struct rte_intr_handle *intr_handle)
                break;
 #endif
        case RTE_INTR_HANDLE_VDEV:
-               /* for vdev, fd points to:
-                * a. eventfd which does not need to read out;
-                * b. datapath fd which needs PMD to read out.
-                */
-               return;
+               bytes_read = intr_handle->efd_counter_size;
+               /* For vdev, number of bytes to read is set by driver */
+               break;
        case RTE_INTR_HANDLE_EXT:
                return;
        default:
@@ -975,6 +936,8 @@ eal_intr_proc_rxtx_intr(int fd, const struct rte_intr_handle *intr_handle)
         * read out to clear the ready-to-be-read flag
         * for epoll_wait.
         */
+       if (bytes_read == 0)
+               return;
        do {
                nbytes = read(fd, &buf, bytes_read);
                if (nbytes < 0) {
@@ -1234,7 +1197,12 @@ rte_intr_efd_enable(struct rte_intr_handle *intr_handle, uint32_t nb_efd)
                intr_handle->nb_efd   = n;
                intr_handle->max_intr = NB_OTHER_INTR + n;
        } else if (intr_handle->type == RTE_INTR_HANDLE_VDEV) {
-               /* do nothing, and let vdev driver to initialize this struct */
+               /* only check, initialization would be done in vdev driver.*/
+               if (intr_handle->efd_counter_size >
+                   sizeof(union rte_intr_read_buffer)) {
+                       RTE_LOG(ERR, EAL, "the efd_counter_size is oversized");
+                       return -EINVAL;
+               }
        } else {
                intr_handle->efds[0]  = intr_handle->fd;
                intr_handle->nb_efd   = RTE_MIN(nb_efd, 1U);