and added files
[bcm963xx.git] / userapps / opensource / net-snmp / agent / mibgroup / ucd-snmp / vmstat_solaris2.c
1 /*
2  *  vmstat_solaris2.c
3  *  UCD SNMP module for systemStats section of UCD-SNMP-MIB for SunOS/Solaris
4  *  Jochen Kmietsch <kmietsch@jochen.de>
5  *  with fixes and additions from the UCD-SNMP community
6  *  Uses some ideas from xosview and top
7  *  Some comments paraphrased from the SUN man pages 
8  *  Version 0.1 initial release (Dec 1999)
9  *  Version 0.2 added support for multiprocessor machines (Jan 2000)
10  *  Version 0.3 some reliability enhancements and compile time fixes (Feb 2000)
11  *  Version 0.4 portability issue and raw cpu value support (Jun 2000)
12  *  Version 0.5 64-bit Solaris support and new data gathering routine (Aug 2000)
13  *  Version 0.6 Memory savings, overroll precautions and lint checks (Aug 2000)
14  *  Version 0.7 More raw counters and some cosmetic changes (Jan 2001)
15  *
16  */
17
18 /*
19  * To make lint skip the debug code and stop complaining 
20  */
21 #ifdef __lint
22 #define SNMP_NO_DEBUGGING 1
23 #endif
24
25 /*
26  * Includes start here 
27  */
28
29 /*
30  * Standard includes 
31  */
32 #include <stdlib.h>
33 #include <unistd.h>
34 #include <sys/types.h>
35 #include <sys/time.h>
36 #include <string.h>
37
38 /*
39  * kstat and sysinfo structs 
40  */
41 #include <kstat.h>
42 #include <sys/sysinfo.h>
43
44 #include <net-snmp/net-snmp-config.h>
45 #include <net-snmp/net-snmp-includes.h>
46 #include <net-snmp/agent/net-snmp-agent-includes.h>
47
48 #include "mibdefs.h"
49 #include "util_funcs.h"
50
51 /*
52  * Header file for this module 
53  */
54 #include "vmstat.h"
55 #include "vmstat_solaris2.h"
56
57 /*
58  * Includes end here 
59  */
60
61
62 /*
63  * Global structures start here 
64  */
65
66 /*
67  * A structure to save data gathered from the kernel kstat interface to.  
68  */
69 /*
70  * We used to have the sys/sysinfo.h cpu_stat_t here but we did not need 
71  */
72 /*
73  * all of it, some in a different size and some additional ones so we build 
74  */
75 /*
76  * our own 
77  */
78 struct cpu_stat_snapshot {
79     hrtime_t        css_time;
80     unsigned int    css_cpus;
81     unsigned long long css_swapin;
82     unsigned long long css_swapout;
83     unsigned long long css_blocks_read;
84     unsigned long long css_blocks_write;
85     unsigned long long css_interrupts;
86     unsigned long long css_context_sw;
87     unsigned long long css_cpu[CPU_STATES];
88 };
89
90 /*
91  * Global structures end here 
92  */
93
94
95 /*
96  * Global variables start here 
97  */
98
99 /*
100  * From kstat.h: 
101  */
102 /*
103  * Provides access to the kernel statistics library by 
104  */
105 /*
106  * initializing a kstat control structure and returning a pointer 
107  */
108 /*
109  * to this structure.  This pointer must be used as the kc argument in  
110  */
111 /*
112  * following function calls from libkstat (here kc is called kstat_fd). 
113  */
114 /*
115  * Pointer to structure to be opened with kstat_open in main procedure. 
116  */
117 /*
118  * We share this one with memory_solaris2 and kernel_sunos5, where it's 
119  */
120 /*
121  * defined. 
122  */
123 extern kstat_ctl_t *kstat_fd;
124
125 /*
126  * Variables for the calculated values, filled in update_stats    
127  */
128 /*
129  * Need to be global since we need them in more than one function 
130  */
131 static ulong    swapin;
132 static ulong    swapout;
133 static ulong    blocks_read;
134 static ulong    blocks_write;
135 static ulong    interrupts;
136 static ulong    context_sw;
137
138 /*
139  * Since MIB wants CPU_SYSTEM, which is CPU_KERNEL + CPU_WAIT 
140  */
141 static long     cpu_perc[CPU_STATES + 1];
142
143 /*
144  * How many snapshots we have already taken, needed for the first 
145  */
146 /*
147  * POLL_INTERVAL * POLL_VALUES seconds of agent running 
148  */
149 static unsigned int number_of_snapshots;
150
151 /*
152  * The place to store the snapshots of system data in 
153  */
154 static struct cpu_stat_snapshot snapshot[POLL_VALUES + 1];
155
156 /*
157  * And one for the raw counters, which we fill when the raw values are 
158  */
159 /*
160  * requested, as opposed to the absolute values, which are taken every 
161  */
162 /*
163  * POLL_INTERVAL seconds and calculated over POLL_INTERVAL * POLL_VALUES time 
164  */
165 static struct cpu_stat_snapshot raw_values;
166
167 /*
168  * Global variables end here 
169  */
170
171
172 /*
173  * Functions start here 
174  */
175
176 /*
177  * Function prototype 
178  */
179 static void     update_stats(unsigned int registrationNumber,
180                              void *clientarg);
181 static int      take_snapshot(struct cpu_stat_snapshot *css);
182
183 /*
184  * init_vmstat_solaris2 starts here 
185  */
186 /*
187  * Init function for this module, from prototype 
188  */
189 /*
190  * Defines variables handled by this module, defines root OID for 
191  */
192 /*
193  * this module and registers it with the agent 
194  */
195
196 FindVarMethod var_extensible_vmstat;
197
198 void
199 init_vmstat_solaris2(void)
200 {
201
202     /*
203      * Which variables do we service ? 
204      */
205     struct variable2 extensible_vmstat_variables[] = {
206         {MIBINDEX, ASN_INTEGER, RONLY, var_extensible_vmstat, 1,
207          {MIBINDEX}},
208         {ERRORNAME, ASN_OCTET_STR, RONLY, var_extensible_vmstat, 1,
209          {ERRORNAME}},
210         {SWAPIN, ASN_INTEGER, RONLY, var_extensible_vmstat, 1, {SWAPIN}},
211         {SWAPOUT, ASN_INTEGER, RONLY, var_extensible_vmstat, 1, {SWAPOUT}},
212         {IOSENT, ASN_INTEGER, RONLY, var_extensible_vmstat, 1, {IOSENT}},
213         {IORECEIVE, ASN_INTEGER, RONLY, var_extensible_vmstat, 1,
214          {IORECEIVE}},
215         {SYSINTERRUPTS, ASN_INTEGER, RONLY, var_extensible_vmstat, 1,
216          {SYSINTERRUPTS}},
217         {SYSCONTEXT, ASN_INTEGER, RONLY, var_extensible_vmstat, 1,
218          {SYSCONTEXT}},
219         {CPUUSER, ASN_INTEGER, RONLY, var_extensible_vmstat, 1, {CPUUSER}},
220         {CPUSYSTEM, ASN_INTEGER, RONLY, var_extensible_vmstat, 1,
221          {CPUSYSTEM}},
222         {CPUIDLE, ASN_INTEGER, RONLY, var_extensible_vmstat, 1, {CPUIDLE}},
223         {CPURAWUSER, ASN_COUNTER, RONLY, var_extensible_vmstat, 1,
224          {CPURAWUSER}},
225         {CPURAWSYSTEM, ASN_COUNTER, RONLY, var_extensible_vmstat, 1,
226          {CPURAWSYSTEM}},
227         {CPURAWIDLE, ASN_COUNTER, RONLY, var_extensible_vmstat, 1,
228          {CPURAWIDLE}},
229         {CPURAWWAIT, ASN_COUNTER, RONLY, var_extensible_vmstat, 1,
230          {CPURAWWAIT}},
231         {CPURAWKERNEL, ASN_COUNTER, RONLY, var_extensible_vmstat, 1,
232          {CPURAWKERNEL}},
233         {IORAWSENT, ASN_COUNTER, RONLY, var_extensible_vmstat, 1,
234          {IORAWSENT}},
235         {IORAWRECEIVE, ASN_COUNTER, RONLY, var_extensible_vmstat, 1,
236          {IORAWRECEIVE}},
237         {SYSRAWINTERRUPTS, ASN_COUNTER, RONLY, var_extensible_vmstat, 1,
238          {SYSRAWINTERRUPTS}},
239         {SYSRAWCONTEXT, ASN_COUNTER, RONLY, var_extensible_vmstat, 1,
240          {SYSRAWCONTEXT}},
241         /*
242          * Future use: 
243          */
244         /*
245          * {ERRORFLAG, ASN_INTEGER, RONLY, var_extensible_vmstat, 1, {ERRORFLAG }},
246          * {ERRORMSG, ASN_OCTET_STR, RONLY, var_extensible_vmstat, 1, {ERRORMSG }}
247          */
248     };
249
250     /*
251      * Define the OID pointer to the top of the mib tree that we're 
252      */
253     /*
254      * registering underneath 
255      */
256     oid             vmstat_variables_oid[] = { UCDAVIS_MIB, 11 };
257
258     /*
259      * register ourselves with the agent to handle our mib tree 
260      */
261     /*
262      * LINTED Trust me, I know what I'm doing 
263      */
264     REGISTER_MIB("ucd-snmp/vmstat", extensible_vmstat_variables, variable2,
265                  vmstat_variables_oid);
266
267     /*
268      * First check whether shared kstat contol is NULL, if so, try to open our 
269      */
270     /*
271      * own. 
272      */
273     if (kstat_fd == NULL) {
274         kstat_fd = kstat_open();
275     }
276
277     /*
278      * Then check whether either shared kstat was found or we succeeded in 
279      */
280     /*
281      * opening our own. 
282      */
283     if (kstat_fd == NULL) {
284         snmp_log(LOG_ERR,
285                  "vmstat_solaris2 (init): kstat_open() failed and no shared kstat control found.\n");
286     }
287
288     /*
289      * Start with some useful data 
290      */
291     update_stats(0, NULL);
292
293     /*
294      * update_stats is run every POLL_INTERVAL seconds using this routine 
295      */
296     /*
297      * (see 'man snmp_alarm') 
298      */
299     /*
300      * This is only executed once to get some useful data in the beginning 
301      */
302     if (snmp_alarm_register(5, NULL, update_stats, NULL) == 0) {
303         snmp_log(LOG_WARNING,
304                  "vmstat_solaris2 (init): snmp_alarm_register failed.\n");
305     }
306     /*
307      * This is the one that runs update_stats every POLL_INTERVAL seconds 
308      */
309     if (snmp_alarm_register(POLL_INTERVAL, SA_REPEAT, update_stats, NULL)
310         == 0) {
311         snmp_log(LOG_ERR,
312                  "vmstat_solaris2 (init): snmp_alarm_register failed, cannot service requests.\n");
313     }
314
315 }                               /* init_vmstat_solaris2 ends here */
316
317 /*
318  * Data collection function take_snapshot starts here 
319  */
320 /*
321  * Get data from kernel and save into the snapshot strutcs 
322  */
323 /*
324  * Argument is the snapshot struct to save to. Global anyway, but looks nicer 
325  */
326 static int
327 take_snapshot(struct cpu_stat_snapshot *css)
328 {
329     /*
330      * Variables start here 
331      */
332
333     /*
334      * From sys/kstat.h (included from kstat.h): 
335      */
336     /*
337      * Pointer to current kstat 
338      */
339     kstat_t        *ksp;
340
341     /*
342      * Counters 
343      */
344     unsigned int    cpu_num = 0;
345
346     /*
347      * High resolution time counter 
348      */
349     hrtime_t        current_time;
350
351     /*
352      * see sys/sysinfo.h, holds CPU data 
353      */
354     cpu_stat_t      cs;
355
356     /*
357      * The usual stuff to count on, err, by 
358      */
359     int             i;
360
361     /*
362      * Variables end here 
363      */
364
365     /*
366      * Function starts here 
367      */
368
369     /*
370      * Get time 
371      */
372     current_time = gethrtime();
373
374     /*
375      * If we have just gotten the data, return the values from last run (skip if-clause) 
376      */
377     /*
378      * This happens on a snmpwalk request.  No need to read the kstat again 
379      */
380     /*
381      * if we just did it less than 2 seconds ago 
382      */
383     /*
384      * Jumps into if-clause either when snapshot is empty or when too old 
385      */
386
387     if ((css->css_time == 0)
388         || (current_time > css->css_time + 2000000000)) {
389         /*
390          * Make sure we clean up before we put new data into snapshot 
391          */
392         memset(css, 0, sizeof *css);
393
394         /*
395          * Update timer 
396          */
397         css->css_time = current_time;
398
399         /*
400          * Look thru all the cpu slots on the machine whether they holds a CPU 
401          */
402         /*
403          * and if so, get the data from that CPU 
404          */
405         /*
406          * We walk through the whole kstat chain and sum up all the found cpu_stat kstats, 
407          */
408         /*
409          * there's one for every CPU in a machine 
410          */
411         for (ksp = kstat_fd->kc_chain; ksp != NULL; ksp = ksp->ks_next) {
412             /*
413              * If we encounter an invalid kstat, skip it and continue with next one 
414              */
415             if (ksp->ks_flags & KSTAT_FLAG_INVALID) {
416                 continue;
417             }
418
419             if (strcmp(ksp->ks_module, "cpu_stat") == 0) {
420                 /*
421                  * Yeah, we found a CPU. 
422                  */
423                 cpu_num++;
424
425                 /*
426                  * Read data from kstat into cs structure 
427                  */
428                 /*
429                  * kstat_fd is the control structure, ksp the kstat we are reading 
430                  */
431                 /*
432                  * and cs the buffer we are writing to. 
433                  */
434                 if ((ksp->ks_type != KSTAT_TYPE_RAW) ||
435                     (ksp->ks_data_size != sizeof cs) ||
436                     (kstat_read(kstat_fd, ksp, &cs) == -1)) {
437                     snmp_log(LOG_ERR,
438                              "vmstat_solaris2 (take_snapshot): could not read cs structure.\n");
439                     return (-1);
440                 }
441
442                 /*
443                  * Get the data from the cs structure and sum it up in our own structure 
444                  */
445                 css->css_swapin +=
446                     (unsigned long long) cs.cpu_vminfo.swapin;
447                 css->css_swapout +=
448                     (unsigned long long) cs.cpu_vminfo.swapout;
449                 css->css_blocks_read +=
450                     (unsigned long long) cs.cpu_sysinfo.bread;
451                 css->css_blocks_write +=
452                     (unsigned long long) cs.cpu_sysinfo.bwrite;
453                 css->css_interrupts +=
454                     (unsigned long long) cs.cpu_sysinfo.intr;
455                 css->css_context_sw +=
456                     (unsigned long long) cs.cpu_sysinfo.pswitch;
457
458                 /*
459                  * We need a for-loop for the CPU values 
460                  */
461                 for (i = 0; i < CPU_STATES; i++) {
462                     css->css_cpu[i] +=
463                         (unsigned long long) cs.cpu_sysinfo.cpu[i];
464                 }               /* end for */
465             }                   /* end if */
466         }                       /* end for */
467
468         /*
469          * Increment number of CPUs we gathered data from, for future use 
470          */
471         css->css_cpus = cpu_num;
472     }
473
474     /*
475      * All engines running at warp speed, no problems (if there are any engines, that is) 
476      */
477     return (cpu_num > 0 ? 0 : -1);
478 }                               /* take_snapshot ends here */
479
480 /*
481  * This gets called every POLL_INTERVAL seconds to update the snapshots.
482  * It takes a new snapshot and drops the oldest one.  This way we move
483  * the time window so we always take the values over 
484  * POLL_INTERVAL * POLL_VALUES seconds and update the data used every
485  * POLL_INTERVAL seconds 
486  * The alarm timer is in the init function of this module (snmp_alarm_register) 
487  */
488 /*
489  * ARGSUSED0 
490  */
491 static void
492 update_stats(unsigned int registrationNumber, void *clientarg)
493 {
494     /*
495      * The time between the samples we compare 
496      */
497     hrtime_t        time_diff;
498
499     /*
500      * Easier to use these than the snapshots, short hand pointers 
501      */
502     struct cpu_stat_snapshot *css_old, *css_new;
503
504     /*
505      * The usual stuff to count on, err, by 
506      */
507     int             i;
508
509     /*
510      * Kstat chain id, to check whether kstat chain changed 
511      */
512     kid_t           kid;
513
514     /*
515      * The sum of the CPU ticks that have passed on the different CPU states, so we can calculate 
516      */
517     /*
518      * the percentages of each state 
519      */
520     unsigned long long cpu_sum = 0;
521
522     DEBUGMSGTL(("ucd-snmp/vmstat_solaris2.c:update_stats",
523                 "updating stats\n"));
524
525     /*
526      * Just in case someone added (or removed) some CPUs during operation (or other kstat chain changes) 
527      */
528     kid = kstat_chain_update(kstat_fd);
529     if (kid != 0) {
530         if (kid == -1) {
531             snmp_log(LOG_WARNING,
532                      "vmstat_solaris2 (update_stats): Could not update kstat chain.\n");
533         } else {
534             /*
535              * On some machines this floods the logfile, thus commented out 
536              */
537             /*
538              * snmp_log(LOG_INFO, "vmstat_solaris2 (update_stats): Kstat chain changed."); 
539              */
540         }
541     }
542
543     /*
544      * Take the current snapshot 
545      */
546     if (take_snapshot(&snapshot[0]) == -1) {
547         snmp_log(LOG_WARNING,
548                  "vmstat_solaris2 (update_stats): Something went wrong with take_snapshot.\n");
549         return;
550     }
551
552     /*
553      * Do we have some data we can use ?  An issue right after the start of the agent 
554      */
555     if (number_of_snapshots > 0) {
556         /*
557          * Huh, the number of CPUs changed during run time.  That is indeed s.th. worth noting, we 
558          */
559         /*
560          * output a humorous (more or less) syslog message and need to retake the snapshots 
561          */
562         if (snapshot[0].css_cpus != snapshot[1].css_cpus) {
563             if (snapshot[0].css_cpus > snapshot[1].css_cpus) {
564                 snmp_log(LOG_NOTICE,
565                          "vmstat_solaris2 (update_stats): Cool ! Number of CPUs increased, must be hot-pluggable.\n");
566             } else {
567                 snmp_log(LOG_NOTICE,
568                          "vmstat_solaris2 (update_stats): Lost at least one CPU, RIP.\n");
569             }
570             /*
571              * Make all snapshots but the current one invalid 
572              */
573             number_of_snapshots = 1;
574             /*
575              * Move the current one in the "first" [1] slot 
576              */
577             memmove(&snapshot[1], &snapshot[0], sizeof snapshot[0]);
578             /*
579              * Erase the current one 
580              */
581             memset(&snapshot[0], 0, sizeof snapshot[0]);
582             /*
583              * Try to get a new snapshot in five seconds so we can return s.th. useful 
584              */
585             if (snmp_alarm_register(5, NULL, update_stats, NULL) == 0) {
586                 snmp_log(LOG_WARNING,
587                          "vmstat_solaris2 (update_stats): snmp_alarm_register failed.\n");
588             }
589             return;
590         }
591
592         /*
593          * Short hand pointers 
594          */
595         css_new = &snapshot[0];
596         css_old = &snapshot[number_of_snapshots];
597
598         /*
599          * How much time has passed between the snapshots we get the values from ? 
600          */
601         /*
602          * Time is in nanoseconds so a few zeros here to juggle with 
603          */
604         /*
605          * But the hrtime is not subject to change (s.b. setting the clock), unlike the normal time 
606          */
607         time_diff =
608             (snapshot[0].css_time -
609              snapshot[number_of_snapshots].css_time) / 1000000;
610
611         DEBUGMSGTL(("ucd-snmp/vmstat_solaris2.c:update_stats",
612                     "time_diff: %lld\n", time_diff));
613
614         /*
615          * swapin and swapout are in pages, MIB wants kB/s,so we just need to get kB and seconds 
616          */
617         /*
618          * For the others we need to get value per second 
619          */
620         /*
621          * getpagesize() returns pagesize in bytes 
622          */
623         /*
624          * decided to use sysconf(_SC_PAGESIZE) instead to get around an #ifndef (I don't like those) 
625          */
626         /*
627          * that was needed b/c some old Solaris versions don't have getpagesize() 
628          */
629         /*
630          * LINTED cast needed, really 
631          */
632         swapin =
633             (uint_t) ((css_new->css_swapin -
634                        css_old->css_swapin) * (hrtime_t) 1000 *
635                       sysconf(_SC_PAGESIZE) / 1024 / time_diff);
636         /*
637          * LINTED cast needed, really 
638          */
639         swapout =
640             (uint_t) ((css_new->css_swapout -
641                        css_old->css_swapout) * (hrtime_t) 1000 *
642                       sysconf(_SC_PAGESIZE) / 1024 / time_diff);
643         /*
644          * LINTED cast needed, really 
645          */
646         blocks_read =
647             (uint_t) ((css_new->css_blocks_read -
648                        css_old->css_blocks_read) * (hrtime_t) 1000 /
649                       time_diff);
650         /*
651          * LINTED cast needed, really 
652          */
653         blocks_write =
654             (uint_t) ((css_new->css_blocks_write -
655                        css_old->css_blocks_write) * (hrtime_t) 1000 /
656                       time_diff);
657         /*
658          * LINTED cast needed, really 
659          */
660         interrupts =
661             (uint_t) ((css_new->css_interrupts -
662                        css_old->css_interrupts) * (hrtime_t) 1000 /
663                       time_diff);
664         /*
665          * LINTED cast needed, really 
666          */
667         context_sw =
668             (uint_t) ((css_new->css_context_sw -
669                        css_old->css_context_sw) * (hrtime_t) 1000 /
670                       time_diff);
671
672         /*
673          * Loop thru all the CPU_STATES and get the differences 
674          */
675         for (i = 0; i < CPU_STATES; i++) {
676             cpu_sum += (css_new->css_cpu[i] - css_old->css_cpu[i]);
677         }
678
679         /*
680          * Now calculate the absolute percentage values 
681          */
682         /*
683          * Looks somewhat complicated sometimes but tries to get around using floats to increase speed 
684          */
685         for (i = 0; i < CPU_STATES; i++) {
686             /*
687              * Since we don't return fractions we use + 0.5 to get between 99 and 101 percent adding the values 
688              */
689             /*
690              * together, otherwise we would get less than 100 most of the time 
691              */
692             /*
693              * LINTED has to be 'long' 
694              */
695             cpu_perc[i] =
696                 (long) (((css_new->css_cpu[i] -
697                           css_old->css_cpu[i]) * 100 +
698                          (cpu_sum / 2)) / cpu_sum);
699         }
700
701         /*
702          * As said before, MIB wants CPU_SYSTEM which is CPU_KERNEL + CPU_WAIT 
703          */
704         /*
705          * LINTED has to be 'long' 
706          */
707         cpu_perc[CPU_SYSTEM] =
708             (long) ((((css_new->css_cpu[CPU_KERNEL] -
709                        css_old->css_cpu[CPU_KERNEL])
710                       + (css_new->css_cpu[CPU_WAIT] -
711                          css_old->css_cpu[CPU_WAIT]))
712                      * 100 + (cpu_sum / 2)) / cpu_sum);
713     }
714
715     /*
716      * Make the current one the first one and move the whole thing one place down 
717      */
718     memmove(&snapshot[1], &snapshot[0],
719             (size_t) (((char *) &snapshot[POLL_VALUES]) -
720                       ((char *) &snapshot[0])));
721
722     /*
723      * Erase the current one 
724      */
725     memset(&snapshot[0], 0, sizeof snapshot[0]);
726
727     /*
728      * Only important on start up, we keep track of how many snapshots we have taken so far 
729      */
730     if (number_of_snapshots < POLL_VALUES) {
731         number_of_snapshots++;
732     }
733 }                               /* update_stats ends here */
734
735 /*
736  * *var_extensible_vmstat starts here 
737  */
738 /*
739  * The guts of the module, this routine gets called to service a request 
740  */
741 unsigned char *
742 var_extensible_vmstat(struct variable *vp,
743                       oid * name,
744                       size_t * length,
745                       int exact,
746                       size_t * var_len, WriteMethod ** write_method)
747 {
748     /*
749      * Needed for returning the values 
750      */
751     static long     long_ret;
752     static char     errmsg[300];
753
754     /*
755      * set to 0 as default 
756      */
757     long_ret = 0;
758
759     /*
760      * generic check whether the options passed make sense and whether the 
761      */
762     /*
763      * right variable is requested 
764      */
765     if (header_generic(vp, name, length, exact, var_len, write_method) !=
766         MATCH_SUCCEEDED) {
767         return (NULL);
768     }
769
770     /*
771      * The function that actually returns s.th. 
772      */
773     switch (vp->magic) {
774     case MIBINDEX:
775         long_ret = 1;
776         return ((u_char *) (&long_ret));
777     case ERRORNAME:            /* dummy name */
778         sprintf(errmsg, "systemStats");
779         *var_len = strlen(errmsg);
780         return ((u_char *) (errmsg));
781     case SWAPIN:
782         return ((u_char *) (&swapin));
783     case SWAPOUT:
784         return ((u_char *) (&swapout));
785     case IOSENT:
786         return ((u_char *) (&blocks_write));
787     case IORECEIVE:
788         return ((u_char *) (&blocks_read));
789     case SYSINTERRUPTS:
790         return ((u_char *) (&interrupts));
791     case SYSCONTEXT:
792         return ((u_char *) (&context_sw));
793     case CPUUSER:
794         return ((u_char *) (&cpu_perc[CPU_USER]));
795     case CPUSYSTEM:
796         return ((u_char *) (&cpu_perc[CPU_SYSTEM]));
797     case CPUIDLE:
798         return ((u_char *) (&cpu_perc[CPU_IDLE]));
799     case CPURAWUSER:
800         take_snapshot(&raw_values);
801         /*
802          * LINTED has to be 'long' 
803          */
804         long_ret =
805             (long) (raw_values.css_cpu[CPU_USER] / raw_values.css_cpus);
806         return ((u_char *) (&long_ret));
807         /*
808          * We are missing CPURAWNICE, Solaris does not account for this in the kernel so this OID can not 
809          */
810         /*
811          * be returned.  Also, these values will roll over sooner or later and then return inaccurate data 
812          */
813         /*
814          * but the MIB wants Integer32 so we cannot put a counter here 
815          */
816         /*
817          * (Has been changed to Counter32 in the latest MIB version!) 
818          */
819     case CPURAWSYSTEM:
820         take_snapshot(&raw_values);
821         /*
822          * LINTED has to be 'long' 
823          */
824         long_ret =
825             (long) ((raw_values.css_cpu[CPU_KERNEL] +
826                      raw_values.css_cpu[CPU_WAIT]) / raw_values.css_cpus);
827         return ((u_char *) (&long_ret));
828     case CPURAWIDLE:
829         take_snapshot(&raw_values);
830         /*
831          * LINTED has to be 'long' 
832          */
833         long_ret =
834             (long) (raw_values.css_cpu[CPU_IDLE] / raw_values.css_cpus);
835         return ((u_char *) (&long_ret));
836     case CPURAWWAIT:
837         take_snapshot(&raw_values);
838         /*
839          * LINTED has to be 'long' 
840          */
841         long_ret =
842             (long) (raw_values.css_cpu[CPU_WAIT] / raw_values.css_cpus);
843         return ((u_char *) (&long_ret));
844     case CPURAWKERNEL:
845         take_snapshot(&raw_values);
846         /*
847          * LINTED has to be 'long' 
848          */
849         long_ret =
850             (long) (raw_values.css_cpu[CPU_KERNEL] / raw_values.css_cpus);
851         return ((u_char *) (&long_ret));
852     case IORAWSENT:
853         long_ret = (long) (raw_values.css_blocks_write);
854         return ((u_char *) (&long_ret));
855     case IORAWRECEIVE:
856         long_ret = (long) (raw_values.css_blocks_read);
857         return ((u_char *) (&long_ret));
858     case SYSRAWINTERRUPTS:
859         long_ret = (long) (raw_values.css_interrupts);
860         return ((u_char *) (&long_ret));
861     case SYSRAWCONTEXT:
862         long_ret = (long) (raw_values.css_context_sw);
863         return ((u_char *) (&long_ret));
864
865         /*
866          * reserved for future use 
867          */
868         /*
869          * case ERRORFLAG:
870          * return((u_char *) (&long_ret));
871          * case ERRORMSG:
872          * return((u_char *) (&long_ret));
873          */
874     default:
875         snmp_log(LOG_ERR,
876                  "vmstat_solaris2: Error in request, no match found.\n");
877     }
878     return (NULL);
879 }                               /* *var_extensible_vmstat ends here */
880
881 /*
882  * Functions end here 
883  */
884
885 /*
886  * Program ends here 
887  */