diff mbox

example: l2fwd: use parameterized array to avoid memory corruption

Message ID 1464319331-31936-1-git-send-email-bill.fischofer@linaro.org
State Accepted
Commit 2a367a02665ab9893bbc66e6d8da9dbb6064c5de
Headers show

Commit Message

Bill Fischofer May 27, 2016, 3:22 a.m. UTC
The switch to agnostic threads requires that arrays be passed to
odph_odpthreads_create() and odph_pthreads_join(). Even though l2fwd uses
only a single worker, this must be declared as an array of size 1 for
consistency. This resolves Bug https://bugs.linaro.org/show_bug.cgi?id=2272

Signed-off-by: Bill Fischofer <bill.fischofer@linaro.org>
---
 example/l2fwd_simple/odp_l2fwd_simple.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

Comments

Bill Fischofer June 1, 2016, 8:43 p.m. UTC | #1
Ping. Needs review to resolve Bug 2272.

On Thu, May 26, 2016 at 10:22 PM, Bill Fischofer <bill.fischofer@linaro.org>
wrote:

> The switch to agnostic threads requires that arrays be passed to
> odph_odpthreads_create() and odph_pthreads_join(). Even though l2fwd uses
> only a single worker, this must be declared as an array of size 1 for
> consistency. This resolves Bug
> https://bugs.linaro.org/show_bug.cgi?id=2272
>
> Signed-off-by: Bill Fischofer <bill.fischofer@linaro.org>
> ---
>  example/l2fwd_simple/odp_l2fwd_simple.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/example/l2fwd_simple/odp_l2fwd_simple.c
> b/example/l2fwd_simple/odp_l2fwd_simple.c
> index daae038..8a14e7d 100644
> --- a/example/l2fwd_simple/odp_l2fwd_simple.c
> +++ b/example/l2fwd_simple/odp_l2fwd_simple.c
> @@ -16,6 +16,7 @@
>  #define POOL_NUM_PKT 8192
>  #define POOL_SEG_LEN 1856
>  #define MAX_PKT_BURST 32
> +#define MAX_WORKERS 1
>
>  struct {
>         odp_pktio_t if0, if1;
> @@ -119,7 +120,7 @@ int main(int argc, char **argv)
>         odp_pool_t pool;
>         odp_pool_param_t params;
>         odp_cpumask_t cpumask;
> -       odph_odpthread_t thd;
> +       odph_odpthread_t thd[MAX_WORKERS];
>         odp_instance_t instance;
>         odph_odpthread_params_t thr_params;
>         int opt;
> @@ -183,7 +184,7 @@ int main(int argc, char **argv)
>         global.if1 = create_pktio(argv[optind + 1], pool, &global.if1in,
>
> &global.if1out);
>
> -       odp_cpumask_default_worker(&cpumask, 1);
> +       odp_cpumask_default_worker(&cpumask, MAX_WORKERS);
>
>         memset(&thr_params, 0, sizeof(thr_params));
>         thr_params.start    = run_worker;
> @@ -191,8 +192,8 @@ int main(int argc, char **argv)
>         thr_params.thr_type = ODP_THREAD_WORKER;
>         thr_params.instance = instance;
>
> -       odph_odpthreads_create(&thd, &cpumask, &thr_params);
> -       odph_odpthreads_join(&thd);
> +       odph_odpthreads_create(thd, &cpumask, &thr_params);
> +       odph_odpthreads_join(thd);
>
>         return 0;
>  }
> --
> 2.7.4
>
>
Mike Holmes June 1, 2016, 9:28 p.m. UTC | #2
On 26 May 2016 at 23:22, Bill Fischofer <bill.fischofer@linaro.org> wrote:
> The switch to agnostic threads requires that arrays be passed to
> odph_odpthreads_create() and odph_pthreads_join(). Even though l2fwd uses
> only a single worker, this must be declared as an array of size 1 for
> consistency. This resolves Bug https://bugs.linaro.org/show_bug.cgi?id=2272
>
> Signed-off-by: Bill Fischofer <bill.fischofer@linaro.org>

Reviewed-and-tested-by: Mike Holmes <mike.holmes@linaro.org>

> ---
>  example/l2fwd_simple/odp_l2fwd_simple.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/example/l2fwd_simple/odp_l2fwd_simple.c b/example/l2fwd_simple/odp_l2fwd_simple.c
> index daae038..8a14e7d 100644
> --- a/example/l2fwd_simple/odp_l2fwd_simple.c
> +++ b/example/l2fwd_simple/odp_l2fwd_simple.c
> @@ -16,6 +16,7 @@
>  #define POOL_NUM_PKT 8192
>  #define POOL_SEG_LEN 1856
>  #define MAX_PKT_BURST 32
> +#define MAX_WORKERS 1
>
>  struct {
>         odp_pktio_t if0, if1;
> @@ -119,7 +120,7 @@ int main(int argc, char **argv)
>         odp_pool_t pool;
>         odp_pool_param_t params;
>         odp_cpumask_t cpumask;
> -       odph_odpthread_t thd;
> +       odph_odpthread_t thd[MAX_WORKERS];
>         odp_instance_t instance;
>         odph_odpthread_params_t thr_params;
>         int opt;
> @@ -183,7 +184,7 @@ int main(int argc, char **argv)
>         global.if1 = create_pktio(argv[optind + 1], pool, &global.if1in,
>                                                                 &global.if1out);
>
> -       odp_cpumask_default_worker(&cpumask, 1);
> +       odp_cpumask_default_worker(&cpumask, MAX_WORKERS);
>
>         memset(&thr_params, 0, sizeof(thr_params));
>         thr_params.start    = run_worker;
> @@ -191,8 +192,8 @@ int main(int argc, char **argv)
>         thr_params.thr_type = ODP_THREAD_WORKER;
>         thr_params.instance = instance;
>
> -       odph_odpthreads_create(&thd, &cpumask, &thr_params);
> -       odph_odpthreads_join(&thd);
> +       odph_odpthreads_create(thd, &cpumask, &thr_params);
> +       odph_odpthreads_join(thd);
>
>         return 0;
>  }
> --
> 2.7.4
>
> _______________________________________________
> lng-odp mailing list
> lng-odp@lists.linaro.org
> https://lists.linaro.org/mailman/listinfo/lng-odp
Maxim Uvarov June 2, 2016, 12:51 p.m. UTC | #3
Merged,
Maxim.

On 06/02/16 00:28, Mike Holmes wrote:
> On 26 May 2016 at 23:22, Bill Fischofer <bill.fischofer@linaro.org> wrote:
>> The switch to agnostic threads requires that arrays be passed to
>> odph_odpthreads_create() and odph_pthreads_join(). Even though l2fwd uses
>> only a single worker, this must be declared as an array of size 1 for
>> consistency. This resolves Bug https://bugs.linaro.org/show_bug.cgi?id=2272
>>
>> Signed-off-by: Bill Fischofer <bill.fischofer@linaro.org>
> Reviewed-and-tested-by: Mike Holmes <mike.holmes@linaro.org>
>
>> ---
>>   example/l2fwd_simple/odp_l2fwd_simple.c | 9 +++++----
>>   1 file changed, 5 insertions(+), 4 deletions(-)
>>
>> diff --git a/example/l2fwd_simple/odp_l2fwd_simple.c b/example/l2fwd_simple/odp_l2fwd_simple.c
>> index daae038..8a14e7d 100644
>> --- a/example/l2fwd_simple/odp_l2fwd_simple.c
>> +++ b/example/l2fwd_simple/odp_l2fwd_simple.c
>> @@ -16,6 +16,7 @@
>>   #define POOL_NUM_PKT 8192
>>   #define POOL_SEG_LEN 1856
>>   #define MAX_PKT_BURST 32
>> +#define MAX_WORKERS 1
>>
>>   struct {
>>          odp_pktio_t if0, if1;
>> @@ -119,7 +120,7 @@ int main(int argc, char **argv)
>>          odp_pool_t pool;
>>          odp_pool_param_t params;
>>          odp_cpumask_t cpumask;
>> -       odph_odpthread_t thd;
>> +       odph_odpthread_t thd[MAX_WORKERS];
>>          odp_instance_t instance;
>>          odph_odpthread_params_t thr_params;
>>          int opt;
>> @@ -183,7 +184,7 @@ int main(int argc, char **argv)
>>          global.if1 = create_pktio(argv[optind + 1], pool, &global.if1in,
>>                                                                  &global.if1out);
>>
>> -       odp_cpumask_default_worker(&cpumask, 1);
>> +       odp_cpumask_default_worker(&cpumask, MAX_WORKERS);
>>
>>          memset(&thr_params, 0, sizeof(thr_params));
>>          thr_params.start    = run_worker;
>> @@ -191,8 +192,8 @@ int main(int argc, char **argv)
>>          thr_params.thr_type = ODP_THREAD_WORKER;
>>          thr_params.instance = instance;
>>
>> -       odph_odpthreads_create(&thd, &cpumask, &thr_params);
>> -       odph_odpthreads_join(&thd);
>> +       odph_odpthreads_create(thd, &cpumask, &thr_params);
>> +       odph_odpthreads_join(thd);
>>
>>          return 0;
>>   }
>> --
>> 2.7.4
>>
>> _______________________________________________
>> lng-odp mailing list
>> lng-odp@lists.linaro.org
>> https://lists.linaro.org/mailman/listinfo/lng-odp
>
>
diff mbox

Patch

diff --git a/example/l2fwd_simple/odp_l2fwd_simple.c b/example/l2fwd_simple/odp_l2fwd_simple.c
index daae038..8a14e7d 100644
--- a/example/l2fwd_simple/odp_l2fwd_simple.c
+++ b/example/l2fwd_simple/odp_l2fwd_simple.c
@@ -16,6 +16,7 @@ 
 #define POOL_NUM_PKT 8192
 #define POOL_SEG_LEN 1856
 #define MAX_PKT_BURST 32
+#define MAX_WORKERS 1
 
 struct {
 	odp_pktio_t if0, if1;
@@ -119,7 +120,7 @@  int main(int argc, char **argv)
 	odp_pool_t pool;
 	odp_pool_param_t params;
 	odp_cpumask_t cpumask;
-	odph_odpthread_t thd;
+	odph_odpthread_t thd[MAX_WORKERS];
 	odp_instance_t instance;
 	odph_odpthread_params_t thr_params;
 	int opt;
@@ -183,7 +184,7 @@  int main(int argc, char **argv)
 	global.if1 = create_pktio(argv[optind + 1], pool, &global.if1in,
 								&global.if1out);
 
-	odp_cpumask_default_worker(&cpumask, 1);
+	odp_cpumask_default_worker(&cpumask, MAX_WORKERS);
 
 	memset(&thr_params, 0, sizeof(thr_params));
 	thr_params.start    = run_worker;
@@ -191,8 +192,8 @@  int main(int argc, char **argv)
 	thr_params.thr_type = ODP_THREAD_WORKER;
 	thr_params.instance = instance;
 
-	odph_odpthreads_create(&thd, &cpumask, &thr_params);
-	odph_odpthreads_join(&thd);
+	odph_odpthreads_create(thd, &cpumask, &thr_params);
+	odph_odpthreads_join(thd);
 
 	return 0;
 }