From 996c1b3d7a4d6e82e1831ff8821e5fd7e1a5522c Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Wed, 26 Jan 2011 09:24:59 -0800 Subject: [PATCH] datapath: Drop port information from odp_stats. As with n_flows, n_ports was used regularly by userspace to determine how much memory to allocate when listing ports, but it is no longer needed for that. max_ports, on the other hand, is necessary but it is also a fixed value for the kernel datapath right now and if we expand it we can also come up with a way to report the expanded value. The remaining members of odp_stats are actually real statistics that I intend to keep. Signed-off-by: Ben Pfaff Acked-by: Jesse Gross --- datapath/datapath.c | 4 ---- datapath/datapath.h | 2 -- include/openvswitch/datapath-protocol.h | 5 ----- lib/dpif-linux.c | 9 +++++++++ lib/dpif-netdev.c | 9 +++++++-- lib/dpif-provider.h | 4 ++++ lib/dpif.c | 8 ++++++++ lib/dpif.h | 1 + ofproto/ofproto.c | 10 +--------- utilities/ovs-dpctl.c | 2 -- 10 files changed, 30 insertions(+), 24 deletions(-) diff --git a/datapath/datapath.c b/datapath/datapath.c index 3cc33669..da96e3ee 100644 --- a/datapath/datapath.c +++ b/datapath/datapath.c @@ -370,7 +370,6 @@ static struct vport *new_vport(const struct vport_parms *parms) rcu_assign_pointer(dp->ports[parms->port_no], vport); list_add_rcu(&vport->node, &dp->port_list); - dp->n_ports++; dp_ifinfo_notify(RTM_NEWLINK, vport); } @@ -390,7 +389,6 @@ int dp_detach_port(struct vport *p) dp_ifinfo_notify(RTM_DELLINK, p); /* First drop references to device. */ - p->dp->n_ports--; list_del_rcu(&p->node); rcu_assign_pointer(p->dp->ports[p->port_no], NULL); @@ -1202,8 +1200,6 @@ static int get_dp_stats(struct datapath *dp, struct odp_stats __user *statsp) struct odp_stats stats; int i; - stats.n_ports = dp->n_ports; - stats.max_ports = DP_MAX_PORTS; stats.n_frags = stats.n_hit = stats.n_missed = stats.n_lost = 0; for_each_possible_cpu(i) { const struct dp_stats_percpu *percpu_stats; diff --git a/datapath/datapath.h b/datapath/datapath.h index 91c8e1e2..d8b7a6da 100644 --- a/datapath/datapath.h +++ b/datapath/datapath.h @@ -68,7 +68,6 @@ struct dp_stats_percpu { * @waitqueue: Waitqueue, for waiting for new packets in @queues. * @n_flows: Number of flows currently in flow table. * @table: Current flow table. - * @n_ports: Number of ports currently in @ports. * @ports: Map from port number to &struct vport. %ODPP_LOCAL port * always exists, other ports may be %NULL. * @port_list: List of all ports in @ports in arbitrary order. @@ -93,7 +92,6 @@ struct datapath { struct tbl __rcu *table; /* Switch ports. */ - unsigned int n_ports; struct vport __rcu *ports[DP_MAX_PORTS]; struct list_head port_list; diff --git a/include/openvswitch/datapath-protocol.h b/include/openvswitch/datapath-protocol.h index d744b9f4..ec089bfe 100644 --- a/include/openvswitch/datapath-protocol.h +++ b/include/openvswitch/datapath-protocol.h @@ -100,11 +100,6 @@ #define ODP_GET_SFLOW_PROBABILITY _IOW('O', 20, int) struct odp_stats { - /* Ports. */ - uint32_t n_ports; /* Current number of ports. */ - uint32_t max_ports; /* Maximum supported number of ports. */ - - /* Lookups. */ uint64_t n_frags; /* Number of dropped IP fragments. */ uint64_t n_hit; /* Number of flow table matches. */ uint64_t n_missed; /* Number of flow table misses. */ diff --git a/lib/dpif-linux.c b/lib/dpif-linux.c index e5ea31a5..6e85d61a 100644 --- a/lib/dpif-linux.c +++ b/lib/dpif-linux.c @@ -365,6 +365,14 @@ dpif_linux_port_query_by_name(const struct dpif *dpif, const char *devname, return dpif_linux_port_query__(dpif, 0, devname, dpif_port); } +static int +dpif_linux_get_max_ports(const struct dpif *dpif OVS_UNUSED) +{ + /* If the datapath increases its range of supported ports, then it should + * start reporting that. */ + return 1024; +} + static int dpif_linux_flow_flush(struct dpif *dpif_) { @@ -681,6 +689,7 @@ const struct dpif_class dpif_linux_class = { dpif_linux_port_del, dpif_linux_port_query_by_number, dpif_linux_port_query_by_name, + dpif_linux_get_max_ports, dpif_linux_port_dump_start, dpif_linux_port_dump_next, dpif_linux_port_dump_done, diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index 8a0363c9..8852e9d5 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -302,8 +302,6 @@ dpif_netdev_get_stats(const struct dpif *dpif, struct odp_stats *stats) { struct dp_netdev *dp = get_dp_netdev(dpif); memset(stats, 0, sizeof *stats); - stats->n_ports = dp->n_ports; - stats->max_ports = MAX_PORTS; stats->n_frags = dp->n_frags; stats->n_hit = dp->n_hit; stats->n_missed = dp->n_missed; @@ -512,6 +510,12 @@ dpif_netdev_port_query_by_name(const struct dpif *dpif, const char *devname, return error; } +static int +dpif_netdev_get_max_ports(const struct dpif *dpif OVS_UNUSED) +{ + return MAX_PORTS; +} + static void dp_netdev_free_flow(struct dp_netdev *dp, struct dp_netdev_flow *flow) { @@ -1393,6 +1397,7 @@ const struct dpif_class dpif_netdev_class = { dpif_netdev_port_del, dpif_netdev_port_query_by_number, dpif_netdev_port_query_by_name, + dpif_netdev_get_max_ports, dpif_netdev_port_dump_start, dpif_netdev_port_dump_next, dpif_netdev_port_dump_done, diff --git a/lib/dpif-provider.h b/lib/dpif-provider.h index eca00598..f6548b39 100644 --- a/lib/dpif-provider.h +++ b/lib/dpif-provider.h @@ -156,6 +156,10 @@ struct dpif_class { int (*port_query_by_name)(const struct dpif *dpif, const char *devname, struct dpif_port *port); + /* Returns one greater than the largest port number accepted in flow + * actions. */ + int (*get_max_ports)(const struct dpif *dpif); + /* Attempts to begin dumping the ports in a dpif. On success, returns 0 * and initializes '*statep' with any data needed for iteration. On * failure, returns a positive errno value. */ diff --git a/lib/dpif.c b/lib/dpif.c index a4dcf4b4..d7441967 100644 --- a/lib/dpif.c +++ b/lib/dpif.c @@ -561,6 +561,14 @@ dpif_port_query_by_name(const struct dpif *dpif, const char *devname, return error; } +/* Returns one greater than the maximum port number accepted in flow + * actions. */ +int +dpif_get_max_ports(const struct dpif *dpif) +{ + return dpif->dpif_class->get_max_ports(dpif); +} + /* Looks up port number 'port_no' in 'dpif'. On success, returns 0 and copies * the port's name into the 'name_size' bytes in 'name', ensuring that the * result is null-terminated. On failure, returns a positive errno value and diff --git a/lib/dpif.h b/lib/dpif.h index c51071da..4efabd0a 100644 --- a/lib/dpif.h +++ b/lib/dpif.h @@ -80,6 +80,7 @@ int dpif_port_query_by_name(const struct dpif *, const char *devname, struct dpif_port *); int dpif_port_get_name(struct dpif *, uint16_t port_no, char *name, size_t name_size); +int dpif_get_max_ports(const struct dpif *); struct dpif_port_dump { const struct dpif *dpif; diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c index b7a20a45..ea869f1e 100644 --- a/ofproto/ofproto.c +++ b/ofproto/ofproto.c @@ -429,7 +429,6 @@ ofproto_create(const char *datapath, const char *datapath_type, const struct ofhooks *ofhooks, void *aux, struct ofproto **ofprotop) { - struct odp_stats stats; struct ofproto *p; struct dpif *dpif; int error; @@ -444,13 +443,6 @@ ofproto_create(const char *datapath, const char *datapath_type, VLOG_ERR("failed to open datapath %s: %s", datapath, strerror(error)); return error; } - error = dpif_get_dp_stats(dpif, &stats); - if (error) { - VLOG_ERR("failed to obtain stats for datapath %s: %s", - datapath, strerror(error)); - dpif_close(dpif); - return error; - } error = dpif_recv_set_mask(dpif, ODPL_MISS | ODPL_ACTION | ODPL_SFLOW); if (error) { VLOG_ERR("failed to listen on datapath %s: %s", @@ -476,7 +468,7 @@ ofproto_create(const char *datapath, const char *datapath_type, p->netdev_monitor = netdev_monitor_create(); hmap_init(&p->ports); shash_init(&p->port_by_name); - p->max_ports = stats.max_ports; + p->max_ports = dpif_get_max_ports(dpif); /* Initialize submodules. */ p->switch_status = switch_status_create(p); diff --git a/utilities/ovs-dpctl.c b/utilities/ovs-dpctl.c index 12500805..31b15e8d 100644 --- a/utilities/ovs-dpctl.c +++ b/utilities/ovs-dpctl.c @@ -338,8 +338,6 @@ show_dpif(struct dpif *dpif) printf("%s:\n", dpif_name(dpif)); if (!dpif_get_dp_stats(dpif, &stats)) { - printf("\tports: cur:%"PRIu32", max:%"PRIu32"\n", - stats.n_ports, stats.max_ports); printf("\tlookups: frags:%llu, hit:%llu, missed:%llu, lost:%llu\n", (unsigned long long int) stats.n_frags, (unsigned long long int) stats.n_hit, -- 2.30.2