Skip to contentSkip to conversation

cxgb4: speed up reading on-chip memory

PATCH Superseded Rahul Lakkireddy 3 participants 6 messages Jan 14, 2018 – Jan 16, 2018

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover cxgb4: speed up reading on-chip memory

This series of patches speed up reading on-chip memory (EDC and MC) by using AVX intrinsic instructions when available.

Patch 1 exports callback to register supported intrinsic instructions when available. Also rework logic to read EDC and MC.

Patch 2 adds AVX CPU intrinsic instructions to read EDC and MC 256-bits at a time. Also fallback to regular 32-bit reads, if AVX is not available.

Thanks,
Rahul

Rahul Lakkireddy (2):
cxgb4: rework on-chip memory read
cxgb4: speed up on-chip memory read

 drivers/net/ethernet/chelsio/cxgb4/Makefile        |   3 +-
 drivers/net/ethernet/chelsio/cxgb4/cudbg_entity.h  |   2 +
 drivers/net/ethernet/chelsio/cxgb4/cudbg_if.h      |   6 +
 .../net/ethernet/chelsio/cxgb4/cudbg_intrinsic.c   |  43 +++++
 .../net/ethernet/chelsio/cxgb4/cudbg_intrinsic.h   |  33 ++++
 .../ethernet/chelsio/cxgb4/cudbg_intrinsic_avx.c   |  78 +++++++++
 drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c     |  70 +++++++-
 drivers/net/ethernet/chelsio/cxgb4/cxgb4.h         |   5 +
 drivers/net/ethernet/chelsio/cxgb4/cxgb4_cudbg.c   |   7 +-
 drivers/net/ethernet/chelsio/cxgb4/cxgb4_ethtool.c |   2 +
 drivers/net/ethernet/chelsio/cxgb4/t4_hw.c         | 193 +++++++++++++--------
 11 files changed, 367 insertions(+), 75 deletions(-)
 create mode 100644 drivers/net/ethernet/chelsio/cxgb4/cudbg_intrinsic.c
 create mode 100644 drivers/net/ethernet/chelsio/cxgb4/cudbg_intrinsic.h
 create mode 100644 drivers/net/ethernet/chelsio/cxgb4/cudbg_intrinsic_avx.c
Signature · 1 line
2.14.1
#1 lore raw

PATCH 1/2 cxgb4: rework on-chip memory read

Export callback to register supported intrinsic instructions to speed up reading EDC and MC. By default, use 32-bit reads. Also rework logic to read EDC and MC.

---
 drivers/net/ethernet/chelsio/cxgb4/Makefile        |   2 +-
 drivers/net/ethernet/chelsio/cxgb4/cudbg_if.h      |   6 +
 .../net/ethernet/chelsio/cxgb4/cudbg_intrinsic.c   |  38 ++++
 .../net/ethernet/chelsio/cxgb4/cudbg_intrinsic.h   |  25 +++
 drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c     |  70 +++++++-
 drivers/net/ethernet/chelsio/cxgb4/cxgb4.h         |   5 +
 drivers/net/ethernet/chelsio/cxgb4/cxgb4_cudbg.c   |   2 +
 drivers/net/ethernet/chelsio/cxgb4/t4_hw.c         | 193 +++++++++++++--------
 8 files changed, 267 insertions(+), 74 deletions(-)
 create mode 100644 drivers/net/ethernet/chelsio/cxgb4/cudbg_intrinsic.c
 create mode 100644 drivers/net/ethernet/chelsio/cxgb4/cudbg_intrinsic.h
drivers/net/ethernet/chelsio/cxgb4/Makefile +1 -1
index 8c9c6b0d2e5d..0dbaf1b18bac 100644
@@ -8,7 +8,7 @@ obj-$(CONFIG_CHELSIO_T4) += cxgb4.o
 cxgb4-objs := cxgb4_main.o l2t.o smt.o t4_hw.o sge.o clip_tbl.o cxgb4_ethtool.o \
 	      cxgb4_uld.o sched.o cxgb4_filter.o cxgb4_tc_u32.o \
 	      cxgb4_ptp.o cxgb4_tc_flower.o cxgb4_cudbg.o \
-	      cudbg_common.o cudbg_lib.o
+	      cudbg_common.o cudbg_lib.o cudbg_intrinsic.o
 cxgb4-$(CONFIG_CHELSIO_T4_DCB) +=  cxgb4_dcb.o
 cxgb4-$(CONFIG_CHELSIO_T4_FCOE) +=  cxgb4_fcoe.o
 cxgb4-$(CONFIG_DEBUG_FS) += cxgb4_debugfs.o
drivers/net/ethernet/chelsio/cxgb4/cudbg_if.h +6 -0
index 88e740082a02..456d61eacb27 100644
@@ -83,10 +83,16 @@ enum cudbg_dbg_entity_type {
 	CUDBG_MAX_ENTITY = 70,
 };
 
+struct cudbg_init;
+typedef unsigned int (*cudbg_intrinsic_t)(struct cudbg_init *pdbg_init,
+					  u32 start, u32 offset, u32 size,
+					  u32 max_size, u8 *buf);
+
 struct cudbg_init {
 	struct adapter *adap; /* Pointer to adapter structure */
 	void *outbuf; /* Output buffer */
 	u32 outbuf_size;  /* Output buffer size */
+	cudbg_intrinsic_t intrinsic_cb; /* CPU intrinsic callback */
 };
 
 static inline unsigned int cudbg_mbytes_to_bytes(unsigned int size)
drivers/net/ethernet/chelsio/cxgb4/cudbg_intrinsic.c new file +38 -0
new file mode 100644
index 000000000000..0b80512e5c0c
@@ -0,0 +1,38 @@
+/*
+ *  Copyright (C) 2018 Chelsio Communications.  All rights reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify it
+ *  under the terms and conditions of the GNU General Public License,
+ *  version 2, as published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope it will be useful, but WITHOUT
+ *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ *  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ *  more details.
+ *
+ *  The full GNU General Public License is included in this distribution in
+ *  the file called "COPYING".
+ *
+ */
+
+#include "cxgb4.h"
+#include "cudbg_if.h"
+#include "cudbg_intrinsic.h"
+
+unsigned int cudbg_mem_read_def(struct cudbg_init *pdbg_init,
+				u32 start, u32 offset, u32 size,
+				u32 mem_aperture, u8 *outbuf)
+{
+	struct adapter *adap = pdbg_init->adap;
+	__be32 *buf = (__be32 *)outbuf;
+
+	*buf = le32_to_cpu((__force __le32)
+			   t4_read_reg(adap, start + offset));
+
+	return sizeof(__be32);
+}
+
+void cudbg_set_intrinsic_callback(struct cudbg_init *pdbg_init)
+{
+	pdbg_init->intrinsic_cb = cudbg_mem_read_def;
+}
drivers/net/ethernet/chelsio/cxgb4/cudbg_intrinsic.h new file +25 -0
new file mode 100644
index 000000000000..3af0f07311ec
@@ -0,0 +1,25 @@
+/*
+ *  Copyright (C) 2018 Chelsio Communications.  All rights reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify it
+ *  under the terms and conditions of the GNU General Public License,
+ *  version 2, as published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope it will be useful, but WITHOUT
+ *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ *  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ *  more details.
+ *
+ *  The full GNU General Public License is included in this distribution in
+ *  the file called "COPYING".
+ *
+ */
+
+#ifndef __CUDBG_INTRINSIC_H__
+#define __CUDBG_INTRINSIC_H__
+
+unsigned int cudbg_mem_read_def(struct cudbg_init *pdbg_init,
+				u32 start, u32 offset, u32 size,
+				u32 mem_aperture, u8 *outbuf);
+void cudbg_set_intrinsic_callback(struct cudbg_init *pdbg_init);
+#endif /* __CUDBG_INTRINSIC_H__ */
drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c +66 -4

88 lines not on this page · raw message

drivers/net/ethernet/chelsio/cxgb4/cxgb4.h +5 -0
index baa67d362051..92f1d87adf9f 100644
@@ -1471,6 +1471,11 @@ u32 t4_read_pcie_cfg4(struct adapter *adap, int reg);
 u32 t4_get_util_window(struct adapter *adap);
 void t4_setup_memwin(struct adapter *adap, u32 memwin_base, u32 window);
 
+int t4_memory_rw_init(struct adapter *adap, int win, int mtype, u32 *mem_off,
+		      u32 *mem_base, u32 *mem_aperture);
+void t4_memory_update_win(struct adapter *adap, int win, u32 addr);
+void t4_memory_rw_residual(struct adapter *adap, u32 off, u32 addr, u8 *buf,
+			   int dir);
 #define T4_MEMORY_WRITE	0
 #define T4_MEMORY_READ	1
 int t4_memory_rw(struct adapter *adap, int win, int mtype, u32 addr, u32 len,
drivers/net/ethernet/chelsio/cxgb4/cxgb4_cudbg.c +2 -0
index a2d6c8a69c52..db1b57a09887 100644
@@ -18,6 +18,7 @@
 #include "t4_regs.h"
 #include "cxgb4.h"
 #include "cxgb4_cudbg.h"
+#include "cudbg_intrinsic.h"
 
 static const struct cxgb4_collect_entity cxgb4_collect_mem_dump[] = {
 	{ CUDBG_EDC0, cudbg_collect_edc0_meminfo },
@@ -395,6 +396,7 @@ int cxgb4_cudbg_collect(struct adapter *adap, void *buf, u32 *buf_size,
 	cudbg_init.adap = adap;
 	cudbg_init.outbuf = buf;
 	cudbg_init.outbuf_size = size;
+	cudbg_set_intrinsic_callback(&cudbg_init);
 
 	dbg_buff.data = buf;
 	dbg_buff.size = size;
drivers/net/ethernet/chelsio/cxgb4/t4_hw.c +124 -69

237 lines not on this page · raw message

Signature · 1 line
2.14.1
#2 lore raw

Re: [PATCH net-next 1/2] cxgb4: rework on-chip memory read

Thank you for the patch! Perhaps something to improve:

Hi Rahul,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on net-next/master]

url: https://github.com/0day-ci/linux/commits/Rahul-Lakkireddy/cxgb4-rework-on-chip-memory-read/20180116-050826
reproduce:

        # apt-get install sparse
        make ARCH=x86_64 allmodconfig
        make C=1 CF=-D__CHECK_ENDIAN__

sparse warnings: (new ones prefixed by >>)

>> drivers/net/ethernet/chelsio/cxgb4/cudbg_intrinsic.c:29:14: sparse: incorrect type in assignment (different base types) @@ expected restricted __be32 <noident> @@ got unsignrestricted __be32 <noident> @@

drivers/net/ethernet/chelsio/cxgb4/cudbg_intrinsic.c:29:14: expected restricted __be32 <noident> drivers/net/ethernet/chelsio/cxgb4/cudbg_intrinsic.c:29:14: got unsigned int <noident>

vim +29 drivers/net/ethernet/chelsio/cxgb4/cudbg_intrinsic.c

    21	
    22	unsigned int cudbg_mem_read_def(struct cudbg_init *pdbg_init,
    23					u32 start, u32 offset, u32 size,
    24					u32 mem_aperture, u8 *outbuf)
    25	{
    26		struct adapter *adap = pdbg_init->adap;
    27		__be32 *buf = (__be32 *)outbuf;
    28	
  > 29		*buf = le32_to_cpu((__force __le32)
    30				   t4_read_reg(adap, start + offset));
    31	
    32		return sizeof(__be32);
    33	}
    34	

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#3 lore raw

PATCH 2/2 cxgb4: speed up on-chip memory read

In reply to Rahul Lakkireddy

Register and use AVX CPU intrinsic instructions when available to do 256-bit reads to speed up reading EDC and MC. Otherwise, fallback to 32-bit reads. Also align destination buffer on 32-byte boundary.

---
 drivers/net/ethernet/chelsio/cxgb4/Makefile        |  1 +
 drivers/net/ethernet/chelsio/cxgb4/cudbg_entity.h  |  2 +
 .../net/ethernet/chelsio/cxgb4/cudbg_intrinsic.c   |  7 +-
 .../net/ethernet/chelsio/cxgb4/cudbg_intrinsic.h   |  8 +++
 .../ethernet/chelsio/cxgb4/cudbg_intrinsic_avx.c   | 78 ++++++++++++++++++++++
 drivers/net/ethernet/chelsio/cxgb4/cxgb4_cudbg.c   |  5 +-
 drivers/net/ethernet/chelsio/cxgb4/cxgb4_ethtool.c |  2 +
 7 files changed, 101 insertions(+), 2 deletions(-)
 create mode 100644 drivers/net/ethernet/chelsio/cxgb4/cudbg_intrinsic_avx.c
drivers/net/ethernet/chelsio/cxgb4/Makefile +1 -0
index 0dbaf1b18bac..a0f5239b19d4 100644
@@ -12,3 +12,4 @@ cxgb4-objs := cxgb4_main.o l2t.o smt.o t4_hw.o sge.o clip_tbl.o cxgb4_ethtool.o
 cxgb4-$(CONFIG_CHELSIO_T4_DCB) +=  cxgb4_dcb.o
 cxgb4-$(CONFIG_CHELSIO_T4_FCOE) +=  cxgb4_fcoe.o
 cxgb4-$(CONFIG_DEBUG_FS) += cxgb4_debugfs.o
+cxgb4-$(CONFIG_X86) += cudbg_intrinsic_avx.o
drivers/net/ethernet/chelsio/cxgb4/cudbg_entity.h +2 -0
index b57acb8dc35b..4269d1621e9a 100644
@@ -25,6 +25,8 @@
 #define MC1_FLAG 4
 #define HMA_FLAG 5
 
+#define CUDBG_MEM_ALIGN 32
+
 #define CUDBG_ENTITY_SIGNATURE 0xCCEDB001
 
 struct cudbg_mbox_log {
drivers/net/ethernet/chelsio/cxgb4/cudbg_intrinsic.c +6 -1
index 0b80512e5c0c..6ed418d90507 100644
@@ -34,5 +34,10 @@ unsigned int cudbg_mem_read_def(struct cudbg_init *pdbg_init,
 
 void cudbg_set_intrinsic_callback(struct cudbg_init *pdbg_init)
 {
-	pdbg_init->intrinsic_cb = cudbg_mem_read_def;
+#ifdef CONFIG_X86
+	if (cudbg_intrinsic_avx_supported())
+		pdbg_init->intrinsic_cb = cudbg_mem_read_avx;
+	else
+#endif
+		pdbg_init->intrinsic_cb = cudbg_mem_read_def;
 }
drivers/net/ethernet/chelsio/cxgb4/cudbg_intrinsic.h +8 -0
index 3af0f07311ec..d878c71ef65d 100644
@@ -21,5 +21,13 @@
 unsigned int cudbg_mem_read_def(struct cudbg_init *pdbg_init,
 				u32 start, u32 offset, u32 size,
 				u32 mem_aperture, u8 *outbuf);
+
+#ifdef CONFIG_X86
+int cudbg_intrinsic_avx_supported(void);
+unsigned int cudbg_mem_read_avx(struct cudbg_init *pdbg_init, u32 start,
+				u32 offset, u32 size, u32 mem_aperture,
+				u8 *outbuf);
+#endif
+
 void cudbg_set_intrinsic_callback(struct cudbg_init *pdbg_init);
 #endif /* __CUDBG_INTRINSIC_H__ */
drivers/net/ethernet/chelsio/cxgb4/cudbg_intrinsic_avx.c new file +78 -0

78 lines not on this page · raw message

drivers/net/ethernet/chelsio/cxgb4/cxgb4_cudbg.c +4 -1
index db1b57a09887..220ba2f60cf7 100644
@@ -428,12 +428,15 @@ int cxgb4_cudbg_collect(struct adapter *adap, void *buf, u32 *buf_size,
 					   buf,
 					   &total_size);
 
-	if (flag & CXGB4_ETH_DUMP_MEM)
+	if (flag & CXGB4_ETH_DUMP_MEM) {
+		dbg_buff.offset = roundup(dbg_buff.offset, CUDBG_MEM_ALIGN);
+		total_size = roundup(total_size, CUDBG_MEM_ALIGN);
 		cxgb4_cudbg_collect_entity(&cudbg_init, &dbg_buff,
 					   cxgb4_collect_mem_dump,
 					   ARRAY_SIZE(cxgb4_collect_mem_dump),
 					   buf,
 					   &total_size);
+	}
 
 	cudbg_hdr->data_len = total_size;
 	*buf_size = total_size;
drivers/net/ethernet/chelsio/cxgb4/cxgb4_ethtool.c +2 -0
index 7852d98bad75..d437e46f6af6 100644
@@ -1362,6 +1362,7 @@ static int set_dump(struct net_device *dev, struct ethtool_dump *eth_dump)
 	len = sizeof(struct cudbg_hdr) +
 	      sizeof(struct cudbg_entity_hdr) * CUDBG_MAX_ENTITY;
 	len += cxgb4_get_dump_length(adapter, eth_dump->flag);
+	len = roundup(len, CUDBG_MEM_ALIGN);
 
 	adapter->eth_dump.flag = eth_dump->flag;
 	adapter->eth_dump.len = len;
@@ -1391,6 +1392,7 @@ static int get_dump_data(struct net_device *dev, struct ethtool_dump *eth_dump,
 	len = sizeof(struct cudbg_hdr) +
 	      sizeof(struct cudbg_entity_hdr) * CUDBG_MAX_ENTITY;
 	len += cxgb4_get_dump_length(adapter, adapter->eth_dump.flag);
+	len = roundup(len, CUDBG_MEM_ALIGN);
 	if (eth_dump->len < len)
 		return -ENOMEM;
 
Signature · 1 line
2.14.1
#4 lore raw

Re: [PATCH net-next 2/2] cxgb4: speed up on-chip memory read

Thank you for the patch! Perhaps something to improve:

Hi Rahul,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on net-next/master]

url: https://github.com/0day-ci/linux/commits/Rahul-Lakkireddy/cxgb4-rework-on-chip-memory-read/20180116-050826
reproduce:

        # apt-get install sparse
        make ARCH=x86_64 allmodconfig
        make C=1 CF=-D__CHECK_ENDIAN__

sparse warnings: (new ones prefixed by >>)

>> drivers/net/ethernet/chelsio/cxgb4/cudbg_intrinsic_avx.c:48:21: sparse: cast removes address space of expression

vim +48 drivers/net/ethernet/chelsio/cxgb4/cudbg_intrinsic_avx.c

    37	
    38	unsigned int cudbg_mem_read_avx(struct cudbg_init *pdbg_init, u32 start,
    39					u32 offset, u32 size, u32 mem_aperture,
    40					u8 *outbuf)
    41	{
    42	#ifdef CONFIG_AS_AVX
    43		u32 max_read_len = CUDBG_MEM_ALIGN_AVX;
    44		struct adapter *adap = pdbg_init->adap;
    45		u8 *reg_addr, *src_addr, *dst_addr;
    46		u32 bytes_read, read_len;
    47	
  > 48		reg_addr = (u8 *)adap->regs + start + offset;

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

maintainer
#5 lore raw
In reply to Rahul Lakkireddy

From: Rahul Lakkireddy <[email protected]>
Date: Sun, 14 Jan 2018 15:02:03 +0530

Quoted 9 lines

This series of patches speed up reading on-chip memory (EDC and MC) by using AVX intrinsic instructions when available.

Patch 1 exports callback to register supported intrinsic instructions when available. Also rework logic to read EDC and MC.

Patch 2 adds AVX CPU intrinsic instructions to read EDC and MC 256-bits at a time. Also fallback to regular 32-bit reads, if AVX is not available.

This violates things on several levels.

IO mappings are a special __iomem type because you _CANNOT_ dereference them directly.

This means you cannot feed them into normal C dereferences or normal loads or stores.

The whole point is that if the layout and format of the __iomem pointer changes, or if some special kind of access is necessary, no driver code needs to change.

But if you start adding direct AVX instruction loads and stores of these pointers, things are going to break in the future.

Sorry, there is no way I am applying this patch set.

Thanks.