Skip to contentSkip to conversation

crypto: IAA stats bugfixes and simplifications

PATCH In review Tom Zanussi 2 participants 6 messages Mar 4, 2024 – Mar 28, 2024

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

cover crypto: IAA stats bugfixes and simplifications

Hi Herbert,

While doing some testing, I noticed a discrepancy in the decomp_bytes_in stat, which the first patch in this series (crypto:
iaa - fix decomp_bytes_in stats) fixes.

I also realized that there were some other problems unrelated to that but also that the stats code could be simplified in a number of ways and that some of it wasn't really useful. The stats code is debugging code and has been helpful to quickly verify whether things are basically working, but since it's there we should make it as accurate and actually useful as possible.

I realize the second patch (crypto: iaa - Remove comp/decomp delay statistics) removes the code I just fixed up in a patch you just merged (crypto: iaa - Fix comp/decomp delay statistics) - let me know if you want me to combine those if you want to remove the latter from your branch...

Thanks,

Tom

*** BLURB HERE ***

Tom Zanussi (4):
crypto: iaa - fix decomp_bytes_in stats
crypto: iaa - Remove comp/decomp delay statistics
crypto: iaa - Add global_stats file and remove individual stat files
crypto: iaa - Change iaa statistics to atomic64_t

 .../driver-api/crypto/iaa/iaa-crypto.rst      |  76 +++++---
 drivers/crypto/intel/iaa/iaa_crypto.h         |  16 +-
 drivers/crypto/intel/iaa/iaa_crypto_main.c    |  13 +-
 drivers/crypto/intel/iaa/iaa_crypto_stats.c   | 183 ++++++++----------
 drivers/crypto/intel/iaa/iaa_crypto_stats.h   |   8 -
 5 files changed, 140 insertions(+), 156 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/4 crypto: iaa - fix decomp_bytes_in stats

Decomp stats should use slen, not dlen. Change both the global and per-wq stats to use the correct value.

---
 drivers/crypto/intel/iaa/iaa_crypto_main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/crypto/intel/iaa/iaa_crypto_main.c +2 -2
index b54f93c64033..466bd0c71816 100644
@@ -1075,8 +1075,8 @@ static void iaa_desc_complete(struct idxd_desc *idxd_desc,
 		update_total_comp_bytes_out(ctx->req->dlen);
 		update_wq_comp_bytes(iaa_wq->wq, ctx->req->dlen);
 	} else {
-		update_total_decomp_bytes_in(ctx->req->dlen);
-		update_wq_decomp_bytes(iaa_wq->wq, ctx->req->dlen);
+		update_total_decomp_bytes_in(ctx->req->slen);
+		update_wq_decomp_bytes(iaa_wq->wq, ctx->req->slen);
 	}
 
 	if (ctx->compress && compression_ctx->verify_compress) {
Signature · 1 line
2.34.1
#2 lore raw

PATCH 2/4 crypto: iaa - Remove comp/decomp delay statistics

In reply to Tom Zanussi

As part of the simplification/cleanup of the iaa statistics, remove the comp/decomp delay statistics.

They're actually not really useful and can be/are being more flexibly generated using standard kernel tracing infrastructure.

---
 drivers/crypto/intel/iaa/iaa_crypto_main.c  |  9 -------
 drivers/crypto/intel/iaa/iaa_crypto_stats.c | 28 ---------------------
 drivers/crypto/intel/iaa/iaa_crypto_stats.h |  8 ------
 3 files changed, 45 deletions(-)
drivers/crypto/intel/iaa/iaa_crypto_main.c +0 -9
index 466bd0c71816..89bc06d4ebc9 100644
@@ -1494,7 +1494,6 @@ static int iaa_comp_acompress(struct acomp_req *req)
 	u32 compression_crc;
 	struct idxd_wq *wq;
 	struct device *dev;
-	u64 start_time_ns;
 	int order = -1;
 
 	compression_ctx = crypto_tfm_ctx(tfm);
@@ -1568,10 +1567,8 @@ static int iaa_comp_acompress(struct acomp_req *req)
 		" req->dlen %d, sg_dma_len(sg) %d\n", dst_addr, nr_sgs,
 		req->dst, req->dlen, sg_dma_len(req->dst));
 
-	start_time_ns = iaa_get_ts();
 	ret = iaa_compress(tfm, req, wq, src_addr, req->slen, dst_addr,
 			   &req->dlen, &compression_crc, disable_async);
-	update_max_comp_delay_ns(start_time_ns);
 	if (ret == -EINPROGRESS)
 		return ret;
 
@@ -1618,7 +1615,6 @@ static int iaa_comp_adecompress_alloc_dest(struct acomp_req *req)
 	struct iaa_wq *iaa_wq;
 	struct device *dev;
 	struct idxd_wq *wq;
-	u64 start_time_ns;
 	int order = -1;
 
 	cpu = get_cpu();
@@ -1675,10 +1671,8 @@ static int iaa_comp_adecompress_alloc_dest(struct acomp_req *req)
 	dev_dbg(dev, "dma_map_sg, dst_addr %llx, nr_sgs %d, req->dst %p,"
 		" req->dlen %d, sg_dma_len(sg) %d\n", dst_addr, nr_sgs,
 		req->dst, req->dlen, sg_dma_len(req->dst));
-	start_time_ns = iaa_get_ts();
 	ret = iaa_decompress(tfm, req, wq, src_addr, req->slen,
 			     dst_addr, &req->dlen, true);
-	update_max_decomp_delay_ns(start_time_ns);
 	if (ret == -EOVERFLOW) {
 		dma_unmap_sg(dev, req->dst, sg_nents(req->dst), DMA_FROM_DEVICE);
 		req->dlen *= 2;
@@ -1709,7 +1703,6 @@ static int iaa_comp_adecompress(struct acomp_req *req)
 	int nr_sgs, cpu, ret = 0;
 	struct iaa_wq *iaa_wq;
 	struct device *dev;
-	u64 start_time_ns;
 	struct idxd_wq *wq;
 
 	if (!iaa_crypto_enabled) {
@@ -1769,10 +1762,8 @@ static int iaa_comp_adecompress(struct acomp_req *req)
 		" req->dlen %d, sg_dma_len(sg) %d\n", dst_addr, nr_sgs,
 		req->dst, req->dlen, sg_dma_len(req->dst));
 
-	start_time_ns = iaa_get_ts();
 	ret = iaa_decompress(tfm, req, wq, src_addr, req->slen,
 			     dst_addr, &req->dlen, false);
-	update_max_decomp_delay_ns(start_time_ns);
 	if (ret == -EINPROGRESS)
 		return ret;
 
drivers/crypto/intel/iaa/iaa_crypto_stats.c +0 -28
index c9f83af4b307..7820062a91e5 100644
@@ -20,8 +20,6 @@
 static u64 total_comp_calls;
 static u64 total_decomp_calls;
 static u64 total_sw_decomp_calls;
-static u64 max_comp_delay_ns;
-static u64 max_decomp_delay_ns;
 static u64 total_comp_bytes_out;
 static u64 total_decomp_bytes_in;
 static u64 total_completion_einval_errors;
@@ -70,26 +68,6 @@ void update_completion_comp_buf_overflow_errs(void)
 	total_completion_comp_buf_overflow_errors++;
 }
 
-void update_max_comp_delay_ns(u64 start_time_ns)
-{
-	u64 time_diff;
-
-	time_diff = ktime_get_ns() - start_time_ns;
-
-	if (time_diff > max_comp_delay_ns)
-		max_comp_delay_ns = time_diff;
-}
-
-void update_max_decomp_delay_ns(u64 start_time_ns)
-{
-	u64 time_diff;
-
-	time_diff = ktime_get_ns() - start_time_ns;
-
-	if (time_diff > max_decomp_delay_ns)
-		max_decomp_delay_ns = time_diff;
-}
-
 void update_wq_comp_calls(struct idxd_wq *idxd_wq)
 {
 	struct iaa_wq *wq = idxd_wq_get_private(idxd_wq);
@@ -127,8 +105,6 @@ static void reset_iaa_crypto_stats(void)
 	total_comp_calls = 0;
 	total_decomp_calls = 0;
 	total_sw_decomp_calls = 0;
-	max_comp_delay_ns = 0;
-	max_decomp_delay_ns = 0;
 	total_comp_bytes_out = 0;
 	total_decomp_bytes_in = 0;
 	total_completion_einval_errors = 0;
@@ -252,10 +228,6 @@ int __init iaa_crypto_debugfs_init(void)
 
 	iaa_crypto_debugfs_root = debugfs_create_dir("iaa_crypto", NULL);
 
-	debugfs_create_u64("max_comp_delay_ns", 0644,
-			   iaa_crypto_debugfs_root, &max_comp_delay_ns);
-	debugfs_create_u64("max_decomp_delay_ns", 0644,
-			   iaa_crypto_debugfs_root, &max_decomp_delay_ns);
 	debugfs_create_u64("total_comp_calls", 0644,
 			   iaa_crypto_debugfs_root, &total_comp_calls);
 	debugfs_create_u64("total_decomp_calls", 0644,
drivers/crypto/intel/iaa/iaa_crypto_stats.h +0 -8
index c916ca83f070..3787a5f507eb 100644
@@ -13,8 +13,6 @@ void	update_total_comp_bytes_out(int n);
 void	update_total_decomp_calls(void);
 void	update_total_sw_decomp_calls(void);
 void	update_total_decomp_bytes_in(int n);
-void	update_max_comp_delay_ns(u64 start_time_ns);
-void	update_max_decomp_delay_ns(u64 start_time_ns);
 void	update_completion_einval_errs(void);
 void	update_completion_timeout_errs(void);
 void	update_completion_comp_buf_overflow_errs(void);
@@ -24,8 +22,6 @@ void	update_wq_comp_bytes(struct idxd_wq *idxd_wq, int n);
 void	update_wq_decomp_calls(struct idxd_wq *idxd_wq);
 void	update_wq_decomp_bytes(struct idxd_wq *idxd_wq, int n);
 
-static inline u64	iaa_get_ts(void) { return ktime_get_ns(); }
-
 #else
 static inline int	iaa_crypto_debugfs_init(void) { return 0; }
 static inline void	iaa_crypto_debugfs_cleanup(void) {}
@@ -35,8 +31,6 @@ static inline void	update_total_comp_bytes_out(int n) {}
 static inline void	update_total_decomp_calls(void) {}
 static inline void	update_total_sw_decomp_calls(void) {}
 static inline void	update_total_decomp_bytes_in(int n) {}
-static inline void	update_max_comp_delay_ns(u64 start_time_ns) {}
-static inline void	update_max_decomp_delay_ns(u64 start_time_ns) {}
 static inline void	update_completion_einval_errs(void) {}
 static inline void	update_completion_timeout_errs(void) {}
 static inline void	update_completion_comp_buf_overflow_errs(void) {}
@@ -46,8 +40,6 @@ static inline void	update_wq_comp_bytes(struct idxd_wq *idxd_wq, int n) {}
 static inline void	update_wq_decomp_calls(struct idxd_wq *idxd_wq) {}
 static inline void	update_wq_decomp_bytes(struct idxd_wq *idxd_wq, int n) {}
 
-static inline u64	iaa_get_ts(void) { return 0; }
-
 #endif // CONFIG_CRYPTO_DEV_IAA_CRYPTO_STATS
 
 #endif
Signature · 1 line
2.34.1
#3 lore raw

PATCH 3/4 crypto: iaa - Add global_stats file and remove individual stat files

In reply to Tom Zanussi

Currently, the wq_stats output also includes the global stats, while the individual global stats are also available as separate debugfs files. Since these are all read-only, there's really no reason to have them as separate files, especially since we already display them as global stats in the wq_stats. It makes more sense to just add a separate global_stats file to display those, and remove them from the wq_stats, as well as removing the individual stats files.

---
 .../driver-api/crypto/iaa/iaa-crypto.rst      | 76 +++++++++++--------
 drivers/crypto/intel/iaa/iaa_crypto_stats.c   | 30 ++++----
 2 files changed, 61 insertions(+), 45 deletions(-)
Documentation/driver-api/crypto/iaa/iaa-crypto.rst +44 -32
index de587cf9cbed..7b28aef39ba0 100644
@@ -321,33 +321,30 @@ driver will generate statistics which can be accessed in debugfs at::
 
   # ls -al /sys/kernel/debug/iaa-crypto/
   total 0
-  drwxr-xr-x  2 root root 0 Mar  3 09:35 .
-  drwx------ 47 root root 0 Mar  3 09:35 ..
-  -rw-r--r--  1 root root 0 Mar  3 09:35 max_acomp_delay_ns
-  -rw-r--r--  1 root root 0 Mar  3 09:35 max_adecomp_delay_ns
-  -rw-r--r--  1 root root 0 Mar  3 09:35 max_comp_delay_ns
-  -rw-r--r--  1 root root 0 Mar  3 09:35 max_decomp_delay_ns
-  -rw-r--r--  1 root root 0 Mar  3 09:35 stats_reset
-  -rw-r--r--  1 root root 0 Mar  3 09:35 total_comp_bytes_out
-  -rw-r--r--  1 root root 0 Mar  3 09:35 total_comp_calls
-  -rw-r--r--  1 root root 0 Mar  3 09:35 total_decomp_bytes_in
-  -rw-r--r--  1 root root 0 Mar  3 09:35 total_decomp_calls
-  -rw-r--r--  1 root root 0 Mar  3 09:35 wq_stats
-
-Most of the above statisticss are self-explanatory.  The wq_stats file
-shows per-wq stats, a set for each iaa device and wq in addition to
-some global stats::
+  drwxr-xr-x  2 root root 0 Mar  3 07:55 .
+  drwx------ 53 root root 0 Mar  3 07:55 ..
+  -rw-r--r--  1 root root 0 Mar  3 07:55 global_stats
+  -rw-r--r--  1 root root 0 Mar  3 07:55 stats_reset
+  -rw-r--r--  1 root root 0 Mar  3 07:55 wq_stats
 
-  # cat wq_stats
+The global_stats file shows a set of global statistics collected since
+the driver has been loaded or reset::
+
+  # cat global_stats
   global stats:
-    total_comp_calls: 100
-    total_decomp_calls: 100
-    total_comp_bytes_out: 22800
-    total_decomp_bytes_in: 22800
+    total_comp_calls: 4300
+    total_decomp_calls: 4164
+    total_sw_decomp_calls: 0
+    total_comp_bytes_out: 5993989
+    total_decomp_bytes_in: 5993989
     total_completion_einval_errors: 0
     total_completion_timeout_errors: 0
-    total_completion_comp_buf_overflow_errors: 0
+    total_completion_comp_buf_overflow_errors: 136
+
+The wq_stats file shows per-wq stats, a set for each iaa device and wq
+in addition to some global stats::
 
+  # cat wq_stats
   iaa device:
     id: 1
     n_wqs: 1
@@ -379,21 +376,36 @@ some global stats::
   iaa device:
     id: 5
     n_wqs: 1
-    comp_calls: 100
-    comp_bytes: 22800
-    decomp_calls: 100
-    decomp_bytes: 22800
+    comp_calls: 1360
+    comp_bytes: 1999776
+    decomp_calls: 0
+    decomp_bytes: 0
     wqs:
       name: iaa_crypto
-      comp_calls: 100
-      comp_bytes: 22800
-      decomp_calls: 100
-      decomp_bytes: 22800
+      comp_calls: 1360
+      comp_bytes: 1999776
+      decomp_calls: 0
+      decomp_bytes: 0
+
+  iaa device:
+    id: 7
+    n_wqs: 1
+    comp_calls: 2940
+    comp_bytes: 3994213
+    decomp_calls: 4164
+    decomp_bytes: 5993989
+    wqs:
+      name: iaa_crypto
+      comp_calls: 2940
+      comp_bytes: 3994213
+      decomp_calls: 4164
+      decomp_bytes: 5993989
+    ...
 
-Writing 0 to 'stats_reset' resets all the stats, including the
+Writing to 'stats_reset' resets all the stats, including the
 per-device and per-wq stats::
 
-  # echo 0 > stats_reset
+  # echo 1 > stats_reset
   # cat wq_stats
     global stats:
     total_comp_calls: 0
drivers/crypto/intel/iaa/iaa_crypto_stats.c +17 -13
index 7820062a91e5..0f225bdf2279 100644
@@ -159,7 +159,7 @@ static void device_stats_show(struct seq_file *m, struct iaa_device *iaa_device)
 		wq_show(m, iaa_wq);
 }
 
-static void global_stats_show(struct seq_file *m)
+static int global_stats_show(struct seq_file *m, void *v)
 {
 	seq_puts(m, "global stats:\n");
 	seq_printf(m, "  total_comp_calls: %llu\n", total_comp_calls);
@@ -173,6 +173,8 @@ static void global_stats_show(struct seq_file *m)
 		   total_completion_timeout_errors);
 	seq_printf(m, "  total_completion_comp_buf_overflow_errors: %llu\n\n",
 		   total_completion_comp_buf_overflow_errors);
+
+	return 0;
 }
 
 static int wq_stats_show(struct seq_file *m, void *v)
@@ -181,8 +183,6 @@ static int wq_stats_show(struct seq_file *m, void *v)
 
 	mutex_lock(&iaa_devices_lock);
 
-	global_stats_show(m);
-
 	list_for_each_entry(iaa_device, &iaa_devices, list)
 		device_stats_show(m, iaa_device);
 
@@ -219,6 +219,18 @@ static const struct file_operations wq_stats_fops = {
 	.release = single_release,
 };
 
+static int global_stats_open(struct inode *inode, struct file *file)
+{
+	return single_open(file, global_stats_show, file);
+}
+
+static const struct file_operations global_stats_fops = {
+	.open = global_stats_open,
+	.read = seq_read,
+	.llseek = seq_lseek,
+	.release = single_release,
+};
+
 DEFINE_DEBUGFS_ATTRIBUTE(wq_stats_reset_fops, NULL, iaa_crypto_stats_reset, "%llu\n");
 
 int __init iaa_crypto_debugfs_init(void)
@@ -228,16 +240,8 @@ int __init iaa_crypto_debugfs_init(void)
 
 	iaa_crypto_debugfs_root = debugfs_create_dir("iaa_crypto", NULL);
 
-	debugfs_create_u64("total_comp_calls", 0644,
-			   iaa_crypto_debugfs_root, &total_comp_calls);
-	debugfs_create_u64("total_decomp_calls", 0644,
-			   iaa_crypto_debugfs_root, &total_decomp_calls);
-	debugfs_create_u64("total_sw_decomp_calls", 0644,
-			   iaa_crypto_debugfs_root, &total_sw_decomp_calls);
-	debugfs_create_u64("total_comp_bytes_out", 0644,
-			   iaa_crypto_debugfs_root, &total_comp_bytes_out);
-	debugfs_create_u64("total_decomp_bytes_in", 0644,
-			   iaa_crypto_debugfs_root, &total_decomp_bytes_in);
+	debugfs_create_file("global_stats", 0644, iaa_crypto_debugfs_root, NULL,
+			    &global_stats_fops);
 	debugfs_create_file("wq_stats", 0644, iaa_crypto_debugfs_root, NULL,
 			    &wq_stats_fops);
 	debugfs_create_file("stats_reset", 0644, iaa_crypto_debugfs_root, NULL,
Signature · 1 line
2.34.1
#4 lore raw

PATCH 4/4 crypto: iaa - Change iaa statistics to atomic64_t

In reply to Tom Zanussi

Change all the iaa statistics to use atomic64_t instead of the current u64, to avoid potentially inconsistent counts.

---
 drivers/crypto/intel/iaa/iaa_crypto.h       |  16 +--
 drivers/crypto/intel/iaa/iaa_crypto_stats.c | 125 +++++++++++---------
 2 files changed, 77 insertions(+), 64 deletions(-)
drivers/crypto/intel/iaa/iaa_crypto.h +8 -8
index 2524091a5f70..56985e395263 100644
@@ -49,10 +49,10 @@ struct iaa_wq {
 
 	struct iaa_device	*iaa_device;
 
-	u64			comp_calls;
-	u64			comp_bytes;
-	u64			decomp_calls;
-	u64			decomp_bytes;
+	atomic64_t		comp_calls;
+	atomic64_t		comp_bytes;
+	atomic64_t		decomp_calls;
+	atomic64_t		decomp_bytes;
 };
 
 struct iaa_device_compression_mode {
@@ -73,10 +73,10 @@ struct iaa_device {
 	int				n_wq;
 	struct list_head		wqs;
 
-	u64				comp_calls;
-	u64				comp_bytes;
-	u64				decomp_calls;
-	u64				decomp_bytes;
+	atomic64_t			comp_calls;
+	atomic64_t			comp_bytes;
+	atomic64_t			decomp_calls;
+	atomic64_t			decomp_bytes;
 };
 
 struct wq_table_entry {
drivers/crypto/intel/iaa/iaa_crypto_stats.c +69 -56

223 lines not on this page · raw message

Signature · 1 line
2.34.1
maintainer
#5 lore raw
In reply to Tom Zanussi
Quoted 32 lines · Tom Zanussi

Hi Herbert,

While doing some testing, I noticed a discrepancy in the decomp_bytes_in stat, which the first patch in this series (crypto:
iaa - fix decomp_bytes_in stats) fixes.

I also realized that there were some other problems unrelated to that but also that the stats code could be simplified in a number of ways and that some of it wasn't really useful. The stats code is debugging code and has been helpful to quickly verify whether things are basically working, but since it's there we should make it as accurate and actually useful as possible.

I realize the second patch (crypto: iaa - Remove comp/decomp delay statistics) removes the code I just fixed up in a patch you just merged (crypto: iaa - Fix comp/decomp delay statistics) - let me know if you want me to combine those if you want to remove the latter from your branch...

Thanks,

Tom

*** BLURB HERE ***

Tom Zanussi (4):
crypto: iaa - fix decomp_bytes_in stats
crypto: iaa - Remove comp/decomp delay statistics
crypto: iaa - Add global_stats file and remove individual stat files
crypto: iaa - Change iaa statistics to atomic64_t

Quoted 9 lines
 .../driver-api/crypto/iaa/iaa-crypto.rst      |  76 +++++---
 drivers/crypto/intel/iaa/iaa_crypto.h         |  16 +-
 drivers/crypto/intel/iaa/iaa_crypto_main.c    |  13 +-
 drivers/crypto/intel/iaa/iaa_crypto_stats.c   | 183 ++++++++----------
 drivers/crypto/intel/iaa/iaa_crypto_stats.h   |   8 -
 5 files changed, 140 insertions(+), 156 deletions(-)
Signature · 1 line
2.34.1

All applied. Thanks.

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt