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
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 <[email protected]>
---
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
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 <[email protected]>
> ---
> 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
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 <[email protected]>
---
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
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
On Tue, Oct 10, 2023 at 7:22 AM Adrian Hunter <[email protected]> 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 <[email protected]>
Reviewed-by: Ian Rogers <[email protected]>
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
>
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 <[email protected]>
> > ---
> > 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
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 <[email protected]>
>>> ---
>>> 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
>
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 <[email protected]>
> >>> ---
> >>> 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