Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf tools: Add get_unaligned_leNN()

Add get_unaligned_le16(), get_unaligned_le32 and get_unaligned_le64, same
as include/asm-generic/unaligned.h. And 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.

Use diagnostic pragmas to ignore -Wpacked used by perf build.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Reviewed-by: Ian Rogers <irogers@google.com>
Link: https://lore.kernel.org/r/20231005190451.175568-2-adrian.hunter@intel.com
Link: https://lore.kernel.org/r/20231010142234.20061-1-adrian.hunter@intel.com
[ squashed check-header.sh addition ]
Signed-off-by: Namhyung Kim <namhyung@kernel.org>

authored by

Adrian Hunter and committed by
Namhyung Kim
a91c9872 a16afcc5

+141 -7
+140 -7
tools/include/asm-generic/unaligned.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 - /* 3 - * Copied from the kernel sources to tools/perf/: 4 - */ 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef __ASM_GENERIC_UNALIGNED_H 3 + #define __ASM_GENERIC_UNALIGNED_H 5 4 6 - #ifndef __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H 7 - #define __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H 5 + /* 6 + * This is the most generic implementation of unaligned accesses 7 + * and should work almost anywhere. 8 + */ 9 + #pragma GCC diagnostic push 10 + #pragma GCC diagnostic ignored "-Wpacked" 8 11 9 12 #define __get_unaligned_t(type, ptr) ({ \ 10 13 const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr); \ ··· 22 19 #define get_unaligned(ptr) __get_unaligned_t(typeof(*(ptr)), (ptr)) 23 20 #define put_unaligned(val, ptr) __put_unaligned_t(typeof(*(ptr)), (val), (ptr)) 24 21 25 - #endif /* __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H */ 22 + static inline u16 get_unaligned_le16(const void *p) 23 + { 24 + return le16_to_cpu(__get_unaligned_t(__le16, p)); 25 + } 26 26 27 + static inline u32 get_unaligned_le32(const void *p) 28 + { 29 + return le32_to_cpu(__get_unaligned_t(__le32, p)); 30 + } 31 + 32 + static inline u64 get_unaligned_le64(const void *p) 33 + { 34 + return le64_to_cpu(__get_unaligned_t(__le64, p)); 35 + } 36 + 37 + static inline void put_unaligned_le16(u16 val, void *p) 38 + { 39 + __put_unaligned_t(__le16, cpu_to_le16(val), p); 40 + } 41 + 42 + static inline void put_unaligned_le32(u32 val, void *p) 43 + { 44 + __put_unaligned_t(__le32, cpu_to_le32(val), p); 45 + } 46 + 47 + static inline void put_unaligned_le64(u64 val, void *p) 48 + { 49 + __put_unaligned_t(__le64, cpu_to_le64(val), p); 50 + } 51 + 52 + static inline u16 get_unaligned_be16(const void *p) 53 + { 54 + return be16_to_cpu(__get_unaligned_t(__be16, p)); 55 + } 56 + 57 + static inline u32 get_unaligned_be32(const void *p) 58 + { 59 + return be32_to_cpu(__get_unaligned_t(__be32, p)); 60 + } 61 + 62 + static inline u64 get_unaligned_be64(const void *p) 63 + { 64 + return be64_to_cpu(__get_unaligned_t(__be64, p)); 65 + } 66 + 67 + static inline void put_unaligned_be16(u16 val, void *p) 68 + { 69 + __put_unaligned_t(__be16, cpu_to_be16(val), p); 70 + } 71 + 72 + static inline void put_unaligned_be32(u32 val, void *p) 73 + { 74 + __put_unaligned_t(__be32, cpu_to_be32(val), p); 75 + } 76 + 77 + static inline void put_unaligned_be64(u64 val, void *p) 78 + { 79 + __put_unaligned_t(__be64, cpu_to_be64(val), p); 80 + } 81 + 82 + static inline u32 __get_unaligned_be24(const u8 *p) 83 + { 84 + return p[0] << 16 | p[1] << 8 | p[2]; 85 + } 86 + 87 + static inline u32 get_unaligned_be24(const void *p) 88 + { 89 + return __get_unaligned_be24(p); 90 + } 91 + 92 + static inline u32 __get_unaligned_le24(const u8 *p) 93 + { 94 + return p[0] | p[1] << 8 | p[2] << 16; 95 + } 96 + 97 + static inline u32 get_unaligned_le24(const void *p) 98 + { 99 + return __get_unaligned_le24(p); 100 + } 101 + 102 + static inline void __put_unaligned_be24(const u32 val, u8 *p) 103 + { 104 + *p++ = val >> 16; 105 + *p++ = val >> 8; 106 + *p++ = val; 107 + } 108 + 109 + static inline void put_unaligned_be24(const u32 val, void *p) 110 + { 111 + __put_unaligned_be24(val, p); 112 + } 113 + 114 + static inline void __put_unaligned_le24(const u32 val, u8 *p) 115 + { 116 + *p++ = val; 117 + *p++ = val >> 8; 118 + *p++ = val >> 16; 119 + } 120 + 121 + static inline void put_unaligned_le24(const u32 val, void *p) 122 + { 123 + __put_unaligned_le24(val, p); 124 + } 125 + 126 + static inline void __put_unaligned_be48(const u64 val, u8 *p) 127 + { 128 + *p++ = val >> 40; 129 + *p++ = val >> 32; 130 + *p++ = val >> 24; 131 + *p++ = val >> 16; 132 + *p++ = val >> 8; 133 + *p++ = val; 134 + } 135 + 136 + static inline void put_unaligned_be48(const u64 val, void *p) 137 + { 138 + __put_unaligned_be48(val, p); 139 + } 140 + 141 + static inline u64 __get_unaligned_be48(const u8 *p) 142 + { 143 + return (u64)p[0] << 40 | (u64)p[1] << 32 | (u64)p[2] << 24 | 144 + p[3] << 16 | p[4] << 8 | p[5]; 145 + } 146 + 147 + static inline u64 get_unaligned_be48(const void *p) 148 + { 149 + return __get_unaligned_be48(p); 150 + } 151 + #pragma GCC diagnostic pop 152 + 153 + #endif /* __ASM_GENERIC_UNALIGNED_H */
+1
tools/perf/check-headers.sh
··· 162 162 check arch/x86/lib/memset_64.S '-I "^EXPORT_SYMBOL" -I "^#include <asm/export.h>" -I"^SYM_FUNC_START\(_LOCAL\)*(memset_\(erms\|orig\))"' 163 163 check arch/x86/include/asm/amd-ibs.h '-I "^#include [<\"]\(asm/\)*msr-index.h"' 164 164 check arch/arm64/include/asm/cputype.h '-I "^#include [<\"]\(asm/\)*sysreg.h"' 165 + check include/asm-generic/unaligned.h '-I "^#include <linux/unaligned/packed_struct.h>" -I "^#include <asm/byteorder.h>" -I "^#pragma GCC diagnostic"' 165 166 check include/uapi/asm-generic/mman.h '-I "^#include <\(uapi/\)*asm-generic/mman-common\(-tools\)*.h>"' 166 167 check include/uapi/linux/mman.h '-I "^#include <\(uapi/\)*asm/mman.h>"' 167 168 check include/linux/build_bug.h '-I "^#\(ifndef\|endif\)\( \/\/\)* static_assert$"'