All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] eal: add function to check if primary proc alive
@ 2016-01-20 13:25 Harry van Haaren
  2016-01-21  6:14 ` Qiu, Michael
                   ` (2 more replies)
  0 siblings, 3 replies; 43+ messages in thread
From: Harry van Haaren @ 2016-01-20 13:25 UTC (permalink / raw)
  To: david.marchand; +Cc: dev

This patch adds a new function to the EAL API:
int rte_eal_primary_proc_alive(const char *path);

The function indicates if a primary process is alive right now.
This functionality is implemented by testing for a write-
lock on the config file, and the function tests for a lock.

The use case for this functionality is that a secondary
process can wait until a primary process starts by polling
the function and waiting. When the primary is running, the
secondary continues to poll to detect if the primary process
has quit unexpectedly, the secondary process can detect this.

The RTE_MAGIC number is written to the shared config by the
primary process, this is the signal to the secondary process
that the EAL is set up, and ready to be used. The function
rte_eal_mcfg_complete() writes RTE_MAGIC. This has been
delayed in the EAL init proceedure, as the PCI probing in
the primary process can interfere with the secondary running.

Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>
---
 doc/guides/rel_notes/release_2_3.rst            |  7 +++++++
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  8 ++++++++
 lib/librte_eal/common/include/rte_eal.h         | 19 +++++++++++++++++++
 lib/librte_eal/linuxapp/eal/eal.c               | 18 ++++++++++++++++--
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |  7 +++++++
 5 files changed, 57 insertions(+), 2 deletions(-)

diff --git a/doc/guides/rel_notes/release_2_3.rst b/doc/guides/rel_notes/release_2_3.rst
index 99de186..14b5b06 100644
--- a/doc/guides/rel_notes/release_2_3.rst
+++ b/doc/guides/rel_notes/release_2_3.rst
@@ -11,6 +11,13 @@ Resolved Issues
 EAL
 ~~~
 
+* **Added rte_eal_primary_proc_alive() function**
+
+  A new function ``rte_eal_primary_proc_alive()`` has been added
+  to allow the user to detect if a primary process is running.
+  Use cases for this feature include fault detection, and monitoring
+  using secondary processes.
+
 
 Drivers
 ~~~~~~~
diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
index 9d7adf1..0e28017 100644
--- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
@@ -135,3 +135,11 @@ DPDK_2.2 {
 	rte_xen_dom0_supported;
 
 } DPDK_2.1;
+
+
+DPDK_2.3 {
+       global:
+
+       rte_eal_primary_proc_alive;
+
+} DPDK_2.2;
diff --git a/lib/librte_eal/common/include/rte_eal.h b/lib/librte_eal/common/include/rte_eal.h
index d2816a8..6eb65f9 100644
--- a/lib/librte_eal/common/include/rte_eal.h
+++ b/lib/librte_eal/common/include/rte_eal.h
@@ -156,6 +156,25 @@ int rte_eal_iopl_init(void);
  *   - On failure, a negative error value.
  */
 int rte_eal_init(int argc, char **argv);
+
+/**
+ * Check if a primary process is currently alive
+ *
+ * This function returns true when a primary process is currently
+ * active.
+ *
+ * @param config_file_path
+ *   The config_file_path argument provided should point at the location
+ *   that the primary process will create its config file. By default,
+ *   /var/run/.rte_config is used. This path can be customized when starting
+ *   a primary process using --file-prefix=custom_path
+ *
+ * @return
+ *  - If alive, returns one.
+ *  - If dead, returns zero.
+ */
+int rte_eal_primary_proc_alive(const char *config_file_path);
+
 /**
  * Usage function typedef used by the application usage function.
  *
diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c
index 635ec36..b419066 100644
--- a/lib/librte_eal/linuxapp/eal/eal.c
+++ b/lib/librte_eal/linuxapp/eal/eal.c
@@ -818,8 +818,6 @@ rte_eal_init(int argc, char **argv)
 
 	eal_check_mem_on_local_socket();
 
-	rte_eal_mcfg_complete();
-
 	if (eal_plugins_init() < 0)
 		rte_panic("Cannot init plugins\n");
 
@@ -877,9 +875,25 @@ rte_eal_init(int argc, char **argv)
 	if (rte_eal_pci_probe())
 		rte_panic("Cannot probe PCI\n");
 
+	rte_eal_mcfg_complete();
+
 	return fctret;
 }
 
+int
+rte_eal_primary_proc_alive(const char *config_file_path)
+{
+	int config_fd;
+	config_fd = open(config_file_path, O_RDONLY);
+	if (config_fd < 0)
+		return 0;
+
+	int ret = lockf(config_fd, F_TEST, 0);
+	close(config_fd);
+
+	return !!ret;
+}
+
 /* get core role */
 enum rte_lcore_role_t
 rte_eal_lcore_role(unsigned lcore_id)
diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
index cbe175f..7a8c530 100644
--- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
@@ -138,3 +138,10 @@ DPDK_2.2 {
 	rte_xen_dom0_supported;
 
 } DPDK_2.1;
+
+DPDK_2.3 {
+	global:
+
+	rte_eal_primary_proc_alive;
+
+} DPDK_2.2;
-- 
2.5.0

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

* Re: [PATCH] eal: add function to check if primary proc alive
  2016-01-20 13:25 [PATCH] eal: add function to check if primary proc alive Harry van Haaren
@ 2016-01-21  6:14 ` Qiu, Michael
  2016-01-21  6:19   ` Matthew Hall
  2016-01-21  9:02   ` Van Haaren, Harry
  2016-01-25  8:11 ` Qiu, Michael
  2016-01-27 10:31 ` [PATCH v2] " Harry van Haaren
  2 siblings, 2 replies; 43+ messages in thread
From: Qiu, Michael @ 2016-01-21  6:14 UTC (permalink / raw)
  To: Van Haaren, Harry, david.marchand; +Cc: dev

On 1/20/2016 9:26 PM, Harry van Haaren wrote:
> This patch adds a new function to the EAL API:
> int rte_eal_primary_proc_alive(const char *path);
>
> The function indicates if a primary process is alive right now.
> This functionality is implemented by testing for a write-
> lock on the config file, and the function tests for a lock.
>
> The use case for this functionality is that a secondary
> process can wait until a primary process starts by polling
> the function and waiting. When the primary is running, the
> secondary continues to poll to detect if the primary process
> has quit unexpectedly, the secondary process can detect this.
>
> The RTE_MAGIC number is written to the shared config by the
> primary process, this is the signal to the secondary process
> that the EAL is set up, and ready to be used. The function
> rte_eal_mcfg_complete() writes RTE_MAGIC. This has been
> delayed in the EAL init proceedure, as the PCI probing in
> the primary process can interfere with the secondary running.
>
> Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>
> ---

one question:

As we could start up many primaries, how does your secondary process
work with them?

Thanks,
Michael


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

* Re: [PATCH] eal: add function to check if primary proc alive
  2016-01-21  6:14 ` Qiu, Michael
@ 2016-01-21  6:19   ` Matthew Hall
  2016-01-21  9:02   ` Van Haaren, Harry
  1 sibling, 0 replies; 43+ messages in thread
From: Matthew Hall @ 2016-01-21  6:19 UTC (permalink / raw)
  To: dev

On 1/20/16 10:14 PM, Qiu, Michael wrote:
> As we could start up many primaries, how does your secondary process
> work with them?

I just worked on this tonight myself. When doing > 1 primary (for 
example pktgen and app), I had to specify:

--no-shconf
--file-prefix pktgen
--file-prefix app

Or you get a panic and RTE fails to init, but the file-prefix seems to 
get applied both to the hugepage mmap() files and also to the lockfiles 
in /var/run:

$ ls -a /var/run | egrep -i '^\.'
.
..
.pktgen_hugepage_info
.rte_config
.rte_hugepage_info
.sdn_sensor_hugepage_info

So I think you have to keep the different primary-secondary sets 
separate using --file-prefix .

Matthew.

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

* Re: [PATCH] eal: add function to check if primary proc alive
  2016-01-21  6:14 ` Qiu, Michael
  2016-01-21  6:19   ` Matthew Hall
@ 2016-01-21  9:02   ` Van Haaren, Harry
  2016-01-22 17:37     ` Bruce Richardson
  1 sibling, 1 reply; 43+ messages in thread
From: Van Haaren, Harry @ 2016-01-21  9:02 UTC (permalink / raw)
  To: Qiu, Michael, david.marchand; +Cc: dev

> From: Qiu, Michael
> Sent: Thursday, January 21, 2016 6:14 AM
> To: Van Haaren, Harry <harry.van.haaren@intel.com>; david.marchand@6wind.com
> Cc: dev@dpdk.org
> Subject: Re: [dpdk-dev] [PATCH] eal: add function to check if primary proc alive
> <snip>
> As we could start up many primaries, how does your secondary process
> work with them?

When a primary process initializes, the location of the config file is important. The default is /var/run/.rte_config

To run multiple primary processes, the --file-prefix= option is used to specific a custom location for the config file. Eg: --file-prefix=testing    /var/run/.testing_config

The rte_eal_check_primary_alive(const char*) function takes a char* parameter - this is the location of the config file that the secondary process will wait for. Setting it to the correct value will make this secondary process wait for the corresponding primary process.

Regards, -Harry

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

* Re: [PATCH] eal: add function to check if primary proc alive
  2016-01-21  9:02   ` Van Haaren, Harry
@ 2016-01-22 17:37     ` Bruce Richardson
  2016-01-25  8:06       ` Qiu, Michael
  2016-01-25 11:44       ` Van Haaren, Harry
  0 siblings, 2 replies; 43+ messages in thread
From: Bruce Richardson @ 2016-01-22 17:37 UTC (permalink / raw)
  To: Van Haaren, Harry; +Cc: dev

On Thu, Jan 21, 2016 at 09:02:41AM +0000, Van Haaren, Harry wrote:
> > From: Qiu, Michael
> > Sent: Thursday, January 21, 2016 6:14 AM
> > To: Van Haaren, Harry <harry.van.haaren@intel.com>; david.marchand@6wind.com
> > Cc: dev@dpdk.org
> > Subject: Re: [dpdk-dev] [PATCH] eal: add function to check if primary proc alive
> > <snip>
> > As we could start up many primaries, how does your secondary process
> > work with them?
> 
> When a primary process initializes, the location of the config file is important. The default is /var/run/.rte_config
> 
> To run multiple primary processes, the --file-prefix= option is used to specific a custom location for the config file. Eg: --file-prefix=testing    /var/run/.testing_config
> 
> The rte_eal_check_primary_alive(const char*) function takes a char* parameter - this is the location of the config file that the secondary process will wait for. Setting it to the correct value will make this secondary process wait for the corresponding primary process.
> 
> Regards, -Harry

Since a given secondary process only works with a single primary process, I'm not
sure why the user should want or need to pass in this parameter. What's the use
case for a secondary process wanting to know about a different primary process?
The details of what the config file is should largely be hidden from the user
IMHO.

If you want to allow a secondary to query an arbitrary primary process can you
still allow a NULL string to query the default primary based on the passed in
file-prefix parameter (if any)?

/Bruce

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

* Re: [PATCH] eal: add function to check if primary proc alive
  2016-01-22 17:37     ` Bruce Richardson
@ 2016-01-25  8:06       ` Qiu, Michael
  2016-01-25 11:44       ` Van Haaren, Harry
  1 sibling, 0 replies; 43+ messages in thread
From: Qiu, Michael @ 2016-01-25  8:06 UTC (permalink / raw)
  To: Richardson, Bruce, Van Haaren, Harry; +Cc: dev

On 1/23/2016 1:38 AM, Richardson, Bruce wrote:
> On Thu, Jan 21, 2016 at 09:02:41AM +0000, Van Haaren, Harry wrote:
>>> From: Qiu, Michael
>>> Sent: Thursday, January 21, 2016 6:14 AM
>>> To: Van Haaren, Harry <harry.van.haaren@intel.com>; david.marchand@6wind.com
>>> Cc: dev@dpdk.org
>>> Subject: Re: [dpdk-dev] [PATCH] eal: add function to check if primary proc alive
>>> <snip>
>>> As we could start up many primaries, how does your secondary process
>>> work with them?
>> When a primary process initializes, the location of the config file is important. The default is /var/run/.rte_config
>>
>> To run multiple primary processes, the --file-prefix= option is used to specific a custom location for the config file. Eg: --file-prefix=testing    /var/run/.testing_config
>>
>> The rte_eal_check_primary_alive(const char*) function takes a char* parameter - this is the location of the config file that the secondary process will wait for. Setting it to the correct value will make this secondary process wait for the corresponding primary process.
>>
>> Regards, -Harry
> Since a given secondary process only works with a single primary process, I'm not
> sure why the user should want or need to pass in this parameter. What's the use
> case for a secondary process wanting to know about a different primary process?
> The details of what the config file is should largely be hidden from the user
> IMHO.

So using the prefix, and get the file name inside the
API(--file-prefix=xxx then the config file /var/run/.xxx_config), if no
perfix, then could be /var/run/.rte_config.

Just a suggestion. Maybe there are better solutions .

Thanks,
Michael
> If you want to allow a secondary to query an arbitrary primary process can you
> still allow a NULL string to query the default primary based on the passed in
> file-prefix parameter (if any)?
>
> /Bruce
>


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

* Re: [PATCH] eal: add function to check if primary proc alive
  2016-01-20 13:25 [PATCH] eal: add function to check if primary proc alive Harry van Haaren
  2016-01-21  6:14 ` Qiu, Michael
@ 2016-01-25  8:11 ` Qiu, Michael
  2016-01-25 11:51   ` Van Haaren, Harry
  2016-01-27 10:31 ` [PATCH v2] " Harry van Haaren
  2 siblings, 1 reply; 43+ messages in thread
From: Qiu, Michael @ 2016-01-25  8:11 UTC (permalink / raw)
  To: Van Haaren, Harry, david.marchand; +Cc: dev

On 1/20/2016 9:26 PM, Harry van Haaren wrote:
> This patch adds a new function to the EAL API:
> int rte_eal_primary_proc_alive(const char *path);
>
> The function indicates if a primary process is alive right now.
> This functionality is implemented by testing for a write-
> lock on the config file, and the function tests for a lock.
>
> The use case for this functionality is that a secondary
> process can wait until a primary process starts by polling
> the function and waiting. When the primary is running, the
> secondary continues to poll to detect if the primary process
> has quit unexpectedly, the secondary process can detect this.
>
> The RTE_MAGIC number is written to the shared config by the
> primary process, this is the signal to the secondary process
> that the EAL is set up, and ready to be used. The function
> rte_eal_mcfg_complete() writes RTE_MAGIC. This has been
> delayed in the EAL init proceedure, as the PCI probing in
> the primary process can interfere with the secondary running.
>
> Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>
> ---
>  

Hi, Harry

So secondary  will waste a whole lcore to do such polling?

Thanks,
Michael



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

* Re: [PATCH] eal: add function to check if primary proc alive
  2016-01-22 17:37     ` Bruce Richardson
  2016-01-25  8:06       ` Qiu, Michael
@ 2016-01-25 11:44       ` Van Haaren, Harry
  2016-01-26 19:13         ` Bruce Richardson
  1 sibling, 1 reply; 43+ messages in thread
From: Van Haaren, Harry @ 2016-01-25 11:44 UTC (permalink / raw)
  To: Richardson, Bruce; +Cc: dev

> From: Richardson, Bruce
> The details of what the config file is should largely be hidden from the user
> IMHO.

Agreed, however hiding it totally removes the flexibility of waiting for a primary
that is starting with --file-prefix (aka: in a non-default location). Imposing
a limit on only monitoring primary procs in the default location seems wrong.

> If you want to allow a secondary to query an arbitrary primary process can you
> still allow a NULL string to query the default primary based on the passed in
> file-prefix parameter (if any)?

Yep, I've made a v2 which includes handling NULL as path arg and using the
default config file, will post later after some more testing.

-Harry

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

* Re: [PATCH] eal: add function to check if primary proc alive
  2016-01-25  8:11 ` Qiu, Michael
@ 2016-01-25 11:51   ` Van Haaren, Harry
  2016-01-26  2:25     ` Qiu, Michael
  0 siblings, 1 reply; 43+ messages in thread
From: Van Haaren, Harry @ 2016-01-25 11:51 UTC (permalink / raw)
  To: Qiu, Michael, david.marchand; +Cc: dev

> From: Qiu, Michael
> Subject: Re: [dpdk-dev] [PATCH] eal: add function to check if primary proc alive
>
> So secondary will waste a whole lcore to do such polling?

Not really, the secondary process will need some CPU,
however it can sleep so it doesn't have to use 100% of it.
It shouldn't be run on a core that is used by the primary
for packet-forwarding though - that will impact performance.

-Harry

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

* Re: [PATCH] eal: add function to check if primary proc alive
  2016-01-25 11:51   ` Van Haaren, Harry
@ 2016-01-26  2:25     ` Qiu, Michael
  2016-01-26  9:04       ` Van Haaren, Harry
  0 siblings, 1 reply; 43+ messages in thread
From: Qiu, Michael @ 2016-01-26  2:25 UTC (permalink / raw)
  To: Van Haaren, Harry, david.marchand; +Cc: dev

On 1/25/2016 7:51 PM, Van Haaren, Harry wrote:
>> From: Qiu, Michael
>> Subject: Re: [dpdk-dev] [PATCH] eal: add function to check if primary proc alive
>>
>> So secondary will waste a whole lcore to do such polling?
> Not really, the secondary process will need some CPU,
> however it can sleep so it doesn't have to use 100% of it.
> It shouldn't be run on a core that is used by the primary
> for packet-forwarding though - that will impact performance.

If not, what will happen if the primary been killed after you check
alive? At that time, the secondary may be doing some work need primary
alive.

Thanks,
Michael
> -Harry
>


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

* Re: [PATCH] eal: add function to check if primary proc alive
  2016-01-26  2:25     ` Qiu, Michael
@ 2016-01-26  9:04       ` Van Haaren, Harry
  2016-01-26 11:07         ` Qiu, Michael
  0 siblings, 1 reply; 43+ messages in thread
From: Van Haaren, Harry @ 2016-01-26  9:04 UTC (permalink / raw)
  To: Qiu, Michael, david.marchand; +Cc: dev

> From: Qiu, Michael
> On 1/25/2016 7:51 PM, Van Haaren, Harry wrote:
> > Not really, the secondary process will need some CPU,
> > however it can sleep so it doesn't have to use 100% of it.
> > It shouldn't be run on a core that is used by the primary
> > for packet-forwarding though - that will impact performance.
> 
> If not, what will happen if the primary been killed after you check
> alive? At that time, the secondary may be doing some work need primary
> alive.

What work are you thinking of? Apart from the shared config
and hugepages, primary and secondary processes are running
in their own address-space, and if the primary gets killed,
the secondary will notice when it next polls rte_eal_primary_proc_alive().

Whatever work the secondary was performing (in its own address space)
won't be directly changed by the primary being killed, because the
shared config and hugepages stay (EAL "cleans up" when the primary
is re-launched, not on quit).

-Harry

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

* Re: [PATCH] eal: add function to check if primary proc alive
  2016-01-26  9:04       ` Van Haaren, Harry
@ 2016-01-26 11:07         ` Qiu, Michael
  2016-01-26 11:19           ` Van Haaren, Harry
  0 siblings, 1 reply; 43+ messages in thread
From: Qiu, Michael @ 2016-01-26 11:07 UTC (permalink / raw)
  To: Van Haaren, Harry, david.marchand; +Cc: dev

On 1/26/2016 5:04 PM, Van Haaren, Harry wrote:
>> From: Qiu, Michael
>> On 1/25/2016 7:51 PM, Van Haaren, Harry wrote:
>>> Not really, the secondary process will need some CPU,
>>> however it can sleep so it doesn't have to use 100% of it.
>>> It shouldn't be run on a core that is used by the primary
>>> for packet-forwarding though - that will impact performance.
>> If not, what will happen if the primary been killed after you check
>> alive? At that time, the secondary may be doing some work need primary
>> alive.
> What work are you thinking of? Apart from the shared config
> and hugepages, primary and secondary processes are running
> in their own address-space, and if the primary gets killed,
> the secondary will notice when it next polls rte_eal_primary_proc_alive().
>
> Whatever work the secondary was performing (in its own address space)
> won't be directly changed by the primary being killed, because the
> shared config and hugepages stay (EAL "cleans up" when the primary
> is re-launched, not on quit).

OK,  when primary quit or be killed, the queues will be freed, it will
be a potential issue when secondary try to access, maybe I'm wrong.

Thanks,
Michael

> -Harry
>
>


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

* Re: [PATCH] eal: add function to check if primary proc alive
  2016-01-26 11:07         ` Qiu, Michael
@ 2016-01-26 11:19           ` Van Haaren, Harry
  0 siblings, 0 replies; 43+ messages in thread
From: Van Haaren, Harry @ 2016-01-26 11:19 UTC (permalink / raw)
  To: Qiu, Michael, david.marchand; +Cc: dev

> From: Qiu, Michael
> > Whatever work the secondary was performing (in its own address space)
> > won't be directly changed by the primary being killed, because the
> > shared config and hugepages stay (EAL "cleans up" when the primary
> > is re-launched, not on quit).
> 
> OK,  when primary quit or be killed, the queues will be freed, it will
> be a potential issue when secondary try to access, maybe I'm wrong.

The use-case for this patch is monitoring statistics and fault-detection.
That involves reading registers directly from the NIC, and the NIC
rx/tx queues are not used. I think you are right that using the rx/tx
queues from a secondary process when they have been cleaned-up by the
primary process will indeed cause issues.

If there is a valid use-case where both primary and secondary processes
will be forwarding packets on the same NIC, this issue should be discussed
in more detail.

In its current state, this patch solves a problem for the use case of a
primary process forwarding packets, and a secondary process monitoring
and providing fault-detection.

-Harry

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

* Re: [PATCH] eal: add function to check if primary proc alive
  2016-01-25 11:44       ` Van Haaren, Harry
@ 2016-01-26 19:13         ` Bruce Richardson
  2016-01-27 10:35           ` Van Haaren, Harry
  0 siblings, 1 reply; 43+ messages in thread
From: Bruce Richardson @ 2016-01-26 19:13 UTC (permalink / raw)
  To: Van Haaren, Harry; +Cc: dev

On Mon, Jan 25, 2016 at 11:44:59AM +0000, Van Haaren, Harry wrote:
> > From: Richardson, Bruce
> > The details of what the config file is should largely be hidden from the user
> > IMHO.
> 
> Agreed, however hiding it totally removes the flexibility of waiting for a primary
> that is starting with --file-prefix (aka: in a non-default location). Imposing
> a limit on only monitoring primary procs in the default location seems wrong.
> 

But the secondary also needs the same prefix. Is that prefix not accessible by
this function to be used?

/Bruce

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

* [PATCH v2] eal: add function to check if primary proc alive
  2016-01-20 13:25 [PATCH] eal: add function to check if primary proc alive Harry van Haaren
  2016-01-21  6:14 ` Qiu, Michael
  2016-01-25  8:11 ` Qiu, Michael
@ 2016-01-27 10:31 ` Harry van Haaren
  2016-02-02 14:11   ` [PATCH v3] " Harry van Haaren
  2 siblings, 1 reply; 43+ messages in thread
From: Harry van Haaren @ 2016-01-27 10:31 UTC (permalink / raw)
  To: david.marchand; +Cc: dev

This patch adds a new function to the EAL API:
int rte_eal_primary_proc_alive(const char *path);

The function indicates if a primary process is alive right now.
This functionality is implemented by testing for a write-
lock on the config file, and the function tests for a lock.

The use case for this functionality is that a secondary
process can wait until a primary process starts by polling
the function and waiting. When the primary is running, the
secondary continues to poll to detect if the primary process
has quit unexpectedly, the secondary process can detect this.

The RTE_MAGIC number is written to the shared config by the
primary process, this is the signal to the secondary process
that the EAL is set up, and ready to be used. The function
rte_eal_mcfg_complete() writes RTE_MAGIC. This has been
delayed in the EAL init proceedure, as the PCI probing in
the primary process can interfere with the secondary running.

Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>
---

v2:
- Passing NULL as const char* uses default /var/run/.rte_config
- Moved code into /common/ instead of /linuxapp/, should work on BSD now

 doc/guides/rel_notes/release_2_3.rst            |  7 +++
 lib/librte_eal/bsdapp/eal/Makefile              |  1 +
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  8 ++++
 lib/librte_eal/common/eal_common_proc.c         | 61 +++++++++++++++++++++++++
 lib/librte_eal/common/include/rte_eal.h         | 18 ++++++++
 lib/librte_eal/linuxapp/eal/Makefile            |  1 +
 lib/librte_eal/linuxapp/eal/eal.c               |  4 +-
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |  7 +++
 8 files changed, 105 insertions(+), 2 deletions(-)
 create mode 100644 lib/librte_eal/common/eal_common_proc.c

diff --git a/doc/guides/rel_notes/release_2_3.rst b/doc/guides/rel_notes/release_2_3.rst
index 99de186..14b5b06 100644
--- a/doc/guides/rel_notes/release_2_3.rst
+++ b/doc/guides/rel_notes/release_2_3.rst
@@ -11,6 +11,13 @@ Resolved Issues
 EAL
 ~~~
 
+* **Added rte_eal_primary_proc_alive() function**
+
+  A new function ``rte_eal_primary_proc_alive()`` has been added
+  to allow the user to detect if a primary process is running.
+  Use cases for this feature include fault detection, and monitoring
+  using secondary processes.
+
 
 Drivers
 ~~~~~~~
diff --git a/lib/librte_eal/bsdapp/eal/Makefile b/lib/librte_eal/bsdapp/eal/Makefile
index 65b293f..2d6e3b1 100644
--- a/lib/librte_eal/bsdapp/eal/Makefile
+++ b/lib/librte_eal/bsdapp/eal/Makefile
@@ -61,6 +61,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_alarm.c
 
 # from common dir
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_lcore.c
+SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_proc.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_timer.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_memzone.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_log.c
diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
index 9d7adf1..0e28017 100644
--- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
@@ -135,3 +135,11 @@ DPDK_2.2 {
 	rte_xen_dom0_supported;
 
 } DPDK_2.1;
+
+
+DPDK_2.3 {
+       global:
+
+       rte_eal_primary_proc_alive;
+
+} DPDK_2.2;
diff --git a/lib/librte_eal/common/eal_common_proc.c b/lib/librte_eal/common/eal_common_proc.c
new file mode 100644
index 0000000..c598891
--- /dev/null
+++ b/lib/librte_eal/common/eal_common_proc.c
@@ -0,0 +1,61 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright 2016 Intel Shannon Ltd. All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <rte_eal.h>
+
+#include "eal_filesystem.h"
+#include "eal_internal_cfg.h"
+
+int
+rte_eal_primary_proc_alive(const char *config_file_path)
+{
+	int config_fd;
+
+	if (config_file_path)
+		config_fd = open(config_file_path, O_RDONLY);
+	else {
+		char default_path[PATH_MAX+1];
+		snprintf(default_path, PATH_MAX, RUNTIME_CONFIG_FMT,
+			 default_config_dir, "rte");
+		config_fd = open(default_path, O_RDONLY);
+	}
+	if (config_fd < 0)
+		return 0;
+
+	int ret = lockf(config_fd, F_TEST, 0);
+	close(config_fd);
+
+	return !!ret;
+}
diff --git a/lib/librte_eal/common/include/rte_eal.h b/lib/librte_eal/common/include/rte_eal.h
index d2816a8..05720ef 100644
--- a/lib/librte_eal/common/include/rte_eal.h
+++ b/lib/librte_eal/common/include/rte_eal.h
@@ -156,6 +156,24 @@ int rte_eal_iopl_init(void);
  *   - On failure, a negative error value.
  */
 int rte_eal_init(int argc, char **argv);
+
+/**
+ * Check if a primary process is currently alive
+ *
+ * This function returns true when a primary process is currently
+ * active.
+ *
+ * @param config_file_path
+ *   The config_file_path argument provided should point at the location
+ *   that the primary process will create its config file. If NULL, the default
+ *   config file path is used.
+ *
+ * @return
+ *  - If alive, returns one.
+ *  - If dead, returns zero.
+ */
+int rte_eal_primary_proc_alive(const char *config_file_path);
+
 /**
  * Usage function typedef used by the application usage function.
  *
diff --git a/lib/librte_eal/linuxapp/eal/Makefile b/lib/librte_eal/linuxapp/eal/Makefile
index 26eced5..6df0d58 100644
--- a/lib/librte_eal/linuxapp/eal/Makefile
+++ b/lib/librte_eal/linuxapp/eal/Makefile
@@ -71,6 +71,7 @@ endif
 
 # from common dir
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_lcore.c
+SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_proc.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_timer.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_memzone.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_log.c
diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c
index 635ec36..c261fc0 100644
--- a/lib/librte_eal/linuxapp/eal/eal.c
+++ b/lib/librte_eal/linuxapp/eal/eal.c
@@ -818,8 +818,6 @@ rte_eal_init(int argc, char **argv)
 
 	eal_check_mem_on_local_socket();
 
-	rte_eal_mcfg_complete();
-
 	if (eal_plugins_init() < 0)
 		rte_panic("Cannot init plugins\n");
 
@@ -877,6 +875,8 @@ rte_eal_init(int argc, char **argv)
 	if (rte_eal_pci_probe())
 		rte_panic("Cannot probe PCI\n");
 
+	rte_eal_mcfg_complete();
+
 	return fctret;
 }
 
diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
index cbe175f..7a8c530 100644
--- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
@@ -138,3 +138,10 @@ DPDK_2.2 {
 	rte_xen_dom0_supported;
 
 } DPDK_2.1;
+
+DPDK_2.3 {
+	global:
+
+	rte_eal_primary_proc_alive;
+
+} DPDK_2.2;
-- 
2.5.0

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

* Re: [PATCH] eal: add function to check if primary proc alive
  2016-01-26 19:13         ` Bruce Richardson
@ 2016-01-27 10:35           ` Van Haaren, Harry
  0 siblings, 0 replies; 43+ messages in thread
From: Van Haaren, Harry @ 2016-01-27 10:35 UTC (permalink / raw)
  To: Richardson, Bruce; +Cc: dev

> From: Richardson, Bruce
> > Agreed, however hiding it totally removes the flexibility of waiting for a primary
> > that is starting with --file-prefix (aka: in a non-default location). Imposing
> > a limit on only monitoring primary procs in the default location seems wrong.
> 
> But the secondary also needs the same prefix. Is that prefix not accessible by
> this function to be used?

The issue is that the EAL parsing code is performed during rte_init(), which
is exactly what this function tries to avoid - initializing EAL before a primary
process starts.

I looked at changing the EAL parsing to come before rte_init(), and considered
adding a minimal parser for --file-prefix. Both routes seem a bad solution,
either for complexity or code-duplication.

v2 of this patch posted to list:
http://dpdk.org/dev/patchwork/patch/10126/

-Harry

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

* [PATCH v3] eal: add function to check if primary proc alive
  2016-01-27 10:31 ` [PATCH v2] " Harry van Haaren
@ 2016-02-02 14:11   ` Harry van Haaren
  2016-02-23 14:10     ` [PATCH v4] " Harry van Haaren
  0 siblings, 1 reply; 43+ messages in thread
From: Harry van Haaren @ 2016-02-02 14:11 UTC (permalink / raw)
  To: david.marchand; +Cc: dev

This patch adds a new function to the EAL API:
int rte_eal_primary_proc_alive(const char *path);

The function indicates if a primary process is alive right now.
This functionality is implemented by testing for a write-
lock on the config file, and the function tests for a lock.

The use case for this functionality is that a secondary
process can wait until a primary process starts by polling
the function and waiting. When the primary is running, the
secondary continues to poll to detect if the primary process
has quit unexpectedly, the secondary process can detect this.

The RTE_MAGIC number is written to the shared config by the
primary process, this is the signal to the secondary process
that the EAL is set up, and ready to be used. The function
rte_eal_mcfg_complete() writes RTE_MAGIC. This has been
delayed in the EAL init proceedure, as the PCI probing in
the primary process can interfere with the secondary running.

Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>
---

v3:
- Fixed Copyright years

v2:
- Passing NULL as const char* uses default /var/run/.rte_config
- Moved code into /common/ instead of /linuxapp/, should work on BSD now

 doc/guides/rel_notes/release_2_3.rst            |  7 +++
 lib/librte_eal/bsdapp/eal/Makefile              |  1 +
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  8 ++++
 lib/librte_eal/common/eal_common_proc.c         | 61 +++++++++++++++++++++++++
 lib/librte_eal/common/include/rte_eal.h         | 20 +++++++-
 lib/librte_eal/linuxapp/eal/Makefile            |  3 +-
 lib/librte_eal/linuxapp/eal/eal.c               |  6 +--
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |  7 +++
 8 files changed, 108 insertions(+), 5 deletions(-)
 create mode 100644 lib/librte_eal/common/eal_common_proc.c

diff --git a/doc/guides/rel_notes/release_2_3.rst b/doc/guides/rel_notes/release_2_3.rst
index 99de186..14b5b06 100644
--- a/doc/guides/rel_notes/release_2_3.rst
+++ b/doc/guides/rel_notes/release_2_3.rst
@@ -11,6 +11,13 @@ Resolved Issues
 EAL
 ~~~
 
+* **Added rte_eal_primary_proc_alive() function**
+
+  A new function ``rte_eal_primary_proc_alive()`` has been added
+  to allow the user to detect if a primary process is running.
+  Use cases for this feature include fault detection, and monitoring
+  using secondary processes.
+
 
 Drivers
 ~~~~~~~
diff --git a/lib/librte_eal/bsdapp/eal/Makefile b/lib/librte_eal/bsdapp/eal/Makefile
index 65b293f..2d6e3b1 100644
--- a/lib/librte_eal/bsdapp/eal/Makefile
+++ b/lib/librte_eal/bsdapp/eal/Makefile
@@ -61,6 +61,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_alarm.c
 
 # from common dir
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_lcore.c
+SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_proc.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_timer.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_memzone.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_log.c
diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
index 9d7adf1..0e28017 100644
--- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
@@ -135,3 +135,11 @@ DPDK_2.2 {
 	rte_xen_dom0_supported;
 
 } DPDK_2.1;
+
+
+DPDK_2.3 {
+       global:
+
+       rte_eal_primary_proc_alive;
+
+} DPDK_2.2;
diff --git a/lib/librte_eal/common/eal_common_proc.c b/lib/librte_eal/common/eal_common_proc.c
new file mode 100644
index 0000000..c598891
--- /dev/null
+++ b/lib/librte_eal/common/eal_common_proc.c
@@ -0,0 +1,61 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright 2016 Intel Shannon Ltd. All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <rte_eal.h>
+
+#include "eal_filesystem.h"
+#include "eal_internal_cfg.h"
+
+int
+rte_eal_primary_proc_alive(const char *config_file_path)
+{
+	int config_fd;
+
+	if (config_file_path)
+		config_fd = open(config_file_path, O_RDONLY);
+	else {
+		char default_path[PATH_MAX+1];
+		snprintf(default_path, PATH_MAX, RUNTIME_CONFIG_FMT,
+			 default_config_dir, "rte");
+		config_fd = open(default_path, O_RDONLY);
+	}
+	if (config_fd < 0)
+		return 0;
+
+	int ret = lockf(config_fd, F_TEST, 0);
+	close(config_fd);
+
+	return !!ret;
+}
diff --git a/lib/librte_eal/common/include/rte_eal.h b/lib/librte_eal/common/include/rte_eal.h
index d2816a8..67a0324 100644
--- a/lib/librte_eal/common/include/rte_eal.h
+++ b/lib/librte_eal/common/include/rte_eal.h
@@ -1,7 +1,7 @@
 /*-
  *   BSD LICENSE
  *
- *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
  *   All rights reserved.
  *
  *   Redistribution and use in source and binary forms, with or without
@@ -156,6 +156,24 @@ int rte_eal_iopl_init(void);
  *   - On failure, a negative error value.
  */
 int rte_eal_init(int argc, char **argv);
+
+/**
+ * Check if a primary process is currently alive
+ *
+ * This function returns true when a primary process is currently
+ * active.
+ *
+ * @param config_file_path
+ *   The config_file_path argument provided should point at the location
+ *   that the primary process will create its config file. If NULL, the default
+ *   config file path is used.
+ *
+ * @return
+ *  - If alive, returns one.
+ *  - If dead, returns zero.
+ */
+int rte_eal_primary_proc_alive(const char *config_file_path);
+
 /**
  * Usage function typedef used by the application usage function.
  *
diff --git a/lib/librte_eal/linuxapp/eal/Makefile b/lib/librte_eal/linuxapp/eal/Makefile
index 26eced5..b3700da 100644
--- a/lib/librte_eal/linuxapp/eal/Makefile
+++ b/lib/librte_eal/linuxapp/eal/Makefile
@@ -1,6 +1,6 @@
 #   BSD LICENSE
 #
-#   Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
+#   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
 #   All rights reserved.
 #
 #   Redistribution and use in source and binary forms, with or without
@@ -71,6 +71,7 @@ endif
 
 # from common dir
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_lcore.c
+SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_proc.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_timer.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_memzone.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_log.c
diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c
index 635ec36..efa1121 100644
--- a/lib/librte_eal/linuxapp/eal/eal.c
+++ b/lib/librte_eal/linuxapp/eal/eal.c
@@ -1,7 +1,7 @@
 /*-
  *   BSD LICENSE
  *
- *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
  *   Copyright(c) 2012-2014 6WIND S.A.
  *   All rights reserved.
  *
@@ -818,8 +818,6 @@ rte_eal_init(int argc, char **argv)
 
 	eal_check_mem_on_local_socket();
 
-	rte_eal_mcfg_complete();
-
 	if (eal_plugins_init() < 0)
 		rte_panic("Cannot init plugins\n");
 
@@ -877,6 +875,8 @@ rte_eal_init(int argc, char **argv)
 	if (rte_eal_pci_probe())
 		rte_panic("Cannot probe PCI\n");
 
+	rte_eal_mcfg_complete();
+
 	return fctret;
 }
 
diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
index cbe175f..7a8c530 100644
--- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
@@ -138,3 +138,10 @@ DPDK_2.2 {
 	rte_xen_dom0_supported;
 
 } DPDK_2.1;
+
+DPDK_2.3 {
+	global:
+
+	rte_eal_primary_proc_alive;
+
+} DPDK_2.2;
-- 
2.5.0

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

* [PATCH v4] eal: add function to check if primary proc alive
  2016-02-02 14:11   ` [PATCH v3] " Harry van Haaren
@ 2016-02-23 14:10     ` Harry van Haaren
  2016-02-24 13:50       ` Tahhan, Maryam
                         ` (2 more replies)
  0 siblings, 3 replies; 43+ messages in thread
From: Harry van Haaren @ 2016-02-23 14:10 UTC (permalink / raw)
  To: david.marchand; +Cc: dev

This patch adds a new function to the EAL API:
int rte_eal_primary_proc_alive(const char *path);

The function indicates if a primary process is alive right now.
This functionality is implemented by testing for a write-
lock on the config file, and the function tests for a lock.

The use case for this functionality is that a secondary
process can wait until a primary process starts by polling
the function and waiting. When the primary is running, the
secondary continues to poll to detect if the primary process
has quit unexpectedly, the secondary process can detect this.

The RTE_MAGIC number is written to the shared config by the
primary process, this is the signal to the secondary process
that the EAL is set up, and ready to be used. The function
rte_eal_mcfg_complete() writes RTE_MAGIC. This has been
delayed in the EAL init proceedure, as the PCI probing in
the primary process can interfere with the secondary running.

Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>
---

v4:
- Rebased to git head (2.3 -> 16.04 changes)

v3:
- Fixed Copyright years

v2:
- Passing NULL as const char* uses default /var/run/.rte_config
- Moved code into /common/ instead of /linuxapp/, should work on BSD now

 doc/guides/rel_notes/release_16_04.rst          |  6 +++
 lib/librte_eal/bsdapp/eal/Makefile              |  1 +
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  1 +
 lib/librte_eal/common/eal_common_proc.c         | 61 +++++++++++++++++++++++++
 lib/librte_eal/common/include/rte_eal.h         | 21 ++++++++-
 lib/librte_eal/linuxapp/eal/Makefile            |  3 +-
 lib/librte_eal/linuxapp/eal/eal.c               |  6 +--
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |  1 +
 8 files changed, 95 insertions(+), 5 deletions(-)
 create mode 100644 lib/librte_eal/common/eal_common_proc.c

diff --git a/doc/guides/rel_notes/release_16_04.rst b/doc/guides/rel_notes/release_16_04.rst
index 5786f74..8893ad5 100644
--- a/doc/guides/rel_notes/release_16_04.rst
+++ b/doc/guides/rel_notes/release_16_04.rst
@@ -62,6 +62,12 @@ This section should contain bug fixes added to the relevant sections. Sample for
 EAL
 ~~~
 
+* **Added rte_eal_primary_proc_alive() function**
+
+  A new function ``rte_eal_primary_proc_alive()`` has been added
+  to allow the user to detect if a primary process is running.
+  Use cases for this feature include fault detection, and monitoring
+  using secondary processes.
 
 Drivers
 ~~~~~~~
diff --git a/lib/librte_eal/bsdapp/eal/Makefile b/lib/librte_eal/bsdapp/eal/Makefile
index d7ca60b..1c79734 100644
--- a/lib/librte_eal/bsdapp/eal/Makefile
+++ b/lib/librte_eal/bsdapp/eal/Makefile
@@ -63,6 +63,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_alarm.c
 
 # from common dir
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_lcore.c
+SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_proc.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_timer.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_memzone.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_log.c
diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
index 4f93ab7..15c0d9e 100644
--- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
@@ -146,5 +146,6 @@ DPDK_2.3 {
 	rte_eal_pci_ioport_write;
 	rte_eal_pci_map_device;
 	rte_eal_pci_unmap_device;
+	rte_eal_primary_proc_alive;
 
 } DPDK_2.2;
diff --git a/lib/librte_eal/common/eal_common_proc.c b/lib/librte_eal/common/eal_common_proc.c
new file mode 100644
index 0000000..c598891
--- /dev/null
+++ b/lib/librte_eal/common/eal_common_proc.c
@@ -0,0 +1,61 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright 2016 Intel Shannon Ltd. All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <rte_eal.h>
+
+#include "eal_filesystem.h"
+#include "eal_internal_cfg.h"
+
+int
+rte_eal_primary_proc_alive(const char *config_file_path)
+{
+	int config_fd;
+
+	if (config_file_path)
+		config_fd = open(config_file_path, O_RDONLY);
+	else {
+		char default_path[PATH_MAX+1];
+		snprintf(default_path, PATH_MAX, RUNTIME_CONFIG_FMT,
+			 default_config_dir, "rte");
+		config_fd = open(default_path, O_RDONLY);
+	}
+	if (config_fd < 0)
+		return 0;
+
+	int ret = lockf(config_fd, F_TEST, 0);
+	close(config_fd);
+
+	return !!ret;
+}
diff --git a/lib/librte_eal/common/include/rte_eal.h b/lib/librte_eal/common/include/rte_eal.h
index 0e99c31..8741627 100644
--- a/lib/librte_eal/common/include/rte_eal.h
+++ b/lib/librte_eal/common/include/rte_eal.h
@@ -1,7 +1,7 @@
 /*-
  *   BSD LICENSE
  *
- *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
  *   All rights reserved.
  *
  *   Redistribution and use in source and binary forms, with or without
@@ -156,6 +156,25 @@ int rte_eal_iopl_init(void);
  *   - On failure, a negative error value.
  */
 int rte_eal_init(int argc, char **argv);
+
+/**
+ * Check if a primary process is currently alive
+ *
+ * This function returns true when a primary process is currently
+ * active.
+ *
+ * @param config_file_path
+ *   The config_file_path argument provided should point at the location
+ *   that the primary process will create its config file. If NULL, the default
+ *   config file path is used.
+ *
+ * @return
+ *  - If alive, returns one.
+ *  - If dead, returns zero.
+ */
+int rte_eal_primary_proc_alive(const char *config_file_path);
+
+
 /**
  * Usage function typedef used by the application usage function.
  *
diff --git a/lib/librte_eal/linuxapp/eal/Makefile b/lib/librte_eal/linuxapp/eal/Makefile
index 6e26250..713dd68 100644
--- a/lib/librte_eal/linuxapp/eal/Makefile
+++ b/lib/librte_eal/linuxapp/eal/Makefile
@@ -1,6 +1,6 @@
 #   BSD LICENSE
 #
-#   Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
+#   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
 #   All rights reserved.
 #
 #   Redistribution and use in source and binary forms, with or without
@@ -73,6 +73,7 @@ endif
 
 # from common dir
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_lcore.c
+SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_proc.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_timer.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_memzone.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_log.c
diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c
index 4d3e0de..f9cdb4a 100644
--- a/lib/librte_eal/linuxapp/eal/eal.c
+++ b/lib/librte_eal/linuxapp/eal/eal.c
@@ -1,7 +1,7 @@
 /*-
  *   BSD LICENSE
  *
- *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
  *   Copyright(c) 2012-2014 6WIND S.A.
  *   All rights reserved.
  *
@@ -819,8 +819,6 @@ rte_eal_init(int argc, char **argv)
 
 	eal_check_mem_on_local_socket();
 
-	rte_eal_mcfg_complete();
-
 	if (eal_plugins_init() < 0)
 		rte_panic("Cannot init plugins\n");
 
@@ -878,6 +876,8 @@ rte_eal_init(int argc, char **argv)
 	if (rte_eal_pci_probe())
 		rte_panic("Cannot probe PCI\n");
 
+	rte_eal_mcfg_complete();
+
 	return fctret;
 }
 
diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
index e8d8660..e31487d 100644
--- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
@@ -149,5 +149,6 @@ DPDK_2.3 {
 	rte_eal_pci_ioport_write;
 	rte_eal_pci_map_device;
 	rte_eal_pci_unmap_device;
+	rte_eal_primary_proc_alive;
 
 } DPDK_2.2;
-- 
2.5.0

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

* Re: [PATCH v4] eal: add function to check if primary proc alive
  2016-02-23 14:10     ` [PATCH v4] " Harry van Haaren
@ 2016-02-24 13:50       ` Tahhan, Maryam
  2016-03-04 18:07       ` Thomas Monjalon
  2016-03-07 11:37       ` [PATCH v5] " Harry van Haaren
  2 siblings, 0 replies; 43+ messages in thread
From: Tahhan, Maryam @ 2016-02-24 13:50 UTC (permalink / raw)
  To: Van Haaren, Harry, david.marchand; +Cc: dev

> From: Van Haaren, Harry
> Sent: Tuesday, February 23, 2016 2:10 PM
> To: david.marchand@6wind.com
> Cc: Tahhan, Maryam <maryam.tahhan@intel.com>; dev@dpdk.org; Van
> Haaren, Harry <harry.van.haaren@intel.com>
> Subject: [PATCH v4] eal: add function to check if primary proc alive
> 
> This patch adds a new function to the EAL API:
> int rte_eal_primary_proc_alive(const char *path);
> 
> The function indicates if a primary process is alive right now.
> This functionality is implemented by testing for a write- lock on the
> config file, and the function tests for a lock.
> 
> The use case for this functionality is that a secondary process can wait
> until a primary process starts by polling the function and waiting. When
> the primary is running, the secondary continues to poll to detect if the
> primary process has quit unexpectedly, the secondary process can detect
> this.
> 
> The RTE_MAGIC number is written to the shared config by the primary
> process, this is the signal to the secondary process that the EAL is set up,
> and ready to be used. The function
> rte_eal_mcfg_complete() writes RTE_MAGIC. This has been delayed in
> the EAL init proceedure, as the PCI probing in the primary process can
> interfere with the secondary running.
> 
> Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>

Acked-by: Maryam Tahhan <maryam.tahhan@intel.com>

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

* Re: [PATCH v4] eal: add function to check if primary proc alive
  2016-02-23 14:10     ` [PATCH v4] " Harry van Haaren
  2016-02-24 13:50       ` Tahhan, Maryam
@ 2016-03-04 18:07       ` Thomas Monjalon
  2016-03-07 11:37       ` [PATCH v5] " Harry van Haaren
  2 siblings, 0 replies; 43+ messages in thread
From: Thomas Monjalon @ 2016-03-04 18:07 UTC (permalink / raw)
  To: Harry van Haaren; +Cc: dev

I'm looking into details...

2016-02-23 14:10, Harry van Haaren:
>  EAL
>  ~~~
>  
> +* **Added rte_eal_primary_proc_alive() function**
> +
> +  A new function ``rte_eal_primary_proc_alive()`` has been added
> +  to allow the user to detect if a primary process is running.
> +  Use cases for this feature include fault detection, and monitoring
> +  using secondary processes.
>  

A space is missing here (2 lines before next title).

>  Drivers
>  ~~~~~~~
[...]
> + *   Copyright 2016 Intel Shannon Ltd. All rights reserved.

I had not noticed before. Intel Shannon Ltd is a separate entity?

[...]
> + * @return
> + *  - If alive, returns one.
> + *  - If dead, returns zero.

Why not use digits?

> + */
> +int rte_eal_primary_proc_alive(const char *config_file_path);
> +
> +

The functions are usually separated by only 1 line,
except in keepalive for an unknown reason.

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

* [PATCH v5] eal: add function to check if primary proc alive
  2016-02-23 14:10     ` [PATCH v4] " Harry van Haaren
  2016-02-24 13:50       ` Tahhan, Maryam
  2016-03-04 18:07       ` Thomas Monjalon
@ 2016-03-07 11:37       ` Harry van Haaren
  2016-03-07 12:02         ` [PATCH v6] " Harry van Haaren
  2 siblings, 1 reply; 43+ messages in thread
From: Harry van Haaren @ 2016-03-07 11:37 UTC (permalink / raw)
  To: dev

This patch adds a new function to the EAL API:
int rte_eal_primary_proc_alive(const char *path);

The function indicates if a primary process is alive right now.
This functionality is implemented by testing for a write-
lock on the config file, and the function tests for a lock.

The use case for this functionality is that a secondary
process can wait until a primary process starts by polling
the function and waiting. When the primary is running, the
secondary continues to poll to detect if the primary process
has quit unexpectedly, the secondary process can detect this.

The RTE_MAGIC number is written to the shared config by the
primary process, this is the signal to the secondary process
that the EAL is set up, and ready to be used. The function
rte_eal_mcfg_complete() writes RTE_MAGIC. This has been
delayed in the EAL init proceedure, as the PCI probing in
the primary process can interfere with the secondary running.

Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>
Acked-by: Maryam Tahhan <maryam.tahhan@intel.com>

---

v5:
- Renamed returns in doc from words to digits
- Fixed line spacing in docs
- Fixed line spacing in EAL header
- Rebased to master (Makefile conflicts)

v4:
- Rebased to git head (2.3 -> 16.04 changes)

v3:
- Fixed Copyright years

v2:
- Passing NULL as const char* uses default /var/run/.rte_config
- Moved code into /common/ instead of /linuxapp/, should work on BSD now
---
 doc/guides/rel_notes/release_16_04.rst          |  8 ++++
 lib/librte_eal/bsdapp/eal/Makefile              |  1 +
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  1 +
 lib/librte_eal/common/eal_common_proc.c         | 61 +++++++++++++++++++++++++
 lib/librte_eal/common/include/rte_eal.h         | 20 +++++++-
 lib/librte_eal/linuxapp/eal/Makefile            |  3 +-
 lib/librte_eal/linuxapp/eal/eal.c               |  6 +--
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |  1 +
 8 files changed, 96 insertions(+), 5 deletions(-)
 create mode 100644 lib/librte_eal/common/eal_common_proc.c

diff --git a/doc/guides/rel_notes/release_16_04.rst b/doc/guides/rel_notes/release_16_04.rst
index 24f15bf..7d5000f 100644
--- a/doc/guides/rel_notes/release_16_04.rst
+++ b/doc/guides/rel_notes/release_16_04.rst
@@ -74,6 +74,14 @@ EAL
 ~~~
 
 
+* **Added rte_eal_primary_proc_alive() function**
+
+  A new function ``rte_eal_primary_proc_alive()`` has been added
+  to allow the user to detect if a primary process is running.
+  Use cases for this feature include fault detection, and monitoring
+  using secondary processes.
+
+
 Drivers
 ~~~~~~~
 
diff --git a/lib/librte_eal/bsdapp/eal/Makefile b/lib/librte_eal/bsdapp/eal/Makefile
index 9015516..9ecf429 100644
--- a/lib/librte_eal/bsdapp/eal/Makefile
+++ b/lib/librte_eal/bsdapp/eal/Makefile
@@ -79,6 +79,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_devargs.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_dev.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_options.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_thread.c
+SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_proc.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += rte_malloc.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += malloc_elem.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += malloc_heap.c
diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
index 0c24223..58c2951 100644
--- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
@@ -148,5 +148,6 @@ DPDK_16.04 {
 	rte_eal_pci_ioport_write;
 	rte_eal_pci_map_device;
 	rte_eal_pci_unmap_device;
+	rte_eal_primary_proc_alive;
 
 } DPDK_2.2;
diff --git a/lib/librte_eal/common/eal_common_proc.c b/lib/librte_eal/common/eal_common_proc.c
new file mode 100644
index 0000000..c598891
--- /dev/null
+++ b/lib/librte_eal/common/eal_common_proc.c
@@ -0,0 +1,61 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright 2016 Intel Shannon Ltd. All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <rte_eal.h>
+
+#include "eal_filesystem.h"
+#include "eal_internal_cfg.h"
+
+int
+rte_eal_primary_proc_alive(const char *config_file_path)
+{
+	int config_fd;
+
+	if (config_file_path)
+		config_fd = open(config_file_path, O_RDONLY);
+	else {
+		char default_path[PATH_MAX+1];
+		snprintf(default_path, PATH_MAX, RUNTIME_CONFIG_FMT,
+			 default_config_dir, "rte");
+		config_fd = open(default_path, O_RDONLY);
+	}
+	if (config_fd < 0)
+		return 0;
+
+	int ret = lockf(config_fd, F_TEST, 0);
+	close(config_fd);
+
+	return !!ret;
+}
diff --git a/lib/librte_eal/common/include/rte_eal.h b/lib/librte_eal/common/include/rte_eal.h
index 0e99c31..a71d6f5 100644
--- a/lib/librte_eal/common/include/rte_eal.h
+++ b/lib/librte_eal/common/include/rte_eal.h
@@ -1,7 +1,7 @@
 /*-
  *   BSD LICENSE
  *
- *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
  *   All rights reserved.
  *
  *   Redistribution and use in source and binary forms, with or without
@@ -156,6 +156,24 @@ int rte_eal_iopl_init(void);
  *   - On failure, a negative error value.
  */
 int rte_eal_init(int argc, char **argv);
+
+/**
+ * Check if a primary process is currently alive
+ *
+ * This function returns true when a primary process is currently
+ * active.
+ *
+ * @param config_file_path
+ *   The config_file_path argument provided should point at the location
+ *   that the primary process will create its config file. If NULL, the default
+ *   config file path is used.
+ *
+ * @return
+ *  - If alive, returns 1.
+ *  - If dead, returns 0.
+ */
+int rte_eal_primary_proc_alive(const char *config_file_path);
+
 /**
  * Usage function typedef used by the application usage function.
  *
diff --git a/lib/librte_eal/linuxapp/eal/Makefile b/lib/librte_eal/linuxapp/eal/Makefile
index c5490e4..d72f035 100644
--- a/lib/librte_eal/linuxapp/eal/Makefile
+++ b/lib/librte_eal/linuxapp/eal/Makefile
@@ -1,6 +1,6 @@
 #   BSD LICENSE
 #
-#   Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
+#   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
 #   All rights reserved.
 #
 #   Redistribution and use in source and binary forms, with or without
@@ -89,6 +89,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_devargs.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_dev.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_options.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_thread.c
+SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_proc.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += rte_malloc.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += malloc_elem.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += malloc_heap.c
diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c
index ceac435..364f303 100644
--- a/lib/librte_eal/linuxapp/eal/eal.c
+++ b/lib/librte_eal/linuxapp/eal/eal.c
@@ -1,7 +1,7 @@
 /*-
  *   BSD LICENSE
  *
- *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
  *   Copyright(c) 2012-2014 6WIND S.A.
  *   All rights reserved.
  *
@@ -821,8 +821,6 @@ rte_eal_init(int argc, char **argv)
 
 	eal_check_mem_on_local_socket();
 
-	rte_eal_mcfg_complete();
-
 	if (eal_plugins_init() < 0)
 		rte_panic("Cannot init plugins\n");
 
@@ -880,6 +878,8 @@ rte_eal_init(int argc, char **argv)
 	if (rte_eal_pci_probe())
 		rte_panic("Cannot probe PCI\n");
 
+	rte_eal_mcfg_complete();
+
 	return fctret;
 }
 
diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
index 4aa9de7..12503ef 100644
--- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
@@ -151,5 +151,6 @@ DPDK_16.04 {
 	rte_eal_pci_ioport_write;
 	rte_eal_pci_map_device;
 	rte_eal_pci_unmap_device;
+	rte_eal_primary_proc_alive;
 
 } DPDK_2.2;
-- 
2.5.0

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

* [PATCH v6] eal: add function to check if primary proc alive
  2016-03-07 11:37       ` [PATCH v5] " Harry van Haaren
@ 2016-03-07 12:02         ` Harry van Haaren
  2016-03-08  8:42           ` David Marchand
  2016-03-08 17:07           ` [PATCH v7 0/2] eal: add function to check primary alive Harry van Haaren
  0 siblings, 2 replies; 43+ messages in thread
From: Harry van Haaren @ 2016-03-07 12:02 UTC (permalink / raw)
  To: david.marchand, dev

This patch adds a new function to the EAL API:
int rte_eal_primary_proc_alive(const char *path);

The function indicates if a primary process is alive right now.
This functionality is implemented by testing for a write-
lock on the config file, and the function tests for a lock.

The use case for this functionality is that a secondary
process can wait until a primary process starts by polling
the function and waiting. When the primary is running, the
secondary continues to poll to detect if the primary process
has quit unexpectedly, the secondary process can detect this.

The RTE_MAGIC number is written to the shared config by the
primary process, this is the signal to the secondary process
that the EAL is set up, and ready to be used. The function
rte_eal_mcfg_complete() writes RTE_MAGIC. This has been
delayed in the EAL init proceedure, as the PCI probing in
the primary process can interfere with the secondary running.

Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>
Acked-by: Maryam Tahhan <maryam.tahhan@intel.com>

---

v6:
- Fix license header

v5:
- Renamed returns in doc from words to digits
- Fixed line spacing in docs
- Fixed line spacing in EAL header
- Rebased to master (Makefile conflicts)

v4:
- Rebased to git head (2.3 -> 16.04 changes)

v3:
- Fixed Copyright years

v2:
- Passing NULL as const char* uses default /var/run/.rte_config
- Moved code into /common/ instead of /linuxapp/, should work on BSD now
---
 doc/guides/rel_notes/release_16_04.rst          |  8 ++++
 lib/librte_eal/bsdapp/eal/Makefile              |  1 +
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  1 +
 lib/librte_eal/common/eal_common_proc.c         | 61 +++++++++++++++++++++++++
 lib/librte_eal/common/include/rte_eal.h         | 20 +++++++-
 lib/librte_eal/linuxapp/eal/Makefile            |  3 +-
 lib/librte_eal/linuxapp/eal/eal.c               |  6 +--
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |  1 +
 8 files changed, 96 insertions(+), 5 deletions(-)
 create mode 100644 lib/librte_eal/common/eal_common_proc.c

diff --git a/doc/guides/rel_notes/release_16_04.rst b/doc/guides/rel_notes/release_16_04.rst
index 24f15bf..7d5000f 100644
--- a/doc/guides/rel_notes/release_16_04.rst
+++ b/doc/guides/rel_notes/release_16_04.rst
@@ -74,6 +74,14 @@ EAL
 ~~~
 
 
+* **Added rte_eal_primary_proc_alive() function**
+
+  A new function ``rte_eal_primary_proc_alive()`` has been added
+  to allow the user to detect if a primary process is running.
+  Use cases for this feature include fault detection, and monitoring
+  using secondary processes.
+
+
 Drivers
 ~~~~~~~
 
diff --git a/lib/librte_eal/bsdapp/eal/Makefile b/lib/librte_eal/bsdapp/eal/Makefile
index 9015516..9ecf429 100644
--- a/lib/librte_eal/bsdapp/eal/Makefile
+++ b/lib/librte_eal/bsdapp/eal/Makefile
@@ -79,6 +79,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_devargs.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_dev.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_options.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_thread.c
+SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_proc.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += rte_malloc.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += malloc_elem.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += malloc_heap.c
diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
index 0c24223..58c2951 100644
--- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
@@ -148,5 +148,6 @@ DPDK_16.04 {
 	rte_eal_pci_ioport_write;
 	rte_eal_pci_map_device;
 	rte_eal_pci_unmap_device;
+	rte_eal_primary_proc_alive;
 
 } DPDK_2.2;
diff --git a/lib/librte_eal/common/eal_common_proc.c b/lib/librte_eal/common/eal_common_proc.c
new file mode 100644
index 0000000..12e0fca
--- /dev/null
+++ b/lib/librte_eal/common/eal_common_proc.c
@@ -0,0 +1,61 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2016 Intel Corporation. All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <rte_eal.h>
+
+#include "eal_filesystem.h"
+#include "eal_internal_cfg.h"
+
+int
+rte_eal_primary_proc_alive(const char *config_file_path)
+{
+	int config_fd;
+
+	if (config_file_path)
+		config_fd = open(config_file_path, O_RDONLY);
+	else {
+		char default_path[PATH_MAX+1];
+		snprintf(default_path, PATH_MAX, RUNTIME_CONFIG_FMT,
+			 default_config_dir, "rte");
+		config_fd = open(default_path, O_RDONLY);
+	}
+	if (config_fd < 0)
+		return 0;
+
+	int ret = lockf(config_fd, F_TEST, 0);
+	close(config_fd);
+
+	return !!ret;
+}
diff --git a/lib/librte_eal/common/include/rte_eal.h b/lib/librte_eal/common/include/rte_eal.h
index 0e99c31..a71d6f5 100644
--- a/lib/librte_eal/common/include/rte_eal.h
+++ b/lib/librte_eal/common/include/rte_eal.h
@@ -1,7 +1,7 @@
 /*-
  *   BSD LICENSE
  *
- *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
  *   All rights reserved.
  *
  *   Redistribution and use in source and binary forms, with or without
@@ -156,6 +156,24 @@ int rte_eal_iopl_init(void);
  *   - On failure, a negative error value.
  */
 int rte_eal_init(int argc, char **argv);
+
+/**
+ * Check if a primary process is currently alive
+ *
+ * This function returns true when a primary process is currently
+ * active.
+ *
+ * @param config_file_path
+ *   The config_file_path argument provided should point at the location
+ *   that the primary process will create its config file. If NULL, the default
+ *   config file path is used.
+ *
+ * @return
+ *  - If alive, returns 1.
+ *  - If dead, returns 0.
+ */
+int rte_eal_primary_proc_alive(const char *config_file_path);
+
 /**
  * Usage function typedef used by the application usage function.
  *
diff --git a/lib/librte_eal/linuxapp/eal/Makefile b/lib/librte_eal/linuxapp/eal/Makefile
index c5490e4..d72f035 100644
--- a/lib/librte_eal/linuxapp/eal/Makefile
+++ b/lib/librte_eal/linuxapp/eal/Makefile
@@ -1,6 +1,6 @@
 #   BSD LICENSE
 #
-#   Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
+#   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
 #   All rights reserved.
 #
 #   Redistribution and use in source and binary forms, with or without
@@ -89,6 +89,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_devargs.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_dev.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_options.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_thread.c
+SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_proc.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += rte_malloc.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += malloc_elem.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += malloc_heap.c
diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c
index ceac435..364f303 100644
--- a/lib/librte_eal/linuxapp/eal/eal.c
+++ b/lib/librte_eal/linuxapp/eal/eal.c
@@ -1,7 +1,7 @@
 /*-
  *   BSD LICENSE
  *
- *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
  *   Copyright(c) 2012-2014 6WIND S.A.
  *   All rights reserved.
  *
@@ -821,8 +821,6 @@ rte_eal_init(int argc, char **argv)
 
 	eal_check_mem_on_local_socket();
 
-	rte_eal_mcfg_complete();
-
 	if (eal_plugins_init() < 0)
 		rte_panic("Cannot init plugins\n");
 
@@ -880,6 +878,8 @@ rte_eal_init(int argc, char **argv)
 	if (rte_eal_pci_probe())
 		rte_panic("Cannot probe PCI\n");
 
+	rte_eal_mcfg_complete();
+
 	return fctret;
 }
 
diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
index 4aa9de7..12503ef 100644
--- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
@@ -151,5 +151,6 @@ DPDK_16.04 {
 	rte_eal_pci_ioport_write;
 	rte_eal_pci_map_device;
 	rte_eal_pci_unmap_device;
+	rte_eal_primary_proc_alive;
 
 } DPDK_2.2;
-- 
2.5.0

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

* Re: [PATCH v6] eal: add function to check if primary proc alive
  2016-03-07 12:02         ` [PATCH v6] " Harry van Haaren
@ 2016-03-08  8:42           ` David Marchand
  2016-03-08  9:58             ` Van Haaren, Harry
  2016-03-08 17:07           ` [PATCH v7 0/2] eal: add function to check primary alive Harry van Haaren
  1 sibling, 1 reply; 43+ messages in thread
From: David Marchand @ 2016-03-08  8:42 UTC (permalink / raw)
  To: Harry van Haaren; +Cc: dev

Hello Harry,

On Mon, Mar 7, 2016 at 1:02 PM, Harry van Haaren
<harry.van.haaren@intel.com> wrote:
> This patch adds a new function to the EAL API:
> int rte_eal_primary_proc_alive(const char *path);
>
> The function indicates if a primary process is alive right now.
> This functionality is implemented by testing for a write-
> lock on the config file, and the function tests for a lock.
>
> The use case for this functionality is that a secondary
> process can wait until a primary process starts by polling
> the function and waiting. When the primary is running, the
> secondary continues to poll to detect if the primary process
> has quit unexpectedly, the secondary process can detect this.
>
> The RTE_MAGIC number is written to the shared config by the
> primary process, this is the signal to the secondary process
> that the EAL is set up, and ready to be used. The function
> rte_eal_mcfg_complete() writes RTE_MAGIC. This has been
> delayed in the EAL init proceedure, as the PCI probing in
> the primary process can interfere with the secondary running.

Well, this sounds odd.
There might be an issue, but I can't see it at the moment.
When I look at this new api, I am under the impression that you are
supposed to check for primary liveliness once dpdk init has finished
(from your secondary process point of view), not before and not while
it is initialising.

Why do you need to move this ?


> diff --git a/lib/librte_eal/common/eal_common_proc.c b/lib/librte_eal/common/eal_common_proc.c
> new file mode 100644
> index 0000000..12e0fca
> --- /dev/null
> +++ b/lib/librte_eal/common/eal_common_proc.c

[snip]

> +int
> +rte_eal_primary_proc_alive(const char *config_file_path)
> +{
> +       int config_fd;
> +
> +       if (config_file_path)
> +               config_fd = open(config_file_path, O_RDONLY);
> +       else {
> +               char default_path[PATH_MAX+1];
> +               snprintf(default_path, PATH_MAX, RUNTIME_CONFIG_FMT,
> +                        default_config_dir, "rte");
> +               config_fd = open(default_path, O_RDONLY);

Can't you reuse eal_runtime_config_path() here ?


-- 
David Marchand

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

* Re: [PATCH v6] eal: add function to check if primary proc alive
  2016-03-08  8:42           ` David Marchand
@ 2016-03-08  9:58             ` Van Haaren, Harry
  2016-03-08 11:13               ` Thomas Monjalon
  0 siblings, 1 reply; 43+ messages in thread
From: Van Haaren, Harry @ 2016-03-08  9:58 UTC (permalink / raw)
  To: David Marchand; +Cc: dev

Hi David,

> From: David Marchand [mailto:david.marchand@6wind.com]
> Subject: Re: [PATCH v6] eal: add function to check if primary proc alive

> When I look at this new api, I am under the impression that you are
> supposed to check for primary liveliness once dpdk init has finished
> (from your secondary process point of view), not before and not while
> it is initialising.

The issue is that if a secondary process is initialized, it holds a read
lock on  /var/run/.rte_config  and this prevents a primary from starting.

So we *must* detect a primary process being ready to attach to, *without*
having called  rte_eal_init()  in the secondary process.


> Why do you need to move this ?

Issues arise when a primary and secondary process both scan the PCI devices
at the same time. Moving  rte_eal_mcfg_complete()  solves this race-cond
because the secondary process will wait until the primary is finished.


> > +       if (config_file_path)
> > +               config_fd = open(config_file_path, O_RDONLY);
> > +       else {
> > +               char default_path[PATH_MAX+1];
> > +               snprintf(default_path, PATH_MAX, RUNTIME_CONFIG_FMT,
> > +                        default_config_dir, "rte");
> > +               config_fd = open(default_path, O_RDONLY);
> 
> Can't you reuse eal_runtime_config_path() here ?

No, as rte_eal_init() has not been called, for the same reason as above.
As rte_eal_init() has not been called, the shared config that is read by
eal_runtime_config_path() has not been initialized.


-Harry

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

* Re: [PATCH v6] eal: add function to check if primary proc alive
  2016-03-08  9:58             ` Van Haaren, Harry
@ 2016-03-08 11:13               ` Thomas Monjalon
  2016-03-08 11:19                 ` David Marchand
  0 siblings, 1 reply; 43+ messages in thread
From: Thomas Monjalon @ 2016-03-08 11:13 UTC (permalink / raw)
  To: Van Haaren, Harry; +Cc: dev

2016-03-08 09:58, Van Haaren, Harry:
> From: David Marchand [mailto:david.marchand@6wind.com]
> > When I look at this new api, I am under the impression that you are
> > supposed to check for primary liveliness once dpdk init has finished
> > (from your secondary process point of view), not before and not while
> > it is initialising.
> 
> The issue is that if a secondary process is initialized, it holds a read
> lock on  /var/run/.rte_config  and this prevents a primary from starting.

The new function is advertised as a monitoring feature.
But it seems to be also a workaround for an ordering issue when starting
primary and secondary processes concurrently, right?

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

* Re: [PATCH v6] eal: add function to check if primary proc alive
  2016-03-08 11:13               ` Thomas Monjalon
@ 2016-03-08 11:19                 ` David Marchand
  2016-03-08 13:57                   ` Van Haaren, Harry
  0 siblings, 1 reply; 43+ messages in thread
From: David Marchand @ 2016-03-08 11:19 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: dev

On Tue, Mar 8, 2016 at 12:13 PM, Thomas Monjalon
<thomas.monjalon@6wind.com> wrote:
> 2016-03-08 09:58, Van Haaren, Harry:
>> From: David Marchand [mailto:david.marchand@6wind.com]
>> > When I look at this new api, I am under the impression that you are
>> > supposed to check for primary liveliness once dpdk init has finished
>> > (from your secondary process point of view), not before and not while
>> > it is initialising.
>>
>> The issue is that if a secondary process is initialized, it holds a read
>> lock on  /var/run/.rte_config  and this prevents a primary from starting.
>
> The new function is advertised as a monitoring feature.
> But it seems to be also a workaround for an ordering issue when starting
> primary and secondary processes concurrently, right?

+1


-- 
David Marchand

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

* Re: [PATCH v6] eal: add function to check if primary proc alive
  2016-03-08 11:19                 ` David Marchand
@ 2016-03-08 13:57                   ` Van Haaren, Harry
  2016-03-08 14:40                     ` David Marchand
  0 siblings, 1 reply; 43+ messages in thread
From: Van Haaren, Harry @ 2016-03-08 13:57 UTC (permalink / raw)
  To: David Marchand, Thomas Monjalon; +Cc: dev

> From: David Marchand [mailto:david.marchand@6wind.com]
> >> The issue is that if a secondary process is initialized, it holds a read
> >> lock on  /var/run/.rte_config  and this prevents a primary from starting.
> >
> > The new function is advertised as a monitoring feature.
> > But it seems to be also a workaround for an ordering issue when starting
> > primary and secondary processes concurrently, right?
> 
> +1

You are correct, the function rte_eal_primary_proc_alive() added here is
for monitoring if there is a primary process alive.

The rte_eal_mcfg_complete() function call in rte_eal_init() is delayed
to avoid a race-condition between secondary and primary processes.
This race-condition occurs when two processes probe the PCI devices
at the same time.

Delaying the rte_eal_mcfg_complete() call until after the primary has
finished rte_eal_pci_probe() ensures that this race condition is avoided.

-Harry

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

* Re: [PATCH v6] eal: add function to check if primary proc alive
  2016-03-08 13:57                   ` Van Haaren, Harry
@ 2016-03-08 14:40                     ` David Marchand
  0 siblings, 0 replies; 43+ messages in thread
From: David Marchand @ 2016-03-08 14:40 UTC (permalink / raw)
  To: Van Haaren, Harry; +Cc: dev

On Tue, Mar 8, 2016 at 2:57 PM, Van Haaren, Harry
<harry.van.haaren@intel.com> wrote:
>> From: David Marchand [mailto:david.marchand@6wind.com]
>> >> The issue is that if a secondary process is initialized, it holds a read
>> >> lock on  /var/run/.rte_config  and this prevents a primary from starting.
>> >
>> > The new function is advertised as a monitoring feature.
>> > But it seems to be also a workaround for an ordering issue when starting
>> > primary and secondary processes concurrently, right?
>>
>> +1
>
> You are correct, the function rte_eal_primary_proc_alive() added here is
> for monitoring if there is a primary process alive.
>
> The rte_eal_mcfg_complete() function call in rte_eal_init() is delayed
> to avoid a race-condition between secondary and primary processes.
> This race-condition occurs when two processes probe the PCI devices
> at the same time.
>
> Delaying the rte_eal_mcfg_complete() call until after the primary has
> finished rte_eal_pci_probe() ensures that this race condition is avoided.

Then, those are two different things.
Can you split this into two patches: one for the fix and one for the
new function ?

CCing sergio, who is the multi process maintainer.

Thanks.

-- 
David Marchand

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

* [PATCH v7 0/2] eal: add function to check primary alive
  2016-03-07 12:02         ` [PATCH v6] " Harry van Haaren
  2016-03-08  8:42           ` David Marchand
@ 2016-03-08 17:07           ` Harry van Haaren
  2016-03-08 17:07             ` [PATCH v7 1/2] eal: fix race-condition in pri/sec proc startup Harry van Haaren
                               ` (2 more replies)
  1 sibling, 3 replies; 43+ messages in thread
From: Harry van Haaren @ 2016-03-08 17:07 UTC (permalink / raw)
  To: david.marchand; +Cc: dev

The first patch of this patchset contains a fix for EAL PCI probing,
to avoid a race-condition where a primary and secondary probe PCI
devices at the same time.

The second patch adds a function that can be polled by a process to
detect if a DPDK primary process is alive. This function does not
rely on rte_eal_init(), as this uses the EAL and thus stops a
primary from starting.

The functionality provided by this patch is very useful for providing
additional services to DPDK primary applications such as monitoring
statistics and performing fault detection.

Harry van Haaren (2):
  eal: fix race-condition in pri/sec proc startup
  eal: add function to check if primary proc alive

 doc/guides/rel_notes/release_16_04.rst          |  8 ++++++++
 lib/librte_eal/bsdapp/eal/Makefile              |  1 +
 lib/librte_eal/bsdapp/eal/eal.c                 |  6 +++---
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  1 +
 lib/librte_eal/common/include/rte_eal.h         | 20 +++++++++++++++++++-
 lib/librte_eal/linuxapp/eal/Makefile            |  3 ++-
 lib/librte_eal/linuxapp/eal/eal.c               |  6 +++---
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |  1 +
 8 files changed, 38 insertions(+), 8 deletions(-)

-- 
2.5.0

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

* [PATCH v7 1/2] eal: fix race-condition in pri/sec proc startup
  2016-03-08 17:07           ` [PATCH v7 0/2] eal: add function to check primary alive Harry van Haaren
@ 2016-03-08 17:07             ` Harry van Haaren
  2016-03-08 17:07             ` [PATCH v7 2/2] eal: add function to check if primary proc alive Harry van Haaren
  2016-03-09 10:12             ` [PATCH v8 0/2] eal: add function to check primary alive Harry van Haaren
  2 siblings, 0 replies; 43+ messages in thread
From: Harry van Haaren @ 2016-03-08 17:07 UTC (permalink / raw)
  To: david.marchand; +Cc: dev

This patch fixes a race-condition when a primary and
secondary process simultaneously probe PCI devices.

This is implemented by moving the rte_eal_mcfg_complete()
function call in rte_eal_init() until after rte_eal_pci_probe().

The end result is that the secondary process waits longer,
until the primary has completed its PCI probing, and then
notifies the secondary process.

This race-condition became visible during the development of
a function that allows a secondary process to be polling until
a primary process exists. The secondary would then probe PCI
devices at the same time, causing an error during rte_eal_init()

Linux EAL:
Fixes: 916e4f4f4e45 ("memory: fix for multi process support")

BSD EAL:
Fixes: 764bf26873b9 ("add FreeBSD support")

Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>
---
 lib/librte_eal/bsdapp/eal/eal.c   | 6 +++---
 lib/librte_eal/linuxapp/eal/eal.c | 6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c
index a34e61d..06bfd4e 100644
--- a/lib/librte_eal/bsdapp/eal/eal.c
+++ b/lib/librte_eal/bsdapp/eal/eal.c
@@ -1,7 +1,7 @@
 /*-
  *   BSD LICENSE
  *
- *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
  *   Copyright(c) 2014 6WIND S.A.
  *   All rights reserved.
  *
@@ -569,8 +569,6 @@ rte_eal_init(int argc, char **argv)
 
 	eal_check_mem_on_local_socket();
 
-	rte_eal_mcfg_complete();
-
 	if (eal_plugins_init() < 0)
 		rte_panic("Cannot init plugins\n");
 
@@ -621,6 +619,8 @@ rte_eal_init(int argc, char **argv)
 	if (rte_eal_pci_probe())
 		rte_panic("Cannot probe PCI\n");
 
+	rte_eal_mcfg_complete();
+
 	return fctret;
 }
 
diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c
index ceac435..364f303 100644
--- a/lib/librte_eal/linuxapp/eal/eal.c
+++ b/lib/librte_eal/linuxapp/eal/eal.c
@@ -1,7 +1,7 @@
 /*-
  *   BSD LICENSE
  *
- *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
  *   Copyright(c) 2012-2014 6WIND S.A.
  *   All rights reserved.
  *
@@ -821,8 +821,6 @@ rte_eal_init(int argc, char **argv)
 
 	eal_check_mem_on_local_socket();
 
-	rte_eal_mcfg_complete();
-
 	if (eal_plugins_init() < 0)
 		rte_panic("Cannot init plugins\n");
 
@@ -880,6 +878,8 @@ rte_eal_init(int argc, char **argv)
 	if (rte_eal_pci_probe())
 		rte_panic("Cannot probe PCI\n");
 
+	rte_eal_mcfg_complete();
+
 	return fctret;
 }
 
-- 
2.5.0

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

* [PATCH v7 2/2] eal: add function to check if primary proc alive
  2016-03-08 17:07           ` [PATCH v7 0/2] eal: add function to check primary alive Harry van Haaren
  2016-03-08 17:07             ` [PATCH v7 1/2] eal: fix race-condition in pri/sec proc startup Harry van Haaren
@ 2016-03-08 17:07             ` Harry van Haaren
  2016-03-09 10:12             ` [PATCH v8 0/2] eal: add function to check primary alive Harry van Haaren
  2 siblings, 0 replies; 43+ messages in thread
From: Harry van Haaren @ 2016-03-08 17:07 UTC (permalink / raw)
  To: david.marchand; +Cc: dev

This patch adds a new function to the EAL API:
int rte_eal_primary_proc_alive(const char *path);

The function indicates if a primary process is alive right now.
This functionality is implemented by testing for a write-
lock on the config file, and the function tests for a lock.

The use case for this functionality is that a secondary
process can wait until a primary process starts by polling
the function and waiting. When the primary is running, the
secondary continues to poll to detect if the primary process
has quit unexpectedly, the secondary process can detect this.

Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>
Acked-by: Maryam Tahhan <maryam.tahhan@intel.com>
---
 doc/guides/rel_notes/release_16_04.rst          |  8 ++++++++
 lib/librte_eal/bsdapp/eal/Makefile              |  1 +
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  1 +
 lib/librte_eal/common/include/rte_eal.h         | 20 +++++++++++++++++++-
 lib/librte_eal/linuxapp/eal/Makefile            |  3 ++-
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |  1 +
 6 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/doc/guides/rel_notes/release_16_04.rst b/doc/guides/rel_notes/release_16_04.rst
index 24f15bf..7d5000f 100644
--- a/doc/guides/rel_notes/release_16_04.rst
+++ b/doc/guides/rel_notes/release_16_04.rst
@@ -74,6 +74,14 @@ EAL
 ~~~
 
 
+* **Added rte_eal_primary_proc_alive() function**
+
+  A new function ``rte_eal_primary_proc_alive()`` has been added
+  to allow the user to detect if a primary process is running.
+  Use cases for this feature include fault detection, and monitoring
+  using secondary processes.
+
+
 Drivers
 ~~~~~~~
 
diff --git a/lib/librte_eal/bsdapp/eal/Makefile b/lib/librte_eal/bsdapp/eal/Makefile
index 9015516..9ecf429 100644
--- a/lib/librte_eal/bsdapp/eal/Makefile
+++ b/lib/librte_eal/bsdapp/eal/Makefile
@@ -79,6 +79,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_devargs.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_dev.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_options.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_thread.c
+SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_proc.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += rte_malloc.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += malloc_elem.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += malloc_heap.c
diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
index 0c24223..58c2951 100644
--- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
@@ -148,5 +148,6 @@ DPDK_16.04 {
 	rte_eal_pci_ioport_write;
 	rte_eal_pci_map_device;
 	rte_eal_pci_unmap_device;
+	rte_eal_primary_proc_alive;
 
 } DPDK_2.2;
diff --git a/lib/librte_eal/common/include/rte_eal.h b/lib/librte_eal/common/include/rte_eal.h
index 0e99c31..a71d6f5 100644
--- a/lib/librte_eal/common/include/rte_eal.h
+++ b/lib/librte_eal/common/include/rte_eal.h
@@ -1,7 +1,7 @@
 /*-
  *   BSD LICENSE
  *
- *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
  *   All rights reserved.
  *
  *   Redistribution and use in source and binary forms, with or without
@@ -156,6 +156,24 @@ int rte_eal_iopl_init(void);
  *   - On failure, a negative error value.
  */
 int rte_eal_init(int argc, char **argv);
+
+/**
+ * Check if a primary process is currently alive
+ *
+ * This function returns true when a primary process is currently
+ * active.
+ *
+ * @param config_file_path
+ *   The config_file_path argument provided should point at the location
+ *   that the primary process will create its config file. If NULL, the default
+ *   config file path is used.
+ *
+ * @return
+ *  - If alive, returns 1.
+ *  - If dead, returns 0.
+ */
+int rte_eal_primary_proc_alive(const char *config_file_path);
+
 /**
  * Usage function typedef used by the application usage function.
  *
diff --git a/lib/librte_eal/linuxapp/eal/Makefile b/lib/librte_eal/linuxapp/eal/Makefile
index c5490e4..d72f035 100644
--- a/lib/librte_eal/linuxapp/eal/Makefile
+++ b/lib/librte_eal/linuxapp/eal/Makefile
@@ -1,6 +1,6 @@
 #   BSD LICENSE
 #
-#   Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
+#   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
 #   All rights reserved.
 #
 #   Redistribution and use in source and binary forms, with or without
@@ -89,6 +89,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_devargs.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_dev.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_options.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_thread.c
+SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_proc.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += rte_malloc.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += malloc_elem.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += malloc_heap.c
diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
index 4aa9de7..12503ef 100644
--- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
@@ -151,5 +151,6 @@ DPDK_16.04 {
 	rte_eal_pci_ioport_write;
 	rte_eal_pci_map_device;
 	rte_eal_pci_unmap_device;
+	rte_eal_primary_proc_alive;
 
 } DPDK_2.2;
-- 
2.5.0

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

* [PATCH v8 0/2] eal: add function to check primary alive
  2016-03-08 17:07           ` [PATCH v7 0/2] eal: add function to check primary alive Harry van Haaren
  2016-03-08 17:07             ` [PATCH v7 1/2] eal: fix race-condition in pri/sec proc startup Harry van Haaren
  2016-03-08 17:07             ` [PATCH v7 2/2] eal: add function to check if primary proc alive Harry van Haaren
@ 2016-03-09 10:12             ` Harry van Haaren
  2016-03-09 10:12               ` [PATCH v8 1/2] eal: fix race-condition in pri/sec proc startup Harry van Haaren
                                 ` (3 more replies)
  2 siblings, 4 replies; 43+ messages in thread
From: Harry van Haaren @ 2016-03-09 10:12 UTC (permalink / raw)
  To: david.marchand; +Cc: dev


The first patch of this patchset contains a fix for EAL PCI probing,
to avoid a race-condition where a primary and secondary probe PCI
devices at the same time.

The second patch adds a function that can be polled by a process to
detect if a DPDK primary process is alive. This function does not
rely on rte_eal_init(), as this uses the EAL and thus stops a
primary from starting.

The functionality provided by this patch is very useful for providing
additional services to DPDK primary applications such as monitoring
statistics and performing fault detection.

v8:
- include implementation of function (got lost in v7)

v7:
- split patch into two, one for eal fix, one for adding functionality

v6:
- Fix license header

v5:
- Renamed returns in doc from words to digits
- Fixed line spacing in docs
- Fixed line spacing in EAL header
- Rebased to master (Makefile conflicts)

v4:
- Rebased to git head (2.3 -> 16.04 changes)

v3:
- Fixed Copyright years

v2:
- Passing NULL as const char* uses default /var/run/.rte_config
- Moved co

Harry van Haaren (2):
  eal: fix race-condition in pri/sec proc startup
  eal: add function to check if primary proc alive

 doc/guides/rel_notes/release_16_04.rst          |  8 ++++
 lib/librte_eal/bsdapp/eal/Makefile              |  1 +
 lib/librte_eal/bsdapp/eal/eal.c                 |  6 +--
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  1 +
 lib/librte_eal/common/eal_common_proc.c         | 61 +++++++++++++++++++++++++
 lib/librte_eal/common/include/rte_eal.h         | 20 +++++++-
 lib/librte_eal/linuxapp/eal/Makefile            |  3 +-
 lib/librte_eal/linuxapp/eal/eal.c               |  6 +--
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |  1 +
 9 files changed, 99 insertions(+), 8 deletions(-)
 create mode 100644 lib/librte_eal/common/eal_common_proc.c

-- 
2.5.0

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

* [PATCH v8 1/2] eal: fix race-condition in pri/sec proc startup
  2016-03-09 10:12             ` [PATCH v8 0/2] eal: add function to check primary alive Harry van Haaren
@ 2016-03-09 10:12               ` Harry van Haaren
  2016-03-09 13:23                 ` Sergio Gonzalez Monroy
  2016-03-09 10:12               ` [PATCH v8 2/2] eal: add function to check if primary proc alive Harry van Haaren
                                 ` (2 subsequent siblings)
  3 siblings, 1 reply; 43+ messages in thread
From: Harry van Haaren @ 2016-03-09 10:12 UTC (permalink / raw)
  To: david.marchand; +Cc: dev

This patch fixes a race-condition when a primary and
secondary process simultaneously probe PCI devices.

This is implemented by moving the rte_eal_mcfg_complete()
function call in rte_eal_init() until after rte_eal_pci_probe().

The end result is that the secondary process waits longer,
until the primary has completed its PCI probing, and then
notifies the secondary process.

This race-condition became visible during the development of
a function that allows a secondary process to be polling until
a primary process exists. The secondary would then probe PCI
devices at the same time, causing an error during rte_eal_init()

Linux EAL:
Fixes: 916e4f4f4e45 ("memory: fix for multi process support")

BSD EAL:
Fixes: 764bf26873b9 ("add FreeBSD support")

Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>
---
 lib/librte_eal/bsdapp/eal/eal.c   | 6 +++---
 lib/librte_eal/linuxapp/eal/eal.c | 6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c
index a34e61d..06bfd4e 100644
--- a/lib/librte_eal/bsdapp/eal/eal.c
+++ b/lib/librte_eal/bsdapp/eal/eal.c
@@ -1,7 +1,7 @@
 /*-
  *   BSD LICENSE
  *
- *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
  *   Copyright(c) 2014 6WIND S.A.
  *   All rights reserved.
  *
@@ -569,8 +569,6 @@ rte_eal_init(int argc, char **argv)
 
 	eal_check_mem_on_local_socket();
 
-	rte_eal_mcfg_complete();
-
 	if (eal_plugins_init() < 0)
 		rte_panic("Cannot init plugins\n");
 
@@ -621,6 +619,8 @@ rte_eal_init(int argc, char **argv)
 	if (rte_eal_pci_probe())
 		rte_panic("Cannot probe PCI\n");
 
+	rte_eal_mcfg_complete();
+
 	return fctret;
 }
 
diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c
index ceac435..364f303 100644
--- a/lib/librte_eal/linuxapp/eal/eal.c
+++ b/lib/librte_eal/linuxapp/eal/eal.c
@@ -1,7 +1,7 @@
 /*-
  *   BSD LICENSE
  *
- *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
  *   Copyright(c) 2012-2014 6WIND S.A.
  *   All rights reserved.
  *
@@ -821,8 +821,6 @@ rte_eal_init(int argc, char **argv)
 
 	eal_check_mem_on_local_socket();
 
-	rte_eal_mcfg_complete();
-
 	if (eal_plugins_init() < 0)
 		rte_panic("Cannot init plugins\n");
 
@@ -880,6 +878,8 @@ rte_eal_init(int argc, char **argv)
 	if (rte_eal_pci_probe())
 		rte_panic("Cannot probe PCI\n");
 
+	rte_eal_mcfg_complete();
+
 	return fctret;
 }
 
-- 
2.5.0

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

* [PATCH v8 2/2] eal: add function to check if primary proc alive
  2016-03-09 10:12             ` [PATCH v8 0/2] eal: add function to check primary alive Harry van Haaren
  2016-03-09 10:12               ` [PATCH v8 1/2] eal: fix race-condition in pri/sec proc startup Harry van Haaren
@ 2016-03-09 10:12               ` Harry van Haaren
  2016-03-09 11:07               ` [PATCH v8 0/2] eal: add function to check primary alive David Marchand
  2016-03-09 13:37               ` [PATCH v9 " Harry van Haaren
  3 siblings, 0 replies; 43+ messages in thread
From: Harry van Haaren @ 2016-03-09 10:12 UTC (permalink / raw)
  To: david.marchand; +Cc: dev

This patch adds a new function to the EAL API:
int rte_eal_primary_proc_alive(const char *path);

The function indicates if a primary process is alive right now.
This functionality is implemented by testing for a write-
lock on the config file, and the function tests for a lock.

The use case for this functionality is that a secondary
process can wait until a primary process starts by polling
the function and waiting. When the primary is running, the
secondary continues to poll to detect if the primary process
has quit unexpectedly, the secondary process can detect this.

Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>
Acked-by: Maryam Tahhan <maryam.tahhan@intel.com>
---
 doc/guides/rel_notes/release_16_04.rst          |  8 ++++
 lib/librte_eal/bsdapp/eal/Makefile              |  1 +
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  1 +
 lib/librte_eal/common/eal_common_proc.c         | 61 +++++++++++++++++++++++++
 lib/librte_eal/common/include/rte_eal.h         | 20 +++++++-
 lib/librte_eal/linuxapp/eal/Makefile            |  3 +-
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |  1 +
 7 files changed, 93 insertions(+), 2 deletions(-)
 create mode 100644 lib/librte_eal/common/eal_common_proc.c

diff --git a/doc/guides/rel_notes/release_16_04.rst b/doc/guides/rel_notes/release_16_04.rst
index 24f15bf..7d5000f 100644
--- a/doc/guides/rel_notes/release_16_04.rst
+++ b/doc/guides/rel_notes/release_16_04.rst
@@ -74,6 +74,14 @@ EAL
 ~~~
 
 
+* **Added rte_eal_primary_proc_alive() function**
+
+  A new function ``rte_eal_primary_proc_alive()`` has been added
+  to allow the user to detect if a primary process is running.
+  Use cases for this feature include fault detection, and monitoring
+  using secondary processes.
+
+
 Drivers
 ~~~~~~~
 
diff --git a/lib/librte_eal/bsdapp/eal/Makefile b/lib/librte_eal/bsdapp/eal/Makefile
index 9015516..9ecf429 100644
--- a/lib/librte_eal/bsdapp/eal/Makefile
+++ b/lib/librte_eal/bsdapp/eal/Makefile
@@ -79,6 +79,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_devargs.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_dev.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_options.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_thread.c
+SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_proc.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += rte_malloc.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += malloc_elem.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += malloc_heap.c
diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
index 0c24223..58c2951 100644
--- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
@@ -148,5 +148,6 @@ DPDK_16.04 {
 	rte_eal_pci_ioport_write;
 	rte_eal_pci_map_device;
 	rte_eal_pci_unmap_device;
+	rte_eal_primary_proc_alive;
 
 } DPDK_2.2;
diff --git a/lib/librte_eal/common/eal_common_proc.c b/lib/librte_eal/common/eal_common_proc.c
new file mode 100644
index 0000000..12e0fca
--- /dev/null
+++ b/lib/librte_eal/common/eal_common_proc.c
@@ -0,0 +1,61 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2016 Intel Corporation. All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <rte_eal.h>
+
+#include "eal_filesystem.h"
+#include "eal_internal_cfg.h"
+
+int
+rte_eal_primary_proc_alive(const char *config_file_path)
+{
+	int config_fd;
+
+	if (config_file_path)
+		config_fd = open(config_file_path, O_RDONLY);
+	else {
+		char default_path[PATH_MAX+1];
+		snprintf(default_path, PATH_MAX, RUNTIME_CONFIG_FMT,
+			 default_config_dir, "rte");
+		config_fd = open(default_path, O_RDONLY);
+	}
+	if (config_fd < 0)
+		return 0;
+
+	int ret = lockf(config_fd, F_TEST, 0);
+	close(config_fd);
+
+	return !!ret;
+}
diff --git a/lib/librte_eal/common/include/rte_eal.h b/lib/librte_eal/common/include/rte_eal.h
index 0e99c31..a71d6f5 100644
--- a/lib/librte_eal/common/include/rte_eal.h
+++ b/lib/librte_eal/common/include/rte_eal.h
@@ -1,7 +1,7 @@
 /*-
  *   BSD LICENSE
  *
- *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
  *   All rights reserved.
  *
  *   Redistribution and use in source and binary forms, with or without
@@ -156,6 +156,24 @@ int rte_eal_iopl_init(void);
  *   - On failure, a negative error value.
  */
 int rte_eal_init(int argc, char **argv);
+
+/**
+ * Check if a primary process is currently alive
+ *
+ * This function returns true when a primary process is currently
+ * active.
+ *
+ * @param config_file_path
+ *   The config_file_path argument provided should point at the location
+ *   that the primary process will create its config file. If NULL, the default
+ *   config file path is used.
+ *
+ * @return
+ *  - If alive, returns 1.
+ *  - If dead, returns 0.
+ */
+int rte_eal_primary_proc_alive(const char *config_file_path);
+
 /**
  * Usage function typedef used by the application usage function.
  *
diff --git a/lib/librte_eal/linuxapp/eal/Makefile b/lib/librte_eal/linuxapp/eal/Makefile
index c5490e4..d72f035 100644
--- a/lib/librte_eal/linuxapp/eal/Makefile
+++ b/lib/librte_eal/linuxapp/eal/Makefile
@@ -1,6 +1,6 @@
 #   BSD LICENSE
 #
-#   Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
+#   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
 #   All rights reserved.
 #
 #   Redistribution and use in source and binary forms, with or without
@@ -89,6 +89,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_devargs.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_dev.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_options.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_thread.c
+SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_proc.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += rte_malloc.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += malloc_elem.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += malloc_heap.c
diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
index 4aa9de7..12503ef 100644
--- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
@@ -151,5 +151,6 @@ DPDK_16.04 {
 	rte_eal_pci_ioport_write;
 	rte_eal_pci_map_device;
 	rte_eal_pci_unmap_device;
+	rte_eal_primary_proc_alive;
 
 } DPDK_2.2;
-- 
2.5.0

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

* Re: [PATCH v8 0/2] eal: add function to check primary alive
  2016-03-09 10:12             ` [PATCH v8 0/2] eal: add function to check primary alive Harry van Haaren
  2016-03-09 10:12               ` [PATCH v8 1/2] eal: fix race-condition in pri/sec proc startup Harry van Haaren
  2016-03-09 10:12               ` [PATCH v8 2/2] eal: add function to check if primary proc alive Harry van Haaren
@ 2016-03-09 11:07               ` David Marchand
  2016-03-09 12:59                 ` Sergio Gonzalez Monroy
  2016-03-09 13:37               ` [PATCH v9 " Harry van Haaren
  3 siblings, 1 reply; 43+ messages in thread
From: David Marchand @ 2016-03-09 11:07 UTC (permalink / raw)
  To: sergio.gonzalez.monroy; +Cc: dev

On Wed, Mar 9, 2016 at 11:12 AM, Harry van Haaren
<harry.van.haaren@intel.com> wrote:
>
> The first patch of this patchset contains a fix for EAL PCI probing,
> to avoid a race-condition where a primary and secondary probe PCI
> devices at the same time.
>
> The second patch adds a function that can be polled by a process to
> detect if a DPDK primary process is alive. This function does not
> rely on rte_eal_init(), as this uses the EAL and thus stops a
> primary from starting.
>
> The functionality provided by this patch is very useful for providing
> additional services to DPDK primary applications such as monitoring
> statistics and performing fault detection.

Sergio, please can you have a look at this patchset ?

Thanks.

-- 
David Marchand

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

* Re: [PATCH v8 0/2] eal: add function to check primary alive
  2016-03-09 11:07               ` [PATCH v8 0/2] eal: add function to check primary alive David Marchand
@ 2016-03-09 12:59                 ` Sergio Gonzalez Monroy
  0 siblings, 0 replies; 43+ messages in thread
From: Sergio Gonzalez Monroy @ 2016-03-09 12:59 UTC (permalink / raw)
  To: David Marchand; +Cc: dev

On 09/03/2016 11:07, David Marchand wrote:
> On Wed, Mar 9, 2016 at 11:12 AM, Harry van Haaren
> <harry.van.haaren@intel.com> wrote:
>> The first patch of this patchset contains a fix for EAL PCI probing,
>> to avoid a race-condition where a primary and secondary probe PCI
>> devices at the same time.
>>
>> The second patch adds a function that can be polled by a process to
>> detect if a DPDK primary process is alive. This function does not
>> rely on rte_eal_init(), as this uses the EAL and thus stops a
>> primary from starting.
>>
>> The functionality provided by this patch is very useful for providing
>> additional services to DPDK primary applications such as monitoring
>> statistics and performing fault detection.
> Sergio, please can you have a look at this patchset ?

Yes, will do.

Sergio

> Thanks.
>

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

* Re: [PATCH v8 1/2] eal: fix race-condition in pri/sec proc startup
  2016-03-09 10:12               ` [PATCH v8 1/2] eal: fix race-condition in pri/sec proc startup Harry van Haaren
@ 2016-03-09 13:23                 ` Sergio Gonzalez Monroy
  0 siblings, 0 replies; 43+ messages in thread
From: Sergio Gonzalez Monroy @ 2016-03-09 13:23 UTC (permalink / raw)
  To: Harry van Haaren, david.marchand; +Cc: dev

On 09/03/2016 10:12, Harry van Haaren wrote:
> This patch fixes a race-condition when a primary and
> secondary process simultaneously probe PCI devices.
>
> This is implemented by moving the rte_eal_mcfg_complete()
> function call in rte_eal_init() until after rte_eal_pci_probe().
>
> The end result is that the secondary process waits longer,
> until the primary has completed its PCI probing, and then
> notifies the secondary process.
>
> This race-condition became visible during the development of
> a function that allows a secondary process to be polling until
> a primary process exists. The secondary would then probe PCI
> devices at the same time, causing an error during rte_eal_init()
>
> Linux EAL:
> Fixes: 916e4f4f4e45 ("memory: fix for multi process support")
>
> BSD EAL:
> Fixes: 764bf26873b9 ("add FreeBSD support")
>
> Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>
> ---
>   lib/librte_eal/bsdapp/eal/eal.c   | 6 +++---
>   lib/librte_eal/linuxapp/eal/eal.c | 6 +++---
>   2 files changed, 6 insertions(+), 6 deletions(-)

Fix is good, I think a bit more detail on the commit message about the
race condition would help for future reference.

So just adding some info pointing out that the mapping of the PCI devices
by the secondary *must* happen after the primary has finished doing the
mapping as it relies on information filled up by the primary.

Other than that,

Acked-by: Sergio Gonzalez Monroy <sergio.gonzalez.monroy@intel.com>

Sergio

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

* [PATCH v9 0/2] eal: add function to check primary alive
  2016-03-09 10:12             ` [PATCH v8 0/2] eal: add function to check primary alive Harry van Haaren
                                 ` (2 preceding siblings ...)
  2016-03-09 11:07               ` [PATCH v8 0/2] eal: add function to check primary alive David Marchand
@ 2016-03-09 13:37               ` Harry van Haaren
  2016-03-09 13:37                 ` [PATCH v9 1/2] eal: fix race-condition in pri/sec proc startup Harry van Haaren
                                   ` (2 more replies)
  3 siblings, 3 replies; 43+ messages in thread
From: Harry van Haaren @ 2016-03-09 13:37 UTC (permalink / raw)
  To: david.marchand; +Cc: dev

The first patch of this patchset contains a fix for EAL PCI probing,
to avoid a race-condition where a primary and secondary probe PCI
devices at the same time.

The second patch adds a function that can be polled by a process to
detect if a DPDK primary process is alive. This function does not
rely on rte_eal_init(), as this uses the EAL and thus stops a
primary from starting.

The functionality provided by this patch is very useful for providing
additional services to DPDK primary applications such as monitoring
statistics and performing fault detection.

v9:
- Improve commit message for EAL fix

v8:
- include implementation of function (got lost in v7)

v7:
- split patch into two, one for eal fix, one for adding functionality

v6:
- Fix license header

v5:
- Renamed returns in doc from words to digits
- Fixed line spacing in docs
- Fixed line spacing in EAL header
- Rebased to master (Makefile conflicts)

v4:
- Rebased to git head (2.3 -> 16.04 changes)

v3:
- Fixed Copyright years

v2:
- Passing NULL as const char* uses default /var/run/.rte_config
- Moved co


Harry van Haaren (2):
  eal: fix race-condition in pri/sec proc startup
  eal: add function to check if primary proc alive

 doc/guides/rel_notes/release_16_04.rst          |  8 ++++
 lib/librte_eal/bsdapp/eal/Makefile              |  1 +
 lib/librte_eal/bsdapp/eal/eal.c                 |  6 +--
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  1 +
 lib/librte_eal/common/eal_common_proc.c         | 61 +++++++++++++++++++++++++
 lib/librte_eal/common/include/rte_eal.h         | 20 +++++++-
 lib/librte_eal/linuxapp/eal/Makefile            |  3 +-
 lib/librte_eal/linuxapp/eal/eal.c               |  6 +--
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |  1 +
 9 files changed, 99 insertions(+), 8 deletions(-)
 create mode 100644 lib/librte_eal/common/eal_common_proc.c

-- 
2.5.0

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

* [PATCH v9 1/2] eal: fix race-condition in pri/sec proc startup
  2016-03-09 13:37               ` [PATCH v9 " Harry van Haaren
@ 2016-03-09 13:37                 ` Harry van Haaren
  2016-03-09 14:27                   ` Sergio Gonzalez Monroy
  2016-03-09 13:37                 ` [PATCH v9 2/2] eal: add function to check if primary proc alive Harry van Haaren
  2016-03-09 15:17                 ` [PATCH v9 0/2] eal: add function to check primary alive Thomas Monjalon
  2 siblings, 1 reply; 43+ messages in thread
From: Harry van Haaren @ 2016-03-09 13:37 UTC (permalink / raw)
  To: david.marchand; +Cc: dev

This patch fixes a race-condition when a primary and
secondary process simultaneously probe PCI devices.

This is implemented by moving the rte_eal_mcfg_complete()
function call in rte_eal_init() until after rte_eal_pci_probe().
The memory mapping of PCI device in the secondary process *must*
happen after the primary has finished doing the mapping as it
relies on information written by the primary.

The end result is that the secondary process waits longer,
until the primary has completed its PCI probing, and then
notifies the secondary process.

This race-condition became visible during the development of
a function that allows a secondary process to be polling until
a primary process exists. The secondary would then probe PCI
devices at the same time, causing an error during rte_eal_init()

Linux EAL:
Fixes: 916e4f4f4e45 ("memory: fix for multi process support")

BSD EAL:
Fixes: 764bf26873b9 ("add FreeBSD support")

Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>
---
 lib/librte_eal/bsdapp/eal/eal.c   | 6 +++---
 lib/librte_eal/linuxapp/eal/eal.c | 6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c
index a34e61d..06bfd4e 100644
--- a/lib/librte_eal/bsdapp/eal/eal.c
+++ b/lib/librte_eal/bsdapp/eal/eal.c
@@ -1,7 +1,7 @@
 /*-
  *   BSD LICENSE
  *
- *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
  *   Copyright(c) 2014 6WIND S.A.
  *   All rights reserved.
  *
@@ -569,8 +569,6 @@ rte_eal_init(int argc, char **argv)
 
 	eal_check_mem_on_local_socket();
 
-	rte_eal_mcfg_complete();
-
 	if (eal_plugins_init() < 0)
 		rte_panic("Cannot init plugins\n");
 
@@ -621,6 +619,8 @@ rte_eal_init(int argc, char **argv)
 	if (rte_eal_pci_probe())
 		rte_panic("Cannot probe PCI\n");
 
+	rte_eal_mcfg_complete();
+
 	return fctret;
 }
 
diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c
index ceac435..364f303 100644
--- a/lib/librte_eal/linuxapp/eal/eal.c
+++ b/lib/librte_eal/linuxapp/eal/eal.c
@@ -1,7 +1,7 @@
 /*-
  *   BSD LICENSE
  *
- *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
  *   Copyright(c) 2012-2014 6WIND S.A.
  *   All rights reserved.
  *
@@ -821,8 +821,6 @@ rte_eal_init(int argc, char **argv)
 
 	eal_check_mem_on_local_socket();
 
-	rte_eal_mcfg_complete();
-
 	if (eal_plugins_init() < 0)
 		rte_panic("Cannot init plugins\n");
 
@@ -880,6 +878,8 @@ rte_eal_init(int argc, char **argv)
 	if (rte_eal_pci_probe())
 		rte_panic("Cannot probe PCI\n");
 
+	rte_eal_mcfg_complete();
+
 	return fctret;
 }
 
-- 
2.5.0

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

* [PATCH v9 2/2] eal: add function to check if primary proc alive
  2016-03-09 13:37               ` [PATCH v9 " Harry van Haaren
  2016-03-09 13:37                 ` [PATCH v9 1/2] eal: fix race-condition in pri/sec proc startup Harry van Haaren
@ 2016-03-09 13:37                 ` Harry van Haaren
  2016-03-09 15:02                   ` Thomas Monjalon
  2016-03-09 15:17                 ` [PATCH v9 0/2] eal: add function to check primary alive Thomas Monjalon
  2 siblings, 1 reply; 43+ messages in thread
From: Harry van Haaren @ 2016-03-09 13:37 UTC (permalink / raw)
  To: david.marchand; +Cc: dev

This patch adds a new function to the EAL API:
int rte_eal_primary_proc_alive(const char *path);

The function indicates if a primary process is alive right now.
This functionality is implemented by testing for a write-
lock on the config file, and the function tests for a lock.

The use case for this functionality is that a secondary
process can wait until a primary process starts by polling
the function and waiting. When the primary is running, the
secondary continues to poll to detect if the primary process
has quit unexpectedly, the secondary process can detect this.

Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>
Acked-by: Maryam Tahhan <maryam.tahhan@intel.com>
---
 doc/guides/rel_notes/release_16_04.rst          |  8 ++++
 lib/librte_eal/bsdapp/eal/Makefile              |  1 +
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  1 +
 lib/librte_eal/common/eal_common_proc.c         | 61 +++++++++++++++++++++++++
 lib/librte_eal/common/include/rte_eal.h         | 20 +++++++-
 lib/librte_eal/linuxapp/eal/Makefile            |  3 +-
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |  1 +
 7 files changed, 93 insertions(+), 2 deletions(-)
 create mode 100644 lib/librte_eal/common/eal_common_proc.c

diff --git a/doc/guides/rel_notes/release_16_04.rst b/doc/guides/rel_notes/release_16_04.rst
index 24f15bf..7d5000f 100644
--- a/doc/guides/rel_notes/release_16_04.rst
+++ b/doc/guides/rel_notes/release_16_04.rst
@@ -74,6 +74,14 @@ EAL
 ~~~
 
 
+* **Added rte_eal_primary_proc_alive() function**
+
+  A new function ``rte_eal_primary_proc_alive()`` has been added
+  to allow the user to detect if a primary process is running.
+  Use cases for this feature include fault detection, and monitoring
+  using secondary processes.
+
+
 Drivers
 ~~~~~~~
 
diff --git a/lib/librte_eal/bsdapp/eal/Makefile b/lib/librte_eal/bsdapp/eal/Makefile
index 9015516..9ecf429 100644
--- a/lib/librte_eal/bsdapp/eal/Makefile
+++ b/lib/librte_eal/bsdapp/eal/Makefile
@@ -79,6 +79,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_devargs.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_dev.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_options.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_thread.c
+SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_proc.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += rte_malloc.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += malloc_elem.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += malloc_heap.c
diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
index 0c24223..58c2951 100644
--- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
@@ -148,5 +148,6 @@ DPDK_16.04 {
 	rte_eal_pci_ioport_write;
 	rte_eal_pci_map_device;
 	rte_eal_pci_unmap_device;
+	rte_eal_primary_proc_alive;
 
 } DPDK_2.2;
diff --git a/lib/librte_eal/common/eal_common_proc.c b/lib/librte_eal/common/eal_common_proc.c
new file mode 100644
index 0000000..12e0fca
--- /dev/null
+++ b/lib/librte_eal/common/eal_common_proc.c
@@ -0,0 +1,61 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2016 Intel Corporation. All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <rte_eal.h>
+
+#include "eal_filesystem.h"
+#include "eal_internal_cfg.h"
+
+int
+rte_eal_primary_proc_alive(const char *config_file_path)
+{
+	int config_fd;
+
+	if (config_file_path)
+		config_fd = open(config_file_path, O_RDONLY);
+	else {
+		char default_path[PATH_MAX+1];
+		snprintf(default_path, PATH_MAX, RUNTIME_CONFIG_FMT,
+			 default_config_dir, "rte");
+		config_fd = open(default_path, O_RDONLY);
+	}
+	if (config_fd < 0)
+		return 0;
+
+	int ret = lockf(config_fd, F_TEST, 0);
+	close(config_fd);
+
+	return !!ret;
+}
diff --git a/lib/librte_eal/common/include/rte_eal.h b/lib/librte_eal/common/include/rte_eal.h
index 0e99c31..a71d6f5 100644
--- a/lib/librte_eal/common/include/rte_eal.h
+++ b/lib/librte_eal/common/include/rte_eal.h
@@ -1,7 +1,7 @@
 /*-
  *   BSD LICENSE
  *
- *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
  *   All rights reserved.
  *
  *   Redistribution and use in source and binary forms, with or without
@@ -156,6 +156,24 @@ int rte_eal_iopl_init(void);
  *   - On failure, a negative error value.
  */
 int rte_eal_init(int argc, char **argv);
+
+/**
+ * Check if a primary process is currently alive
+ *
+ * This function returns true when a primary process is currently
+ * active.
+ *
+ * @param config_file_path
+ *   The config_file_path argument provided should point at the location
+ *   that the primary process will create its config file. If NULL, the default
+ *   config file path is used.
+ *
+ * @return
+ *  - If alive, returns 1.
+ *  - If dead, returns 0.
+ */
+int rte_eal_primary_proc_alive(const char *config_file_path);
+
 /**
  * Usage function typedef used by the application usage function.
  *
diff --git a/lib/librte_eal/linuxapp/eal/Makefile b/lib/librte_eal/linuxapp/eal/Makefile
index c5490e4..d72f035 100644
--- a/lib/librte_eal/linuxapp/eal/Makefile
+++ b/lib/librte_eal/linuxapp/eal/Makefile
@@ -1,6 +1,6 @@
 #   BSD LICENSE
 #
-#   Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
+#   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
 #   All rights reserved.
 #
 #   Redistribution and use in source and binary forms, with or without
@@ -89,6 +89,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_devargs.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_dev.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_options.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_thread.c
+SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_proc.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += rte_malloc.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += malloc_elem.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += malloc_heap.c
diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
index 4aa9de7..12503ef 100644
--- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
@@ -151,5 +151,6 @@ DPDK_16.04 {
 	rte_eal_pci_ioport_write;
 	rte_eal_pci_map_device;
 	rte_eal_pci_unmap_device;
+	rte_eal_primary_proc_alive;
 
 } DPDK_2.2;
-- 
2.5.0

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

* Re: [PATCH v9 1/2] eal: fix race-condition in pri/sec proc startup
  2016-03-09 13:37                 ` [PATCH v9 1/2] eal: fix race-condition in pri/sec proc startup Harry van Haaren
@ 2016-03-09 14:27                   ` Sergio Gonzalez Monroy
  0 siblings, 0 replies; 43+ messages in thread
From: Sergio Gonzalez Monroy @ 2016-03-09 14:27 UTC (permalink / raw)
  To: Harry van Haaren, david.marchand; +Cc: dev

On 09/03/2016 13:37, Harry van Haaren wrote:
> This patch fixes a race-condition when a primary and
> secondary process simultaneously probe PCI devices.
>
> This is implemented by moving the rte_eal_mcfg_complete()
> function call in rte_eal_init() until after rte_eal_pci_probe().
> The memory mapping of PCI device in the secondary process *must*
> happen after the primary has finished doing the mapping as it
> relies on information written by the primary.
>
> The end result is that the secondary process waits longer,
> until the primary has completed its PCI probing, and then
> notifies the secondary process.
>
> This race-condition became visible during the development of
> a function that allows a secondary process to be polling until
> a primary process exists. The secondary would then probe PCI
> devices at the same time, causing an error during rte_eal_init()
>
> Linux EAL:
> Fixes: 916e4f4f4e45 ("memory: fix for multi process support")
>
> BSD EAL:
> Fixes: 764bf26873b9 ("add FreeBSD support")
>
> Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>
> ---
>

Acked-by: Sergio Gonzalez Monroy <sergio.gonzalez.monroy@intel.com>

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

* Re: [PATCH v9 2/2] eal: add function to check if primary proc alive
  2016-03-09 13:37                 ` [PATCH v9 2/2] eal: add function to check if primary proc alive Harry van Haaren
@ 2016-03-09 15:02                   ` Thomas Monjalon
  0 siblings, 0 replies; 43+ messages in thread
From: Thomas Monjalon @ 2016-03-09 15:02 UTC (permalink / raw)
  To: Harry van Haaren; +Cc: dev

2016-03-09 13:37, Harry van Haaren:
> This patch adds a new function to the EAL API:
> int rte_eal_primary_proc_alive(const char *path);
> 
> The function indicates if a primary process is alive right now.
> This functionality is implemented by testing for a write-
> lock on the config file, and the function tests for a lock.
> 
> The use case for this functionality is that a secondary
> process can wait until a primary process starts by polling
> the function and waiting. When the primary is running, the
> secondary continues to poll to detect if the primary process
> has quit unexpectedly, the secondary process can detect this.
> 
> Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>
> Acked-by: Maryam Tahhan <maryam.tahhan@intel.com>
> ---
>  doc/guides/rel_notes/release_16_04.rst          |  8 ++++
>  lib/librte_eal/bsdapp/eal/Makefile              |  1 +
>  lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  1 +
>  lib/librte_eal/common/eal_common_proc.c         | 61 +++++++++++++++++++++++++
>  lib/librte_eal/common/include/rte_eal.h         | 20 +++++++-
>  lib/librte_eal/linuxapp/eal/Makefile            |  3 +-
>  lib/librte_eal/linuxapp/eal/rte_eal_version.map |  1 +
>  7 files changed, 93 insertions(+), 2 deletions(-)
>  create mode 100644 lib/librte_eal/common/eal_common_proc.c
> 
> diff --git a/doc/guides/rel_notes/release_16_04.rst b/doc/guides/rel_notes/release_16_04.rst
> index 24f15bf..7d5000f 100644
> --- a/doc/guides/rel_notes/release_16_04.rst
> +++ b/doc/guides/rel_notes/release_16_04.rst
> @@ -74,6 +74,14 @@ EAL
>  ~~~
>  
>  
> +* **Added rte_eal_primary_proc_alive() function**
> +
> +  A new function ``rte_eal_primary_proc_alive()`` has been added
> +  to allow the user to detect if a primary process is running.
> +  Use cases for this feature include fault detection, and monitoring
> +  using secondary processes.

It is not in the right section (fixed issues).
Moved and reworded before applying:
* **Added function to check primary process state.**

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

* Re: [PATCH v9 0/2] eal: add function to check primary alive
  2016-03-09 13:37               ` [PATCH v9 " Harry van Haaren
  2016-03-09 13:37                 ` [PATCH v9 1/2] eal: fix race-condition in pri/sec proc startup Harry van Haaren
  2016-03-09 13:37                 ` [PATCH v9 2/2] eal: add function to check if primary proc alive Harry van Haaren
@ 2016-03-09 15:17                 ` Thomas Monjalon
  2 siblings, 0 replies; 43+ messages in thread
From: Thomas Monjalon @ 2016-03-09 15:17 UTC (permalink / raw)
  To: Harry van Haaren; +Cc: dev

2016-03-09 13:37, Harry van Haaren:
> The first patch of this patchset contains a fix for EAL PCI probing,
> to avoid a race-condition where a primary and secondary probe PCI
> devices at the same time.
> 
> The second patch adds a function that can be polled by a process to
> detect if a DPDK primary process is alive. This function does not
> rely on rte_eal_init(), as this uses the EAL and thus stops a
> primary from starting.
> 
> The functionality provided by this patch is very useful for providing
> additional services to DPDK primary applications such as monitoring
> statistics and performing fault detection.

Applied, thanks

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

end of thread, other threads:[~2016-03-09 15:19 UTC | newest]

Thread overview: 43+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-20 13:25 [PATCH] eal: add function to check if primary proc alive Harry van Haaren
2016-01-21  6:14 ` Qiu, Michael
2016-01-21  6:19   ` Matthew Hall
2016-01-21  9:02   ` Van Haaren, Harry
2016-01-22 17:37     ` Bruce Richardson
2016-01-25  8:06       ` Qiu, Michael
2016-01-25 11:44       ` Van Haaren, Harry
2016-01-26 19:13         ` Bruce Richardson
2016-01-27 10:35           ` Van Haaren, Harry
2016-01-25  8:11 ` Qiu, Michael
2016-01-25 11:51   ` Van Haaren, Harry
2016-01-26  2:25     ` Qiu, Michael
2016-01-26  9:04       ` Van Haaren, Harry
2016-01-26 11:07         ` Qiu, Michael
2016-01-26 11:19           ` Van Haaren, Harry
2016-01-27 10:31 ` [PATCH v2] " Harry van Haaren
2016-02-02 14:11   ` [PATCH v3] " Harry van Haaren
2016-02-23 14:10     ` [PATCH v4] " Harry van Haaren
2016-02-24 13:50       ` Tahhan, Maryam
2016-03-04 18:07       ` Thomas Monjalon
2016-03-07 11:37       ` [PATCH v5] " Harry van Haaren
2016-03-07 12:02         ` [PATCH v6] " Harry van Haaren
2016-03-08  8:42           ` David Marchand
2016-03-08  9:58             ` Van Haaren, Harry
2016-03-08 11:13               ` Thomas Monjalon
2016-03-08 11:19                 ` David Marchand
2016-03-08 13:57                   ` Van Haaren, Harry
2016-03-08 14:40                     ` David Marchand
2016-03-08 17:07           ` [PATCH v7 0/2] eal: add function to check primary alive Harry van Haaren
2016-03-08 17:07             ` [PATCH v7 1/2] eal: fix race-condition in pri/sec proc startup Harry van Haaren
2016-03-08 17:07             ` [PATCH v7 2/2] eal: add function to check if primary proc alive Harry van Haaren
2016-03-09 10:12             ` [PATCH v8 0/2] eal: add function to check primary alive Harry van Haaren
2016-03-09 10:12               ` [PATCH v8 1/2] eal: fix race-condition in pri/sec proc startup Harry van Haaren
2016-03-09 13:23                 ` Sergio Gonzalez Monroy
2016-03-09 10:12               ` [PATCH v8 2/2] eal: add function to check if primary proc alive Harry van Haaren
2016-03-09 11:07               ` [PATCH v8 0/2] eal: add function to check primary alive David Marchand
2016-03-09 12:59                 ` Sergio Gonzalez Monroy
2016-03-09 13:37               ` [PATCH v9 " Harry van Haaren
2016-03-09 13:37                 ` [PATCH v9 1/2] eal: fix race-condition in pri/sec proc startup Harry van Haaren
2016-03-09 14:27                   ` Sergio Gonzalez Monroy
2016-03-09 13:37                 ` [PATCH v9 2/2] eal: add function to check if primary proc alive Harry van Haaren
2016-03-09 15:02                   ` Thomas Monjalon
2016-03-09 15:17                 ` [PATCH v9 0/2] eal: add function to check primary alive Thomas Monjalon

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.