Skip to content

Commit 09ae5d3

Browse files
Mahipal Challaherbertx
authored andcommitted
crypto: zip - Add Compression/Decompression statistics
Add statistics for compression/decompression hardware offload under debugfs. Signed-off-by: Mahipal Challa <[email protected]> Signed-off-by: Jan Glauber <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent f05845f commit 09ae5d3

File tree

4 files changed

+271
-0
lines changed

4 files changed

+271
-0
lines changed

drivers/crypto/cavium/zip/zip_deflate.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,19 @@ int zip_deflate(struct zip_operation *zip_ops, struct zip_state *s,
122122
/* Prepares zip command based on the input parameters */
123123
prepare_zip_command(zip_ops, s, zip_cmd);
124124

125+
atomic64_add(zip_ops->input_len, &zip_dev->stats.comp_in_bytes);
125126
/* Loads zip command into command queues and rings door bell */
126127
queue = zip_load_instr(zip_cmd, zip_dev);
127128

129+
/* Stats update for compression requests submitted */
130+
atomic64_inc(&zip_dev->stats.comp_req_submit);
131+
128132
while (!result_ptr->s.compcode)
129133
continue;
130134

135+
/* Stats update for compression requests completed */
136+
atomic64_inc(&zip_dev->stats.comp_req_complete);
137+
131138
zip_ops->compcode = result_ptr->s.compcode;
132139
switch (zip_ops->compcode) {
133140
case ZIP_CMD_NOTDONE:
@@ -175,6 +182,9 @@ int zip_deflate(struct zip_operation *zip_ops, struct zip_state *s,
175182
zip_err("Unknown Format:%d\n", zip_ops->format);
176183
}
177184

185+
atomic64_add(result_ptr->s.totalbyteswritten,
186+
&zip_dev->stats.comp_out_bytes);
187+
178188
/* Update output_len */
179189
if (zip_ops->output_len < result_ptr->s.totalbyteswritten) {
180190
/* Dynamic stop && strm->output_len < zipconstants[onfsize] */

drivers/crypto/cavium/zip/zip_inflate.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,20 @@ int zip_inflate(struct zip_operation *zip_ops, struct zip_state *s,
135135
/* Prepare inflate zip command */
136136
prepare_inflate_zcmd(zip_ops, s, zip_cmd);
137137

138+
atomic64_add(zip_ops->input_len, &zip_dev->stats.decomp_in_bytes);
139+
138140
/* Load inflate command to zip queue and ring the doorbell */
139141
queue = zip_load_instr(zip_cmd, zip_dev);
140142

143+
/* Decompression requests submitted stats update */
144+
atomic64_inc(&zip_dev->stats.decomp_req_submit);
145+
141146
while (!result_ptr->s.compcode)
142147
continue;
143148

149+
/* Decompression requests completed stats update */
150+
atomic64_inc(&zip_dev->stats.decomp_req_complete);
151+
144152
zip_ops->compcode = result_ptr->s.compcode;
145153
switch (zip_ops->compcode) {
146154
case ZIP_CMD_NOTDONE:
@@ -157,6 +165,7 @@ int zip_inflate(struct zip_operation *zip_ops, struct zip_state *s,
157165

158166
default:
159167
zip_dbg("Instruction failed. Code = %d\n", zip_ops->compcode);
168+
atomic64_inc(&zip_dev->stats.decomp_bad_reqs);
160169
zip_update_cmd_bufs(zip_dev, queue);
161170
return ZIP_ERROR;
162171
}
@@ -169,6 +178,9 @@ int zip_inflate(struct zip_operation *zip_ops, struct zip_state *s,
169178

170179
zip_ops->csum = result_ptr->s.adler32;
171180

181+
atomic64_add(result_ptr->s.totalbyteswritten,
182+
&zip_dev->stats.decomp_out_bytes);
183+
172184
if (zip_ops->output_len < result_ptr->s.totalbyteswritten) {
173185
zip_err("output_len (%d) < total bytes written (%d)\n",
174186
zip_ops->output_len, result_ptr->s.totalbyteswritten);

drivers/crypto/cavium/zip/zip_main.c

Lines changed: 234 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,228 @@ static void zip_unregister_compression_device(void)
451451
crypto_unregister_scomp(&zip_scomp_lzs);
452452
}
453453

454+
/*
455+
* debugfs functions
456+
*/
457+
#ifdef CONFIG_DEBUG_FS
458+
#include <linux/debugfs.h>
459+
460+
/* Displays ZIP device statistics */
461+
static int zip_show_stats(struct seq_file *s, void *unused)
462+
{
463+
u64 val = 0ull;
464+
u64 avg_chunk = 0ull, avg_cr = 0ull;
465+
u32 q = 0;
466+
467+
int index = 0;
468+
struct zip_device *zip;
469+
struct zip_stats *st;
470+
471+
for (index = 0; index < MAX_ZIP_DEVICES; index++) {
472+
if (zip_dev[index]) {
473+
zip = zip_dev[index];
474+
st = &zip->stats;
475+
476+
/* Get all the pending requests */
477+
for (q = 0; q < ZIP_NUM_QUEUES; q++) {
478+
val = zip_reg_read((zip->reg_base +
479+
ZIP_DBG_COREX_STA(q)));
480+
val = (val >> 32);
481+
val = val & 0xffffff;
482+
atomic64_add(val, &st->pending_req);
483+
}
484+
485+
avg_chunk = (atomic64_read(&st->comp_in_bytes) /
486+
atomic64_read(&st->comp_req_complete));
487+
avg_cr = (atomic64_read(&st->comp_in_bytes) /
488+
atomic64_read(&st->comp_out_bytes));
489+
seq_printf(s, " ZIP Device %d Stats\n"
490+
"-----------------------------------\n"
491+
"Comp Req Submitted : \t%ld\n"
492+
"Comp Req Completed : \t%ld\n"
493+
"Compress In Bytes : \t%ld\n"
494+
"Compressed Out Bytes : \t%ld\n"
495+
"Average Chunk size : \t%llu\n"
496+
"Average Compression ratio : \t%llu\n"
497+
"Decomp Req Submitted : \t%ld\n"
498+
"Decomp Req Completed : \t%ld\n"
499+
"Decompress In Bytes : \t%ld\n"
500+
"Decompressed Out Bytes : \t%ld\n"
501+
"Decompress Bad requests : \t%ld\n"
502+
"Pending Req : \t%ld\n"
503+
"---------------------------------\n",
504+
index,
505+
atomic64_read(&st->comp_req_submit),
506+
atomic64_read(&st->comp_req_complete),
507+
atomic64_read(&st->comp_in_bytes),
508+
atomic64_read(&st->comp_out_bytes),
509+
avg_chunk,
510+
avg_cr,
511+
atomic64_read(&st->decomp_req_submit),
512+
atomic64_read(&st->decomp_req_complete),
513+
atomic64_read(&st->decomp_in_bytes),
514+
atomic64_read(&st->decomp_out_bytes),
515+
atomic64_read(&st->decomp_bad_reqs),
516+
atomic64_read(&st->pending_req));
517+
518+
/* Reset pending requests count */
519+
atomic64_set(&st->pending_req, 0);
520+
}
521+
}
522+
return 0;
523+
}
524+
525+
/* Clears stats data */
526+
static int zip_clear_stats(struct seq_file *s, void *unused)
527+
{
528+
int index = 0;
529+
530+
for (index = 0; index < MAX_ZIP_DEVICES; index++) {
531+
if (zip_dev[index]) {
532+
memset(&zip_dev[index]->stats, 0,
533+
sizeof(struct zip_state));
534+
seq_printf(s, "Cleared stats for zip %d\n", index);
535+
}
536+
}
537+
538+
return 0;
539+
}
540+
541+
static struct zip_registers zipregs[64] = {
542+
{"ZIP_CMD_CTL ", 0x0000ull},
543+
{"ZIP_THROTTLE ", 0x0010ull},
544+
{"ZIP_CONSTANTS ", 0x00A0ull},
545+
{"ZIP_QUE0_MAP ", 0x1400ull},
546+
{"ZIP_QUE1_MAP ", 0x1408ull},
547+
{"ZIP_QUE_ENA ", 0x0500ull},
548+
{"ZIP_QUE_PRI ", 0x0508ull},
549+
{"ZIP_QUE0_DONE ", 0x2000ull},
550+
{"ZIP_QUE1_DONE ", 0x2008ull},
551+
{"ZIP_QUE0_DOORBELL ", 0x4000ull},
552+
{"ZIP_QUE1_DOORBELL ", 0x4008ull},
553+
{"ZIP_QUE0_SBUF_ADDR ", 0x1000ull},
554+
{"ZIP_QUE1_SBUF_ADDR ", 0x1008ull},
555+
{"ZIP_QUE0_SBUF_CTL ", 0x1200ull},
556+
{"ZIP_QUE1_SBUF_CTL ", 0x1208ull},
557+
{ NULL, 0}
558+
};
559+
560+
/* Prints registers' contents */
561+
static int zip_print_regs(struct seq_file *s, void *unused)
562+
{
563+
u64 val = 0;
564+
int i = 0, index = 0;
565+
566+
for (index = 0; index < MAX_ZIP_DEVICES; index++) {
567+
if (zip_dev[index]) {
568+
seq_printf(s, "--------------------------------\n"
569+
" ZIP Device %d Registers\n"
570+
"--------------------------------\n",
571+
index);
572+
573+
i = 0;
574+
575+
while (zipregs[i].reg_name) {
576+
val = zip_reg_read((zip_dev[index]->reg_base +
577+
zipregs[i].reg_offset));
578+
seq_printf(s, "%s: 0x%016llx\n",
579+
zipregs[i].reg_name, val);
580+
i++;
581+
}
582+
}
583+
}
584+
return 0;
585+
}
586+
587+
static int zip_stats_open(struct inode *inode, struct file *file)
588+
{
589+
return single_open(file, zip_show_stats, NULL);
590+
}
591+
592+
static const struct file_operations zip_stats_fops = {
593+
.owner = THIS_MODULE,
594+
.open = zip_stats_open,
595+
.read = seq_read,
596+
};
597+
598+
static int zip_clear_open(struct inode *inode, struct file *file)
599+
{
600+
return single_open(file, zip_clear_stats, NULL);
601+
}
602+
603+
static const struct file_operations zip_clear_fops = {
604+
.owner = THIS_MODULE,
605+
.open = zip_clear_open,
606+
.read = seq_read,
607+
};
608+
609+
static int zip_regs_open(struct inode *inode, struct file *file)
610+
{
611+
return single_open(file, zip_print_regs, NULL);
612+
}
613+
614+
static const struct file_operations zip_regs_fops = {
615+
.owner = THIS_MODULE,
616+
.open = zip_regs_open,
617+
.read = seq_read,
618+
};
619+
620+
/* Root directory for thunderx_zip debugfs entry */
621+
static struct dentry *zip_debugfs_root;
622+
623+
static int __init zip_debugfs_init(void)
624+
{
625+
struct dentry *zip_stats, *zip_clear, *zip_regs;
626+
627+
if (!debugfs_initialized())
628+
return -ENODEV;
629+
630+
zip_debugfs_root = debugfs_create_dir("thunderx_zip", NULL);
631+
if (!zip_debugfs_root)
632+
return -ENOMEM;
633+
634+
/* Creating files for entries inside thunderx_zip directory */
635+
zip_stats = debugfs_create_file("zip_stats", 0444,
636+
zip_debugfs_root,
637+
NULL, &zip_stats_fops);
638+
if (!zip_stats)
639+
goto failed_to_create;
640+
641+
zip_clear = debugfs_create_file("zip_clear", 0444,
642+
zip_debugfs_root,
643+
NULL, &zip_clear_fops);
644+
if (!zip_clear)
645+
goto failed_to_create;
646+
647+
zip_regs = debugfs_create_file("zip_regs", 0444,
648+
zip_debugfs_root,
649+
NULL, &zip_regs_fops);
650+
if (!zip_regs)
651+
goto failed_to_create;
652+
653+
return 0;
654+
655+
failed_to_create:
656+
debugfs_remove_recursive(zip_debugfs_root);
657+
return -ENOENT;
658+
}
659+
660+
static void __exit zip_debugfs_exit(void)
661+
{
662+
debugfs_remove_recursive(zip_debugfs_root);
663+
}
664+
665+
#else
666+
static int __init zip_debugfs_init(void)
667+
{
668+
return 0;
669+
}
670+
671+
static void __exit zip_debugfs_exit(void) { }
672+
673+
#endif
674+
/* debugfs - end */
675+
454676
static int __init zip_init_module(void)
455677
{
456678
int ret;
@@ -470,15 +692,27 @@ static int __init zip_init_module(void)
470692
goto err_pci_unregister;
471693
}
472694

695+
/* comp-decomp statistics are handled with debugfs interface */
696+
ret = zip_debugfs_init();
697+
if (ret < 0) {
698+
zip_err("ZIP: debugfs initialization failed\n");
699+
goto err_crypto_unregister;
700+
}
701+
473702
return ret;
474703

704+
err_crypto_unregister:
705+
zip_unregister_compression_device();
706+
475707
err_pci_unregister:
476708
pci_unregister_driver(&zip_driver);
477709
return ret;
478710
}
479711

480712
static void __exit zip_cleanup_module(void)
481713
{
714+
zip_debugfs_exit();
715+
482716
/* Unregister from the kernel crypto interface */
483717
zip_unregister_compression_device();
484718

drivers/crypto/cavium/zip/zip_main.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,20 @@ struct zip_registers {
6868
u64 reg_offset;
6969
};
7070

71+
/* ZIP Compression - Decompression stats */
72+
struct zip_stats {
73+
atomic64_t comp_req_submit;
74+
atomic64_t comp_req_complete;
75+
atomic64_t decomp_req_submit;
76+
atomic64_t decomp_req_complete;
77+
atomic64_t pending_req;
78+
atomic64_t comp_in_bytes;
79+
atomic64_t comp_out_bytes;
80+
atomic64_t decomp_in_bytes;
81+
atomic64_t decomp_out_bytes;
82+
atomic64_t decomp_bad_reqs;
83+
};
84+
7185
/* ZIP Instruction Queue */
7286
struct zip_iq {
7387
u64 *sw_head;
@@ -93,6 +107,7 @@ struct zip_device {
93107
u64 ctxsize;
94108

95109
struct zip_iq iq[ZIP_MAX_NUM_QUEUES];
110+
struct zip_stats stats;
96111
};
97112

98113
/* Prototypes */

0 commit comments

Comments
 (0)