eal: check for interrupt context
Checks
Commit Message
Added an API to check if current execution is in interrupt
context. This will be helpful to handle nested interrupt cases.
Signed-off-by: Harman Kalra <hkalra@marvell.com>
---
lib/librte_eal/common/include/rte_interrupts.h | 13 +++++++++++++
lib/librte_eal/freebsd/eal/eal_interrupts.c | 8 ++++++++
lib/librte_eal/linux/eal/eal_interrupts.c | 8 ++++++++
lib/librte_eal/rte_eal_version.map | 1 +
4 files changed, 30 insertions(+)
Comments
On Sun, 17 Nov 2019 19:36:11 +0000
Harman Kalra <hkalra@marvell.com> wrote:
> +int rte_thread_is_intr(void)
> +{
> + if (pthread_equal(intr_thread, pthread_self()))
> + return true;
> + else
> + return false;
> +}
A couple of things here.
1. true/false implies that this is of type bool not int.
2. Why the if, you can just do:
return pthread_equal()
On Sun, 17 Nov 2019 19:36:11 +0000
Harman Kalra <hkalra@marvell.com> wrote:
> Added an API to check if current execution is in interrupt
> context. This will be helpful to handle nested interrupt cases.
>
> Signed-off-by: Harman Kalra <hkalra@marvell.com>
Please add a user of this routine. Unused code is added burden.
On 17-Nov-19 7:36 PM, Harman Kalra wrote:
> Added an API to check if current execution is in interrupt
> context. This will be helpful to handle nested interrupt cases.
>
> Signed-off-by: Harman Kalra <hkalra@marvell.com>
> ---
This is a great idea. It would be nice to add checks for is_intr()
inside rte_malloc routines, as currently attempting to rte_malloc (or
allocate anything) may lead to a deadlock. Is this intended for this
release, or future one?
@@ -138,6 +138,19 @@ int rte_intr_disable(const struct rte_intr_handle *intr_handle);
__rte_experimental
int rte_intr_ack(const struct rte_intr_handle *intr_handle);
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice
+ *
+ * Check if currently executing in interrupt context
+ *
+ * @return
+ * On success, returns 1, else 0
+ */
+__rte_experimental
+int
+rte_thread_is_intr(void);
+
#ifdef __cplusplus
}
#endif
@@ -671,3 +671,11 @@ rte_intr_free_epoll_fd(struct rte_intr_handle *intr_handle)
{
RTE_SET_USED(intr_handle);
}
+
+int rte_thread_is_intr(void)
+{
+ if (pthread_equal(intr_thread, pthread_self()))
+ return true;
+ else
+ return false;
+}
@@ -1487,3 +1487,11 @@ rte_intr_cap_multiple(struct rte_intr_handle *intr_handle)
return 0;
}
+
+int rte_thread_is_intr(void)
+{
+ if (pthread_equal(intr_thread, pthread_self()))
+ return true;
+ else
+ return false;
+}
@@ -427,4 +427,5 @@ EXPERIMENTAL {
# added in 19.11
rte_log_get_stream;
+ rte_thread_is_intr;
};