[v2] eal: add API to check if its 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>
---
V2:
* Removed unnecessary if statement.
* Reworded subject line
* Updated return values of API
lib/librte_eal/common/include/rte_interrupts.h | 15 +++++++++++++++
lib/librte_eal/freebsd/eal/eal_interrupts.c | 5 +++++
lib/librte_eal/linux/eal/eal_interrupts.c | 5 +++++
lib/librte_eal/rte_eal_version.map | 1 +
4 files changed, 26 insertions(+)
@@ -138,6 +138,21 @@ 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
+ * - positive in case of interrupt context
+ * - zero in case of process context
+ * - negative if unsuccessful
+ */
+__rte_experimental
+int
+rte_thread_is_intr(void);
+
#ifdef __cplusplus
}
#endif
@@ -671,3 +671,8 @@ rte_intr_free_epoll_fd(struct rte_intr_handle *intr_handle)
{
RTE_SET_USED(intr_handle);
}
+
+int rte_thread_is_intr(void)
+{
+ return pthread_equal(intr_thread, pthread_self());
+}
@@ -1487,3 +1487,8 @@ rte_intr_cap_multiple(struct rte_intr_handle *intr_handle)
return 0;
}
+
+int rte_thread_is_intr(void)
+{
+ return pthread_equal(intr_thread, pthread_self());
+}
@@ -427,4 +427,5 @@ EXPERIMENTAL {
# added in 19.11
rte_log_get_stream;
+ rte_thread_is_intr;
};