All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] trace-cmd: add trace_hash_find_reverse
@ 2015-12-15 16:13 Josef Bacik
  2016-02-23 22:26 ` Steven Rostedt
  0 siblings, 1 reply; 3+ messages in thread
From: Josef Bacik @ 2015-12-15 16:13 UTC (permalink / raw)
  To: kernel-team, linux-kernel, rostedt

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 <jbacik@fb.com>
---
 list.h       |  5 +++++
 trace-hash.c | 22 ++++++++++++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/list.h b/list.h
index 9817871..93c64f5 100644
--- a/list.h
+++ b/list.h
@@ -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 */
diff --git a/trace-hash.c b/trace-hash.c
index 5ffe61c..0dc4f73 100644
--- a/trace-hash.c
+++ b/trace-hash.c
@@ -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;
+}
-- 
2.5.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] trace-cmd: add trace_hash_find_reverse
  2015-12-15 16:13 [PATCH] trace-cmd: add trace_hash_find_reverse Josef Bacik
@ 2016-02-23 22:26 ` Steven Rostedt
  2016-02-24 18:25   ` Josef Bacik
  0 siblings, 1 reply; 3+ messages in thread
From: Steven Rostedt @ 2016-02-23 22:26 UTC (permalink / raw)
  To: Josef Bacik; +Cc: kernel-team, linux-kernel

On Tue, 15 Dec 2015 11:13:24 -0500
Josef Bacik <jbacik@fb.com> 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 <jbacik@fb.com>
> ---
>  list.h       |  5 +++++
>  trace-hash.c | 22 ++++++++++++++++++++++
>  2 files changed, 27 insertions(+)
> 
> diff --git a/list.h b/list.h
> index 9817871..93c64f5 100644
> --- a/list.h
> +++ b/list.h
> @@ -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 */
> diff --git a/trace-hash.c b/trace-hash.c
> index 5ffe61c..0dc4f73 100644
> --- a/trace-hash.c
> +++ b/trace-hash.c
> @@ -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) {

Strange, this doesn't compile.

 "struct trace_hash_item has no member named list"

-- Steve

> +		if (item->key == key) {
> +			if (!match)
> +				return item;
> +			if (match(item, data))
> +				return item;
> +		}
> +	}
> +
> +	return NULL;
> +}

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] trace-cmd: add trace_hash_find_reverse
  2016-02-23 22:26 ` Steven Rostedt
@ 2016-02-24 18:25   ` Josef Bacik
  0 siblings, 0 replies; 3+ messages in thread
From: Josef Bacik @ 2016-02-24 18:25 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: kernel-team, linux-kernel

On 02/23/2016 05:26 PM, Steven Rostedt wrote:
> On Tue, 15 Dec 2015 11:13:24 -0500
> Josef Bacik <jbacik@fb.com> 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 <jbacik@fb.com>
>> ---
>>   list.h       |  5 +++++
>>   trace-hash.c | 22 ++++++++++++++++++++++
>>   2 files changed, 27 insertions(+)
>>
>> diff --git a/list.h b/list.h
>> index 9817871..93c64f5 100644
>> --- a/list.h
>> +++ b/list.h
>> @@ -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 */
>> diff --git a/trace-hash.c b/trace-hash.c
>> index 5ffe61c..0dc4f73 100644
>> --- a/trace-hash.c
>> +++ b/trace-hash.c
>> @@ -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) {
>
> Strange, this doesn't compile.
>
>   "struct trace_hash_item has 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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-02-24 18:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-15 16:13 [PATCH] trace-cmd: add trace_hash_find_reverse Josef Bacik
2016-02-23 22:26 ` Steven Rostedt
2016-02-24 18:25   ` Josef Bacik

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.