DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] eal: check for interrupt context
@ 2019-11-17 19:36 Harman Kalra
  2019-11-17 20:03 ` Stephen Hemminger
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Harman Kalra @ 2019-11-17 19:36 UTC (permalink / raw)
  To: Bruce Richardson; +Cc: dev, Harman Kalra

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(+)

diff --git a/lib/librte_eal/common/include/rte_interrupts.h b/lib/librte_eal/common/include/rte_interrupts.h
index e3b406abc..1e64f5329 100644
--- a/lib/librte_eal/common/include/rte_interrupts.h
+++ b/lib/librte_eal/common/include/rte_interrupts.h
@@ -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
diff --git a/lib/librte_eal/freebsd/eal/eal_interrupts.c b/lib/librte_eal/freebsd/eal/eal_interrupts.c
index f6831b790..c60fd782a 100644
--- a/lib/librte_eal/freebsd/eal/eal_interrupts.c
+++ b/lib/librte_eal/freebsd/eal/eal_interrupts.c
@@ -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;
+}
diff --git a/lib/librte_eal/linux/eal/eal_interrupts.c b/lib/librte_eal/linux/eal/eal_interrupts.c
index 1955324d3..516cbbfa8 100644
--- a/lib/librte_eal/linux/eal/eal_interrupts.c
+++ b/lib/librte_eal/linux/eal/eal_interrupts.c
@@ -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;
+}
diff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map
index f1982f2f7..ab5dd5b47 100644
--- a/lib/librte_eal/rte_eal_version.map
+++ b/lib/librte_eal/rte_eal_version.map
@@ -427,4 +427,5 @@ EXPERIMENTAL {
 
 	# added in 19.11
 	rte_log_get_stream;
+	rte_thread_is_intr;
 };
-- 
2.18.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [dpdk-dev] [PATCH] eal: check for interrupt context
  2019-11-17 19:36 [dpdk-dev] [PATCH] eal: check for interrupt context Harman Kalra
@ 2019-11-17 20:03 ` Stephen Hemminger
  2019-11-18  7:43   ` [dpdk-dev] [PATCH v2] eal: add API to check if its " Harman Kalra
  2019-11-17 20:04 ` [dpdk-dev] [PATCH] eal: check for " Stephen Hemminger
  2019-11-18 10:18 ` Burakov, Anatoly
  2 siblings, 1 reply; 5+ messages in thread
From: Stephen Hemminger @ 2019-11-17 20:03 UTC (permalink / raw)
  To: Harman Kalra; +Cc: Bruce Richardson, dev

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()


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [dpdk-dev] [PATCH] eal: check for interrupt context
  2019-11-17 19:36 [dpdk-dev] [PATCH] eal: check for interrupt context Harman Kalra
  2019-11-17 20:03 ` Stephen Hemminger
@ 2019-11-17 20:04 ` Stephen Hemminger
  2019-11-18 10:18 ` Burakov, Anatoly
  2 siblings, 0 replies; 5+ messages in thread
From: Stephen Hemminger @ 2019-11-17 20:04 UTC (permalink / raw)
  To: Harman Kalra; +Cc: Bruce Richardson, dev

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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [dpdk-dev] [PATCH v2] eal: add API to check if its interrupt context
  2019-11-17 20:03 ` Stephen Hemminger
@ 2019-11-18  7:43   ` Harman Kalra
  0 siblings, 0 replies; 5+ messages in thread
From: Harman Kalra @ 2019-11-18  7:43 UTC (permalink / raw)
  To: stephen, Bruce Richardson; +Cc: dev, Harman Kalra

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(+)

diff --git a/lib/librte_eal/common/include/rte_interrupts.h b/lib/librte_eal/common/include/rte_interrupts.h
index e3b406abc..0a82e28a8 100644
--- a/lib/librte_eal/common/include/rte_interrupts.h
+++ b/lib/librte_eal/common/include/rte_interrupts.h
@@ -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
diff --git a/lib/librte_eal/freebsd/eal/eal_interrupts.c b/lib/librte_eal/freebsd/eal/eal_interrupts.c
index f6831b790..ce2a27b4a 100644
--- a/lib/librte_eal/freebsd/eal/eal_interrupts.c
+++ b/lib/librte_eal/freebsd/eal/eal_interrupts.c
@@ -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());
+}
diff --git a/lib/librte_eal/linux/eal/eal_interrupts.c b/lib/librte_eal/linux/eal/eal_interrupts.c
index 1955324d3..c00f5a575 100644
--- a/lib/librte_eal/linux/eal/eal_interrupts.c
+++ b/lib/librte_eal/linux/eal/eal_interrupts.c
@@ -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());
+}
diff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map
index f1982f2f7..ab5dd5b47 100644
--- a/lib/librte_eal/rte_eal_version.map
+++ b/lib/librte_eal/rte_eal_version.map
@@ -427,4 +427,5 @@ EXPERIMENTAL {
 
 	# added in 19.11
 	rte_log_get_stream;
+	rte_thread_is_intr;
 };
-- 
2.18.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [dpdk-dev] [PATCH] eal: check for interrupt context
  2019-11-17 19:36 [dpdk-dev] [PATCH] eal: check for interrupt context Harman Kalra
  2019-11-17 20:03 ` Stephen Hemminger
  2019-11-17 20:04 ` [dpdk-dev] [PATCH] eal: check for " Stephen Hemminger
@ 2019-11-18 10:18 ` Burakov, Anatoly
  2 siblings, 0 replies; 5+ messages in thread
From: Burakov, Anatoly @ 2019-11-18 10:18 UTC (permalink / raw)
  To: Harman Kalra, Bruce Richardson; +Cc: dev

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?

-- 
Thanks,
Anatoly

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-11-18 10:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-17 19:36 [dpdk-dev] [PATCH] eal: check for interrupt context Harman Kalra
2019-11-17 20:03 ` Stephen Hemminger
2019-11-18  7:43   ` [dpdk-dev] [PATCH v2] eal: add API to check if its " Harman Kalra
2019-11-17 20:04 ` [dpdk-dev] [PATCH] eal: check for " Stephen Hemminger
2019-11-18 10:18 ` Burakov, Anatoly

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).