* [PATCH 0/5] perf intel-pt: Use of get_unaligned_le16() etc
@ 2023-10-05 19:04 Adrian Hunter
2023-10-05 19:04 ` [PATCH 1/5] perf tools: Add get_unaligned_leNN() Adrian Hunter
` (5 more replies)
0 siblings, 6 replies; 14+ messages in thread
From: Adrian Hunter @ 2023-10-05 19:04 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Jiri Olsa, Namhyung Kim, Ian Rogers, linux-kernel,
linux-perf-users
Hi
Ian sent a patch for this, but using get_unaligned_le16() etc seems nicer.
Adrian Hunter (5):
perf tools: Add get_unaligned_leNN()
perf intel-pt: Simplify intel_pt_get_vmcs()
perf intel-pt: Use existing definitions of le16_to_cpu() etc
perf intel-pt: Use of get_unaligned_le16() etc
perf intel-pt: Prefer get_unaligned_le64 to memcpy_le64
tools/include/asm-generic/unaligned.h | 20 ++++++++++
.../util/intel-pt-decoder/intel-pt-pkt-decoder.c | 43 +++++++++-------------
2 files changed, 37 insertions(+), 26 deletions(-)
Regards
Adrian
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 1/5] perf tools: Add get_unaligned_leNN()
2023-10-05 19:04 [PATCH 0/5] perf intel-pt: Use of get_unaligned_le16() etc Adrian Hunter
@ 2023-10-05 19:04 ` Adrian Hunter
2023-10-05 19:38 ` Arnaldo Carvalho de Melo
2023-10-05 19:04 ` [PATCH 2/5] perf intel-pt: Simplify intel_pt_get_vmcs() Adrian Hunter
` (4 subsequent siblings)
5 siblings, 1 reply; 14+ messages in thread
From: Adrian Hunter @ 2023-10-05 19:04 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Jiri Olsa, Namhyung Kim, Ian Rogers, linux-kernel,
linux-perf-users
Add get_unaligned_le16(), get_unaligned_le32 and get_unaligned_le64, same
as include/asm-generic/unaligned.h.
Use diagnostic pragmas to ignore -Wpacked used by perf build.
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
tools/include/asm-generic/unaligned.h | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/tools/include/asm-generic/unaligned.h b/tools/include/asm-generic/unaligned.h
index 47387c607035..9140bb4e16c6 100644
--- a/tools/include/asm-generic/unaligned.h
+++ b/tools/include/asm-generic/unaligned.h
@@ -6,6 +6,9 @@
#ifndef __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H
#define __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wpacked"
+
#define __get_unaligned_t(type, ptr) ({ \
const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr); \
__pptr->x; \
@@ -19,5 +22,22 @@
#define get_unaligned(ptr) __get_unaligned_t(typeof(*(ptr)), (ptr))
#define put_unaligned(val, ptr) __put_unaligned_t(typeof(*(ptr)), (val), (ptr))
+static inline u16 get_unaligned_le16(const void *p)
+{
+ return le16_to_cpu(__get_unaligned_t(__le16, p));
+}
+
+static inline u32 get_unaligned_le32(const void *p)
+{
+ return le32_to_cpu(__get_unaligned_t(__le32, p));
+}
+
+static inline u64 get_unaligned_le64(const void *p)
+{
+ return le64_to_cpu(__get_unaligned_t(__le64, p));
+}
+
+#pragma GCC diagnostic pop
+
#endif /* __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H */
--
2.34.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 2/5] perf intel-pt: Simplify intel_pt_get_vmcs()
2023-10-05 19:04 [PATCH 0/5] perf intel-pt: Use of get_unaligned_le16() etc Adrian Hunter
2023-10-05 19:04 ` [PATCH 1/5] perf tools: Add get_unaligned_leNN() Adrian Hunter
@ 2023-10-05 19:04 ` Adrian Hunter
2023-10-05 19:04 ` [PATCH 3/5] perf intel-pt: Use existing definitions of le16_to_cpu() etc Adrian Hunter
` (3 subsequent siblings)
5 siblings, 0 replies; 14+ messages in thread
From: Adrian Hunter @ 2023-10-05 19:04 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Jiri Olsa, Namhyung Kim, Ian Rogers, linux-kernel,
linux-perf-users
Simplify and remove unnecessary constant expressions.
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
.../util/intel-pt-decoder/intel-pt-pkt-decoder.c | 13 ++++---------
1 file changed, 4 insertions(+), 9 deletions(-)
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 af9710622a1f..249610cc9284 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
@@ -131,19 +131,14 @@ static int intel_pt_get_cbr(const unsigned char *buf, size_t len,
static int intel_pt_get_vmcs(const unsigned char *buf, size_t len,
struct intel_pt_pkt *packet)
{
- unsigned int count = (52 - 5) >> 3;
-
- if (count < 1 || count > 7)
- return INTEL_PT_BAD_PACKET;
-
- if (len < count + 2)
+ if (len < 7)
return INTEL_PT_NEED_MORE_BYTES;
packet->type = INTEL_PT_VMCS;
- packet->count = count;
- memcpy_le64(&packet->payload, buf + 2, count);
+ packet->count = 5;
+ memcpy_le64(&packet->payload, buf + 2, 5);
- return count + 2;
+ return 7;
}
static int intel_pt_get_ovf(struct intel_pt_pkt *packet)
--
2.34.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 3/5] perf intel-pt: Use existing definitions of le16_to_cpu() etc
2023-10-05 19:04 [PATCH 0/5] perf intel-pt: Use of get_unaligned_le16() etc Adrian Hunter
2023-10-05 19:04 ` [PATCH 1/5] perf tools: Add get_unaligned_leNN() Adrian Hunter
2023-10-05 19:04 ` [PATCH 2/5] perf intel-pt: Simplify intel_pt_get_vmcs() Adrian Hunter
@ 2023-10-05 19:04 ` Adrian Hunter
2023-10-05 19:04 ` [PATCH 4/5] perf intel-pt: Use get_unaligned_le16() etc Adrian Hunter
` (2 subsequent siblings)
5 siblings, 0 replies; 14+ messages in thread
From: Adrian Hunter @ 2023-10-05 19:04 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Jiri Olsa, Namhyung Kim, Ian Rogers, linux-kernel,
linux-perf-users
Use definitions from tools/include/linux/kernel.h
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
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 249610cc9284..ffd0d647473c 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
@@ -8,6 +8,7 @@
#include <string.h>
#include <endian.h>
#include <byteswap.h>
+#include <linux/kernel.h>
#include <linux/compiler.h>
#include "intel-pt-pkt-decoder.h"
@@ -17,17 +18,11 @@
#define BIT63 ((uint64_t)1 << 63)
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
-#define le16_to_cpu bswap_16
-#define le32_to_cpu bswap_32
-#define le64_to_cpu bswap_64
#define memcpy_le64(d, s, n) do { \
memcpy((d), (s), (n)); \
*(d) = le64_to_cpu(*(d)); \
} while (0)
#else
-#define le16_to_cpu
-#define le32_to_cpu
-#define le64_to_cpu
#define memcpy_le64 memcpy
#endif
--
2.34.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 4/5] perf intel-pt: Use get_unaligned_le16() etc
2023-10-05 19:04 [PATCH 0/5] perf intel-pt: Use of get_unaligned_le16() etc Adrian Hunter
` (2 preceding siblings ...)
2023-10-05 19:04 ` [PATCH 3/5] perf intel-pt: Use existing definitions of le16_to_cpu() etc Adrian Hunter
@ 2023-10-05 19:04 ` Adrian Hunter
2023-10-05 19:04 ` [PATCH 5/5] perf intel-pt: Prefer get_unaligned_le64 to memcpy_le64 Adrian Hunter
2023-10-10 14:22 ` [PATCH] perf tools: Add unaligned.h to check-headers.sh Adrian Hunter
5 siblings, 0 replies; 14+ messages in thread
From: Adrian Hunter @ 2023-10-05 19:04 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Jiri Olsa, Namhyung Kim, Ian Rogers, linux-kernel,
linux-perf-users
Avoid unaligned access by using get_unaligned_le16(), get_unaligned_le32()
and get_unaligned_le64().
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
.../intel-pt-decoder/intel-pt-pkt-decoder.c | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
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 ffd0d647473c..7a90218aecb1 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
@@ -10,6 +10,7 @@
#include <byteswap.h>
#include <linux/kernel.h>
#include <linux/compiler.h>
+#include <asm-generic/unaligned.h>
#include "intel-pt-pkt-decoder.h"
@@ -78,7 +79,7 @@ static int intel_pt_get_long_tnt(const unsigned char *buf, size_t len,
if (len < 8)
return INTEL_PT_NEED_MORE_BYTES;
- payload = le64_to_cpu(*(uint64_t *)buf);
+ payload = get_unaligned_le64(buf);
for (count = 47; count; count--) {
if (payload & BIT63)
@@ -119,7 +120,7 @@ static int intel_pt_get_cbr(const unsigned char *buf, size_t len,
if (len < 4)
return INTEL_PT_NEED_MORE_BYTES;
packet->type = INTEL_PT_CBR;
- packet->payload = le16_to_cpu(*(uint16_t *)(buf + 2));
+ packet->payload = get_unaligned_le16(buf + 2);
return 4;
}
@@ -218,12 +219,12 @@ static int intel_pt_get_ptwrite(const unsigned char *buf, size_t len,
case 0:
if (len < 6)
return INTEL_PT_NEED_MORE_BYTES;
- packet->payload = le32_to_cpu(*(uint32_t *)(buf + 2));
+ packet->payload = get_unaligned_le32(buf + 2);
return 6;
case 1:
if (len < 10)
return INTEL_PT_NEED_MORE_BYTES;
- packet->payload = le64_to_cpu(*(uint64_t *)(buf + 2));
+ packet->payload = get_unaligned_le64(buf + 2);
return 10;
default:
return INTEL_PT_BAD_PACKET;
@@ -248,7 +249,7 @@ static int intel_pt_get_mwait(const unsigned char *buf, size_t len,
if (len < 10)
return INTEL_PT_NEED_MORE_BYTES;
packet->type = INTEL_PT_MWAIT;
- packet->payload = le64_to_cpu(*(uint64_t *)(buf + 2));
+ packet->payload = get_unaligned_le64(buf + 2);
return 10;
}
@@ -455,13 +456,13 @@ static int intel_pt_get_ip(enum intel_pt_pkt_type type, unsigned int byte,
if (len < 3)
return INTEL_PT_NEED_MORE_BYTES;
ip_len = 2;
- packet->payload = le16_to_cpu(*(uint16_t *)(buf + 1));
+ packet->payload = get_unaligned_le16(buf + 1);
break;
case 2:
if (len < 5)
return INTEL_PT_NEED_MORE_BYTES;
ip_len = 4;
- packet->payload = le32_to_cpu(*(uint32_t *)(buf + 1));
+ packet->payload = get_unaligned_le32(buf + 1);
break;
case 3:
case 4:
@@ -474,7 +475,7 @@ static int intel_pt_get_ip(enum intel_pt_pkt_type type, unsigned int byte,
if (len < 9)
return INTEL_PT_NEED_MORE_BYTES;
ip_len = 8;
- packet->payload = le64_to_cpu(*(uint64_t *)(buf + 1));
+ packet->payload = get_unaligned_le64(buf + 1);
break;
default:
return INTEL_PT_BAD_PACKET;
--
2.34.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 5/5] perf intel-pt: Prefer get_unaligned_le64 to memcpy_le64
2023-10-05 19:04 [PATCH 0/5] perf intel-pt: Use of get_unaligned_le16() etc Adrian Hunter
` (3 preceding siblings ...)
2023-10-05 19:04 ` [PATCH 4/5] perf intel-pt: Use get_unaligned_le16() etc Adrian Hunter
@ 2023-10-05 19:04 ` Adrian Hunter
2023-10-10 14:22 ` [PATCH] perf tools: Add unaligned.h to check-headers.sh Adrian Hunter
5 siblings, 0 replies; 14+ messages in thread
From: Adrian Hunter @ 2023-10-05 19:04 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Jiri Olsa, Namhyung Kim, Ian Rogers, linux-kernel,
linux-perf-users
Use get_unaligned_le64() instead of memcpy_le64(..., 8) because it produces
simpler code.
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
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 7a90218aecb1..bccb988a7a44 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
@@ -190,7 +190,7 @@ static int intel_pt_get_mnt(const unsigned char *buf, size_t len,
if (len < 11)
return INTEL_PT_NEED_MORE_BYTES;
packet->type = INTEL_PT_MNT;
- memcpy_le64(&packet->payload, buf + 3, 8);
+ packet->payload = get_unaligned_le64(buf + 3);
return 11;
}
@@ -302,7 +302,7 @@ static int intel_pt_get_bip_8(const unsigned char *buf, size_t len,
return INTEL_PT_NEED_MORE_BYTES;
packet->type = INTEL_PT_BIP;
packet->count = buf[0] >> 3;
- memcpy_le64(&packet->payload, buf + 1, 8);
+ packet->payload = get_unaligned_le64(buf + 1);
return 9;
}
@@ -341,7 +341,7 @@ static int intel_pt_get_evd(const unsigned char *buf, size_t len,
packet->type = INTEL_PT_EVD;
packet->count = buf[2] & 0x3f;
packet->payload = buf[3];
- memcpy_le64(&packet->payload, buf + 3, 8);
+ packet->payload = get_unaligned_le64(buf + 3);
return 11;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH 1/5] perf tools: Add get_unaligned_leNN()
2023-10-05 19:04 ` [PATCH 1/5] perf tools: Add get_unaligned_leNN() Adrian Hunter
@ 2023-10-05 19:38 ` Arnaldo Carvalho de Melo
2023-10-10 14:29 ` Adrian Hunter
2023-10-26 13:44 ` Arnaldo Carvalho de Melo
0 siblings, 2 replies; 14+ messages in thread
From: Arnaldo Carvalho de Melo @ 2023-10-05 19:38 UTC (permalink / raw)
To: Adrian Hunter
Cc: Jiri Olsa, Namhyung Kim, Ian Rogers, linux-kernel,
linux-perf-users
Em Thu, Oct 05, 2023 at 10:04:47PM +0300, Adrian Hunter escreveu:
> Add get_unaligned_le16(), get_unaligned_le32 and get_unaligned_le64, same
> as include/asm-generic/unaligned.h.
>
> Use diagnostic pragmas to ignore -Wpacked used by perf build.
Can we get the tools copy of include/asm-generic/unaligned.h closer and
have it in check-headers.sh?
- Arnaldo
> Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
> ---
> tools/include/asm-generic/unaligned.h | 20 ++++++++++++++++++++
> 1 file changed, 20 insertions(+)
>
> diff --git a/tools/include/asm-generic/unaligned.h b/tools/include/asm-generic/unaligned.h
> index 47387c607035..9140bb4e16c6 100644
> --- a/tools/include/asm-generic/unaligned.h
> +++ b/tools/include/asm-generic/unaligned.h
> @@ -6,6 +6,9 @@
> #ifndef __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H
> #define __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H
>
> +#pragma GCC diagnostic push
> +#pragma GCC diagnostic ignored "-Wpacked"
> +
> #define __get_unaligned_t(type, ptr) ({ \
> const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr); \
> __pptr->x; \
> @@ -19,5 +22,22 @@
> #define get_unaligned(ptr) __get_unaligned_t(typeof(*(ptr)), (ptr))
> #define put_unaligned(val, ptr) __put_unaligned_t(typeof(*(ptr)), (val), (ptr))
>
> +static inline u16 get_unaligned_le16(const void *p)
> +{
> + return le16_to_cpu(__get_unaligned_t(__le16, p));
> +}
> +
> +static inline u32 get_unaligned_le32(const void *p)
> +{
> + return le32_to_cpu(__get_unaligned_t(__le32, p));
> +}
> +
> +static inline u64 get_unaligned_le64(const void *p)
> +{
> + return le64_to_cpu(__get_unaligned_t(__le64, p));
> +}
> +
> +#pragma GCC diagnostic pop
> +
> #endif /* __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H */
>
> --
> 2.34.1
>
--
- Arnaldo
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH] perf tools: Add unaligned.h to check-headers.sh
2023-10-05 19:04 [PATCH 0/5] perf intel-pt: Use of get_unaligned_le16() etc Adrian Hunter
` (4 preceding siblings ...)
2023-10-05 19:04 ` [PATCH 5/5] perf intel-pt: Prefer get_unaligned_le64 to memcpy_le64 Adrian Hunter
@ 2023-10-10 14:22 ` Adrian Hunter
2023-10-10 15:28 ` Ian Rogers
5 siblings, 1 reply; 14+ messages in thread
From: Adrian Hunter @ 2023-10-10 14:22 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Jiri Olsa, Namhyung Kim, Ian Rogers, linux-kernel,
linux-perf-users
Add include/asm-generic/unaligned.h to check-headers.sh bringing
tools/include/asm-generic/unaligned.h up to date so that the kernel and
tools versions match.
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
Based on top of 5 patch set "perf intel-pt: Use of get_unaligned_le16() etc"
tools/include/asm-generic/unaligned.h | 129 ++++++++++++++++++++++++--
| 1 +
2 files changed, 122 insertions(+), 8 deletions(-)
diff --git a/tools/include/asm-generic/unaligned.h b/tools/include/asm-generic/unaligned.h
index 9140bb4e16c6..156743d399ae 100644
--- a/tools/include/asm-generic/unaligned.h
+++ b/tools/include/asm-generic/unaligned.h
@@ -1,11 +1,11 @@
-/* SPDX-License-Identifier: GPL-2.0-or-later */
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __ASM_GENERIC_UNALIGNED_H
+#define __ASM_GENERIC_UNALIGNED_H
+
/*
- * Copied from the kernel sources to tools/perf/:
+ * This is the most generic implementation of unaligned accesses
+ * and should work almost anywhere.
*/
-
-#ifndef __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H
-#define __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H
-
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpacked"
@@ -37,7 +37,120 @@ static inline u64 get_unaligned_le64(const void *p)
return le64_to_cpu(__get_unaligned_t(__le64, p));
}
-#pragma GCC diagnostic pop
+static inline void put_unaligned_le16(u16 val, void *p)
+{
+ __put_unaligned_t(__le16, cpu_to_le16(val), p);
+}
+
+static inline void put_unaligned_le32(u32 val, void *p)
+{
+ __put_unaligned_t(__le32, cpu_to_le32(val), p);
+}
+
+static inline void put_unaligned_le64(u64 val, void *p)
+{
+ __put_unaligned_t(__le64, cpu_to_le64(val), p);
+}
+
+static inline u16 get_unaligned_be16(const void *p)
+{
+ return be16_to_cpu(__get_unaligned_t(__be16, p));
+}
+
+static inline u32 get_unaligned_be32(const void *p)
+{
+ return be32_to_cpu(__get_unaligned_t(__be32, p));
+}
+
+static inline u64 get_unaligned_be64(const void *p)
+{
+ return be64_to_cpu(__get_unaligned_t(__be64, p));
+}
+
+static inline void put_unaligned_be16(u16 val, void *p)
+{
+ __put_unaligned_t(__be16, cpu_to_be16(val), p);
+}
+
+static inline void put_unaligned_be32(u32 val, void *p)
+{
+ __put_unaligned_t(__be32, cpu_to_be32(val), p);
+}
+
+static inline void put_unaligned_be64(u64 val, void *p)
+{
+ __put_unaligned_t(__be64, cpu_to_be64(val), p);
+}
+
+static inline u32 __get_unaligned_be24(const u8 *p)
+{
+ return p[0] << 16 | p[1] << 8 | p[2];
+}
-#endif /* __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H */
+static inline u32 get_unaligned_be24(const void *p)
+{
+ return __get_unaligned_be24(p);
+}
+
+static inline u32 __get_unaligned_le24(const u8 *p)
+{
+ return p[0] | p[1] << 8 | p[2] << 16;
+}
+
+static inline u32 get_unaligned_le24(const void *p)
+{
+ return __get_unaligned_le24(p);
+}
+
+static inline void __put_unaligned_be24(const u32 val, u8 *p)
+{
+ *p++ = val >> 16;
+ *p++ = val >> 8;
+ *p++ = val;
+}
+
+static inline void put_unaligned_be24(const u32 val, void *p)
+{
+ __put_unaligned_be24(val, p);
+}
+
+static inline void __put_unaligned_le24(const u32 val, u8 *p)
+{
+ *p++ = val;
+ *p++ = val >> 8;
+ *p++ = val >> 16;
+}
+
+static inline void put_unaligned_le24(const u32 val, void *p)
+{
+ __put_unaligned_le24(val, p);
+}
+
+static inline void __put_unaligned_be48(const u64 val, u8 *p)
+{
+ *p++ = val >> 40;
+ *p++ = val >> 32;
+ *p++ = val >> 24;
+ *p++ = val >> 16;
+ *p++ = val >> 8;
+ *p++ = val;
+}
+
+static inline void put_unaligned_be48(const u64 val, void *p)
+{
+ __put_unaligned_be48(val, p);
+}
+
+static inline u64 __get_unaligned_be48(const u8 *p)
+{
+ return (u64)p[0] << 40 | (u64)p[1] << 32 | (u64)p[2] << 24 |
+ p[3] << 16 | p[4] << 8 | p[5];
+}
+
+static inline u64 get_unaligned_be48(const void *p)
+{
+ return __get_unaligned_be48(p);
+}
+#pragma GCC diagnostic pop
+#endif /* __ASM_GENERIC_UNALIGNED_H */
--git a/tools/perf/check-headers.sh b/tools/perf/check-headers.sh
index 4314c9197850..d09c3d46f08f 100755
--- a/tools/perf/check-headers.sh
+++ b/tools/perf/check-headers.sh
@@ -161,6 +161,7 @@ check arch/x86/lib/memcpy_64.S '-I "^EXPORT_SYMBOL" -I "^#include <asm/ex
check arch/x86/lib/memset_64.S '-I "^EXPORT_SYMBOL" -I "^#include <asm/export.h>" -I"^SYM_FUNC_START\(_LOCAL\)*(memset_\(erms\|orig\))"'
check arch/x86/include/asm/amd-ibs.h '-I "^#include [<\"]\(asm/\)*msr-index.h"'
check arch/arm64/include/asm/cputype.h '-I "^#include [<\"]\(asm/\)*sysreg.h"'
+check include/asm-generic/unaligned.h '-I "^#include <linux/unaligned/packed_struct.h>" -I "^#include <asm/byteorder.h>" -I "^#pragma GCC diagnostic"'
check include/uapi/asm-generic/mman.h '-I "^#include <\(uapi/\)*asm-generic/mman-common\(-tools\)*.h>"'
check include/uapi/linux/mman.h '-I "^#include <\(uapi/\)*asm/mman.h>"'
check include/linux/build_bug.h '-I "^#\(ifndef\|endif\)\( \/\/\)* static_assert$"'
--
2.34.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH 1/5] perf tools: Add get_unaligned_leNN()
2023-10-05 19:38 ` Arnaldo Carvalho de Melo
@ 2023-10-10 14:29 ` Adrian Hunter
2023-10-26 13:44 ` Arnaldo Carvalho de Melo
1 sibling, 0 replies; 14+ messages in thread
From: Adrian Hunter @ 2023-10-10 14:29 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Jiri Olsa, Namhyung Kim, Ian Rogers, linux-kernel,
linux-perf-users
On 5/10/23 22:38, Arnaldo Carvalho de Melo wrote:
> Em Thu, Oct 05, 2023 at 10:04:47PM +0300, Adrian Hunter escreveu:
>> Add get_unaligned_le16(), get_unaligned_le32 and get_unaligned_le64, same
>> as include/asm-generic/unaligned.h.
>>
>> Use diagnostic pragmas to ignore -Wpacked used by perf build.
>
> Can we get the tools copy of include/asm-generic/unaligned.h closer and
> have it in check-headers.sh?
I sent another patch for that
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH] perf tools: Add unaligned.h to check-headers.sh
2023-10-10 14:22 ` [PATCH] perf tools: Add unaligned.h to check-headers.sh Adrian Hunter
@ 2023-10-10 15:28 ` Ian Rogers
0 siblings, 0 replies; 14+ messages in thread
From: Ian Rogers @ 2023-10-10 15:28 UTC (permalink / raw)
To: Adrian Hunter
Cc: Arnaldo Carvalho de Melo, Jiri Olsa, Namhyung Kim, linux-kernel,
linux-perf-users
On Tue, Oct 10, 2023 at 7:22 AM Adrian Hunter <adrian.hunter@intel.com> wrote:
>
> Add include/asm-generic/unaligned.h to check-headers.sh bringing
> tools/include/asm-generic/unaligned.h up to date so that the kernel and
> tools versions match.
>
> Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Reviewed-by: Ian Rogers <irogers@google.com>
Thanks,
Ian
> ---
>
>
> Based on top of 5 patch set "perf intel-pt: Use of get_unaligned_le16() etc"
>
>
> tools/include/asm-generic/unaligned.h | 129 ++++++++++++++++++++++++--
> tools/perf/check-headers.sh | 1 +
> 2 files changed, 122 insertions(+), 8 deletions(-)
>
> diff --git a/tools/include/asm-generic/unaligned.h b/tools/include/asm-generic/unaligned.h
> index 9140bb4e16c6..156743d399ae 100644
> --- a/tools/include/asm-generic/unaligned.h
> +++ b/tools/include/asm-generic/unaligned.h
> @@ -1,11 +1,11 @@
> -/* SPDX-License-Identifier: GPL-2.0-or-later */
> +/* SPDX-License-Identifier: GPL-2.0 */
> +#ifndef __ASM_GENERIC_UNALIGNED_H
> +#define __ASM_GENERIC_UNALIGNED_H
> +
> /*
> - * Copied from the kernel sources to tools/perf/:
> + * This is the most generic implementation of unaligned accesses
> + * and should work almost anywhere.
> */
> -
> -#ifndef __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H
> -#define __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H
> -
> #pragma GCC diagnostic push
> #pragma GCC diagnostic ignored "-Wpacked"
>
> @@ -37,7 +37,120 @@ static inline u64 get_unaligned_le64(const void *p)
> return le64_to_cpu(__get_unaligned_t(__le64, p));
> }
>
> -#pragma GCC diagnostic pop
> +static inline void put_unaligned_le16(u16 val, void *p)
> +{
> + __put_unaligned_t(__le16, cpu_to_le16(val), p);
> +}
> +
> +static inline void put_unaligned_le32(u32 val, void *p)
> +{
> + __put_unaligned_t(__le32, cpu_to_le32(val), p);
> +}
> +
> +static inline void put_unaligned_le64(u64 val, void *p)
> +{
> + __put_unaligned_t(__le64, cpu_to_le64(val), p);
> +}
> +
> +static inline u16 get_unaligned_be16(const void *p)
> +{
> + return be16_to_cpu(__get_unaligned_t(__be16, p));
> +}
> +
> +static inline u32 get_unaligned_be32(const void *p)
> +{
> + return be32_to_cpu(__get_unaligned_t(__be32, p));
> +}
> +
> +static inline u64 get_unaligned_be64(const void *p)
> +{
> + return be64_to_cpu(__get_unaligned_t(__be64, p));
> +}
> +
> +static inline void put_unaligned_be16(u16 val, void *p)
> +{
> + __put_unaligned_t(__be16, cpu_to_be16(val), p);
> +}
> +
> +static inline void put_unaligned_be32(u32 val, void *p)
> +{
> + __put_unaligned_t(__be32, cpu_to_be32(val), p);
> +}
> +
> +static inline void put_unaligned_be64(u64 val, void *p)
> +{
> + __put_unaligned_t(__be64, cpu_to_be64(val), p);
> +}
> +
> +static inline u32 __get_unaligned_be24(const u8 *p)
> +{
> + return p[0] << 16 | p[1] << 8 | p[2];
> +}
>
> -#endif /* __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H */
> +static inline u32 get_unaligned_be24(const void *p)
> +{
> + return __get_unaligned_be24(p);
> +}
> +
> +static inline u32 __get_unaligned_le24(const u8 *p)
> +{
> + return p[0] | p[1] << 8 | p[2] << 16;
> +}
> +
> +static inline u32 get_unaligned_le24(const void *p)
> +{
> + return __get_unaligned_le24(p);
> +}
> +
> +static inline void __put_unaligned_be24(const u32 val, u8 *p)
> +{
> + *p++ = val >> 16;
> + *p++ = val >> 8;
> + *p++ = val;
> +}
> +
> +static inline void put_unaligned_be24(const u32 val, void *p)
> +{
> + __put_unaligned_be24(val, p);
> +}
> +
> +static inline void __put_unaligned_le24(const u32 val, u8 *p)
> +{
> + *p++ = val;
> + *p++ = val >> 8;
> + *p++ = val >> 16;
> +}
> +
> +static inline void put_unaligned_le24(const u32 val, void *p)
> +{
> + __put_unaligned_le24(val, p);
> +}
> +
> +static inline void __put_unaligned_be48(const u64 val, u8 *p)
> +{
> + *p++ = val >> 40;
> + *p++ = val >> 32;
> + *p++ = val >> 24;
> + *p++ = val >> 16;
> + *p++ = val >> 8;
> + *p++ = val;
> +}
> +
> +static inline void put_unaligned_be48(const u64 val, void *p)
> +{
> + __put_unaligned_be48(val, p);
> +}
> +
> +static inline u64 __get_unaligned_be48(const u8 *p)
> +{
> + return (u64)p[0] << 40 | (u64)p[1] << 32 | (u64)p[2] << 24 |
> + p[3] << 16 | p[4] << 8 | p[5];
> +}
> +
> +static inline u64 get_unaligned_be48(const void *p)
> +{
> + return __get_unaligned_be48(p);
> +}
> +#pragma GCC diagnostic pop
>
> +#endif /* __ASM_GENERIC_UNALIGNED_H */
> diff --git a/tools/perf/check-headers.sh b/tools/perf/check-headers.sh
> index 4314c9197850..d09c3d46f08f 100755
> --- a/tools/perf/check-headers.sh
> +++ b/tools/perf/check-headers.sh
> @@ -161,6 +161,7 @@ check arch/x86/lib/memcpy_64.S '-I "^EXPORT_SYMBOL" -I "^#include <asm/ex
> check arch/x86/lib/memset_64.S '-I "^EXPORT_SYMBOL" -I "^#include <asm/export.h>" -I"^SYM_FUNC_START\(_LOCAL\)*(memset_\(erms\|orig\))"'
> check arch/x86/include/asm/amd-ibs.h '-I "^#include [<\"]\(asm/\)*msr-index.h"'
> check arch/arm64/include/asm/cputype.h '-I "^#include [<\"]\(asm/\)*sysreg.h"'
> +check include/asm-generic/unaligned.h '-I "^#include <linux/unaligned/packed_struct.h>" -I "^#include <asm/byteorder.h>" -I "^#pragma GCC diagnostic"'
> check include/uapi/asm-generic/mman.h '-I "^#include <\(uapi/\)*asm-generic/mman-common\(-tools\)*.h>"'
> check include/uapi/linux/mman.h '-I "^#include <\(uapi/\)*asm/mman.h>"'
> check include/linux/build_bug.h '-I "^#\(ifndef\|endif\)\( \/\/\)* static_assert$"'
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 1/5] perf tools: Add get_unaligned_leNN()
2023-10-05 19:38 ` Arnaldo Carvalho de Melo
2023-10-10 14:29 ` Adrian Hunter
@ 2023-10-26 13:44 ` Arnaldo Carvalho de Melo
2023-10-26 16:09 ` Adrian Hunter
1 sibling, 1 reply; 14+ messages in thread
From: Arnaldo Carvalho de Melo @ 2023-10-26 13:44 UTC (permalink / raw)
To: Adrian Hunter
Cc: Jiri Olsa, Namhyung Kim, Ian Rogers, linux-kernel,
linux-perf-users
Em Thu, Oct 05, 2023 at 04:38:05PM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Thu, Oct 05, 2023 at 10:04:47PM +0300, Adrian Hunter escreveu:
> > Add get_unaligned_le16(), get_unaligned_le32 and get_unaligned_le64, same
> > as include/asm-generic/unaligned.h.
> >
> > Use diagnostic pragmas to ignore -Wpacked used by perf build.
>
> Can we get the tools copy of include/asm-generic/unaligned.h closer and
> have it in check-headers.sh?
And this is not building when cross building to mips, mips64 and mipsel
on debian:experimental:
In file included from util/intel-pt-decoder/intel-pt-pkt-decoder.c:10:
/git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h: In function 'get_unaligned_le16':
/git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h:13:29: error: packed attribute causes inefficient alignment for 'x' [-Werror=attributes]
13 | const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr); \
| ^
/git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h:27:28: note: in expansion of macro '__get_unaligned_t'
27 | return le16_to_cpu(__get_unaligned_t(__le16, p));
| ^~~~~~~~~~~~~~~~~
/git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h: In function 'get_unaligned_le32':
/git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h:13:29: error: packed attribute causes inefficient alignment for 'x' [-Werror=attributes]
13 | const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr); \
| ^
/git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h:32:28: note: in expansion of macro '__get_unaligned_t'
32 | return le32_to_cpu(__get_unaligned_t(__le32, p));
| ^~~~~~~~~~~~~~~~~
Ditto for some other distros when cross building on ubuntu:18.04
MKDIR /tmp/build/perf/util/perf-regs-arch/
In file included from /usr/sparc64-linux-gnu/include/bits/byteswap.h:34:0,
from /usr/sparc64-linux-gnu/include/endian.h:60,
from util/intel-pt-decoder/intel-pt-pkt-decoder.c:9:
/git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h: In function 'get_unaligned_le16':
/git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h:13:22: error: packed attribute causes inefficient alignment for 'x' [-Werror=attributes]
const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr); \
^
/git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h:27:21: note: in expansion of macro '__get_unaligned_t'
return le16_to_cpu(__get_unaligned_t(__le16, p));
^~~~~~~~~~~~~~~~~
37 14.17 ubuntu:18.04-x-arm : FAIL gcc version 7.5.0 (Ubuntu/Linaro 7.5.0-3ubuntu1~18.04)
38 13.56 ubuntu:18.04-x-arm64 : FAIL gcc version 7.5.0 (Ubuntu/Linaro 7.5.0-3ubuntu1~18.04)
42 12.70 ubuntu:18.04-x-riscv64 : FAIL gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)
44 13.95 ubuntu:18.04-x-sh4 : FAIL gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)
45 13.08 ubuntu:18.04-x-sparc64 : FAIL gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)
> - Arnaldo
>
> > Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
> > ---
> > tools/include/asm-generic/unaligned.h | 20 ++++++++++++++++++++
> > 1 file changed, 20 insertions(+)
> >
> > diff --git a/tools/include/asm-generic/unaligned.h b/tools/include/asm-generic/unaligned.h
> > index 47387c607035..9140bb4e16c6 100644
> > --- a/tools/include/asm-generic/unaligned.h
> > +++ b/tools/include/asm-generic/unaligned.h
> > @@ -6,6 +6,9 @@
> > #ifndef __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H
> > #define __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H
> >
> > +#pragma GCC diagnostic push
> > +#pragma GCC diagnostic ignored "-Wpacked"
> > +
> > #define __get_unaligned_t(type, ptr) ({ \
> > const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr); \
> > __pptr->x; \
> > @@ -19,5 +22,22 @@
> > #define get_unaligned(ptr) __get_unaligned_t(typeof(*(ptr)), (ptr))
> > #define put_unaligned(val, ptr) __put_unaligned_t(typeof(*(ptr)), (val), (ptr))
> >
> > +static inline u16 get_unaligned_le16(const void *p)
> > +{
> > + return le16_to_cpu(__get_unaligned_t(__le16, p));
> > +}
> > +
> > +static inline u32 get_unaligned_le32(const void *p)
> > +{
> > + return le32_to_cpu(__get_unaligned_t(__le32, p));
> > +}
> > +
> > +static inline u64 get_unaligned_le64(const void *p)
> > +{
> > + return le64_to_cpu(__get_unaligned_t(__le64, p));
> > +}
> > +
> > +#pragma GCC diagnostic pop
> > +
> > #endif /* __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H */
> >
> > --
> > 2.34.1
> >
>
> --
>
> - Arnaldo
--
- Arnaldo
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 1/5] perf tools: Add get_unaligned_leNN()
2023-10-26 13:44 ` Arnaldo Carvalho de Melo
@ 2023-10-26 16:09 ` Adrian Hunter
2023-10-26 20:08 ` Arnaldo Carvalho de Melo
2023-11-09 19:34 ` Arnaldo Carvalho de Melo
0 siblings, 2 replies; 14+ messages in thread
From: Adrian Hunter @ 2023-10-26 16:09 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Jiri Olsa, Namhyung Kim, Ian Rogers, linux-kernel,
linux-perf-users
On 26/10/23 16:44, Arnaldo Carvalho de Melo wrote:
> Em Thu, Oct 05, 2023 at 04:38:05PM -0300, Arnaldo Carvalho de Melo escreveu:
>> Em Thu, Oct 05, 2023 at 10:04:47PM +0300, Adrian Hunter escreveu:
>>> Add get_unaligned_le16(), get_unaligned_le32 and get_unaligned_le64, same
>>> as include/asm-generic/unaligned.h.
>>>
>>> Use diagnostic pragmas to ignore -Wpacked used by perf build.
>>
>> Can we get the tools copy of include/asm-generic/unaligned.h closer and
>> have it in check-headers.sh?
>
> And this is not building when cross building to mips, mips64 and mipsel
> on debian:experimental:
>
> In file included from util/intel-pt-decoder/intel-pt-pkt-decoder.c:10:
> /git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h: In function 'get_unaligned_le16':
> /git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h:13:29: error: packed attribute causes inefficient alignment for 'x' [-Werror=attributes]
So I guess another diagnostic pragma is needed, perhaps the following works?
#pragma GCC diagnostic ignored "-Wattributes"
> 13 | const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr); \
> | ^
> /git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h:27:28: note: in expansion of macro '__get_unaligned_t'
> 27 | return le16_to_cpu(__get_unaligned_t(__le16, p));
> | ^~~~~~~~~~~~~~~~~
> /git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h: In function 'get_unaligned_le32':
> /git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h:13:29: error: packed attribute causes inefficient alignment for 'x' [-Werror=attributes]
> 13 | const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr); \
> | ^
> /git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h:32:28: note: in expansion of macro '__get_unaligned_t'
> 32 | return le32_to_cpu(__get_unaligned_t(__le32, p));
> | ^~~~~~~~~~~~~~~~~
>
>
> Ditto for some other distros when cross building on ubuntu:18.04
>
> MKDIR /tmp/build/perf/util/perf-regs-arch/
> In file included from /usr/sparc64-linux-gnu/include/bits/byteswap.h:34:0,
> from /usr/sparc64-linux-gnu/include/endian.h:60,
> from util/intel-pt-decoder/intel-pt-pkt-decoder.c:9:
> /git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h: In function 'get_unaligned_le16':
> /git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h:13:22: error: packed attribute causes inefficient alignment for 'x' [-Werror=attributes]
> const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr); \
> ^
> /git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h:27:21: note: in expansion of macro '__get_unaligned_t'
> return le16_to_cpu(__get_unaligned_t(__le16, p));
> ^~~~~~~~~~~~~~~~~
>
> 37 14.17 ubuntu:18.04-x-arm : FAIL gcc version 7.5.0 (Ubuntu/Linaro 7.5.0-3ubuntu1~18.04)
> 38 13.56 ubuntu:18.04-x-arm64 : FAIL gcc version 7.5.0 (Ubuntu/Linaro 7.5.0-3ubuntu1~18.04)
> 42 12.70 ubuntu:18.04-x-riscv64 : FAIL gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)
> 44 13.95 ubuntu:18.04-x-sh4 : FAIL gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)
> 45 13.08 ubuntu:18.04-x-sparc64 : FAIL gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)
>
>> - Arnaldo
>>
>>> Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
>>> ---
>>> tools/include/asm-generic/unaligned.h | 20 ++++++++++++++++++++
>>> 1 file changed, 20 insertions(+)
>>>
>>> diff --git a/tools/include/asm-generic/unaligned.h b/tools/include/asm-generic/unaligned.h
>>> index 47387c607035..9140bb4e16c6 100644
>>> --- a/tools/include/asm-generic/unaligned.h
>>> +++ b/tools/include/asm-generic/unaligned.h
>>> @@ -6,6 +6,9 @@
>>> #ifndef __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H
>>> #define __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H
>>>
>>> +#pragma GCC diagnostic push
>>> +#pragma GCC diagnostic ignored "-Wpacked"
>>> +
>>> #define __get_unaligned_t(type, ptr) ({ \
>>> const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr); \
>>> __pptr->x; \
>>> @@ -19,5 +22,22 @@
>>> #define get_unaligned(ptr) __get_unaligned_t(typeof(*(ptr)), (ptr))
>>> #define put_unaligned(val, ptr) __put_unaligned_t(typeof(*(ptr)), (val), (ptr))
>>>
>>> +static inline u16 get_unaligned_le16(const void *p)
>>> +{
>>> + return le16_to_cpu(__get_unaligned_t(__le16, p));
>>> +}
>>> +
>>> +static inline u32 get_unaligned_le32(const void *p)
>>> +{
>>> + return le32_to_cpu(__get_unaligned_t(__le32, p));
>>> +}
>>> +
>>> +static inline u64 get_unaligned_le64(const void *p)
>>> +{
>>> + return le64_to_cpu(__get_unaligned_t(__le64, p));
>>> +}
>>> +
>>> +#pragma GCC diagnostic pop
>>> +
>>> #endif /* __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H */
>>>
>>> --
>>> 2.34.1
>>>
>>
>> --
>>
>> - Arnaldo
>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 1/5] perf tools: Add get_unaligned_leNN()
2023-10-26 16:09 ` Adrian Hunter
@ 2023-10-26 20:08 ` Arnaldo Carvalho de Melo
2023-11-09 19:34 ` Arnaldo Carvalho de Melo
1 sibling, 0 replies; 14+ messages in thread
From: Arnaldo Carvalho de Melo @ 2023-10-26 20:08 UTC (permalink / raw)
To: Adrian Hunter
Cc: Jiri Olsa, Namhyung Kim, Ian Rogers, linux-kernel,
linux-perf-users
Em Thu, Oct 26, 2023 at 07:09:26PM +0300, Adrian Hunter escreveu:
> On 26/10/23 16:44, Arnaldo Carvalho de Melo wrote:
> > Em Thu, Oct 05, 2023 at 04:38:05PM -0300, Arnaldo Carvalho de Melo escreveu:
> >> Em Thu, Oct 05, 2023 at 10:04:47PM +0300, Adrian Hunter escreveu:
> >>> Add get_unaligned_le16(), get_unaligned_le32 and get_unaligned_le64, same
> >>> as include/asm-generic/unaligned.h.
> >>>
> >>> Use diagnostic pragmas to ignore -Wpacked used by perf build.
> >>
> >> Can we get the tools copy of include/asm-generic/unaligned.h closer and
> >> have it in check-headers.sh?
> >
> > And this is not building when cross building to mips, mips64 and mipsel
> > on debian:experimental:
> >
> > In file included from util/intel-pt-decoder/intel-pt-pkt-decoder.c:10:
> > /git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h: In function 'get_unaligned_le16':
> > /git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h:13:29: error: packed attribute causes inefficient alignment for 'x' [-Werror=attributes]
>
> So I guess another diagnostic pragma is needed, perhaps the following works?
>
> #pragma GCC diagnostic ignored "-Wattributes"
I'll try it.
- Arnaldo
>
> > 13 | const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr); \
> > | ^
> > /git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h:27:28: note: in expansion of macro '__get_unaligned_t'
> > 27 | return le16_to_cpu(__get_unaligned_t(__le16, p));
> > | ^~~~~~~~~~~~~~~~~
> > /git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h: In function 'get_unaligned_le32':
> > /git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h:13:29: error: packed attribute causes inefficient alignment for 'x' [-Werror=attributes]
> > 13 | const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr); \
> > | ^
> > /git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h:32:28: note: in expansion of macro '__get_unaligned_t'
> > 32 | return le32_to_cpu(__get_unaligned_t(__le32, p));
> > | ^~~~~~~~~~~~~~~~~
> >
> >
> > Ditto for some other distros when cross building on ubuntu:18.04
> >
> > MKDIR /tmp/build/perf/util/perf-regs-arch/
> > In file included from /usr/sparc64-linux-gnu/include/bits/byteswap.h:34:0,
> > from /usr/sparc64-linux-gnu/include/endian.h:60,
> > from util/intel-pt-decoder/intel-pt-pkt-decoder.c:9:
> > /git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h: In function 'get_unaligned_le16':
> > /git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h:13:22: error: packed attribute causes inefficient alignment for 'x' [-Werror=attributes]
> > const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr); \
> > ^
> > /git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h:27:21: note: in expansion of macro '__get_unaligned_t'
> > return le16_to_cpu(__get_unaligned_t(__le16, p));
> > ^~~~~~~~~~~~~~~~~
> >
> > 37 14.17 ubuntu:18.04-x-arm : FAIL gcc version 7.5.0 (Ubuntu/Linaro 7.5.0-3ubuntu1~18.04)
> > 38 13.56 ubuntu:18.04-x-arm64 : FAIL gcc version 7.5.0 (Ubuntu/Linaro 7.5.0-3ubuntu1~18.04)
> > 42 12.70 ubuntu:18.04-x-riscv64 : FAIL gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)
> > 44 13.95 ubuntu:18.04-x-sh4 : FAIL gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)
> > 45 13.08 ubuntu:18.04-x-sparc64 : FAIL gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)
> >
> >> - Arnaldo
> >>
> >>> Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
> >>> ---
> >>> tools/include/asm-generic/unaligned.h | 20 ++++++++++++++++++++
> >>> 1 file changed, 20 insertions(+)
> >>>
> >>> diff --git a/tools/include/asm-generic/unaligned.h b/tools/include/asm-generic/unaligned.h
> >>> index 47387c607035..9140bb4e16c6 100644
> >>> --- a/tools/include/asm-generic/unaligned.h
> >>> +++ b/tools/include/asm-generic/unaligned.h
> >>> @@ -6,6 +6,9 @@
> >>> #ifndef __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H
> >>> #define __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H
> >>>
> >>> +#pragma GCC diagnostic push
> >>> +#pragma GCC diagnostic ignored "-Wpacked"
> >>> +
> >>> #define __get_unaligned_t(type, ptr) ({ \
> >>> const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr); \
> >>> __pptr->x; \
> >>> @@ -19,5 +22,22 @@
> >>> #define get_unaligned(ptr) __get_unaligned_t(typeof(*(ptr)), (ptr))
> >>> #define put_unaligned(val, ptr) __put_unaligned_t(typeof(*(ptr)), (val), (ptr))
> >>>
> >>> +static inline u16 get_unaligned_le16(const void *p)
> >>> +{
> >>> + return le16_to_cpu(__get_unaligned_t(__le16, p));
> >>> +}
> >>> +
> >>> +static inline u32 get_unaligned_le32(const void *p)
> >>> +{
> >>> + return le32_to_cpu(__get_unaligned_t(__le32, p));
> >>> +}
> >>> +
> >>> +static inline u64 get_unaligned_le64(const void *p)
> >>> +{
> >>> + return le64_to_cpu(__get_unaligned_t(__le64, p));
> >>> +}
> >>> +
> >>> +#pragma GCC diagnostic pop
> >>> +
> >>> #endif /* __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H */
> >>>
> >>> --
> >>> 2.34.1
> >>>
> >>
> >> --
> >>
> >> - Arnaldo
> >
>
--
- Arnaldo
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 1/5] perf tools: Add get_unaligned_leNN()
2023-10-26 16:09 ` Adrian Hunter
2023-10-26 20:08 ` Arnaldo Carvalho de Melo
@ 2023-11-09 19:34 ` Arnaldo Carvalho de Melo
1 sibling, 0 replies; 14+ messages in thread
From: Arnaldo Carvalho de Melo @ 2023-11-09 19:34 UTC (permalink / raw)
To: Adrian Hunter
Cc: Jiri Olsa, Namhyung Kim, Ian Rogers, linux-kernel,
linux-perf-users
Em Thu, Oct 26, 2023 at 07:09:26PM +0300, Adrian Hunter escreveu:
> On 26/10/23 16:44, Arnaldo Carvalho de Melo wrote:
> > Em Thu, Oct 05, 2023 at 04:38:05PM -0300, Arnaldo Carvalho de Melo escreveu:
> >> Em Thu, Oct 05, 2023 at 10:04:47PM +0300, Adrian Hunter escreveu:
> >>> Add get_unaligned_le16(), get_unaligned_le32 and get_unaligned_le64, same
> >>> as include/asm-generic/unaligned.h.
> >>>
> >>> Use diagnostic pragmas to ignore -Wpacked used by perf build.
> >>
> >> Can we get the tools copy of include/asm-generic/unaligned.h closer and
> >> have it in check-headers.sh?
> >
> > And this is not building when cross building to mips, mips64 and mipsel
> > on debian:experimental:
> >
> > In file included from util/intel-pt-decoder/intel-pt-pkt-decoder.c:10:
> > /git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h: In function 'get_unaligned_le16':
> > /git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h:13:29: error: packed attribute causes inefficient alignment for 'x' [-Werror=attributes]
>
> So I guess another diagnostic pragma is needed, perhaps the following works?
>
> #pragma GCC diagnostic ignored "-Wattributes"
Yeah, I tested with this and it works, I'll add a patch with your
Suggested-by, ok?
- Arnaldo
>
> > 13 | const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr); \
> > | ^
> > /git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h:27:28: note: in expansion of macro '__get_unaligned_t'
> > 27 | return le16_to_cpu(__get_unaligned_t(__le16, p));
> > | ^~~~~~~~~~~~~~~~~
> > /git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h: In function 'get_unaligned_le32':
> > /git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h:13:29: error: packed attribute causes inefficient alignment for 'x' [-Werror=attributes]
> > 13 | const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr); \
> > | ^
> > /git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h:32:28: note: in expansion of macro '__get_unaligned_t'
> > 32 | return le32_to_cpu(__get_unaligned_t(__le32, p));
> > | ^~~~~~~~~~~~~~~~~
> >
> >
> > Ditto for some other distros when cross building on ubuntu:18.04
> >
> > MKDIR /tmp/build/perf/util/perf-regs-arch/
> > In file included from /usr/sparc64-linux-gnu/include/bits/byteswap.h:34:0,
> > from /usr/sparc64-linux-gnu/include/endian.h:60,
> > from util/intel-pt-decoder/intel-pt-pkt-decoder.c:9:
> > /git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h: In function 'get_unaligned_le16':
> > /git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h:13:22: error: packed attribute causes inefficient alignment for 'x' [-Werror=attributes]
> > const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr); \
> > ^
> > /git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h:27:21: note: in expansion of macro '__get_unaligned_t'
> > return le16_to_cpu(__get_unaligned_t(__le16, p));
> > ^~~~~~~~~~~~~~~~~
> >
> > 37 14.17 ubuntu:18.04-x-arm : FAIL gcc version 7.5.0 (Ubuntu/Linaro 7.5.0-3ubuntu1~18.04)
> > 38 13.56 ubuntu:18.04-x-arm64 : FAIL gcc version 7.5.0 (Ubuntu/Linaro 7.5.0-3ubuntu1~18.04)
> > 42 12.70 ubuntu:18.04-x-riscv64 : FAIL gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)
> > 44 13.95 ubuntu:18.04-x-sh4 : FAIL gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)
> > 45 13.08 ubuntu:18.04-x-sparc64 : FAIL gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)
> >
> >> - Arnaldo
> >>
> >>> Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
> >>> ---
> >>> tools/include/asm-generic/unaligned.h | 20 ++++++++++++++++++++
> >>> 1 file changed, 20 insertions(+)
> >>>
> >>> diff --git a/tools/include/asm-generic/unaligned.h b/tools/include/asm-generic/unaligned.h
> >>> index 47387c607035..9140bb4e16c6 100644
> >>> --- a/tools/include/asm-generic/unaligned.h
> >>> +++ b/tools/include/asm-generic/unaligned.h
> >>> @@ -6,6 +6,9 @@
> >>> #ifndef __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H
> >>> #define __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H
> >>>
> >>> +#pragma GCC diagnostic push
> >>> +#pragma GCC diagnostic ignored "-Wpacked"
> >>> +
> >>> #define __get_unaligned_t(type, ptr) ({ \
> >>> const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr); \
> >>> __pptr->x; \
> >>> @@ -19,5 +22,22 @@
> >>> #define get_unaligned(ptr) __get_unaligned_t(typeof(*(ptr)), (ptr))
> >>> #define put_unaligned(val, ptr) __put_unaligned_t(typeof(*(ptr)), (val), (ptr))
> >>>
> >>> +static inline u16 get_unaligned_le16(const void *p)
> >>> +{
> >>> + return le16_to_cpu(__get_unaligned_t(__le16, p));
> >>> +}
> >>> +
> >>> +static inline u32 get_unaligned_le32(const void *p)
> >>> +{
> >>> + return le32_to_cpu(__get_unaligned_t(__le32, p));
> >>> +}
> >>> +
> >>> +static inline u64 get_unaligned_le64(const void *p)
> >>> +{
> >>> + return le64_to_cpu(__get_unaligned_t(__le64, p));
> >>> +}
> >>> +
> >>> +#pragma GCC diagnostic pop
> >>> +
> >>> #endif /* __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H */
> >>>
> >>> --
> >>> 2.34.1
> >>>
> >>
> >> --
> >>
> >> - Arnaldo
> >
>
--
- Arnaldo
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2023-11-09 19:34 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-05 19:04 [PATCH 0/5] perf intel-pt: Use of get_unaligned_le16() etc Adrian Hunter
2023-10-05 19:04 ` [PATCH 1/5] perf tools: Add get_unaligned_leNN() Adrian Hunter
2023-10-05 19:38 ` Arnaldo Carvalho de Melo
2023-10-10 14:29 ` Adrian Hunter
2023-10-26 13:44 ` Arnaldo Carvalho de Melo
2023-10-26 16:09 ` Adrian Hunter
2023-10-26 20:08 ` Arnaldo Carvalho de Melo
2023-11-09 19:34 ` Arnaldo Carvalho de Melo
2023-10-05 19:04 ` [PATCH 2/5] perf intel-pt: Simplify intel_pt_get_vmcs() Adrian Hunter
2023-10-05 19:04 ` [PATCH 3/5] perf intel-pt: Use existing definitions of le16_to_cpu() etc Adrian Hunter
2023-10-05 19:04 ` [PATCH 4/5] perf intel-pt: Use get_unaligned_le16() etc Adrian Hunter
2023-10-05 19:04 ` [PATCH 5/5] perf intel-pt: Prefer get_unaligned_le64 to memcpy_le64 Adrian Hunter
2023-10-10 14:22 ` [PATCH] perf tools: Add unaligned.h to check-headers.sh Adrian Hunter
2023-10-10 15:28 ` Ian Rogers
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).