[API-NEXT,PATCHv6,05/13] api: shm: add flags to shm_reserve and function to find external mem

Message ID 1477903945-39693-6-git-send-email-christophe.milard@linaro.org
State New
Headers show

Commit Message

Christophe Milard Oct. 31, 2016, 8:52 a.m.
The ODP_SHM_SINGLE_VA flag is created: when set (at odp_shm_reserve()),
this flag guarantees that all ODP threads sharing this memory
block will see the block at the same address (regadless of ODP
thread type -pthread vs process- or fork time)

The flag ODP_SHM_EXPORT is added: when passed at odp_shm_reserve() time
the memory block becomes visible to other ODP instances.
The function odp_shm_find_exported() is added: this function enables to
reserve block of memories exported by other ODP instances (using the
ODP_SHM_EXPORT flag).

Signed-off-by: Christophe Milard <christophe.milard@linaro.org>

---
 include/odp/api/spec/shared_memory.h | 38 +++++++++++++++++++++++++++++++-----
 1 file changed, 33 insertions(+), 5 deletions(-)

-- 
2.7.4

Comments

Maxim Uvarov Oct. 31, 2016, 12:33 p.m. | #1
Petri,

please review API patch.


On 10/31/16 11:52, Christophe Milard wrote:
> The ODP_SHM_SINGLE_VA flag is created: when set (at odp_shm_reserve()),

> this flag guarantees that all ODP threads sharing this memory

> block will see the block at the same address (regadless of ODP

> thread type -pthread vs process- or fork time)

>

> The flag ODP_SHM_EXPORT is added: when passed at odp_shm_reserve() time

> the memory block becomes visible to other ODP instances.

> The function odp_shm_find_exported() is added: this function enables to

> reserve block of memories exported by other ODP instances (using the

> ODP_SHM_EXPORT flag).

>

> Signed-off-by: Christophe Milard <christophe.milard@linaro.org>

> ---

>   include/odp/api/spec/shared_memory.h | 38 +++++++++++++++++++++++++++++++-----

>   1 file changed, 33 insertions(+), 5 deletions(-)

>

> diff --git a/include/odp/api/spec/shared_memory.h b/include/odp/api/spec/shared_memory.h

> index 8c76807..80cc143 100644

> --- a/include/odp/api/spec/shared_memory.h

> +++ b/include/odp/api/spec/shared_memory.h

> @@ -14,6 +14,7 @@

>   #ifndef ODP_API_SHARED_MEMORY_H_

>   #define ODP_API_SHARED_MEMORY_H_

>   #include <odp/visibility_begin.h>

> +#include <odp/api/init.h>

>   

>   #ifdef __cplusplus

>   extern "C" {

> @@ -43,12 +44,25 @@ extern "C" {

>   #define ODP_SHM_NAME_LEN 32

>   

>   /*

> - * Shared memory flags

> + * Shared memory flags:

>    */

> -

> -/* Share level */

> -#define ODP_SHM_SW_ONLY 0x1 /**< Application SW only, no HW access */

> -#define ODP_SHM_PROC    0x2 /**< Share with external processes */

> +#define ODP_SHM_SW_ONLY		0x1 /**< Application SW only, no HW access   */

> +#define ODP_SHM_PROC		0x2 /**< Share with external processes       */

> +/**

> + * Single virtual address

> + *

> + * When set, this flag guarantees that all ODP threads sharing this

> + * memory block will see the block at the same address - regardless

> + * of ODP thread type (e.g. pthread vs. process (or fork process time)).

> + */

> +#define ODP_SHM_SINGLE_VA	0x4

> +/**

> + * Export memory

> + *

> + * When set, the memory block becomes visible to other ODP instances

> + * through odp_shm_find_exported().

> + */

> +#define ODP_SHM_EXPORT		0x08

>   

>   /**

>    * Shared memory block info

> @@ -135,6 +149,20 @@ int odp_shm_free(odp_shm_t shm);

>    */

>   odp_shm_t odp_shm_lookup(const char *name);

>   

> +/**

> + * Get and reserve a block of shared memory, exported by another ODP instance

> + *

> + * @param remote_name  Name of the block, in the remote ODP instance

> + * @param odp_inst     Remote ODP instance, as returned by odp_init_global()

> + * @param local_name   Name given to the block, in the local ODP instance

> + *		       (or NULL, if the application doesn't care)

> + *

> + * @return A new handle to the block if it is found (must be freed when done).

> + * @retval ODP_SHM_INVALID on failure

> + */

> +odp_shm_t odp_shm_find_exported(const char *remote_name,

> +				odp_instance_t odp_inst,

> +				const char *local_name);

>   

I might lost some discussion. But for now it looks like we can
extend odp_shm_lookup() with that arguments. I.e. if odp_inst = 0,
local look up will be done.

Maxim.

>   /**

>    * Shared memory block address
Christophe Milard Oct. 31, 2016, 1:06 p.m. | #2
don't agree, as this is not a lookup.  That was the confusion I was
trying to avoid by having it as a reserve_*) function...
This one allocates a new handles, and therefore needs a free().
In my eyes, the former name, reserve_exoprted() was better, but Petri nacked it.

On 31 October 2016 at 13:33, Maxim Uvarov <maxim.uvarov@linaro.org> wrote:
> Petri,

>

> please review API patch.

>

>

>

> On 10/31/16 11:52, Christophe Milard wrote:

>>

>> The ODP_SHM_SINGLE_VA flag is created: when set (at odp_shm_reserve()),

>> this flag guarantees that all ODP threads sharing this memory

>> block will see the block at the same address (regadless of ODP

>> thread type -pthread vs process- or fork time)

>>

>> The flag ODP_SHM_EXPORT is added: when passed at odp_shm_reserve() time

>> the memory block becomes visible to other ODP instances.

>> The function odp_shm_find_exported() is added: this function enables to

>> reserve block of memories exported by other ODP instances (using the

>> ODP_SHM_EXPORT flag).

>>

>> Signed-off-by: Christophe Milard <christophe.milard@linaro.org>

>> ---

>>   include/odp/api/spec/shared_memory.h | 38

>> +++++++++++++++++++++++++++++++-----

>>   1 file changed, 33 insertions(+), 5 deletions(-)

>>

>> diff --git a/include/odp/api/spec/shared_memory.h

>> b/include/odp/api/spec/shared_memory.h

>> index 8c76807..80cc143 100644

>> --- a/include/odp/api/spec/shared_memory.h

>> +++ b/include/odp/api/spec/shared_memory.h

>> @@ -14,6 +14,7 @@

>>   #ifndef ODP_API_SHARED_MEMORY_H_

>>   #define ODP_API_SHARED_MEMORY_H_

>>   #include <odp/visibility_begin.h>

>> +#include <odp/api/init.h>

>>     #ifdef __cplusplus

>>   extern "C" {

>> @@ -43,12 +44,25 @@ extern "C" {

>>   #define ODP_SHM_NAME_LEN 32

>>     /*

>> - * Shared memory flags

>> + * Shared memory flags:

>>    */

>> -

>> -/* Share level */

>> -#define ODP_SHM_SW_ONLY 0x1 /**< Application SW only, no HW access */

>> -#define ODP_SHM_PROC    0x2 /**< Share with external processes */

>> +#define ODP_SHM_SW_ONLY                0x1 /**< Application SW only, no

>> HW access   */

>> +#define ODP_SHM_PROC           0x2 /**< Share with external processes

>> */

>> +/**

>> + * Single virtual address

>> + *

>> + * When set, this flag guarantees that all ODP threads sharing this

>> + * memory block will see the block at the same address - regardless

>> + * of ODP thread type (e.g. pthread vs. process (or fork process time)).

>> + */

>> +#define ODP_SHM_SINGLE_VA      0x4

>> +/**

>> + * Export memory

>> + *

>> + * When set, the memory block becomes visible to other ODP instances

>> + * through odp_shm_find_exported().

>> + */

>> +#define ODP_SHM_EXPORT         0x08

>>     /**

>>    * Shared memory block info

>> @@ -135,6 +149,20 @@ int odp_shm_free(odp_shm_t shm);

>>    */

>>   odp_shm_t odp_shm_lookup(const char *name);

>>   +/**

>> + * Get and reserve a block of shared memory, exported by another ODP

>> instance

>> + *

>> + * @param remote_name  Name of the block, in the remote ODP instance

>> + * @param odp_inst     Remote ODP instance, as returned by

>> odp_init_global()

>> + * @param local_name   Name given to the block, in the local ODP instance

>> + *                    (or NULL, if the application doesn't care)

>> + *

>> + * @return A new handle to the block if it is found (must be freed when

>> done).

>> + * @retval ODP_SHM_INVALID on failure

>> + */

>> +odp_shm_t odp_shm_find_exported(const char *remote_name,

>> +                               odp_instance_t odp_inst,

>> +                               const char *local_name);

>>

>

> I might lost some discussion. But for now it looks like we can

> extend odp_shm_lookup() with that arguments. I.e. if odp_inst = 0,

> local look up will be done.

>

> Maxim.

>

>

>>   /**

>>    * Shared memory block address

>

>
Savolainen, Petri (Nokia - FI/Espoo) Nov. 17, 2016, 11:28 a.m. | #3
> -----Original Message-----

> From: lng-odp [mailto:lng-odp-bounces@lists.linaro.org] On Behalf Of

> Christophe Milard

> Sent: Monday, October 31, 2016 10:52 AM

> To: mike.holmes@linaro.org; bill.fischofer@linaro.org; lng-

> odp@lists.linaro.org

> Subject: [lng-odp] [API-NEXT PATCHv6 05/13] api: shm: add flags to

> shm_reserve and function to find external mem

> 

> The ODP_SHM_SINGLE_VA flag is created: when set (at odp_shm_reserve()),

> this flag guarantees that all ODP threads sharing this memory

> block will see the block at the same address (regadless of ODP

> thread type -pthread vs process- or fork time)

> 

> The flag ODP_SHM_EXPORT is added: when passed at odp_shm_reserve() time

> the memory block becomes visible to other ODP instances.

> The function odp_shm_find_exported() is added: this function enables to

> reserve block of memories exported by other ODP instances (using the

> ODP_SHM_EXPORT flag).

> 

> Signed-off-by: Christophe Milard <christophe.milard@linaro.org>

> ---

>  include/odp/api/spec/shared_memory.h | 38

> +++++++++++++++++++++++++++++++-----

>  1 file changed, 33 insertions(+), 5 deletions(-)

> 

> diff --git a/include/odp/api/spec/shared_memory.h

> b/include/odp/api/spec/shared_memory.h

> index 8c76807..80cc143 100644

> --- a/include/odp/api/spec/shared_memory.h

> +++ b/include/odp/api/spec/shared_memory.h

> @@ -14,6 +14,7 @@

>  #ifndef ODP_API_SHARED_MEMORY_H_

>  #define ODP_API_SHARED_MEMORY_H_

>  #include <odp/visibility_begin.h>

> +#include <odp/api/init.h>

> 

>  #ifdef __cplusplus

>  extern "C" {

> @@ -43,12 +44,25 @@ extern "C" {

>  #define ODP_SHM_NAME_LEN 32

> 

>  /*

> - * Shared memory flags

> + * Shared memory flags:

>   */

> -

> -/* Share level */

> -#define ODP_SHM_SW_ONLY 0x1 /**< Application SW only, no HW access */

> -#define ODP_SHM_PROC    0x2 /**< Share with external processes */

> +#define ODP_SHM_SW_ONLY		0x1 /**< Application SW only, no HW

> access   */

> +#define ODP_SHM_PROC		0x2 /**< Share with external processes

> */

> +/**

> + * Single virtual address

> + *

> + * When set, this flag guarantees that all ODP threads sharing this

> + * memory block will see the block at the same address - regardless

> + * of ODP thread type (e.g. pthread vs. process (or fork process time)).

> + */

> +#define ODP_SHM_SINGLE_VA	0x4

> +/**

> + * Export memory

> + *

> + * When set, the memory block becomes visible to other ODP instances

> + * through odp_shm_find_exported().


Through odp_shm_import() see under

> + */

> +#define ODP_SHM_EXPORT		0x08

> 

>  /**

>   * Shared memory block info

> @@ -135,6 +149,20 @@ int odp_shm_free(odp_shm_t shm);

>   */

>  odp_shm_t odp_shm_lookup(const char *name);

> 

> +/**

> + * Get and reserve a block of shared memory, exported by another ODP

> instance

> + *

> + * @param remote_name  Name of the block, in the remote ODP instance

> + * @param odp_inst     Remote ODP instance, as returned by

> odp_init_global()

> + * @param local_name   Name given to the block, in the local ODP instance

> + *		       (or NULL, if the application doesn't care)

> + *

> + * @return A new handle to the block if it is found (must be freed when

> done).

> + * @retval ODP_SHM_INVALID on failure

> + */

> +odp_shm_t odp_shm_find_exported(const char *remote_name,

> +				odp_instance_t odp_inst,

> +				const char *local_name);



Patch is otherwise OK, but I think export -> import is a better naming convention. I also updated the spec text to be a bit more specific about the feature, see under.

/**
 * Import a block of shared memory that was exported by another ODP instance
 *
 * This call creates a new handle for accessing a shared memory block created
 * (with ODP_SHM_EXPORT flag) by another ODP instance. An instance may have
 * only a single handle to the same block. Application must not access the
 * block after freeing the handle. When an imported handle is freed, only
 * the calling instance is affected. The exported block may be freed only
 * after all other instances have stopped accessing the block.
 *
 * @param remote_name  Name of the block, in the remote ODP instance
 * @param odp_inst     Remote ODP instance, as returned by odp_init_global()
 * @param local_name   Name given to the shm block, in the local ODP instance.
 *                     May be NULL, if the application doesn't need a name
 *                     (for a lookup).
 *
 * @return A handle to access a block exported by another ODP instance
 * @retval ODP_SHM_INVALID on failure
 */
odp_shm_t odp_shm_import(const char *remote_name, odp_instance_t odp_inst,
				 const char *local_name);


-Petri

Patch

diff --git a/include/odp/api/spec/shared_memory.h b/include/odp/api/spec/shared_memory.h
index 8c76807..80cc143 100644
--- a/include/odp/api/spec/shared_memory.h
+++ b/include/odp/api/spec/shared_memory.h
@@ -14,6 +14,7 @@ 
 #ifndef ODP_API_SHARED_MEMORY_H_
 #define ODP_API_SHARED_MEMORY_H_
 #include <odp/visibility_begin.h>
+#include <odp/api/init.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -43,12 +44,25 @@  extern "C" {
 #define ODP_SHM_NAME_LEN 32
 
 /*
- * Shared memory flags
+ * Shared memory flags:
  */
-
-/* Share level */
-#define ODP_SHM_SW_ONLY 0x1 /**< Application SW only, no HW access */
-#define ODP_SHM_PROC    0x2 /**< Share with external processes */
+#define ODP_SHM_SW_ONLY		0x1 /**< Application SW only, no HW access   */
+#define ODP_SHM_PROC		0x2 /**< Share with external processes       */
+/**
+ * Single virtual address
+ *
+ * When set, this flag guarantees that all ODP threads sharing this
+ * memory block will see the block at the same address - regardless
+ * of ODP thread type (e.g. pthread vs. process (or fork process time)).
+ */
+#define ODP_SHM_SINGLE_VA	0x4
+/**
+ * Export memory
+ *
+ * When set, the memory block becomes visible to other ODP instances
+ * through odp_shm_find_exported().
+ */
+#define ODP_SHM_EXPORT		0x08
 
 /**
  * Shared memory block info
@@ -135,6 +149,20 @@  int odp_shm_free(odp_shm_t shm);
  */
 odp_shm_t odp_shm_lookup(const char *name);
 
+/**
+ * Get and reserve a block of shared memory, exported by another ODP instance
+ *
+ * @param remote_name  Name of the block, in the remote ODP instance
+ * @param odp_inst     Remote ODP instance, as returned by odp_init_global()
+ * @param local_name   Name given to the block, in the local ODP instance
+ *		       (or NULL, if the application doesn't care)
+ *
+ * @return A new handle to the block if it is found (must be freed when done).
+ * @retval ODP_SHM_INVALID on failure
+ */
+odp_shm_t odp_shm_find_exported(const char *remote_name,
+				odp_instance_t odp_inst,
+				const char *local_name);
 
 /**
  * Shared memory block address