From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755487AbcBWW0N (ORCPT ); Tue, 23 Feb 2016 17:26:13 -0500 Received: from smtprelay0070.hostedemail.com ([216.40.44.70]:34826 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752099AbcBWW0M (ORCPT ); Tue, 23 Feb 2016 17:26:12 -0500 X-Session-Marker: 726F737465647440676F6F646D69732E6F7267 X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,rostedt@goodmis.org,:::::,RULES_HIT:41:355:379:541:599:800:960:973:988:989:1260:1277:1311:1313:1314:1345:1359:1437:1515:1516:1518:1534:1542:1593:1594:1711:1730:1747:1777:1792:2393:2553:2559:2562:2693:3138:3139:3140:3141:3142:3354:3622:3865:3867:3870:3871:4250:4321:4605:5007:6261:7875:7904:9010:10004:10400:10848:10967:11026:11232:11658:11914:12043:12114:12291:12296:12438:12517:12519:12555:12740:13138:13231:14096:14097:14659:21080:30054:30064:30090:30091,0,RBL:error,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:error,Custom_rules:0:0:0,LFtime:2000,LUA_SUMMARY:none X-HE-Tag: hill37_359813fbc300b X-Filterd-Recvd-Size: 2925 Date: Tue, 23 Feb 2016 17:26:07 -0500 From: Steven Rostedt To: Josef Bacik Cc: , Subject: Re: [PATCH] trace-cmd: add trace_hash_find_reverse Message-ID: <20160223172607.5d377d2a@gandalf.local.home> In-Reply-To: <1450196004-1899-1-git-send-email-jbacik@fb.com> References: <1450196004-1899-1-git-send-email-jbacik@fb.com> X-Mailer: Claws Mail 3.13.1 (GTK+ 2.24.29; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 15 Dec 2015 11:13:24 -0500 Josef Bacik 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 > --- > 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; > +}