11f1e2261SMartin Matuska /*
21f1e2261SMartin Matuska * CDDL HEADER START
31f1e2261SMartin Matuska *
41f1e2261SMartin Matuska * The contents of this file are subject to the terms of the
51f1e2261SMartin Matuska * Common Development and Distribution License (the "License").
61f1e2261SMartin Matuska * You may not use this file except in compliance with the License.
71f1e2261SMartin Matuska *
81f1e2261SMartin Matuska * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9271171e0SMartin Matuska * or https://opensource.org/licenses/CDDL-1.0.
101f1e2261SMartin Matuska * See the License for the specific language governing permissions
111f1e2261SMartin Matuska * and limitations under the License.
121f1e2261SMartin Matuska *
131f1e2261SMartin Matuska * When distributing Covered Code, include this CDDL HEADER in each
141f1e2261SMartin Matuska * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
151f1e2261SMartin Matuska * If applicable, add the following below this CDDL HEADER, with the
161f1e2261SMartin Matuska * fields enclosed by brackets "[]" replaced with your own identifying
171f1e2261SMartin Matuska * information: Portions Copyright [yyyy] [name of copyright owner]
181f1e2261SMartin Matuska *
191f1e2261SMartin Matuska * CDDL HEADER END
201f1e2261SMartin Matuska */
211f1e2261SMartin Matuska
221f1e2261SMartin Matuska /*
23271171e0SMartin Matuska * Copyright (c) 2021-2022 Tino Reichardt <milky-zfs@mcmilk.de>
241f1e2261SMartin Matuska */
251f1e2261SMartin Matuska
261f1e2261SMartin Matuska #include <sys/zio_checksum.h>
271f1e2261SMartin Matuska #include <sys/zfs_context.h>
281f1e2261SMartin Matuska #include <sys/zfs_chksum.h>
29*2a58b312SMartin Matuska #include <sys/zfs_impl.h>
301f1e2261SMartin Matuska
311f1e2261SMartin Matuska #include <sys/blake3.h>
32*2a58b312SMartin Matuska #include <sys/sha2.h>
331f1e2261SMartin Matuska
34271171e0SMartin Matuska /* limit benchmarking to max 256KiB, when EdonR is slower then this: */
35271171e0SMartin Matuska #define LIMIT_PERF_MBS 300
361f1e2261SMartin Matuska
371f1e2261SMartin Matuska typedef struct {
381f1e2261SMartin Matuska const char *name;
391f1e2261SMartin Matuska const char *impl;
401f1e2261SMartin Matuska uint64_t bs1k;
411f1e2261SMartin Matuska uint64_t bs4k;
421f1e2261SMartin Matuska uint64_t bs16k;
431f1e2261SMartin Matuska uint64_t bs64k;
441f1e2261SMartin Matuska uint64_t bs256k;
451f1e2261SMartin Matuska uint64_t bs1m;
461f1e2261SMartin Matuska uint64_t bs4m;
47271171e0SMartin Matuska uint64_t bs16m;
481f1e2261SMartin Matuska zio_cksum_salt_t salt;
491f1e2261SMartin Matuska zio_checksum_t *(func);
501f1e2261SMartin Matuska zio_checksum_tmpl_init_t *(init);
511f1e2261SMartin Matuska zio_checksum_tmpl_free_t *(free);
521f1e2261SMartin Matuska } chksum_stat_t;
531f1e2261SMartin Matuska
541f1e2261SMartin Matuska static chksum_stat_t *chksum_stat_data = 0;
55271171e0SMartin Matuska static int chksum_stat_cnt = 0;
56271171e0SMartin Matuska static kstat_t *chksum_kstat = NULL;
571f1e2261SMartin Matuska
581f1e2261SMartin Matuska /*
59*2a58b312SMartin Matuska * Sample output on i3-1005G1 System:
601f1e2261SMartin Matuska *
61*2a58b312SMartin Matuska * implementation 1k 4k 16k 64k 256k 1m 4m 16m
62*2a58b312SMartin Matuska * edonr-generic 1278 1625 1769 1776 1783 1778 1771 1767
63*2a58b312SMartin Matuska * skein-generic 548 594 613 623 621 623 621 486
64*2a58b312SMartin Matuska * sha256-generic 255 270 281 278 279 281 283 283
65*2a58b312SMartin Matuska * sha256-x64 288 310 316 317 318 317 317 316
66*2a58b312SMartin Matuska * sha256-ssse3 304 342 351 355 356 357 356 356
67*2a58b312SMartin Matuska * sha256-avx 311 348 359 362 362 363 363 362
68*2a58b312SMartin Matuska * sha256-avx2 330 378 389 395 395 395 395 395
69*2a58b312SMartin Matuska * sha256-shani 908 1127 1212 1230 1233 1234 1223 1230
70*2a58b312SMartin Matuska * sha512-generic 359 409 431 427 429 430 428 423
71*2a58b312SMartin Matuska * sha512-x64 420 473 490 496 497 497 496 495
72*2a58b312SMartin Matuska * sha512-avx 406 522 546 560 560 560 556 560
73*2a58b312SMartin Matuska * sha512-avx2 464 568 601 606 609 610 607 608
74*2a58b312SMartin Matuska * blake3-generic 330 327 324 323 324 320 323 322
75*2a58b312SMartin Matuska * blake3-sse2 424 1366 1449 1468 1458 1453 1395 1408
76*2a58b312SMartin Matuska * blake3-sse41 453 1554 1658 1703 1689 1669 1622 1630
77*2a58b312SMartin Matuska * blake3-avx2 452 2013 3225 3351 3356 3261 3076 3101
78*2a58b312SMartin Matuska * blake3-avx512 498 2869 5269 5926 5872 5643 5014 5005
791f1e2261SMartin Matuska */
801f1e2261SMartin Matuska static int
chksum_kstat_headers(char * buf,size_t size)81271171e0SMartin Matuska chksum_kstat_headers(char *buf, size_t size)
821f1e2261SMartin Matuska {
831f1e2261SMartin Matuska ssize_t off = 0;
841f1e2261SMartin Matuska
85dbd5678dSMartin Matuska off += kmem_scnprintf(buf + off, size, "%-23s", "implementation");
86dbd5678dSMartin Matuska off += kmem_scnprintf(buf + off, size - off, "%8s", "1k");
87dbd5678dSMartin Matuska off += kmem_scnprintf(buf + off, size - off, "%8s", "4k");
88dbd5678dSMartin Matuska off += kmem_scnprintf(buf + off, size - off, "%8s", "16k");
89dbd5678dSMartin Matuska off += kmem_scnprintf(buf + off, size - off, "%8s", "64k");
90dbd5678dSMartin Matuska off += kmem_scnprintf(buf + off, size - off, "%8s", "256k");
91dbd5678dSMartin Matuska off += kmem_scnprintf(buf + off, size - off, "%8s", "1m");
92dbd5678dSMartin Matuska off += kmem_scnprintf(buf + off, size - off, "%8s", "4m");
93dbd5678dSMartin Matuska (void) kmem_scnprintf(buf + off, size - off, "%8s\n", "16m");
941f1e2261SMartin Matuska
951f1e2261SMartin Matuska return (0);
961f1e2261SMartin Matuska }
971f1e2261SMartin Matuska
981f1e2261SMartin Matuska static int
chksum_kstat_data(char * buf,size_t size,void * data)99271171e0SMartin Matuska chksum_kstat_data(char *buf, size_t size, void *data)
1001f1e2261SMartin Matuska {
1011f1e2261SMartin Matuska chksum_stat_t *cs;
1021f1e2261SMartin Matuska ssize_t off = 0;
1031f1e2261SMartin Matuska char b[24];
1041f1e2261SMartin Matuska
1051f1e2261SMartin Matuska cs = (chksum_stat_t *)data;
106dbd5678dSMartin Matuska kmem_scnprintf(b, 23, "%s-%s", cs->name, cs->impl);
107dbd5678dSMartin Matuska off += kmem_scnprintf(buf + off, size - off, "%-23s", b);
108dbd5678dSMartin Matuska off += kmem_scnprintf(buf + off, size - off, "%8llu",
1091f1e2261SMartin Matuska (u_longlong_t)cs->bs1k);
110dbd5678dSMartin Matuska off += kmem_scnprintf(buf + off, size - off, "%8llu",
1111f1e2261SMartin Matuska (u_longlong_t)cs->bs4k);
112dbd5678dSMartin Matuska off += kmem_scnprintf(buf + off, size - off, "%8llu",
1131f1e2261SMartin Matuska (u_longlong_t)cs->bs16k);
114dbd5678dSMartin Matuska off += kmem_scnprintf(buf + off, size - off, "%8llu",
1151f1e2261SMartin Matuska (u_longlong_t)cs->bs64k);
116dbd5678dSMartin Matuska off += kmem_scnprintf(buf + off, size - off, "%8llu",
1171f1e2261SMartin Matuska (u_longlong_t)cs->bs256k);
118dbd5678dSMartin Matuska off += kmem_scnprintf(buf + off, size - off, "%8llu",
1191f1e2261SMartin Matuska (u_longlong_t)cs->bs1m);
120dbd5678dSMartin Matuska off += kmem_scnprintf(buf + off, size - off, "%8llu",
1211f1e2261SMartin Matuska (u_longlong_t)cs->bs4m);
122dbd5678dSMartin Matuska (void) kmem_scnprintf(buf + off, size - off, "%8llu\n",
123271171e0SMartin Matuska (u_longlong_t)cs->bs16m);
1241f1e2261SMartin Matuska
1251f1e2261SMartin Matuska return (0);
1261f1e2261SMartin Matuska }
1271f1e2261SMartin Matuska
1281f1e2261SMartin Matuska static void *
chksum_kstat_addr(kstat_t * ksp,loff_t n)129271171e0SMartin Matuska chksum_kstat_addr(kstat_t *ksp, loff_t n)
1301f1e2261SMartin Matuska {
1311f1e2261SMartin Matuska if (n < chksum_stat_cnt)
1321f1e2261SMartin Matuska ksp->ks_private = (void *)(chksum_stat_data + n);
1331f1e2261SMartin Matuska else
1341f1e2261SMartin Matuska ksp->ks_private = NULL;
1351f1e2261SMartin Matuska
1361f1e2261SMartin Matuska return (ksp->ks_private);
1371f1e2261SMartin Matuska }
1381f1e2261SMartin Matuska
1391f1e2261SMartin Matuska static void
chksum_run(chksum_stat_t * cs,abd_t * abd,void * ctx,int round,uint64_t * result)1401f1e2261SMartin Matuska chksum_run(chksum_stat_t *cs, abd_t *abd, void *ctx, int round,
1411f1e2261SMartin Matuska uint64_t *result)
1421f1e2261SMartin Matuska {
1431f1e2261SMartin Matuska hrtime_t start;
1441f1e2261SMartin Matuska uint64_t run_bw, run_time_ns, run_count = 0, size = 0;
1451f1e2261SMartin Matuska uint32_t l, loops = 0;
1461f1e2261SMartin Matuska zio_cksum_t zcp;
1471f1e2261SMartin Matuska
1481f1e2261SMartin Matuska switch (round) {
1491f1e2261SMartin Matuska case 1: /* 1k */
1501f1e2261SMartin Matuska size = 1<<10; loops = 128; break;
1511f1e2261SMartin Matuska case 2: /* 2k */
1521f1e2261SMartin Matuska size = 1<<12; loops = 64; break;
1531f1e2261SMartin Matuska case 3: /* 4k */
1541f1e2261SMartin Matuska size = 1<<14; loops = 32; break;
1551f1e2261SMartin Matuska case 4: /* 16k */
1561f1e2261SMartin Matuska size = 1<<16; loops = 16; break;
1571f1e2261SMartin Matuska case 5: /* 256k */
1581f1e2261SMartin Matuska size = 1<<18; loops = 8; break;
1591f1e2261SMartin Matuska case 6: /* 1m */
1601f1e2261SMartin Matuska size = 1<<20; loops = 4; break;
1611f1e2261SMartin Matuska case 7: /* 4m */
1621f1e2261SMartin Matuska size = 1<<22; loops = 1; break;
163271171e0SMartin Matuska case 8: /* 16m */
164271171e0SMartin Matuska size = 1<<24; loops = 1; break;
1651f1e2261SMartin Matuska }
1661f1e2261SMartin Matuska
1671f1e2261SMartin Matuska kpreempt_disable();
1681f1e2261SMartin Matuska start = gethrtime();
1691f1e2261SMartin Matuska do {
1701f1e2261SMartin Matuska for (l = 0; l < loops; l++, run_count++)
1711f1e2261SMartin Matuska cs->func(abd, size, ctx, &zcp);
1721f1e2261SMartin Matuska
1731f1e2261SMartin Matuska run_time_ns = gethrtime() - start;
1741f1e2261SMartin Matuska } while (run_time_ns < MSEC2NSEC(1));
1751f1e2261SMartin Matuska kpreempt_enable();
1761f1e2261SMartin Matuska
1771f1e2261SMartin Matuska run_bw = size * run_count * NANOSEC;
1781f1e2261SMartin Matuska run_bw /= run_time_ns; /* B/s */
1791f1e2261SMartin Matuska *result = run_bw/1024/1024; /* MiB/s */
1801f1e2261SMartin Matuska }
1811f1e2261SMartin Matuska
182271171e0SMartin Matuska #define LIMIT_INIT 0
183271171e0SMartin Matuska #define LIMIT_NEEDED 1
184271171e0SMartin Matuska #define LIMIT_NOLIMIT 2
185271171e0SMartin Matuska
1861f1e2261SMartin Matuska static void
chksum_benchit(chksum_stat_t * cs)1871f1e2261SMartin Matuska chksum_benchit(chksum_stat_t *cs)
1881f1e2261SMartin Matuska {
1891f1e2261SMartin Matuska abd_t *abd;
1901f1e2261SMartin Matuska void *ctx = 0;
1911f1e2261SMartin Matuska void *salt = &cs->salt.zcs_bytes;
192271171e0SMartin Matuska static int chksum_stat_limit = LIMIT_INIT;
1931f1e2261SMartin Matuska
1941f1e2261SMartin Matuska memset(salt, 0, sizeof (cs->salt.zcs_bytes));
195271171e0SMartin Matuska if (cs->init)
1961f1e2261SMartin Matuska ctx = cs->init(&cs->salt);
1971f1e2261SMartin Matuska
198271171e0SMartin Matuska /* allocate test memory via abd linear interface */
199271171e0SMartin Matuska abd = abd_alloc_linear(1<<20, B_FALSE);
2001f1e2261SMartin Matuska chksum_run(cs, abd, ctx, 1, &cs->bs1k);
2011f1e2261SMartin Matuska chksum_run(cs, abd, ctx, 2, &cs->bs4k);
2021f1e2261SMartin Matuska chksum_run(cs, abd, ctx, 3, &cs->bs16k);
2031f1e2261SMartin Matuska chksum_run(cs, abd, ctx, 4, &cs->bs64k);
2041f1e2261SMartin Matuska chksum_run(cs, abd, ctx, 5, &cs->bs256k);
205271171e0SMartin Matuska
206271171e0SMartin Matuska /* check if we ran on a slow cpu */
207271171e0SMartin Matuska if (chksum_stat_limit == LIMIT_INIT) {
208271171e0SMartin Matuska if (cs->bs1k < LIMIT_PERF_MBS) {
209271171e0SMartin Matuska chksum_stat_limit = LIMIT_NEEDED;
210271171e0SMartin Matuska } else {
211271171e0SMartin Matuska chksum_stat_limit = LIMIT_NOLIMIT;
212271171e0SMartin Matuska }
213271171e0SMartin Matuska }
214271171e0SMartin Matuska
215271171e0SMartin Matuska /* skip benchmarks >= 1MiB when the CPU is to slow */
216271171e0SMartin Matuska if (chksum_stat_limit == LIMIT_NEEDED)
217271171e0SMartin Matuska goto abort;
218271171e0SMartin Matuska
2191f1e2261SMartin Matuska chksum_run(cs, abd, ctx, 6, &cs->bs1m);
220271171e0SMartin Matuska abd_free(abd);
221271171e0SMartin Matuska
222271171e0SMartin Matuska /* allocate test memory via abd non linear interface */
223271171e0SMartin Matuska abd = abd_alloc(1<<24, B_FALSE);
2241f1e2261SMartin Matuska chksum_run(cs, abd, ctx, 7, &cs->bs4m);
225271171e0SMartin Matuska chksum_run(cs, abd, ctx, 8, &cs->bs16m);
226271171e0SMartin Matuska
227271171e0SMartin Matuska abort:
228271171e0SMartin Matuska abd_free(abd);
2291f1e2261SMartin Matuska
2301f1e2261SMartin Matuska /* free up temp memory */
231271171e0SMartin Matuska if (cs->free)
2321f1e2261SMartin Matuska cs->free(ctx);
2331f1e2261SMartin Matuska }
2341f1e2261SMartin Matuska
2351f1e2261SMartin Matuska /*
2361f1e2261SMartin Matuska * Initialize and benchmark all supported implementations.
2371f1e2261SMartin Matuska */
2381f1e2261SMartin Matuska static void
chksum_benchmark(void)2391f1e2261SMartin Matuska chksum_benchmark(void)
2401f1e2261SMartin Matuska {
2411f1e2261SMartin Matuska #ifndef _KERNEL
2421f1e2261SMartin Matuska /* we need the benchmark only for the kernel module */
2431f1e2261SMartin Matuska return;
2441f1e2261SMartin Matuska #endif
2451f1e2261SMartin Matuska
2461f1e2261SMartin Matuska chksum_stat_t *cs;
247*2a58b312SMartin Matuska uint64_t max;
248*2a58b312SMartin Matuska uint32_t id, cbid = 0, id_save;
249*2a58b312SMartin Matuska const zfs_impl_t *blake3 = zfs_impl_get_ops("blake3");
250*2a58b312SMartin Matuska const zfs_impl_t *sha256 = zfs_impl_get_ops("sha256");
251*2a58b312SMartin Matuska const zfs_impl_t *sha512 = zfs_impl_get_ops("sha512");
2521f1e2261SMartin Matuska
253*2a58b312SMartin Matuska /* count implementations */
254*2a58b312SMartin Matuska chksum_stat_cnt = 2;
255*2a58b312SMartin Matuska chksum_stat_cnt += sha256->getcnt();
256*2a58b312SMartin Matuska chksum_stat_cnt += sha512->getcnt();
257*2a58b312SMartin Matuska chksum_stat_cnt += blake3->getcnt();
25815f0b8c3SMartin Matuska chksum_stat_data = kmem_zalloc(
2591f1e2261SMartin Matuska sizeof (chksum_stat_t) * chksum_stat_cnt, KM_SLEEP);
2601f1e2261SMartin Matuska
261271171e0SMartin Matuska /* edonr - needs to be the first one here (slow CPU check) */
2621f1e2261SMartin Matuska cs = &chksum_stat_data[cbid++];
263*2a58b312SMartin Matuska
264*2a58b312SMartin Matuska /* edonr */
2651f1e2261SMartin Matuska cs->init = abd_checksum_edonr_tmpl_init;
2661f1e2261SMartin Matuska cs->func = abd_checksum_edonr_native;
2671f1e2261SMartin Matuska cs->free = abd_checksum_edonr_tmpl_free;
2681f1e2261SMartin Matuska cs->name = "edonr";
2691f1e2261SMartin Matuska cs->impl = "generic";
2701f1e2261SMartin Matuska chksum_benchit(cs);
2711f1e2261SMartin Matuska
2721f1e2261SMartin Matuska /* skein */
2731f1e2261SMartin Matuska cs = &chksum_stat_data[cbid++];
2741f1e2261SMartin Matuska cs->init = abd_checksum_skein_tmpl_init;
2751f1e2261SMartin Matuska cs->func = abd_checksum_skein_native;
2761f1e2261SMartin Matuska cs->free = abd_checksum_skein_tmpl_free;
2771f1e2261SMartin Matuska cs->name = "skein";
2781f1e2261SMartin Matuska cs->impl = "generic";
2791f1e2261SMartin Matuska chksum_benchit(cs);
2801f1e2261SMartin Matuska
2811f1e2261SMartin Matuska /* sha256 */
282*2a58b312SMartin Matuska id_save = sha256->getid();
283*2a58b312SMartin Matuska for (max = 0, id = 0; id < sha256->getcnt(); id++) {
284*2a58b312SMartin Matuska sha256->setid(id);
2851f1e2261SMartin Matuska cs = &chksum_stat_data[cbid++];
2861f1e2261SMartin Matuska cs->init = 0;
287*2a58b312SMartin Matuska cs->func = abd_checksum_sha256;
2881f1e2261SMartin Matuska cs->free = 0;
289*2a58b312SMartin Matuska cs->name = sha256->name;
290*2a58b312SMartin Matuska cs->impl = sha256->getname();
2911f1e2261SMartin Matuska chksum_benchit(cs);
292*2a58b312SMartin Matuska if (cs->bs256k > max) {
293*2a58b312SMartin Matuska max = cs->bs256k;
294*2a58b312SMartin Matuska sha256->set_fastest(id);
295*2a58b312SMartin Matuska }
296*2a58b312SMartin Matuska }
297*2a58b312SMartin Matuska sha256->setid(id_save);
2981f1e2261SMartin Matuska
2991f1e2261SMartin Matuska /* sha512 */
300*2a58b312SMartin Matuska id_save = sha512->getid();
301*2a58b312SMartin Matuska for (max = 0, id = 0; id < sha512->getcnt(); id++) {
302*2a58b312SMartin Matuska sha512->setid(id);
3031f1e2261SMartin Matuska cs = &chksum_stat_data[cbid++];
3041f1e2261SMartin Matuska cs->init = 0;
305*2a58b312SMartin Matuska cs->func = abd_checksum_sha512_native;
3061f1e2261SMartin Matuska cs->free = 0;
307*2a58b312SMartin Matuska cs->name = sha512->name;
308*2a58b312SMartin Matuska cs->impl = sha512->getname();
3091f1e2261SMartin Matuska chksum_benchit(cs);
310*2a58b312SMartin Matuska if (cs->bs256k > max) {
311*2a58b312SMartin Matuska max = cs->bs256k;
312*2a58b312SMartin Matuska sha512->set_fastest(id);
313*2a58b312SMartin Matuska }
314*2a58b312SMartin Matuska }
315*2a58b312SMartin Matuska sha512->setid(id_save);
3161f1e2261SMartin Matuska
3171f1e2261SMartin Matuska /* blake3 */
318*2a58b312SMartin Matuska id_save = blake3->getid();
319*2a58b312SMartin Matuska for (max = 0, id = 0; id < blake3->getcnt(); id++) {
320*2a58b312SMartin Matuska blake3->setid(id);
3211f1e2261SMartin Matuska cs = &chksum_stat_data[cbid++];
3221f1e2261SMartin Matuska cs->init = abd_checksum_blake3_tmpl_init;
3231f1e2261SMartin Matuska cs->func = abd_checksum_blake3_native;
3241f1e2261SMartin Matuska cs->free = abd_checksum_blake3_tmpl_free;
325*2a58b312SMartin Matuska cs->name = blake3->name;
326*2a58b312SMartin Matuska cs->impl = blake3->getname();
3271f1e2261SMartin Matuska chksum_benchit(cs);
3281f1e2261SMartin Matuska if (cs->bs256k > max) {
3291f1e2261SMartin Matuska max = cs->bs256k;
330*2a58b312SMartin Matuska blake3->set_fastest(id);
3311f1e2261SMartin Matuska }
3321f1e2261SMartin Matuska }
333*2a58b312SMartin Matuska blake3->setid(id_save);
3341f1e2261SMartin Matuska }
3351f1e2261SMartin Matuska
3361f1e2261SMartin Matuska void
chksum_init(void)3371f1e2261SMartin Matuska chksum_init(void)
3381f1e2261SMartin Matuska {
3391f1e2261SMartin Matuska #ifdef _KERNEL
3401f1e2261SMartin Matuska blake3_per_cpu_ctx_init();
3411f1e2261SMartin Matuska #endif
3421f1e2261SMartin Matuska
3431f1e2261SMartin Matuska /* Benchmark supported implementations */
3441f1e2261SMartin Matuska chksum_benchmark();
3451f1e2261SMartin Matuska
3461f1e2261SMartin Matuska /* Install kstats for all implementations */
3471f1e2261SMartin Matuska chksum_kstat = kstat_create("zfs", 0, "chksum_bench", "misc",
3481f1e2261SMartin Matuska KSTAT_TYPE_RAW, 0, KSTAT_FLAG_VIRTUAL);
3491f1e2261SMartin Matuska
3501f1e2261SMartin Matuska if (chksum_kstat != NULL) {
3511f1e2261SMartin Matuska chksum_kstat->ks_data = NULL;
3521f1e2261SMartin Matuska chksum_kstat->ks_ndata = UINT32_MAX;
3531f1e2261SMartin Matuska kstat_set_raw_ops(chksum_kstat,
354271171e0SMartin Matuska chksum_kstat_headers,
355271171e0SMartin Matuska chksum_kstat_data,
356271171e0SMartin Matuska chksum_kstat_addr);
3571f1e2261SMartin Matuska kstat_install(chksum_kstat);
3581f1e2261SMartin Matuska }
3591f1e2261SMartin Matuska }
3601f1e2261SMartin Matuska
3611f1e2261SMartin Matuska void
chksum_fini(void)3621f1e2261SMartin Matuska chksum_fini(void)
3631f1e2261SMartin Matuska {
3641f1e2261SMartin Matuska if (chksum_kstat != NULL) {
3651f1e2261SMartin Matuska kstat_delete(chksum_kstat);
3661f1e2261SMartin Matuska chksum_kstat = NULL;
3671f1e2261SMartin Matuska }
3681f1e2261SMartin Matuska
3691f1e2261SMartin Matuska if (chksum_stat_cnt) {
3701f1e2261SMartin Matuska kmem_free(chksum_stat_data,
3711f1e2261SMartin Matuska sizeof (chksum_stat_t) * chksum_stat_cnt);
3721f1e2261SMartin Matuska chksum_stat_cnt = 0;
3731f1e2261SMartin Matuska chksum_stat_data = 0;
3741f1e2261SMartin Matuska }
3751f1e2261SMartin Matuska
3761f1e2261SMartin Matuska #ifdef _KERNEL
3771f1e2261SMartin Matuska blake3_per_cpu_ctx_fini();
3781f1e2261SMartin Matuska #endif
3791f1e2261SMartin Matuska }
380