]> git.droids-corp.org - dpdk.git/commitdiff
alarm: remove direct access to interrupt handle
authorHarman Kalra <hkalra@marvell.com>
Fri, 22 Oct 2021 20:49:32 +0000 (02:19 +0530)
committerDavid Marchand <david.marchand@redhat.com>
Mon, 25 Oct 2021 19:20:12 +0000 (21:20 +0200)
Removing direct access to interrupt handle structure fields,
rather use respective get set APIs for the same.
Making changes to all the libraries access the interrupt handle fields.

Implementing alarm cleanup routine, where the memory allocated
for interrupt instance can be freed.

Signed-off-by: Harman Kalra <hkalra@marvell.com>
Signed-off-by: David Marchand <david.marchand@redhat.com>
Tested-by: Raslan Darawsheh <rasland@nvidia.com>
lib/eal/common/eal_private.h
lib/eal/freebsd/eal.c
lib/eal/freebsd/eal_alarm.c
lib/eal/linux/eal.c
lib/eal/linux/eal_alarm.c

index 86dab1f057c0fecede2b4a24da4c1bdd819fe045..36bcc0b5a49227580c40c6a1d0bb16ca468cef05 100644 (file)
@@ -163,6 +163,16 @@ int rte_eal_intr_init(void);
  */
 int rte_eal_alarm_init(void);
 
+/**
+ * Alarm mechanism cleanup.
+ *
+ * This function is private to EAL.
+ *
+ * @return
+ *  0 on success, negative on error
+ */
+void rte_eal_alarm_cleanup(void);
+
 /**
  * Function is to check if the kernel module(like, vfio, vfio_iommu_type1,
  * etc.) loaded.
index 56a60f13e90e76689ff7046cc870a1068e515577..9935356ed4c4c951df6dd4778ad84753c5eabcc3 100644 (file)
@@ -975,6 +975,7 @@ rte_eal_cleanup(void)
        rte_mp_channel_cleanup();
        /* after this point, any DPDK pointers will become dangling */
        rte_eal_memory_detach();
+       rte_eal_alarm_cleanup();
        rte_trace_save();
        eal_trace_fini();
        eal_cleanup_config(internal_conf);
index c38b2e04f81167828568c4b8ba18576869391bfb..1023c329378fd01d2f1cab460bee13912a5ee32f 100644 (file)
@@ -32,7 +32,6 @@
 
 struct alarm_entry {
        LIST_ENTRY(alarm_entry) next;
-       struct rte_intr_handle handle;
        struct timespec time;
        rte_eal_alarm_callback cb_fn;
        void *cb_arg;
@@ -43,22 +42,46 @@ struct alarm_entry {
 static LIST_HEAD(alarm_list, alarm_entry) alarm_list = LIST_HEAD_INITIALIZER();
 static rte_spinlock_t alarm_list_lk = RTE_SPINLOCK_INITIALIZER;
 
-static struct rte_intr_handle intr_handle = {.fd = -1 };
+static struct rte_intr_handle *intr_handle;
 static void eal_alarm_callback(void *arg);
 
+void
+rte_eal_alarm_cleanup(void)
+{
+       rte_intr_instance_free(intr_handle);
+}
+
 int
 rte_eal_alarm_init(void)
 {
-       intr_handle.type = RTE_INTR_HANDLE_ALARM;
+       int fd;
+
+       intr_handle = rte_intr_instance_alloc(RTE_INTR_INSTANCE_F_PRIVATE);
+       if (intr_handle == NULL) {
+               RTE_LOG(ERR, EAL, "Fail to allocate intr_handle\n");
+               goto error;
+       }
+
+       if (rte_intr_type_set(intr_handle, RTE_INTR_HANDLE_ALARM))
+               goto error;
+
+       if (rte_intr_fd_set(intr_handle, -1))
+               goto error;
 
        /* on FreeBSD, timers don't use fd's, and their identifiers are stored
         * in separate namespace from fd's, so using any value is OK. however,
         * EAL interrupts handler expects fd's to be unique, so use an actual fd
         * to guarantee unique timer identifier.
         */
-       intr_handle.fd = open("/dev/zero", O_RDONLY);
+       fd = open("/dev/zero", O_RDONLY);
+
+       if (rte_intr_fd_set(intr_handle, fd))
+               goto error;
 
        return 0;
+error:
+       rte_intr_instance_free(intr_handle);
+       return -1;
 }
 
 static inline int
@@ -118,7 +141,7 @@ unregister_current_callback(void)
                ap = LIST_FIRST(&alarm_list);
 
                do {
-                       ret = rte_intr_callback_unregister(&intr_handle,
+                       ret = rte_intr_callback_unregister(intr_handle,
                                eal_alarm_callback, &ap->time);
                } while (ret == -EAGAIN);
        }
@@ -136,7 +159,7 @@ register_first_callback(void)
                ap = LIST_FIRST(&alarm_list);
 
                /* register a new callback */
-               ret = rte_intr_callback_register(&intr_handle,
+               ret = rte_intr_callback_register(intr_handle,
                                eal_alarm_callback, &ap->time);
        }
        return ret;
index 0d0fc66668a9e2b098b174a724c00d451d679fa9..81fdebc6a0cf5257fd98131afc51eedb79dfd5ae 100644 (file)
@@ -1368,6 +1368,7 @@ rte_eal_cleanup(void)
        rte_mp_channel_cleanup();
        /* after this point, any DPDK pointers will become dangling */
        rte_eal_memory_detach();
+       rte_eal_alarm_cleanup();
        rte_trace_save();
        eal_trace_fini();
        eal_cleanup_config(internal_conf);
index 3252c6fa590997e3a188e01c56032f36051d8678..3b5e894595c0be9ade377c474cd8b985e7a8a94d 100644 (file)
@@ -54,22 +54,40 @@ struct alarm_entry {
 static LIST_HEAD(alarm_list, alarm_entry) alarm_list = LIST_HEAD_INITIALIZER();
 static rte_spinlock_t alarm_list_lk = RTE_SPINLOCK_INITIALIZER;
 
-static struct rte_intr_handle intr_handle = {.fd = -1 };
+static struct rte_intr_handle *intr_handle;
 static int handler_registered = 0;
 static void eal_alarm_callback(void *arg);
 
+void
+rte_eal_alarm_cleanup(void)
+{
+       rte_intr_instance_free(intr_handle);
+}
+
 int
 rte_eal_alarm_init(void)
 {
-       intr_handle.type = RTE_INTR_HANDLE_ALARM;
+
+       intr_handle = rte_intr_instance_alloc(RTE_INTR_INSTANCE_F_PRIVATE);
+       if (intr_handle == NULL) {
+               RTE_LOG(ERR, EAL, "Fail to allocate intr_handle\n");
+               goto error;
+       }
+
+       if (rte_intr_type_set(intr_handle, RTE_INTR_HANDLE_ALARM))
+               goto error;
+
        /* create a timerfd file descriptor */
-       intr_handle.fd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK);
-       if (intr_handle.fd == -1)
+       if (rte_intr_fd_set(intr_handle,
+                       timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK)))
                goto error;
 
+       if (rte_intr_fd_get(intr_handle) == -1)
+               goto error;
        return 0;
 
 error:
+       rte_intr_instance_free(intr_handle);
        rte_errno = errno;
        return -1;
 }
@@ -109,7 +127,7 @@ eal_alarm_callback(void *arg __rte_unused)
 
                atime.it_value.tv_sec -= now.tv_sec;
                atime.it_value.tv_nsec -= now.tv_nsec;
-               timerfd_settime(intr_handle.fd, 0, &atime, NULL);
+               timerfd_settime(rte_intr_fd_get(intr_handle), 0, &atime, NULL);
        }
        rte_spinlock_unlock(&alarm_list_lk);
 }
@@ -140,7 +158,7 @@ rte_eal_alarm_set(uint64_t us, rte_eal_alarm_callback cb_fn, void *cb_arg)
        rte_spinlock_lock(&alarm_list_lk);
        if (!handler_registered) {
                /* registration can fail, callback can be registered later */
-               if (rte_intr_callback_register(&intr_handle,
+               if (rte_intr_callback_register(intr_handle,
                                eal_alarm_callback, NULL) == 0)
                        handler_registered = 1;
        }
@@ -170,7 +188,7 @@ rte_eal_alarm_set(uint64_t us, rte_eal_alarm_callback cb_fn, void *cb_arg)
                                .tv_nsec = (us % US_PER_S) * NS_PER_US,
                        },
                };
-               ret |= timerfd_settime(intr_handle.fd, 0, &alarm_time, NULL);
+               ret |= timerfd_settime(rte_intr_fd_get(intr_handle), 0, &alarm_time, NULL);
        }
        rte_spinlock_unlock(&alarm_list_lk);