diff mbox

[v2,1/1] Compile ODP for PowerPC targets

Message ID 1395042910-18389-1-git-send-email-alexandru.badicioiu@linaro.org
State Accepted, archived
Headers show

Commit Message

Alexandru Badicioiu March 17, 2014, 7:55 a.m. UTC
From: Alexandru Badicioiu <alexandru.badicioiu@linaro.org>

- define cache line size
- fallback to 32bit atomics on 32bit platforms
- enable hugetlb mappings
- fix compilation errors when hugetlb mappings are not used
- cpuinfo parser

Signed-off-by: Alexandru Badicioiu <alexandru.badicioiu@linaro.org>
---
 include/odp_align.h                               |    4 ++
 include/odp_atomic.h                              |   21 ++++++++-
 platform/linux-generic/source/odp_shared_memory.c |    5 ++
 platform/linux-generic/source/odp_system_info.c   |   50 ++++++++++++++++++++-
 4 files changed, 76 insertions(+), 4 deletions(-)

Comments

Maxim Uvarov March 19, 2014, 9:54 a.m. UTC | #1
applied!

thanks,
Maxim.
On 03/17/2014 11:55 AM, alexandru.badicioiu@linaro.org wrote:
> From: Alexandru Badicioiu <alexandru.badicioiu@linaro.org>
>
> - define cache line size
> - fallback to 32bit atomics on 32bit platforms
> - enable hugetlb mappings
> - fix compilation errors when hugetlb mappings are not used
> - cpuinfo parser
>
> Signed-off-by: Alexandru Badicioiu <alexandru.badicioiu@linaro.org>
> ---
>   include/odp_align.h                               |    4 ++
>   include/odp_atomic.h                              |   21 ++++++++-
>   platform/linux-generic/source/odp_shared_memory.c |    5 ++
>   platform/linux-generic/source/odp_system_info.c   |   50 ++++++++++++++++++++-
>   4 files changed, 76 insertions(+), 4 deletions(-)
>
> diff --git a/include/odp_align.h b/include/odp_align.h
> index 0f0c614..67a7cdc 100644
> --- a/include/odp_align.h
> +++ b/include/odp_align.h
> @@ -42,6 +42,10 @@ extern "C" {
>   
>   #define ODP_CACHE_LINE_SIZE 128
>   
> +#elif defined __powerpc__
> +
> +#define ODP_CACHE_LINE_SIZE 64
> +
>   #else
>   #error GCC target not found
>   #endif
> diff --git a/include/odp_atomic.h b/include/odp_atomic.h
> index 3a8a18d..763436a 100644
> --- a/include/odp_atomic.h
> +++ b/include/odp_atomic.h
> @@ -353,12 +353,21 @@ static inline void odp_atomic_add_u64(odp_atomic_u64_t *ptr, uint64_t value)
>    *
>    * @return Value of the variable before the operation
>    */
> +
> +#if defined __powerpc__ && !defined __powerpc64__
> +static inline uint64_t odp_atomic_fetch_add_u64(odp_atomic_u64_t *ptr,
> +						uint64_t value)
> +{
> +	return __sync_fetch_and_add((odp_atomic_u32_t *)ptr,
> +				   (uint32_t)value);
> +}
> +#else
>   static inline uint64_t odp_atomic_fetch_add_u64(odp_atomic_u64_t *ptr,
>   						uint64_t value)
>   {
>   	return __sync_fetch_and_add(ptr, value);
>   }
> -
> +#endif
>   /**
>    * Subtract atomic uint64
>    *
> @@ -379,12 +388,20 @@ static inline void odp_atomic_sub_u64(odp_atomic_u64_t *ptr, uint64_t value)
>    *
>    * @return Value of the variable before the operation
>    */
> +#if defined __powerpc__ && !defined __powerpc64__
> +static inline uint64_t odp_atomic_fetch_sub_u64(odp_atomic_u64_t *ptr,
> +						uint64_t value)
> +{
> +	return __sync_fetch_and_sub((odp_atomic_u32_t *)ptr,
> +				   (uint32_t)value);
> +}
> +#else
>   static inline uint64_t odp_atomic_fetch_sub_u64(odp_atomic_u64_t *ptr,
>   						uint64_t value)
>   {
>   	return __sync_fetch_and_sub(ptr, value);
>   }
> -
> +#endif
>   /**
>    * Fetch and increment atomic uint64 by 1
>    *
> diff --git a/platform/linux-generic/source/odp_shared_memory.c b/platform/linux-generic/source/odp_shared_memory.c
> index ef4bfcd..c607c99 100644
> --- a/platform/linux-generic/source/odp_shared_memory.c
> +++ b/platform/linux-generic/source/odp_shared_memory.c
> @@ -13,6 +13,9 @@
>   #include <odp_debug.h>
>   
>   #include <sys/mman.h>
> +#ifdef __powerpc__
> +#include <asm/mman.h>
> +#endif
>   #include <fcntl.h>
>   
>   #include <stdio.h>
> @@ -97,10 +100,12 @@ void *odp_shm_reserve(const char *name, uint64_t size, uint64_t align)
>   	int i;
>   	odp_shm_block_t *block;
>   	void *addr;
> +#ifdef MAP_HUGETLB
>   	uint64_t huge_sz, page_sz;
>   
>   	huge_sz = odp_sys_huge_page_size();
>   	page_sz = odp_sys_page_size();
> +#endif
>   
>   	odp_spinlock_lock(&odp_shm_tbl->lock);
>   
> diff --git a/platform/linux-generic/source/odp_system_info.c b/platform/linux-generic/source/odp_system_info.c
> index 43129db..17617b0 100644
> --- a/platform/linux-generic/source/odp_system_info.c
> +++ b/platform/linux-generic/source/odp_system_info.c
> @@ -60,7 +60,8 @@ static int sysconf_core_count(void)
>   }
>   
>   
> -#if defined __x86_64__ || defined __i386__ || defined __OCTEON__
> +#if defined __x86_64__ || defined __i386__ || defined __OCTEON__ || \
> +defined __powerpc__
>   /*
>    * Analysis of /sys/devices/system/cpu/ files
>    */
> @@ -213,6 +214,46 @@ static int cpuinfo_octeon(FILE *file, odp_system_info_t *sysinfo)
>   
>   	return 0;
>   }
> +#elif defined __powerpc__
> +static int cpuinfo_powerpc(FILE *file, odp_system_info_t *sysinfo)
> +{
> +	char str[1024];
> +	char *pos;
> +	double mhz = 0.0;
> +	int model = 0;
> +	int count = 2;
> +
> +	while (fgets(str, sizeof(str), file) != NULL && count > 0) {
> +		if (!mhz) {
> +			pos = strstr(str, "clock");
> +
> +			if (pos) {
> +				sscanf(pos, "clock : %lf", &mhz);
> +				count--;
> +			}
> +		}
> +
> +		if (!model) {
> +			pos = strstr(str, "cpu");
> +
> +			if (pos) {
> +				int len;
> +				pos = strchr(str, ':');
> +				strncpy(sysinfo->model_str, pos+2,
> +					sizeof(sysinfo->model_str));
> +				len = strlen(sysinfo->model_str);
> +				sysinfo->model_str[len - 1] = 0;
> +				model = 1;
> +				count--;
> +			}
> +		}
> +
> +		sysinfo->cpu_hz = (uint64_t) (mhz * 1000000.0);
> +	}
> +
> +
> +	return 0;
> +}
>   
>   #else
>   	#error GCC target not found
> @@ -231,13 +272,18 @@ static odp_compiler_info_t compiler_info = {
>   	.cpu_arch_str = "octeon",
>   	.cpuinfo_parser = cpuinfo_octeon
>   
> +	#elif defined __powerpc__
> +	.cpu_arch_str = "powerpc",
> +	.cpuinfo_parser = cpuinfo_powerpc
> +
>   	#else
>   	#error GCC target not found
>   	#endif
>   };
>   
>   
> -#if defined __x86_64__ || defined __i386__ || defined __OCTEON__
> +#if defined __x86_64__ || defined __i386__ || defined __OCTEON__ || \
> +defined __powerpc__
>   
>   /*
>    * Analysis of /sys/devices/system/cpu/ files
diff mbox

Patch

diff --git a/include/odp_align.h b/include/odp_align.h
index 0f0c614..67a7cdc 100644
--- a/include/odp_align.h
+++ b/include/odp_align.h
@@ -42,6 +42,10 @@  extern "C" {
 
 #define ODP_CACHE_LINE_SIZE 128
 
+#elif defined __powerpc__
+
+#define ODP_CACHE_LINE_SIZE 64
+
 #else
 #error GCC target not found
 #endif
diff --git a/include/odp_atomic.h b/include/odp_atomic.h
index 3a8a18d..763436a 100644
--- a/include/odp_atomic.h
+++ b/include/odp_atomic.h
@@ -353,12 +353,21 @@  static inline void odp_atomic_add_u64(odp_atomic_u64_t *ptr, uint64_t value)
  *
  * @return Value of the variable before the operation
  */
+
+#if defined __powerpc__ && !defined __powerpc64__
+static inline uint64_t odp_atomic_fetch_add_u64(odp_atomic_u64_t *ptr,
+						uint64_t value)
+{
+	return __sync_fetch_and_add((odp_atomic_u32_t *)ptr,
+				   (uint32_t)value);
+}
+#else
 static inline uint64_t odp_atomic_fetch_add_u64(odp_atomic_u64_t *ptr,
 						uint64_t value)
 {
 	return __sync_fetch_and_add(ptr, value);
 }
-
+#endif
 /**
  * Subtract atomic uint64
  *
@@ -379,12 +388,20 @@  static inline void odp_atomic_sub_u64(odp_atomic_u64_t *ptr, uint64_t value)
  *
  * @return Value of the variable before the operation
  */
+#if defined __powerpc__ && !defined __powerpc64__
+static inline uint64_t odp_atomic_fetch_sub_u64(odp_atomic_u64_t *ptr,
+						uint64_t value)
+{
+	return __sync_fetch_and_sub((odp_atomic_u32_t *)ptr,
+				   (uint32_t)value);
+}
+#else
 static inline uint64_t odp_atomic_fetch_sub_u64(odp_atomic_u64_t *ptr,
 						uint64_t value)
 {
 	return __sync_fetch_and_sub(ptr, value);
 }
-
+#endif
 /**
  * Fetch and increment atomic uint64 by 1
  *
diff --git a/platform/linux-generic/source/odp_shared_memory.c b/platform/linux-generic/source/odp_shared_memory.c
index ef4bfcd..c607c99 100644
--- a/platform/linux-generic/source/odp_shared_memory.c
+++ b/platform/linux-generic/source/odp_shared_memory.c
@@ -13,6 +13,9 @@ 
 #include <odp_debug.h>
 
 #include <sys/mman.h>
+#ifdef __powerpc__
+#include <asm/mman.h>
+#endif
 #include <fcntl.h>
 
 #include <stdio.h>
@@ -97,10 +100,12 @@  void *odp_shm_reserve(const char *name, uint64_t size, uint64_t align)
 	int i;
 	odp_shm_block_t *block;
 	void *addr;
+#ifdef MAP_HUGETLB
 	uint64_t huge_sz, page_sz;
 
 	huge_sz = odp_sys_huge_page_size();
 	page_sz = odp_sys_page_size();
+#endif
 
 	odp_spinlock_lock(&odp_shm_tbl->lock);
 
diff --git a/platform/linux-generic/source/odp_system_info.c b/platform/linux-generic/source/odp_system_info.c
index 43129db..17617b0 100644
--- a/platform/linux-generic/source/odp_system_info.c
+++ b/platform/linux-generic/source/odp_system_info.c
@@ -60,7 +60,8 @@  static int sysconf_core_count(void)
 }
 
 
-#if defined __x86_64__ || defined __i386__ || defined __OCTEON__
+#if defined __x86_64__ || defined __i386__ || defined __OCTEON__ || \
+defined __powerpc__
 /*
  * Analysis of /sys/devices/system/cpu/ files
  */
@@ -213,6 +214,46 @@  static int cpuinfo_octeon(FILE *file, odp_system_info_t *sysinfo)
 
 	return 0;
 }
+#elif defined __powerpc__
+static int cpuinfo_powerpc(FILE *file, odp_system_info_t *sysinfo)
+{
+	char str[1024];
+	char *pos;
+	double mhz = 0.0;
+	int model = 0;
+	int count = 2;
+
+	while (fgets(str, sizeof(str), file) != NULL && count > 0) {
+		if (!mhz) {
+			pos = strstr(str, "clock");
+
+			if (pos) {
+				sscanf(pos, "clock : %lf", &mhz);
+				count--;
+			}
+		}
+
+		if (!model) {
+			pos = strstr(str, "cpu");
+
+			if (pos) {
+				int len;
+				pos = strchr(str, ':');
+				strncpy(sysinfo->model_str, pos+2,
+					sizeof(sysinfo->model_str));
+				len = strlen(sysinfo->model_str);
+				sysinfo->model_str[len - 1] = 0;
+				model = 1;
+				count--;
+			}
+		}
+
+		sysinfo->cpu_hz = (uint64_t) (mhz * 1000000.0);
+	}
+
+
+	return 0;
+}
 
 #else
 	#error GCC target not found
@@ -231,13 +272,18 @@  static odp_compiler_info_t compiler_info = {
 	.cpu_arch_str = "octeon",
 	.cpuinfo_parser = cpuinfo_octeon
 
+	#elif defined __powerpc__
+	.cpu_arch_str = "powerpc",
+	.cpuinfo_parser = cpuinfo_powerpc
+
 	#else
 	#error GCC target not found
 	#endif
 };
 
 
-#if defined __x86_64__ || defined __i386__ || defined __OCTEON__
+#if defined __x86_64__ || defined __i386__ || defined __OCTEON__ || \
+defined __powerpc__
 
 /*
  * Analysis of /sys/devices/system/cpu/ files