diff options
author | Mauro Carvalho Chehab <mchehab@redhat.com> | 2012-10-17 08:32:49 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2012-10-17 08:32:49 -0400 |
commit | 214e2ca2b82d335935a861c253fe94c61ad77aad (patch) | |
tree | eee42ff74d10470789d919b8499737ad0e919360 /lib/interval_tree_test_main.c | |
parent | 1fdead8ad31d3aa833bc37739273fcde89ace93c (diff) | |
parent | ddffeb8c4d0331609ef2581d84de4d763607bd37 (diff) |
Merge tag 'v3.7-rc1' into staging/for_v3.8
Linux 3.7-rc1
* tag 'v3.7-rc1': (9579 commits)
Linux 3.7-rc1
x86, boot: Explicitly include autoconf.h for hostprogs
perf: Fix UAPI fallout
ARM: config: make sure that platforms are ordered by option string
ARM: config: sort select statements alphanumerically
UAPI: (Scripted) Disintegrate include/linux/byteorder
UAPI: (Scripted) Disintegrate include/linux
UAPI: Unexport linux/blk_types.h
UAPI: Unexport part of linux/ppp-comp.h
perf: Handle new rbtree implementation
procfs: don't need a PATH_MAX allocation to hold a string representation of an int
vfs: embed struct filename inside of names_cache allocation if possible
audit: make audit_inode take struct filename
vfs: make path_openat take a struct filename pointer
vfs: turn do_path_lookup into wrapper around struct filename variant
audit: allow audit code to satisfy getname requests from its names_list
vfs: define struct filename and have getname() return it
btrfs: Fix compilation with user namespace support enabled
userns: Fix posix_acl_file_xattr_userns gid conversion
userns: Properly print bluetooth socket uids
...
Diffstat (limited to 'lib/interval_tree_test_main.c')
-rw-r--r-- | lib/interval_tree_test_main.c | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/lib/interval_tree_test_main.c b/lib/interval_tree_test_main.c new file mode 100644 index 000000000000..b25903987f7a --- /dev/null +++ b/lib/interval_tree_test_main.c | |||
@@ -0,0 +1,105 @@ | |||
1 | #include <linux/module.h> | ||
2 | #include <linux/interval_tree.h> | ||
3 | #include <linux/random.h> | ||
4 | #include <asm/timex.h> | ||
5 | |||
6 | #define NODES 100 | ||
7 | #define PERF_LOOPS 100000 | ||
8 | #define SEARCHES 100 | ||
9 | #define SEARCH_LOOPS 10000 | ||
10 | |||
11 | static struct rb_root root = RB_ROOT; | ||
12 | static struct interval_tree_node nodes[NODES]; | ||
13 | static u32 queries[SEARCHES]; | ||
14 | |||
15 | static struct rnd_state rnd; | ||
16 | |||
17 | static inline unsigned long | ||
18 | search(unsigned long query, struct rb_root *root) | ||
19 | { | ||
20 | struct interval_tree_node *node; | ||
21 | unsigned long results = 0; | ||
22 | |||
23 | for (node = interval_tree_iter_first(root, query, query); node; | ||
24 | node = interval_tree_iter_next(node, query, query)) | ||
25 | results++; | ||
26 | return results; | ||
27 | } | ||
28 | |||
29 | static void init(void) | ||
30 | { | ||
31 | int i; | ||
32 | for (i = 0; i < NODES; i++) { | ||
33 | u32 a = prandom32(&rnd), b = prandom32(&rnd); | ||
34 | if (a <= b) { | ||
35 | nodes[i].start = a; | ||
36 | nodes[i].last = b; | ||
37 | } else { | ||
38 | nodes[i].start = b; | ||
39 | nodes[i].last = a; | ||
40 | } | ||
41 | } | ||
42 | for (i = 0; i < SEARCHES; i++) | ||
43 | queries[i] = prandom32(&rnd); | ||
44 | } | ||
45 | |||
46 | static int interval_tree_test_init(void) | ||
47 | { | ||
48 | int i, j; | ||
49 | unsigned long results; | ||
50 | cycles_t time1, time2, time; | ||
51 | |||
52 | printk(KERN_ALERT "interval tree insert/remove"); | ||
53 | |||
54 | prandom32_seed(&rnd, 3141592653589793238ULL); | ||
55 | init(); | ||
56 | |||
57 | time1 = get_cycles(); | ||
58 | |||
59 | for (i = 0; i < PERF_LOOPS; i++) { | ||
60 | for (j = 0; j < NODES; j++) | ||
61 | interval_tree_insert(nodes + j, &root); | ||
62 | for (j = 0; j < NODES; j++) | ||
63 | interval_tree_remove(nodes + j, &root); | ||
64 | } | ||
65 | |||
66 | time2 = get_cycles(); | ||
67 | time = time2 - time1; | ||
68 | |||
69 | time = div_u64(time, PERF_LOOPS); | ||
70 | printk(" -> %llu cycles\n", (unsigned long long)time); | ||
71 | |||
72 | printk(KERN_ALERT "interval tree search"); | ||
73 | |||
74 | for (j = 0; j < NODES; j++) | ||
75 | interval_tree_insert(nodes + j, &root); | ||
76 | |||
77 | time1 = get_cycles(); | ||
78 | |||
79 | results = 0; | ||
80 | for (i = 0; i < SEARCH_LOOPS; i++) | ||
81 | for (j = 0; j < SEARCHES; j++) | ||
82 | results += search(queries[j], &root); | ||
83 | |||
84 | time2 = get_cycles(); | ||
85 | time = time2 - time1; | ||
86 | |||
87 | time = div_u64(time, SEARCH_LOOPS); | ||
88 | results = div_u64(results, SEARCH_LOOPS); | ||
89 | printk(" -> %llu cycles (%lu results)\n", | ||
90 | (unsigned long long)time, results); | ||
91 | |||
92 | return -EAGAIN; /* Fail will directly unload the module */ | ||
93 | } | ||
94 | |||
95 | static void interval_tree_test_exit(void) | ||
96 | { | ||
97 | printk(KERN_ALERT "test exit\n"); | ||
98 | } | ||
99 | |||
100 | module_init(interval_tree_test_init) | ||
101 | module_exit(interval_tree_test_exit) | ||
102 | |||
103 | MODULE_LICENSE("GPL"); | ||
104 | MODULE_AUTHOR("Michel Lespinasse"); | ||
105 | MODULE_DESCRIPTION("Interval Tree test"); | ||