aboutsummaryrefslogtreecommitdiffstats
path: root/tools/include/linux
diff options
context:
space:
mode:
authorLevin, Alexander (Sasha Levin) <alexander.levin@verizon.com>2017-05-25 08:58:47 -0400
committerIngo Molnar <mingo@kernel.org>2017-06-05 03:28:09 -0400
commit6c8e6483850e7a7e44fd584790969c308887c468 (patch)
treea22b5da6c662b1479f17b6fbfaf040f4a0881491 /tools/include/linux
parent20fb654aef1c929f7befb40678e2cb65a77ead7f (diff)
tools/lib/lockdep: Fix compilation for 4.11
- More rcu stubs - New dummy headers due to sched header split - jhash2 included in due to kernel lockdep inclusion and usage Signed-off-by: Sasha Levin <alexander.levin@verizon.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: a.p.zijlstra@chello.nl Cc: ben@decadent.org.uk Link: http://lkml.kernel.org/r/20170525130005.5947-13-alexander.levin@verizon.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'tools/include/linux')
-rw-r--r--tools/include/linux/bitops.h10
-rw-r--r--tools/include/linux/jhash.h175
-rw-r--r--tools/include/linux/unaligned/packed_struct.h46
3 files changed, 231 insertions, 0 deletions
diff --git a/tools/include/linux/bitops.h b/tools/include/linux/bitops.h
index 1aecad369af5..969db1981868 100644
--- a/tools/include/linux/bitops.h
+++ b/tools/include/linux/bitops.h
@@ -61,4 +61,14 @@ static inline unsigned fls_long(unsigned long l)
61 return fls64(l); 61 return fls64(l);
62} 62}
63 63
64/**
65 * rol32 - rotate a 32-bit value left
66 * @word: value to rotate
67 * @shift: bits to roll
68 */
69static inline __u32 rol32(__u32 word, unsigned int shift)
70{
71 return (word << shift) | (word >> ((-shift) & 31));
72}
73
64#endif 74#endif
diff --git a/tools/include/linux/jhash.h b/tools/include/linux/jhash.h
new file mode 100644
index 000000000000..348c6f47e4cc
--- /dev/null
+++ b/tools/include/linux/jhash.h
@@ -0,0 +1,175 @@
1#ifndef _LINUX_JHASH_H
2#define _LINUX_JHASH_H
3
4/* jhash.h: Jenkins hash support.
5 *
6 * Copyright (C) 2006. Bob Jenkins (bob_jenkins@burtleburtle.net)
7 *
8 * http://burtleburtle.net/bob/hash/
9 *
10 * These are the credits from Bob's sources:
11 *
12 * lookup3.c, by Bob Jenkins, May 2006, Public Domain.
13 *
14 * These are functions for producing 32-bit hashes for hash table lookup.
15 * hashword(), hashlittle(), hashlittle2(), hashbig(), mix(), and final()
16 * are externally useful functions. Routines to test the hash are included
17 * if SELF_TEST is defined. You can use this free for any purpose. It's in
18 * the public domain. It has no warranty.
19 *
20 * Copyright (C) 2009-2010 Jozsef Kadlecsik (kadlec@blackhole.kfki.hu)
21 *
22 * I've modified Bob's hash to be useful in the Linux kernel, and
23 * any bugs present are my fault.
24 * Jozsef
25 */
26#include <linux/bitops.h>
27#include <linux/unaligned/packed_struct.h>
28
29/* Best hash sizes are of power of two */
30#define jhash_size(n) ((u32)1<<(n))
31/* Mask the hash value, i.e (value & jhash_mask(n)) instead of (value % n) */
32#define jhash_mask(n) (jhash_size(n)-1)
33
34/* __jhash_mix -- mix 3 32-bit values reversibly. */
35#define __jhash_mix(a, b, c) \
36{ \
37 a -= c; a ^= rol32(c, 4); c += b; \
38 b -= a; b ^= rol32(a, 6); a += c; \
39 c -= b; c ^= rol32(b, 8); b += a; \
40 a -= c; a ^= rol32(c, 16); c += b; \
41 b -= a; b ^= rol32(a, 19); a += c; \
42 c -= b; c ^= rol32(b, 4); b += a; \
43}
44
45/* __jhash_final - final mixing of 3 32-bit values (a,b,c) into c */
46#define __jhash_final(a, b, c) \
47{ \
48 c ^= b; c -= rol32(b, 14); \
49 a ^= c; a -= rol32(c, 11); \
50 b ^= a; b -= rol32(a, 25); \
51 c ^= b; c -= rol32(b, 16); \
52 a ^= c; a -= rol32(c, 4); \
53 b ^= a; b -= rol32(a, 14); \
54 c ^= b; c -= rol32(b, 24); \
55}
56
57/* An arbitrary initial parameter */
58#define JHASH_INITVAL 0xdeadbeef
59
60/* jhash - hash an arbitrary key
61 * @k: sequence of bytes as key
62 * @length: the length of the key
63 * @initval: the previous hash, or an arbitray value
64 *
65 * The generic version, hashes an arbitrary sequence of bytes.
66 * No alignment or length assumptions are made about the input key.
67 *
68 * Returns the hash value of the key. The result depends on endianness.
69 */
70static inline u32 jhash(const void *key, u32 length, u32 initval)
71{
72 u32 a, b, c;
73 const u8 *k = key;
74
75 /* Set up the internal state */
76 a = b = c = JHASH_INITVAL + length + initval;
77
78 /* All but the last block: affect some 32 bits of (a,b,c) */
79 while (length > 12) {
80 a += __get_unaligned_cpu32(k);
81 b += __get_unaligned_cpu32(k + 4);
82 c += __get_unaligned_cpu32(k + 8);
83 __jhash_mix(a, b, c);
84 length -= 12;
85 k += 12;
86 }
87 /* Last block: affect all 32 bits of (c) */
88 /* All the case statements fall through */
89 switch (length) {
90 case 12: c += (u32)k[11]<<24;
91 case 11: c += (u32)k[10]<<16;
92 case 10: c += (u32)k[9]<<8;
93 case 9: c += k[8];
94 case 8: b += (u32)k[7]<<24;
95 case 7: b += (u32)k[6]<<16;
96 case 6: b += (u32)k[5]<<8;
97 case 5: b += k[4];
98 case 4: a += (u32)k[3]<<24;
99 case 3: a += (u32)k[2]<<16;
100 case 2: a += (u32)k[1]<<8;
101 case 1: a += k[0];
102 __jhash_final(a, b, c);
103 case 0: /* Nothing left to add */
104 break;
105 }
106
107 return c;
108}
109
110/* jhash2 - hash an array of u32's
111 * @k: the key which must be an array of u32's
112 * @length: the number of u32's in the key
113 * @initval: the previous hash, or an arbitray value
114 *
115 * Returns the hash value of the key.
116 */
117static inline u32 jhash2(const u32 *k, u32 length, u32 initval)
118{
119 u32 a, b, c;
120
121 /* Set up the internal state */
122 a = b = c = JHASH_INITVAL + (length<<2) + initval;
123
124 /* Handle most of the key */
125 while (length > 3) {
126 a += k[0];
127 b += k[1];
128 c += k[2];
129 __jhash_mix(a, b, c);
130 length -= 3;
131 k += 3;
132 }
133
134 /* Handle the last 3 u32's: all the case statements fall through */
135 switch (length) {
136 case 3: c += k[2];
137 case 2: b += k[1];
138 case 1: a += k[0];
139 __jhash_final(a, b, c);
140 case 0: /* Nothing left to add */
141 break;
142 }
143
144 return c;
145}
146
147
148/* __jhash_nwords - hash exactly 3, 2 or 1 word(s) */
149static inline u32 __jhash_nwords(u32 a, u32 b, u32 c, u32 initval)
150{
151 a += initval;
152 b += initval;
153 c += initval;
154
155 __jhash_final(a, b, c);
156
157 return c;
158}
159
160static inline u32 jhash_3words(u32 a, u32 b, u32 c, u32 initval)
161{
162 return __jhash_nwords(a, b, c, initval + JHASH_INITVAL + (3 << 2));
163}
164
165static inline u32 jhash_2words(u32 a, u32 b, u32 initval)
166{
167 return __jhash_nwords(a, b, 0, initval + JHASH_INITVAL + (2 << 2));
168}
169
170static inline u32 jhash_1word(u32 a, u32 initval)
171{
172 return __jhash_nwords(a, 0, 0, initval + JHASH_INITVAL + (1 << 2));
173}
174
175#endif /* _LINUX_JHASH_H */
diff --git a/tools/include/linux/unaligned/packed_struct.h b/tools/include/linux/unaligned/packed_struct.h
new file mode 100644
index 000000000000..c0d817de4df2
--- /dev/null
+++ b/tools/include/linux/unaligned/packed_struct.h
@@ -0,0 +1,46 @@
1#ifndef _LINUX_UNALIGNED_PACKED_STRUCT_H
2#define _LINUX_UNALIGNED_PACKED_STRUCT_H
3
4#include <linux/kernel.h>
5
6struct __una_u16 { u16 x; } __packed;
7struct __una_u32 { u32 x; } __packed;
8struct __una_u64 { u64 x; } __packed;
9
10static inline u16 __get_unaligned_cpu16(const void *p)
11{
12 const struct __una_u16 *ptr = (const struct __una_u16 *)p;
13 return ptr->x;
14}
15
16static inline u32 __get_unaligned_cpu32(const void *p)
17{
18 const struct __una_u32 *ptr = (const struct __una_u32 *)p;
19 return ptr->x;
20}
21
22static inline u64 __get_unaligned_cpu64(const void *p)
23{
24 const struct __una_u64 *ptr = (const struct __una_u64 *)p;
25 return ptr->x;
26}
27
28static inline void __put_unaligned_cpu16(u16 val, void *p)
29{
30 struct __una_u16 *ptr = (struct __una_u16 *)p;
31 ptr->x = val;
32}
33
34static inline void __put_unaligned_cpu32(u32 val, void *p)
35{
36 struct __una_u32 *ptr = (struct __una_u32 *)p;
37 ptr->x = val;
38}
39
40static inline void __put_unaligned_cpu64(u64 val, void *p)
41{
42 struct __una_u64 *ptr = (struct __una_u64 *)p;
43 ptr->x = val;
44}
45
46#endif /* _LINUX_UNALIGNED_PACKED_STRUCT_H */