* [PATCH v2 1/2] liblockdep: Fix compile errors
@ 2016-06-14 10:49 Vishal Thanki
2016-06-14 10:49 ` [PATCH v2 2/2] liblockdep: Remove -lpthread compiler option Vishal Thanki
2016-06-14 18:44 ` [PATCH v2 1/2] liblockdep: Fix compile errors Sasha Levin
0 siblings, 2 replies; 3+ messages in thread
From: Vishal Thanki @ 2016-06-14 10:49 UTC (permalink / raw)
To: sasha.levin, linux-kernel; +Cc: Vishal Thanki
Following commit caused failures.
dfaaf3fa0: (Use __jhash_mix() for iterate_chain_key())
Fixed by adding jhash.h
75dd602a5: (lockdep: Fix lock_chain::base size)
Fixed by adding ARRAY_SIZE macro definition and
changing the MAX_LOCK_DEPTH value to similar defined
in linux/sched.h
Signed-off-by: Vishal Thanki <vishalthanki@gmail.com>
---
tools/lib/lockdep/lockdep.c | 2 +-
tools/lib/lockdep/uinclude/linux/bitops.h | 8 +-
tools/lib/lockdep/uinclude/linux/compiler.h | 1 +
tools/lib/lockdep/uinclude/linux/jhash.h | 175 +++++++++++++++++++++
tools/lib/lockdep/uinclude/linux/kernel.h | 1 +
tools/lib/lockdep/uinclude/linux/lockdep.h | 2 +-
.../uinclude/linux/unaligned/packed_struct.h | 46 ++++++
7 files changed, 232 insertions(+), 3 deletions(-)
create mode 100644 tools/lib/lockdep/uinclude/linux/jhash.h
create mode 100644 tools/lib/lockdep/uinclude/linux/unaligned/packed_struct.h
diff --git a/tools/lib/lockdep/lockdep.c b/tools/lib/lockdep/lockdep.c
index a0a2e3a..1ba6f33 100644
--- a/tools/lib/lockdep/lockdep.c
+++ b/tools/lib/lockdep/lockdep.c
@@ -4,5 +4,5 @@
#define hlist_for_each_entry_rcu hlist_for_each_entry
#define hlist_add_head_rcu hlist_add_head
#define hlist_del_rcu hlist_del
-
+#define prandom_u32 rand
#include "../../../kernel/locking/lockdep.c"
diff --git a/tools/lib/lockdep/uinclude/linux/bitops.h b/tools/lib/lockdep/uinclude/linux/bitops.h
index fab00ff..684cc20 100644
--- a/tools/lib/lockdep/uinclude/linux/bitops.h
+++ b/tools/lib/lockdep/uinclude/linux/bitops.h
@@ -1,3 +1,9 @@
+#ifndef _LINUX_BITOPS_H
+#define _LINUX_BITOPS_H
-/* empty file */
+static inline __u32 rol32(__u32 word, unsigned int shift)
+{
+ return (word << shift) | (word >> ((-shift) & 31));
+}
+#endif
diff --git a/tools/lib/lockdep/uinclude/linux/compiler.h b/tools/lib/lockdep/uinclude/linux/compiler.h
index fd3e56a..46bf03e 100644
--- a/tools/lib/lockdep/uinclude/linux/compiler.h
+++ b/tools/lib/lockdep/uinclude/linux/compiler.h
@@ -2,6 +2,7 @@
#define _LIBLOCKDEP_LINUX_COMPILER_H_
#define __used __attribute__((__unused__))
+#define __packed __attribute__((__packed__))
#define unlikely
#define READ_ONCE(x) (x)
#define WRITE_ONCE(x, val) x=(val)
diff --git a/tools/lib/lockdep/uinclude/linux/jhash.h b/tools/lib/lockdep/uinclude/linux/jhash.h
new file mode 100644
index 0000000..348c6f4
--- /dev/null
+++ b/tools/lib/lockdep/uinclude/linux/jhash.h
@@ -0,0 +1,175 @@
+#ifndef _LINUX_JHASH_H
+#define _LINUX_JHASH_H
+
+/* jhash.h: Jenkins hash support.
+ *
+ * Copyright (C) 2006. Bob Jenkins (bob_jenkins@burtleburtle.net)
+ *
+ * http://burtleburtle.net/bob/hash/
+ *
+ * These are the credits from Bob's sources:
+ *
+ * lookup3.c, by Bob Jenkins, May 2006, Public Domain.
+ *
+ * These are functions for producing 32-bit hashes for hash table lookup.
+ * hashword(), hashlittle(), hashlittle2(), hashbig(), mix(), and final()
+ * are externally useful functions. Routines to test the hash are included
+ * if SELF_TEST is defined. You can use this free for any purpose. It's in
+ * the public domain. It has no warranty.
+ *
+ * Copyright (C) 2009-2010 Jozsef Kadlecsik (kadlec@blackhole.kfki.hu)
+ *
+ * I've modified Bob's hash to be useful in the Linux kernel, and
+ * any bugs present are my fault.
+ * Jozsef
+ */
+#include <linux/bitops.h>
+#include <linux/unaligned/packed_struct.h>
+
+/* Best hash sizes are of power of two */
+#define jhash_size(n) ((u32)1<<(n))
+/* Mask the hash value, i.e (value & jhash_mask(n)) instead of (value % n) */
+#define jhash_mask(n) (jhash_size(n)-1)
+
+/* __jhash_mix -- mix 3 32-bit values reversibly. */
+#define __jhash_mix(a, b, c) \
+{ \
+ a -= c; a ^= rol32(c, 4); c += b; \
+ b -= a; b ^= rol32(a, 6); a += c; \
+ c -= b; c ^= rol32(b, 8); b += a; \
+ a -= c; a ^= rol32(c, 16); c += b; \
+ b -= a; b ^= rol32(a, 19); a += c; \
+ c -= b; c ^= rol32(b, 4); b += a; \
+}
+
+/* __jhash_final - final mixing of 3 32-bit values (a,b,c) into c */
+#define __jhash_final(a, b, c) \
+{ \
+ c ^= b; c -= rol32(b, 14); \
+ a ^= c; a -= rol32(c, 11); \
+ b ^= a; b -= rol32(a, 25); \
+ c ^= b; c -= rol32(b, 16); \
+ a ^= c; a -= rol32(c, 4); \
+ b ^= a; b -= rol32(a, 14); \
+ c ^= b; c -= rol32(b, 24); \
+}
+
+/* An arbitrary initial parameter */
+#define JHASH_INITVAL 0xdeadbeef
+
+/* jhash - hash an arbitrary key
+ * @k: sequence of bytes as key
+ * @length: the length of the key
+ * @initval: the previous hash, or an arbitray value
+ *
+ * The generic version, hashes an arbitrary sequence of bytes.
+ * No alignment or length assumptions are made about the input key.
+ *
+ * Returns the hash value of the key. The result depends on endianness.
+ */
+static inline u32 jhash(const void *key, u32 length, u32 initval)
+{
+ u32 a, b, c;
+ const u8 *k = key;
+
+ /* Set up the internal state */
+ a = b = c = JHASH_INITVAL + length + initval;
+
+ /* All but the last block: affect some 32 bits of (a,b,c) */
+ while (length > 12) {
+ a += __get_unaligned_cpu32(k);
+ b += __get_unaligned_cpu32(k + 4);
+ c += __get_unaligned_cpu32(k + 8);
+ __jhash_mix(a, b, c);
+ length -= 12;
+ k += 12;
+ }
+ /* Last block: affect all 32 bits of (c) */
+ /* All the case statements fall through */
+ switch (length) {
+ case 12: c += (u32)k[11]<<24;
+ case 11: c += (u32)k[10]<<16;
+ case 10: c += (u32)k[9]<<8;
+ case 9: c += k[8];
+ case 8: b += (u32)k[7]<<24;
+ case 7: b += (u32)k[6]<<16;
+ case 6: b += (u32)k[5]<<8;
+ case 5: b += k[4];
+ case 4: a += (u32)k[3]<<24;
+ case 3: a += (u32)k[2]<<16;
+ case 2: a += (u32)k[1]<<8;
+ case 1: a += k[0];
+ __jhash_final(a, b, c);
+ case 0: /* Nothing left to add */
+ break;
+ }
+
+ return c;
+}
+
+/* jhash2 - hash an array of u32's
+ * @k: the key which must be an array of u32's
+ * @length: the number of u32's in the key
+ * @initval: the previous hash, or an arbitray value
+ *
+ * Returns the hash value of the key.
+ */
+static inline u32 jhash2(const u32 *k, u32 length, u32 initval)
+{
+ u32 a, b, c;
+
+ /* Set up the internal state */
+ a = b = c = JHASH_INITVAL + (length<<2) + initval;
+
+ /* Handle most of the key */
+ while (length > 3) {
+ a += k[0];
+ b += k[1];
+ c += k[2];
+ __jhash_mix(a, b, c);
+ length -= 3;
+ k += 3;
+ }
+
+ /* Handle the last 3 u32's: all the case statements fall through */
+ switch (length) {
+ case 3: c += k[2];
+ case 2: b += k[1];
+ case 1: a += k[0];
+ __jhash_final(a, b, c);
+ case 0: /* Nothing left to add */
+ break;
+ }
+
+ return c;
+}
+
+
+/* __jhash_nwords - hash exactly 3, 2 or 1 word(s) */
+static inline u32 __jhash_nwords(u32 a, u32 b, u32 c, u32 initval)
+{
+ a += initval;
+ b += initval;
+ c += initval;
+
+ __jhash_final(a, b, c);
+
+ return c;
+}
+
+static inline u32 jhash_3words(u32 a, u32 b, u32 c, u32 initval)
+{
+ return __jhash_nwords(a, b, c, initval + JHASH_INITVAL + (3 << 2));
+}
+
+static inline u32 jhash_2words(u32 a, u32 b, u32 initval)
+{
+ return __jhash_nwords(a, b, 0, initval + JHASH_INITVAL + (2 << 2));
+}
+
+static inline u32 jhash_1word(u32 a, u32 initval)
+{
+ return __jhash_nwords(a, 0, 0, initval + JHASH_INITVAL + (1 << 2));
+}
+
+#endif /* _LINUX_JHASH_H */
diff --git a/tools/lib/lockdep/uinclude/linux/kernel.h b/tools/lib/lockdep/uinclude/linux/kernel.h
index 276c7a8..ab204c8 100644
--- a/tools/lib/lockdep/uinclude/linux/kernel.h
+++ b/tools/lib/lockdep/uinclude/linux/kernel.h
@@ -44,4 +44,5 @@
#define _THIS_IP_ ({ __label__ __here; __here: (unsigned long)&&__here; })
#endif
+#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
#endif
diff --git a/tools/lib/lockdep/uinclude/linux/lockdep.h b/tools/lib/lockdep/uinclude/linux/lockdep.h
index c808c7d..8f6e725 100644
--- a/tools/lib/lockdep/uinclude/linux/lockdep.h
+++ b/tools/lib/lockdep/uinclude/linux/lockdep.h
@@ -8,7 +8,7 @@
#include <linux/utsname.h>
#include <linux/compiler.h>
-#define MAX_LOCK_DEPTH 2000UL
+#define MAX_LOCK_DEPTH 48UL
#define asmlinkage
#define __visible
diff --git a/tools/lib/lockdep/uinclude/linux/unaligned/packed_struct.h b/tools/lib/lockdep/uinclude/linux/unaligned/packed_struct.h
new file mode 100644
index 0000000..c0d817d
--- /dev/null
+++ b/tools/lib/lockdep/uinclude/linux/unaligned/packed_struct.h
@@ -0,0 +1,46 @@
+#ifndef _LINUX_UNALIGNED_PACKED_STRUCT_H
+#define _LINUX_UNALIGNED_PACKED_STRUCT_H
+
+#include <linux/kernel.h>
+
+struct __una_u16 { u16 x; } __packed;
+struct __una_u32 { u32 x; } __packed;
+struct __una_u64 { u64 x; } __packed;
+
+static inline u16 __get_unaligned_cpu16(const void *p)
+{
+ const struct __una_u16 *ptr = (const struct __una_u16 *)p;
+ return ptr->x;
+}
+
+static inline u32 __get_unaligned_cpu32(const void *p)
+{
+ const struct __una_u32 *ptr = (const struct __una_u32 *)p;
+ return ptr->x;
+}
+
+static inline u64 __get_unaligned_cpu64(const void *p)
+{
+ const struct __una_u64 *ptr = (const struct __una_u64 *)p;
+ return ptr->x;
+}
+
+static inline void __put_unaligned_cpu16(u16 val, void *p)
+{
+ struct __una_u16 *ptr = (struct __una_u16 *)p;
+ ptr->x = val;
+}
+
+static inline void __put_unaligned_cpu32(u32 val, void *p)
+{
+ struct __una_u32 *ptr = (struct __una_u32 *)p;
+ ptr->x = val;
+}
+
+static inline void __put_unaligned_cpu64(u64 val, void *p)
+{
+ struct __una_u64 *ptr = (struct __una_u64 *)p;
+ ptr->x = val;
+}
+
+#endif /* _LINUX_UNALIGNED_PACKED_STRUCT_H */
--
2.4.11
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH v2 2/2] liblockdep: Remove -lpthread compiler option
2016-06-14 10:49 [PATCH v2 1/2] liblockdep: Fix compile errors Vishal Thanki
@ 2016-06-14 10:49 ` Vishal Thanki
2016-06-14 18:44 ` [PATCH v2 1/2] liblockdep: Fix compile errors Sasha Levin
1 sibling, 0 replies; 3+ messages in thread
From: Vishal Thanki @ 2016-06-14 10:49 UTC (permalink / raw)
To: sasha.levin, linux-kernel; +Cc: Vishal Thanki
With -lpthread option, the test for ABBA_2threads was
failing, and test passed if it was removed.
Since -pthread compiler option is sufficient for linking
to pthread libraries, this patch removes -lpthread.
Signed-off-by: Vishal Thanki <vishalthanki@gmail.com>
---
tools/lib/lockdep/run_tests.sh | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/lib/lockdep/run_tests.sh b/tools/lib/lockdep/run_tests.sh
index 1069d96..3fd297b 100755
--- a/tools/lib/lockdep/run_tests.sh
+++ b/tools/lib/lockdep/run_tests.sh
@@ -4,7 +4,7 @@ make &> /dev/null
for i in `ls tests/*.c`; do
testname=$(basename "$i" .c)
- gcc -o tests/$testname -pthread -lpthread $i liblockdep.a -Iinclude -D__USE_LIBLOCKDEP &> /dev/null
+ gcc -o tests/$testname -pthread $i liblockdep.a -Iinclude -D__USE_LIBLOCKDEP &> /dev/null
echo -ne "$testname... "
if [ $(timeout 1 ./tests/$testname | wc -l) -gt 0 ]; then
echo "PASSED!"
@@ -18,7 +18,7 @@ done
for i in `ls tests/*.c`; do
testname=$(basename "$i" .c)
- gcc -o tests/$testname -pthread -lpthread -Iinclude $i &> /dev/null
+ gcc -o tests/$testname -pthread -Iinclude $i &> /dev/null
echo -ne "(PRELOAD) $testname... "
if [ $(timeout 1 ./lockdep ./tests/$testname | wc -l) -gt 0 ]; then
echo "PASSED!"
--
2.4.11
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2 1/2] liblockdep: Fix compile errors
2016-06-14 10:49 [PATCH v2 1/2] liblockdep: Fix compile errors Vishal Thanki
2016-06-14 10:49 ` [PATCH v2 2/2] liblockdep: Remove -lpthread compiler option Vishal Thanki
@ 2016-06-14 18:44 ` Sasha Levin
1 sibling, 0 replies; 3+ messages in thread
From: Sasha Levin @ 2016-06-14 18:44 UTC (permalink / raw)
To: Vishal Thanki, linux-kernel
On 06/14/2016 06:49 AM, Vishal Thanki wrote:
> diff --git a/tools/lib/lockdep/uinclude/linux/jhash.h b/tools/lib/lockdep/uinclude/linux/jhash.h
> new file mode 100644
> index 0000000..348c6f4
> --- /dev/null
> +++ b/tools/lib/lockdep/uinclude/linux/jhash.h
> @@ -0,0 +1,175 @@
> +#ifndef _LINUX_JHASH_H
Oh, we don't need to copy the whole thing. I was thinking about something like:
diff --git a/tools/lib/lockdep/uinclude/linux/unaligned/packed_struct.h b/tools/lib/lockdep/uinclude/linux/unaligned/packed_struct.h
new file mode 100644
index 0000000..7b204fc
--- /dev/null
+++ b/tools/lib/lockdep/uinclude/linux/unaligned/packed_struct.h
@@ -0,0 +1,2 @@
+#include "../../../include/linux/unaligned/packed_struct.h"
for both packed_struct.h and jhash.h. This was we get the advantage of having any
fixes to those headers automatically go into liblockdep as well.
Thanks,
Sasha
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-06-14 18:45 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-14 10:49 [PATCH v2 1/2] liblockdep: Fix compile errors Vishal Thanki
2016-06-14 10:49 ` [PATCH v2 2/2] liblockdep: Remove -lpthread compiler option Vishal Thanki
2016-06-14 18:44 ` [PATCH v2 1/2] liblockdep: Fix compile errors Sasha Levin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).