diff mbox series

[net-next,09/14] nexthop: Allow reporting activity of nexthop buckets

Message ID d1e3bab356ae50c7e716721ed63d3ffeae91a451.1615387786.git.petrm@nvidia.com
State Superseded
Headers show
Series None | expand

Commit Message

Petr Machata March 10, 2021, 3:03 p.m. UTC
From: Ido Schimmel <idosch@nvidia.com>

The kernel periodically checks the idle time of nexthop buckets to
determine if they are idle and can be re-populated with a new nexthop.

When the resilient nexthop group is offloaded to hardware, the kernel
will not see activity on nexthop buckets unless it is reported from
hardware.

Add a function that can be periodically called by device drivers to
report activity on nexthop buckets after querying it from the underlying
device.

Signed-off-by: Ido Schimmel <idosch@nvidia.com>
Reviewed-by: Petr Machata <petrm@nvidia.com>
Signed-off-by: Petr Machata <petrm@nvidia.com>
---

Notes:
    v1 (changes since RFC):
    - u32 -> u16 for bucket counts / indices

 include/net/nexthop.h |  2 ++
 net/ipv4/nexthop.c    | 35 +++++++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+)

Comments

David Ahern March 11, 2021, 4:04 p.m. UTC | #1
On 3/10/21 8:03 AM, Petr Machata wrote:
> From: Ido Schimmel <idosch@nvidia.com>

> 

> The kernel periodically checks the idle time of nexthop buckets to

> determine if they are idle and can be re-populated with a new nexthop.

> 

> When the resilient nexthop group is offloaded to hardware, the kernel

> will not see activity on nexthop buckets unless it is reported from

> hardware.

> 

> Add a function that can be periodically called by device drivers to

> report activity on nexthop buckets after querying it from the underlying

> device.

> 

> Signed-off-by: Ido Schimmel <idosch@nvidia.com>

> Reviewed-by: Petr Machata <petrm@nvidia.com>

> Signed-off-by: Petr Machata <petrm@nvidia.com>

> ---

> 

> Notes:

>     v1 (changes since RFC):

>     - u32 -> u16 for bucket counts / indices

> 

>  include/net/nexthop.h |  2 ++

>  net/ipv4/nexthop.c    | 35 +++++++++++++++++++++++++++++++++++

>  2 files changed, 37 insertions(+)

> 


Reviewed-by: David Ahern <dsahern@kernel.org>
diff mbox series

Patch

diff --git a/include/net/nexthop.h b/include/net/nexthop.h
index 685f208d26b5..ba94868a21d5 100644
--- a/include/net/nexthop.h
+++ b/include/net/nexthop.h
@@ -222,6 +222,8 @@  int unregister_nexthop_notifier(struct net *net, struct notifier_block *nb);
 void nexthop_set_hw_flags(struct net *net, u32 id, bool offload, bool trap);
 void nexthop_bucket_set_hw_flags(struct net *net, u32 id, u16 bucket_index,
 				 bool offload, bool trap);
+void nexthop_res_grp_activity_update(struct net *net, u32 id, u16 num_buckets,
+				     unsigned long *activity);
 
 /* caller is holding rcu or rtnl; no reference taken to nexthop */
 struct nexthop *nexthop_find_by_id(struct net *net, u32 id);
diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c
index 1fce4ff39390..495b5e69ffcd 100644
--- a/net/ipv4/nexthop.c
+++ b/net/ipv4/nexthop.c
@@ -3106,6 +3106,41 @@  void nexthop_bucket_set_hw_flags(struct net *net, u32 id, u16 bucket_index,
 }
 EXPORT_SYMBOL(nexthop_bucket_set_hw_flags);
 
+void nexthop_res_grp_activity_update(struct net *net, u32 id, u16 num_buckets,
+				     unsigned long *activity)
+{
+	struct nh_res_table *res_table;
+	struct nexthop *nexthop;
+	struct nh_group *nhg;
+	u16 i;
+
+	rcu_read_lock();
+
+	nexthop = nexthop_find_by_id(net, id);
+	if (!nexthop || !nexthop->is_group)
+		goto out;
+
+	nhg = rcu_dereference(nexthop->nh_grp);
+	if (!nhg->resilient)
+		goto out;
+
+	/* Instead of silently ignoring some buckets, demand that the sizes
+	 * be the same.
+	 */
+	res_table = rcu_dereference(nhg->res_table);
+	if (num_buckets != res_table->num_nh_buckets)
+		goto out;
+
+	for (i = 0; i < num_buckets; i++) {
+		if (test_bit(i, activity))
+			nh_res_bucket_set_busy(&res_table->nh_buckets[i]);
+	}
+
+out:
+	rcu_read_unlock();
+}
+EXPORT_SYMBOL(nexthop_res_grp_activity_update);
+
 static void __net_exit nexthop_net_exit(struct net *net)
 {
 	rtnl_lock();