Re: [PATCH] perf lock: Implement basic sorting function of perf lock

Hitoshi Mitake
2010-01-08T08:34:06Z

On 2009年12月28日 20:01, Peter Zijlstra wrote:
> On Sun, 2009-12-20 at 11:56 +0900, Hitoshi Mitake wrote:
>> +static struct lock_stat *lock_stat_findnew(void *addr, const char *name)
>> +{
>> + struct list_head *entry = lockhashentry(addr);
>> + struct lock_stat *ret, *new;
>
>
> Right, so you use a hash table to match lock instances, I suppose that's
> faster than an rb-tree?

Maybe. But it is hard to determine which data structure is better.
This is a histogram from perf.data produced by "perf bench sched messaging",

(left is length of list, right is number of list whose length is value
of left)
0: 3333
1: 153
2: 91
3: 114
4: 96
5: 75
6: 61
7: 43
8: 29
9: 32
10: 23
11: 15
12: 9
13: 5
14: 7
15: 3
16: 1
17: 3
18: 0
19: 3 # 19 means "longer than 19"

Total number of lock instances is 3459,
so if perf lock use rb-tree for storing info of lock instances,
average order of accessing stored node is lg 4096 == 12.
And the histogram above describes,
there are relatively very few lists with length over 12.
So I think hash list is better thing for storing info of lock instances
than rb-tree.
(Sorting result is another issue, of course.)

>
> Do you also remove instances after a match to keep the hash relatively
> small?
>
>

No, I don't.
At the last phase of profiling,
perf lock makes rb-tree sorted by the key user specified.

static void sort_result(void)
{
unsigned int i;
struct lock_stat *st;

for (i = 0; i < LOCKHASH_SIZE; i++) {
list_for_each_entry(st, &lockhash_table[i], hash_entry) {
insert_to_result(st, compare); # insert to rb-tree
}
}
}

As this code describes,
referencing the completed hash list is done only once.
So removing instances to keep the hash list relatively small
is not required, I think.