All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tipc: Use bsearch library function
@ 2017-09-09  3:18 Thomas Meyer
  2017-09-11 21:30 ` David Miller
  0 siblings, 1 reply; 21+ messages in thread
From: Thomas Meyer @ 2017-09-09  3:18 UTC (permalink / raw)
  To: jon.maloy, ying.xue, davem, netdev, tipc-discussion, linux-kernel
  Cc: Thomas Meyer

Use common library function rather than explicitly coding
some variant of it yourself.

Signed-off-by: Thomas Meyer <thomas@m3y3r.de>
---
 net/tipc/name_table.c | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/net/tipc/name_table.c b/net/tipc/name_table.c
index bd0aac87b41a..345454106390 100644
--- a/net/tipc/name_table.c
+++ b/net/tipc/name_table.c
@@ -44,6 +44,7 @@
 #include "addr.h"
 #include "node.h"
 #include <net/genetlink.h>
+#include <linux/bsearch.h>
 
 #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)
+{
+	u32 instance = *(u32 *)key;
+	struct sub_seq *sseq = (struct sub_seq *)elt;
+
+	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);
 }
 
 /**
-- 
2.11.0

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

* Re: [PATCH] tipc: Use bsearch library function
  2017-09-09  3:18 [PATCH] tipc: Use bsearch library function Thomas Meyer
@ 2017-09-11 21:30 ` David Miller
  2017-09-12  9:24     ` David Laight
  2017-09-16  7:50   ` [PATCH V2] " Thomas Meyer
  0 siblings, 2 replies; 21+ messages in thread
From: David Miller @ 2017-09-11 21:30 UTC (permalink / raw)
  To: thomas; +Cc: jon.maloy, ying.xue, netdev, tipc-discussion, linux-kernel

From: Thomas Meyer <thomas@m3y3r.de>
Date: Sat,  9 Sep 2017 05:18:19 +0200

> @@ -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)
> +{
> +	u32 instance = *(u32 *)key;
> +	struct sub_seq *sseq = (struct sub_seq *)elt;

Please order local variables from longest to shortest (ie. reverse
christmas tree).

Thank you.

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

* RE: [PATCH] tipc: Use bsearch library function
  2017-09-11 21:30 ` David Miller
@ 2017-09-12  9:24     ` David Laight
  2017-09-16  7:50   ` [PATCH V2] " Thomas Meyer
  1 sibling, 0 replies; 21+ messages in thread
From: David Laight @ 2017-09-12  9:24 UTC (permalink / raw)
  To: 'David Miller', thomas
  Cc: jon.maloy, ying.xue, netdev, tipc-discussion, linux-kernel

From: David Miller
> Sent: 11 September 2017 22:30
> From: Thomas Meyer <thomas@m3y3r.de>
> Date: Sat,  9 Sep 2017 05:18:19 +0200
> 
> > @@ -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)
> > +{
> > +	u32 instance = *(u32 *)key;
> > +	struct sub_seq *sseq = (struct sub_seq *)elt;
> 
> Please order local variables from longest to shortest (ie. reverse
> christmas tree).

You probably just need to remove the unnecessary cast of 'void *'.
Although adding the 'const' qualifier will make it wrong again.

You probably ought to make the 'key' a structure - even if it only
contains a single u32.
Casting pointers to numeric types is often wrong.

	David

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

* RE: [PATCH] tipc: Use bsearch library function
@ 2017-09-12  9:24     ` David Laight
  0 siblings, 0 replies; 21+ messages in thread
From: David Laight @ 2017-09-12  9:24 UTC (permalink / raw)
  To: 'David Miller', thomas
  Cc: jon.maloy, ying.xue, netdev, tipc-discussion, linux-kernel

From: David Miller
> Sent: 11 September 2017 22:30
> From: Thomas Meyer <thomas@m3y3r.de>
> Date: Sat,  9 Sep 2017 05:18:19 +0200
> 
> > @@ -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)
> > +{
> > +	u32 instance = *(u32 *)key;
> > +	struct sub_seq *sseq = (struct sub_seq *)elt;
> 
> Please order local variables from longest to shortest (ie. reverse
> christmas tree).

You probably just need to remove the unnecessary cast of 'void *'.
Although adding the 'const' qualifier will make it wrong again.

You probably ought to make the 'key' a structure - even if it only
contains a single u32.
Casting pointers to numeric types is often wrong.

	David

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

* [PATCH V2] tipc: Use bsearch library function
  2017-09-11 21:30 ` David Miller
  2017-09-12  9:24     ` David Laight
@ 2017-09-16  7:50   ` Thomas Meyer
  2017-09-16  9:02     ` Ying Xue
  1 sibling, 1 reply; 21+ messages in thread
From: Thomas Meyer @ 2017-09-16  7:50 UTC (permalink / raw)
  To: jon.maloy, ying.xue, netdev, tipc-discussion, linux-kernel, davem
  Cc: Thomas Meyer

Use common library function rather than explicitly coding
some variant of it yourself.

Signed-off-by: Thomas Meyer <thomas@m3y3r.de>
---
 net/tipc/name_table.c | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

V2: Coding style

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 <net/genetlink.h>
+#include <linux/bsearch.h>
 
 #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);
 }
 
 /**
-- 
2.11.0

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

* Re: [PATCH V2] tipc: Use bsearch library function
  2017-09-16  7:50   ` [PATCH V2] " Thomas Meyer
@ 2017-09-16  9:02     ` Ying Xue
  2017-09-16  9:26       ` Joe Perches
  0 siblings, 1 reply; 21+ messages in thread
From: Ying Xue @ 2017-09-16  9:02 UTC (permalink / raw)
  To: Thomas Meyer, jon.maloy, netdev, tipc-discussion, linux-kernel, davem

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 <thomas@m3y3r.de>

Acked-by: Ying Xue <ying.xue@windriver.com>

> ---
>  net/tipc/name_table.c | 30 +++++++++++++++---------------
>  1 file changed, 15 insertions(+), 15 deletions(-)
> 
> V2: Coding style
> 
> 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 <net/genetlink.h>
> +#include <linux/bsearch.h>
>  
>  #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);
>  }
>  
>  /**
> 

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

* Re: [PATCH V2] tipc: Use bsearch library function
  2017-09-16  9:02     ` Ying Xue
@ 2017-09-16  9:26       ` Joe Perches
  2017-09-16  9:36         ` Ying Xue
  0 siblings, 1 reply; 21+ messages in thread
From: Joe Perches @ 2017-09-16  9:26 UTC (permalink / raw)
  To: Ying Xue, Thomas Meyer, jon.maloy, netdev, tipc-discussion,
	linux-kernel, davem

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 <thomas@m3y3r.de>
> 
> Acked-by: Ying Xue <ying.xue@windriver.com>

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 <net/genetlink.h>
> > +#include <linux/bsearch.h>
> >  
> >  #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);
> >  }
> >  
> >  /**
> > 

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

* Re: [PATCH V2] tipc: Use bsearch library function
  2017-09-16  9:26       ` Joe Perches
@ 2017-09-16  9:36         ` Ying Xue
  2017-09-16  9:58           ` Joe Perches
  0 siblings, 1 reply; 21+ messages in thread
From: Ying Xue @ 2017-09-16  9:36 UTC (permalink / raw)
  To: Joe Perches, Thomas Meyer, jon.maloy, netdev, tipc-discussion,
	linux-kernel, davem

On 09/16/2017 05:26 PM, Joe Perches wrote:
> 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 <thomas@m3y3r.de>
>>
>> Acked-by: Ying Xue <ying.xue@windriver.com>
> 
> 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?

Sorry, I couldn't see any essential difference between this new
implementation and the original one except that the former tries to use
the library function - bsearch() to replace the original binary search
algorithm implemented in TIPC itself. Therefore, I don't think the
change will have a big impact on performance.

If I miss something, please let me know.

Thanks,
Ying

> 
>>> 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 <net/genetlink.h>
>>> +#include <linux/bsearch.h>
>>>  
>>>  #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);
>>>  }
>>>  
>>>  /**
>>>
> 

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

* Re: [PATCH V2] tipc: Use bsearch library function
  2017-09-16  9:36         ` Ying Xue
@ 2017-09-16  9:58           ` Joe Perches
  2017-09-16 10:10             ` Ying Xue
  0 siblings, 1 reply; 21+ messages in thread
From: Joe Perches @ 2017-09-16  9:58 UTC (permalink / raw)
  To: Ying Xue, Thomas Meyer, jon.maloy, netdev, tipc-discussion,
	linux-kernel, davem

On Sat, 2017-09-16 at 17:36 +0800, Ying Xue wrote:
> On 09/16/2017 05:26 PM, Joe Perches wrote:
> > 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 <thomas@m3y3r.de>
> > > 
> > > Acked-by: Ying Xue <ying.xue@windriver.com>
> > 
> > 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?
> 
> Sorry, I couldn't see any essential difference between this new
> implementation and the original one except that the former tries to use
> the library function - bsearch() to replace the original binary search
> algorithm implemented in TIPC itself. Therefore, I don't think the
> change will have a big impact on performance.
> 
> If I miss something, please let me know.

Comparison via a function pointer in bsearch is slower
than direct code without the function call overhead.

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

* Re: [PATCH V2] tipc: Use bsearch library function
  2017-09-16  9:58           ` Joe Perches
@ 2017-09-16 10:10             ` Ying Xue
  2017-09-16 10:17               ` Joe Perches
  0 siblings, 1 reply; 21+ messages in thread
From: Ying Xue @ 2017-09-16 10:10 UTC (permalink / raw)
  To: Joe Perches, Thomas Meyer, jon.maloy, netdev, tipc-discussion,
	linux-kernel, davem

On 09/16/2017 05:58 PM, Joe Perches wrote:
> On Sat, 2017-09-16 at 17:36 +0800, Ying Xue wrote:
>> On 09/16/2017 05:26 PM, Joe Perches wrote:
>>> 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 <thomas@m3y3r.de>
>>>>
>>>> Acked-by: Ying Xue <ying.xue@windriver.com>
>>>
>>> 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?
>>
>> Sorry, I couldn't see any essential difference between this new
>> implementation and the original one except that the former tries to use
>> the library function - bsearch() to replace the original binary search
>> algorithm implemented in TIPC itself. Therefore, I don't think the
>> change will have a big impact on performance.
>>
>> If I miss something, please let me know.
> 
> Comparison via a function pointer in bsearch is slower
> than direct code without the function call overhead.
> 

Right, but probably we can tolerate the slight sacrifice here.

> 

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

* Re: [PATCH V2] tipc: Use bsearch library function
  2017-09-16 10:10             ` Ying Xue
@ 2017-09-16 10:17               ` Joe Perches
  2017-09-16 13:20                   ` Jon Maloy
  0 siblings, 1 reply; 21+ messages in thread
From: Joe Perches @ 2017-09-16 10:17 UTC (permalink / raw)
  To: Ying Xue, Thomas Meyer, jon.maloy, netdev, tipc-discussion,
	linux-kernel, davem

On Sat, 2017-09-16 at 18:10 +0800, Ying Xue wrote:
> On 09/16/2017 05:58 PM, Joe Perches wrote:
> > On Sat, 2017-09-16 at 17:36 +0800, Ying Xue wrote:
> > > On 09/16/2017 05:26 PM, Joe Perches wrote:
> > > > 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 <thomas@m3y3r.de>
> > > > > 
> > > > > Acked-by: Ying Xue <ying.xue@windriver.com>
> > > > 
> > > > 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?
> > > 
> > > Sorry, I couldn't see any essential difference between this new
> > > implementation and the original one except that the former tries to use
> > > the library function - bsearch() to replace the original binary search
> > > algorithm implemented in TIPC itself. Therefore, I don't think the
> > > change will have a big impact on performance.
> > > 
> > > If I miss something, please let me know.
> > 
> > Comparison via a function pointer in bsearch is slower
> > than direct code without the function call overhead.
> > 
> 
> Right, but probably we can tolerate the slight sacrifice here.

What part of "very time critical" have you verified
and benchmarked as inconsequential?

Please post your results.

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

* RE: [PATCH V2] tipc: Use bsearch library function
  2017-09-16 10:17               ` Joe Perches
@ 2017-09-16 13:20                   ` Jon Maloy
  0 siblings, 0 replies; 21+ messages in thread
From: Jon Maloy @ 2017-09-16 13:20 UTC (permalink / raw)
  To: Joe Perches, Ying Xue, Thomas Meyer, netdev, tipc-discussion,
	linux-kernel, davem



> -----Original Message-----
> From: netdev-owner@vger.kernel.org [mailto:netdev-
> owner@vger.kernel.org] On Behalf Of Joe Perches
> Sent: Saturday, September 16, 2017 06:18
> To: Ying Xue <ying.xue@windriver.com>; Thomas Meyer
> <thomas@m3y3r.de>; Jon Maloy <jon.maloy@ericsson.com>;
> netdev@vger.kernel.org; tipc-discussion@lists.sourceforge.net; linux-
> kernel@vger.kernel.org; davem@davemloft.net
> Subject: Re: [PATCH V2] tipc: Use bsearch library function
> 
> On Sat, 2017-09-16 at 18:10 +0800, Ying Xue wrote:
> > On 09/16/2017 05:58 PM, Joe Perches wrote:
> > > On Sat, 2017-09-16 at 17:36 +0800, Ying Xue wrote:
> > > > On 09/16/2017 05:26 PM, Joe Perches wrote:
> > > > > 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 <thomas@m3y3r.de>
> > > > > >
> > > > > > Acked-by: Ying Xue <ying.xue@windriver.com>
> > > > >
> > > > > 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?
> > > >
> > > > Sorry, I couldn't see any essential difference between this new
> > > > implementation and the original one except that the former tries
> > > > to use the library function - bsearch() to replace the original
> > > > binary search algorithm implemented in TIPC itself. Therefore, I
> > > > don't think the change will have a big impact on performance.
> > > >
> > > > If I miss something, please let me know.
> > >
> > > Comparison via a function pointer in bsearch is slower than direct
> > > code without the function call overhead.
> > >
> >
> > Right, but probably we can tolerate the slight sacrifice here.
> 
> What part of "very time critical" have you verified and benchmarked as
> inconsequential?
> 
> Please post your results.

I agree with Joe here. This change does not simplify anything, it does not reduce the amount of code, plus that it introduce an unnecessary outline call in a place where we have every reason to let the compiler do its optimization job properly.

///jon

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

* RE: [PATCH V2] tipc: Use bsearch library function
@ 2017-09-16 13:20                   ` Jon Maloy
  0 siblings, 0 replies; 21+ messages in thread
From: Jon Maloy @ 2017-09-16 13:20 UTC (permalink / raw)
  To: Joe Perches, Ying Xue, Thomas Meyer, netdev, tipc-discussion,
	linux-kernel, davem



> -----Original Message-----
> From: netdev-owner@vger.kernel.org [mailto:netdev-
> owner@vger.kernel.org] On Behalf Of Joe Perches
> Sent: Saturday, September 16, 2017 06:18
> To: Ying Xue <ying.xue@windriver.com>; Thomas Meyer
> <thomas@m3y3r.de>; Jon Maloy <jon.maloy@ericsson.com>;
> netdev@vger.kernel.org; tipc-discussion@lists.sourceforge.net; linux-
> kernel@vger.kernel.org; davem@davemloft.net
> Subject: Re: [PATCH V2] tipc: Use bsearch library function
> 
> On Sat, 2017-09-16 at 18:10 +0800, Ying Xue wrote:
> > On 09/16/2017 05:58 PM, Joe Perches wrote:
> > > On Sat, 2017-09-16 at 17:36 +0800, Ying Xue wrote:
> > > > On 09/16/2017 05:26 PM, Joe Perches wrote:
> > > > > 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 <thomas@m3y3r.de>
> > > > > >
> > > > > > Acked-by: Ying Xue <ying.xue@windriver.com>
> > > > >
> > > > > 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?
> > > >
> > > > Sorry, I couldn't see any essential difference between this new
> > > > implementation and the original one except that the former tries
> > > > to use the library function - bsearch() to replace the original
> > > > binary search algorithm implemented in TIPC itself. Therefore, I
> > > > don't think the change will have a big impact on performance.
> > > >
> > > > If I miss something, please let me know.
> > >
> > > Comparison via a function pointer in bsearch is slower than direct
> > > code without the function call overhead.
> > >
> >
> > Right, but probably we can tolerate the slight sacrifice here.
> 
> What part of "very time critical" have you verified and benchmarked as
> inconsequential?
> 
> Please post your results.

I agree with Joe here. This change does not simplify anything, it does not reduce the amount of code, plus that it introduce an unnecessary outline call in a place where we have every reason to let the compiler do its optimization job properly.

///jon

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

* Re: [PATCH V2] tipc: Use bsearch library function
  2017-09-16 13:20                   ` Jon Maloy
@ 2017-09-17 15:00                     ` Thomas Meyer
  -1 siblings, 0 replies; 21+ messages in thread
From: Thomas Meyer @ 2017-09-17 15:00 UTC (permalink / raw)
  To: Jon Maloy
  Cc: Joe Perches, Ying Xue, netdev, tipc-discussion, linux-kernel, davem

[-- Attachment #1: Type: text/plain, Size: 717 bytes --]


> Am 16.09.2017 um 15:20 schrieb Jon Maloy <jon.maloy@ericsson.com>.
>> 
>> What part of "very time critical" have you verified and benchmarked as
>> inconsequential?
>> 
>> Please post your results.
> 
> I agree with Joe here. This change does not simplify anything, it does not reduce the amount of code, plus that it introduce an unnecessary outline call in a place where we have every reason to let the compiler do its optimization job properly.

Hi,

Okay, should I prepare some performance numbers or do we NAK this change?
What about the other binary search implementation in the same file? Should I try to convert it it will it get NAKed for performance reasons too?

With kind regards
Thomas

[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5334 bytes --]

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

* Re: [PATCH V2] tipc: Use bsearch library function
@ 2017-09-17 15:00                     ` Thomas Meyer
  0 siblings, 0 replies; 21+ messages in thread
From: Thomas Meyer @ 2017-09-17 15:00 UTC (permalink / raw)
  To: Jon Maloy
  Cc: Joe Perches, Ying Xue, netdev, tipc-discussion, linux-kernel, davem

[-- Attachment #1: Type: text/plain, Size: 717 bytes --]


> Am 16.09.2017 um 15:20 schrieb Jon Maloy <jon.maloy@ericsson.com>.
>> 
>> What part of "very time critical" have you verified and benchmarked as
>> inconsequential?
>> 
>> Please post your results.
> 
> I agree with Joe here. This change does not simplify anything, it does not reduce the amount of code, plus that it introduce an unnecessary outline call in a place where we have every reason to let the compiler do its optimization job properly.

Hi,

Okay, should I prepare some performance numbers or do we NAK this change?
What about the other binary search implementation in the same file? Should I try to convert it it will it get NAKed for performance reasons too?

With kind regards
Thomas

[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5334 bytes --]

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

* RE: [PATCH V2] tipc: Use bsearch library function
  2017-09-17 15:00                     ` Thomas Meyer
@ 2017-09-17 16:27                       ` Jon Maloy
  -1 siblings, 0 replies; 21+ messages in thread
From: Jon Maloy @ 2017-09-17 16:27 UTC (permalink / raw)
  To: Thomas Meyer
  Cc: Joe Perches, Ying Xue, netdev, tipc-discussion, linux-kernel, davem

[-- Attachment #1: Type: text/plain, Size: 1396 bytes --]



> -----Original Message-----
> From: Thomas Meyer [mailto:thomas@m3y3r.de]
> Sent: Sunday, September 17, 2017 11:00
> To: Jon Maloy <jon.maloy@ericsson.com>
> Cc: Joe Perches <joe@perches.com>; Ying Xue <ying.xue@windriver.com>;
> netdev@vger.kernel.org; tipc-discussion@lists.sourceforge.net; linux-
> kernel@vger.kernel.org; davem@davemloft.net
> Subject: Re: [PATCH V2] tipc: Use bsearch library function
> 
> 
> > Am 16.09.2017 um 15:20 schrieb Jon Maloy <jon.maloy@ericsson.com>.
> >>
> >> What part of "very time critical" have you verified and benchmarked as
> >> inconsequential?
> >>
> >> Please post your results.
> >
> > I agree with Joe here. This change does not simplify anything, it does
not
> reduce the amount of code, plus that it introduce an unnecessary outline
call
> in a place where we have every reason to let the compiler do its
optimization
> job properly.
> 
> Hi,
> 
> Okay, should I prepare some performance numbers or do we NAK this
> change?
> What about the other binary search implementation in the same file? Should
> I try to convert it it will it get NAKed for performance reasons too?

The searches for inserting and removing publications is less time critical,
so that would be ok with me.
If you have any more general interest in improving the code in this file
(which is needed) it would also be appreciated.

BR
///jon


> 
> With kind regards
> Thomas

[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 6242 bytes --]

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

* RE: [PATCH V2] tipc: Use bsearch library function
@ 2017-09-17 16:27                       ` Jon Maloy
  0 siblings, 0 replies; 21+ messages in thread
From: Jon Maloy @ 2017-09-17 16:27 UTC (permalink / raw)
  To: Thomas Meyer
  Cc: Joe Perches, Ying Xue, netdev, tipc-discussion, linux-kernel, davem

[-- Attachment #1: Type: text/plain, Size: 1396 bytes --]



> -----Original Message-----
> From: Thomas Meyer [mailto:thomas@m3y3r.de]
> Sent: Sunday, September 17, 2017 11:00
> To: Jon Maloy <jon.maloy@ericsson.com>
> Cc: Joe Perches <joe@perches.com>; Ying Xue <ying.xue@windriver.com>;
> netdev@vger.kernel.org; tipc-discussion@lists.sourceforge.net; linux-
> kernel@vger.kernel.org; davem@davemloft.net
> Subject: Re: [PATCH V2] tipc: Use bsearch library function
> 
> 
> > Am 16.09.2017 um 15:20 schrieb Jon Maloy <jon.maloy@ericsson.com>.
> >>
> >> What part of "very time critical" have you verified and benchmarked as
> >> inconsequential?
> >>
> >> Please post your results.
> >
> > I agree with Joe here. This change does not simplify anything, it does
not
> reduce the amount of code, plus that it introduce an unnecessary outline
call
> in a place where we have every reason to let the compiler do its
optimization
> job properly.
> 
> Hi,
> 
> Okay, should I prepare some performance numbers or do we NAK this
> change?
> What about the other binary search implementation in the same file? Should
> I try to convert it it will it get NAKed for performance reasons too?

The searches for inserting and removing publications is less time critical,
so that would be ok with me.
If you have any more general interest in improving the code in this file
(which is needed) it would also be appreciated.

BR
///jon


> 
> With kind regards
> Thomas

[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 6242 bytes --]

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

* Re: [PATCH V2] tipc: Use bsearch library function
  2017-09-17 16:27                       ` Jon Maloy
@ 2017-09-17 21:15                         ` Joe Perches
  -1 siblings, 0 replies; 21+ messages in thread
From: Joe Perches @ 2017-09-17 21:15 UTC (permalink / raw)
  To: Jon Maloy, Thomas Meyer
  Cc: Ying Xue, netdev, tipc-discussion, linux-kernel, davem

On Sun, 2017-09-17 at 16:27 +0000, Jon Maloy wrote:
> > -----Original Message-----
> > From: Thomas Meyer [mailto:thomas@m3y3r.de]
[]
> > What about the other binary search implementation in the same file? Should
> > I try to convert it it will it get NAKed for performance reasons too?
> 
> The searches for inserting and removing publications is less time critical,
> so that would be ok with me.
> If you have any more general interest in improving the code in this file
> (which is needed) it would also be appreciated.

Perhaps using an rbtree would be an improvement.

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

* Re: [PATCH V2] tipc: Use bsearch library function
@ 2017-09-17 21:15                         ` Joe Perches
  0 siblings, 0 replies; 21+ messages in thread
From: Joe Perches @ 2017-09-17 21:15 UTC (permalink / raw)
  To: Jon Maloy, Thomas Meyer
  Cc: Ying Xue, netdev, tipc-discussion, linux-kernel, davem

On Sun, 2017-09-17 at 16:27 +0000, Jon Maloy wrote:
> > -----Original Message-----
> > From: Thomas Meyer [mailto:thomas@m3y3r.de]
[]
> > What about the other binary search implementation in the same file? Should
> > I try to convert it it will it get NAKed for performance reasons too?
> 
> The searches for inserting and removing publications is less time critical,
> so that would be ok with me.
> If you have any more general interest in improving the code in this file
> (which is needed) it would also be appreciated.

Perhaps using an rbtree would be an improvement.

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

* RE: [PATCH V2] tipc: Use bsearch library function
  2017-09-17 21:15                         ` Joe Perches
@ 2017-09-19  1:08                           ` Jon Maloy
  -1 siblings, 0 replies; 21+ messages in thread
From: Jon Maloy @ 2017-09-19  1:08 UTC (permalink / raw)
  To: Joe Perches, Thomas Meyer
  Cc: Ying Xue, netdev, tipc-discussion, linux-kernel, davem



> -----Original Message-----
> From: netdev-owner@vger.kernel.org [mailto:netdev-
> owner@vger.kernel.org] On Behalf Of Joe Perches
> Sent: Sunday, September 17, 2017 23:15
> To: Jon Maloy <jon.maloy@ericsson.com>; Thomas Meyer
> <thomas@m3y3r.de>
> Cc: Ying Xue <ying.xue@windriver.com>; netdev@vger.kernel.org; tipc-
> discussion@lists.sourceforge.net; linux-kernel@vger.kernel.org;
> davem@davemloft.net
> Subject: Re: [PATCH V2] tipc: Use bsearch library function
> 
> On Sun, 2017-09-17 at 16:27 +0000, Jon Maloy wrote:
> > > -----Original Message-----
> > > From: Thomas Meyer [mailto:thomas@m3y3r.de]
> []
> > > What about the other binary search implementation in the same file?
> > > Should I try to convert it it will it get NAKed for performance reasons too?
> >
> > The searches for inserting and removing publications is less time
> > critical, so that would be ok with me.
> > If you have any more general interest in improving the code in this
> > file (which is needed) it would also be appreciated.
> 
> Perhaps using an rbtree would be an improvement.

Not a bad idea. It would probably reduce the code amount, possibly at the expense of cache hit rate during the binary lookup.
It is worth looking into.

///jon

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

* RE: [PATCH V2] tipc: Use bsearch library function
@ 2017-09-19  1:08                           ` Jon Maloy
  0 siblings, 0 replies; 21+ messages in thread
From: Jon Maloy @ 2017-09-19  1:08 UTC (permalink / raw)
  To: Joe Perches, Thomas Meyer
  Cc: Ying Xue, netdev, tipc-discussion, linux-kernel, davem



> -----Original Message-----
> From: netdev-owner@vger.kernel.org [mailto:netdev-
> owner@vger.kernel.org] On Behalf Of Joe Perches
> Sent: Sunday, September 17, 2017 23:15
> To: Jon Maloy <jon.maloy@ericsson.com>; Thomas Meyer
> <thomas@m3y3r.de>
> Cc: Ying Xue <ying.xue@windriver.com>; netdev@vger.kernel.org; tipc-
> discussion@lists.sourceforge.net; linux-kernel@vger.kernel.org;
> davem@davemloft.net
> Subject: Re: [PATCH V2] tipc: Use bsearch library function
> 
> On Sun, 2017-09-17 at 16:27 +0000, Jon Maloy wrote:
> > > -----Original Message-----
> > > From: Thomas Meyer [mailto:thomas@m3y3r.de]
> []
> > > What about the other binary search implementation in the same file?
> > > Should I try to convert it it will it get NAKed for performance reasons too?
> >
> > The searches for inserting and removing publications is less time
> > critical, so that would be ok with me.
> > If you have any more general interest in improving the code in this
> > file (which is needed) it would also be appreciated.
> 
> Perhaps using an rbtree would be an improvement.

Not a bad idea. It would probably reduce the code amount, possibly at the expense of cache hit rate during the binary lookup.
It is worth looking into.

///jon

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

end of thread, other threads:[~2017-09-19  1:08 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-09  3:18 [PATCH] tipc: Use bsearch library function Thomas Meyer
2017-09-11 21:30 ` David Miller
2017-09-12  9:24   ` David Laight
2017-09-12  9:24     ` David Laight
2017-09-16  7:50   ` [PATCH V2] " Thomas Meyer
2017-09-16  9:02     ` Ying Xue
2017-09-16  9:26       ` Joe Perches
2017-09-16  9:36         ` Ying Xue
2017-09-16  9:58           ` Joe Perches
2017-09-16 10:10             ` Ying Xue
2017-09-16 10:17               ` Joe Perches
2017-09-16 13:20                 ` Jon Maloy
2017-09-16 13:20                   ` Jon Maloy
2017-09-17 15:00                   ` Thomas Meyer
2017-09-17 15:00                     ` Thomas Meyer
2017-09-17 16:27                     ` Jon Maloy
2017-09-17 16:27                       ` Jon Maloy
2017-09-17 21:15                       ` Joe Perches
2017-09-17 21:15                         ` Joe Perches
2017-09-19  1:08                         ` Jon Maloy
2017-09-19  1:08                           ` Jon Maloy

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.