linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] perf: Use __BYTE_ORDER__
@ 2021-11-04 13:23 Ilya Leoshkevich
  2021-11-06 20:02 ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 2+ messages in thread
From: Ilya Leoshkevich @ 2021-11-04 13:23 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: linux-kernel, Heiko Carstens, Vasily Gorbik, Thomas Richter,
	Ilya Leoshkevich

Switch from the libc-defined __BYTE_ORDER to the compiler-defined
__BYTE_ORDER__ in order to make endianness detection more robust, like
it was done for libbpf.

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
---
 tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c    | 2 +-
 tools/perf/util/data-convert-bt.c                        | 2 +-
 tools/perf/util/genelf.h                                 | 2 +-
 tools/perf/util/intel-bts.c                              | 2 +-
 tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.c | 2 +-
 tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c  | 2 +-
 tools/perf/util/s390-cpumsf.c                            | 8 ++++----
 7 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c b/tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c
index 2e5eff4f8f03..2f311189c6e8 100644
--- a/tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c
+++ b/tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c
@@ -13,7 +13,7 @@
 
 #include "arm-spe-pkt-decoder.h"
 
-#if __BYTE_ORDER == __BIG_ENDIAN
+#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
 #define le16_to_cpu bswap_16
 #define le32_to_cpu bswap_32
 #define le64_to_cpu bswap_64
diff --git a/tools/perf/util/data-convert-bt.c b/tools/perf/util/data-convert-bt.c
index aa862a26d95c..8f7705bbc2da 100644
--- a/tools/perf/util/data-convert-bt.c
+++ b/tools/perf/util/data-convert-bt.c
@@ -1437,7 +1437,7 @@ static struct bt_ctf_field_type *create_int_type(int size, bool sign, bool hex)
 	    bt_ctf_field_type_integer_set_base(type, BT_CTF_INTEGER_BASE_HEXADECIMAL))
 		goto err;
 
-#if __BYTE_ORDER == __BIG_ENDIAN
+#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
 	bt_ctf_field_type_set_byte_order(type, BT_CTF_BYTE_ORDER_BIG_ENDIAN);
 #else
 	bt_ctf_field_type_set_byte_order(type, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN);
diff --git a/tools/perf/util/genelf.h b/tools/perf/util/genelf.h
index d4137559be05..3db3293213a9 100644
--- a/tools/perf/util/genelf.h
+++ b/tools/perf/util/genelf.h
@@ -42,7 +42,7 @@ int jit_add_debug_info(Elf *e, uint64_t code_addr, void *debug, int nr_debug_ent
 #error "unsupported architecture"
 #endif
 
-#if __BYTE_ORDER == __BIG_ENDIAN
+#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
 #define GEN_ELF_ENDIAN	ELFDATA2MSB
 #else
 #define GEN_ELF_ENDIAN	ELFDATA2LSB
diff --git a/tools/perf/util/intel-bts.c b/tools/perf/util/intel-bts.c
index af1e78d76228..2c8147a62203 100644
--- a/tools/perf/util/intel-bts.c
+++ b/tools/perf/util/intel-bts.c
@@ -35,7 +35,7 @@
 #define INTEL_BTS_ERR_NOINSN  5
 #define INTEL_BTS_ERR_LOST    9
 
-#if __BYTE_ORDER == __BIG_ENDIAN
+#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
 #define le64_to_cpu bswap_64
 #else
 #define le64_to_cpu
diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.c b/tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.c
index 593f20e9774c..9d5e65cec89b 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.c
@@ -143,7 +143,7 @@ static void intel_pt_insn_decoder(struct insn *insn,
 
 	if (branch == INTEL_PT_BR_CONDITIONAL ||
 	    branch == INTEL_PT_BR_UNCONDITIONAL) {
-#if __BYTE_ORDER == __BIG_ENDIAN
+#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
 		switch (insn->immediate.nbytes) {
 		case 1:
 			intel_pt_insn->rel = insn->immediate.value;
diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c b/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c
index 02a3395d6ce3..4bd154848cad 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c
@@ -16,7 +16,7 @@
 
 #define BIT63		((uint64_t)1 << 63)
 
-#if __BYTE_ORDER == __BIG_ENDIAN
+#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
 #define le16_to_cpu bswap_16
 #define le32_to_cpu bswap_32
 #define le64_to_cpu bswap_64
diff --git a/tools/perf/util/s390-cpumsf.c b/tools/perf/util/s390-cpumsf.c
index 8130b56aa04b..f3fdad28a852 100644
--- a/tools/perf/util/s390-cpumsf.c
+++ b/tools/perf/util/s390-cpumsf.c
@@ -244,7 +244,7 @@ static bool s390_cpumsf_basic_show(const char *color, size_t pos,
 				   struct hws_basic_entry *basicp)
 {
 	struct hws_basic_entry *basic = basicp;
-#if __BYTE_ORDER == __LITTLE_ENDIAN
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
 	struct hws_basic_entry local;
 	unsigned long long word = be64toh(*(unsigned long long *)basicp);
 
@@ -288,7 +288,7 @@ static bool s390_cpumsf_diag_show(const char *color, size_t pos,
 				  struct hws_diag_entry *diagp)
 {
 	struct hws_diag_entry *diag = diagp;
-#if __BYTE_ORDER == __LITTLE_ENDIAN
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
 	struct hws_diag_entry local;
 	unsigned long long word = be64toh(*(unsigned long long *)diagp);
 
@@ -322,7 +322,7 @@ static unsigned long long trailer_timestamp(struct hws_trailer_entry *te,
 static bool s390_cpumsf_trailer_show(const char *color, size_t pos,
 				     struct hws_trailer_entry *te)
 {
-#if __BYTE_ORDER == __LITTLE_ENDIAN
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
 	struct hws_trailer_entry local;
 	const unsigned long long flags = be64toh(te->flags);
 
@@ -552,7 +552,7 @@ static unsigned long long get_trailer_time(const unsigned char *buf)
 	te = (struct hws_trailer_entry *)(buf + S390_CPUMSF_PAGESZ
 					      - sizeof(*te));
 
-#if __BYTE_ORDER == __LITTLE_ENDIAN
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
 	clock_base = be64toh(te->progusage[0]) >> 63 & 0x1;
 	progusage2 = be64toh(te->progusage[1]);
 #else
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] perf: Use __BYTE_ORDER__
  2021-11-04 13:23 [PATCH] perf: Use __BYTE_ORDER__ Ilya Leoshkevich
@ 2021-11-06 20:02 ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 2+ messages in thread
From: Arnaldo Carvalho de Melo @ 2021-11-06 20:02 UTC (permalink / raw)
  To: Ilya Leoshkevich
  Cc: Arnaldo Carvalho de Melo, linux-kernel, Heiko Carstens,
	Vasily Gorbik, Thomas Richter

Em Thu, Nov 04, 2021 at 02:23:11PM +0100, Ilya Leoshkevich escreveu:
> Switch from the libc-defined __BYTE_ORDER to the compiler-defined
> __BYTE_ORDER__ in order to make endianness detection more robust, like
> it was done for libbpf.

Thanks, applied.

- Arnaldo

 
> Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
> ---
>  tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c    | 2 +-
>  tools/perf/util/data-convert-bt.c                        | 2 +-
>  tools/perf/util/genelf.h                                 | 2 +-
>  tools/perf/util/intel-bts.c                              | 2 +-
>  tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.c | 2 +-
>  tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c  | 2 +-
>  tools/perf/util/s390-cpumsf.c                            | 8 ++++----
>  7 files changed, 10 insertions(+), 10 deletions(-)
> 
> diff --git a/tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c b/tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c
> index 2e5eff4f8f03..2f311189c6e8 100644
> --- a/tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c
> +++ b/tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c
> @@ -13,7 +13,7 @@
>  
>  #include "arm-spe-pkt-decoder.h"
>  
> -#if __BYTE_ORDER == __BIG_ENDIAN
> +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
>  #define le16_to_cpu bswap_16
>  #define le32_to_cpu bswap_32
>  #define le64_to_cpu bswap_64
> diff --git a/tools/perf/util/data-convert-bt.c b/tools/perf/util/data-convert-bt.c
> index aa862a26d95c..8f7705bbc2da 100644
> --- a/tools/perf/util/data-convert-bt.c
> +++ b/tools/perf/util/data-convert-bt.c
> @@ -1437,7 +1437,7 @@ static struct bt_ctf_field_type *create_int_type(int size, bool sign, bool hex)
>  	    bt_ctf_field_type_integer_set_base(type, BT_CTF_INTEGER_BASE_HEXADECIMAL))
>  		goto err;
>  
> -#if __BYTE_ORDER == __BIG_ENDIAN
> +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
>  	bt_ctf_field_type_set_byte_order(type, BT_CTF_BYTE_ORDER_BIG_ENDIAN);
>  #else
>  	bt_ctf_field_type_set_byte_order(type, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN);
> diff --git a/tools/perf/util/genelf.h b/tools/perf/util/genelf.h
> index d4137559be05..3db3293213a9 100644
> --- a/tools/perf/util/genelf.h
> +++ b/tools/perf/util/genelf.h
> @@ -42,7 +42,7 @@ int jit_add_debug_info(Elf *e, uint64_t code_addr, void *debug, int nr_debug_ent
>  #error "unsupported architecture"
>  #endif
>  
> -#if __BYTE_ORDER == __BIG_ENDIAN
> +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
>  #define GEN_ELF_ENDIAN	ELFDATA2MSB
>  #else
>  #define GEN_ELF_ENDIAN	ELFDATA2LSB
> diff --git a/tools/perf/util/intel-bts.c b/tools/perf/util/intel-bts.c
> index af1e78d76228..2c8147a62203 100644
> --- a/tools/perf/util/intel-bts.c
> +++ b/tools/perf/util/intel-bts.c
> @@ -35,7 +35,7 @@
>  #define INTEL_BTS_ERR_NOINSN  5
>  #define INTEL_BTS_ERR_LOST    9
>  
> -#if __BYTE_ORDER == __BIG_ENDIAN
> +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
>  #define le64_to_cpu bswap_64
>  #else
>  #define le64_to_cpu
> diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.c b/tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.c
> index 593f20e9774c..9d5e65cec89b 100644
> --- a/tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.c
> +++ b/tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.c
> @@ -143,7 +143,7 @@ static void intel_pt_insn_decoder(struct insn *insn,
>  
>  	if (branch == INTEL_PT_BR_CONDITIONAL ||
>  	    branch == INTEL_PT_BR_UNCONDITIONAL) {
> -#if __BYTE_ORDER == __BIG_ENDIAN
> +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
>  		switch (insn->immediate.nbytes) {
>  		case 1:
>  			intel_pt_insn->rel = insn->immediate.value;
> diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c b/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c
> index 02a3395d6ce3..4bd154848cad 100644
> --- a/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c
> +++ b/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c
> @@ -16,7 +16,7 @@
>  
>  #define BIT63		((uint64_t)1 << 63)
>  
> -#if __BYTE_ORDER == __BIG_ENDIAN
> +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
>  #define le16_to_cpu bswap_16
>  #define le32_to_cpu bswap_32
>  #define le64_to_cpu bswap_64
> diff --git a/tools/perf/util/s390-cpumsf.c b/tools/perf/util/s390-cpumsf.c
> index 8130b56aa04b..f3fdad28a852 100644
> --- a/tools/perf/util/s390-cpumsf.c
> +++ b/tools/perf/util/s390-cpumsf.c
> @@ -244,7 +244,7 @@ static bool s390_cpumsf_basic_show(const char *color, size_t pos,
>  				   struct hws_basic_entry *basicp)
>  {
>  	struct hws_basic_entry *basic = basicp;
> -#if __BYTE_ORDER == __LITTLE_ENDIAN
> +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
>  	struct hws_basic_entry local;
>  	unsigned long long word = be64toh(*(unsigned long long *)basicp);
>  
> @@ -288,7 +288,7 @@ static bool s390_cpumsf_diag_show(const char *color, size_t pos,
>  				  struct hws_diag_entry *diagp)
>  {
>  	struct hws_diag_entry *diag = diagp;
> -#if __BYTE_ORDER == __LITTLE_ENDIAN
> +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
>  	struct hws_diag_entry local;
>  	unsigned long long word = be64toh(*(unsigned long long *)diagp);
>  
> @@ -322,7 +322,7 @@ static unsigned long long trailer_timestamp(struct hws_trailer_entry *te,
>  static bool s390_cpumsf_trailer_show(const char *color, size_t pos,
>  				     struct hws_trailer_entry *te)
>  {
> -#if __BYTE_ORDER == __LITTLE_ENDIAN
> +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
>  	struct hws_trailer_entry local;
>  	const unsigned long long flags = be64toh(te->flags);
>  
> @@ -552,7 +552,7 @@ static unsigned long long get_trailer_time(const unsigned char *buf)
>  	te = (struct hws_trailer_entry *)(buf + S390_CPUMSF_PAGESZ
>  					      - sizeof(*te));
>  
> -#if __BYTE_ORDER == __LITTLE_ENDIAN
> +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
>  	clock_base = be64toh(te->progusage[0]) >> 63 & 0x1;
>  	progusage2 = be64toh(te->progusage[1]);
>  #else
> -- 
> 2.31.1
> 

-- 

- Arnaldo

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-11-06 20:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-04 13:23 [PATCH] perf: Use __BYTE_ORDER__ Ilya Leoshkevich
2021-11-06 20:02 ` Arnaldo Carvalho de Melo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).