[v3,1/3] lib/lpm: not inline unnecessary functions

Message ID 20190627093751.7746-1-ruifeng.wang@arm.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series [v3,1/3] lib/lpm: not inline unnecessary functions |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/intel-Performance-Testing success Performance Testing PASS
ci/mellanox-Performance-Testing success Performance Testing PASS

Commit Message

Ruifeng Wang June 27, 2019, 9:37 a.m. UTC
  Tests showed that the function inlining caused performance drop
on some x86 platforms with the memory ordering patches applied.
By force no-inline functions, the performance was better than
before on x86 and no impact to arm64 platforms.

Suggested-by: Medvedkin Vladimir <vladimir.medvedkin@intel.com>
Signed-off-by: Ruifeng Wang <ruifeng.wang@arm.com>
Reviewed-by: Gavin Hu <gavin.hu@arm.com>
---
v3: use __rte_noinline to force no inline
v2: initail version to remove 'inline' keyword

 lib/librte_lpm/rte_lpm.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
  

Comments

Stephen Hemminger June 27, 2019, 3:24 p.m. UTC | #1
On Thu, 27 Jun 2019 17:37:49 +0800
Ruifeng Wang <ruifeng.wang@arm.com> wrote:

> Tests showed that the function inlining caused performance drop
> on some x86 platforms with the memory ordering patches applied.
> By force no-inline functions, the performance was better than
> before on x86 and no impact to arm64 platforms.
> 
> Suggested-by: Medvedkin Vladimir <vladimir.medvedkin@intel.com>
> Signed-off-by: Ruifeng Wang <ruifeng.wang@arm.com>
> Reviewed-by: Gavin Hu <gavin.hu@arm.com>
 {

Do you actually need to force noinline or is just taking of inline enough?
In general, letting compiler decide is often best practice.
  
Ruifeng Wang June 28, 2019, 2:44 a.m. UTC | #2
Hi Stephen,

> -----Original Message-----
> From: Stephen Hemminger <stephen@networkplumber.org>
> Sent: Thursday, June 27, 2019 23:25
> To: Ruifeng Wang (Arm Technology China) <Ruifeng.Wang@arm.com>
> Cc: bruce.richardson@intel.com; vladimir.medvedkin@intel.com;
> dev@dpdk.org; Honnappa Nagarahalli <Honnappa.Nagarahalli@arm.com>;
> Gavin Hu (Arm Technology China) <Gavin.Hu@arm.com>; nd <nd@arm.com>
> Subject: Re: [dpdk-dev] [PATCH v3 1/3] lib/lpm: not inline unnecessary
> functions
> 
> On Thu, 27 Jun 2019 17:37:49 +0800
> Ruifeng Wang <ruifeng.wang@arm.com> wrote:
> 
> > Tests showed that the function inlining caused performance drop on
> > some x86 platforms with the memory ordering patches applied.
> > By force no-inline functions, the performance was better than before
> > on x86 and no impact to arm64 platforms.
> >
> > Suggested-by: Medvedkin Vladimir <vladimir.medvedkin@intel.com>
> > Signed-off-by: Ruifeng Wang <ruifeng.wang@arm.com>
> > Reviewed-by: Gavin Hu <gavin.hu@arm.com>
>  {
> 
> Do you actually need to force noinline or is just taking of inline enough?
> In general, letting compiler decide is often best practice.

The force noinline is an optimization for x86 platforms to keep rte_lpm_add() API
performance with memory ordering applied.
  
Stephen Hemminger June 28, 2019, 4:34 a.m. UTC | #3
On Fri, 28 Jun 2019 02:44:54 +0000
"Ruifeng Wang (Arm Technology China)" <Ruifeng.Wang@arm.com> wrote:

> >   
> > > Tests showed that the function inlining caused performance drop on
> > > some x86 platforms with the memory ordering patches applied.
> > > By force no-inline functions, the performance was better than before
> > > on x86 and no impact to arm64 platforms.
> > >
> > > Suggested-by: Medvedkin Vladimir <vladimir.medvedkin@intel.com>
> > > Signed-off-by: Ruifeng Wang <ruifeng.wang@arm.com>
> > > Reviewed-by: Gavin Hu <gavin.hu@arm.com>  
> >  {
> > 
> > Do you actually need to force noinline or is just taking of inline enough?
> > In general, letting compiler decide is often best practice.  
> 
> The force noinline is an optimization for x86 platforms to keep rte_lpm_add() API
> performance with memory ordering applied. 

I don't think you answered my question. What does a recent version of GCC do
if you drop the inline.

Actually all the functions in rte_lpm should drop inline.

diff --git a/lib/librte_lpm/rte_lpm.c b/lib/librte_lpm/rte_lpm.c
index 6b7b28a2e431..ffe07e980864 100644
--- a/lib/librte_lpm/rte_lpm.c
+++ b/lib/librte_lpm/rte_lpm.c
@@ -399,7 +399,7 @@ MAP_STATIC_SYMBOL(void rte_lpm_free(struct rte_lpm *lpm),
  * are stored in the rule table from 0 - 31.
  * NOTE: Valid range for depth parameter is 1 .. 32 inclusive.
  */
-static inline int32_t
+static int32_t
 rule_add_v20(struct rte_lpm_v20 *lpm, uint32_t ip_masked, uint8_t depth,
 	uint8_t next_hop)
 {
@@ -471,7 +471,7 @@ rule_add_v20(struct rte_lpm_v20 *lpm, uint32_t ip_masked, uint8_t depth,
 	return rule_index;
 }
 
-static inline int32_t
+static int32_t
 rule_add_v1604(struct rte_lpm *lpm, uint32_t ip_masked, uint8_t depth,
 	uint32_t next_hop)
 {
@@ -547,7 +547,7 @@ rule_add_v1604(struct rte_lpm *lpm, uint32_t ip_masked, uint8_t depth,
  * Delete a rule from the rule table.
  * NOTE: Valid range for depth parameter is 1 .. 32 inclusive.
  */
-static inline void
+static void
 rule_delete_v20(struct rte_lpm_v20 *lpm, int32_t rule_index, uint8_t depth)
 {
 	int i;
@@ -570,7 +570,7 @@ rule_delete_v20(struct rte_lpm_v20 *lpm, int32_t rule_index, uint8_t depth)
 	lpm->rule_info[depth - 1].used_rules--;
 }
 
-static inline void
+static void
 rule_delete_v1604(struct rte_lpm *lpm, int32_t rule_index, uint8_t depth)
 {
 	int i;
@@ -597,7 +597,7 @@ rule_delete_v1604(struct rte_lpm *lpm, int32_t rule_index, uint8_t depth)
  * Finds a rule in rule table.
  * NOTE: Valid range for depth parameter is 1 .. 32 inclusive.
  */
-static inline int32_t
+static int32_t
 rule_find_v20(struct rte_lpm_v20 *lpm, uint32_t ip_masked, uint8_t depth)
 {
 	uint32_t rule_gindex, last_rule, rule_index;
@@ -618,7 +618,7 @@ rule_find_v20(struct rte_lpm_v20 *lpm, uint32_t ip_masked, uint8_t depth)
 	return -EINVAL;
 }
 
-static inline int32_t
+static int32_t
 rule_find_v1604(struct rte_lpm *lpm, uint32_t ip_masked, uint8_t depth)
 {
 	uint32_t rule_gindex, last_rule, rule_index;
@@ -642,7 +642,7 @@ rule_find_v1604(struct rte_lpm *lpm, uint32_t ip_masked, uint8_t depth)
 /*
  * Find, clean and allocate a tbl8.
  */
-static inline int32_t
+static int32_t
 tbl8_alloc_v20(struct rte_lpm_tbl_entry_v20 *tbl8)
 {
 	uint32_t group_idx; /* tbl8 group index. */
@@ -669,7 +669,7 @@ tbl8_alloc_v20(struct rte_lpm_tbl_entry_v20 *tbl8)
 	return -ENOSPC;
 }
 
-static inline int32_t
+static int32_t
 tbl8_alloc_v1604(struct rte_lpm_tbl_entry *tbl8, uint32_t number_tbl8s)
 {
 	uint32_t group_idx; /* tbl8 group index. */
@@ -709,7 +709,7 @@ tbl8_free_v1604(struct rte_lpm_tbl_entry *tbl8, uint32_t tbl8_group_start)
 	tbl8[tbl8_group_start].valid_group = INVALID;
 }
 
-static inline int32_t
+static int32_t
 add_depth_small_v20(struct rte_lpm_v20 *lpm, uint32_t ip, uint8_t depth,
 		uint8_t next_hop)
 {
@@ -777,7 +777,7 @@ add_depth_small_v20(struct rte_lpm_v20 *lpm, uint32_t ip, uint8_t depth,
 	return 0;
 }
 
-static inline int32_t
+static int32_t
 add_depth_small_v1604(struct rte_lpm *lpm, uint32_t ip, uint8_t depth,
 		uint32_t next_hop)
 {
@@ -846,7 +846,7 @@ add_depth_small_v1604(struct rte_lpm *lpm, uint32_t ip, uint8_t depth,
 	return 0;
 }
 
-static inline int32_t
+static int32_t
 add_depth_big_v20(struct rte_lpm_v20 *lpm, uint32_t ip_masked, uint8_t depth,
 		uint8_t next_hop)
 {
@@ -971,7 +971,7 @@ add_depth_big_v20(struct rte_lpm_v20 *lpm, uint32_t ip_masked, uint8_t depth,
 	return 0;
 }
 
-static inline int32_t
+static int32_t
 add_depth_big_v1604(struct rte_lpm *lpm, uint32_t ip_masked, uint8_t depth,
 		uint32_t next_hop)
 {
@@ -1244,7 +1244,7 @@ BIND_DEFAULT_SYMBOL(rte_lpm_is_rule_present, _v1604, 16.04);
 MAP_STATIC_SYMBOL(int rte_lpm_is_rule_present(struct rte_lpm *lpm, uint32_t ip,
 		uint8_t depth, uint32_t *next_hop), rte_lpm_is_rule_present_v1604);
 
-static inline int32_t
+static int32_t
 find_previous_rule_v20(struct rte_lpm_v20 *lpm, uint32_t ip, uint8_t depth,
 		uint8_t *sub_rule_depth)
 {
@@ -1266,7 +1266,7 @@ find_previous_rule_v20(struct rte_lpm_v20 *lpm, uint32_t ip, uint8_t depth,
 	return -1;
 }
 
-static inline int32_t
+static int32_t
 find_previous_rule_v1604(struct rte_lpm *lpm, uint32_t ip, uint8_t depth,
 		uint8_t *sub_rule_depth)
 {
@@ -1288,7 +1288,7 @@ find_previous_rule_v1604(struct rte_lpm *lpm, uint32_t ip, uint8_t depth,
 	return -1;
 }
 
-static inline int32_t
+static int32_t
 delete_depth_small_v20(struct rte_lpm_v20 *lpm, uint32_t ip_masked,
 	uint8_t depth, int32_t sub_rule_index, uint8_t sub_rule_depth)
 {
@@ -1381,7 +1381,7 @@ delete_depth_small_v20(struct rte_lpm_v20 *lpm, uint32_t ip_masked,
 	return 0;
 }
 
-static inline int32_t
+static int32_t
 delete_depth_small_v1604(struct rte_lpm *lpm, uint32_t ip_masked,
 	uint8_t depth, int32_t sub_rule_index, uint8_t sub_rule_depth)
 {
@@ -1483,7 +1483,7 @@ delete_depth_small_v1604(struct rte_lpm *lpm, uint32_t ip_masked,
  * Return of value > -1 means tbl8 is in use but has all the same values and
  * thus can be recycled
  */
-static inline int32_t
+static int32_t
 tbl8_recycle_check_v20(struct rte_lpm_tbl_entry_v20 *tbl8,
 		uint32_t tbl8_group_start)
 {
@@ -1530,7 +1530,7 @@ tbl8_recycle_check_v20(struct rte_lpm_tbl_entry_v20 *tbl8,
 	return -EINVAL;
 }
 
-static inline int32_t
+static int32_t
 tbl8_recycle_check_v1604(struct rte_lpm_tbl_entry *tbl8,
 		uint32_t tbl8_group_start)
 {
@@ -1577,7 +1577,7 @@ tbl8_recycle_check_v1604(struct rte_lpm_tbl_entry *tbl8,
 	return -EINVAL;
 }
 
-static inline int32_t
+static int32_t
 delete_depth_big_v20(struct rte_lpm_v20 *lpm, uint32_t ip_masked,
 	uint8_t depth, int32_t sub_rule_index, uint8_t sub_rule_depth)
 {
@@ -1655,7 +1655,7 @@ delete_depth_big_v20(struct rte_lpm_v20 *lpm, uint32_t ip_masked,
 	return 0;
 }
 
-static inline int32_t
+static int32_t
 delete_depth_big_v1604(struct rte_lpm *lpm, uint32_t ip_masked,
 	uint8_t depth, int32_t sub_rule_index, uint8_t sub_rule_depth)
 {
  
Ruifeng Wang June 28, 2019, 5:48 a.m. UTC | #4
Hi Stephen,

> -----Original Message-----
> From: Stephen Hemminger <stephen@networkplumber.org>
> Sent: Friday, June 28, 2019 12:35
> To: Ruifeng Wang (Arm Technology China) <Ruifeng.Wang@arm.com>
> Cc: bruce.richardson@intel.com; vladimir.medvedkin@intel.com;
> dev@dpdk.org; Honnappa Nagarahalli <Honnappa.Nagarahalli@arm.com>;
> Gavin Hu (Arm Technology China) <Gavin.Hu@arm.com>; nd <nd@arm.com>
> Subject: Re: [dpdk-dev] [PATCH v3 1/3] lib/lpm: not inline unnecessary
> functions
> 
> On Fri, 28 Jun 2019 02:44:54 +0000
> "Ruifeng Wang (Arm Technology China)" <Ruifeng.Wang@arm.com> wrote:
> 
> > >
> > > > Tests showed that the function inlining caused performance drop on
> > > > some x86 platforms with the memory ordering patches applied.
> > > > By force no-inline functions, the performance was better than
> > > > before on x86 and no impact to arm64 platforms.
> > > >
> > > > Suggested-by: Medvedkin Vladimir <vladimir.medvedkin@intel.com>
> > > > Signed-off-by: Ruifeng Wang <ruifeng.wang@arm.com>
> > > > Reviewed-by: Gavin Hu <gavin.hu@arm.com>
> > >  {
> > >
> > > Do you actually need to force noinline or is just taking of inline enough?
> > > In general, letting compiler decide is often best practice.
> >
> > The force noinline is an optimization for x86 platforms to keep
> > rte_lpm_add() API performance with memory ordering applied.
> 
> I don't think you answered my question. What does a recent version of GCC
> do if you drop the inline.
> 
GCC still inlines it when inline is dropped. So we need the force noinline.
See Vladmir's comment in http://patches.dpdk.org/patch/54936/.

> Actually all the functions in rte_lpm should drop inline.
> 
I don't know if we have guideline on use of 'inline'.
In general, 'inline' is not used and it is upon compiler to decide?
Is it reasonable to use force inline or force noinline for performance tunning?

> diff --git a/lib/librte_lpm/rte_lpm.c b/lib/librte_lpm/rte_lpm.c index
> 6b7b28a2e431..ffe07e980864 100644
> --- a/lib/librte_lpm/rte_lpm.c
> +++ b/lib/librte_lpm/rte_lpm.c
> @@ -399,7 +399,7 @@ MAP_STATIC_SYMBOL(void rte_lpm_free(struct
> rte_lpm *lpm),
>   * are stored in the rule table from 0 - 31.
>   * NOTE: Valid range for depth parameter is 1 .. 32 inclusive.
>   */
> -static inline int32_t
> +static int32_t
>  rule_add_v20(struct rte_lpm_v20 *lpm, uint32_t ip_masked, uint8_t depth,
>  	uint8_t next_hop)
>  {
> @@ -471,7 +471,7 @@ rule_add_v20(struct rte_lpm_v20 *lpm, uint32_t
> ip_masked, uint8_t depth,
>  	return rule_index;
>  }
> 
> -static inline int32_t
> +static int32_t
>  rule_add_v1604(struct rte_lpm *lpm, uint32_t ip_masked, uint8_t depth,
>  	uint32_t next_hop)
>  {
> @@ -547,7 +547,7 @@ rule_add_v1604(struct rte_lpm *lpm, uint32_t
> ip_masked, uint8_t depth,
>   * Delete a rule from the rule table.
>   * NOTE: Valid range for depth parameter is 1 .. 32 inclusive.
>   */
> -static inline void
> +static void
>  rule_delete_v20(struct rte_lpm_v20 *lpm, int32_t rule_index, uint8_t depth)
> {
>  	int i;
> @@ -570,7 +570,7 @@ rule_delete_v20(struct rte_lpm_v20 *lpm, int32_t
> rule_index, uint8_t depth)
>  	lpm->rule_info[depth - 1].used_rules--;  }
> 
> -static inline void
> +static void
>  rule_delete_v1604(struct rte_lpm *lpm, int32_t rule_index, uint8_t depth)  {
>  	int i;
> @@ -597,7 +597,7 @@ rule_delete_v1604(struct rte_lpm *lpm, int32_t
> rule_index, uint8_t depth)
>   * Finds a rule in rule table.
>   * NOTE: Valid range for depth parameter is 1 .. 32 inclusive.
>   */
> -static inline int32_t
> +static int32_t
>  rule_find_v20(struct rte_lpm_v20 *lpm, uint32_t ip_masked, uint8_t depth)
> {
>  	uint32_t rule_gindex, last_rule, rule_index; @@ -618,7 +618,7 @@
> rule_find_v20(struct rte_lpm_v20 *lpm, uint32_t ip_masked, uint8_t depth)
>  	return -EINVAL;
>  }
> 
> -static inline int32_t
> +static int32_t
>  rule_find_v1604(struct rte_lpm *lpm, uint32_t ip_masked, uint8_t depth)  {
>  	uint32_t rule_gindex, last_rule, rule_index; @@ -642,7 +642,7 @@
> rule_find_v1604(struct rte_lpm *lpm, uint32_t ip_masked, uint8_t depth)
>  /*
>   * Find, clean and allocate a tbl8.
>   */
> -static inline int32_t
> +static int32_t
>  tbl8_alloc_v20(struct rte_lpm_tbl_entry_v20 *tbl8)  {
>  	uint32_t group_idx; /* tbl8 group index. */ @@ -669,7 +669,7 @@
> tbl8_alloc_v20(struct rte_lpm_tbl_entry_v20 *tbl8)
>  	return -ENOSPC;
>  }
> 
> -static inline int32_t
> +static int32_t
>  tbl8_alloc_v1604(struct rte_lpm_tbl_entry *tbl8, uint32_t number_tbl8s)  {
>  	uint32_t group_idx; /* tbl8 group index. */ @@ -709,7 +709,7 @@
> tbl8_free_v1604(struct rte_lpm_tbl_entry *tbl8, uint32_t tbl8_group_start)
>  	tbl8[tbl8_group_start].valid_group = INVALID;  }
> 
> -static inline int32_t
> +static int32_t
>  add_depth_small_v20(struct rte_lpm_v20 *lpm, uint32_t ip, uint8_t depth,
>  		uint8_t next_hop)
>  {
> @@ -777,7 +777,7 @@ add_depth_small_v20(struct rte_lpm_v20 *lpm,
> uint32_t ip, uint8_t depth,
>  	return 0;
>  }
> 
> -static inline int32_t
> +static int32_t
>  add_depth_small_v1604(struct rte_lpm *lpm, uint32_t ip, uint8_t depth,
>  		uint32_t next_hop)
>  {
> @@ -846,7 +846,7 @@ add_depth_small_v1604(struct rte_lpm *lpm,
> uint32_t ip, uint8_t depth,
>  	return 0;
>  }
> 
> -static inline int32_t
> +static int32_t
>  add_depth_big_v20(struct rte_lpm_v20 *lpm, uint32_t ip_masked, uint8_t
> depth,
>  		uint8_t next_hop)
>  {
> @@ -971,7 +971,7 @@ add_depth_big_v20(struct rte_lpm_v20 *lpm,
> uint32_t ip_masked, uint8_t depth,
>  	return 0;
>  }
> 
> -static inline int32_t
> +static int32_t
>  add_depth_big_v1604(struct rte_lpm *lpm, uint32_t ip_masked, uint8_t
> depth,
>  		uint32_t next_hop)
>  {
> @@ -1244,7 +1244,7 @@ BIND_DEFAULT_SYMBOL(rte_lpm_is_rule_present,
> _v1604, 16.04);  MAP_STATIC_SYMBOL(int rte_lpm_is_rule_present(struct
> rte_lpm *lpm, uint32_t ip,
>  		uint8_t depth, uint32_t *next_hop),
> rte_lpm_is_rule_present_v1604);
> 
> -static inline int32_t
> +static int32_t
>  find_previous_rule_v20(struct rte_lpm_v20 *lpm, uint32_t ip, uint8_t depth,
>  		uint8_t *sub_rule_depth)
>  {
> @@ -1266,7 +1266,7 @@ find_previous_rule_v20(struct rte_lpm_v20 *lpm,
> uint32_t ip, uint8_t depth,
>  	return -1;
>  }
> 
> -static inline int32_t
> +static int32_t
>  find_previous_rule_v1604(struct rte_lpm *lpm, uint32_t ip, uint8_t depth,
>  		uint8_t *sub_rule_depth)
>  {
> @@ -1288,7 +1288,7 @@ find_previous_rule_v1604(struct rte_lpm *lpm,
> uint32_t ip, uint8_t depth,
>  	return -1;
>  }
> 
> -static inline int32_t
> +static int32_t
>  delete_depth_small_v20(struct rte_lpm_v20 *lpm, uint32_t ip_masked,
>  	uint8_t depth, int32_t sub_rule_index, uint8_t sub_rule_depth)
> { @@ -1381,7 +1381,7 @@ delete_depth_small_v20(struct rte_lpm_v20
> *lpm, uint32_t ip_masked,
>  	return 0;
>  }
> 
> -static inline int32_t
> +static int32_t
>  delete_depth_small_v1604(struct rte_lpm *lpm, uint32_t ip_masked,
>  	uint8_t depth, int32_t sub_rule_index, uint8_t sub_rule_depth)
> { @@ -1483,7 +1483,7 @@ delete_depth_small_v1604(struct rte_lpm *lpm,
> uint32_t ip_masked,
>   * Return of value > -1 means tbl8 is in use but has all the same values and
>   * thus can be recycled
>   */
> -static inline int32_t
> +static int32_t
>  tbl8_recycle_check_v20(struct rte_lpm_tbl_entry_v20 *tbl8,
>  		uint32_t tbl8_group_start)
>  {
> @@ -1530,7 +1530,7 @@ tbl8_recycle_check_v20(struct
> rte_lpm_tbl_entry_v20 *tbl8,
>  	return -EINVAL;
>  }
> 
> -static inline int32_t
> +static int32_t
>  tbl8_recycle_check_v1604(struct rte_lpm_tbl_entry *tbl8,
>  		uint32_t tbl8_group_start)
>  {
> @@ -1577,7 +1577,7 @@ tbl8_recycle_check_v1604(struct
> rte_lpm_tbl_entry *tbl8,
>  	return -EINVAL;
>  }
> 
> -static inline int32_t
> +static int32_t
>  delete_depth_big_v20(struct rte_lpm_v20 *lpm, uint32_t ip_masked,
>  	uint8_t depth, int32_t sub_rule_index, uint8_t sub_rule_depth)
> { @@ -1655,7 +1655,7 @@ delete_depth_big_v20(struct rte_lpm_v20 *lpm,
> uint32_t ip_masked,
>  	return 0;
>  }
> 
> -static inline int32_t
> +static int32_t
>  delete_depth_big_v1604(struct rte_lpm *lpm, uint32_t ip_masked,
>  	uint8_t depth, int32_t sub_rule_index, uint8_t sub_rule_depth)  {
  
Vladimir Medvedkin June 28, 2019, 1:38 p.m. UTC | #5
Hi Stephen,

On 27/06/2019 16:24, Stephen Hemminger wrote:
> On Thu, 27 Jun 2019 17:37:49 +0800
> Ruifeng Wang <ruifeng.wang@arm.com> wrote:
>
>> Tests showed that the function inlining caused performance drop
>> on some x86 platforms with the memory ordering patches applied.
>> By force no-inline functions, the performance was better than
>> before on x86 and no impact to arm64 platforms.
>>
>> Suggested-by: Medvedkin Vladimir <vladimir.medvedkin@intel.com>
>> Signed-off-by: Ruifeng Wang <ruifeng.wang@arm.com>
>> Reviewed-by: Gavin Hu <gavin.hu@arm.com>
>   {
>
> Do you actually need to force noinline or is just taking of inline enough?
> In general, letting compiler decide is often best practice.
In some cases compiler inlines this functions even if they don't have an 
inline qualifier. On some processors it leads to performance drop (maybe 
because of icache trashing).
  
Vladimir Medvedkin June 28, 2019, 1:47 p.m. UTC | #6
Hi all,

On 28/06/2019 05:34, Stephen Hemminger wrote:
> On Fri, 28 Jun 2019 02:44:54 +0000
> "Ruifeng Wang (Arm Technology China)"<Ruifeng.Wang@arm.com>  wrote:
>
>>>    
>>>> Tests showed that the function inlining caused performance drop on
>>>> some x86 platforms with the memory ordering patches applied.
>>>> By force no-inline functions, the performance was better than before
>>>> on x86 and no impact to arm64 platforms.
>>>>
>>>> Suggested-by: Medvedkin Vladimir<vladimir.medvedkin@intel.com>
>>>> Signed-off-by: Ruifeng Wang<ruifeng.wang@arm.com>
>>>> Reviewed-by: Gavin Hu<gavin.hu@arm.com>   
>>>   {
>>>
>>> Do you actually need to force noinline or is just taking of inline enough?
>>> In general, letting compiler decide is often best practice.
>> The force noinline is an optimization for x86 platforms to keep rte_lpm_add() API
>> performance with memory ordering applied.
> I don't think you answered my question. What does a recent version of GCC do
> if you drop the inline.
>
> Actually all the functions in rte_lpm should drop inline.
I'm agree with Stephen. If it is not a fastpath and size of function is 
not minimal it is good to remove inline qualifier for other control 
plane functions such as rule_add/delete/find/etc and let the compiler 
decide to inline it (unless it affects performance).
> diff --git a/lib/librte_lpm/rte_lpm.c b/lib/librte_lpm/rte_lpm.c
> index 6b7b28a2e431..ffe07e980864 100644
> --- a/lib/librte_lpm/rte_lpm.c
> +++ b/lib/librte_lpm/rte_lpm.c
> @@ -399,7 +399,7 @@ MAP_STATIC_SYMBOL(void rte_lpm_free(struct rte_lpm *lpm),
>    * are stored in the rule table from 0 - 31.
>    * NOTE: Valid range for depth parameter is 1 .. 32 inclusive.
>    */
> -static inline int32_t
> +static int32_t
>   rule_add_v20(struct rte_lpm_v20 *lpm, uint32_t ip_masked, uint8_t depth,
>   	uint8_t next_hop)
>   {
> @@ -471,7 +471,7 @@ rule_add_v20(struct rte_lpm_v20 *lpm, uint32_t ip_masked, uint8_t depth,
>   	return rule_index;
>   }
>   
> -static inline int32_t
> +static int32_t
>   rule_add_v1604(struct rte_lpm *lpm, uint32_t ip_masked, uint8_t depth,
>   	uint32_t next_hop)
>   {
> @@ -547,7 +547,7 @@ rule_add_v1604(struct rte_lpm *lpm, uint32_t ip_masked, uint8_t depth,
>    * Delete a rule from the rule table.
>    * NOTE: Valid range for depth parameter is 1 .. 32 inclusive.
>    */
> -static inline void
> +static void
>   rule_delete_v20(struct rte_lpm_v20 *lpm, int32_t rule_index, uint8_t depth)
>   {
>   	int i;
> @@ -570,7 +570,7 @@ rule_delete_v20(struct rte_lpm_v20 *lpm, int32_t rule_index, uint8_t depth)
>   	lpm->rule_info[depth - 1].used_rules--;
>   }
>   
> -static inline void
> +static void
>   rule_delete_v1604(struct rte_lpm *lpm, int32_t rule_index, uint8_t depth)
>   {
>   	int i;
> @@ -597,7 +597,7 @@ rule_delete_v1604(struct rte_lpm *lpm, int32_t rule_index, uint8_t depth)
>    * Finds a rule in rule table.
>    * NOTE: Valid range for depth parameter is 1 .. 32 inclusive.
>    */
> -static inline int32_t
> +static int32_t
>   rule_find_v20(struct rte_lpm_v20 *lpm, uint32_t ip_masked, uint8_t depth)
>   {
>   	uint32_t rule_gindex, last_rule, rule_index;
> @@ -618,7 +618,7 @@ rule_find_v20(struct rte_lpm_v20 *lpm, uint32_t ip_masked, uint8_t depth)
>   	return -EINVAL;
>   }
>   
> -static inline int32_t
> +static int32_t
>   rule_find_v1604(struct rte_lpm *lpm, uint32_t ip_masked, uint8_t depth)
>   {
>   	uint32_t rule_gindex, last_rule, rule_index;
> @@ -642,7 +642,7 @@ rule_find_v1604(struct rte_lpm *lpm, uint32_t ip_masked, uint8_t depth)
>   /*
>    * Find, clean and allocate a tbl8.
>    */
> -static inline int32_t
> +static int32_t
>   tbl8_alloc_v20(struct rte_lpm_tbl_entry_v20 *tbl8)
>   {
>   	uint32_t group_idx; /* tbl8 group index. */
> @@ -669,7 +669,7 @@ tbl8_alloc_v20(struct rte_lpm_tbl_entry_v20 *tbl8)
>   	return -ENOSPC;
>   }
>   
> -static inline int32_t
> +static int32_t
>   tbl8_alloc_v1604(struct rte_lpm_tbl_entry *tbl8, uint32_t number_tbl8s)
>   {
>   	uint32_t group_idx; /* tbl8 group index. */
> @@ -709,7 +709,7 @@ tbl8_free_v1604(struct rte_lpm_tbl_entry *tbl8, uint32_t tbl8_group_start)
>   	tbl8[tbl8_group_start].valid_group = INVALID;
>   }
>   
> -static inline int32_t
> +static int32_t
>   add_depth_small_v20(struct rte_lpm_v20 *lpm, uint32_t ip, uint8_t depth,
>   		uint8_t next_hop)
>   {
> @@ -777,7 +777,7 @@ add_depth_small_v20(struct rte_lpm_v20 *lpm, uint32_t ip, uint8_t depth,
>   	return 0;
>   }
>   
> -static inline int32_t
> +static int32_t
>   add_depth_small_v1604(struct rte_lpm *lpm, uint32_t ip, uint8_t depth,
>   		uint32_t next_hop)
>   {
> @@ -846,7 +846,7 @@ add_depth_small_v1604(struct rte_lpm *lpm, uint32_t ip, uint8_t depth,
>   	return 0;
>   }
>   
> -static inline int32_t
> +static int32_t
>   add_depth_big_v20(struct rte_lpm_v20 *lpm, uint32_t ip_masked, uint8_t depth,
>   		uint8_t next_hop)
>   {
> @@ -971,7 +971,7 @@ add_depth_big_v20(struct rte_lpm_v20 *lpm, uint32_t ip_masked, uint8_t depth,
>   	return 0;
>   }
>   
> -static inline int32_t
> +static int32_t
>   add_depth_big_v1604(struct rte_lpm *lpm, uint32_t ip_masked, uint8_t depth,
>   		uint32_t next_hop)
>   {
> @@ -1244,7 +1244,7 @@ BIND_DEFAULT_SYMBOL(rte_lpm_is_rule_present, _v1604, 16.04);
>   MAP_STATIC_SYMBOL(int rte_lpm_is_rule_present(struct rte_lpm *lpm, uint32_t ip,
>   		uint8_t depth, uint32_t *next_hop), rte_lpm_is_rule_present_v1604);
>   
> -static inline int32_t
> +static int32_t
>   find_previous_rule_v20(struct rte_lpm_v20 *lpm, uint32_t ip, uint8_t depth,
>   		uint8_t *sub_rule_depth)
>   {
> @@ -1266,7 +1266,7 @@ find_previous_rule_v20(struct rte_lpm_v20 *lpm, uint32_t ip, uint8_t depth,
>   	return -1;
>   }
>   
> -static inline int32_t
> +static int32_t
>   find_previous_rule_v1604(struct rte_lpm *lpm, uint32_t ip, uint8_t depth,
>   		uint8_t *sub_rule_depth)
>   {
> @@ -1288,7 +1288,7 @@ find_previous_rule_v1604(struct rte_lpm *lpm, uint32_t ip, uint8_t depth,
>   	return -1;
>   }
>   
> -static inline int32_t
> +static int32_t
>   delete_depth_small_v20(struct rte_lpm_v20 *lpm, uint32_t ip_masked,
>   	uint8_t depth, int32_t sub_rule_index, uint8_t sub_rule_depth)
>   {
> @@ -1381,7 +1381,7 @@ delete_depth_small_v20(struct rte_lpm_v20 *lpm, uint32_t ip_masked,
>   	return 0;
>   }
>   
> -static inline int32_t
> +static int32_t
>   delete_depth_small_v1604(struct rte_lpm *lpm, uint32_t ip_masked,
>   	uint8_t depth, int32_t sub_rule_index, uint8_t sub_rule_depth)
>   {
> @@ -1483,7 +1483,7 @@ delete_depth_small_v1604(struct rte_lpm *lpm, uint32_t ip_masked,
>    * Return of value > -1 means tbl8 is in use but has all the same values and
>    * thus can be recycled
>    */
> -static inline int32_t
> +static int32_t
>   tbl8_recycle_check_v20(struct rte_lpm_tbl_entry_v20 *tbl8,
>   		uint32_t tbl8_group_start)
>   {
> @@ -1530,7 +1530,7 @@ tbl8_recycle_check_v20(struct rte_lpm_tbl_entry_v20 *tbl8,
>   	return -EINVAL;
>   }
>   
> -static inline int32_t
> +static int32_t
>   tbl8_recycle_check_v1604(struct rte_lpm_tbl_entry *tbl8,
>   		uint32_t tbl8_group_start)
>   {
> @@ -1577,7 +1577,7 @@ tbl8_recycle_check_v1604(struct rte_lpm_tbl_entry *tbl8,
>   	return -EINVAL;
>   }
>   
> -static inline int32_t
> +static int32_t
>   delete_depth_big_v20(struct rte_lpm_v20 *lpm, uint32_t ip_masked,
>   	uint8_t depth, int32_t sub_rule_index, uint8_t sub_rule_depth)
>   {
> @@ -1655,7 +1655,7 @@ delete_depth_big_v20(struct rte_lpm_v20 *lpm, uint32_t ip_masked,
>   	return 0;
>   }
>   
> -static inline int32_t
> +static int32_t
>   delete_depth_big_v1604(struct rte_lpm *lpm, uint32_t ip_masked,
>   	uint8_t depth, int32_t sub_rule_index, uint8_t sub_rule_depth)
>   {
  
Honnappa Nagarahalli June 28, 2019, 1:57 p.m. UTC | #7
> Hi all,
> 
> On 28/06/2019 05:34, Stephen Hemminger wrote:
> > On Fri, 28 Jun 2019 02:44:54 +0000
> > "Ruifeng Wang (Arm Technology China)"<Ruifeng.Wang@arm.com>  wrote:
> >
> >>>
> >>>> Tests showed that the function inlining caused performance drop on
> >>>> some x86 platforms with the memory ordering patches applied.
> >>>> By force no-inline functions, the performance was better than
> >>>> before on x86 and no impact to arm64 platforms.
> >>>>
> >>>> Suggested-by: Medvedkin Vladimir<vladimir.medvedkin@intel.com>
> >>>> Signed-off-by: Ruifeng Wang<ruifeng.wang@arm.com>
> >>>> Reviewed-by: Gavin Hu<gavin.hu@arm.com>
> >>>   {
> >>>
> >>> Do you actually need to force noinline or is just taking of inline enough?
> >>> In general, letting compiler decide is often best practice.
> >> The force noinline is an optimization for x86 platforms to keep
> >> rte_lpm_add() API performance with memory ordering applied.
> > I don't think you answered my question. What does a recent version of
> > GCC do if you drop the inline.
> >
> > Actually all the functions in rte_lpm should drop inline.
> I'm agree with Stephen. If it is not a fastpath and size of function is not
> minimal it is good to remove inline qualifier for other control plane functions
> such as rule_add/delete/find/etc and let the compiler decide to inline it
> (unless it affects performance).
IMO, the rule needs to be simple. If it is control plane function, we should leave it to the compiler to decide. I do not think we need to worry too much about performance for control plane functions.

> > diff --git a/lib/librte_lpm/rte_lpm.c b/lib/librte_lpm/rte_lpm.c index
> > 6b7b28a2e431..ffe07e980864 100644
> > --- a/lib/librte_lpm/rte_lpm.c
> > +++ b/lib/librte_lpm/rte_lpm.c
> > @@ -399,7 +399,7 @@ MAP_STATIC_SYMBOL(void rte_lpm_free(struct
> rte_lpm *lpm),
> >    * are stored in the rule table from 0 - 31.
> >    * NOTE: Valid range for depth parameter is 1 .. 32 inclusive.
> >    */
> > -static inline int32_t
> > +static int32_t
> >   rule_add_v20(struct rte_lpm_v20 *lpm, uint32_t ip_masked, uint8_t
> depth,
> >   	uint8_t next_hop)
> >   {
> > @@ -471,7 +471,7 @@ rule_add_v20(struct rte_lpm_v20 *lpm, uint32_t
> ip_masked, uint8_t depth,
> >   	return rule_index;
> >   }
> >
> > -static inline int32_t
> > +static int32_t
> >   rule_add_v1604(struct rte_lpm *lpm, uint32_t ip_masked, uint8_t depth,
> >   	uint32_t next_hop)
> >   {
> > @@ -547,7 +547,7 @@ rule_add_v1604(struct rte_lpm *lpm, uint32_t
> ip_masked, uint8_t depth,
> >    * Delete a rule from the rule table.
> >    * NOTE: Valid range for depth parameter is 1 .. 32 inclusive.
> >    */
> > -static inline void
> > +static void
> >   rule_delete_v20(struct rte_lpm_v20 *lpm, int32_t rule_index, uint8_t
> depth)
> >   {
> >   	int i;
> > @@ -570,7 +570,7 @@ rule_delete_v20(struct rte_lpm_v20 *lpm, int32_t
> rule_index, uint8_t depth)
> >   	lpm->rule_info[depth - 1].used_rules--;
> >   }
> >
> > -static inline void
> > +static void
> >   rule_delete_v1604(struct rte_lpm *lpm, int32_t rule_index, uint8_t depth)
> >   {
> >   	int i;
> > @@ -597,7 +597,7 @@ rule_delete_v1604(struct rte_lpm *lpm, int32_t
> rule_index, uint8_t depth)
> >    * Finds a rule in rule table.
> >    * NOTE: Valid range for depth parameter is 1 .. 32 inclusive.
> >    */
> > -static inline int32_t
> > +static int32_t
> >   rule_find_v20(struct rte_lpm_v20 *lpm, uint32_t ip_masked, uint8_t
> depth)
> >   {
> >   	uint32_t rule_gindex, last_rule, rule_index; @@ -618,7 +618,7 @@
> > rule_find_v20(struct rte_lpm_v20 *lpm, uint32_t ip_masked, uint8_t depth)
> >   	return -EINVAL;
> >   }
> >
> > -static inline int32_t
> > +static int32_t
> >   rule_find_v1604(struct rte_lpm *lpm, uint32_t ip_masked, uint8_t depth)
> >   {
> >   	uint32_t rule_gindex, last_rule, rule_index; @@ -642,7 +642,7 @@
> > rule_find_v1604(struct rte_lpm *lpm, uint32_t ip_masked, uint8_t depth)
> >   /*
> >    * Find, clean and allocate a tbl8.
> >    */
> > -static inline int32_t
> > +static int32_t
> >   tbl8_alloc_v20(struct rte_lpm_tbl_entry_v20 *tbl8)
> >   {
> >   	uint32_t group_idx; /* tbl8 group index. */ @@ -669,7 +669,7 @@
> > tbl8_alloc_v20(struct rte_lpm_tbl_entry_v20 *tbl8)
> >   	return -ENOSPC;
> >   }
> >
> > -static inline int32_t
> > +static int32_t
> >   tbl8_alloc_v1604(struct rte_lpm_tbl_entry *tbl8, uint32_t number_tbl8s)
> >   {
> >   	uint32_t group_idx; /* tbl8 group index. */ @@ -709,7 +709,7 @@
> > tbl8_free_v1604(struct rte_lpm_tbl_entry *tbl8, uint32_t tbl8_group_start)
> >   	tbl8[tbl8_group_start].valid_group = INVALID;
> >   }
> >
> > -static inline int32_t
> > +static int32_t
> >   add_depth_small_v20(struct rte_lpm_v20 *lpm, uint32_t ip, uint8_t depth,
> >   		uint8_t next_hop)
> >   {
> > @@ -777,7 +777,7 @@ add_depth_small_v20(struct rte_lpm_v20 *lpm,
> uint32_t ip, uint8_t depth,
> >   	return 0;
> >   }
> >
> > -static inline int32_t
> > +static int32_t
> >   add_depth_small_v1604(struct rte_lpm *lpm, uint32_t ip, uint8_t depth,
> >   		uint32_t next_hop)
> >   {
> > @@ -846,7 +846,7 @@ add_depth_small_v1604(struct rte_lpm *lpm,
> uint32_t ip, uint8_t depth,
> >   	return 0;
> >   }
> >
> > -static inline int32_t
> > +static int32_t
> >   add_depth_big_v20(struct rte_lpm_v20 *lpm, uint32_t ip_masked,
> uint8_t depth,
> >   		uint8_t next_hop)
> >   {
> > @@ -971,7 +971,7 @@ add_depth_big_v20(struct rte_lpm_v20 *lpm,
> uint32_t ip_masked, uint8_t depth,
> >   	return 0;
> >   }
> >
> > -static inline int32_t
> > +static int32_t
> >   add_depth_big_v1604(struct rte_lpm *lpm, uint32_t ip_masked, uint8_t
> depth,
> >   		uint32_t next_hop)
> >   {
> > @@ -1244,7 +1244,7 @@
> BIND_DEFAULT_SYMBOL(rte_lpm_is_rule_present, _v1604, 16.04);
> >   MAP_STATIC_SYMBOL(int rte_lpm_is_rule_present(struct rte_lpm *lpm,
> uint32_t ip,
> >   		uint8_t depth, uint32_t *next_hop),
> > rte_lpm_is_rule_present_v1604);
> >
> > -static inline int32_t
> > +static int32_t
> >   find_previous_rule_v20(struct rte_lpm_v20 *lpm, uint32_t ip, uint8_t
> depth,
> >   		uint8_t *sub_rule_depth)
> >   {
> > @@ -1266,7 +1266,7 @@ find_previous_rule_v20(struct rte_lpm_v20
> *lpm, uint32_t ip, uint8_t depth,
> >   	return -1;
> >   }
> >
> > -static inline int32_t
> > +static int32_t
> >   find_previous_rule_v1604(struct rte_lpm *lpm, uint32_t ip, uint8_t depth,
> >   		uint8_t *sub_rule_depth)
> >   {
> > @@ -1288,7 +1288,7 @@ find_previous_rule_v1604(struct rte_lpm *lpm,
> uint32_t ip, uint8_t depth,
> >   	return -1;
> >   }
> >
> > -static inline int32_t
> > +static int32_t
> >   delete_depth_small_v20(struct rte_lpm_v20 *lpm, uint32_t ip_masked,
> >   	uint8_t depth, int32_t sub_rule_index, uint8_t sub_rule_depth)
> >   {
> > @@ -1381,7 +1381,7 @@ delete_depth_small_v20(struct rte_lpm_v20
> *lpm, uint32_t ip_masked,
> >   	return 0;
> >   }
> >
> > -static inline int32_t
> > +static int32_t
> >   delete_depth_small_v1604(struct rte_lpm *lpm, uint32_t ip_masked,
> >   	uint8_t depth, int32_t sub_rule_index, uint8_t sub_rule_depth)
> >   {
> > @@ -1483,7 +1483,7 @@ delete_depth_small_v1604(struct rte_lpm *lpm,
> uint32_t ip_masked,
> >    * Return of value > -1 means tbl8 is in use but has all the same values and
> >    * thus can be recycled
> >    */
> > -static inline int32_t
> > +static int32_t
> >   tbl8_recycle_check_v20(struct rte_lpm_tbl_entry_v20 *tbl8,
> >   		uint32_t tbl8_group_start)
> >   {
> > @@ -1530,7 +1530,7 @@ tbl8_recycle_check_v20(struct
> rte_lpm_tbl_entry_v20 *tbl8,
> >   	return -EINVAL;
> >   }
> >
> > -static inline int32_t
> > +static int32_t
> >   tbl8_recycle_check_v1604(struct rte_lpm_tbl_entry *tbl8,
> >   		uint32_t tbl8_group_start)
> >   {
> > @@ -1577,7 +1577,7 @@ tbl8_recycle_check_v1604(struct
> rte_lpm_tbl_entry *tbl8,
> >   	return -EINVAL;
> >   }
> >
> > -static inline int32_t
> > +static int32_t
> >   delete_depth_big_v20(struct rte_lpm_v20 *lpm, uint32_t ip_masked,
> >   	uint8_t depth, int32_t sub_rule_index, uint8_t sub_rule_depth)
> >   {
> > @@ -1655,7 +1655,7 @@ delete_depth_big_v20(struct rte_lpm_v20 *lpm,
> uint32_t ip_masked,
> >   	return 0;
> >   }
> >
> > -static inline int32_t
> > +static int32_t
> >   delete_depth_big_v1604(struct rte_lpm *lpm, uint32_t ip_masked,
> >   	uint8_t depth, int32_t sub_rule_index, uint8_t sub_rule_depth)
> >   {
> 
> --
> Regards,
> Vladimir
  
Vladimir Medvedkin June 28, 2019, 2:16 p.m. UTC | #8
Hi Honnappa,

On 28/06/2019 14:57, Honnappa Nagarahalli wrote:
>> Hi all,
>>
>> On 28/06/2019 05:34, Stephen Hemminger wrote:
>>> On Fri, 28 Jun 2019 02:44:54 +0000
>>> "Ruifeng Wang (Arm Technology China)"<Ruifeng.Wang@arm.com>  wrote:
>>>
>>>>>> Tests showed that the function inlining caused performance drop on
>>>>>> some x86 platforms with the memory ordering patches applied.
>>>>>> By force no-inline functions, the performance was better than
>>>>>> before on x86 and no impact to arm64 platforms.
>>>>>>
>>>>>> Suggested-by: Medvedkin Vladimir<vladimir.medvedkin@intel.com>
>>>>>> Signed-off-by: Ruifeng Wang<ruifeng.wang@arm.com>
>>>>>> Reviewed-by: Gavin Hu<gavin.hu@arm.com>
>>>>>    {
>>>>>
>>>>> Do you actually need to force noinline or is just taking of inline enough?
>>>>> In general, letting compiler decide is often best practice.
>>>> The force noinline is an optimization for x86 platforms to keep
>>>> rte_lpm_add() API performance with memory ordering applied.
>>> I don't think you answered my question. What does a recent version of
>>> GCC do if you drop the inline.
>>>
>>> Actually all the functions in rte_lpm should drop inline.
>> I'm agree with Stephen. If it is not a fastpath and size of function is not
>> minimal it is good to remove inline qualifier for other control plane functions
>> such as rule_add/delete/find/etc and let the compiler decide to inline it
>> (unless it affects performance).
> IMO, the rule needs to be simple. If it is control plane function, we should leave it to the compiler to decide. I do not think we need to worry too much about performance for control plane functions.
Control plane is not as important as data plane speed but it is still 
important. For lpm we are talking not about initialization, but runtime 
routes add/del related functions. If it is very slow the library will be 
totally unusable because after it receives a route update it will be 
blocked for a long time and route update queue would overflow.
>>> diff --git a/lib/librte_lpm/rte_lpm.c b/lib/librte_lpm/rte_lpm.c index
>>> 6b7b28a2e431..ffe07e980864 100644
>>> --- a/lib/librte_lpm/rte_lpm.c
>>> +++ b/lib/librte_lpm/rte_lpm.c
>>> @@ -399,7 +399,7 @@ MAP_STATIC_SYMBOL(void rte_lpm_free(struct
>> rte_lpm *lpm),
>>>     * are stored in the rule table from 0 - 31.
>>>     * NOTE: Valid range for depth parameter is 1 .. 32 inclusive.
>>>     */
>>> -static inline int32_t
>>> +static int32_t
>>>    rule_add_v20(struct rte_lpm_v20 *lpm, uint32_t ip_masked, uint8_t
>> depth,
>>>    	uint8_t next_hop)
>>>    {
>>> @@ -471,7 +471,7 @@ rule_add_v20(struct rte_lpm_v20 *lpm, uint32_t
>> ip_masked, uint8_t depth,
>>>    	return rule_index;
>>>    }
>>>
>>> -static inline int32_t
>>> +static int32_t
>>>    rule_add_v1604(struct rte_lpm *lpm, uint32_t ip_masked, uint8_t depth,
>>>    	uint32_t next_hop)
>>>    {
>>> @@ -547,7 +547,7 @@ rule_add_v1604(struct rte_lpm *lpm, uint32_t
>> ip_masked, uint8_t depth,
>>>     * Delete a rule from the rule table.
>>>     * NOTE: Valid range for depth parameter is 1 .. 32 inclusive.
>>>     */
>>> -static inline void
>>> +static void
>>>    rule_delete_v20(struct rte_lpm_v20 *lpm, int32_t rule_index, uint8_t
>> depth)
>>>    {
>>>    	int i;
>>> @@ -570,7 +570,7 @@ rule_delete_v20(struct rte_lpm_v20 *lpm, int32_t
>> rule_index, uint8_t depth)
>>>    	lpm->rule_info[depth - 1].used_rules--;
>>>    }
>>>
>>> -static inline void
>>> +static void
>>>    rule_delete_v1604(struct rte_lpm *lpm, int32_t rule_index, uint8_t depth)
>>>    {
>>>    	int i;
>>> @@ -597,7 +597,7 @@ rule_delete_v1604(struct rte_lpm *lpm, int32_t
>> rule_index, uint8_t depth)
>>>     * Finds a rule in rule table.
>>>     * NOTE: Valid range for depth parameter is 1 .. 32 inclusive.
>>>     */
>>> -static inline int32_t
>>> +static int32_t
>>>    rule_find_v20(struct rte_lpm_v20 *lpm, uint32_t ip_masked, uint8_t
>> depth)
>>>    {
>>>    	uint32_t rule_gindex, last_rule, rule_index; @@ -618,7 +618,7 @@
>>> rule_find_v20(struct rte_lpm_v20 *lpm, uint32_t ip_masked, uint8_t depth)
>>>    	return -EINVAL;
>>>    }
>>>
>>> -static inline int32_t
>>> +static int32_t
>>>    rule_find_v1604(struct rte_lpm *lpm, uint32_t ip_masked, uint8_t depth)
>>>    {
>>>    	uint32_t rule_gindex, last_rule, rule_index; @@ -642,7 +642,7 @@
>>> rule_find_v1604(struct rte_lpm *lpm, uint32_t ip_masked, uint8_t depth)
>>>    /*
>>>     * Find, clean and allocate a tbl8.
>>>     */
>>> -static inline int32_t
>>> +static int32_t
>>>    tbl8_alloc_v20(struct rte_lpm_tbl_entry_v20 *tbl8)
>>>    {
>>>    	uint32_t group_idx; /* tbl8 group index. */ @@ -669,7 +669,7 @@
>>> tbl8_alloc_v20(struct rte_lpm_tbl_entry_v20 *tbl8)
>>>    	return -ENOSPC;
>>>    }
>>>
>>> -static inline int32_t
>>> +static int32_t
>>>    tbl8_alloc_v1604(struct rte_lpm_tbl_entry *tbl8, uint32_t number_tbl8s)
>>>    {
>>>    	uint32_t group_idx; /* tbl8 group index. */ @@ -709,7 +709,7 @@
>>> tbl8_free_v1604(struct rte_lpm_tbl_entry *tbl8, uint32_t tbl8_group_start)
>>>    	tbl8[tbl8_group_start].valid_group = INVALID;
>>>    }
>>>
>>> -static inline int32_t
>>> +static int32_t
>>>    add_depth_small_v20(struct rte_lpm_v20 *lpm, uint32_t ip, uint8_t depth,
>>>    		uint8_t next_hop)
>>>    {
>>> @@ -777,7 +777,7 @@ add_depth_small_v20(struct rte_lpm_v20 *lpm,
>> uint32_t ip, uint8_t depth,
>>>    	return 0;
>>>    }
>>>
>>> -static inline int32_t
>>> +static int32_t
>>>    add_depth_small_v1604(struct rte_lpm *lpm, uint32_t ip, uint8_t depth,
>>>    		uint32_t next_hop)
>>>    {
>>> @@ -846,7 +846,7 @@ add_depth_small_v1604(struct rte_lpm *lpm,
>> uint32_t ip, uint8_t depth,
>>>    	return 0;
>>>    }
>>>
>>> -static inline int32_t
>>> +static int32_t
>>>    add_depth_big_v20(struct rte_lpm_v20 *lpm, uint32_t ip_masked,
>> uint8_t depth,
>>>    		uint8_t next_hop)
>>>    {
>>> @@ -971,7 +971,7 @@ add_depth_big_v20(struct rte_lpm_v20 *lpm,
>> uint32_t ip_masked, uint8_t depth,
>>>    	return 0;
>>>    }
>>>
>>> -static inline int32_t
>>> +static int32_t
>>>    add_depth_big_v1604(struct rte_lpm *lpm, uint32_t ip_masked, uint8_t
>> depth,
>>>    		uint32_t next_hop)
>>>    {
>>> @@ -1244,7 +1244,7 @@
>> BIND_DEFAULT_SYMBOL(rte_lpm_is_rule_present, _v1604, 16.04);
>>>    MAP_STATIC_SYMBOL(int rte_lpm_is_rule_present(struct rte_lpm *lpm,
>> uint32_t ip,
>>>    		uint8_t depth, uint32_t *next_hop),
>>> rte_lpm_is_rule_present_v1604);
>>>
>>> -static inline int32_t
>>> +static int32_t
>>>    find_previous_rule_v20(struct rte_lpm_v20 *lpm, uint32_t ip, uint8_t
>> depth,
>>>    		uint8_t *sub_rule_depth)
>>>    {
>>> @@ -1266,7 +1266,7 @@ find_previous_rule_v20(struct rte_lpm_v20
>> *lpm, uint32_t ip, uint8_t depth,
>>>    	return -1;
>>>    }
>>>
>>> -static inline int32_t
>>> +static int32_t
>>>    find_previous_rule_v1604(struct rte_lpm *lpm, uint32_t ip, uint8_t depth,
>>>    		uint8_t *sub_rule_depth)
>>>    {
>>> @@ -1288,7 +1288,7 @@ find_previous_rule_v1604(struct rte_lpm *lpm,
>> uint32_t ip, uint8_t depth,
>>>    	return -1;
>>>    }
>>>
>>> -static inline int32_t
>>> +static int32_t
>>>    delete_depth_small_v20(struct rte_lpm_v20 *lpm, uint32_t ip_masked,
>>>    	uint8_t depth, int32_t sub_rule_index, uint8_t sub_rule_depth)
>>>    {
>>> @@ -1381,7 +1381,7 @@ delete_depth_small_v20(struct rte_lpm_v20
>> *lpm, uint32_t ip_masked,
>>>    	return 0;
>>>    }
>>>
>>> -static inline int32_t
>>> +static int32_t
>>>    delete_depth_small_v1604(struct rte_lpm *lpm, uint32_t ip_masked,
>>>    	uint8_t depth, int32_t sub_rule_index, uint8_t sub_rule_depth)
>>>    {
>>> @@ -1483,7 +1483,7 @@ delete_depth_small_v1604(struct rte_lpm *lpm,
>> uint32_t ip_masked,
>>>     * Return of value > -1 means tbl8 is in use but has all the same values and
>>>     * thus can be recycled
>>>     */
>>> -static inline int32_t
>>> +static int32_t
>>>    tbl8_recycle_check_v20(struct rte_lpm_tbl_entry_v20 *tbl8,
>>>    		uint32_t tbl8_group_start)
>>>    {
>>> @@ -1530,7 +1530,7 @@ tbl8_recycle_check_v20(struct
>> rte_lpm_tbl_entry_v20 *tbl8,
>>>    	return -EINVAL;
>>>    }
>>>
>>> -static inline int32_t
>>> +static int32_t
>>>    tbl8_recycle_check_v1604(struct rte_lpm_tbl_entry *tbl8,
>>>    		uint32_t tbl8_group_start)
>>>    {
>>> @@ -1577,7 +1577,7 @@ tbl8_recycle_check_v1604(struct
>> rte_lpm_tbl_entry *tbl8,
>>>    	return -EINVAL;
>>>    }
>>>
>>> -static inline int32_t
>>> +static int32_t
>>>    delete_depth_big_v20(struct rte_lpm_v20 *lpm, uint32_t ip_masked,
>>>    	uint8_t depth, int32_t sub_rule_index, uint8_t sub_rule_depth)
>>>    {
>>> @@ -1655,7 +1655,7 @@ delete_depth_big_v20(struct rte_lpm_v20 *lpm,
>> uint32_t ip_masked,
>>>    	return 0;
>>>    }
>>>
>>> -static inline int32_t
>>> +static int32_t
>>>    delete_depth_big_v1604(struct rte_lpm *lpm, uint32_t ip_masked,
>>>    	uint8_t depth, int32_t sub_rule_index, uint8_t sub_rule_depth)
>>>    {
>> --
>> Regards,
>> Vladimir
  
Stephen Hemminger June 28, 2019, 3:35 p.m. UTC | #9
On Fri, 28 Jun 2019 15:16:30 +0100
"Medvedkin, Vladimir" <vladimir.medvedkin@intel.com> wrote:

> Hi Honnappa,
> 
> On 28/06/2019 14:57, Honnappa Nagarahalli wrote:
> >> Hi all,
> >>
> >> On 28/06/2019 05:34, Stephen Hemminger wrote:  
> >>> On Fri, 28 Jun 2019 02:44:54 +0000
> >>> "Ruifeng Wang (Arm Technology China)"<Ruifeng.Wang@arm.com>  wrote:
> >>>  
> >>>>>> Tests showed that the function inlining caused performance drop on
> >>>>>> some x86 platforms with the memory ordering patches applied.
> >>>>>> By force no-inline functions, the performance was better than
> >>>>>> before on x86 and no impact to arm64 platforms.
> >>>>>>
> >>>>>> Suggested-by: Medvedkin Vladimir<vladimir.medvedkin@intel.com>
> >>>>>> Signed-off-by: Ruifeng Wang<ruifeng.wang@arm.com>
> >>>>>> Reviewed-by: Gavin Hu<gavin.hu@arm.com>  
> >>>>>    {
> >>>>>
> >>>>> Do you actually need to force noinline or is just taking of inline enough?
> >>>>> In general, letting compiler decide is often best practice.  
> >>>> The force noinline is an optimization for x86 platforms to keep
> >>>> rte_lpm_add() API performance with memory ordering applied.  
> >>> I don't think you answered my question. What does a recent version of
> >>> GCC do if you drop the inline.
> >>>
> >>> Actually all the functions in rte_lpm should drop inline.  
> >> I'm agree with Stephen. If it is not a fastpath and size of function is not
> >> minimal it is good to remove inline qualifier for other control plane functions
> >> such as rule_add/delete/find/etc and let the compiler decide to inline it
> >> (unless it affects performance).  
> > IMO, the rule needs to be simple. If it is control plane function, we should leave it to the compiler to decide. I do not think we need to worry too much about performance for control plane functions.  
> Control plane is not as important as data plane speed but it is still 
> important. For lpm we are talking not about initialization, but runtime 
> routes add/del related functions. If it is very slow the library will be 
> totally unusable because after it receives a route update it will be 
> blocked for a long time and route update queue would overflow.

Control plane performance is more impacted by algorithmic choice.
The original LPM had terrible (n^2?) control path. Current code is better.
I had a patch using RB tree, but it was rejected because it used the
/usr/include/bsd/sys/tree.h which added a dependency.
  
Ruifeng Wang July 1, 2019, 6:44 a.m. UTC | #10
Hi Medvedkin,

> -----Original Message-----
> From: Stephen Hemminger <stephen@networkplumber.org>
> Sent: Friday, June 28, 2019 23:35
> To: Medvedkin, Vladimir <vladimir.medvedkin@intel.com>
> Cc: Honnappa Nagarahalli <Honnappa.Nagarahalli@arm.com>; Ruifeng Wang
> (Arm Technology China) <Ruifeng.Wang@arm.com>;
> bruce.richardson@intel.com; dev@dpdk.org; Gavin Hu (Arm Technology
> China) <Gavin.Hu@arm.com>; nd <nd@arm.com>
> Subject: Re: [dpdk-dev] [PATCH v3 1/3] lib/lpm: not inline unnecessary
> functions
> 
> On Fri, 28 Jun 2019 15:16:30 +0100
> "Medvedkin, Vladimir" <vladimir.medvedkin@intel.com> wrote:
> 
> > Hi Honnappa,
> >
> > On 28/06/2019 14:57, Honnappa Nagarahalli wrote:
> > >> Hi all,
> > >>
> > >> On 28/06/2019 05:34, Stephen Hemminger wrote:
> > >>> On Fri, 28 Jun 2019 02:44:54 +0000 "Ruifeng Wang (Arm Technology
> > >>> China)"<Ruifeng.Wang@arm.com>  wrote:
> > >>>
> > >>>>>> Tests showed that the function inlining caused performance drop
> > >>>>>> on some x86 platforms with the memory ordering patches applied.
> > >>>>>> By force no-inline functions, the performance was better than
> > >>>>>> before on x86 and no impact to arm64 platforms.
> > >>>>>>
> > >>>>>> Suggested-by: Medvedkin
> Vladimir<vladimir.medvedkin@intel.com>
> > >>>>>> Signed-off-by: Ruifeng Wang<ruifeng.wang@arm.com>
> > >>>>>> Reviewed-by: Gavin Hu<gavin.hu@arm.com>
> > >>>>>    {
> > >>>>>
> > >>>>> Do you actually need to force noinline or is just taking of inline
> enough?
> > >>>>> In general, letting compiler decide is often best practice.
> > >>>> The force noinline is an optimization for x86 platforms to keep
> > >>>> rte_lpm_add() API performance with memory ordering applied.
> > >>> I don't think you answered my question. What does a recent version
> > >>> of GCC do if you drop the inline.
> > >>>
> > >>> Actually all the functions in rte_lpm should drop inline.
> > >> I'm agree with Stephen. If it is not a fastpath and size of
> > >> function is not minimal it is good to remove inline qualifier for
> > >> other control plane functions such as rule_add/delete/find/etc and
> > >> let the compiler decide to inline it (unless it affects performance).
> > > IMO, the rule needs to be simple. If it is control plane function, we should
> leave it to the compiler to decide. I do not think we need to worry too much
> about performance for control plane functions.
> > Control plane is not as important as data plane speed but it is still
> > important. For lpm we are talking not about initialization, but
> > runtime routes add/del related functions. If it is very slow the
> > library will be totally unusable because after it receives a route
> > update it will be blocked for a long time and route update queue would
> overflow.
> 
> Control plane performance is more impacted by algorithmic choice.
> The original LPM had terrible (n^2?) control path. Current code is better.
> I had a patch using RB tree, but it was rejected because it used the
> /usr/include/bsd/sys/tree.h which added a dependency.

Based on current discussion, I'd like to drop this single patch from the patch set.
Since it is not directly related to memory ordering changes in this library.
We can remove inlines in a follow up patch.
  
Vladimir Medvedkin July 5, 2019, 10:31 a.m. UTC | #11
Hi Stephen,

On 28/06/2019 16:35, Stephen Hemminger wrote:
> On Fri, 28 Jun 2019 15:16:30 +0100
> "Medvedkin, Vladimir" <vladimir.medvedkin@intel.com> wrote:
>
>> Hi Honnappa,
>>
>> On 28/06/2019 14:57, Honnappa Nagarahalli wrote:
>>>> Hi all,
>>>>
>>>> On 28/06/2019 05:34, Stephen Hemminger wrote:
>>>>> On Fri, 28 Jun 2019 02:44:54 +0000
>>>>> "Ruifeng Wang (Arm Technology China)"<Ruifeng.Wang@arm.com>  wrote:
>>>>>   
>>>>>>>> Tests showed that the function inlining caused performance drop on
>>>>>>>> some x86 platforms with the memory ordering patches applied.
>>>>>>>> By force no-inline functions, the performance was better than
>>>>>>>> before on x86 and no impact to arm64 platforms.
>>>>>>>>
>>>>>>>> Suggested-by: Medvedkin Vladimir<vladimir.medvedkin@intel.com>
>>>>>>>> Signed-off-by: Ruifeng Wang<ruifeng.wang@arm.com>
>>>>>>>> Reviewed-by: Gavin Hu<gavin.hu@arm.com>
>>>>>>>     {
>>>>>>>
>>>>>>> Do you actually need to force noinline or is just taking of inline enough?
>>>>>>> In general, letting compiler decide is often best practice.
>>>>>> The force noinline is an optimization for x86 platforms to keep
>>>>>> rte_lpm_add() API performance with memory ordering applied.
>>>>> I don't think you answered my question. What does a recent version of
>>>>> GCC do if you drop the inline.
>>>>>
>>>>> Actually all the functions in rte_lpm should drop inline.
>>>> I'm agree with Stephen. If it is not a fastpath and size of function is not
>>>> minimal it is good to remove inline qualifier for other control plane functions
>>>> such as rule_add/delete/find/etc and let the compiler decide to inline it
>>>> (unless it affects performance).
>>> IMO, the rule needs to be simple. If it is control plane function, we should leave it to the compiler to decide. I do not think we need to worry too much about performance for control plane functions.
>> Control plane is not as important as data plane speed but it is still
>> important. For lpm we are talking not about initialization, but runtime
>> routes add/del related functions. If it is very slow the library will be
>> totally unusable because after it receives a route update it will be
>> blocked for a long time and route update queue would overflow.
> Control plane performance is more impacted by algorithmic choice.
> The original LPM had terrible (n^2?) control path. Current code is better.
> I had a patch using RB tree, but it was rejected because it used the
> /usr/include/bsd/sys/tree.h which added a dependency.

You're absolutely right,  control plane performance is mostly depends on 
algorithm. Current LPM implementation has number of problems there. One 
problem is rules_tbl[] that is a flat array containing routes for 
control plane purposes. Replacing it with a rb-tree solves this problem, 
but there are another problems. For example, when you try to add a route 
10.0.0.0/8 while a number of subroutes are exist in the table (for 
example 10.20.0.0/16), current implementation will load tbl_entry -> do 
some checks (depth, ext entry) -> conditionally store new entry. Under 
several circumstances it would take a lot time.  But in fact it needs to 
unconditionally rewrite only two ranges - from 10.0.0.0 to 10.19.255.255 
and from 10.21.0.0 to 10.255.255.255. And control plane could help us to 
get this two ranges. The best struct to do so is lc-tree because it is 
relatively easy to traverse subtree (described by 10.0.0.0/8) and get 
subroutes. We are working on a new implementation, hopefully it will be 
ready soon.
  
Vladimir Medvedkin July 5, 2019, 10:40 a.m. UTC | #12
On 01/07/2019 07:44, Ruifeng Wang (Arm Technology China) wrote:
> Hi Medvedkin,
>
>> -----Original Message-----
>> From: Stephen Hemminger <stephen@networkplumber.org>
>> Sent: Friday, June 28, 2019 23:35
>> To: Medvedkin, Vladimir <vladimir.medvedkin@intel.com>
>> Cc: Honnappa Nagarahalli <Honnappa.Nagarahalli@arm.com>; Ruifeng Wang
>> (Arm Technology China) <Ruifeng.Wang@arm.com>;
>> bruce.richardson@intel.com; dev@dpdk.org; Gavin Hu (Arm Technology
>> China) <Gavin.Hu@arm.com>; nd <nd@arm.com>
>> Subject: Re: [dpdk-dev] [PATCH v3 1/3] lib/lpm: not inline unnecessary
>> functions
>>
>> On Fri, 28 Jun 2019 15:16:30 +0100
>> "Medvedkin, Vladimir" <vladimir.medvedkin@intel.com> wrote:
>>
>>> Hi Honnappa,
>>>
>>> On 28/06/2019 14:57, Honnappa Nagarahalli wrote:
>>>>> Hi all,
>>>>>
>>>>> On 28/06/2019 05:34, Stephen Hemminger wrote:
>>>>>> On Fri, 28 Jun 2019 02:44:54 +0000 "Ruifeng Wang (Arm Technology
>>>>>> China)"<Ruifeng.Wang@arm.com>  wrote:
>>>>>>
>>>>>>>>> Tests showed that the function inlining caused performance drop
>>>>>>>>> on some x86 platforms with the memory ordering patches applied.
>>>>>>>>> By force no-inline functions, the performance was better than
>>>>>>>>> before on x86 and no impact to arm64 platforms.
>>>>>>>>>
>>>>>>>>> Suggested-by: Medvedkin
>> Vladimir<vladimir.medvedkin@intel.com>
>>>>>>>>> Signed-off-by: Ruifeng Wang<ruifeng.wang@arm.com>
>>>>>>>>> Reviewed-by: Gavin Hu<gavin.hu@arm.com>
>>>>>>>>     {
>>>>>>>>
>>>>>>>> Do you actually need to force noinline or is just taking of inline
>> enough?
>>>>>>>> In general, letting compiler decide is often best practice.
>>>>>>> The force noinline is an optimization for x86 platforms to keep
>>>>>>> rte_lpm_add() API performance with memory ordering applied.
>>>>>> I don't think you answered my question. What does a recent version
>>>>>> of GCC do if you drop the inline.
>>>>>>
>>>>>> Actually all the functions in rte_lpm should drop inline.
>>>>> I'm agree with Stephen. If it is not a fastpath and size of
>>>>> function is not minimal it is good to remove inline qualifier for
>>>>> other control plane functions such as rule_add/delete/find/etc and
>>>>> let the compiler decide to inline it (unless it affects performance).
>>>> IMO, the rule needs to be simple. If it is control plane function, we should
>> leave it to the compiler to decide. I do not think we need to worry too much
>> about performance for control plane functions.
>>> Control plane is not as important as data plane speed but it is still
>>> important. For lpm we are talking not about initialization, but
>>> runtime routes add/del related functions. If it is very slow the
>>> library will be totally unusable because after it receives a route
>>> update it will be blocked for a long time and route update queue would
>> overflow.
>>
>> Control plane performance is more impacted by algorithmic choice.
>> The original LPM had terrible (n^2?) control path. Current code is better.
>> I had a patch using RB tree, but it was rejected because it used the
>> /usr/include/bsd/sys/tree.h which added a dependency.
> Based on current discussion, I'd like to drop this single patch from the patch set.
> Since it is not directly related to memory ordering changes in this library.
> We can remove inlines in a follow up patch.
I think this patch is indirectly related to changes. I can't accept a 
memory ordering patch series _before_ this patch because a repository 
state will appear in which the performance of LPM add/delete has 
dropped. So if it could be avoided it have to be avoided.
  
Ruifeng Wang July 5, 2019, 10:58 a.m. UTC | #13
> -----Original Message-----
> From: Medvedkin, Vladimir <vladimir.medvedkin@intel.com>
> Sent: Friday, July 5, 2019 18:41
> To: Ruifeng Wang (Arm Technology China) <Ruifeng.Wang@arm.com>
> Cc: Honnappa Nagarahalli <Honnappa.Nagarahalli@arm.com>; Stephen
> Hemminger <stephen@networkplumber.org>; bruce.richardson@intel.com;
> dev@dpdk.org; Gavin Hu (Arm Technology China) <Gavin.Hu@arm.com>; nd
> <nd@arm.com>
> Subject: Re: [dpdk-dev] [PATCH v3 1/3] lib/lpm: not inline unnecessary
> functions
> 
> 
> On 01/07/2019 07:44, Ruifeng Wang (Arm Technology China) wrote:
> > Hi Medvedkin,
> >
> >> -----Original Message-----
> >> From: Stephen Hemminger <stephen@networkplumber.org>
> >> Sent: Friday, June 28, 2019 23:35
> >> To: Medvedkin, Vladimir <vladimir.medvedkin@intel.com>
> >> Cc: Honnappa Nagarahalli <Honnappa.Nagarahalli@arm.com>; Ruifeng
> Wang
> >> (Arm Technology China) <Ruifeng.Wang@arm.com>;
> >> bruce.richardson@intel.com; dev@dpdk.org; Gavin Hu (Arm Technology
> >> China) <Gavin.Hu@arm.com>; nd <nd@arm.com>
> >> Subject: Re: [dpdk-dev] [PATCH v3 1/3] lib/lpm: not inline
> >> unnecessary functions
> >>
> >> On Fri, 28 Jun 2019 15:16:30 +0100
> >> "Medvedkin, Vladimir" <vladimir.medvedkin@intel.com> wrote:
> >>
> >>> Hi Honnappa,
> >>>
> >>> On 28/06/2019 14:57, Honnappa Nagarahalli wrote:
> >>>>> Hi all,
> >>>>>
> >>>>> On 28/06/2019 05:34, Stephen Hemminger wrote:
> >>>>>> On Fri, 28 Jun 2019 02:44:54 +0000 "Ruifeng Wang (Arm Technology
> >>>>>> China)"<Ruifeng.Wang@arm.com>  wrote:
> >>>>>>
> >>>>>>>>> Tests showed that the function inlining caused performance
> >>>>>>>>> drop on some x86 platforms with the memory ordering patches
> applied.
> >>>>>>>>> By force no-inline functions, the performance was better than
> >>>>>>>>> before on x86 and no impact to arm64 platforms.
> >>>>>>>>>
> >>>>>>>>> Suggested-by: Medvedkin
> >> Vladimir<vladimir.medvedkin@intel.com>
> >>>>>>>>> Signed-off-by: Ruifeng Wang<ruifeng.wang@arm.com>
> >>>>>>>>> Reviewed-by: Gavin Hu<gavin.hu@arm.com>
> >>>>>>>>     {
> >>>>>>>>
> >>>>>>>> Do you actually need to force noinline or is just taking of
> >>>>>>>> inline
> >> enough?
> >>>>>>>> In general, letting compiler decide is often best practice.
> >>>>>>> The force noinline is an optimization for x86 platforms to keep
> >>>>>>> rte_lpm_add() API performance with memory ordering applied.
> >>>>>> I don't think you answered my question. What does a recent
> >>>>>> version of GCC do if you drop the inline.
> >>>>>>
> >>>>>> Actually all the functions in rte_lpm should drop inline.
> >>>>> I'm agree with Stephen. If it is not a fastpath and size of
> >>>>> function is not minimal it is good to remove inline qualifier for
> >>>>> other control plane functions such as rule_add/delete/find/etc and
> >>>>> let the compiler decide to inline it (unless it affects performance).
> >>>> IMO, the rule needs to be simple. If it is control plane function,
> >>>> we should
> >> leave it to the compiler to decide. I do not think we need to worry
> >> too much about performance for control plane functions.
> >>> Control plane is not as important as data plane speed but it is
> >>> still important. For lpm we are talking not about initialization,
> >>> but runtime routes add/del related functions. If it is very slow the
> >>> library will be totally unusable because after it receives a route
> >>> update it will be blocked for a long time and route update queue
> >>> would
> >> overflow.
> >>
> >> Control plane performance is more impacted by algorithmic choice.
> >> The original LPM had terrible (n^2?) control path. Current code is better.
> >> I had a patch using RB tree, but it was rejected because it used the
> >> /usr/include/bsd/sys/tree.h which added a dependency.
> > Based on current discussion, I'd like to drop this single patch from the patch
> set.
> > Since it is not directly related to memory ordering changes in this library.
> > We can remove inlines in a follow up patch.
> I think this patch is indirectly related to changes. I can't accept a memory
> ordering patch series _before_ this patch because a repository state will
> appear in which the performance of LPM add/delete has dropped. So if it
> could be avoided it have to be avoided.
> 
In patch set v4, I dropped this patch and added atomic relaxed store for other
table entries. Test result showed no performance drop with the whole patch set.
Test data was updated in commit message of the first patch.
Please have a check. Thanks.
  
Alex Kiselev July 5, 2019, 1:37 p.m. UTC | #14
пт, 5 июл. 2019 г. в 13:31, Medvedkin, Vladimir <vladimir.medvedkin@intel.com>:
>
> Hi Stephen,
>
> On 28/06/2019 16:35, Stephen Hemminger wrote:
> > On Fri, 28 Jun 2019 15:16:30 +0100
> > "Medvedkin, Vladimir" <vladimir.medvedkin@intel.com> wrote:
> >
> >> Hi Honnappa,
> >>
> >> On 28/06/2019 14:57, Honnappa Nagarahalli wrote:
> >>>> Hi all,
> >>>>
> >>>> On 28/06/2019 05:34, Stephen Hemminger wrote:
> >>>>> On Fri, 28 Jun 2019 02:44:54 +0000
> >>>>> "Ruifeng Wang (Arm Technology China)"<Ruifeng.Wang@arm.com>  wrote:
> >>>>>
> >>>>>>>> Tests showed that the function inlining caused performance drop on
> >>>>>>>> some x86 platforms with the memory ordering patches applied.
> >>>>>>>> By force no-inline functions, the performance was better than
> >>>>>>>> before on x86 and no impact to arm64 platforms.
> >>>>>>>>
> >>>>>>>> Suggested-by: Medvedkin Vladimir<vladimir.medvedkin@intel.com>
> >>>>>>>> Signed-off-by: Ruifeng Wang<ruifeng.wang@arm.com>
> >>>>>>>> Reviewed-by: Gavin Hu<gavin.hu@arm.com>
> >>>>>>>     {
> >>>>>>>
> >>>>>>> Do you actually need to force noinline or is just taking of inline enough?
> >>>>>>> In general, letting compiler decide is often best practice.
> >>>>>> The force noinline is an optimization for x86 platforms to keep
> >>>>>> rte_lpm_add() API performance with memory ordering applied.
> >>>>> I don't think you answered my question. What does a recent version of
> >>>>> GCC do if you drop the inline.
> >>>>>
> >>>>> Actually all the functions in rte_lpm should drop inline.
> >>>> I'm agree with Stephen. If it is not a fastpath and size of function is not
> >>>> minimal it is good to remove inline qualifier for other control plane functions
> >>>> such as rule_add/delete/find/etc and let the compiler decide to inline it
> >>>> (unless it affects performance).
> >>> IMO, the rule needs to be simple. If it is control plane function, we should leave it to the compiler to decide. I do not think we need to worry too much about performance for control plane functions.
> >> Control plane is not as important as data plane speed but it is still
> >> important. For lpm we are talking not about initialization, but runtime
> >> routes add/del related functions. If it is very slow the library will be
> >> totally unusable because after it receives a route update it will be
> >> blocked for a long time and route update queue would overflow.
> > Control plane performance is more impacted by algorithmic choice.
> > The original LPM had terrible (n^2?) control path. Current code is better.
> > I had a patch using RB tree, but it was rejected because it used the
> > /usr/include/bsd/sys/tree.h which added a dependency.
>
> You're absolutely right,  control plane performance is mostly depends on
> algorithm. Current LPM implementation has number of problems there. One
> problem is rules_tbl[] that is a flat array containing routes for
> control plane purposes. Replacing it with a rb-tree solves this problem,
> but there are another problems. For example, when you try to add a route
> 10.0.0.0/8 while a number of subroutes are exist in the table (for
> example 10.20.0.0/16), current implementation will load tbl_entry -> do
> some checks (depth, ext entry) -> conditionally store new entry. Under
> several circumstances it would take a lot time.  But in fact it needs to
> unconditionally rewrite only two ranges - from 10.0.0.0 to 10.19.255.255
> and from 10.21.0.0 to 10.255.255.255. And control plane could help us to
> get this two ranges. The best struct to do so is lc-tree because it is
> relatively easy to traverse subtree (described by 10.0.0.0/8) and get
> subroutes. We are working on a new implementation, hopefully it will be
> ready soon.

Have you considered switching to this algorithm?
http://www.nxlab.fer.hr/dxr/
  
Vladimir Medvedkin July 5, 2019, 4:53 p.m. UTC | #15
Hi Alex,

On 05/07/2019 14:37, Alex Kiselev wrote:
> пт, 5 июл. 2019 г. в 13:31, Medvedkin, Vladimir <vladimir.medvedkin@intel.com>:
>> Hi Stephen,
>>
>> On 28/06/2019 16:35, Stephen Hemminger wrote:
>>> On Fri, 28 Jun 2019 15:16:30 +0100
>>> "Medvedkin, Vladimir" <vladimir.medvedkin@intel.com> wrote:
>>>
>>>> Hi Honnappa,
>>>>
>>>> On 28/06/2019 14:57, Honnappa Nagarahalli wrote:
>>>>>> Hi all,
>>>>>>
>>>>>> On 28/06/2019 05:34, Stephen Hemminger wrote:
>>>>>>> On Fri, 28 Jun 2019 02:44:54 +0000
>>>>>>> "Ruifeng Wang (Arm Technology China)"<Ruifeng.Wang@arm.com>  wrote:
>>>>>>>
>>>>>>>>>> Tests showed that the function inlining caused performance drop on
>>>>>>>>>> some x86 platforms with the memory ordering patches applied.
>>>>>>>>>> By force no-inline functions, the performance was better than
>>>>>>>>>> before on x86 and no impact to arm64 platforms.
>>>>>>>>>>
>>>>>>>>>> Suggested-by: Medvedkin Vladimir<vladimir.medvedkin@intel.com>
>>>>>>>>>> Signed-off-by: Ruifeng Wang<ruifeng.wang@arm.com>
>>>>>>>>>> Reviewed-by: Gavin Hu<gavin.hu@arm.com>
>>>>>>>>>      {
>>>>>>>>>
>>>>>>>>> Do you actually need to force noinline or is just taking of inline enough?
>>>>>>>>> In general, letting compiler decide is often best practice.
>>>>>>>> The force noinline is an optimization for x86 platforms to keep
>>>>>>>> rte_lpm_add() API performance with memory ordering applied.
>>>>>>> I don't think you answered my question. What does a recent version of
>>>>>>> GCC do if you drop the inline.
>>>>>>>
>>>>>>> Actually all the functions in rte_lpm should drop inline.
>>>>>> I'm agree with Stephen. If it is not a fastpath and size of function is not
>>>>>> minimal it is good to remove inline qualifier for other control plane functions
>>>>>> such as rule_add/delete/find/etc and let the compiler decide to inline it
>>>>>> (unless it affects performance).
>>>>> IMO, the rule needs to be simple. If it is control plane function, we should leave it to the compiler to decide. I do not think we need to worry too much about performance for control plane functions.
>>>> Control plane is not as important as data plane speed but it is still
>>>> important. For lpm we are talking not about initialization, but runtime
>>>> routes add/del related functions. If it is very slow the library will be
>>>> totally unusable because after it receives a route update it will be
>>>> blocked for a long time and route update queue would overflow.
>>> Control plane performance is more impacted by algorithmic choice.
>>> The original LPM had terrible (n^2?) control path. Current code is better.
>>> I had a patch using RB tree, but it was rejected because it used the
>>> /usr/include/bsd/sys/tree.h which added a dependency.
>> You're absolutely right,  control plane performance is mostly depends on
>> algorithm. Current LPM implementation has number of problems there. One
>> problem is rules_tbl[] that is a flat array containing routes for
>> control plane purposes. Replacing it with a rb-tree solves this problem,
>> but there are another problems. For example, when you try to add a route
>> 10.0.0.0/8 while a number of subroutes are exist in the table (for
>> example 10.20.0.0/16), current implementation will load tbl_entry -> do
>> some checks (depth, ext entry) -> conditionally store new entry. Under
>> several circumstances it would take a lot time.  But in fact it needs to
>> unconditionally rewrite only two ranges - from 10.0.0.0 to 10.19.255.255
>> and from 10.21.0.0 to 10.255.255.255. And control plane could help us to
>> get this two ranges. The best struct to do so is lc-tree because it is
>> relatively easy to traverse subtree (described by 10.0.0.0/8) and get
>> subroutes. We are working on a new implementation, hopefully it will be
>> ready soon.
> Have you considered switching to this algorithm?
> http://www.nxlab.fer.hr/dxr/
I considered DXR (and not only, for example poptrie). There are number 
of pros and cons comparing to DIR24-8. In my opinion it would be great 
to provide an option to choose an algo for your routing table.
>
  

Patch

diff --git a/lib/librte_lpm/rte_lpm.c b/lib/librte_lpm/rte_lpm.c
index 6b7b28a2e..eb835f052 100644
--- a/lib/librte_lpm/rte_lpm.c
+++ b/lib/librte_lpm/rte_lpm.c
@@ -709,7 +709,7 @@  tbl8_free_v1604(struct rte_lpm_tbl_entry *tbl8, uint32_t tbl8_group_start)
 	tbl8[tbl8_group_start].valid_group = INVALID;
 }
 
-static inline int32_t
+static __rte_noinline int32_t
 add_depth_small_v20(struct rte_lpm_v20 *lpm, uint32_t ip, uint8_t depth,
 		uint8_t next_hop)
 {
@@ -777,7 +777,7 @@  add_depth_small_v20(struct rte_lpm_v20 *lpm, uint32_t ip, uint8_t depth,
 	return 0;
 }
 
-static inline int32_t
+static __rte_noinline int32_t
 add_depth_small_v1604(struct rte_lpm *lpm, uint32_t ip, uint8_t depth,
 		uint32_t next_hop)
 {
@@ -846,7 +846,7 @@  add_depth_small_v1604(struct rte_lpm *lpm, uint32_t ip, uint8_t depth,
 	return 0;
 }
 
-static inline int32_t
+static __rte_noinline int32_t
 add_depth_big_v20(struct rte_lpm_v20 *lpm, uint32_t ip_masked, uint8_t depth,
 		uint8_t next_hop)
 {
@@ -971,7 +971,7 @@  add_depth_big_v20(struct rte_lpm_v20 *lpm, uint32_t ip_masked, uint8_t depth,
 	return 0;
 }
 
-static inline int32_t
+static __rte_noinline int32_t
 add_depth_big_v1604(struct rte_lpm *lpm, uint32_t ip_masked, uint8_t depth,
 		uint32_t next_hop)
 {