4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
26 * This program is strictly for demonstration purposes and not for
27 * production use. It demonstrates how to access the dynamic memory
28 * caching statistics and turning variables via the kstat library.
45 #include <sys/types.h>
47 #include <sys/sysinfo.h>
54 #define SDBC_KSTAT_MODULE "sdbc"
55 #define SDBC_KSTAT_DYNMEM "dynmem"
98 DYNMEM_KNP_DEFN dynmem_knp
[] = {
99 NULL
, "sdbc_monitor_dynmem", NO_VALUE
,
100 NULL
, "sdbc_max_dyn_list", NO_VALUE
,
101 NULL
, "sdbc_cache_aging_ct1", NO_VALUE
,
102 NULL
, "sdbc_cache_aging_ct2", NO_VALUE
,
103 NULL
, "sdbc_cache_aging_ct3", NO_VALUE
,
104 NULL
, "sdbc_cache_aging_sec1", NO_VALUE
,
105 NULL
, "sdbc_cache_aging_sec2", NO_VALUE
,
106 NULL
, "sdbc_cache_aging_sec3", NO_VALUE
,
107 NULL
, "sdbc_cache_aging_pcnt1", NO_VALUE
,
108 NULL
, "sdbc_cache_aging_pcnt2", NO_VALUE
,
109 NULL
, "sdbc_max_holds_pcnt", NO_VALUE
,
110 NULL
, "sdbc_alloc_cnt", NO_VALUE
,
111 NULL
, "sdbc_dealloc_cnt", NO_VALUE
,
112 NULL
, "sdbc_history", NO_VALUE
,
113 NULL
, "sdbc_nodatas", NO_VALUE
,
114 NULL
, "sdbc_candidates", NO_VALUE
,
115 NULL
, "sdbc_deallocs", NO_VALUE
,
116 NULL
, "sdbc_hosts", NO_VALUE
,
117 NULL
, "sdbc_pests", NO_VALUE
,
118 NULL
, "sdbc_metas", NO_VALUE
,
119 NULL
, "sdbc_holds", NO_VALUE
,
120 NULL
, "sdbc_others", NO_VALUE
,
121 NULL
, "sdbc_notavail", NO_VALUE
,
122 NULL
, "sdbc_process_directive", NO_VALUE
,
123 NULL
, "sdbc_simplect", NO_VALUE
,
133 (void) printf("USAGE: wake - wakeup thread, hys - max hysteresis\n");
134 (void) printf(" mon 1 - monitor shutdown\n");
135 (void) printf(" 2 - monitor thread stats1\n");
136 (void) printf(" 4 - monitor thread stats2\n");
137 (void) printf(" age1 n - num cyc to full host aging and "
139 (void) printf(" age2 n - num cyc to full meta aging and "
141 (void) printf(" age3 n - num cyc to full one pg aging and "
143 (void) printf(" sec1 n - sec1 aging time\n");
144 (void) printf(" sec2 n - sec2 aging time\n");
145 (void) printf(" sec3 n - sec3 aging time\n");
146 (void) printf(" pcnt1 n - percent to sec1/sec2 trans\n");
147 (void) printf(" pcnt2 n - percent to sec2/sec3 trans\n");
148 (void) printf(" hdpcnt n - max percent of cents for holds\n");
149 (void) printf(" list n - host+pest max len\n");
150 (void) printf("No Args - print current settings only\n");
159 sd_dynmem_lintmain(int argc
, char *argv
[])
162 main(int argc
, char *argv
[])
165 DYNMEM_KNP_DEFN
*p_dynmem_knp
;
167 KSTAT_INFO_DEF info_ksp
;
169 char **pargs
, **cur_pargs
;
172 * grab and parse argument list
174 p_dynmem_knp
= dynmem_knp
;
177 (void) printf("pargs=%x - %s\n", (uint_t
)pargs
, *pargs
);
182 if (strcmp(*cur_pargs
, "h") == 0) {
187 if (strcmp(*cur_pargs
, "wake") == 0) {
188 if ((p_dynmem_knp
+DIRECTIVE
)->newval
== NO_VALUE
)
189 (p_dynmem_knp
+DIRECTIVE
)->newval
= 0;
190 (p_dynmem_knp
+DIRECTIVE
)->newval
|= 0x01;
194 if (strcmp(*cur_pargs
, "hys") == 0) {
195 if ((p_dynmem_knp
+DIRECTIVE
)->newval
== NO_VALUE
)
196 (p_dynmem_knp
+DIRECTIVE
)->newval
= 0;
197 (p_dynmem_knp
+DIRECTIVE
)->newval
|= 0x02;
201 if (strcmp (*cur_pargs
, "mon") == 0) {
203 (void) printf("errno=%x, %s=%x\n", errno
, *cur_pargs
,
206 (p_dynmem_knp
+MONITOR
)->newval
= val
;
209 if (strcmp (*cur_pargs
, "age1") == 0) {
211 (void) printf("errno=%x, %s=%x\n", errno
, *cur_pargs
,
214 (p_dynmem_knp
+AGECT1
)->newval
= val
;
217 if (strcmp(*cur_pargs
, "age2") == 0) {
219 (void) printf("errno=%x, %s=%x\n", errno
, *cur_pargs
,
222 (p_dynmem_knp
+AGECT2
)->newval
= val
;
225 if (strcmp(*cur_pargs
, "age3") == 0) {
227 (void) printf("errno=%x, %s=%x\n", errno
, *cur_pargs
,
230 (p_dynmem_knp
+AGECT3
)->newval
= val
;
233 if (strcmp (*cur_pargs
, "sec1") == 0) {
235 (void) printf("errno=%x, %s=%x\n", errno
, *cur_pargs
,
241 (p_dynmem_knp
+SEC1
)->newval
= val
;
246 if (strcmp(*cur_pargs
, "sec2") == 0) {
249 (void) printf("errno=%x, %s=%x\n", errno
, *cur_pargs
,
254 (p_dynmem_knp
+SEC2
)->newval
= val
;
259 if (strcmp(*cur_pargs
, "sec3") == 0) {
262 (void) printf("errno=%x, %s=%x\n", errno
, *cur_pargs
,
267 (p_dynmem_knp
+SEC3
)->newval
= val
;
272 if (strcmp(*cur_pargs
, "pcnt1") == 0) {
275 (void) printf("errno=%x, %s=%x\n", errno
, *cur_pargs
,
280 (p_dynmem_knp
+PCNT1
)->newval
= val
;
285 if (strcmp(*cur_pargs
, "pcnt2") == 0) {
288 (void) printf("errno=%x, %s=%x\n", errno
, *cur_pargs
,
293 (p_dynmem_knp
+PCNT2
)->newval
= val
;
298 if (strcmp(*cur_pargs
, "hdpcnt") == 0) {
301 (void) printf("errno=%x, %s=%x\n", errno
, *cur_pargs
,
306 (p_dynmem_knp
+HDPCNT
)->newval
= val
;
311 if (strcmp(*cur_pargs
, "list") == 0) {
314 (void) printf("errno=%x, %s=%x\n", errno
, *cur_pargs
,
319 (p_dynmem_knp
+MAXLIST
)->newval
= val
;
323 } /* while(*pargs && cl) */
326 * open the kstat library
330 (void) printf("kstat_open() failed\n");
335 * is the name module about
337 info_ksp
.instance
= 0;
338 info_ksp
.ksp
= kstat_lookup(kctl
, SDBC_KSTAT_MODULE
, 0,
340 if (info_ksp
.ksp
== NULL
) {
341 (void) printf("No module to report\n");
346 * using the info get a copy of the data
348 if (kstat_read(kctl
, info_ksp
.ksp
, NULL
) == -1) {
349 (void) printf("Can't read kstat\n");
354 * print the current data
356 p_dynmem_knp
= dynmem_knp
;
357 while (p_dynmem_knp
->named
) {
359 kstat_data_lookup(info_ksp
.ksp
, p_dynmem_knp
->named
);
360 if (p_dynmem_knp
->knp
== NULL
) {
361 (void) printf("kstat_data_lookup(%s) failed\n",
362 p_dynmem_knp
->named
);
365 (void) printf("%s: %x\n", p_dynmem_knp
->named
,
366 (uint_t
)p_dynmem_knp
->knp
->value
.ul
);
372 * modify the data and write it back
374 p_dynmem_knp
= dynmem_knp
;
375 while (p_dynmem_knp
->named
) {
376 if (p_dynmem_knp
->newval
!= NO_VALUE
)
377 p_dynmem_knp
->knp
->value
.ul
= p_dynmem_knp
->newval
;
381 if (kstat_write(kctl
, info_ksp
.ksp
, NULL
) == -1) {
382 (void) printf("kstat_write() failed\n");
386 (void) printf("Finished (h for help)\n");