perf intel-pt: Use of get_unaligned_le16() etc
Adrian Hunter
reviewercover perf intel-pt: Use of get_unaligned_le16() etc
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
Adrian Hunter
reviewerPATCH 1/5 perf tools: Add get_unaligned_leNN()
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.
--- tools/include/asm-generic/unaligned.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
tools/include/asm-generic/unaligned.h +20 -0
@@ -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 */
Signature · 1 line
2.34.1
Arnaldo Carvalho de Melo
maintainerRe: [PATCH 1/5] perf tools: Add get_unaligned_leNN()
Em Thu, Oct 05, 2023 at 10:04:47PM +0300, Adrian Hunter escreveu:
Quoted 4 lines
Add
get_unaligned_le16(),get_unaligned_le32andget_unaligned_le64, same asinclude/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
Quoted 45 lines
Signed-off-by Adrian Hunter <[email protected]>--- tools/include/asm-generic/unaligned.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)tools/include/asm-generic/unaligned.h +20
-0@@ -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 */ Signature · 1 line
2.34.1
Signature · 1 line
- Arnaldo
Adrian Hunter
reviewerRe: [PATCH 1/5] perf tools: Add get_unaligned_leNN()
Quoted 8 lines · Arnaldo Carvalho de Melo
Em Thu, Oct 05, 2023 at 10:04:47PM +0300, Adrian Hunter escreveu:
Quoted 4 lines
Add
get_unaligned_le16(),get_unaligned_le32andget_unaligned_le64, same asinclude/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.hcloser and have it incheck-headers.sh?
I sent another patch for that
Arnaldo Carvalho de Melo
maintainerRe: [PATCH 1/5] perf tools: Add get_unaligned_leNN()
In reply to Arnaldo Carvalho de MeloEm Thu, Oct 05, 2023 at 04:38:05PM -0300, Arnaldo Carvalho de Melo escreveu:
Quoted 8 lines
Em Thu, Oct 05, 2023 at 10:04:47PM +0300, Adrian Hunter escreveu:
Quoted 4 lines
Add
get_unaligned_le16(),get_unaligned_le32andget_unaligned_le64, same asinclude/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.hcloser and have it incheck-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)
Quoted 51 lines
- Arnaldo
Quoted 45 lines
Signed-off-by Adrian Hunter <[email protected]>--- tools/include/asm-generic/unaligned.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)tools/include/asm-generic/unaligned.h +20
-0@@ -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 */ Signature · 1 line
2.34.1Signature · 1 line
- Arnaldo
Signature · 1 line
- Arnaldo
Adrian Hunter
reviewerRe: [PATCH 1/5] perf tools: Add get_unaligned_leNN()
Quoted 10 lines · Arnaldo Carvalho de Melo
Em Thu, Oct 05, 2023 at 04:38:05PM -0300, Arnaldo Carvalho de Melo escreveu:
Quoted 8 lines
Em Thu, Oct 05, 2023 at 10:04:47PM +0300, Adrian Hunter escreveu:
Quoted 4 lines
Add
get_unaligned_le16(),get_unaligned_le32andget_unaligned_le64, same asinclude/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.hcloser and have it incheck-headers.sh?
Quoted 6 lines
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"
Quoted 86 lines
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)Quoted 51 lines
- Arnaldo
Quoted 45 lines
Signed-off-by Adrian Hunter <[email protected]>--- tools/include/asm-generic/unaligned.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)tools/include/asm-generic/unaligned.h +20
-0@@ -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 */ Signature · 1 line
2.34.1Signature · 1 line
- Arnaldo
Arnaldo Carvalho de Melo
maintainerRe: [PATCH 1/5] perf tools: Add get_unaligned_leNN()
Em Thu, Oct 26, 2023 at 07:09:26PM +0300, Adrian Hunter escreveu:
Quoted 14 lines · Arnaldo Carvalho de Melo
Quoted 13 lines
Em Thu, Oct 05, 2023 at 04:38:05PM -0300, Arnaldo Carvalho de Melo escreveu:
Quoted 8 lines
Em Thu, Oct 05, 2023 at 10:04:47PM +0300, Adrian Hunter escreveu:
Quoted 4 lines
Add
get_unaligned_le16(),get_unaligned_le32andget_unaligned_le64, same asinclude/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.hcloser and have it incheck-headers.sh?And this is not building when cross building to mips, mips64 and mipsel on debian:experimental:
Quoted 7 lines
Quoted 3 lines
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
Quoted 88 lines
Quoted 87 lines
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)Quoted 51 lines
- Arnaldo
Quoted 45 lines
Signed-off-by Adrian Hunter <[email protected]>--- tools/include/asm-generic/unaligned.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)tools/include/asm-generic/unaligned.h +20
-0@@ -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 */ Signature · 1 line
2.34.1Signature · 1 line
- Arnaldo
Signature · 1 line
- Arnaldo
Arnaldo Carvalho de Melo
maintainerRe: [PATCH 1/5] perf tools: Add get_unaligned_leNN()
In reply to Adrian HunterEm Thu, Oct 26, 2023 at 07:09:26PM +0300, Adrian Hunter escreveu:
Quoted 14 lines · Arnaldo Carvalho de Melo
Quoted 13 lines
Em Thu, Oct 05, 2023 at 04:38:05PM -0300, Arnaldo Carvalho de Melo escreveu:
Quoted 8 lines
Em Thu, Oct 05, 2023 at 10:04:47PM +0300, Adrian Hunter escreveu:
Quoted 4 lines
Add
get_unaligned_le16(),get_unaligned_le32andget_unaligned_le64, same asinclude/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.hcloser and have it incheck-headers.sh?And this is not building when cross building to mips, mips64 and mipsel on debian:experimental:
Quoted 7 lines
Quoted 3 lines
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
Quoted 88 lines
Quoted 87 lines
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)Quoted 51 lines
- Arnaldo
Quoted 45 lines
Signed-off-by Adrian Hunter <[email protected]>--- tools/include/asm-generic/unaligned.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)tools/include/asm-generic/unaligned.h +20
-0@@ -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 */ Signature · 1 line
2.34.1Signature · 1 line
- Arnaldo
Signature · 1 line
- Arnaldo
Adrian Hunter
reviewerPATCH 2/5 perf intel-pt: Simplify intel_pt_get_vmcs()
In reply to Adrian HunterSimplify and remove unnecessary constant expressions.
--- .../util/intel-pt-decoder/intel-pt-pkt-decoder.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-)
tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c +4 -9
@@ -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)
Signature · 1 line
2.34.1
Adrian Hunter
reviewerPATCH 3/5 perf intel-pt: Use existing definitions of le16_to_cpu() etc
In reply to Adrian HunterUse definitions from tools/include/linux/kernel.h
--- tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c +1 -6
@@ -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
Signature · 1 line
2.34.1
Adrian Hunter
reviewerPATCH 4/5 perf intel-pt: Use get_unaligned_le16() etc
In reply to Adrian HunterAvoid unaligned access by using get_unaligned_le16(), get_unaligned_le32() and get_unaligned_le64().
--- .../intel-pt-decoder/intel-pt-pkt-decoder.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c +9 -8
@@ -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 ;
Signature · 1 line
2.34.1
Adrian Hunter
reviewerPATCH 5/5 perf intel-pt: Prefer get_unaligned_le64 to memcpy_le64
In reply to Adrian HunterUse get_unaligned_le64() instead of memcpy_le64(..., 8) because it produces simpler code.
--- tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c +3 -3
@@ -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 ; }
Signature · 1 line
2.34.1
Adrian Hunter
reviewerPATCH 1/1 perf tools: Add unaligned.h to check-headers.sh
In reply to Adrian HunterAdd 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.
---
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(-)
tools/include/asm-generic/unaligned.h +121 -8
@@ -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 */
tools/perf/check-headers.sh +1 -0
@@ -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$"'
Signature · 1 line
2.34.1
Re: [PATCH] perf tools: Add unaligned.h to check-headers.sh
Quoted 6 lines · Adrian Hunter
Add
include/asm-generic/unaligned.htocheck-headers.shbringingtools/include/asm-generic/unaligned.hup to date so that the kernel and tools versions match.Signed-off-by Adrian Hunter <[email protected]>
Thanks,
Ian
Quoted 170 lines
---
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(-)tools/include/asm-generic/unaligned.h +121
-8@@ -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 */ tools/perf/check-headers.sh +1
-1@@ -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