diff options
author | Petri Savolainen <petri.savolainen@nokia.com> | 2016-07-04 18:42:23 +0300 |
---|---|---|
committer | Maxim Uvarov <maxim.uvarov@linaro.org> | 2016-07-05 15:09:13 +0300 |
commit | 9f0f2b86309aa8021ec937e7c0ee1d6f48b0d769 (patch) | |
tree | 228d471e3fbacc60c3f7396ef879cb9781447a70 | |
parent | c03685af2895b20a5e8a046ea910254a96ab15c4 (diff) |
linux-gen: cpumask: remove dependency to sched.h
Platform specific API files included sched.h for accessing
cpu_set_t. This is problematic since application may need to
include it also and possibly with GNU extension (with #define
_GNU_SOURCE). Application should be able to include odp_api.h
in any order relative to other headers, and with or without
any (e.g. GNU) extensions.
The odp_cpumask_t is defined with equal (or larger) size to
Linux cpu_set_t and this is verified with build time asserts.
Linux CPU_SET macros are used to access the mask as before.
Signed-off-by: Petri Savolainen <petri.savolainen@nokia.com>
Reviewed-and-tested-by: Bill Fischofer <bill.fischofer@linaro.org>
Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
-rw-r--r-- | platform/linux-generic/include/odp/api/cpumask.h | 4 | ||||
-rw-r--r-- | platform/linux-generic/include/odp/api/plat/cpumask_types.h | 10 | ||||
-rw-r--r-- | platform/linux-generic/include/odp/api/std_clib.h | 1 | ||||
-rw-r--r-- | platform/linux-generic/odp_cpumask.c | 39 | ||||
-rw-r--r-- | platform/linux-generic/odp_init.c | 1 |
5 files changed, 33 insertions, 22 deletions
diff --git a/platform/linux-generic/include/odp/api/cpumask.h b/platform/linux-generic/include/odp/api/cpumask.h index 15bf25e8a..325ea52ed 100644 --- a/platform/linux-generic/include/odp/api/cpumask.h +++ b/platform/linux-generic/include/odp/api/cpumask.h @@ -17,10 +17,6 @@ extern "C" { #endif -#include <string.h> -#include <sched.h> - -#include <odp/api/std_types.h> #include <odp/api/plat/cpumask_types.h> #include <odp/api/spec/cpumask.h> diff --git a/platform/linux-generic/include/odp/api/plat/cpumask_types.h b/platform/linux-generic/include/odp/api/plat/cpumask_types.h index c59f407a0..c2727a46c 100644 --- a/platform/linux-generic/include/odp/api/plat/cpumask_types.h +++ b/platform/linux-generic/include/odp/api/plat/cpumask_types.h @@ -23,6 +23,7 @@ extern "C" { */ #include <odp/api/std_types.h> +#include <odp/api/align.h> #define ODP_CPUMASK_SIZE 1024 @@ -34,8 +35,13 @@ extern "C" { * Don't access directly, use access functions. */ typedef struct odp_cpumask_t { - cpu_set_t set; /**< @private Mask*/ -} odp_cpumask_t; + /** @private CPU mask storage + * + * This is private to the implementation. + * Don't access directly, use access functions. + */ + uint8_t _u8[ODP_CPUMASK_SIZE / 8]; +} odp_cpumask_t ODP_ALIGNED(8); /** * @} diff --git a/platform/linux-generic/include/odp/api/std_clib.h b/platform/linux-generic/include/odp/api/std_clib.h index 1578d09f1..40c0ea8ae 100644 --- a/platform/linux-generic/include/odp/api/std_clib.h +++ b/platform/linux-generic/include/odp/api/std_clib.h @@ -12,6 +12,7 @@ extern "C" { #endif #include <odp/api/spec/std_types.h> +#include <string.h> static inline void *odp_memcpy(void *dst, const void *src, size_t num) { diff --git a/platform/linux-generic/odp_cpumask.c b/platform/linux-generic/odp_cpumask.c index 3d35aded9..6bf26322f 100644 --- a/platform/linux-generic/odp_cpumask.c +++ b/platform/linux-generic/odp_cpumask.c @@ -20,9 +20,13 @@ #include <errno.h> #include <sys/types.h> -/** @internal Compile time assert */ -ODP_STATIC_ASSERT(CPU_SETSIZE >= ODP_CPUMASK_SIZE, - "ODP_CPUMASK_SIZE__SIZE_ERROR"); +/* Check that mask can hold all system CPUs*/ +ODP_STATIC_ASSERT(ODP_CPUMASK_SIZE >= CPU_SETSIZE, + "ODP_CPUMASK_SIZE_TOO_SMALL"); + +/* Check that mask type is large enough */ +ODP_STATIC_ASSERT(sizeof(odp_cpumask_t) >= sizeof(cpu_set_t), + "ODP_CPUMASK_T_TOO_SMALL"); void odp_cpumask_from_str(odp_cpumask_t *mask, const char *str_in) { @@ -66,7 +70,7 @@ void odp_cpumask_from_str(odp_cpumask_t *mask, const char *str_in) } /* Copy the computed mask */ - memcpy(&mask->set, &cpuset, sizeof(cpuset)); + memcpy(mask, &cpuset, sizeof(cpuset)); } int32_t odp_cpumask_to_str(const odp_cpumask_t *mask, char *str, int32_t len) @@ -106,7 +110,7 @@ int32_t odp_cpumask_to_str(const odp_cpumask_t *mask, char *str, int32_t len) value = 0; do { /* Set bit to go into the current nibble */ - if (CPU_ISSET(cpu, &mask->set)) + if (CPU_ISSET(cpu, (const cpu_set_t *)mask)) value |= 1 << (cpu % 4); /* If we are on a nibble boundary flush value to string */ @@ -126,12 +130,12 @@ int32_t odp_cpumask_to_str(const odp_cpumask_t *mask, char *str, int32_t len) void odp_cpumask_zero(odp_cpumask_t *mask) { - CPU_ZERO(&mask->set); + CPU_ZERO((cpu_set_t *)mask); } void odp_cpumask_set(odp_cpumask_t *mask, int cpu) { - CPU_SET(cpu, &mask->set); + CPU_SET(cpu, (cpu_set_t *)mask); } void odp_cpumask_setall(odp_cpumask_t *mask) @@ -139,51 +143,54 @@ void odp_cpumask_setall(odp_cpumask_t *mask) int cpu; for (cpu = 0; cpu < CPU_SETSIZE; cpu++) - CPU_SET(cpu, &mask->set); + CPU_SET(cpu, (cpu_set_t *)mask); } void odp_cpumask_clr(odp_cpumask_t *mask, int cpu) { - CPU_CLR(cpu, &mask->set); + CPU_CLR(cpu, (cpu_set_t *)mask); } int odp_cpumask_isset(const odp_cpumask_t *mask, int cpu) { - return CPU_ISSET(cpu, &mask->set); + return CPU_ISSET(cpu, (const cpu_set_t *)mask); } int odp_cpumask_count(const odp_cpumask_t *mask) { - return CPU_COUNT(&mask->set); + return CPU_COUNT((const cpu_set_t *)mask); } void odp_cpumask_and(odp_cpumask_t *dest, const odp_cpumask_t *src1, const odp_cpumask_t *src2) { - CPU_AND(&dest->set, &src1->set, &src2->set); + CPU_AND((cpu_set_t *)dest, (const cpu_set_t *)src1, + (const cpu_set_t *)src2); } void odp_cpumask_or(odp_cpumask_t *dest, const odp_cpumask_t *src1, const odp_cpumask_t *src2) { - CPU_OR(&dest->set, &src1->set, &src2->set); + CPU_OR((cpu_set_t *)dest, (const cpu_set_t *)src1, + (const cpu_set_t *)src2); } void odp_cpumask_xor(odp_cpumask_t *dest, const odp_cpumask_t *src1, const odp_cpumask_t *src2) { - CPU_XOR(&dest->set, &src1->set, &src2->set); + CPU_XOR((cpu_set_t *)dest, (const cpu_set_t *)src1, + (const cpu_set_t *)src2); } int odp_cpumask_equal(const odp_cpumask_t *mask1, const odp_cpumask_t *mask2) { - return CPU_EQUAL(&mask1->set, &mask2->set); + return CPU_EQUAL((const cpu_set_t *)mask1, (const cpu_set_t *)mask2); } void odp_cpumask_copy(odp_cpumask_t *dest, const odp_cpumask_t *src) { - memcpy(&dest->set, &src->set, sizeof(src->set)); + memcpy(dest, src, sizeof(odp_cpumask_t)); } int odp_cpumask_first(const odp_cpumask_t *mask) diff --git a/platform/linux-generic/odp_init.c b/platform/linux-generic/odp_init.c index f58f41078..f534759e1 100644 --- a/platform/linux-generic/odp_init.c +++ b/platform/linux-generic/odp_init.c @@ -9,6 +9,7 @@ #include <unistd.h> #include <odp_internal.h> #include <odp_schedule_if.h> +#include <string.h> struct odp_global_data_s odp_global_data; |