trace-cmd: add trace_hash_find_reverse
PATCH 1/1 trace-cmd: add trace_hash_find_reverse
Sometimes we want to FIFO identical entries in the hash table, so add trace_hash_find_reverse, which will cycle through the hash list in reverse. This is helpful in our case where we are monitoring block request issues to match with their corresponding completes, if we issue multiple times to the same block we want to be able to match them with the correct completes (more or less anyway). Thanks,
--- list.h | 5 +++++ trace-hash.c | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+)
list.h +5 -0
@@ -79,4 +79,9 @@ static inline int list_empty(struct list_head *list) &(p)->field != list; \ p = n, n = container_of((p)->field.next, typeof(*p), field)) +#define list_for_each_entry_reverse (p, list, field) \ + for (p = container_of((list)->prev, typeof(*p), field); \ + &p->field != list; \ + p = container_of((p)->field.prev, typeof(*p), field)) +#endif /* __LIST_H */
trace-hash.c +22 -0
@@ -94,3 +94,25 @@ trace_hash_find(struct trace_hash *hash, unsigned long long key,return NULL ; } + +struct trace_hash_item * +trace_hash_find_reverse (struct trace_hash *hash,unsigned long long key, +trace_hash_func match,void *data) +{ +struct trace_hash_item *item; +struct list_head *bucket; +int bucket_nr = hash->power ? key & hash->power : + key % hash->nr_buckets; + + bucket = hash->buckets + bucket_nr; +list_for_each_entry_reverse (item, bucket, list) { +if (item->key == key) { +if (!match) +return item; +if (match (item, data)) +return item; + } + } + +return NULL ; +}
Signature · 1 line
2.5.0
Quoted 37 lines · On Tue, 15 Dec 2015 11:13:24 -0500 Josef Bacik <[email protected]> wrote:
Sometimes we want to FIFO identical entries in the hash table, so add
trace_hash_find_reverse, which will cycle through the hash list in reverse. This is helpful in our case where we are monitoring block request issues to match with their corresponding completes, if we issue multiple times to the same block we want to be able to match them with the correct completes (more or less anyway). Thanks,Signed-off-by Josef Bacik <[email protected]>--- list.h | 5 +++++ trace-hash.c | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+)list.h +5
-0@@ -79,4 +79,9 @@ static inline int list_empty(struct list_head *list) &(p)->field != list; \ p = n, n = container_of((p)->field.next, typeof(*p), field)) +#define list_for_each_entry_reverse (p, list, field) \ + for (p = container_of((list)->prev, typeof(*p), field); \ + &p->field != list; \ + p = container_of((p)->field.prev, typeof(*p), field)) +#endif /* __LIST_H */ trace-hash.c +2
-0@@ -94,3 +94,25 @@ trace_hash_find(struct trace_hash *hash, unsigned long long key,return NULL ; } + +struct trace_hash_item *
trace-hash.c trace_hash_find(struct trace_hash *hash, unsigned long long key, · line 108
Quoted 10 lines
trace-hash.c +10
-0+trace_hash_find_reverse(struct trace_hash *hash, unsigned long long key, + trace_hash_func match, void *data) +{ + struct trace_hash_item *item; +struct list_head *bucket; +int bucket_nr = hash->power ? key & hash->power : + key % hash->nr_buckets; + + bucket = hash->buckets + bucket_nr; +list_for_each_entry_reverse (item, bucket, list) {
Strange, this doesn't compile.
"struct trace_hash_item has no member named list"
-- Steve
Quoted 10 lines
trace-hash.c +10
-0+if (item->key == key) { +if (!match) +return item; +if (match (item, data)) +return item; + } + } + +return NULL ; +}
Quoted 53 lines · Steven Rostedt
Quoted 37 lines · On Tue, 15 Dec 2015 11:13:24 -0500 Josef Bacik <[email protected]> wrote:
Sometimes we want to FIFO identical entries in the hash table, so add
trace_hash_find_reverse, which will cycle through the hash list in reverse. This is helpful in our case where we are monitoring block request issues to match with their corresponding completes, if we issue multiple times to the same block we want to be able to match them with the correct completes (more or less anyway). Thanks,Signed-off-by Josef Bacik <[email protected]>--- list.h | 5 +++++ trace-hash.c | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+)list.h +5
-0@@ -79,4 +79,9 @@ static inline int list_empty(struct list_head *list) &(p)->field != list; \ p = n, n = container_of((p)->field.next, typeof(*p), field)) +#define list_for_each_entry_reverse (p, list, field) \ + for (p = container_of((list)->prev, typeof(*p), field); \ + &p->field != list; \ + p = container_of((p)->field.prev, typeof(*p), field)) +#endif /* __LIST_H */ trace-hash.c +2
-0@@ -94,3 +94,25 @@ trace_hash_find(struct trace_hash *hash, unsigned long long key,return NULL ; } + +struct trace_hash_item *trace-hash.c trace_hash_find(struct trace_hash *hash, unsigned long long key, · line 108
Quoted 10 lines
trace-hash.c +10
-0+trace_hash_find_reverse(struct trace_hash *hash, unsigned long long key, + trace_hash_func match, void *data) +{ + struct trace_hash_item *item; +struct list_head *bucket; +int bucket_nr = hash->power ? key & hash->power : + key % hash->nr_buckets; + + bucket = hash->buckets + bucket_nr; +list_for_each_entry_reverse (item, bucket, list) {Strange, this doesn't compile.
Quoted 2 lines
"struct
trace_hash_itemhas no member named list"
Sorry I sent out the wrong version of this patch. I don't actually need this anymore so you can just drop it. Thanks,
Josef