Commit bf264145 authored by Tom Herbert's avatar Tom Herbert Committed by David S. Miller

xps: Add CONFIG_XPS

This patch adds XPS_CONFIG option to enable and disable XPS.  This is
done in the same manner as RPS_CONFIG.  This is also fixes build
failure in XPS code when SMP is not enabled.
Signed-off-by: default avatarTom Herbert <therbert@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 8fa9208e
...@@ -535,30 +535,6 @@ struct rps_map { ...@@ -535,30 +535,6 @@ struct rps_map {
}; };
#define RPS_MAP_SIZE(_num) (sizeof(struct rps_map) + (_num * sizeof(u16))) #define RPS_MAP_SIZE(_num) (sizeof(struct rps_map) + (_num * sizeof(u16)))
/*
* This structure holds an XPS map which can be of variable length. The
* map is an array of queues.
*/
struct xps_map {
unsigned int len;
unsigned int alloc_len;
struct rcu_head rcu;
u16 queues[0];
};
#define XPS_MAP_SIZE(_num) (sizeof(struct xps_map) + (_num * sizeof(u16)))
#define XPS_MIN_MAP_ALLOC ((L1_CACHE_BYTES - sizeof(struct xps_map)) \
/ sizeof(u16))
/*
* This structure holds all XPS maps for device. Maps are indexed by CPU.
*/
struct xps_dev_maps {
struct rcu_head rcu;
struct xps_map *cpu_map[0];
};
#define XPS_DEV_MAPS_SIZE (sizeof(struct xps_dev_maps) + \
(nr_cpu_ids * sizeof(struct xps_map *)))
/* /*
* The rps_dev_flow structure contains the mapping of a flow to a CPU and the * The rps_dev_flow structure contains the mapping of a flow to a CPU and the
* tail pointer for that CPU's input queue at the time of last enqueue. * tail pointer for that CPU's input queue at the time of last enqueue.
...@@ -626,6 +602,32 @@ struct netdev_rx_queue { ...@@ -626,6 +602,32 @@ struct netdev_rx_queue {
} ____cacheline_aligned_in_smp; } ____cacheline_aligned_in_smp;
#endif /* CONFIG_RPS */ #endif /* CONFIG_RPS */
#ifdef CONFIG_XPS
/*
* This structure holds an XPS map which can be of variable length. The
* map is an array of queues.
*/
struct xps_map {
unsigned int len;
unsigned int alloc_len;
struct rcu_head rcu;
u16 queues[0];
};
#define XPS_MAP_SIZE(_num) (sizeof(struct xps_map) + (_num * sizeof(u16)))
#define XPS_MIN_MAP_ALLOC ((L1_CACHE_BYTES - sizeof(struct xps_map)) \
/ sizeof(u16))
/*
* This structure holds all XPS maps for device. Maps are indexed by CPU.
*/
struct xps_dev_maps {
struct rcu_head rcu;
struct xps_map *cpu_map[0];
};
#define XPS_DEV_MAPS_SIZE (sizeof(struct xps_dev_maps) + \
(nr_cpu_ids * sizeof(struct xps_map *)))
#endif /* CONFIG_XPS */
/* /*
* This structure defines the management hooks for network devices. * This structure defines the management hooks for network devices.
* The following hooks can be defined; unless noted otherwise, they are * The following hooks can be defined; unless noted otherwise, they are
...@@ -1046,7 +1048,9 @@ struct net_device { ...@@ -1046,7 +1048,9 @@ struct net_device {
unsigned long tx_queue_len; /* Max frames per queue allowed */ unsigned long tx_queue_len; /* Max frames per queue allowed */
spinlock_t tx_global_lock; spinlock_t tx_global_lock;
#ifdef CONFIG_XPS
struct xps_dev_maps *xps_maps; struct xps_dev_maps *xps_maps;
#endif
/* These may be needed for future network-power-down code. */ /* These may be needed for future network-power-down code. */
......
...@@ -220,6 +220,11 @@ config RPS ...@@ -220,6 +220,11 @@ config RPS
depends on SMP && SYSFS && USE_GENERIC_SMP_HELPERS depends on SMP && SYSFS && USE_GENERIC_SMP_HELPERS
default y default y
config XPS
boolean
depends on SMP && SYSFS && USE_GENERIC_SMP_HELPERS
default y
menu "Network testing" menu "Network testing"
config NET_PKTGEN config NET_PKTGEN
......
...@@ -1567,6 +1567,9 @@ int netif_set_real_num_tx_queues(struct net_device *dev, unsigned int txq) ...@@ -1567,6 +1567,9 @@ int netif_set_real_num_tx_queues(struct net_device *dev, unsigned int txq)
rc = netdev_queue_update_kobjects(dev, dev->real_num_tx_queues, rc = netdev_queue_update_kobjects(dev, dev->real_num_tx_queues,
txq); txq);
if (rc)
return rc;
if (txq < dev->real_num_tx_queues) if (txq < dev->real_num_tx_queues)
qdisc_reset_all_tx_gt(dev, txq); qdisc_reset_all_tx_gt(dev, txq);
} }
...@@ -2148,7 +2151,7 @@ static inline u16 dev_cap_txqueue(struct net_device *dev, u16 queue_index) ...@@ -2148,7 +2151,7 @@ static inline u16 dev_cap_txqueue(struct net_device *dev, u16 queue_index)
static inline int get_xps_queue(struct net_device *dev, struct sk_buff *skb) static inline int get_xps_queue(struct net_device *dev, struct sk_buff *skb)
{ {
#ifdef CONFIG_RPS #ifdef CONFIG_XPS
struct xps_dev_maps *dev_maps; struct xps_dev_maps *dev_maps;
struct xps_map *map; struct xps_map *map;
int queue_index = -1; int queue_index = -1;
...@@ -5085,9 +5088,9 @@ void netif_stacked_transfer_operstate(const struct net_device *rootdev, ...@@ -5085,9 +5088,9 @@ void netif_stacked_transfer_operstate(const struct net_device *rootdev,
} }
EXPORT_SYMBOL(netif_stacked_transfer_operstate); EXPORT_SYMBOL(netif_stacked_transfer_operstate);
#ifdef CONFIG_RPS
static int netif_alloc_rx_queues(struct net_device *dev) static int netif_alloc_rx_queues(struct net_device *dev)
{ {
#ifdef CONFIG_RPS
unsigned int i, count = dev->num_rx_queues; unsigned int i, count = dev->num_rx_queues;
struct netdev_rx_queue *rx; struct netdev_rx_queue *rx;
...@@ -5102,9 +5105,9 @@ static int netif_alloc_rx_queues(struct net_device *dev) ...@@ -5102,9 +5105,9 @@ static int netif_alloc_rx_queues(struct net_device *dev)
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
rx[i].dev = dev; rx[i].dev = dev;
#endif
return 0; return 0;
} }
#endif
static int netif_alloc_netdev_queues(struct net_device *dev) static int netif_alloc_netdev_queues(struct net_device *dev)
{ {
......
...@@ -751,10 +751,12 @@ static int rx_queue_add_kobject(struct net_device *net, int index) ...@@ -751,10 +751,12 @@ static int rx_queue_add_kobject(struct net_device *net, int index)
return error; return error;
} }
#endif /* CONFIG_RPS */
int int
net_rx_queue_update_kobjects(struct net_device *net, int old_num, int new_num) net_rx_queue_update_kobjects(struct net_device *net, int old_num, int new_num)
{ {
#ifdef CONFIG_RPS
int i; int i;
int error = 0; int error = 0;
...@@ -770,8 +772,12 @@ net_rx_queue_update_kobjects(struct net_device *net, int old_num, int new_num) ...@@ -770,8 +772,12 @@ net_rx_queue_update_kobjects(struct net_device *net, int old_num, int new_num)
kobject_put(&net->_rx[i].kobj); kobject_put(&net->_rx[i].kobj);
return error; return error;
#else
return 0;
#endif
} }
#ifdef CONFIG_XPS
/* /*
* netdev_queue sysfs structures and functions. * netdev_queue sysfs structures and functions.
*/ */
...@@ -1090,10 +1096,12 @@ static int netdev_queue_add_kobject(struct net_device *net, int index) ...@@ -1090,10 +1096,12 @@ static int netdev_queue_add_kobject(struct net_device *net, int index)
return error; return error;
} }
#endif /* CONFIG_XPS */
int int
netdev_queue_update_kobjects(struct net_device *net, int old_num, int new_num) netdev_queue_update_kobjects(struct net_device *net, int old_num, int new_num)
{ {
#ifdef CONFIG_XPS
int i; int i;
int error = 0; int error = 0;
...@@ -1109,27 +1117,36 @@ netdev_queue_update_kobjects(struct net_device *net, int old_num, int new_num) ...@@ -1109,27 +1117,36 @@ netdev_queue_update_kobjects(struct net_device *net, int old_num, int new_num)
kobject_put(&net->_tx[i].kobj); kobject_put(&net->_tx[i].kobj);
return error; return error;
#else
return 0;
#endif
} }
static int register_queue_kobjects(struct net_device *net) static int register_queue_kobjects(struct net_device *net)
{ {
int error = 0, txq = 0, rxq = 0; int error = 0, txq = 0, rxq = 0, real_rx = 0, real_tx = 0;
#if defined(CONFIG_RPS) || defined(CONFIG_XPS)
net->queues_kset = kset_create_and_add("queues", net->queues_kset = kset_create_and_add("queues",
NULL, &net->dev.kobj); NULL, &net->dev.kobj);
if (!net->queues_kset) if (!net->queues_kset)
return -ENOMEM; return -ENOMEM;
#endif
#ifdef CONFIG_RPS
real_rx = net->real_num_rx_queues;
#endif
real_tx = net->real_num_tx_queues;
error = net_rx_queue_update_kobjects(net, 0, net->real_num_rx_queues); error = net_rx_queue_update_kobjects(net, 0, real_rx);
if (error) if (error)
goto error; goto error;
rxq = net->real_num_rx_queues; rxq = real_rx;
error = netdev_queue_update_kobjects(net, 0, error = netdev_queue_update_kobjects(net, 0, real_tx);
net->real_num_tx_queues);
if (error) if (error)
goto error; goto error;
txq = net->real_num_tx_queues; txq = real_tx;
return 0; return 0;
...@@ -1141,11 +1158,19 @@ static int register_queue_kobjects(struct net_device *net) ...@@ -1141,11 +1158,19 @@ static int register_queue_kobjects(struct net_device *net)
static void remove_queue_kobjects(struct net_device *net) static void remove_queue_kobjects(struct net_device *net)
{ {
net_rx_queue_update_kobjects(net, net->real_num_rx_queues, 0); int real_rx = 0, real_tx = 0;
netdev_queue_update_kobjects(net, net->real_num_tx_queues, 0);
#ifdef CONFIG_RPS
real_rx = net->real_num_rx_queues;
#endif
real_tx = net->real_num_tx_queues;
net_rx_queue_update_kobjects(net, real_rx, 0);
netdev_queue_update_kobjects(net, real_tx, 0);
#if defined(CONFIG_RPS) || defined(CONFIG_XPS)
kset_unregister(net->queues_kset); kset_unregister(net->queues_kset);
#endif
} }
#endif /* CONFIG_RPS */
static const void *net_current_ns(void) static const void *net_current_ns(void)
{ {
...@@ -1244,9 +1269,7 @@ void netdev_unregister_kobject(struct net_device * net) ...@@ -1244,9 +1269,7 @@ void netdev_unregister_kobject(struct net_device * net)
kobject_get(&dev->kobj); kobject_get(&dev->kobj);
#ifdef CONFIG_RPS
remove_queue_kobjects(net); remove_queue_kobjects(net);
#endif
device_del(dev); device_del(dev);
} }
...@@ -1285,13 +1308,11 @@ int netdev_register_kobject(struct net_device *net) ...@@ -1285,13 +1308,11 @@ int netdev_register_kobject(struct net_device *net)
if (error) if (error)
return error; return error;
#ifdef CONFIG_RPS
error = register_queue_kobjects(net); error = register_queue_kobjects(net);
if (error) { if (error) {
device_del(dev); device_del(dev);
return error; return error;
} }
#endif
return error; return error;
} }
......
...@@ -4,11 +4,8 @@ ...@@ -4,11 +4,8 @@
int netdev_kobject_init(void); int netdev_kobject_init(void);
int netdev_register_kobject(struct net_device *); int netdev_register_kobject(struct net_device *);
void netdev_unregister_kobject(struct net_device *); void netdev_unregister_kobject(struct net_device *);
#ifdef CONFIG_RPS
int net_rx_queue_update_kobjects(struct net_device *, int old_num, int new_num); int net_rx_queue_update_kobjects(struct net_device *, int old_num, int new_num);
int netdev_queue_update_kobjects(struct net_device *net, int netdev_queue_update_kobjects(struct net_device *net,
int old_num, int new_num); int old_num, int new_num);
#endif #endif
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment