diff mbox

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

Message ID 1483968904-21625-1-git-send-email-balakrishna.garapati@linaro.org
State Superseded
Headers show

Commit Message

Balakrishna Garapati Jan. 9, 2017, 1:35 p.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.

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

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

-- 
1.9.1

Comments

Bill Fischofer Jan. 10, 2017, 1:30 a.m. UTC | #1
On Mon, Jan 9, 2017 at 7:35 AM, Balakrishna Garapati
<balakrishna.garapati@linaro.org> 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.

>

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


Reviewed-by: Bill Fischofer <bill.fischofer@linaro.org>


> ---

>  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

>
Bill Fischofer Jan. 10, 2017, 1:31 a.m. UTC | #2
On Mon, Jan 9, 2017 at 7:30 PM, Bill Fischofer
<bill.fischofer@linaro.org> wrote:
> On Mon, Jan 9, 2017 at 7:35 AM, Balakrishna Garapati

> <balakrishna.garapati@linaro.org> 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.

>>

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

>

> Reviewed-by: Bill Fischofer <bill.fischofer@linaro.org>


Forgot to mention that since this is fixing a bug a Bug entry should
be opened for this and the commit log should reference that so we can
track its resolution.

>

>> ---

>>  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

>>
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);