Re: [ovs-dev] [PATCH 2/3] netdev: Change macro to function.
On Mon, Nov 13, 2017 at 06:41:20PM -0800, Gregory Rose wrote: > > > On 11/13/2017 2:04 PM, Ben Pfaff wrote: > >There was no reason that this should have been a macro. > > > >Signed-off-by: Ben Pfaff> >--- > > lib/netdev.c | 17 ++--- > > 1 file changed, 10 insertions(+), 7 deletions(-) > > > >diff --git a/lib/netdev.c b/lib/netdev.c > >index 7792b1b75681..8dd35864d7cb 100644 > >--- a/lib/netdev.c > >+++ b/lib/netdev.c > >@@ -2179,18 +2179,21 @@ struct ifindex_to_port_data { > > const struct dpif_class *dpif_class; > > }; > >-#define NETDEV_PORTS_HASH_INT(port, dpif) \ > >-hash_int(odp_to_u32(port),\ > >-hash_pointer(dpif, 0)); > >+static uint32_t > >+netdev_ports_hash(odp_port_t port, const struct dpif_class *dpif_class) > >+{ > >+return hash_int(odp_to_u32(port), hash_pointer(dpif_class, 0)); > >+} > > static struct port_to_netdev_data * > > netdev_ports_lookup(odp_port_t port_no, const struct dpif_class > > *dpif_class) > > OVS_REQUIRES(netdev_hmap_mutex) > > { > >-size_t hash = NETDEV_PORTS_HASH_INT(port_no, dpif_class); > > struct port_to_netdev_data *data; > >-HMAP_FOR_EACH_WITH_HASH (data, node, hash, _to_netdev) { > >+HMAP_FOR_EACH_WITH_HASH (data, node, > >+ netdev_ports_hash(port_no, dpif_class), > >+ _to_netdev) { > > if (data->dpif_class == dpif_class > > && data->dpif_port.port_no == port_no) { > > return data; > >@@ -2203,7 +2206,6 @@ int > > netdev_ports_insert(struct netdev *netdev, const struct dpif_class > > *dpif_class, > > struct dpif_port *dpif_port) > > { > >-size_t hash = NETDEV_PORTS_HASH_INT(dpif_port->port_no, dpif_class); > > struct port_to_netdev_data *data; > > struct ifindex_to_port_data *ifidx; > > int ifindex = netdev_get_ifindex(netdev); > >@@ -2228,7 +2230,8 @@ netdev_ports_insert(struct netdev *netdev, const > >struct dpif_class *dpif_class, > > ifidx->port = dpif_port->port_no; > > ifidx->dpif_class = dpif_class; > >-hmap_insert(_to_netdev, >node, hash); > >+hmap_insert(_to_netdev, >node, > >+netdev_ports_hash(dpif_port->port_no, dpif_class)); > > hmap_insert(_to_port, >node, ifidx->ifindex); > > ovs_mutex_unlock(_hmap_mutex); > Much better. > > Reviewed-by: Greg Rose > Thanks, I applied this to master. ___ dev mailing list d...@openvswitch.org https://mail.openvswitch.org/mailman/listinfo/ovs-dev
Re: [ovs-dev] [PATCH 2/3] netdev: Change macro to function.
On 11/13/2017 2:04 PM, Ben Pfaff wrote: There was no reason that this should have been a macro. Signed-off-by: Ben Pfaff--- lib/netdev.c | 17 ++--- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/netdev.c b/lib/netdev.c index 7792b1b75681..8dd35864d7cb 100644 --- a/lib/netdev.c +++ b/lib/netdev.c @@ -2179,18 +2179,21 @@ struct ifindex_to_port_data { const struct dpif_class *dpif_class; }; -#define NETDEV_PORTS_HASH_INT(port, dpif) \ -hash_int(odp_to_u32(port),\ -hash_pointer(dpif, 0)); +static uint32_t +netdev_ports_hash(odp_port_t port, const struct dpif_class *dpif_class) +{ +return hash_int(odp_to_u32(port), hash_pointer(dpif_class, 0)); +} static struct port_to_netdev_data * netdev_ports_lookup(odp_port_t port_no, const struct dpif_class *dpif_class) OVS_REQUIRES(netdev_hmap_mutex) { -size_t hash = NETDEV_PORTS_HASH_INT(port_no, dpif_class); struct port_to_netdev_data *data; -HMAP_FOR_EACH_WITH_HASH (data, node, hash, _to_netdev) { +HMAP_FOR_EACH_WITH_HASH (data, node, + netdev_ports_hash(port_no, dpif_class), + _to_netdev) { if (data->dpif_class == dpif_class && data->dpif_port.port_no == port_no) { return data; @@ -2203,7 +2206,6 @@ int netdev_ports_insert(struct netdev *netdev, const struct dpif_class *dpif_class, struct dpif_port *dpif_port) { -size_t hash = NETDEV_PORTS_HASH_INT(dpif_port->port_no, dpif_class); struct port_to_netdev_data *data; struct ifindex_to_port_data *ifidx; int ifindex = netdev_get_ifindex(netdev); @@ -2228,7 +2230,8 @@ netdev_ports_insert(struct netdev *netdev, const struct dpif_class *dpif_class, ifidx->port = dpif_port->port_no; ifidx->dpif_class = dpif_class; -hmap_insert(_to_netdev, >node, hash); +hmap_insert(_to_netdev, >node, +netdev_ports_hash(dpif_port->port_no, dpif_class)); hmap_insert(_to_port, >node, ifidx->ifindex); ovs_mutex_unlock(_hmap_mutex); Much better. Reviewed-by: Greg Rose ___ dev mailing list d...@openvswitch.org https://mail.openvswitch.org/mailman/listinfo/ovs-dev
[ovs-dev] [PATCH 2/3] netdev: Change macro to function.
There was no reason that this should have been a macro. Signed-off-by: Ben Pfaff--- lib/netdev.c | 17 ++--- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/netdev.c b/lib/netdev.c index 7792b1b75681..8dd35864d7cb 100644 --- a/lib/netdev.c +++ b/lib/netdev.c @@ -2179,18 +2179,21 @@ struct ifindex_to_port_data { const struct dpif_class *dpif_class; }; -#define NETDEV_PORTS_HASH_INT(port, dpif) \ -hash_int(odp_to_u32(port),\ -hash_pointer(dpif, 0)); +static uint32_t +netdev_ports_hash(odp_port_t port, const struct dpif_class *dpif_class) +{ +return hash_int(odp_to_u32(port), hash_pointer(dpif_class, 0)); +} static struct port_to_netdev_data * netdev_ports_lookup(odp_port_t port_no, const struct dpif_class *dpif_class) OVS_REQUIRES(netdev_hmap_mutex) { -size_t hash = NETDEV_PORTS_HASH_INT(port_no, dpif_class); struct port_to_netdev_data *data; -HMAP_FOR_EACH_WITH_HASH (data, node, hash, _to_netdev) { +HMAP_FOR_EACH_WITH_HASH (data, node, + netdev_ports_hash(port_no, dpif_class), + _to_netdev) { if (data->dpif_class == dpif_class && data->dpif_port.port_no == port_no) { return data; @@ -2203,7 +2206,6 @@ int netdev_ports_insert(struct netdev *netdev, const struct dpif_class *dpif_class, struct dpif_port *dpif_port) { -size_t hash = NETDEV_PORTS_HASH_INT(dpif_port->port_no, dpif_class); struct port_to_netdev_data *data; struct ifindex_to_port_data *ifidx; int ifindex = netdev_get_ifindex(netdev); @@ -2228,7 +2230,8 @@ netdev_ports_insert(struct netdev *netdev, const struct dpif_class *dpif_class, ifidx->port = dpif_port->port_no; ifidx->dpif_class = dpif_class; -hmap_insert(_to_netdev, >node, hash); +hmap_insert(_to_netdev, >node, +netdev_ports_hash(dpif_port->port_no, dpif_class)); hmap_insert(_to_port, >node, ifidx->ifindex); ovs_mutex_unlock(_hmap_mutex); -- 2.10.2 ___ dev mailing list d...@openvswitch.org https://mail.openvswitch.org/mailman/listinfo/ovs-dev