Lines Matching +full:atomic +full:- +full:threshold +full:- +full:us
1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (C) 2013-2020 B.A.T.M.A.N. contributors:
10 #include <linux/atomic.h>
39 #include "hard-interface.h"
47 struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface); in batadv_v_iface_activate()
61 if (hard_iface->if_status == BATADV_IF_TO_BE_ACTIVATED) in batadv_v_iface_activate()
62 hard_iface->if_status = BATADV_IF_ACTIVE; in batadv_v_iface_activate()
93 * batadv_v_iface_update_mac() - react to hard-interface MAC address change
101 struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface); in batadv_v_iface_update_mac()
117 ewma_throughput_init(&hardif_neigh->bat_v.throughput); in batadv_v_hardif_neigh_init()
118 INIT_WORK(&hardif_neigh->bat_v.metric_work, in batadv_v_hardif_neigh_init()
124 * batadv_v_orig_print_neigh() - print neighbors for the originator table
139 hlist_for_each_entry_rcu(neigh_node, &orig_node->neigh_list, list) { in batadv_v_orig_print_neigh()
145 neigh_node->addr, in batadv_v_orig_print_neigh()
146 n_ifinfo->bat_v.throughput / 10, in batadv_v_orig_print_neigh()
147 n_ifinfo->bat_v.throughput % 10); in batadv_v_orig_print_neigh()
154 * batadv_v_hardif_neigh_print() - print a single ELP neighbour node
165 last_secs = jiffies_to_msecs(jiffies - hardif_neigh->last_seen) / 1000; in batadv_v_hardif_neigh_print()
166 last_msecs = jiffies_to_msecs(jiffies - hardif_neigh->last_seen) % 1000; in batadv_v_hardif_neigh_print()
167 throughput = ewma_throughput_read(&hardif_neigh->bat_v.throughput); in batadv_v_hardif_neigh_print()
170 hardif_neigh->addr, last_secs, last_msecs, throughput / 10, in batadv_v_hardif_neigh_print()
171 throughput % 10, hardif_neigh->if_incoming->net_dev->name); in batadv_v_hardif_neigh_print()
175 * batadv_v_neigh_print() - print the single hop neighbour list
182 struct net_device *net_dev = (struct net_device *)seq->private; in batadv_v_neigh_print()
188 " Neighbor last-seen ( throughput) [ IF]\n"); in batadv_v_neigh_print()
192 if (hard_iface->soft_iface != net_dev) in batadv_v_neigh_print()
196 &hard_iface->neigh_list, list) { in batadv_v_neigh_print()
209 * batadv_v_neigh_dump_neigh() - Dump a neighbour into a message
225 last_seen_msecs = jiffies_to_msecs(jiffies - hardif_neigh->last_seen); in batadv_v_neigh_dump_neigh()
226 throughput = ewma_throughput_read(&hardif_neigh->bat_v.throughput); in batadv_v_neigh_dump_neigh()
232 return -ENOBUFS; in batadv_v_neigh_dump_neigh()
235 hardif_neigh->addr) || in batadv_v_neigh_dump_neigh()
237 hardif_neigh->if_incoming->net_dev->ifindex) || in batadv_v_neigh_dump_neigh()
248 return -EMSGSIZE; in batadv_v_neigh_dump_neigh()
252 * batadv_v_neigh_dump_hardif() - Dump the neighbours of a hard interface into
275 &hard_iface->neigh_list, list) { in batadv_v_neigh_dump_hardif()
280 *idx_s = idx - 1; in batadv_v_neigh_dump_hardif()
281 return -EMSGSIZE; in batadv_v_neigh_dump_hardif()
290 * batadv_v_neigh_dump() - Dump the neighbours of a hard interface into a
304 int i_hardif_s = cb->args[0]; in batadv_v_neigh_dump()
305 int idx = cb->args[1]; in batadv_v_neigh_dump()
306 int portid = NETLINK_CB(cb->skb).portid; in batadv_v_neigh_dump()
312 cb->nlh->nlmsg_seq, in batadv_v_neigh_dump()
319 if (hard_iface->soft_iface != bat_priv->soft_iface) in batadv_v_neigh_dump()
326 cb->nlh->nlmsg_seq, in batadv_v_neigh_dump()
329 i_hardif--; in batadv_v_neigh_dump()
336 cb->args[0] = i_hardif; in batadv_v_neigh_dump()
337 cb->args[1] = idx; in batadv_v_neigh_dump()
342 * batadv_v_orig_print() - print the originator table
352 struct batadv_hashtable *hash = bat_priv->orig_hash; in batadv_v_orig_print()
362 …" Originator last-seen ( throughput) Nexthop [outgoingIF]: Potential nexthops ..… in batadv_v_orig_print()
364 for (i = 0; i < hash->size; i++) { in batadv_v_orig_print()
365 head = &hash->table[i]; in batadv_v_orig_print()
379 last_seen_jiffies = jiffies - orig_node->last_seen; in batadv_v_orig_print()
385 orig_node->orig, last_seen_secs, in batadv_v_orig_print()
387 n_ifinfo->bat_v.throughput / 10, in batadv_v_orig_print()
388 n_ifinfo->bat_v.throughput % 10, in batadv_v_orig_print()
389 neigh_node->addr, in batadv_v_orig_print()
390 neigh_node->if_incoming->net_dev->name); in batadv_v_orig_print()
410 * batadv_v_orig_dump_subentry() - Dump an originator subentry into a message
439 throughput = n_ifinfo->bat_v.throughput * 100; in batadv_v_orig_dump_subentry()
443 last_seen_msecs = jiffies_to_msecs(jiffies - orig_node->last_seen); in batadv_v_orig_dump_subentry()
446 if_outgoing != neigh_node->if_incoming) in batadv_v_orig_dump_subentry()
452 return -ENOBUFS; in batadv_v_orig_dump_subentry()
454 if (nla_put(msg, BATADV_ATTR_ORIG_ADDRESS, ETH_ALEN, orig_node->orig) || in batadv_v_orig_dump_subentry()
456 neigh_node->addr) || in batadv_v_orig_dump_subentry()
458 neigh_node->if_incoming->net_dev->ifindex) || in batadv_v_orig_dump_subentry()
472 return -EMSGSIZE; in batadv_v_orig_dump_subentry()
476 * batadv_v_orig_dump_entry() - Dump an originator entry into a message
504 hlist_for_each_entry_rcu(neigh_node, &orig_node->neigh_list, list) { in batadv_v_orig_dump_entry()
515 *sub_s = sub - 1; in batadv_v_orig_dump_entry()
516 return -EMSGSIZE; in batadv_v_orig_dump_entry()
529 * batadv_v_orig_dump_bucket() - Dump an originator bucket into a message
558 *idx_s = idx - 1; in batadv_v_orig_dump_bucket()
559 return -EMSGSIZE; in batadv_v_orig_dump_bucket()
570 * batadv_v_orig_dump() - Dump the originators into a message
581 struct batadv_hashtable *hash = bat_priv->orig_hash; in batadv_v_orig_dump()
583 int bucket = cb->args[0]; in batadv_v_orig_dump()
584 int idx = cb->args[1]; in batadv_v_orig_dump()
585 int sub = cb->args[2]; in batadv_v_orig_dump()
586 int portid = NETLINK_CB(cb->skb).portid; in batadv_v_orig_dump()
588 while (bucket < hash->size) { in batadv_v_orig_dump()
589 head = &hash->table[bucket]; in batadv_v_orig_dump()
592 cb->nlh->nlmsg_seq, in batadv_v_orig_dump()
600 cb->args[0] = bucket; in batadv_v_orig_dump()
601 cb->args[1] = idx; in batadv_v_orig_dump()
602 cb->args[2] = sub; in batadv_v_orig_dump()
621 ret = ifinfo1->bat_v.throughput - ifinfo2->bat_v.throughput; in batadv_v_neigh_cmp()
636 u32 threshold; in batadv_v_neigh_is_sob() local
647 threshold = ifinfo1->bat_v.throughput / 4; in batadv_v_neigh_is_sob()
648 threshold = ifinfo1->bat_v.throughput - threshold; in batadv_v_neigh_is_sob()
650 ret = ifinfo2->bat_v.throughput > threshold; in batadv_v_neigh_is_sob()
660 * batadv_v_init_sel_class() - initialize GW selection class
665 /* set default throughput difference threshold to 5Mbps */ in batadv_v_init_sel_class()
666 atomic_set(&bat_priv->gw.sel_class, 50); in batadv_v_init_sel_class()
674 if (!batadv_parse_throughput(bat_priv->soft_iface, buff, in batadv_v_store_sel_class()
677 return -EINVAL; in batadv_v_store_sel_class()
679 old_class = atomic_read(&bat_priv->gw.sel_class); in batadv_v_store_sel_class()
680 atomic_set(&bat_priv->gw.sel_class, class); in batadv_v_store_sel_class()
690 u32 class = atomic_read(&bat_priv->gw.sel_class); in batadv_v_show_sel_class()
696 * batadv_v_gw_throughput_get() - retrieve the GW-bandwidth for a given GW
702 * Return: 0 on success, -1 on failure
709 int ret = -1; in batadv_v_gw_throughput_get()
711 orig_node = gw_node->orig_node; in batadv_v_gw_throughput_get()
722 * This gives us an approximation of the effective throughput that the in batadv_v_gw_throughput_get()
725 *bw = router_ifinfo->bat_v.throughput; in batadv_v_gw_throughput_get()
726 *bw = min_t(u32, *bw, gw_node->bandwidth_down); in batadv_v_gw_throughput_get()
739 * batadv_v_gw_get_best_gw_node() - retrieve the best GW node
742 * Return: the GW node having the best GW-metric, NULL if no GW is known
751 hlist_for_each_entry_rcu(gw_node, &bat_priv->gw.gateway_list, list) { in batadv_v_gw_get_best_gw_node()
752 if (!kref_get_unless_zero(&gw_node->refcount)) in batadv_v_gw_get_best_gw_node()
765 kref_get(&curr_gw->refcount); in batadv_v_gw_get_best_gw_node()
777 * batadv_v_gw_is_eligible() - check if a originator would be selected as GW
789 u32 gw_throughput, orig_throughput, threshold; in batadv_v_gw_is_eligible() local
792 threshold = atomic_read(&bat_priv->gw.sel_class); in batadv_v_gw_is_eligible()
815 if ((orig_throughput - gw_throughput) < threshold) in batadv_v_gw_is_eligible()
841 int ret = -1; in batadv_v_gw_write_buffer_text()
843 router = batadv_orig_router_get(gw_node->orig_node, BATADV_IF_DEFAULT); in batadv_v_gw_write_buffer_text()
855 gw_node->orig_node->orig, in batadv_v_gw_write_buffer_text()
856 router_ifinfo->bat_v.throughput / 10, in batadv_v_gw_write_buffer_text()
857 router_ifinfo->bat_v.throughput % 10, router->addr, in batadv_v_gw_write_buffer_text()
858 router->if_incoming->net_dev->name, in batadv_v_gw_write_buffer_text()
859 gw_node->bandwidth_down / 10, in batadv_v_gw_write_buffer_text()
860 gw_node->bandwidth_down % 10, in batadv_v_gw_write_buffer_text()
861 gw_node->bandwidth_up / 10, in batadv_v_gw_write_buffer_text()
862 gw_node->bandwidth_up % 10); in batadv_v_gw_write_buffer_text()
863 ret = seq_has_overflowed(seq) ? -1 : 0; in batadv_v_gw_write_buffer_text()
876 * batadv_v_gw_print() - print the gateway list
890 hlist_for_each_entry_rcu(gw_node, &bat_priv->gw.gateway_list, list) { in batadv_v_gw_print()
905 * batadv_v_gw_dump_entry() - Dump a gateway into a message
925 router = batadv_orig_router_get(gw_node->orig_node, BATADV_IF_DEFAULT); in batadv_v_gw_dump_entry()
935 hdr = genlmsg_put(msg, portid, cb->nlh->nlmsg_seq, in batadv_v_gw_dump_entry()
939 ret = -ENOBUFS; in batadv_v_gw_dump_entry()
945 ret = -EMSGSIZE; in batadv_v_gw_dump_entry()
955 gw_node->orig_node->orig)) { in batadv_v_gw_dump_entry()
961 router_ifinfo->bat_v.throughput)) { in batadv_v_gw_dump_entry()
966 if (nla_put(msg, BATADV_ATTR_ROUTER, ETH_ALEN, router->addr)) { in batadv_v_gw_dump_entry()
972 router->if_incoming->net_dev->name)) { in batadv_v_gw_dump_entry()
978 gw_node->bandwidth_down)) { in batadv_v_gw_dump_entry()
983 if (nla_put_u32(msg, BATADV_ATTR_BANDWIDTH_UP, gw_node->bandwidth_up)) { in batadv_v_gw_dump_entry()
1002 * batadv_v_gw_dump() - Dump gateways into a message
1010 int portid = NETLINK_CB(cb->skb).portid; in batadv_v_gw_dump()
1012 int idx_skip = cb->args[0]; in batadv_v_gw_dump()
1015 spin_lock_bh(&bat_priv->gw.list_lock); in batadv_v_gw_dump()
1016 cb->seq = bat_priv->gw.generation << 1 | 1; in batadv_v_gw_dump()
1018 hlist_for_each_entry(gw_node, &bat_priv->gw.gateway_list, list) { in batadv_v_gw_dump()
1024 idx_skip = idx - 1; in batadv_v_gw_dump()
1031 spin_unlock_bh(&bat_priv->gw.list_lock); in batadv_v_gw_dump()
1033 cb->args[0] = idx_skip; in batadv_v_gw_dump()
1074 * batadv_v_hardif_init() - initialize the algorithm specific fields in the
1075 * hard-interface object
1076 * @hard_iface: the hard-interface to initialize
1080 /* enable link throughput auto-detection by setting the throughput in batadv_v_hardif_init()
1083 atomic_set(&hard_iface->bat_v.throughput_override, 0); in batadv_v_hardif_init()
1084 atomic_set(&hard_iface->bat_v.elp_interval, 500); in batadv_v_hardif_init()
1086 hard_iface->bat_v.aggr_len = 0; in batadv_v_hardif_init()
1087 skb_queue_head_init(&hard_iface->bat_v.aggr_list); in batadv_v_hardif_init()
1088 INIT_DELAYED_WORK(&hard_iface->bat_v.aggr_wq, in batadv_v_hardif_init()
1093 * batadv_v_mesh_init() - initialize the B.A.T.M.A.N. V private resources for a
1111 * batadv_v_mesh_free() - free the B.A.T.M.A.N. V private resources for a mesh
1120 * batadv_v_init() - B.A.T.M.A.N. V initialization function