Skip to contentSkip to conversation

cxgb4: reduce memory footprint for collecting firmware dump

PATCH In review Rahul Lakkireddy 2 participants 4 messages Jan 17, 2018 – Jan 19, 2018

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover cxgb4: reduce memory footprint for collecting firmware dump

Firmware dump can be large (upto 2 GB). In low memory conditions, ethtool fails to allocate such large memory. So, use zlib deflate to compress collected firmware dump.

Patch 1 updates collection logic to use compression.

Patch 2 adds zlib deflate to compress collected firmware dump.

Thanks,
Rahul

Rahul Lakkireddy (2):
cxgb4: update dump collection logic to use compression
cxgb4: use zlib deflate to compress firmware dump

 drivers/net/ethernet/chelsio/cxgb4/Makefile        |   1 +
 drivers/net/ethernet/chelsio/cxgb4/cudbg_common.c  |  24 +-
 drivers/net/ethernet/chelsio/cxgb4/cudbg_if.h      |   4 +
 drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c     | 280 +++++++++++----------
 .../net/ethernet/chelsio/cxgb4/cudbg_lib_common.h  |   8 +-
 drivers/net/ethernet/chelsio/cxgb4/cudbg_zlib.c    |  81 ++++++
 drivers/net/ethernet/chelsio/cxgb4/cudbg_zlib.h    |  56 +++++
 drivers/net/ethernet/chelsio/cxgb4/cxgb4_cudbg.c   |  65 ++++-
 drivers/net/ethernet/chelsio/cxgb4/cxgb4_cudbg.h   |   3 +
 9 files changed, 374 insertions(+), 148 deletions(-)
 create mode 100644 drivers/net/ethernet/chelsio/cxgb4/cudbg_zlib.c
 create mode 100644 drivers/net/ethernet/chelsio/cxgb4/cudbg_zlib.h
Signature · 1 line
2.14.1
#2 lore raw

PATCH 2/2 cxgb4: use zlib deflate to compress firmware dump

Use zlib deflate to compress firmware dump. Collect and compress as much firmware dump as possible into a 32 MB buffer.

---
 drivers/net/ethernet/chelsio/cxgb4/Makefile        |  1 +
 drivers/net/ethernet/chelsio/cxgb4/cudbg_if.h      |  1 +
 .../net/ethernet/chelsio/cxgb4/cudbg_lib_common.h  |  1 +
 drivers/net/ethernet/chelsio/cxgb4/cudbg_zlib.c    | 81 ++++++++++++++++++++++
 drivers/net/ethernet/chelsio/cxgb4/cudbg_zlib.h    | 29 ++++++++
 drivers/net/ethernet/chelsio/cxgb4/cxgb4_cudbg.c   | 56 ++++++++++++++-
 drivers/net/ethernet/chelsio/cxgb4/cxgb4_cudbg.h   |  3 +
 7 files changed, 169 insertions(+), 3 deletions(-)
 create mode 100644 drivers/net/ethernet/chelsio/cxgb4/cudbg_zlib.c
drivers/net/ethernet/chelsio/cxgb4/Makefile +1 -0
index 8c9c6b0d2e5d..5df923798669 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_ZLIB_DEFLATE) += cudbg_zlib.o
drivers/net/ethernet/chelsio/cxgb4/cudbg_if.h +1 -0
index eb1d2f48ebd3..8568a51f6414 100644
@@ -90,6 +90,7 @@ struct cudbg_init {
 	u8 compress_type; /* Type of compression to use */
 	void *compress_buff; /* Compression buffer */
 	u32 compress_buff_size; /* Compression buffer size */
+	void *workspace; /* Workspace for zlib */
 };
 
 static inline unsigned int cudbg_mbytes_to_bytes(unsigned int size)
drivers/net/ethernet/chelsio/cxgb4/cudbg_lib_common.h +1 -0
index 2e1c8e87c9bd..8150ea85d6a5 100644
@@ -26,6 +26,7 @@ enum cudbg_dump_type {
 
 enum cudbg_compression_type {
 	CUDBG_COMPRESSION_NONE = 1,
+	CUDBG_COMPRESSION_ZLIB,
 };
 
 struct cudbg_hdr {
drivers/net/ethernet/chelsio/cxgb4/cudbg_zlib.c new file +81 -0

81 lines not on this page · raw message

drivers/net/ethernet/chelsio/cxgb4/cudbg_zlib.h +29 -0
index f4b4a4a2301d..9d55c4c38c84 100644
@@ -18,10 +18,39 @@
 #ifndef __CUDBG_ZLIB_H__
 #define __CUDBG_ZLIB_H__
 
+#include <linux/zlib.h>
+
+#define CUDBG_ZLIB_COMPRESS_ID 17
+#define CUDBG_ZLIB_WIN_BITS 12
+#define CUDBG_ZLIB_MEM_LVL 4
+
+struct cudbg_compress_hdr {
+	u32 compress_id;
+	u64 decompress_size;
+	u64 compress_size;
+	u64 rsvd[32];
+};
+
+static inline int cudbg_get_workspace_size(void)
+{
+#ifdef CONFIG_ZLIB_DEFLATE
+	return zlib_deflate_workspacesize(CUDBG_ZLIB_WIN_BITS,
+					  CUDBG_ZLIB_MEM_LVL);
+#else
+	return 0;
+#endif /* CONFIG_ZLIB_DEFLATE */
+}
+
+#ifndef CONFIG_ZLIB_DEFLATE
 static inline int cudbg_compress_buff(struct cudbg_init *pdbg_init,
 				      struct cudbg_buffer *pin_buff,
 				      struct cudbg_buffer *pout_buff)
 {
 	return 0;
 }
+#else
+int cudbg_compress_buff(struct cudbg_init *pdbg_init,
+			struct cudbg_buffer *pin_buff,
+			struct cudbg_buffer *pout_buff);
+#endif /* CONFIG_ZLIB_DEFLATE */
 #endif /* __CUDBG_ZLIB_H__ */
drivers/net/ethernet/chelsio/cxgb4/cxgb4_cudbg.c +53 -3

105 lines not on this page · raw message

drivers/net/ethernet/chelsio/cxgb4/cxgb4_cudbg.h +3 -0
index 7ceeb0bc9fa8..ce1ac9a1c878 100644
@@ -23,6 +23,9 @@
 #include "cudbg_entity.h"
 #include "cudbg_lib.h"
 
+#define CUDBG_DUMP_BUFF_SIZE (32 * 1024 * 1024) /* 32 MB */
+#define CUDBG_COMPRESS_BUFF_SIZE (4 * 1024 * 1024) /* 4 MB */
+
 typedef int (*cudbg_collect_callback_t)(struct cudbg_init *pdbg_init,
 					struct cudbg_buffer *dbg_buff,
 					struct cudbg_error *cudbg_err);
Signature · 1 line
2.14.1
#1 lore raw

PATCH 1/2 cxgb4: update dump collection logic to use compression

In reply to Rahul Lakkireddy

Update firmware dump collection logic to use compression when available. Let collection logic attempt to do compression, instead of returning out of memory early.

---
 drivers/net/ethernet/chelsio/cxgb4/cudbg_common.c  |  24 +-
 drivers/net/ethernet/chelsio/cxgb4/cudbg_if.h      |   3 +
 drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c     | 280 +++++++++++----------
 .../net/ethernet/chelsio/cxgb4/cudbg_lib_common.h  |   7 +-
 drivers/net/ethernet/chelsio/cxgb4/cudbg_zlib.h    |  27 ++
 drivers/net/ethernet/chelsio/cxgb4/cxgb4_cudbg.c   |  13 +-
 6 files changed, 207 insertions(+), 147 deletions(-)
 create mode 100644 drivers/net/ethernet/chelsio/cxgb4/cudbg_zlib.h
drivers/net/ethernet/chelsio/cxgb4/cudbg_common.c +19 -5
index f78ba1743b5a..8edc49827af0 100644
@@ -19,7 +19,8 @@
 #include "cudbg_if.h"
 #include "cudbg_lib_common.h"
 
-int cudbg_get_buff(struct cudbg_buffer *pdbg_buff, u32 size,
+int cudbg_get_buff(struct cudbg_init *pdbg_init,
+		   struct cudbg_buffer *pdbg_buff, u32 size,
 		   struct cudbg_buffer *pin_buff)
 {
 	u32 offset;
@@ -28,17 +29,30 @@ int cudbg_get_buff(struct cudbg_buffer *pdbg_buff, u32 size,
 	if (offset + size > pdbg_buff->size)
 		return CUDBG_STATUS_NO_MEM;
 
+	if (pdbg_init->compress_type != CUDBG_COMPRESSION_NONE) {
+		if (size > pdbg_init->compress_buff_size)
+			return CUDBG_STATUS_NO_MEM;
+
+		pin_buff->data = (char *)pdbg_init->compress_buff;
+		pin_buff->offset = 0;
+		pin_buff->size = size;
+		return 0;
+	}
+
 	pin_buff->data = (char *)pdbg_buff->data + offset;
 	pin_buff->offset = offset;
 	pin_buff->size = size;
-	pdbg_buff->size -= size;
 	return 0;
 }
 
-void cudbg_put_buff(struct cudbg_buffer *pin_buff,
-		    struct cudbg_buffer *pdbg_buff)
+void cudbg_put_buff(struct cudbg_init *pdbg_init,
+		    struct cudbg_buffer *pin_buff)
 {
-	pdbg_buff->size += pin_buff->size;
+	/* Clear compression buffer for re-use */
+	if (pdbg_init->compress_type != CUDBG_COMPRESSION_NONE)
+		memset(pdbg_init->compress_buff, 0,
+		       pdbg_init->compress_buff_size);
+
 	pin_buff->data = NULL;
 	pin_buff->offset = 0;
 	pin_buff->size = 0;
drivers/net/ethernet/chelsio/cxgb4/cudbg_if.h +3 -0
index 88e740082a02..eb1d2f48ebd3 100644
@@ -87,6 +87,9 @@ struct cudbg_init {
 	struct adapter *adap; /* Pointer to adapter structure */
 	void *outbuf; /* Output buffer */
 	u32 outbuf_size;  /* Output buffer size */
+	u8 compress_type; /* Type of compression to use */
+	void *compress_buff; /* Compression buffer */
+	u32 compress_buff_size; /* Compression buffer size */
 };
 
 static inline unsigned int cudbg_mbytes_to_bytes(unsigned int size)
drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c +151 -129

794 lines not on this page · raw message

drivers/net/ethernet/chelsio/cxgb4/cudbg_lib_common.h +4 -3
index 24b33f28e548..2e1c8e87c9bd 100644
@@ -78,10 +78,11 @@ struct cudbg_error {
 #define CDUMP_MAX_COMP_BUF_SIZE ((64 * 1024) - 1)
 #define CUDBG_CHUNK_SIZE ((CDUMP_MAX_COMP_BUF_SIZE / 1024) * 1024)
 
-int cudbg_get_buff(struct cudbg_buffer *pdbg_buff, u32 size,
+int cudbg_get_buff(struct cudbg_init *pdbg_init,
+		   struct cudbg_buffer *pdbg_buff, u32 size,
 		   struct cudbg_buffer *pin_buff);
-void cudbg_put_buff(struct cudbg_buffer *pin_buff,
-		    struct cudbg_buffer *pdbg_buff);
+void cudbg_put_buff(struct cudbg_init *pdbg_init,
+		    struct cudbg_buffer *pin_buff);
 void cudbg_update_buff(struct cudbg_buffer *pin_buff,
 		       struct cudbg_buffer *pout_buff);
 #endif /* __CUDBG_LIB_COMMON_H__ */
drivers/net/ethernet/chelsio/cxgb4/cudbg_zlib.h new file +27 -0
new file mode 100644
index 000000000000..f4b4a4a2301d
@@ -0,0 +1,27 @@
+/*
+ *  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_ZLIB_H__
+#define __CUDBG_ZLIB_H__
+
+static inline int cudbg_compress_buff(struct cudbg_init *pdbg_init,
+				      struct cudbg_buffer *pin_buff,
+				      struct cudbg_buffer *pout_buff)
+{
+	return 0;
+}
+#endif /* __CUDBG_ZLIB_H__ */
drivers/net/ethernet/chelsio/cxgb4/cxgb4_cudbg.c +3 -10
index a2d6c8a69c52..bf1732da8c6d 100644
@@ -341,22 +341,14 @@ static void cxgb4_cudbg_collect_entity(struct cudbg_init *pdbg_init,
 				       const struct cxgb4_collect_entity *e_arr,
 				       u32 arr_size, void *buf, u32 *tot_size)
 {
-	struct adapter *adap = pdbg_init->adap;
 	struct cudbg_error cudbg_err = { 0 };
 	struct cudbg_entity_hdr *entity_hdr;
-	u32 entity_size, i;
-	u32 total_size = 0;
+	u32 i, total_size = 0;
 	int ret;
 
 	for (i = 0; i < arr_size; i++) {
 		const struct cxgb4_collect_entity *e = &e_arr[i];
 
-		/* Skip entities that won't fit in output buffer */
-		entity_size = cxgb4_get_entity_length(adap, e->entity);
-		if (entity_size >
-		    pdbg_init->outbuf_size - *tot_size - total_size)
-			continue;
-
 		entity_hdr = cudbg_get_entity_hdr(buf, e->entity);
 		entity_hdr->entity_type = e->entity;
 		entity_hdr->start_offset = dbg_buff->offset;
@@ -408,7 +400,8 @@ int cxgb4_cudbg_collect(struct adapter *adap, void *buf, u32 *buf_size,
 	cudbg_hdr->max_entities = CUDBG_MAX_ENTITY;
 	cudbg_hdr->chip_ver = adap->params.chip;
 	cudbg_hdr->dump_type = CUDBG_DUMP_TYPE_MINI;
-	cudbg_hdr->compress_type = CUDBG_COMPRESSION_NONE;
+	cudbg_init.compress_type = CUDBG_COMPRESSION_NONE;
+	cudbg_hdr->compress_type = cudbg_init.compress_type;
 
 	min_size = sizeof(struct cudbg_hdr) +
 		   sizeof(struct cudbg_entity_hdr) *
Signature · 1 line
2.14.1
maintainer
#3 lore raw
In reply to Rahul Lakkireddy

From: Rahul Lakkireddy <[email protected]>
Date: Wed, 17 Jan 2018 12:53:45 +0530

Quoted 7 lines

Firmware dump can be large (upto 2 GB). In low memory conditions, ethtool fails to allocate such large memory. So, use zlib deflate to compress collected firmware dump.

Patch 1 updates collection logic to use compression.

Patch 2 adds zlib deflate to compress collected firmware dump.

Series applied, thanks Rahul.