Skip to content

Commit 8c87663

Browse files
Pravin B Shelardavem330
authored andcommitted
openvswitch: Remove vport stats.
Since all vport types are now backed by netdev, we can directly use netdev stats. Following patch removes redundant stat from vport. Signed-off-by: Pravin B Shelar <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 3eedb41 commit 8c87663

File tree

5 files changed

+56
-170
lines changed

5 files changed

+56
-170
lines changed

net/openvswitch/vport-internal_dev.c

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -43,35 +43,26 @@ static struct internal_dev *internal_dev_priv(struct net_device *netdev)
4343
return netdev_priv(netdev);
4444
}
4545

46-
/* This function is only called by the kernel network layer.*/
47-
static struct rtnl_link_stats64 *internal_dev_get_stats(struct net_device *netdev,
48-
struct rtnl_link_stats64 *stats)
49-
{
50-
struct vport *vport = ovs_internal_dev_get_vport(netdev);
51-
struct ovs_vport_stats vport_stats;
52-
53-
ovs_vport_get_stats(vport, &vport_stats);
54-
55-
/* The tx and rx stats need to be swapped because the
56-
* switch and host OS have opposite perspectives. */
57-
stats->rx_packets = vport_stats.tx_packets;
58-
stats->tx_packets = vport_stats.rx_packets;
59-
stats->rx_bytes = vport_stats.tx_bytes;
60-
stats->tx_bytes = vport_stats.rx_bytes;
61-
stats->rx_errors = vport_stats.tx_errors;
62-
stats->tx_errors = vport_stats.rx_errors;
63-
stats->rx_dropped = vport_stats.tx_dropped;
64-
stats->tx_dropped = vport_stats.rx_dropped;
65-
66-
return stats;
67-
}
68-
6946
/* Called with rcu_read_lock_bh. */
7047
static int internal_dev_xmit(struct sk_buff *skb, struct net_device *netdev)
7148
{
49+
int len, err;
50+
51+
len = skb->len;
7252
rcu_read_lock();
73-
ovs_vport_receive(internal_dev_priv(netdev)->vport, skb, NULL);
53+
err = ovs_vport_receive(internal_dev_priv(netdev)->vport, skb, NULL);
7454
rcu_read_unlock();
55+
56+
if (likely(!err)) {
57+
struct pcpu_sw_netstats *tstats = this_cpu_ptr(netdev->tstats);
58+
59+
u64_stats_update_begin(&tstats->syncp);
60+
tstats->tx_bytes += len;
61+
tstats->tx_packets++;
62+
u64_stats_update_end(&tstats->syncp);
63+
} else {
64+
netdev->stats.tx_errors++;
65+
}
7566
return 0;
7667
}
7768

@@ -121,7 +112,6 @@ static const struct net_device_ops internal_dev_netdev_ops = {
121112
.ndo_start_xmit = internal_dev_xmit,
122113
.ndo_set_mac_address = eth_mac_addr,
123114
.ndo_change_mtu = internal_dev_change_mtu,
124-
.ndo_get_stats64 = internal_dev_get_stats,
125115
};
126116

127117
static struct rtnl_link_ops internal_dev_link_ops __read_mostly = {
@@ -212,18 +202,17 @@ static void internal_dev_destroy(struct vport *vport)
212202
rtnl_unlock();
213203
}
214204

215-
static int internal_dev_recv(struct vport *vport, struct sk_buff *skb)
205+
static void internal_dev_recv(struct vport *vport, struct sk_buff *skb)
216206
{
217207
struct net_device *netdev = vport->dev;
218-
int len;
208+
struct pcpu_sw_netstats *stats;
219209

220210
if (unlikely(!(netdev->flags & IFF_UP))) {
221211
kfree_skb(skb);
222-
return 0;
212+
netdev->stats.rx_dropped++;
213+
return;
223214
}
224215

225-
len = skb->len;
226-
227216
skb_dst_drop(skb);
228217
nf_reset(skb);
229218
secpath_reset(skb);
@@ -233,9 +222,13 @@ static int internal_dev_recv(struct vport *vport, struct sk_buff *skb)
233222
skb->protocol = eth_type_trans(skb, netdev);
234223
skb_postpull_rcsum(skb, eth_hdr(skb), ETH_HLEN);
235224

236-
netif_rx(skb);
225+
stats = this_cpu_ptr(netdev->tstats);
226+
u64_stats_update_begin(&stats->syncp);
227+
stats->rx_packets++;
228+
stats->rx_bytes += skb->len;
229+
u64_stats_update_end(&stats->syncp);
237230

238-
return len;
231+
netif_rx(skb);
239232
}
240233

241234
static struct vport_ops ovs_internal_vport_ops = {

net/openvswitch/vport-netdev.c

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,11 @@
3939
static struct vport_ops ovs_netdev_vport_ops;
4040

4141
/* Must be called with rcu_read_lock. */
42-
static void netdev_port_receive(struct vport *vport, struct sk_buff *skb)
42+
static void netdev_port_receive(struct sk_buff *skb)
4343
{
44+
struct vport *vport;
45+
46+
vport = ovs_netdev_get_vport(skb->dev);
4447
if (unlikely(!vport))
4548
goto error;
4649

@@ -56,10 +59,8 @@ static void netdev_port_receive(struct vport *vport, struct sk_buff *skb)
5659

5760
skb_push(skb, ETH_HLEN);
5861
ovs_skb_postpush_rcsum(skb, skb->data, ETH_HLEN);
59-
6062
ovs_vport_receive(vport, skb, skb_tunnel_info(skb));
6163
return;
62-
6364
error:
6465
kfree_skb(skb);
6566
}
@@ -68,15 +69,11 @@ static void netdev_port_receive(struct vport *vport, struct sk_buff *skb)
6869
static rx_handler_result_t netdev_frame_hook(struct sk_buff **pskb)
6970
{
7071
struct sk_buff *skb = *pskb;
71-
struct vport *vport;
7272

7373
if (unlikely(skb->pkt_type == PACKET_LOOPBACK))
7474
return RX_HANDLER_PASS;
7575

76-
vport = ovs_netdev_get_vport(skb->dev);
77-
78-
netdev_port_receive(vport, skb);
79-
76+
netdev_port_receive(skb);
8077
return RX_HANDLER_CONSUMED;
8178
}
8279

@@ -203,27 +200,24 @@ static unsigned int packet_length(const struct sk_buff *skb)
203200
return length;
204201
}
205202

206-
int ovs_netdev_send(struct vport *vport, struct sk_buff *skb)
203+
void ovs_netdev_send(struct vport *vport, struct sk_buff *skb)
207204
{
208205
int mtu = vport->dev->mtu;
209-
int len;
210206

211207
if (unlikely(packet_length(skb) > mtu && !skb_is_gso(skb))) {
212208
net_warn_ratelimited("%s: dropped over-mtu packet: %d > %d\n",
213209
vport->dev->name,
214210
packet_length(skb), mtu);
211+
vport->dev->stats.tx_errors++;
215212
goto drop;
216213
}
217214

218215
skb->dev = vport->dev;
219-
len = skb->len;
220216
dev_queue_xmit(skb);
221-
222-
return len;
217+
return;
223218

224219
drop:
225220
kfree_skb(skb);
226-
return 0;
227221
}
228222
EXPORT_SYMBOL_GPL(ovs_netdev_send);
229223

net/openvswitch/vport-netdev.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
struct vport *ovs_netdev_get_vport(struct net_device *dev);
2828

2929
struct vport *ovs_netdev_link(struct vport *vport, const char *name);
30-
int ovs_netdev_send(struct vport *vport, struct sk_buff *skb);
30+
void ovs_netdev_send(struct vport *vport, struct sk_buff *skb);
3131
void ovs_netdev_detach_dev(struct vport *);
3232

3333
int __init ovs_netdev_init(void);

net/openvswitch/vport.c

Lines changed: 12 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@
3434
#include "vport.h"
3535
#include "vport-internal_dev.h"
3636

37-
static void ovs_vport_record_error(struct vport *,
38-
enum vport_err_type err_type);
39-
4037
static LIST_HEAD(vport_ops_list);
4138

4239
/* Protected by RCU read lock for reading, ovs_mutex for writing. */
@@ -157,12 +154,6 @@ struct vport *ovs_vport_alloc(int priv_size, const struct vport_ops *ops,
157154
return ERR_PTR(-EINVAL);
158155
}
159156

160-
vport->percpu_stats = netdev_alloc_pcpu_stats(struct pcpu_sw_netstats);
161-
if (!vport->percpu_stats) {
162-
kfree(vport);
163-
return ERR_PTR(-ENOMEM);
164-
}
165-
166157
return vport;
167158
}
168159
EXPORT_SYMBOL_GPL(ovs_vport_alloc);
@@ -183,7 +174,6 @@ void ovs_vport_free(struct vport *vport)
183174
* it is safe to use raw dereference.
184175
*/
185176
kfree(rcu_dereference_raw(vport->upcall_portids));
186-
free_percpu(vport->percpu_stats);
187177
kfree(vport);
188178
}
189179
EXPORT_SYMBOL_GPL(ovs_vport_free);
@@ -290,30 +280,24 @@ void ovs_vport_del(struct vport *vport)
290280
*/
291281
void ovs_vport_get_stats(struct vport *vport, struct ovs_vport_stats *stats)
292282
{
283+
struct net_device *dev = vport->dev;
293284
int i;
294285

295286
memset(stats, 0, sizeof(*stats));
287+
stats->rx_errors = dev->stats.rx_errors;
288+
stats->tx_errors = dev->stats.tx_errors;
289+
stats->tx_dropped = dev->stats.tx_dropped;
290+
stats->rx_dropped = dev->stats.rx_dropped;
296291

297-
/* We potentially have 2 sources of stats that need to be combined:
298-
* those we have collected (split into err_stats and percpu_stats) from
299-
* set_stats() and device error stats from netdev->get_stats() (for
300-
* errors that happen downstream and therefore aren't reported through
301-
* our vport_record_error() function).
302-
* Stats from first source are reported by ovs (OVS_VPORT_ATTR_STATS).
303-
* netdev-stats can be directly read over netlink-ioctl.
304-
*/
305-
306-
stats->rx_errors = atomic_long_read(&vport->err_stats.rx_errors);
307-
stats->tx_errors = atomic_long_read(&vport->err_stats.tx_errors);
308-
stats->tx_dropped = atomic_long_read(&vport->err_stats.tx_dropped);
309-
stats->rx_dropped = atomic_long_read(&vport->err_stats.rx_dropped);
292+
stats->rx_dropped += atomic_long_read(&dev->rx_dropped);
293+
stats->tx_dropped += atomic_long_read(&dev->tx_dropped);
310294

311295
for_each_possible_cpu(i) {
312296
const struct pcpu_sw_netstats *percpu_stats;
313297
struct pcpu_sw_netstats local_stats;
314298
unsigned int start;
315299

316-
percpu_stats = per_cpu_ptr(vport->percpu_stats, i);
300+
percpu_stats = per_cpu_ptr(dev->tstats, i);
317301

318302
do {
319303
start = u64_stats_fetch_begin_irq(&percpu_stats->syncp);
@@ -468,94 +452,25 @@ u32 ovs_vport_find_upcall_portid(const struct vport *vport, struct sk_buff *skb)
468452
* Must be called with rcu_read_lock. The packet cannot be shared and
469453
* skb->data should point to the Ethernet header.
470454
*/
471-
void ovs_vport_receive(struct vport *vport, struct sk_buff *skb,
472-
const struct ip_tunnel_info *tun_info)
455+
int ovs_vport_receive(struct vport *vport, struct sk_buff *skb,
456+
const struct ip_tunnel_info *tun_info)
473457
{
474-
struct pcpu_sw_netstats *stats;
475458
struct sw_flow_key key;
476459
int error;
477460

478-
stats = this_cpu_ptr(vport->percpu_stats);
479-
u64_stats_update_begin(&stats->syncp);
480-
stats->rx_packets++;
481-
stats->rx_bytes += skb->len +
482-
(skb_vlan_tag_present(skb) ? VLAN_HLEN : 0);
483-
u64_stats_update_end(&stats->syncp);
484-
485461
OVS_CB(skb)->input_vport = vport;
486462
OVS_CB(skb)->mru = 0;
487463
/* Extract flow from 'skb' into 'key'. */
488464
error = ovs_flow_key_extract(tun_info, skb, &key);
489465
if (unlikely(error)) {
490466
kfree_skb(skb);
491-
return;
467+
return error;
492468
}
493469
ovs_dp_process_packet(skb, &key);
470+
return 0;
494471
}
495472
EXPORT_SYMBOL_GPL(ovs_vport_receive);
496473

497-
/**
498-
* ovs_vport_send - send a packet on a device
499-
*
500-
* @vport: vport on which to send the packet
501-
* @skb: skb to send
502-
*
503-
* Sends the given packet and returns the length of data sent. Either ovs
504-
* lock or rcu_read_lock must be held.
505-
*/
506-
int ovs_vport_send(struct vport *vport, struct sk_buff *skb)
507-
{
508-
int sent = vport->ops->send(vport, skb);
509-
510-
if (likely(sent > 0)) {
511-
struct pcpu_sw_netstats *stats;
512-
513-
stats = this_cpu_ptr(vport->percpu_stats);
514-
515-
u64_stats_update_begin(&stats->syncp);
516-
stats->tx_packets++;
517-
stats->tx_bytes += sent;
518-
u64_stats_update_end(&stats->syncp);
519-
} else if (sent < 0) {
520-
ovs_vport_record_error(vport, VPORT_E_TX_ERROR);
521-
} else {
522-
ovs_vport_record_error(vport, VPORT_E_TX_DROPPED);
523-
}
524-
return sent;
525-
}
526-
527-
/**
528-
* ovs_vport_record_error - indicate device error to generic stats layer
529-
*
530-
* @vport: vport that encountered the error
531-
* @err_type: one of enum vport_err_type types to indicate the error type
532-
*
533-
* If using the vport generic stats layer indicate that an error of the given
534-
* type has occurred.
535-
*/
536-
static void ovs_vport_record_error(struct vport *vport,
537-
enum vport_err_type err_type)
538-
{
539-
switch (err_type) {
540-
case VPORT_E_RX_DROPPED:
541-
atomic_long_inc(&vport->err_stats.rx_dropped);
542-
break;
543-
544-
case VPORT_E_RX_ERROR:
545-
atomic_long_inc(&vport->err_stats.rx_errors);
546-
break;
547-
548-
case VPORT_E_TX_DROPPED:
549-
atomic_long_inc(&vport->err_stats.tx_dropped);
550-
break;
551-
552-
case VPORT_E_TX_ERROR:
553-
atomic_long_inc(&vport->err_stats.tx_errors);
554-
break;
555-
}
556-
557-
}
558-
559474
static void free_vport_rcu(struct rcu_head *rcu)
560475
{
561476
struct vport *vport = container_of(rcu, struct vport, rcu);

0 commit comments

Comments
 (0)