summaryrefslogtreecommitdiffstats
path: root/drivers/crypto/intel/iaa/iaa_crypto_stats.c
blob: 2e3b7b73af20444a2480078b51eee8a55c9ba268 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
// SPDX-License-Identifier: GPL-2.0
/* Copyright(c) 2021 Intel Corporation. All rights rsvd. */

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/highmem.h>
#include <linux/mm.h>
#include <linux/slab.h>
#include <linux/delay.h>
#include <linux/smp.h>
#include <uapi/linux/idxd.h>
#include <linux/idxd.h>
#include <linux/dmaengine.h>
#include "../../dma/idxd/idxd.h"
#include <linux/debugfs.h>
#include <crypto/internal/acompress.h>
#include "iaa_crypto.h"
#include "iaa_crypto_stats.h"

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 max_acomp_delay_ns;
static u64 max_adecomp_delay_ns;
static u64 total_comp_bytes_out;
static u64 total_decomp_bytes_in;
static u64 total_completion_einval_errors;
static u64 total_completion_timeout_errors;
static u64 total_completion_comp_buf_overflow_errors;

static struct dentry *iaa_crypto_debugfs_root;

void update_total_comp_calls(void)
{
	total_comp_calls++;
}

void update_total_comp_bytes_out(int n)
{
	total_comp_bytes_out += n;
}

void update_total_decomp_calls(void)
{
	total_decomp_calls++;
}

void update_total_sw_decomp_calls(void)
{
	total_sw_decomp_calls++;
}

void update_total_decomp_bytes_in(int n)
{
	total_decomp_bytes_in += n;
}

void update_completion_einval_errs(void)
{
	total_completion_einval_errors++;
}

void update_completion_timeout_errs(void)
{
	total_completion_timeout_errors++;
}

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_max_acomp_delay_ns(u64 start_time_ns)
{
	u64 time_diff;

	time_diff = ktime_get_ns() - start_time_ns;

	if (time_diff > max_acomp_delay_ns)
		max_acomp_delay_ns = time_diff;
}

void update_max_adecomp_delay_ns(u64 start_time_ns)
{
	u64 time_diff;

	time_diff = ktime_get_ns() - start_time_ns;

	if (time_diff > max_adecomp_delay_ns)
		max_adecomp_delay_ns = time_diff;
}

void update_wq_comp_calls(struct idxd_wq *idxd_wq)
{
	struct iaa_wq *wq = idxd_wq_get_private(idxd_wq);

	wq->comp_calls++;
	wq->iaa_device->comp_calls++;
}

void update_wq_comp_bytes(struct idxd_wq *idxd_wq, int n)
{
	struct iaa_wq *wq = idxd_wq_get_private(idxd_wq);

	wq->comp_bytes += n;
	wq->iaa_device->comp_bytes += n;
}

void update_wq_decomp_calls(struct idxd_wq *idxd_wq)
{
	struct iaa_wq *wq = idxd_wq_get_private(idxd_wq);

	wq->decomp_calls++;
	wq->iaa_device->decomp_calls++;
}

void update_wq_decomp_bytes(struct idxd_wq *idxd_wq, int n)
{
	struct iaa_wq *wq = idxd_wq_get_private(idxd_wq);

	wq->decomp_bytes += n;
	wq->iaa_device->decomp_bytes += n;
}

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;
	max_acomp_delay_ns = 0;
	max_adecomp_delay_ns = 0;
	total_comp_bytes_out = 0;
	total_decomp_bytes_in = 0;
	total_completion_einval_errors = 0;
	total_completion_timeout_errors = 0;
	total_completion_comp_buf_overflow_errors = 0;
}

static void reset_wq_stats(struct iaa_wq *wq)
{
	wq->comp_calls = 0;
	wq->comp_bytes = 0;
	wq->decomp_calls = 0;
	wq->decomp_bytes = 0;
}

static void reset_device_stats(struct iaa_device *iaa_device)
{
	struct iaa_wq *iaa_wq;

	iaa_device->comp_calls = 0;
	iaa_device->comp_bytes = 0;
	iaa_device->decomp_calls = 0;
	iaa_device->decomp_bytes = 0;

	list_for_each_entry(iaa_wq, &iaa_device->wqs, list)
		reset_wq_stats(iaa_wq);
}

static void wq_show(struct seq_file *m, struct iaa_wq *iaa_wq)
{
	seq_printf(m, "    name: %s\n", iaa_wq->wq->name);
	seq_printf(m, "    comp_calls: %llu\n", iaa_wq->comp_calls);
	seq_printf(m, "    comp_bytes: %llu\n", iaa_wq->comp_bytes);
	seq_printf(m, "    decomp_calls: %llu\n", iaa_wq->decomp_calls);
	seq_printf(m, "    decomp_bytes: %llu\n\n", iaa_wq->decomp_bytes);
}

static void device_stats_show(struct seq_file *m, struct iaa_device *iaa_device)
{
	struct iaa_wq *iaa_wq;

	seq_puts(m, "iaa device:\n");
	seq_printf(m, "  id: %d\n", iaa_device->idxd->id);
	seq_printf(m, "  n_wqs: %d\n", iaa_device->n_wq);
	seq_printf(m, "  comp_calls: %llu\n", iaa_device->comp_calls);
	seq_printf(m, "  comp_bytes: %llu\n", iaa_device->comp_bytes);
	seq_printf(m, "  decomp_calls: %llu\n", iaa_device->decomp_calls);
	seq_printf(m, "  decomp_bytes: %llu\n", iaa_device->decomp_bytes);
	seq_puts(m, "  wqs:\n");

	list_for_each_entry(iaa_wq, &iaa_device->wqs, list)
		wq_show(m, iaa_wq);
}

static void global_stats_show(struct seq_file *m)
{
	seq_puts(m, "global stats:\n");
	seq_printf(m, "  total_comp_calls: %llu\n", total_comp_calls);
	seq_printf(m, "  total_decomp_calls: %llu\n", total_decomp_calls);
	seq_printf(m, "  total_sw_decomp_calls: %llu\n", total_sw_decomp_calls);
	seq_printf(m, "  total_comp_bytes_out: %llu\n", total_comp_bytes_out);
	seq_printf(m, "  total_decomp_bytes_in: %llu\n", total_decomp_bytes_in);
	seq_printf(m, "  total_completion_einval_errors: %llu\n",
		   total_completion_einval_errors);
	seq_printf(m, "  total_completion_timeout_errors: %llu\n",
		   total_completion_timeout_errors);
	seq_printf(m, "  total_completion_comp_buf_overflow_errors: %llu\n\n",
		   total_completion_comp_buf_overflow_errors);
}

static int wq_stats_show(struct seq_file *m, void *v)
{
	struct iaa_device *iaa_device;

	mutex_lock(&iaa_devices_lock);

	global_stats_show(m);

	list_for_each_entry(iaa_device, &iaa_devices, list)
		device_stats_show(m, iaa_device);

	mutex_unlock(&iaa_devices_lock);

	return 0;
}

static int iaa_crypto_stats_reset(void *data, u64 value)
{
	struct iaa_device *iaa_device;

	reset_iaa_crypto_stats();

	mutex_lock(&iaa_devices_lock);

	list_for_each_entry(iaa_device, &iaa_devices, list)
		reset_device_stats(iaa_device);

	mutex_unlock(&iaa_devices_lock);

	return 0;
}

static int wq_stats_open(struct inode *inode, struct file *file)
{
	return single_open(file, wq_stats_show, file);
}

static const struct file_operations wq_stats_fops = {
	.open = wq_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)
{
	if (!debugfs_initialized())
		return -ENODEV;

	iaa_crypto_debugfs_root = debugfs_create_dir("iaa_crypto", NULL);
	if (!iaa_crypto_debugfs_root)
		return -ENOMEM;

	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("max_acomp_delay_ns", 0644,
			   iaa_crypto_debugfs_root, &max_comp_delay_ns);
	debugfs_create_u64("max_adecomp_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,
			   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("wq_stats", 0644, iaa_crypto_debugfs_root, NULL,
			    &wq_stats_fops);
	debugfs_create_file("stats_reset", 0644, iaa_crypto_debugfs_root, NULL,
			    &wq_stats_reset_fops);

	return 0;
}

void __exit iaa_crypto_debugfs_cleanup(void)
{
	debugfs_remove_recursive(iaa_crypto_debugfs_root);
}

MODULE_LICENSE("GPL");