Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751272AbdIPJ0P (ORCPT ); Sat, 16 Sep 2017 05:26:15 -0400 Received: from smtprelay0197.hostedemail.com ([216.40.44.197]:45392 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750909AbdIPJ0O (ORCPT ); Sat, 16 Sep 2017 05:26:14 -0400 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::::,RULES_HIT:41:355:379:541:599:800:960:966:973:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1381:1437:1515:1516:1518:1534:1542:1593:1594:1711:1730:1747:1777:1792:2196:2199:2393:2559:2562:2828:3138:3139:3140:3141:3142:3354:3622:3865:3866:3867:3872:3873:4321:4385:4605:5007:7875:8527:10004:10400:10848:10903:11026:11232:11473:11658:11914:12048:12296:12438:12555:12740:12895:13180:13229:13439:13894:14181:14659:14721:21080:21324:21451:21611:21627:30029:30054:30070:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:2,LUA_SUMMARY:none X-HE-Tag: cream64_8d70a65bcfe13 X-Filterd-Recvd-Size: 3208 Message-ID: <1505553970.16316.1.camel@perches.com> Subject: Re: [PATCH V2] tipc: Use bsearch library function From: Joe Perches To: Ying Xue , Thomas Meyer , jon.maloy@ericsson.com, netdev@vger.kernel.org, tipc-discussion@lists.sourceforge.net, linux-kernel@vger.kernel.org, davem@davemloft.net Date: Sat, 16 Sep 2017 02:26:10 -0700 In-Reply-To: <16128f5e-66ff-b6ec-c0e1-74ea08c212b0@windriver.com> References: <20170911.143025.555018840006192902.davem@davemloft.net> <20170916075036.28676-1-thomas@m3y3r.de> <16128f5e-66ff-b6ec-c0e1-74ea08c212b0@windriver.com> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.22.6-1ubuntu1 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2169 Lines: 73 On Sat, 2017-09-16 at 17:02 +0800, Ying Xue wrote: > On 09/16/2017 03:50 PM, Thomas Meyer wrote: > > Use common library function rather than explicitly coding > > some variant of it yourself. > > > > Signed-off-by: Thomas Meyer > > Acked-by: Ying Xue Are you sure you want to do this? Note the comment above nameseq_find_subseq ?* Very time-critical, so binary searches through sub-sequence array. What impact does this change have on performance? > > diff --git a/net/tipc/name_table.c b/net/tipc/name_table.c > > index bd0aac87b41a..eeb4d7a13de2 100644 > > --- a/net/tipc/name_table.c > > +++ b/net/tipc/name_table.c > > @@ -44,6 +44,7 @@ > > #include "addr.h" > > #include "node.h" > > #include > > +#include > > > > #define TIPC_NAMETBL_SIZE 1024 /* must be a power of 2 */ > > > > @@ -168,6 +169,18 @@ static struct name_seq *tipc_nameseq_create(u32 type, struct hlist_head *seq_hea > > return nseq; > > } > > > > +static int nameseq_find_subseq_cmp(const void *key, const void *elt) > > +{ > > + struct sub_seq *sseq = (struct sub_seq *)elt; > > + u32 instance = *(u32 *)key; > > + > > + if (instance < sseq->lower) > > + return -1; > > + else if (instance > sseq->upper) > > + return 1; > > + return 0; > > +} > > + > > /** > > * nameseq_find_subseq - find sub-sequence (if any) matching a name instance > > * > > @@ -176,21 +189,8 @@ static struct name_seq *tipc_nameseq_create(u32 type, struct hlist_head *seq_hea > > static struct sub_seq *nameseq_find_subseq(struct name_seq *nseq, > > u32 instance) > > { > > - struct sub_seq *sseqs = nseq->sseqs; > > - int low = 0; > > - int high = nseq->first_free - 1; > > - int mid; > > - > > - while (low <= high) { > > - mid = (low + high) / 2; > > - if (instance < sseqs[mid].lower) > > - high = mid - 1; > > - else if (instance > sseqs[mid].upper) > > - low = mid + 1; > > - else > > - return &sseqs[mid]; > > - } > > - return NULL; > > + return bsearch(&instance, nseq->sseqs, nseq->first_free, > > + sizeof(struct sub_seq), nameseq_find_subseq_cmp); > > } > > > > /** > >