eal/linux: add interrupt counter size for vdev
authorJingjing Wu <jingjing.wu@intel.com>
Thu, 24 Aug 2017 02:10:56 +0000 (10:10 +0800)
committerThomas Monjalon <thomas@monjalon.net>
Tue, 7 Nov 2017 00:42:04 +0000 (01:42 +0100)
For virtual device, the rte_intr_handle struct is
initialized by the virtual device driver, including
the event fd assignment. If the event fd need to be
read for clean, an argument is required for the proper
event fd read.

This patch adds efd_counter_size in rte_intr_handle
struct to tell the rx interrupt process the read size.

Signed-off-by: Jingjing Wu <jingjing.wu@intel.com>
Reviewed-by: Jianfeng Tan <jianfeng.tan@intel.com>
drivers/net/virtio/virtio_user/virtio_user_dev.c
lib/librte_eal/common/include/rte_eal_interrupts.h
lib/librte_eal/linuxapp/eal/eal_interrupts.c

index 7941271..906d7a2 100644 (file)
@@ -270,6 +270,8 @@ virtio_user_fill_intr_handle(struct virtio_user_dev *dev)
        eth_dev->intr_handle->nb_efd = dev->max_queue_pairs;
        eth_dev->intr_handle->max_intr = dev->max_queue_pairs + 1;
        eth_dev->intr_handle->type = RTE_INTR_HANDLE_VDEV;
+       /* For virtio vdev, no need to read counter for clean */
+       eth_dev->intr_handle->efd_counter_size = 0;
        if (dev->vhostfd >= 0)
                eth_dev->intr_handle->fd = dev->vhostfd;
 
index 5628f62..031f78c 100644 (file)
@@ -103,6 +103,7 @@ struct rte_intr_handle {
        enum rte_intr_handle_type type;  /**< handle type */
        uint32_t max_intr;             /**< max interrupt requested */
        uint32_t nb_efd;               /**< number of available efd(event fd) */
+       uint8_t efd_counter_size;      /**< size of efd counter, used for vdev */
        int efds[RTE_MAX_RXTX_INTR_VEC_ID];  /**< intr vectors/efds mapping */
        struct rte_epoll_event elist[RTE_MAX_RXTX_INTR_VEC_ID];
                                       /**< intr vector epoll event */
index 8f65872..1c20693 100644 (file)
@@ -912,7 +912,7 @@ 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) {
@@ -928,11 +928,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:
@@ -945,6 +943,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) {
@@ -1204,7 +1204,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);