diff mbox

[PATCHv3] example: hello: set cpu affinity from cgroup

Message ID 1484016722-10558-1-git-send-email-balakrishna.garapati@linaro.org
State New
Headers show

Commit Message

Balakrishna Garapati Jan. 10, 2017, 2:52 a.m. UTC
This will resolve the test in ci when using cgroups.
odp_hello app fails to set cpu affinity to zero all ways
when cgroup doesn't include that cpu in the set.

Fixes: https://bugs.linaro.org/show_bug.cgi?id=2806

Signed-off-by: Balakrishna Garapati <balakrishna.garapati@linaro.org>

---

 since v2: Added link to bug

 example/hello/odp_hello.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

--
1.9.1

Comments

Maxim Uvarov Jan. 10, 2017, 3:02 p.m. UTC | #1
after one more look at this I think we need to remove affinity setting
from hello word app. It's really not needed and not related to odp.

Maxim.

On 01/10/17 05:52, Balakrishna Garapati wrote:
> This will resolve the test in ci when using cgroups.

> odp_hello app fails to set cpu affinity to zero all ways

> when cgroup doesn't include that cpu in the set.

> 

> Fixes: https://bugs.linaro.org/show_bug.cgi?id=2806

> 

> Signed-off-by: Balakrishna Garapati <balakrishna.garapati@linaro.org>

> ---

> 

>  since v2: Added link to bug

> 

>  example/hello/odp_hello.c | 19 ++++++++++++++++---

>  1 file changed, 16 insertions(+), 3 deletions(-)

> 

> diff --git a/example/hello/odp_hello.c b/example/hello/odp_hello.c

> index 6d114ee..59a31b2 100644

> --- a/example/hello/odp_hello.c

> +++ b/example/hello/odp_hello.c

> @@ -60,16 +60,29 @@ int main(int argc, char *argv[])

>  	options_t opt;

>  	pid_t pid;

>  	cpu_set_t cpu_set;

> -	int i;

> +	int i, ret, first_cpu = 0, cpu;

> +

> +	pid = getpid();

> +	ret = sched_getaffinity(pid, sizeof(cpu_set_t), &cpu_set);

> +	if (ret < 0) {

> +		printf("get CPU affinity failed.\n");

> +		return -1;

> +	}

> +

> +	for (cpu = 0; cpu < CPU_SETSIZE; cpu++) {

> +		if (CPU_ISSET(cpu, &cpu_set)) {

> +			first_cpu = cpu;

> +			break;

> +		}

> +	}

> 

>  	memset(&opt, 0, sizeof(opt));

> -	opt.cpu = 0;

> +	opt.cpu = first_cpu;

>  	opt.num = 1;

> 

>  	if (parse_args(argc, argv, &opt))

>  		return -1;

> 

> -	pid = getpid();

>  	CPU_ZERO(&cpu_set);

>  	CPU_SET(opt.cpu, &cpu_set);

> 

> --

> 1.9.1

>
Mike Holmes Jan. 10, 2017, 3:08 p.m. UTC | #2
On 10 January 2017 at 10:02, Maxim Uvarov <maxim.uvarov@linaro.org> wrote:

> after one more look at this I think we need to remove affinity setting

> from hello word app. It's really not needed and not related to odp.

>


As a hello world, is it not useful to describe general usage ?
I don't disagree with you, just asking if it helps to keep it.


>

> Maxim.

>

> On 01/10/17 05:52, Balakrishna Garapati wrote:

> > This will resolve the test in ci when using cgroups.

> > odp_hello app fails to set cpu affinity to zero all ways

> > when cgroup doesn't include that cpu in the set.

> >

> > Fixes: https://bugs.linaro.org/show_bug.cgi?id=2806

> >

> > Signed-off-by: Balakrishna Garapati <balakrishna.garapati@linaro.org>

> > ---

> >

> >  since v2: Added link to bug

> >

> >  example/hello/odp_hello.c | 19 ++++++++++++++++---

> >  1 file changed, 16 insertions(+), 3 deletions(-)

> >

> > diff --git a/example/hello/odp_hello.c b/example/hello/odp_hello.c

> > index 6d114ee..59a31b2 100644

> > --- a/example/hello/odp_hello.c

> > +++ b/example/hello/odp_hello.c

> > @@ -60,16 +60,29 @@ int main(int argc, char *argv[])

> >       options_t opt;

> >       pid_t pid;

> >       cpu_set_t cpu_set;

> > -     int i;

> > +     int i, ret, first_cpu = 0, cpu;

> > +

> > +     pid = getpid();

> > +     ret = sched_getaffinity(pid, sizeof(cpu_set_t), &cpu_set);

> > +     if (ret < 0) {

> > +             printf("get CPU affinity failed.\n");

> > +             return -1;

> > +     }

> > +

> > +     for (cpu = 0; cpu < CPU_SETSIZE; cpu++) {

> > +             if (CPU_ISSET(cpu, &cpu_set)) {

> > +                     first_cpu = cpu;

> > +                     break;

> > +             }

> > +     }

> >

> >       memset(&opt, 0, sizeof(opt));

> > -     opt.cpu = 0;

> > +     opt.cpu = first_cpu;

> >       opt.num = 1;

> >

> >       if (parse_args(argc, argv, &opt))

> >               return -1;

> >

> > -     pid = getpid();

> >       CPU_ZERO(&cpu_set);

> >       CPU_SET(opt.cpu, &cpu_set);

> >

> > --

> > 1.9.1

> >

>

>



-- 
Mike Holmes
Program Manager - Linaro Networking Group
Linaro.org <http://www.linaro.org/> *│ *Open source software for ARM SoCs
"Work should be fun and collaborative, the rest follows"
Maxim Uvarov Jan. 10, 2017, 3:30 p.m. UTC | #3
On 01/10/17 18:08, Mike Holmes wrote:
> 

> 

> On 10 January 2017 at 10:02, Maxim Uvarov <maxim.uvarov@linaro.org

> <mailto:maxim.uvarov@linaro.org>> wrote:

> 

>     after one more look at this I think we need to remove affinity setting

>     from hello word app. It's really not needed and not related to odp.

> 

> 

> As a hello world, is it not useful to describe general usage ?

> I don't disagree with you, just asking if it helps to keep it.

> 


I think Hello world has to be minimal app. ODP can work with not bind to
cpu threads. But it will be good if 'hello' app will not any linux
specifics and can run on all environments like bare metal.

Maxim.




> 

> 

>     Maxim.

> 

>     On 01/10/17 05:52, Balakrishna Garapati wrote:

>     > This will resolve the test in ci when using cgroups.

>     > odp_hello app fails to set cpu affinity to zero all ways

>     > when cgroup doesn't include that cpu in the set.

>     >

>     > Fixes: https://bugs.linaro.org/show_bug.cgi?id=2806

>     <https://bugs.linaro.org/show_bug.cgi?id=2806>

>     >

>     > Signed-off-by: Balakrishna Garapati

>     <balakrishna.garapati@linaro.org

>     <mailto:balakrishna.garapati@linaro.org>>

>     > ---

>     >

>     >  since v2: Added link to bug

>     >

>     >  example/hello/odp_hello.c | 19 ++++++++++++++++---

>     >  1 file changed, 16 insertions(+), 3 deletions(-)

>     >

>     > diff --git a/example/hello/odp_hello.c b/example/hello/odp_hello.c

>     > index 6d114ee..59a31b2 100644

>     > --- a/example/hello/odp_hello.c

>     > +++ b/example/hello/odp_hello.c

>     > @@ -60,16 +60,29 @@ int main(int argc, char *argv[])

>     >       options_t opt;

>     >       pid_t pid;

>     >       cpu_set_t cpu_set;

>     > -     int i;

>     > +     int i, ret, first_cpu = 0, cpu;

>     > +

>     > +     pid = getpid();

>     > +     ret = sched_getaffinity(pid, sizeof(cpu_set_t), &cpu_set);

>     > +     if (ret < 0) {

>     > +             printf("get CPU affinity failed.\n");

>     > +             return -1;

>     > +     }

>     > +

>     > +     for (cpu = 0; cpu < CPU_SETSIZE; cpu++) {

>     > +             if (CPU_ISSET(cpu, &cpu_set)) {

>     > +                     first_cpu = cpu;

>     > +                     break;

>     > +             }

>     > +     }

>     >

>     >       memset(&opt, 0, sizeof(opt));

>     > -     opt.cpu = 0;

>     > +     opt.cpu = first_cpu;

>     >       opt.num = 1;

>     >

>     >       if (parse_args(argc, argv, &opt))

>     >               return -1;

>     >

>     > -     pid = getpid();

>     >       CPU_ZERO(&cpu_set);

>     >       CPU_SET(opt.cpu, &cpu_set);

>     >

>     > --

>     > 1.9.1

>     >

> 

> 

> 

> 

> -- 

> Mike Holmes

> Program Manager - Linaro Networking Group

> Linaro.org <http://www.linaro.org/>* **│ *Open source software for ARM SoCs

> "Work should be fun and collaborative, the rest follows"

> 

> __

> 

>
Mike Holmes Jan. 10, 2017, 3:46 p.m. UTC | #4
On 10 January 2017 at 10:30, Maxim Uvarov <maxim.uvarov@linaro.org> wrote:

> On 01/10/17 18:08, Mike Holmes wrote:

> >

> >

> > On 10 January 2017 at 10:02, Maxim Uvarov <maxim.uvarov@linaro.org

> > <mailto:maxim.uvarov@linaro.org>> wrote:

> >

> >     after one more look at this I think we need to remove affinity

> setting

> >     from hello word app. It's really not needed and not related to odp.

> >

> >

> > As a hello world, is it not useful to describe general usage ?

> > I don't disagree with you, just asking if it helps to keep it.

> >

>

> I think Hello world has to be minimal app. ODP can work with not bind to

> cpu threads. But it will be good if 'hello' app will not any linux

> specifics and can run on all environments like bare metal.

>


Makes sence


>

> Maxim.

>

>

>

>

> >

> >

> >     Maxim.

> >

> >     On 01/10/17 05:52, Balakrishna Garapati wrote:

> >     > This will resolve the test in ci when using cgroups.

> >     > odp_hello app fails to set cpu affinity to zero all ways

> >     > when cgroup doesn't include that cpu in the set.

> >     >

> >     > Fixes: https://bugs.linaro.org/show_bug.cgi?id=2806

> >     <https://bugs.linaro.org/show_bug.cgi?id=2806>

> >     >

> >     > Signed-off-by: Balakrishna Garapati

> >     <balakrishna.garapati@linaro.org

> >     <mailto:balakrishna.garapati@linaro.org>>

> >     > ---

> >     >

> >     >  since v2: Added link to bug

> >     >

> >     >  example/hello/odp_hello.c | 19 ++++++++++++++++---

> >     >  1 file changed, 16 insertions(+), 3 deletions(-)

> >     >

> >     > diff --git a/example/hello/odp_hello.c b/example/hello/odp_hello.c

> >     > index 6d114ee..59a31b2 100644

> >     > --- a/example/hello/odp_hello.c

> >     > +++ b/example/hello/odp_hello.c

> >     > @@ -60,16 +60,29 @@ int main(int argc, char *argv[])

> >     >       options_t opt;

> >     >       pid_t pid;

> >     >       cpu_set_t cpu_set;

> >     > -     int i;

> >     > +     int i, ret, first_cpu = 0, cpu;

> >     > +

> >     > +     pid = getpid();

> >     > +     ret = sched_getaffinity(pid, sizeof(cpu_set_t), &cpu_set);

> >     > +     if (ret < 0) {

> >     > +             printf("get CPU affinity failed.\n");

> >     > +             return -1;

> >     > +     }

> >     > +

> >     > +     for (cpu = 0; cpu < CPU_SETSIZE; cpu++) {

> >     > +             if (CPU_ISSET(cpu, &cpu_set)) {

> >     > +                     first_cpu = cpu;

> >     > +                     break;

> >     > +             }

> >     > +     }

> >     >

> >     >       memset(&opt, 0, sizeof(opt));

> >     > -     opt.cpu = 0;

> >     > +     opt.cpu = first_cpu;

> >     >       opt.num = 1;

> >     >

> >     >       if (parse_args(argc, argv, &opt))

> >     >               return -1;

> >     >

> >     > -     pid = getpid();

> >     >       CPU_ZERO(&cpu_set);

> >     >       CPU_SET(opt.cpu, &cpu_set);

> >     >

> >     > --

> >     > 1.9.1

> >     >

> >

> >

> >

> >

> > --

> > Mike Holmes

> > Program Manager - Linaro Networking Group

> > Linaro.org <http://www.linaro.org/>* **│ *Open source software for ARM

> SoCs

> > "Work should be fun and collaborative, the rest follows"

> >

> > __

> >

> >

>

>



-- 
Mike Holmes
Program Manager - Linaro Networking Group
Linaro.org <http://www.linaro.org/> *│ *Open source software for ARM SoCs
"Work should be fun and collaborative, the rest follows"
Balakrishna Garapati Jan. 11, 2017, 3:32 a.m. UTC | #5
On 10 January 2017 at 16:46, Mike Holmes <mike.holmes@linaro.org> wrote:

> On 10 January 2017 at 10:30, Maxim Uvarov <maxim.uvarov@linaro.org> wrote:

>

> > On 01/10/17 18:08, Mike Holmes wrote:

> > >

> > >

> > > On 10 January 2017 at 10:02, Maxim Uvarov <maxim.uvarov@linaro.org

> > > <mailto:maxim.uvarov@linaro.org>> wrote:

> > >

> > >     after one more look at this I think we need to remove affinity

> > setting

> > >     from hello word app. It's really not needed and not related to odp.

> > >

> > >

> > > As a hello world, is it not useful to describe general usage ?

> > > I don't disagree with you, just asking if it helps to keep it.

> > >

> >

> > I think Hello world has to be minimal app. ODP can work with not bind to

> > cpu threads. But it will be good if 'hello' app will not any linux

> > specifics and can run on all environments like bare metal.

> >

>

> Makes sence

>

So shall I scrap this patch and send a new patch with different subject
name ?
/Krishna

>

>

> >

> > Maxim.

> >

> >

> >

> >

> > >

> > >

> > >     Maxim.

> > >

> > >     On 01/10/17 05:52, Balakrishna Garapati wrote:

> > >     > This will resolve the test in ci when using cgroups.

> > >     > odp_hello app fails to set cpu affinity to zero all ways

> > >     > when cgroup doesn't include that cpu in the set.

> > >     >

> > >     > Fixes: https://bugs.linaro.org/show_bug.cgi?id=2806

> > >     <https://bugs.linaro.org/show_bug.cgi?id=2806>

> > >     >

> > >     > Signed-off-by: Balakrishna Garapati

> > >     <balakrishna.garapati@linaro.org

> > >     <mailto:balakrishna.garapati@linaro.org>>

> > >     > ---

> > >     >

> > >     >  since v2: Added link to bug

> > >     >

> > >     >  example/hello/odp_hello.c | 19 ++++++++++++++++---

> > >     >  1 file changed, 16 insertions(+), 3 deletions(-)

> > >     >

> > >     > diff --git a/example/hello/odp_hello.c

> b/example/hello/odp_hello.c

> > >     > index 6d114ee..59a31b2 100644

> > >     > --- a/example/hello/odp_hello.c

> > >     > +++ b/example/hello/odp_hello.c

> > >     > @@ -60,16 +60,29 @@ int main(int argc, char *argv[])

> > >     >       options_t opt;

> > >     >       pid_t pid;

> > >     >       cpu_set_t cpu_set;

> > >     > -     int i;

> > >     > +     int i, ret, first_cpu = 0, cpu;

> > >     > +

> > >     > +     pid = getpid();

> > >     > +     ret = sched_getaffinity(pid, sizeof(cpu_set_t), &cpu_set);

> > >     > +     if (ret < 0) {

> > >     > +             printf("get CPU affinity failed.\n");

> > >     > +             return -1;

> > >     > +     }

> > >     > +

> > >     > +     for (cpu = 0; cpu < CPU_SETSIZE; cpu++) {

> > >     > +             if (CPU_ISSET(cpu, &cpu_set)) {

> > >     > +                     first_cpu = cpu;

> > >     > +                     break;

> > >     > +             }

> > >     > +     }

> > >     >

> > >     >       memset(&opt, 0, sizeof(opt));

> > >     > -     opt.cpu = 0;

> > >     > +     opt.cpu = first_cpu;

> > >     >       opt.num = 1;

> > >     >

> > >     >       if (parse_args(argc, argv, &opt))

> > >     >               return -1;

> > >     >

> > >     > -     pid = getpid();

> > >     >       CPU_ZERO(&cpu_set);

> > >     >       CPU_SET(opt.cpu, &cpu_set);

> > >     >

> > >     > --

> > >     > 1.9.1

> > >     >

> > >

> > >

> > >

> > >

> > > --

> > > Mike Holmes

> > > Program Manager - Linaro Networking Group

> > > Linaro.org <http://www.linaro.org/>* **│ *Open source software for ARM

> > SoCs

> > > "Work should be fun and collaborative, the rest follows"

> > >

> > > __

> > >

> > >

> >

> >

>

>

> --

> Mike Holmes

> Program Manager - Linaro Networking Group

> Linaro.org <http://www.linaro.org/> *│ *Open source software for ARM SoCs

> "Work should be fun and collaborative, the rest follows"

>
Maxim Uvarov Jan. 11, 2017, 6:54 a.m. UTC | #6
On 11 January 2017 at 06:32, Krishna Garapati <
balakrishna.garapati@linaro.org> wrote:

>

>

> On 10 January 2017 at 16:46, Mike Holmes <mike.holmes@linaro.org> wrote:

>

>> On 10 January 2017 at 10:30, Maxim Uvarov <maxim.uvarov@linaro.org>

>> wrote:

>>

>> > On 01/10/17 18:08, Mike Holmes wrote:

>> > >

>> > >

>> > > On 10 January 2017 at 10:02, Maxim Uvarov <maxim.uvarov@linaro.org

>> > > <mailto:maxim.uvarov@linaro.org>> wrote:

>> > >

>> > >     after one more look at this I think we need to remove affinity

>> > setting

>> > >     from hello word app. It's really not needed and not related to

>> odp.

>> > >

>> > >

>> > > As a hello world, is it not useful to describe general usage ?

>> > > I don't disagree with you, just asking if it helps to keep it.

>> > >

>> >

>> > I think Hello world has to be minimal app. ODP can work with not bind to

>> > cpu threads. But it will be good if 'hello' app will not any linux

>> > specifics and can run on all environments like bare metal.

>> >

>>

>> Makes sence

>>

> So shall I scrap this patch and send a new patch with different subject

> name ?

> /Krishna

>



Yes, please.

Maxim.



>

>>

>> >

>> > Maxim.

>> >

>> >

>> >

>> >

>> > >

>> > >

>> > >     Maxim.

>> > >

>> > >     On 01/10/17 05:52, Balakrishna Garapati wrote:

>> > >     > This will resolve the test in ci when using cgroups.

>> > >     > odp_hello app fails to set cpu affinity to zero all ways

>> > >     > when cgroup doesn't include that cpu in the set.

>> > >     >

>> > >     > Fixes: https://bugs.linaro.org/show_bug.cgi?id=2806

>> > >     <https://bugs.linaro.org/show_bug.cgi?id=2806>

>> > >     >

>> > >     > Signed-off-by: Balakrishna Garapati

>> > >     <balakrishna.garapati@linaro.org

>> > >     <mailto:balakrishna.garapati@linaro.org>>

>> > >     > ---

>> > >     >

>> > >     >  since v2: Added link to bug

>> > >     >

>> > >     >  example/hello/odp_hello.c | 19 ++++++++++++++++---

>> > >     >  1 file changed, 16 insertions(+), 3 deletions(-)

>> > >     >

>> > >     > diff --git a/example/hello/odp_hello.c

>> b/example/hello/odp_hello.c

>> > >     > index 6d114ee..59a31b2 100644

>> > >     > --- a/example/hello/odp_hello.c

>> > >     > +++ b/example/hello/odp_hello.c

>> > >     > @@ -60,16 +60,29 @@ int main(int argc, char *argv[])

>> > >     >       options_t opt;

>> > >     >       pid_t pid;

>> > >     >       cpu_set_t cpu_set;

>> > >     > -     int i;

>> > >     > +     int i, ret, first_cpu = 0, cpu;

>> > >     > +

>> > >     > +     pid = getpid();

>> > >     > +     ret = sched_getaffinity(pid, sizeof(cpu_set_t), &cpu_set);

>> > >     > +     if (ret < 0) {

>> > >     > +             printf("get CPU affinity failed.\n");

>> > >     > +             return -1;

>> > >     > +     }

>> > >     > +

>> > >     > +     for (cpu = 0; cpu < CPU_SETSIZE; cpu++) {

>> > >     > +             if (CPU_ISSET(cpu, &cpu_set)) {

>> > >     > +                     first_cpu = cpu;

>> > >     > +                     break;

>> > >     > +             }

>> > >     > +     }

>> > >     >

>> > >     >       memset(&opt, 0, sizeof(opt));

>> > >     > -     opt.cpu = 0;

>> > >     > +     opt.cpu = first_cpu;

>> > >     >       opt.num = 1;

>> > >     >

>> > >     >       if (parse_args(argc, argv, &opt))

>> > >     >               return -1;

>> > >     >

>> > >     > -     pid = getpid();

>> > >     >       CPU_ZERO(&cpu_set);

>> > >     >       CPU_SET(opt.cpu, &cpu_set);

>> > >     >

>> > >     > --

>> > >     > 1.9.1

>> > >     >

>> > >

>> > >

>> > >

>> > >

>> > > --

>> > > Mike Holmes

>> > > Program Manager - Linaro Networking Group

>> > > Linaro.org <http://www.linaro.org/>* **│ *Open source software for

>> ARM

>> > SoCs

>> > > "Work should be fun and collaborative, the rest follows"

>> > >

>> > > __

>> > >

>> > >

>> >

>> >

>>

>>

>> --

>> Mike Holmes

>> Program Manager - Linaro Networking Group

>> Linaro.org <http://www.linaro.org/> *│ *Open source software for ARM SoCs

>> "Work should be fun and collaborative, the rest follows"

>>

>

>
Maxim Uvarov Jan. 13, 2017, 9:01 a.m. UTC | #7
Hello Krishna,

can you please send patch removing setting affinity? I want to merge it to
release.

Maxim.

On 11 January 2017 at 09:54, Maxim Uvarov <maxim.uvarov@linaro.org> wrote:

>

>

> On 11 January 2017 at 06:32, Krishna Garapati <

> balakrishna.garapati@linaro.org> wrote:

>

>>

>>

>> On 10 January 2017 at 16:46, Mike Holmes <mike.holmes@linaro.org> wrote:

>>

>>> On 10 January 2017 at 10:30, Maxim Uvarov <maxim.uvarov@linaro.org>

>>> wrote:

>>>

>>> > On 01/10/17 18:08, Mike Holmes wrote:

>>> > >

>>> > >

>>> > > On 10 January 2017 at 10:02, Maxim Uvarov <maxim.uvarov@linaro.org

>>> > > <mailto:maxim.uvarov@linaro.org>> wrote:

>>> > >

>>> > >     after one more look at this I think we need to remove affinity

>>> > setting

>>> > >     from hello word app. It's really not needed and not related to

>>> odp.

>>> > >

>>> > >

>>> > > As a hello world, is it not useful to describe general usage ?

>>> > > I don't disagree with you, just asking if it helps to keep it.

>>> > >

>>> >

>>> > I think Hello world has to be minimal app. ODP can work with not bind

>>> to

>>> > cpu threads. But it will be good if 'hello' app will not any linux

>>> > specifics and can run on all environments like bare metal.

>>> >

>>>

>>> Makes sence

>>>

>> So shall I scrap this patch and send a new patch with different subject

>> name ?

>> /Krishna

>>

>

>

> Yes, please.

>

> Maxim.

>

>

>

>>

>>>

>>> >

>>> > Maxim.

>>> >

>>> >

>>> >

>>> >

>>> > >

>>> > >

>>> > >     Maxim.

>>> > >

>>> > >     On 01/10/17 05:52, Balakrishna Garapati wrote:

>>> > >     > This will resolve the test in ci when using cgroups.

>>> > >     > odp_hello app fails to set cpu affinity to zero all ways

>>> > >     > when cgroup doesn't include that cpu in the set.

>>> > >     >

>>> > >     > Fixes: https://bugs.linaro.org/show_bug.cgi?id=2806

>>> > >     <https://bugs.linaro.org/show_bug.cgi?id=2806>

>>> > >     >

>>> > >     > Signed-off-by: Balakrishna Garapati

>>> > >     <balakrishna.garapati@linaro.org

>>> > >     <mailto:balakrishna.garapati@linaro.org>>

>>> > >     > ---

>>> > >     >

>>> > >     >  since v2: Added link to bug

>>> > >     >

>>> > >     >  example/hello/odp_hello.c | 19 ++++++++++++++++---

>>> > >     >  1 file changed, 16 insertions(+), 3 deletions(-)

>>> > >     >

>>> > >     > diff --git a/example/hello/odp_hello.c

>>> b/example/hello/odp_hello.c

>>> > >     > index 6d114ee..59a31b2 100644

>>> > >     > --- a/example/hello/odp_hello.c

>>> > >     > +++ b/example/hello/odp_hello.c

>>> > >     > @@ -60,16 +60,29 @@ int main(int argc, char *argv[])

>>> > >     >       options_t opt;

>>> > >     >       pid_t pid;

>>> > >     >       cpu_set_t cpu_set;

>>> > >     > -     int i;

>>> > >     > +     int i, ret, first_cpu = 0, cpu;

>>> > >     > +

>>> > >     > +     pid = getpid();

>>> > >     > +     ret = sched_getaffinity(pid, sizeof(cpu_set_t),

>>> &cpu_set);

>>> > >     > +     if (ret < 0) {

>>> > >     > +             printf("get CPU affinity failed.\n");

>>> > >     > +             return -1;

>>> > >     > +     }

>>> > >     > +

>>> > >     > +     for (cpu = 0; cpu < CPU_SETSIZE; cpu++) {

>>> > >     > +             if (CPU_ISSET(cpu, &cpu_set)) {

>>> > >     > +                     first_cpu = cpu;

>>> > >     > +                     break;

>>> > >     > +             }

>>> > >     > +     }

>>> > >     >

>>> > >     >       memset(&opt, 0, sizeof(opt));

>>> > >     > -     opt.cpu = 0;

>>> > >     > +     opt.cpu = first_cpu;

>>> > >     >       opt.num = 1;

>>> > >     >

>>> > >     >       if (parse_args(argc, argv, &opt))

>>> > >     >               return -1;

>>> > >     >

>>> > >     > -     pid = getpid();

>>> > >     >       CPU_ZERO(&cpu_set);

>>> > >     >       CPU_SET(opt.cpu, &cpu_set);

>>> > >     >

>>> > >     > --

>>> > >     > 1.9.1

>>> > >     >

>>> > >

>>> > >

>>> > >

>>> > >

>>> > > --

>>> > > Mike Holmes

>>> > > Program Manager - Linaro Networking Group

>>> > > Linaro.org <http://www.linaro.org/>* **│ *Open source software for

>>> ARM

>>> > SoCs

>>> > > "Work should be fun and collaborative, the rest follows"

>>> > >

>>> > > __

>>> > >

>>> > >

>>> >

>>> >

>>>

>>>

>>> --

>>> Mike Holmes

>>> Program Manager - Linaro Networking Group

>>> Linaro.org <http://www.linaro.org/> *│ *Open source software for ARM

>>> SoCs

>>> "Work should be fun and collaborative, the rest follows"

>>>

>>

>>

>
diff mbox

Patch

diff --git a/example/hello/odp_hello.c b/example/hello/odp_hello.c
index 6d114ee..59a31b2 100644
--- a/example/hello/odp_hello.c
+++ b/example/hello/odp_hello.c
@@ -60,16 +60,29 @@  int main(int argc, char *argv[])
 	options_t opt;
 	pid_t pid;
 	cpu_set_t cpu_set;
-	int i;
+	int i, ret, first_cpu = 0, cpu;
+
+	pid = getpid();
+	ret = sched_getaffinity(pid, sizeof(cpu_set_t), &cpu_set);
+	if (ret < 0) {
+		printf("get CPU affinity failed.\n");
+		return -1;
+	}
+
+	for (cpu = 0; cpu < CPU_SETSIZE; cpu++) {
+		if (CPU_ISSET(cpu, &cpu_set)) {
+			first_cpu = cpu;
+			break;
+		}
+	}

 	memset(&opt, 0, sizeof(opt));
-	opt.cpu = 0;
+	opt.cpu = first_cpu;
 	opt.num = 1;

 	if (parse_args(argc, argv, &opt))
 		return -1;

-	pid = getpid();
 	CPU_ZERO(&cpu_set);
 	CPU_SET(opt.cpu, &cpu_set);