Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1481383

[RFC V3 PATCH 05/26] net/netpolicy: create CPU and queue mapping

From kan.liang@intel.com
Newsgroups linux.kernel
Subject [RFC V3 PATCH 05/26] net/netpolicy: create CPU and queue mapping
Date 2016-09-12 17:00 +0200
Message-ID <sgASe-4DC-29@gated-at.bofh.it> (permalink)
References <sgASd-4DC-5@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


From: Kan Liang <kan.liang@intel.com>

Current implementation forces CPU and queue 1:1 mapping. This patch
introduces the function netpolicy_update_sys_map to create this mapping.
The result is stored in netpolicy_sys_info.

If the CPU count and queue count are different, the remaining
CPUs/queues are not used for now.

CPU hotplug, device hotplug or ethtool may change the CPU count or
queue count. For these cases, this function can also be called to
reconstruct the mapping. These cases will be handled later in this
series.

Signed-off-by: Kan Liang <kan.liang@intel.com>
---
 include/linux/netpolicy.h | 18 ++++++++++++
 net/core/netpolicy.c      | 74 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 92 insertions(+)

diff --git a/include/linux/netpolicy.h b/include/linux/netpolicy.h
index fc87d9b..a946b75c 100644
--- a/include/linux/netpolicy.h
+++ b/include/linux/netpolicy.h
@@ -30,9 +30,27 @@ struct netpolicy_dev_info {
 	u32	*tx_irq;
 };
 
+struct netpolicy_sys_map {
+	u32	cpu;
+	u32	queue;
+	u32	irq;
+};
+
+struct netpolicy_sys_info {
+	/*
+	 * Record the cpu and queue 1:1 mapping
+	 */
+	u32				avail_rx_num;
+	struct netpolicy_sys_map	*rx;
+	u32				avail_tx_num;
+	struct netpolicy_sys_map	*tx;
+};
+
 struct netpolicy_info {
 	enum netpolicy_name	cur_policy;
 	unsigned long avail_policy[BITS_TO_LONGS(NET_POLICY_MAX)];
+	/* cpu and queue mapping information */
+	struct netpolicy_sys_info	sys_info;
 };
 
 #endif /*__LINUX_NETPOLICY_H*/
diff --git a/net/core/netpolicy.c b/net/core/netpolicy.c
index 31c41ca..0972341 100644
--- a/net/core/netpolicy.c
+++ b/net/core/netpolicy.c
@@ -55,6 +55,80 @@ static u32 netpolicy_get_cpu_information(void)
 	return num_online_cpus();
 }
 
+static void netpolicy_free_sys_map(struct net_device *dev)
+{
+	struct netpolicy_sys_info *s_info = &dev->netpolicy->sys_info;
+
+	kfree(s_info->rx);
+	s_info->rx = NULL;
+	s_info->avail_rx_num = 0;
+	kfree(s_info->tx);
+	s_info->tx = NULL;
+	s_info->avail_tx_num = 0;
+}
+
+static int netpolicy_update_sys_map(struct net_device *dev,
+				    struct netpolicy_dev_info *d_info,
+				    u32 cpu)
+{
+	struct netpolicy_sys_info *s_info = &dev->netpolicy->sys_info;
+	u32 num, i, online_cpu;
+	cpumask_var_t cpumask;
+
+	if (!alloc_cpumask_var(&cpumask, GFP_ATOMIC))
+		return -ENOMEM;
+
+	/* update rx cpu map */
+	if (cpu > d_info->rx_num)
+		num = d_info->rx_num;
+	else
+		num = cpu;
+
+	s_info->avail_rx_num = num;
+	s_info->rx = kcalloc(num, sizeof(*s_info->rx), GFP_ATOMIC);
+	if (!s_info->rx)
+		goto err;
+	cpumask_copy(cpumask, cpu_online_mask);
+
+	i = 0;
+	for_each_cpu(online_cpu, cpumask) {
+		if (i == num)
+			break;
+		s_info->rx[i].cpu = online_cpu;
+		s_info->rx[i].queue = i;
+		s_info->rx[i].irq = d_info->rx_irq[i];
+		i++;
+	}
+
+	/* update tx cpu map */
+	if (cpu >= d_info->tx_num)
+		num = d_info->tx_num;
+	else
+		num = cpu;
+
+	s_info->avail_tx_num = num;
+	s_info->tx = kcalloc(num, sizeof(*s_info->tx), GFP_ATOMIC);
+	if (!s_info->tx)
+		goto err;
+
+	i = 0;
+	for_each_cpu(online_cpu, cpumask) {
+		if (i == num)
+			break;
+		s_info->tx[i].cpu = online_cpu;
+		s_info->tx[i].queue = i;
+		s_info->tx[i].irq = d_info->tx_irq[i];
+		i++;
+	}
+
+	free_cpumask_var(cpumask);
+	return 0;
+err:
+	netpolicy_free_sys_map(dev);
+	free_cpumask_var(cpumask);
+	return -ENOMEM;
+}
+
 const char *policy_name[NET_POLICY_MAX] = {
 	"NONE"
 };
-- 
2.5.5

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[RFC V3 PATCH 00/26] Kernel NET policy kan.liang@intel.com - 2016-09-12 17:00 +0200
  [RFC V3 PATCH 26/26] Documentation/networking: Document NET policy kan.liang@intel.com - 2016-09-12 17:00 +0200
  [RFC V3 PATCH 05/26] net/netpolicy: create CPU and queue mapping kan.liang@intel.com - 2016-09-12 17:00 +0200
  [RFC V3 PATCH 22/26] net/netpolicy: set per task policy by proc kan.liang@intel.com - 2016-09-12 17:00 +0200
    Re: [RFC V3 PATCH 22/26] net/netpolicy: set per task policy by proc Sergei Shtylyov <sergei.shtylyov@cogentembedded.com> - 2016-09-12 19:10 +0200
  [RFC V3 PATCH 08/26] net/netpolicy: introduce NET policy object kan.liang@intel.com - 2016-09-12 17:00 +0200
  [RFC V3 PATCH 21/26] net/netpolicy: introduce per task net policy kan.liang@intel.com - 2016-09-12 17:00 +0200
  [RFC V3 PATCH 24/26] net/netpolicy: optimize for queue pair kan.liang@intel.com - 2016-09-12 17:00 +0200
  [RFC V3 PATCH 20/26] net/netpolicy: set Rx queues according to policy kan.liang@intel.com - 2016-09-12 17:00 +0200
  [RFC V3 PATCH 25/26] net/netpolicy: limit the total record number kan.liang@intel.com - 2016-09-12 17:00 +0200
  [RFC V3 PATCH 10/26] net/netpolicy: add three new NET policies kan.liang@intel.com - 2016-09-12 17:10 +0200
  [RFC V3 PATCH 09/26] net/netpolicy: set NET policy by policy name kan.liang@intel.com - 2016-09-12 17:10 +0200
  [RFC V3 PATCH 18/26] net/netpolicy: set tx queues according to policy kan.liang@intel.com - 2016-09-12 17:10 +0200
    Re: [RFC V3 PATCH 18/26] net/netpolicy: set tx queues according to policy Tom Herbert <tom@herbertland.com> - 2016-09-12 22:30 +0200
      RE: [RFC V3 PATCH 18/26] net/netpolicy: set tx queues according to  policy "Liang, Kan" <kan.liang@intel.com> - 2016-09-13 14:30 +0200
  [RFC V3 PATCH 02/26] net/netpolicy: init NET policy kan.liang@intel.com - 2016-09-12 17:10 +0200
  [RFC V3 PATCH 01/26] net: introduce NET policy kan.liang@intel.com - 2016-09-12 17:10 +0200
  [RFC V3 PATCH 14/26] net/netpolicy: handle channel changes kan.liang@intel.com - 2016-09-12 17:10 +0200
  [RFC V3 PATCH 13/26] net/netpolicy: support CPU hotplug kan.liang@intel.com - 2016-09-12 17:10 +0200
  [RFC V3 PATCH 11/26] net/netpolicy: add MIX policy kan.liang@intel.com - 2016-09-12 17:10 +0200
  [RFC V3 PATCH 17/26] net/netpolicy: introduce netpolicy_pick_queue kan.liang@intel.com - 2016-09-12 17:10 +0200
  [RFC V3 PATCH 03/26] net/netpolicy: get device queue irq information kan.liang@intel.com - 2016-09-12 17:10 +0200
    Re: [RFC V3 PATCH 03/26] net/netpolicy: get device queue irq  information Sergei Shtylyov <sergei.shtylyov@cogentembedded.com> - 2016-09-12 18:50 +0200
      RE: [RFC V3 PATCH 03/26] net/netpolicy: get device queue irq  information "Liang, Kan" <kan.liang@intel.com> - 2016-09-13 14:30 +0200
        Re: [RFC V3 PATCH 03/26] net/netpolicy: get device queue irq information Alexander Duyck <alexander.duyck@gmail.com> - 2016-09-13 15:20 +0200
          RE: [RFC V3 PATCH 03/26] net/netpolicy: get device queue irq  information "Liang, Kan" <kan.liang@intel.com> - 2016-09-13 15:30 +0200
  [RFC V3 PATCH 15/26] net/netpolicy: implement netpolicy register kan.liang@intel.com - 2016-09-12 17:10 +0200
  [RFC V3 PATCH 19/26] net/netpolicy: tc bpf extension to pick Tx queue kan.liang@intel.com - 2016-09-12 17:10 +0200
  [RFC V3 PATCH 12/26] net/netpolicy: NET device hotplug kan.liang@intel.com - 2016-09-12 17:10 +0200
  [RFC V3 PATCH 04/26] net/netpolicy: get CPU information kan.liang@intel.com - 2016-09-12 17:10 +0200
  Re: [RFC V3 PATCH 00/26] Kernel NET policy Florian Westphal <fw@strlen.de> - 2016-09-12 17:40 +0200
    Re: [RFC V3 PATCH 00/26] Kernel NET policy Cong Wang <xiyou.wangcong@gmail.com> - 2016-09-12 19:30 +0200
  Re: [RFC V3 PATCH 00/26] Kernel NET policy Eric Dumazet <eric.dumazet@gmail.com> - 2016-09-12 18:00 +0200
    Re: [RFC V3 PATCH 00/26] Kernel NET policy Stephen Hemminger <stephen@networkplumber.org> - 2016-09-19 22:40 +0200

csiph-web