perf tools: Add unaligned.h to check-headers.sh

Message ID 20231010142234.20061-1-adrian.hunter@intel.com
State New
Headers
Series perf tools: Add unaligned.h to check-headers.sh |

Commit Message

Adrian Hunter Oct. 10, 2023, 2:22 p.m. UTC
  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 ++++++++++++++++++++++++--
 tools/perf/check-headers.sh           |   1 +
 2 files changed, 122 insertions(+), 8 deletions(-)
  

Comments

Ian Rogers Oct. 10, 2023, 3:28 p.m. UTC | #1
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
>
  

Patch

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$"'