]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tools/tools/crypto/cryptostats.c
config: Fix a few mandoc related errors
[FreeBSD/FreeBSD.git] / tools / tools / crypto / cryptostats.c
1 /*-
2  * Copyright (c) 2002, 2003     Sam Leffler, Errno Consulting
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  * $FreeBSD$
27  */
28
29 /*
30  * Little program to dump the crypto statistics block and, optionally,
31  * zero all the stats or just the timing stuff.
32  */
33
34 #include <sys/types.h>
35 #include <sys/sysctl.h>
36 #include <sys/time.h>
37
38 #include <crypto/cryptodev.h>
39
40 #include <err.h>
41 #include <stdio.h>
42 #include <stdlib.h>
43 #include <string.h>
44 #include <strings.h>
45
46 static void
47 printt(const char* tag, struct cryptotstat *ts)
48 {
49         uint64_t avg, min, max;
50
51         if (ts->count == 0)
52                 return;
53         avg = (1000000000LL*ts->acc.tv_sec + ts->acc.tv_nsec) / ts->count;
54         min = 1000000000LL*ts->min.tv_sec + ts->min.tv_nsec;
55         max = 1000000000LL*ts->max.tv_sec + ts->max.tv_nsec;
56         printf("%16.16s: avg %6llu ns : min %6llu ns : max %7llu ns [%u samps]\n",
57                 tag, avg, min, max, ts->count);
58 }
59
60 int
61 main(int argc, char *argv[])
62 {
63         struct cryptostats stats;
64         size_t slen;
65
66         slen = sizeof (stats);
67         if (sysctlbyname("kern.crypto_stats", &stats, &slen, NULL, 0) < 0)
68                 err(1, "kern.cryptostats");
69
70         if (argc > 1 && strcmp(argv[1], "-z") == 0) {
71                 bzero(&stats.cs_invoke, sizeof (stats.cs_invoke));
72                 bzero(&stats.cs_done, sizeof (stats.cs_done));
73                 bzero(&stats.cs_cb, sizeof (stats.cs_cb));
74                 bzero(&stats.cs_finis, sizeof (stats.cs_finis));
75                 stats.cs_invoke.min.tv_sec = 10000;
76                 stats.cs_done.min.tv_sec = 10000;
77                 stats.cs_cb.min.tv_sec = 10000;
78                 stats.cs_finis.min.tv_sec = 10000;
79                 if (sysctlbyname("kern.crypto_stats", NULL, NULL, &stats, sizeof (stats)) < 0)
80                         err(1, "kern.cryptostats");
81                 exit(0);
82         }
83         if (argc > 1 && strcmp(argv[1], "-Z") == 0) {
84                 bzero(&stats, sizeof (stats));
85                 stats.cs_invoke.min.tv_sec = 10000;
86                 stats.cs_done.min.tv_sec = 10000;
87                 stats.cs_cb.min.tv_sec = 10000;
88                 stats.cs_finis.min.tv_sec = 10000;
89                 if (sysctlbyname("kern.crypto_stats", NULL, NULL, &stats, sizeof (stats)) < 0)
90                         err(1, "kern.cryptostats");
91                 exit(0);
92         }
93
94
95         printf("%u symmetric crypto ops (%u errors, %u times driver blocked)\n"
96                 , stats.cs_ops, stats.cs_errs, stats.cs_blocks);
97         printf("%u key ops (%u errors, %u times driver blocked)\n"
98                 , stats.cs_kops, stats.cs_kerrs, stats.cs_kblocks);
99         printf("%u crypto dispatch thread activations\n", stats.cs_intrs);
100         printf("%u crypto return thread activations\n", stats.cs_rets);
101         if (stats.cs_invoke.count) {
102                 printf("\n");
103                 printt("dispatch->invoke", &stats.cs_invoke);
104                 printt("invoke->done", &stats.cs_done);
105                 printt("done->cb", &stats.cs_cb);
106                 printt("cb->finis", &stats.cs_finis);
107         }
108         return 0;
109 }