4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <sys/mdb_modapi.h>
30 #include <mdb/mdb_ctf.h>
31 #include <sys/random.h>
34 * rnd_stats dcmd - Print out the global rnd_stats structure, nicely formatted.
38 rnd_get_stats(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
40 rnd_stats_t rnd_stats
, rnd_stats_cpu
;
41 uint32_t random_max_ncpus
;
43 ulong_t rndmag_t_offset
;
45 mdb_ctf_id_t rndmag_id
;
48 if ((flags
& DCMD_ADDRSPEC
) || argc
!= 0)
51 if (mdb_readvar(&rnd_stats
, "rnd_stats") == -1) {
52 mdb_warn("failed to read rnd_stats structure");
56 if ((mdb_ctf_lookup_by_name("rndmag_t", &rndmag_id
) != 0) ||
57 (mdb_ctf_offsetof(rndmag_id
, "rm_stats", &rndmag_t_offset
) != 0) ||
58 (mdb_readvar(&random_max_ncpus
, "random_max_ncpus") == -1) ||
59 (mdb_readvar(&rndmag
, "rndmag") == -1) ||
60 ((rndmag_t_size
= mdb_ctf_type_size(rndmag_id
)) == 0)) {
61 /* Can't find per-cpu stats. Don't add them in. */
68 * Read and aggregate per-cpu stats if we have them.
70 for (i
= 0; i
< random_max_ncpus
; i
++) {
71 mdb_vread(&rnd_stats_cpu
, sizeof (rnd_stats_cpu
),
72 rndmag
+ rndmag_t_offset
+ i
* rndmag_t_size
);
74 rnd_stats
.rs_rndOut
+= rnd_stats_cpu
.rs_rndOut
;
75 rnd_stats
.rs_rndcOut
+= rnd_stats_cpu
.rs_rndcOut
;
76 rnd_stats
.rs_urndOut
+= rnd_stats_cpu
.rs_urndOut
;
79 mdb_printf("Random number device statistics:\n");
81 mdb_printf("%8llu bytes generated for /dev/random\n",
83 mdb_printf("%8llu bytes read from /dev/random cache\n",
84 rnd_stats
.rs_rndcOut
);
85 mdb_printf("%8llu bytes generated for /dev/urandom\n",
86 rnd_stats
.rs_urndOut
);
92 * swrand_stats dcmd - Print out the global swrand_stats structure,
97 swrand_get_stats(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
99 swrand_stats_t swrand_stats
;
101 if ((flags
& DCMD_ADDRSPEC
) || argc
!= 0)
104 if (mdb_readvar(&swrand_stats
, "swrand_stats") == -1) {
105 mdb_warn("failed to read swrand_stats structure");
109 mdb_printf("Software-based Random number generator statistics:\n");
111 mdb_printf("%8u bits of entropy estimate\n", swrand_stats
.ss_entEst
);
112 mdb_printf("%8llu bits of entropy added to the pool\n",
113 swrand_stats
.ss_entIn
);
114 mdb_printf("%8llu bits of entropy extracted from the pool\n",
115 swrand_stats
.ss_entOut
);
116 mdb_printf("%8llu bytes added to the random pool\n",
117 swrand_stats
.ss_bytesIn
);
118 mdb_printf("%8llu bytes extracted from the random pool\n",
119 swrand_stats
.ss_bytesOut
);
124 static const mdb_dcmd_t dcmds
[] = {
127 "print random number device statistics",
131 "print kernel random number provider statistics",
136 static const mdb_modinfo_t modinfo
= {
137 MDB_API_VERSION
, dcmds
, NULL
140 const mdb_modinfo_t
*