diff mbox

[PATCHv2] linux-generic: move default cpumask functions to separate file

Message ID 1439297274-4110-1-git-send-email-maxim.uvarov@linaro.org
State Accepted
Commit 6e1e925a5b54750be954a5c01e549b138c583a95
Headers show

Commit Message

Maxim Uvarov Aug. 11, 2015, 12:47 p.m. UTC
Keep functions which iterates with bit mask and more likely will not
be accelerated by hw in odp_cpumask.c. And put functions for default
cpu mask to odp_cpumask_task.c, which is more platform specific. That
patch should simplify portability to other platforms when odp_cpumask.c
will be inherit from linux generic.

Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
---
 v2: - copyright 2015
     - odp_cpumask_def.c -> odp_cpumask_task.c

 platform/linux-generic/Makefile.am        |  1 +
 platform/linux-generic/odp_cpumask.c      | 38 ----------------------
 platform/linux-generic/odp_cpumask_task.c | 52 +++++++++++++++++++++++++++++++
 3 files changed, 53 insertions(+), 38 deletions(-)
 create mode 100644 platform/linux-generic/odp_cpumask_task.c

Comments

Mike Holmes Aug. 11, 2015, 4:16 p.m. UTC | #1
On 11 August 2015 at 08:47, Maxim Uvarov <maxim.uvarov@linaro.org> wrote:
> Keep functions which iterates with bit mask and more likely will not
> be accelerated by hw in odp_cpumask.c. And put functions for default
> cpu mask to odp_cpumask_task.c, which is more platform specific. That
> patch should simplify portability to other platforms when odp_cpumask.c
> will be inherit from linux generic.
>
> Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>

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

> ---
>  v2: - copyright 2015
>      - odp_cpumask_def.c -> odp_cpumask_task.c
>
>  platform/linux-generic/Makefile.am        |  1 +
>  platform/linux-generic/odp_cpumask.c      | 38 ----------------------
>  platform/linux-generic/odp_cpumask_task.c | 52 +++++++++++++++++++++++++++++++
>  3 files changed, 53 insertions(+), 38 deletions(-)
>  create mode 100644 platform/linux-generic/odp_cpumask_task.c
>
> diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am
> index ed4add5..fb145e7 100644
> --- a/platform/linux-generic/Makefile.am
> +++ b/platform/linux-generic/Makefile.am
> @@ -134,6 +134,7 @@ __LIB__libodp_la_SOURCES = \
>                            odp_buffer.c \
>                            odp_classification.c \
>                            odp_cpumask.c \
> +                          odp_cpumask_task.c \
>                            odp_crypto.c \
>                            odp_errno.c \
>                            odp_event.c \
> diff --git a/platform/linux-generic/odp_cpumask.c b/platform/linux-generic/odp_cpumask.c
> index c28153b..b31e1ca 100644
> --- a/platform/linux-generic/odp_cpumask.c
> +++ b/platform/linux-generic/odp_cpumask.c
> @@ -205,41 +205,3 @@ int odp_cpumask_next(const odp_cpumask_t *mask, int cpu)
>                         return cpu;
>         return -1;
>  }
> -
> -int odp_cpumask_def_worker(odp_cpumask_t *mask, int num)
> -{
> -       int ret, cpu, i;
> -       cpu_set_t cpuset;
> -
> -       ret = pthread_getaffinity_np(pthread_self(),
> -                                    sizeof(cpu_set_t), &cpuset);
> -       if (ret != 0)
> -               ODP_ABORT("failed to read CPU affinity value\n");
> -
> -       odp_cpumask_zero(mask);
> -
> -       /*
> -        * If no user supplied number or it's too large, then attempt
> -        * to use all CPUs
> -        */
> -       if (0 == num || CPU_SETSIZE < num)
> -               num = CPU_COUNT(&cpuset);
> -
> -       /* build the mask, allocating down from highest numbered CPU */
> -       for (cpu = 0, i = CPU_SETSIZE - 1; i >= 0 && cpu < num; --i) {
> -               if (CPU_ISSET(i, &cpuset)) {
> -                       odp_cpumask_set(mask, i);
> -                       cpu++;
> -               }
> -       }
> -
> -       return cpu;
> -}
> -
> -int odp_cpumask_def_control(odp_cpumask_t *mask, int num ODP_UNUSED)
> -{
> -       odp_cpumask_zero(mask);
> -       /* By default all control threads on CPU 0 */
> -       odp_cpumask_set(mask, 0);
> -       return 1;
> -}
> diff --git a/platform/linux-generic/odp_cpumask_task.c b/platform/linux-generic/odp_cpumask_task.c
> new file mode 100644
> index 0000000..665e82a
> --- /dev/null
> +++ b/platform/linux-generic/odp_cpumask_task.c
> @@ -0,0 +1,52 @@
> +/* Copyright (c) 2015, Linaro Limited
> + * All rights reserved.
> + *
> + * SPDX-License-Identifier:     BSD-3-Clause
> + */
> +
> +#ifndef _GNU_SOURCE
> +#define _GNU_SOURCE
> +#endif
> +#include <sched.h>
> +#include <pthread.h>
> +
> +#include <odp/cpumask.h>
> +#include <odp_debug_internal.h>
> +
> +int odp_cpumask_def_worker(odp_cpumask_t *mask, int num)
> +{
> +       int ret, cpu, i;
> +       cpu_set_t cpuset;
> +
> +       ret = pthread_getaffinity_np(pthread_self(),
> +                                    sizeof(cpu_set_t), &cpuset);
> +       if (ret != 0)
> +               ODP_ABORT("failed to read CPU affinity value\n");
> +
> +       odp_cpumask_zero(mask);
> +
> +       /*
> +        * If no user supplied number or it's too large, then attempt
> +        * to use all CPUs
> +        */
> +       if (0 == num || CPU_SETSIZE < num)
> +               num = CPU_COUNT(&cpuset);
> +
> +       /* build the mask, allocating down from highest numbered CPU */
> +       for (cpu = 0, i = CPU_SETSIZE - 1; i >= 0 && cpu < num; --i) {
> +               if (CPU_ISSET(i, &cpuset)) {
> +                       odp_cpumask_set(mask, i);
> +                       cpu++;
> +               }
> +       }
> +
> +       return cpu;
> +}
> +
> +int odp_cpumask_def_control(odp_cpumask_t *mask, int num ODP_UNUSED)
> +{
> +       odp_cpumask_zero(mask);
> +       /* By default all control threads on CPU 0 */
> +       odp_cpumask_set(mask, 0);
> +       return 1;
> +}
> --
> 1.9.1
>
> _______________________________________________
> lng-odp mailing list
> lng-odp@lists.linaro.org
> https://lists.linaro.org/mailman/listinfo/lng-odp
Maxim Uvarov Aug. 12, 2015, 9:32 a.m. UTC | #2
Merged,
Maxim.

On 08/11/15 19:16, Mike Holmes wrote:
> On 11 August 2015 at 08:47, Maxim Uvarov <maxim.uvarov@linaro.org> wrote:
>> Keep functions which iterates with bit mask and more likely will not
>> be accelerated by hw in odp_cpumask.c. And put functions for default
>> cpu mask to odp_cpumask_task.c, which is more platform specific. That
>> patch should simplify portability to other platforms when odp_cpumask.c
>> will be inherit from linux generic.
>>
>> Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
> Reviewed-by: Mike Holmes <mike.holmes@linaro.org>
>
>> ---
>>   v2: - copyright 2015
>>       - odp_cpumask_def.c -> odp_cpumask_task.c
>>
>>   platform/linux-generic/Makefile.am        |  1 +
>>   platform/linux-generic/odp_cpumask.c      | 38 ----------------------
>>   platform/linux-generic/odp_cpumask_task.c | 52 +++++++++++++++++++++++++++++++
>>   3 files changed, 53 insertions(+), 38 deletions(-)
>>   create mode 100644 platform/linux-generic/odp_cpumask_task.c
>>
>> diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am
>> index ed4add5..fb145e7 100644
>> --- a/platform/linux-generic/Makefile.am
>> +++ b/platform/linux-generic/Makefile.am
>> @@ -134,6 +134,7 @@ __LIB__libodp_la_SOURCES = \
>>                             odp_buffer.c \
>>                             odp_classification.c \
>>                             odp_cpumask.c \
>> +                          odp_cpumask_task.c \
>>                             odp_crypto.c \
>>                             odp_errno.c \
>>                             odp_event.c \
>> diff --git a/platform/linux-generic/odp_cpumask.c b/platform/linux-generic/odp_cpumask.c
>> index c28153b..b31e1ca 100644
>> --- a/platform/linux-generic/odp_cpumask.c
>> +++ b/platform/linux-generic/odp_cpumask.c
>> @@ -205,41 +205,3 @@ int odp_cpumask_next(const odp_cpumask_t *mask, int cpu)
>>                          return cpu;
>>          return -1;
>>   }
>> -
>> -int odp_cpumask_def_worker(odp_cpumask_t *mask, int num)
>> -{
>> -       int ret, cpu, i;
>> -       cpu_set_t cpuset;
>> -
>> -       ret = pthread_getaffinity_np(pthread_self(),
>> -                                    sizeof(cpu_set_t), &cpuset);
>> -       if (ret != 0)
>> -               ODP_ABORT("failed to read CPU affinity value\n");
>> -
>> -       odp_cpumask_zero(mask);
>> -
>> -       /*
>> -        * If no user supplied number or it's too large, then attempt
>> -        * to use all CPUs
>> -        */
>> -       if (0 == num || CPU_SETSIZE < num)
>> -               num = CPU_COUNT(&cpuset);
>> -
>> -       /* build the mask, allocating down from highest numbered CPU */
>> -       for (cpu = 0, i = CPU_SETSIZE - 1; i >= 0 && cpu < num; --i) {
>> -               if (CPU_ISSET(i, &cpuset)) {
>> -                       odp_cpumask_set(mask, i);
>> -                       cpu++;
>> -               }
>> -       }
>> -
>> -       return cpu;
>> -}
>> -
>> -int odp_cpumask_def_control(odp_cpumask_t *mask, int num ODP_UNUSED)
>> -{
>> -       odp_cpumask_zero(mask);
>> -       /* By default all control threads on CPU 0 */
>> -       odp_cpumask_set(mask, 0);
>> -       return 1;
>> -}
>> diff --git a/platform/linux-generic/odp_cpumask_task.c b/platform/linux-generic/odp_cpumask_task.c
>> new file mode 100644
>> index 0000000..665e82a
>> --- /dev/null
>> +++ b/platform/linux-generic/odp_cpumask_task.c
>> @@ -0,0 +1,52 @@
>> +/* Copyright (c) 2015, Linaro Limited
>> + * All rights reserved.
>> + *
>> + * SPDX-License-Identifier:     BSD-3-Clause
>> + */
>> +
>> +#ifndef _GNU_SOURCE
>> +#define _GNU_SOURCE
>> +#endif
>> +#include <sched.h>
>> +#include <pthread.h>
>> +
>> +#include <odp/cpumask.h>
>> +#include <odp_debug_internal.h>
>> +
>> +int odp_cpumask_def_worker(odp_cpumask_t *mask, int num)
>> +{
>> +       int ret, cpu, i;
>> +       cpu_set_t cpuset;
>> +
>> +       ret = pthread_getaffinity_np(pthread_self(),
>> +                                    sizeof(cpu_set_t), &cpuset);
>> +       if (ret != 0)
>> +               ODP_ABORT("failed to read CPU affinity value\n");
>> +
>> +       odp_cpumask_zero(mask);
>> +
>> +       /*
>> +        * If no user supplied number or it's too large, then attempt
>> +        * to use all CPUs
>> +        */
>> +       if (0 == num || CPU_SETSIZE < num)
>> +               num = CPU_COUNT(&cpuset);
>> +
>> +       /* build the mask, allocating down from highest numbered CPU */
>> +       for (cpu = 0, i = CPU_SETSIZE - 1; i >= 0 && cpu < num; --i) {
>> +               if (CPU_ISSET(i, &cpuset)) {
>> +                       odp_cpumask_set(mask, i);
>> +                       cpu++;
>> +               }
>> +       }
>> +
>> +       return cpu;
>> +}
>> +
>> +int odp_cpumask_def_control(odp_cpumask_t *mask, int num ODP_UNUSED)
>> +{
>> +       odp_cpumask_zero(mask);
>> +       /* By default all control threads on CPU 0 */
>> +       odp_cpumask_set(mask, 0);
>> +       return 1;
>> +}
>> --
>> 1.9.1
>>
>> _______________________________________________
>> lng-odp mailing list
>> lng-odp@lists.linaro.org
>> https://lists.linaro.org/mailman/listinfo/lng-odp
>
>
diff mbox

Patch

diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am
index ed4add5..fb145e7 100644
--- a/platform/linux-generic/Makefile.am
+++ b/platform/linux-generic/Makefile.am
@@ -134,6 +134,7 @@  __LIB__libodp_la_SOURCES = \
 			   odp_buffer.c \
 			   odp_classification.c \
 			   odp_cpumask.c \
+			   odp_cpumask_task.c \
 			   odp_crypto.c \
 			   odp_errno.c \
 			   odp_event.c \
diff --git a/platform/linux-generic/odp_cpumask.c b/platform/linux-generic/odp_cpumask.c
index c28153b..b31e1ca 100644
--- a/platform/linux-generic/odp_cpumask.c
+++ b/platform/linux-generic/odp_cpumask.c
@@ -205,41 +205,3 @@  int odp_cpumask_next(const odp_cpumask_t *mask, int cpu)
 			return cpu;
 	return -1;
 }
-
-int odp_cpumask_def_worker(odp_cpumask_t *mask, int num)
-{
-	int ret, cpu, i;
-	cpu_set_t cpuset;
-
-	ret = pthread_getaffinity_np(pthread_self(),
-				     sizeof(cpu_set_t), &cpuset);
-	if (ret != 0)
-		ODP_ABORT("failed to read CPU affinity value\n");
-
-	odp_cpumask_zero(mask);
-
-	/*
-	 * If no user supplied number or it's too large, then attempt
-	 * to use all CPUs
-	 */
-	if (0 == num || CPU_SETSIZE < num)
-		num = CPU_COUNT(&cpuset);
-
-	/* build the mask, allocating down from highest numbered CPU */
-	for (cpu = 0, i = CPU_SETSIZE - 1; i >= 0 && cpu < num; --i) {
-		if (CPU_ISSET(i, &cpuset)) {
-			odp_cpumask_set(mask, i);
-			cpu++;
-		}
-	}
-
-	return cpu;
-}
-
-int odp_cpumask_def_control(odp_cpumask_t *mask, int num ODP_UNUSED)
-{
-	odp_cpumask_zero(mask);
-	/* By default all control threads on CPU 0 */
-	odp_cpumask_set(mask, 0);
-	return 1;
-}
diff --git a/platform/linux-generic/odp_cpumask_task.c b/platform/linux-generic/odp_cpumask_task.c
new file mode 100644
index 0000000..665e82a
--- /dev/null
+++ b/platform/linux-generic/odp_cpumask_task.c
@@ -0,0 +1,52 @@ 
+/* Copyright (c) 2015, Linaro Limited
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier:     BSD-3-Clause
+ */
+
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+#include <sched.h>
+#include <pthread.h>
+
+#include <odp/cpumask.h>
+#include <odp_debug_internal.h>
+
+int odp_cpumask_def_worker(odp_cpumask_t *mask, int num)
+{
+	int ret, cpu, i;
+	cpu_set_t cpuset;
+
+	ret = pthread_getaffinity_np(pthread_self(),
+				     sizeof(cpu_set_t), &cpuset);
+	if (ret != 0)
+		ODP_ABORT("failed to read CPU affinity value\n");
+
+	odp_cpumask_zero(mask);
+
+	/*
+	 * If no user supplied number or it's too large, then attempt
+	 * to use all CPUs
+	 */
+	if (0 == num || CPU_SETSIZE < num)
+		num = CPU_COUNT(&cpuset);
+
+	/* build the mask, allocating down from highest numbered CPU */
+	for (cpu = 0, i = CPU_SETSIZE - 1; i >= 0 && cpu < num; --i) {
+		if (CPU_ISSET(i, &cpuset)) {
+			odp_cpumask_set(mask, i);
+			cpu++;
+		}
+	}
+
+	return cpu;
+}
+
+int odp_cpumask_def_control(odp_cpumask_t *mask, int num ODP_UNUSED)
+{
+	odp_cpumask_zero(mask);
+	/* By default all control threads on CPU 0 */
+	odp_cpumask_set(mask, 0);
+	return 1;
+}