Re: [ovs-dev] [PATCH v6 18/18] lib/rstp: Use hmap instead of a list for ports.
Series pushed to master, thank you for your contribution!
Jarno
On Sep 9, 2014, at 3:39 AM, Daniele Venturino
wrote:
> Acked-by: Daniele Venturino
>
> 2014-08-21 1:57 GMT+02:00 Jarno Rajahalme :
> Finding a given port is faster.
>
> Signed-off-by: Jarno Rajahalme
> ---
> lib/rstp-common.h |5 +++--
> lib/rstp-state-machines.c | 30 +++---
> lib/rstp.c| 35 ++-
> 3 files changed, 36 insertions(+), 34 deletions(-)
>
> diff --git a/lib/rstp-common.h b/lib/rstp-common.h
> index 2be5861..dd756ef 100644
> --- a/lib/rstp-common.h
> +++ b/lib/rstp-common.h
> @@ -32,6 +32,7 @@
> #include "rstp.h"
> #include
> #include
> +#include "hmap.h"
> #include "list.h"
> #include "ovs-atomic.h"
> #include "packets.h"
> @@ -264,7 +265,7 @@ struct rstp_port {
> struct ovs_refcount ref_cnt;
>
> struct rstp *rstp OVS_GUARDED_BY(rstp_mutex);
> -struct list node OVS_GUARDED_BY(rstp_mutex); /* Node in rstp->ports
> list. */
> +struct hmap_node node OVS_GUARDED_BY(rstp_mutex); /* In rstp->ports. */
> void *aux OVS_GUARDED_BY(rstp_mutex);
> struct rstp_bpdu received_bpdu_buffer OVS_GUARDED_BY(rstp_mutex);
>
> /*
> @@ -866,7 +867,7 @@ struct rstp {
> bool stp_version OVS_GUARDED_BY(rstp_mutex);
>
> /* Ports */
> -struct list ports OVS_GUARDED_BY(rstp_mutex);
> +struct hmap ports OVS_GUARDED_BY(rstp_mutex);
>
> struct ovs_refcount ref_cnt;
>
> diff --git a/lib/rstp-state-machines.c b/lib/rstp-state-machines.c
> index c40449d..2a98f62 100644
> --- a/lib/rstp-state-machines.c
> +++ b/lib/rstp-state-machines.c
> @@ -190,7 +190,7 @@ move_rstp__(struct rstp *rstp)
>
> rstp->changes = false;
> port_role_selection_sm(rstp);
> -LIST_FOR_EACH (p, node, &rstp->ports) {
> +HMAP_FOR_EACH (p, node, &rstp->ports) {
> if (p->rstp_state != RSTP_DISABLED) {
> port_receive_sm(p);
> bridge_detection_sm(p);
> @@ -217,7 +217,7 @@ void decrease_rstp_port_timers__(struct rstp *r)
> {
> struct rstp_port *p;
>
> -LIST_FOR_EACH (p, node, &r->ports) {
> +HMAP_FOR_EACH (p, node, &r->ports) {
> decrement_timer(&p->hello_when);
> decrement_timer(&p->tc_while);
> decrement_timer(&p->fd_while);
> @@ -250,7 +250,7 @@ updt_role_disabled_tree(struct rstp *r)
> {
> struct rstp_port *p;
>
> -LIST_FOR_EACH (p, node, &r->ports) {
> +HMAP_FOR_EACH (p, node, &r->ports) {
> p->selected_role = ROLE_DISABLED;
> }
> }
> @@ -261,7 +261,7 @@ clear_reselect_tree(struct rstp *r)
> {
> struct rstp_port *p;
>
> -LIST_FOR_EACH (p, node, &r->ports) {
> +HMAP_FOR_EACH (p, node, &r->ports) {
> p->reselect = false;
> }
> }
> @@ -279,7 +279,7 @@ updt_roles_tree__(struct rstp *r)
> /* Letter c1) */
> r->root_times = r->bridge_times;
> /* Letters a) b) c) */
> -LIST_FOR_EACH (p, node, &r->ports) {
> +HMAP_FOR_EACH (p, node, &r->ports) {
> uint32_t old_root_path_cost;
> uint32_t root_path_cost;
>
> @@ -310,7 +310,7 @@ updt_roles_tree__(struct rstp *r)
> VLOG_DBG("%s: new Root is "RSTP_ID_FMT"", r->name,
> RSTP_ID_ARGS(r->root_priority.root_bridge_id));
> /* Letters d) e) */
> -LIST_FOR_EACH (p, node, &r->ports) {
> +HMAP_FOR_EACH (p, node, &r->ports) {
> p->designated_priority_vector.root_bridge_id =
> r->root_priority.root_bridge_id;
> p->designated_priority_vector.root_path_cost =
> @@ -322,7 +322,7 @@ updt_roles_tree__(struct rstp *r)
> p->designated_times = r->root_times;
> p->designated_times.hello_time = r->bridge_times.hello_time;
> }
> -LIST_FOR_EACH (p, node, &r->ports) {
> +HMAP_FOR_EACH (p, node, &r->ports) {
> switch (p->info_is) {
> case INFO_IS_DISABLED:
> p->selected_role = ROLE_DISABLED;
> @@ -374,12 +374,12 @@ set_selected_tree(struct rstp *r)
> {
> struct rstp_port *p;
>
> -LIST_FOR_EACH (p, node, &r->ports) {
> +HMAP_FOR_EACH (p, node, &r->ports) {
> if (p->reselect) {
> return;
> }
> }
> -LIST_FOR_EACH (p, node, &r->ports) {
> +HMAP_FOR_EACH (p, node, &r->ports) {
> p->selected = true;
> }
> }
> @@ -416,7 +416,7 @@ port_role_selection_sm(struct rstp *r)
> PORT_ROLE_SELECTION_SM_ROLE_SELECTION;
> /* no break */
> case PORT_ROLE_SELECTION_SM_ROLE_SELECTION:
> -LIST_FOR_EACH (p, node, &r->ports) {
> +HMAP_FOR_EACH (p, node, &r->ports) {
> if (p->reselect) {
> r->port_role_selection_sm_state =
> PORT_ROLE_SELECTION_SM_ROLE_SELECTION_EXEC;
> @@ -1260,7 +1260,7 @@ set_re_root_tree(struct rstp_port *p)
> struct rstp_port *p1;
>
>
Re: [ovs-dev] [PATCH v6 18/18] lib/rstp: Use hmap instead of a list for ports.
Acked-by: Daniele Venturino
2014-08-21 1:57 GMT+02:00 Jarno Rajahalme :
> Finding a given port is faster.
>
> Signed-off-by: Jarno Rajahalme
> ---
> lib/rstp-common.h |5 +++--
> lib/rstp-state-machines.c | 30 +++---
> lib/rstp.c| 35 ++-
> 3 files changed, 36 insertions(+), 34 deletions(-)
>
> diff --git a/lib/rstp-common.h b/lib/rstp-common.h
> index 2be5861..dd756ef 100644
> --- a/lib/rstp-common.h
> +++ b/lib/rstp-common.h
> @@ -32,6 +32,7 @@
> #include "rstp.h"
> #include
> #include
> +#include "hmap.h"
> #include "list.h"
> #include "ovs-atomic.h"
> #include "packets.h"
> @@ -264,7 +265,7 @@ struct rstp_port {
> struct ovs_refcount ref_cnt;
>
> struct rstp *rstp OVS_GUARDED_BY(rstp_mutex);
> -struct list node OVS_GUARDED_BY(rstp_mutex); /* Node in rstp->ports
> list. */
> +struct hmap_node node OVS_GUARDED_BY(rstp_mutex); /* In rstp->ports.
> */
> void *aux OVS_GUARDED_BY(rstp_mutex);
> struct rstp_bpdu received_bpdu_buffer OVS_GUARDED_BY(rstp_mutex);
>
> /*
> @@ -866,7 +867,7 @@ struct rstp {
> bool stp_version OVS_GUARDED_BY(rstp_mutex);
>
> /* Ports */
> -struct list ports OVS_GUARDED_BY(rstp_mutex);
> +struct hmap ports OVS_GUARDED_BY(rstp_mutex);
>
> struct ovs_refcount ref_cnt;
>
> diff --git a/lib/rstp-state-machines.c b/lib/rstp-state-machines.c
> index c40449d..2a98f62 100644
> --- a/lib/rstp-state-machines.c
> +++ b/lib/rstp-state-machines.c
> @@ -190,7 +190,7 @@ move_rstp__(struct rstp *rstp)
>
> rstp->changes = false;
> port_role_selection_sm(rstp);
> -LIST_FOR_EACH (p, node, &rstp->ports) {
> +HMAP_FOR_EACH (p, node, &rstp->ports) {
> if (p->rstp_state != RSTP_DISABLED) {
> port_receive_sm(p);
> bridge_detection_sm(p);
> @@ -217,7 +217,7 @@ void decrease_rstp_port_timers__(struct rstp *r)
> {
> struct rstp_port *p;
>
> -LIST_FOR_EACH (p, node, &r->ports) {
> +HMAP_FOR_EACH (p, node, &r->ports) {
> decrement_timer(&p->hello_when);
> decrement_timer(&p->tc_while);
> decrement_timer(&p->fd_while);
> @@ -250,7 +250,7 @@ updt_role_disabled_tree(struct rstp *r)
> {
> struct rstp_port *p;
>
> -LIST_FOR_EACH (p, node, &r->ports) {
> +HMAP_FOR_EACH (p, node, &r->ports) {
> p->selected_role = ROLE_DISABLED;
> }
> }
> @@ -261,7 +261,7 @@ clear_reselect_tree(struct rstp *r)
> {
> struct rstp_port *p;
>
> -LIST_FOR_EACH (p, node, &r->ports) {
> +HMAP_FOR_EACH (p, node, &r->ports) {
> p->reselect = false;
> }
> }
> @@ -279,7 +279,7 @@ updt_roles_tree__(struct rstp *r)
> /* Letter c1) */
> r->root_times = r->bridge_times;
> /* Letters a) b) c) */
> -LIST_FOR_EACH (p, node, &r->ports) {
> +HMAP_FOR_EACH (p, node, &r->ports) {
> uint32_t old_root_path_cost;
> uint32_t root_path_cost;
>
> @@ -310,7 +310,7 @@ updt_roles_tree__(struct rstp *r)
> VLOG_DBG("%s: new Root is "RSTP_ID_FMT"", r->name,
> RSTP_ID_ARGS(r->root_priority.root_bridge_id));
> /* Letters d) e) */
> -LIST_FOR_EACH (p, node, &r->ports) {
> +HMAP_FOR_EACH (p, node, &r->ports) {
> p->designated_priority_vector.root_bridge_id =
> r->root_priority.root_bridge_id;
> p->designated_priority_vector.root_path_cost =
> @@ -322,7 +322,7 @@ updt_roles_tree__(struct rstp *r)
> p->designated_times = r->root_times;
> p->designated_times.hello_time = r->bridge_times.hello_time;
> }
> -LIST_FOR_EACH (p, node, &r->ports) {
> +HMAP_FOR_EACH (p, node, &r->ports) {
> switch (p->info_is) {
> case INFO_IS_DISABLED:
> p->selected_role = ROLE_DISABLED;
> @@ -374,12 +374,12 @@ set_selected_tree(struct rstp *r)
> {
> struct rstp_port *p;
>
> -LIST_FOR_EACH (p, node, &r->ports) {
> +HMAP_FOR_EACH (p, node, &r->ports) {
> if (p->reselect) {
> return;
> }
> }
> -LIST_FOR_EACH (p, node, &r->ports) {
> +HMAP_FOR_EACH (p, node, &r->ports) {
> p->selected = true;
> }
> }
> @@ -416,7 +416,7 @@ port_role_selection_sm(struct rstp *r)
> PORT_ROLE_SELECTION_SM_ROLE_SELECTION;
> /* no break */
> case PORT_ROLE_SELECTION_SM_ROLE_SELECTION:
> -LIST_FOR_EACH (p, node, &r->ports) {
> +HMAP_FOR_EACH (p, node, &r->ports) {
> if (p->reselect) {
> r->port_role_selection_sm_state =
> PORT_ROLE_SELECTION_SM_ROLE_SELECTION_EXEC;
> @@ -1260,7 +1260,7 @@ set_re_root_tree(struct rstp_port *p)
> struct rstp_port *p1;
>
> r = p->rstp;
> -LIST_FOR_EACH (p1, node, &r->ports) {
> +HMAP_FOR_EACH (p1, node, &r->ports) {
> p1->re_root = true;
>
[ovs-dev] [PATCH v6 18/18] lib/rstp: Use hmap instead of a list for ports.
Finding a given port is faster.
Signed-off-by: Jarno Rajahalme
---
lib/rstp-common.h |5 +++--
lib/rstp-state-machines.c | 30 +++---
lib/rstp.c| 35 ++-
3 files changed, 36 insertions(+), 34 deletions(-)
diff --git a/lib/rstp-common.h b/lib/rstp-common.h
index 2be5861..dd756ef 100644
--- a/lib/rstp-common.h
+++ b/lib/rstp-common.h
@@ -32,6 +32,7 @@
#include "rstp.h"
#include
#include
+#include "hmap.h"
#include "list.h"
#include "ovs-atomic.h"
#include "packets.h"
@@ -264,7 +265,7 @@ struct rstp_port {
struct ovs_refcount ref_cnt;
struct rstp *rstp OVS_GUARDED_BY(rstp_mutex);
-struct list node OVS_GUARDED_BY(rstp_mutex); /* Node in rstp->ports list.
*/
+struct hmap_node node OVS_GUARDED_BY(rstp_mutex); /* In rstp->ports. */
void *aux OVS_GUARDED_BY(rstp_mutex);
struct rstp_bpdu received_bpdu_buffer OVS_GUARDED_BY(rstp_mutex);
/*
@@ -866,7 +867,7 @@ struct rstp {
bool stp_version OVS_GUARDED_BY(rstp_mutex);
/* Ports */
-struct list ports OVS_GUARDED_BY(rstp_mutex);
+struct hmap ports OVS_GUARDED_BY(rstp_mutex);
struct ovs_refcount ref_cnt;
diff --git a/lib/rstp-state-machines.c b/lib/rstp-state-machines.c
index c40449d..2a98f62 100644
--- a/lib/rstp-state-machines.c
+++ b/lib/rstp-state-machines.c
@@ -190,7 +190,7 @@ move_rstp__(struct rstp *rstp)
rstp->changes = false;
port_role_selection_sm(rstp);
-LIST_FOR_EACH (p, node, &rstp->ports) {
+HMAP_FOR_EACH (p, node, &rstp->ports) {
if (p->rstp_state != RSTP_DISABLED) {
port_receive_sm(p);
bridge_detection_sm(p);
@@ -217,7 +217,7 @@ void decrease_rstp_port_timers__(struct rstp *r)
{
struct rstp_port *p;
-LIST_FOR_EACH (p, node, &r->ports) {
+HMAP_FOR_EACH (p, node, &r->ports) {
decrement_timer(&p->hello_when);
decrement_timer(&p->tc_while);
decrement_timer(&p->fd_while);
@@ -250,7 +250,7 @@ updt_role_disabled_tree(struct rstp *r)
{
struct rstp_port *p;
-LIST_FOR_EACH (p, node, &r->ports) {
+HMAP_FOR_EACH (p, node, &r->ports) {
p->selected_role = ROLE_DISABLED;
}
}
@@ -261,7 +261,7 @@ clear_reselect_tree(struct rstp *r)
{
struct rstp_port *p;
-LIST_FOR_EACH (p, node, &r->ports) {
+HMAP_FOR_EACH (p, node, &r->ports) {
p->reselect = false;
}
}
@@ -279,7 +279,7 @@ updt_roles_tree__(struct rstp *r)
/* Letter c1) */
r->root_times = r->bridge_times;
/* Letters a) b) c) */
-LIST_FOR_EACH (p, node, &r->ports) {
+HMAP_FOR_EACH (p, node, &r->ports) {
uint32_t old_root_path_cost;
uint32_t root_path_cost;
@@ -310,7 +310,7 @@ updt_roles_tree__(struct rstp *r)
VLOG_DBG("%s: new Root is "RSTP_ID_FMT"", r->name,
RSTP_ID_ARGS(r->root_priority.root_bridge_id));
/* Letters d) e) */
-LIST_FOR_EACH (p, node, &r->ports) {
+HMAP_FOR_EACH (p, node, &r->ports) {
p->designated_priority_vector.root_bridge_id =
r->root_priority.root_bridge_id;
p->designated_priority_vector.root_path_cost =
@@ -322,7 +322,7 @@ updt_roles_tree__(struct rstp *r)
p->designated_times = r->root_times;
p->designated_times.hello_time = r->bridge_times.hello_time;
}
-LIST_FOR_EACH (p, node, &r->ports) {
+HMAP_FOR_EACH (p, node, &r->ports) {
switch (p->info_is) {
case INFO_IS_DISABLED:
p->selected_role = ROLE_DISABLED;
@@ -374,12 +374,12 @@ set_selected_tree(struct rstp *r)
{
struct rstp_port *p;
-LIST_FOR_EACH (p, node, &r->ports) {
+HMAP_FOR_EACH (p, node, &r->ports) {
if (p->reselect) {
return;
}
}
-LIST_FOR_EACH (p, node, &r->ports) {
+HMAP_FOR_EACH (p, node, &r->ports) {
p->selected = true;
}
}
@@ -416,7 +416,7 @@ port_role_selection_sm(struct rstp *r)
PORT_ROLE_SELECTION_SM_ROLE_SELECTION;
/* no break */
case PORT_ROLE_SELECTION_SM_ROLE_SELECTION:
-LIST_FOR_EACH (p, node, &r->ports) {
+HMAP_FOR_EACH (p, node, &r->ports) {
if (p->reselect) {
r->port_role_selection_sm_state =
PORT_ROLE_SELECTION_SM_ROLE_SELECTION_EXEC;
@@ -1260,7 +1260,7 @@ set_re_root_tree(struct rstp_port *p)
struct rstp_port *p1;
r = p->rstp;
-LIST_FOR_EACH (p1, node, &r->ports) {
+HMAP_FOR_EACH (p1, node, &r->ports) {
p1->re_root = true;
}
}
@@ -1273,7 +1273,7 @@ set_sync_tree(struct rstp_port *p)
struct rstp_port *p1;
r = p->rstp;
-LIST_FOR_EACH (p1, node, &r->ports) {
+HMAP_FOR_EACH (p1, node, &r->ports) {
p1->sync = true;
}
}
@@ -1361,7 +1361,7 @@ re_rooted(struct rstp_port *p)
struct rstp_port *p1;
r = p->rs
