2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-22 09:58:01 +00:00
ovs/lib/netdev-linux-private.h

146 lines
4.6 KiB
C
Raw Normal View History

/*
* Copyright (c) 2019 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef NETDEV_LINUX_PRIVATE_H
#define NETDEV_LINUX_PRIVATE_H 1
#include <linux/filter.h>
#include <linux/gen_stats.h>
#include <linux/if_ether.h>
#include <linux/if_tun.h>
#include <linux/types.h>
#include <linux/ethtool.h>
#include <linux/mii.h>
#include <stdint.h>
#include <stdbool.h>
#include "dp-packet.h"
#include "netdev-afxdp.h"
#include "netdev-afxdp-pool.h"
#include "netdev-provider.h"
#include "netdev-vport.h"
#include "openvswitch/thread.h"
#include "ovs-atomic.h"
#include "timer.h"
struct netdev;
/* The maximum packet length is 16 bits */
#define LINUX_RXQ_TSO_MAX_LEN 65535
struct netdev_rxq_linux {
struct netdev_rxq up;
bool is_tap;
int fd;
char *aux_bufs[NETDEV_MAX_BURST]; /* Batch of preallocated TSO buffers. */
};
int netdev_linux_construct(struct netdev *);
void netdev_linux_run(const struct netdev_class *);
int get_stats_via_netlink(const struct netdev *netdev_,
struct netdev_stats *stats);
struct netdev_linux {
struct netdev up;
/* Protects all members below. */
struct ovs_mutex mutex;
unsigned int cache_valid;
bool miimon; /* Link status of last poll. */
long long int miimon_interval; /* Miimon Poll rate. Disabled if <= 0. */
struct timer miimon_timer;
int netnsid; /* Network namespace ID. */
/* The following are figured out "on demand" only. They are only valid
* when the corresponding VALID_* bit in 'cache_valid' is set. */
int ifindex;
struct eth_addr etheraddr;
int mtu;
unsigned int ifi_flags;
long long int carrier_resets;
uint32_t kbits_rate; /* Policing data. */
uint32_t kbits_burst;
int vport_stats_error; /* Cached error code from vport_get_stats().
0 or an errno value. */
int netdev_mtu_error; /* Cached error code from SIOCGIFMTU
* or SIOCSIFMTU.
*/
int ether_addr_error; /* Cached error code from set/get etheraddr. */
int netdev_policing_error; /* Cached error code from set policing. */
int get_features_error; /* Cached error code from ETHTOOL_GSET. */
int get_ifindex_error; /* Cached error code from SIOCGIFINDEX. */
enum netdev_features current; /* Cached from ETHTOOL_GSET. */
enum netdev_features advertised; /* Cached from ETHTOOL_GSET. */
enum netdev_features supported; /* Cached from ETHTOOL_GSET. */
struct ethtool_drvinfo drvinfo; /* Cached from ETHTOOL_GDRVINFO. */
struct tc *tc;
/* For devices of class netdev_tap_class only. */
int tap_fd;
bool present; /* If the device is present in the namespace */
uint64_t tx_dropped; /* tap device can drop if the iface is down */
uint64_t rx_dropped; /* Packets dropped while recv from kernel. */
/* LAG information. */
bool is_lag_master; /* True if the netdev is a LAG master. */
int numa_id; /* NUMA node id. */
#ifdef HAVE_AF_XDP
/* AF_XDP information. */
struct xsk_socket_info **xsks;
int requested_n_rxq;
netdev-afxdp: Best-effort configuration of XDP mode. Until now there was only two options for XDP mode in OVS: SKB or DRV. i.e. 'generic XDP' or 'native XDP with zero-copy enabled'. Devices like 'veth' interfaces in Linux supports native XDP, but doesn't support zero-copy mode. This case can not be covered by existing API and we have to use slower generic XDP for such devices. There are few more issues, e.g. TCP is not supported in generic XDP mode for veth interfaces due to kernel limitations, however it is supported in native mode. This change introduces ability to use native XDP without zero-copy along with best-effort configuration option that enabled by default. In best-effort case OVS will sequentially try different modes starting from the fastest one and will choose the first acceptable for current interface. This will guarantee the best possible performance. If user will want to choose specific mode, it's still possible by setting the 'options:xdp-mode'. This change additionally changes the API by renaming the configuration knob from 'xdpmode' to 'xdp-mode' and also renaming the modes themselves to be more user-friendly. The full list of currently supported modes: * native-with-zerocopy - former DRV * native - new one, DRV without zero-copy * generic - former SKB * best-effort - new one, chooses the best available from 3 above modes Since 'best-effort' is a default mode, users will not need to explicitely set 'xdp-mode' in most cases. TCP related tests enabled back in system afxdp testsuite, because 'best-effort' will choose 'native' mode for veth interfaces and this mode has no issues with TCP. Signed-off-by: Ilya Maximets <i.maximets@ovn.org> Acked-by: William Tu <u9012063@gmail.com> Acked-by: Eelco Chaudron <echaudro@redhat.com>
2019-11-06 21:38:33 +00:00
enum afxdp_mode xdp_mode; /* Configured AF_XDP mode. */
enum afxdp_mode requested_xdp_mode; /* Requested AF_XDP mode. */
enum afxdp_mode xdp_mode_in_use; /* Effective AF_XDP mode. */
bool use_need_wakeup;
bool requested_need_wakeup;
netdev-afxdp: Best-effort configuration of XDP mode. Until now there was only two options for XDP mode in OVS: SKB or DRV. i.e. 'generic XDP' or 'native XDP with zero-copy enabled'. Devices like 'veth' interfaces in Linux supports native XDP, but doesn't support zero-copy mode. This case can not be covered by existing API and we have to use slower generic XDP for such devices. There are few more issues, e.g. TCP is not supported in generic XDP mode for veth interfaces due to kernel limitations, however it is supported in native mode. This change introduces ability to use native XDP without zero-copy along with best-effort configuration option that enabled by default. In best-effort case OVS will sequentially try different modes starting from the fastest one and will choose the first acceptable for current interface. This will guarantee the best possible performance. If user will want to choose specific mode, it's still possible by setting the 'options:xdp-mode'. This change additionally changes the API by renaming the configuration knob from 'xdpmode' to 'xdp-mode' and also renaming the modes themselves to be more user-friendly. The full list of currently supported modes: * native-with-zerocopy - former DRV * native - new one, DRV without zero-copy * generic - former SKB * best-effort - new one, chooses the best available from 3 above modes Since 'best-effort' is a default mode, users will not need to explicitely set 'xdp-mode' in most cases. TCP related tests enabled back in system afxdp testsuite, because 'best-effort' will choose 'native' mode for veth interfaces and this mode has no issues with TCP. Signed-off-by: Ilya Maximets <i.maximets@ovn.org> Acked-by: William Tu <u9012063@gmail.com> Acked-by: Eelco Chaudron <echaudro@redhat.com>
2019-11-06 21:38:33 +00:00
ovs-thread: Avoid huge alignment on a base spinlock structure. Marking the structure as 64 bytes aligned forces compiler to produce big holes in the containing structures in order to fulfill this requirement. Also, any structure that contains this one as a member automatically inherits this huge alignment making resulted memory layout not efficient. For example, 'struct umem_pool' currently uses 3 full cache lines (192 bytes) with only 32 bytes of actual data: struct umem_pool { int index; /* 0 4 */ unsigned int size; /* 4 4 */ /* XXX 56 bytes hole, try to pack */ /* --- cacheline 1 boundary (64 bytes) --- */ struct ovs_spin lock __attribute__((__aligned__(64))); /* 64 64 */ /* XXX last struct has 48 bytes of padding */ /* --- cacheline 2 boundary (128 bytes) --- */ void * * array; /* 128 8 */ /* size: 192, cachelines: 3, members: 4 */ /* sum members: 80, holes: 1, sum holes: 56 */ /* padding: 56 */ /* paddings: 1, sum paddings: 48 */ /* forced alignments: 1, forced holes: 1, sum forced holes: 56 */ } __attribute__((__aligned__(64))); Actual alignment of a spin lock is required only for Tx queue locks inside netdev-afxdp to avoid false sharing, in all other cases alignment only produces inefficient memory usage. Also, CACHE_LINE_SIZE macro should be used instead of 64 as different platforms may have different cache line sizes. Using PADDED_MEMBERS to avoid alignment inheritance. Fixes: ae36d63d7e3c ("ovs-thread: Make struct spin lock cache aligned.") Signed-off-by: Ilya Maximets <i.maximets@ovn.org> Acked-by: William Tu <u9012063@gmail.com>
2019-12-16 13:54:38 +01:00
struct netdev_afxdp_tx_lock *tx_locks; /* Array of locks for TX queues. */
#endif
};
static bool
is_netdev_linux_class(const struct netdev_class *netdev_class)
{
return netdev_class->run == netdev_linux_run;
}
static struct netdev_linux *
netdev_linux_cast(const struct netdev *netdev)
{
ovs_assert(is_netdev_linux_class(netdev_get_class(netdev)));
return CONTAINER_OF(netdev, struct netdev_linux, up);
}
static struct netdev_rxq_linux *
netdev_rxq_linux_cast(const struct netdev_rxq *rx)
{
ovs_assert(is_netdev_linux_class(netdev_get_class(rx->netdev)));
return CONTAINER_OF(rx, struct netdev_rxq_linux, up);
}
#endif /* netdev-linux-private.h */