diff mbox

[1/1] Compile ODP for PowerPC targets

Message ID 1393503189-3430-1-git-send-email-alexandru.badicioiu@linaro.org
State Superseded, archived
Headers show

Commit Message

Alexandru Badicioiu Feb. 27, 2014, 12:13 p.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, 75 insertions(+), 5 deletions(-)

Comments

Maxim Uvarov March 4, 2014, 3:16 a.m. UTC | #1
On 02/27/2014 04:13 PM, 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, 75 insertions(+), 5 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..b4ec87c 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
is this tool chain specific version? why is that different for powerpc?
>   #include <fcntl.h>
>   
>   #include <stdio.h>
> @@ -97,7 +100,7 @@ void *odp_shm_reserve(const char *name, uint64_t size, uint64_t align)
>   	int i;
>   	odp_shm_block_t *block;
>   	void *addr;
> -	uint64_t huge_sz, page_sz;
> +	uint64_t huge_sz ODP_UNUSED, page_sz ODP_UNUSED;
>   
>   	huge_sz = odp_sys_huge_page_size();
>   	page_sz = odp_sys_page_size();
if you set huge_sz here do you really need ODP_UNUSED?
> 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
Alexandru Badicioiu March 4, 2014, 3:20 a.m. UTC | #2
The header containing MAP_HUGETLB definitions seems to be specific for PPC
- <asm/mman.h> instead of <sys/mman.h>. I'm not aware of the reasons, but
no matter which header file is, if MAP_HUGETLB is not defined then a
compile warning saying "huge_sz and page_sz set but not used" will stop the
compilation because of -Werror switch.

Alex


On 4 March 2014 11:16, Maxim Uvarov <maxim.uvarov@linaro.org> wrote:

> On 02/27/2014 04:13 PM, 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, 75 insertions(+), 5 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..b4ec87c 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
>>
> is this tool chain specific version? why is that different for powerpc?
>
>    #include <fcntl.h>
>>     #include <stdio.h>
>> @@ -97,7 +100,7 @@ void *odp_shm_reserve(const char *name, uint64_t size,
>> uint64_t align)
>>         int i;
>>         odp_shm_block_t *block;
>>         void *addr;
>> -       uint64_t huge_sz, page_sz;
>> +       uint64_t huge_sz ODP_UNUSED, page_sz ODP_UNUSED;
>>         huge_sz = odp_sys_huge_page_size();
>>         page_sz = odp_sys_page_size();
>>
> if you set huge_sz here do you really need ODP_UNUSED?
>
>  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
>>
>
>
Petri Savolainen March 4, 2014, 7:03 a.m. UTC | #3
Hi,

On Thursday, 27 February 2014 14:13:09 UTC+2, Alexandru Badicioiu wrote:

> From: Alexandru Badicioiu <alexandru...@linaro.org <javascript:>> 
>   
>
 

>   */ 
> + 
> +#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); 
> +} 
>

Is this correct also in the 64 bit case ( == __powerpc64__) ?
 

> +#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); 
> +}

 
Same thing here.
 

>
> +#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..b4ec87c 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,7 +100,7 @@ void *odp_shm_reserve(const char *name, uint64_t size, 
> uint64_t align) 
>          int i; 
>          odp_shm_block_t *block; 
>          void *addr; 
> -        uint64_t huge_sz, page_sz; 
> +        uint64_t huge_sz ODP_UNUSED, page_sz ODP_UNUSED; 
>

It's better to #ifdef MAP_HUGETLB also these, than set to unused. Those are 
used when MAP_HUGETLB is defined. 
 

>   
>          huge_sz = odp_sys_huge_page_size(); 
>          page_sz = odp_sys_page_size(); 
>
>
-Petri
Alexandru Badicioiu March 4, 2014, 2:13 p.m. UTC | #4
64bit PPC defines both __powerpc__ and __powerpc64__. 32b PPC defines only
__powerpc__. In case of 32b PPC atomic gcc builtins cause a link error so
this is the purpose of casts to 32b types.I assume that 64bit atomics still
can be implemented with inline assembly on PPC 32, but the fallback to 32b
value was agreed with Bill.


On 4 March 2014 15:03, Petri Savolainen <petri.savolainen@linaro.org> wrote:

> Hi,
>
> On Thursday, 27 February 2014 14:13:09 UTC+2, Alexandru Badicioiu wrote:
>
>> From: Alexandru Badicioiu <alexandru...@linaro.org>
>>
>>
>
>
>>   */
>> +
>> +#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);
>> +}
>>
>
> Is this correct also in the 64 bit case ( == __powerpc64__) ?
>
>
>> +#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);
>> +}
>
>
> Same thing here.
>
>
>>
>> +#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..b4ec87c 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,7 +100,7 @@ void *odp_shm_reserve(const char *name, uint64_t size,
>> uint64_t align)
>>          int i;
>>          odp_shm_block_t *block;
>>          void *addr;
>> -        uint64_t huge_sz, page_sz;
>> +        uint64_t huge_sz ODP_UNUSED, page_sz ODP_UNUSED;
>>
>
> It's better to #ifdef MAP_HUGETLB also these, than set to unused. Those
> are used when MAP_HUGETLB is defined.
>
>
>>
>>          huge_sz = odp_sys_huge_page_size();
>>          page_sz = odp_sys_page_size();
>>
>>
> -Petri
>
>
Santosh Shukla March 15, 2014, 6:48 p.m. UTC | #5
Alexandru,

any update on this thread?

Thanks.

On 4 March 2014 19:43, Alexandru Badicioiu
<alexandru.badicioiu@linaro.org> wrote:
> 64bit PPC defines both __powerpc__ and __powerpc64__. 32b PPC defines only
> __powerpc__. In case of 32b PPC atomic gcc builtins cause a link error so
> this is the purpose of casts to 32b types.I assume that 64bit atomics still
> can be implemented with inline assembly on PPC 32, but the fallback to 32b
> value was agreed with Bill.
>
>
> On 4 March 2014 15:03, Petri Savolainen <petri.savolainen@linaro.org> wrote:
>>
>> Hi,
>>
>> On Thursday, 27 February 2014 14:13:09 UTC+2, Alexandru Badicioiu wrote:
>>>
>>> From: Alexandru Badicioiu <alexandru...@linaro.org>
>>>
>>
>>
>>>
>>>   */
>>> +
>>> +#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);
>>> +}
>>
>>
>> Is this correct also in the 64 bit case ( == __powerpc64__) ?
>>
>>>
>>> +#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);
>>> +}
>>
>>
>> Same thing here.
>>
>>>
>>>
>>> +#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..b4ec87c 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,7 +100,7 @@ void *odp_shm_reserve(const char *name, uint64_t size,
>>> uint64_t align)
>>>          int i;
>>>          odp_shm_block_t *block;
>>>          void *addr;
>>> -        uint64_t huge_sz, page_sz;
>>> +        uint64_t huge_sz ODP_UNUSED, page_sz ODP_UNUSED;
>>
>>
>> It's better to #ifdef MAP_HUGETLB also these, than set to unused. Those
>> are used when MAP_HUGETLB is defined.
>>
>>>
>>>
>>>          huge_sz = odp_sys_huge_page_size();
>>>          page_sz = odp_sys_page_size();
>>>
>>
>> -Petri
>>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "LNG ODP Sub-team - lng-odp@linaro.org" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to lng-odp+unsubscribe@linaro.org.
> To post to this group, send email to lng-odp@linaro.org.
> Visit this group at http://groups.google.com/a/linaro.org/group/lng-odp/.
> To view this discussion on the web visit
> https://groups.google.com/a/linaro.org/d/msgid/lng-odp/CA%2BgU81S48SJMiDGeFNMXDu4Jeo9JHmDKprV35LrpdLqsT5pJjg%40mail.gmail.com.
>
> For more options, visit
> https://groups.google.com/a/linaro.org/groups/opt_out.
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..b4ec87c 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,7 +100,7 @@  void *odp_shm_reserve(const char *name, uint64_t size, uint64_t align)
 	int i;
 	odp_shm_block_t *block;
 	void *addr;
-	uint64_t huge_sz, page_sz;
+	uint64_t huge_sz ODP_UNUSED, page_sz ODP_UNUSED;
 
 	huge_sz = odp_sys_huge_page_size();
 	page_sz = odp_sys_page_size();
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