Re: [lng-odp] [PATCH] example: timer: remove global variables to share the data between workers

2015-04-24 Thread Maxim Uvarov

On 04/20/15 11:28, Jerin Jacob wrote:

+   /* Reserve memory for test_globals_t from shared mem */
+   shm = odp_shm_reserve(shm_test_globals, sizeof(test_globals_t),
+ ODP_CACHE_LINE_SIZE, 0);


if (ODP_SHM_INVALID == shm)
return -1;


+   gbls = odp_shm_addr(shm);
+
+   if (gbls == NULL) {
+   EXAMPLE_ERR(Error: shared mem alloc failed.\n);
+   return -1;
+   }

that is not needed.


Thanks,
Maxim.
___
lng-odp mailing list
lng-odp@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/lng-odp


Re: [lng-odp] [PATCH] example: timer: remove global variables to share the data between workers

2015-04-24 Thread Maxim Uvarov

On 04/24/15 12:19, Jerin Jacob wrote:

On Fri, Apr 24, 2015 at 11:39:58AM +0300, Maxim Uvarov wrote:

On 04/20/15 11:28, Jerin Jacob wrote:

+   /* Reserve memory for test_globals_t from shared mem */
+   shm = odp_shm_reserve(shm_test_globals, sizeof(test_globals_t),
+ ODP_CACHE_LINE_SIZE, 0);

if (ODP_SHM_INVALID == shm)
 return -1;


+   gbls = odp_shm_addr(shm);
+
+   if (gbls == NULL) {
+   EXAMPLE_ERR(Error: shared mem alloc failed.\n);
+   return -1;
+   }

that is not needed.

This check should be required. odp_shm_addr() can return NULL.
Above proposed ODP_SHM_INVALID == shm check
may not be required as odp_shm_addr() function will return NULL if shm == 
ODP_SHM_INVALID

yes, but at least for linux-generic it does not check.

Maxim.




Thanks,
Maxim.
___
lng-odp mailing list
lng-odp@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/lng-odp


___
lng-odp mailing list
lng-odp@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/lng-odp


Re: [lng-odp] [PATCH] example: timer: remove global variables to share the data between workers

2015-04-24 Thread Jerin Jacob
On Fri, Apr 24, 2015 at 11:39:58AM +0300, Maxim Uvarov wrote:
 On 04/20/15 11:28, Jerin Jacob wrote:
 +/* Reserve memory for test_globals_t from shared mem */
 +shm = odp_shm_reserve(shm_test_globals, sizeof(test_globals_t),
 +  ODP_CACHE_LINE_SIZE, 0);
 
 if (ODP_SHM_INVALID == shm)
 return -1;
 
 +gbls = odp_shm_addr(shm);
 +
 +if (gbls == NULL) {
 +EXAMPLE_ERR(Error: shared mem alloc failed.\n);
 +return -1;
 +}
 that is not needed.

This check should be required. odp_shm_addr() can return NULL. 
Above proposed ODP_SHM_INVALID == shm check
may not be required as odp_shm_addr() function will return NULL if shm == 
ODP_SHM_INVALID


 
 
 Thanks,
 Maxim.
 ___
 lng-odp mailing list
 lng-odp@lists.linaro.org
 https://lists.linaro.org/mailman/listinfo/lng-odp
___
lng-odp mailing list
lng-odp@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/lng-odp


Re: [lng-odp] [PATCH] example: timer: remove global variables to share the data between workers

2015-04-24 Thread Jerin Jacob
On Mon, Apr 20, 2015 at 02:05:50PM +0530, Jerin Jacob wrote:

ping

 Adding the the complete git commit log for the commit
 
 example: timer: remove global variables to share the data between workers.
 use the odp_shared_memory allocater instead to enable the timer example
 to run on baremetal/linux process execution environments.
 
 
 On Mon, Apr 20, 2015 at 01:58:01PM +0530, Jerin Jacob wrote:
  Signed-off-by: Jerin Jacob jerin.ja...@caviumnetworks.com
  ---
   example/timer/odp_timer_test.c | 124 
  +
   1 file changed, 65 insertions(+), 59 deletions(-)
  
  diff --git a/example/timer/odp_timer_test.c b/example/timer/odp_timer_test.c
  index 6b60ec4..876bf33 100644
  --- a/example/timer/odp_timer_test.c
  +++ b/example/timer/odp_timer_test.c
  @@ -39,18 +39,21 @@ typedef struct {
  int tmo_count; /** Timeout count*/
   } test_args_t;
   
  -
  -/** @private Barrier for test synchronisation */
  -static odp_barrier_t test_barrier;
  -
  -/** @private Pool handle */
  -static odp_pool_t pool;
  -
  -/** @private Timer pool handle */
  -static odp_timer_pool_t tp;
  -
  -/** @private Number of timeouts to receive */
  -static odp_atomic_u32_t remain;
  +/** @private Helper struct for timers */
  +struct test_timer {
  +   odp_timer_t tim;
  +   odp_event_t ev;
  +};
  +
  +/** Test global variables */
  +typedef struct {
  +   test_args_t args;   /** Test argunments*/
  +   odp_barrier_t test_barrier; /** Barrier for test synchronisation*/
  +   odp_pool_t pool;/** pool handle*/
  +   odp_timer_pool_t tp;/** Timer pool handle*/
  +   odp_atomic_u32_t remain;/** Number of timeouts to receive*/
  +   struct test_timer tt[256];  /** Array of all timer helper structs*/
  +} test_globals_t;
   
   /** @private Timer set status ASCII strings */
   static const char *timerset2str(odp_timer_set_t val)
  @@ -69,17 +72,9 @@ static const char *timerset2str(odp_timer_set_t val)
  }
   };
   
  -/** @private Helper struct for timers */
  -struct test_timer {
  -   odp_timer_t tim;
  -   odp_event_t ev;
  -};
  -
  -/** @private Array of all timer helper structs */
  -static struct test_timer tt[256];
   
   /** @private test timeout */
  -static void test_abs_timeouts(int thr, test_args_t *args)
  +static void test_abs_timeouts(int thr, test_globals_t *gbls)
   {
  uint64_t period;
  uint64_t period_ns;
  @@ -92,30 +87,30 @@ static void test_abs_timeouts(int thr, test_args_t 
  *args)
   
  queue = odp_queue_lookup(timer_queue);
   
  -   period_ns = args-period_us*ODP_TIME_USEC;
  -   period= odp_timer_ns_to_tick(tp, period_ns);
  +   period_ns = gbls-args.period_us*ODP_TIME_USEC;
  +   period= odp_timer_ns_to_tick(gbls-tp, period_ns);
   
  EXAMPLE_DBG(  [%i] period %PRIu64 ticks,  %PRIu64 ns\n, thr,
  period, period_ns);
   
  EXAMPLE_DBG(  [%i] current tick %PRIu64\n, thr,
  -   odp_timer_current_tick(tp));
  +   odp_timer_current_tick(gbls-tp));
   
  -   ttp = tt[thr - 1]; /* Thread starts at 1 */
  -   ttp-tim = odp_timer_alloc(tp, queue, ttp);
  +   ttp = gbls-tt[thr];
  +   ttp-tim = odp_timer_alloc(gbls-tp, queue, ttp);
  if (ttp-tim == ODP_TIMER_INVALID) {
  EXAMPLE_ERR(Failed to allocate timer\n);
  return;
  }
  -   tmo = odp_timeout_alloc(pool);
  +   tmo = odp_timeout_alloc(gbls-pool);
  if (tmo == ODP_TIMEOUT_INVALID) {
  EXAMPLE_ERR(Failed to allocate timeout\n);
  return;
  }
  ttp-ev = odp_timeout_to_event(tmo);
  -   tick = odp_timer_current_tick(tp);
  +   tick = odp_timer_current_tick(gbls-tp);
   
  -   while ((int)odp_atomic_load_u32(remain)  0) {
  +   while ((int)odp_atomic_load_u32(gbls-remain)  0) {
  odp_event_t ev;
  odp_timer_set_t rc;
   
  @@ -140,7 +135,7 @@ static void test_abs_timeouts(int thr, test_args_t 
  *args)
  /* Check if odp_schedule() timed out, possibly there
   * are no remaining timeouts to receive */
  } while (ev == ODP_EVENT_INVALID 
  -(int)odp_atomic_load_u32(remain)  0);
  +(int)odp_atomic_load_u32(gbls-remain)  0);
   
  if (ev == ODP_EVENT_INVALID)
  break; /* No more timeouts */
  @@ -161,7 +156,7 @@ static void test_abs_timeouts(int thr, test_args_t 
  *args)
  }
  EXAMPLE_DBG(  [%i] timeout, tick %PRIu64\n, thr, tick);
   
  -   odp_atomic_dec_u32(remain);
  +   odp_atomic_dec_u32(gbls-remain);
  }
   
  /* Cancel and free last timer used */
  @@ -187,9 +182,9 @@ static void *run_thread(void *ptr)
   {
  int thr;
  odp_pool_t msg_pool;
  -   test_args_t *args;
  +   test_globals_t *gbls;
   
  -   args = ptr;
  +   gbls = ptr;
  thr  = odp_thread_id();
   
  printf(Thread %i starts on cpu %i\n, thr, 

Re: [lng-odp] [PATCH] example: timer: remove global variables to share the data between workers

2015-04-20 Thread Jerin Jacob
Adding the the complete git commit log for the commit

example: timer: remove global variables to share the data between workers.
use the odp_shared_memory allocater instead to enable the timer example
to run on baremetal/linux process execution environments.


On Mon, Apr 20, 2015 at 01:58:01PM +0530, Jerin Jacob wrote:
 Signed-off-by: Jerin Jacob jerin.ja...@caviumnetworks.com
 ---
  example/timer/odp_timer_test.c | 124 
 +
  1 file changed, 65 insertions(+), 59 deletions(-)
 
 diff --git a/example/timer/odp_timer_test.c b/example/timer/odp_timer_test.c
 index 6b60ec4..876bf33 100644
 --- a/example/timer/odp_timer_test.c
 +++ b/example/timer/odp_timer_test.c
 @@ -39,18 +39,21 @@ typedef struct {
   int tmo_count; /** Timeout count*/
  } test_args_t;
  
 -
 -/** @private Barrier for test synchronisation */
 -static odp_barrier_t test_barrier;
 -
 -/** @private Pool handle */
 -static odp_pool_t pool;
 -
 -/** @private Timer pool handle */
 -static odp_timer_pool_t tp;
 -
 -/** @private Number of timeouts to receive */
 -static odp_atomic_u32_t remain;
 +/** @private Helper struct for timers */
 +struct test_timer {
 + odp_timer_t tim;
 + odp_event_t ev;
 +};
 +
 +/** Test global variables */
 +typedef struct {
 + test_args_t args;   /** Test argunments*/
 + odp_barrier_t test_barrier; /** Barrier for test synchronisation*/
 + odp_pool_t pool;/** pool handle*/
 + odp_timer_pool_t tp;/** Timer pool handle*/
 + odp_atomic_u32_t remain;/** Number of timeouts to receive*/
 + struct test_timer tt[256];  /** Array of all timer helper structs*/
 +} test_globals_t;
  
  /** @private Timer set status ASCII strings */
  static const char *timerset2str(odp_timer_set_t val)
 @@ -69,17 +72,9 @@ static const char *timerset2str(odp_timer_set_t val)
   }
  };
  
 -/** @private Helper struct for timers */
 -struct test_timer {
 - odp_timer_t tim;
 - odp_event_t ev;
 -};
 -
 -/** @private Array of all timer helper structs */
 -static struct test_timer tt[256];
  
  /** @private test timeout */
 -static void test_abs_timeouts(int thr, test_args_t *args)
 +static void test_abs_timeouts(int thr, test_globals_t *gbls)
  {
   uint64_t period;
   uint64_t period_ns;
 @@ -92,30 +87,30 @@ static void test_abs_timeouts(int thr, test_args_t *args)
  
   queue = odp_queue_lookup(timer_queue);
  
 - period_ns = args-period_us*ODP_TIME_USEC;
 - period= odp_timer_ns_to_tick(tp, period_ns);
 + period_ns = gbls-args.period_us*ODP_TIME_USEC;
 + period= odp_timer_ns_to_tick(gbls-tp, period_ns);
  
   EXAMPLE_DBG(  [%i] period %PRIu64 ticks,  %PRIu64 ns\n, thr,
   period, period_ns);
  
   EXAMPLE_DBG(  [%i] current tick %PRIu64\n, thr,
 - odp_timer_current_tick(tp));
 + odp_timer_current_tick(gbls-tp));
  
 - ttp = tt[thr - 1]; /* Thread starts at 1 */
 - ttp-tim = odp_timer_alloc(tp, queue, ttp);
 + ttp = gbls-tt[thr];
 + ttp-tim = odp_timer_alloc(gbls-tp, queue, ttp);
   if (ttp-tim == ODP_TIMER_INVALID) {
   EXAMPLE_ERR(Failed to allocate timer\n);
   return;
   }
 - tmo = odp_timeout_alloc(pool);
 + tmo = odp_timeout_alloc(gbls-pool);
   if (tmo == ODP_TIMEOUT_INVALID) {
   EXAMPLE_ERR(Failed to allocate timeout\n);
   return;
   }
   ttp-ev = odp_timeout_to_event(tmo);
 - tick = odp_timer_current_tick(tp);
 + tick = odp_timer_current_tick(gbls-tp);
  
 - while ((int)odp_atomic_load_u32(remain)  0) {
 + while ((int)odp_atomic_load_u32(gbls-remain)  0) {
   odp_event_t ev;
   odp_timer_set_t rc;
  
 @@ -140,7 +135,7 @@ static void test_abs_timeouts(int thr, test_args_t *args)
   /* Check if odp_schedule() timed out, possibly there
* are no remaining timeouts to receive */
   } while (ev == ODP_EVENT_INVALID 
 -  (int)odp_atomic_load_u32(remain)  0);
 +  (int)odp_atomic_load_u32(gbls-remain)  0);
  
   if (ev == ODP_EVENT_INVALID)
   break; /* No more timeouts */
 @@ -161,7 +156,7 @@ static void test_abs_timeouts(int thr, test_args_t *args)
   }
   EXAMPLE_DBG(  [%i] timeout, tick %PRIu64\n, thr, tick);
  
 - odp_atomic_dec_u32(remain);
 + odp_atomic_dec_u32(gbls-remain);
   }
  
   /* Cancel and free last timer used */
 @@ -187,9 +182,9 @@ static void *run_thread(void *ptr)
  {
   int thr;
   odp_pool_t msg_pool;
 - test_args_t *args;
 + test_globals_t *gbls;
  
 - args = ptr;
 + gbls = ptr;
   thr  = odp_thread_id();
  
   printf(Thread %i starts on cpu %i\n, thr, odp_cpu_id());
 @@ -204,9 +199,9 @@ static void *run_thread(void *ptr)
   return 

[lng-odp] [PATCH] example: timer: remove global variables to share the data between workers

2015-04-20 Thread Jerin Jacob
Signed-off-by: Jerin Jacob jerin.ja...@caviumnetworks.com
---
 example/timer/odp_timer_test.c | 124 +
 1 file changed, 65 insertions(+), 59 deletions(-)

diff --git a/example/timer/odp_timer_test.c b/example/timer/odp_timer_test.c
index 6b60ec4..876bf33 100644
--- a/example/timer/odp_timer_test.c
+++ b/example/timer/odp_timer_test.c
@@ -39,18 +39,21 @@ typedef struct {
int tmo_count; /** Timeout count*/
 } test_args_t;
 
-
-/** @private Barrier for test synchronisation */
-static odp_barrier_t test_barrier;
-
-/** @private Pool handle */
-static odp_pool_t pool;
-
-/** @private Timer pool handle */
-static odp_timer_pool_t tp;
-
-/** @private Number of timeouts to receive */
-static odp_atomic_u32_t remain;
+/** @private Helper struct for timers */
+struct test_timer {
+   odp_timer_t tim;
+   odp_event_t ev;
+};
+
+/** Test global variables */
+typedef struct {
+   test_args_t args;   /** Test argunments*/
+   odp_barrier_t test_barrier; /** Barrier for test synchronisation*/
+   odp_pool_t pool;/** pool handle*/
+   odp_timer_pool_t tp;/** Timer pool handle*/
+   odp_atomic_u32_t remain;/** Number of timeouts to receive*/
+   struct test_timer tt[256];  /** Array of all timer helper structs*/
+} test_globals_t;
 
 /** @private Timer set status ASCII strings */
 static const char *timerset2str(odp_timer_set_t val)
@@ -69,17 +72,9 @@ static const char *timerset2str(odp_timer_set_t val)
}
 };
 
-/** @private Helper struct for timers */
-struct test_timer {
-   odp_timer_t tim;
-   odp_event_t ev;
-};
-
-/** @private Array of all timer helper structs */
-static struct test_timer tt[256];
 
 /** @private test timeout */
-static void test_abs_timeouts(int thr, test_args_t *args)
+static void test_abs_timeouts(int thr, test_globals_t *gbls)
 {
uint64_t period;
uint64_t period_ns;
@@ -92,30 +87,30 @@ static void test_abs_timeouts(int thr, test_args_t *args)
 
queue = odp_queue_lookup(timer_queue);
 
-   period_ns = args-period_us*ODP_TIME_USEC;
-   period= odp_timer_ns_to_tick(tp, period_ns);
+   period_ns = gbls-args.period_us*ODP_TIME_USEC;
+   period= odp_timer_ns_to_tick(gbls-tp, period_ns);
 
EXAMPLE_DBG(  [%i] period %PRIu64 ticks,  %PRIu64 ns\n, thr,
period, period_ns);
 
EXAMPLE_DBG(  [%i] current tick %PRIu64\n, thr,
-   odp_timer_current_tick(tp));
+   odp_timer_current_tick(gbls-tp));
 
-   ttp = tt[thr - 1]; /* Thread starts at 1 */
-   ttp-tim = odp_timer_alloc(tp, queue, ttp);
+   ttp = gbls-tt[thr];
+   ttp-tim = odp_timer_alloc(gbls-tp, queue, ttp);
if (ttp-tim == ODP_TIMER_INVALID) {
EXAMPLE_ERR(Failed to allocate timer\n);
return;
}
-   tmo = odp_timeout_alloc(pool);
+   tmo = odp_timeout_alloc(gbls-pool);
if (tmo == ODP_TIMEOUT_INVALID) {
EXAMPLE_ERR(Failed to allocate timeout\n);
return;
}
ttp-ev = odp_timeout_to_event(tmo);
-   tick = odp_timer_current_tick(tp);
+   tick = odp_timer_current_tick(gbls-tp);
 
-   while ((int)odp_atomic_load_u32(remain)  0) {
+   while ((int)odp_atomic_load_u32(gbls-remain)  0) {
odp_event_t ev;
odp_timer_set_t rc;
 
@@ -140,7 +135,7 @@ static void test_abs_timeouts(int thr, test_args_t *args)
/* Check if odp_schedule() timed out, possibly there
 * are no remaining timeouts to receive */
} while (ev == ODP_EVENT_INVALID 
-(int)odp_atomic_load_u32(remain)  0);
+(int)odp_atomic_load_u32(gbls-remain)  0);
 
if (ev == ODP_EVENT_INVALID)
break; /* No more timeouts */
@@ -161,7 +156,7 @@ static void test_abs_timeouts(int thr, test_args_t *args)
}
EXAMPLE_DBG(  [%i] timeout, tick %PRIu64\n, thr, tick);
 
-   odp_atomic_dec_u32(remain);
+   odp_atomic_dec_u32(gbls-remain);
}
 
/* Cancel and free last timer used */
@@ -187,9 +182,9 @@ static void *run_thread(void *ptr)
 {
int thr;
odp_pool_t msg_pool;
-   test_args_t *args;
+   test_globals_t *gbls;
 
-   args = ptr;
+   gbls = ptr;
thr  = odp_thread_id();
 
printf(Thread %i starts on cpu %i\n, thr, odp_cpu_id());
@@ -204,9 +199,9 @@ static void *run_thread(void *ptr)
return NULL;
}
 
-   odp_barrier_wait(test_barrier);
+   odp_barrier_wait(gbls-test_barrier);
 
-   test_abs_timeouts(thr, args);
+   test_abs_timeouts(thr, gbls);
 
 
printf(Thread %i exits\n, thr);
@@ -308,7 +303,6 @@ static void parse_args(int argc, char *argv[], test_args_t 
*args)
 int main(int