[BACK]Return to vmstat.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / systat

Diff for /src/usr.bin/systat/vmstat.c between version 1.50 and 1.51

version 1.50, 2004/06/11 06:31:32 version 1.51, 2004/06/28 01:45:51
Line 63 
Line 63 
 #include <utmp.h>  #include <utmp.h>
 #include <unistd.h>  #include <unistd.h>
   
 #if defined(__i386__)  
 #define _KERNEL  
 #include <machine/psl.h>  
 #undef _KERNEL  
 #endif  
   
 #include "systat.h"  #include "systat.h"
 #include "extern.h"  #include "extern.h"
   
Line 144 
Line 138 
         { "_intrcnt" },          { "_intrcnt" },
 #define X_EINTRCNT      3               /* no sysctl */  #define X_EINTRCNT      3               /* no sysctl */
         { "_eintrcnt" },          { "_eintrcnt" },
 #if defined(__i386__)  
 #define X_INTRHAND      4               /* no sysctl */  
         { "_intrhand" },  
 #define X_APICINTRHAND  5               /* no sysctl */  
         { "_apic_intrhand" },  
 #endif  
         { "" },          { "" },
 };  };
   
Line 184 
Line 172 
 int  int
 initkre(void)  initkre(void)
 {  {
         char *intrnamebuf, *cp;          int mib[4], i, ret;
         size_t size = sizeof(ncpu);          size_t size;
         int mib[2], i, ret;  
   
         if (namelist[0].n_type == 0) {          if (namelist[0].n_type == 0) {
                 if ((ret = kvm_nlist(kd, namelist)) == -1)                  if ((ret = kvm_nlist(kd, namelist)) == -1)
                         errx(1, "%s", kvm_geterr(kd));                          errx(1, "%s", kvm_geterr(kd));
 #if defined(__i386__)  
                 else if (ret == 1 && namelist[X_APICINTRHAND].n_value != 0)  
                         nlisterr(namelist);  
 #endif  
                 else if (ret > 1)                  else if (ret > 1)
                         nlisterr(namelist);                          nlisterr(namelist);
                 if (namelist[0].n_type == 0) {                  if (namelist[0].n_type == 0) {
Line 205 
Line 188 
   
         mib[0] = CTL_HW;          mib[0] = CTL_HW;
         mib[1] = HW_NCPU;          mib[1] = HW_NCPU;
         if (sysctl(mib, 2, &ncpu, &size, NULL, 0) == -1)          size = sizeof(ncpu);
                 return (-1);          if (sysctl(mib, 2, &ncpu, &size, NULL, 0) < 0)
                   return (-1);
   
         hertz = stathz ? stathz : hz;          hertz = stathz ? stathz : hz;
         if (!dkinit(1))          if (!dkinit(1))
                 return(0);                  return(0);
         if (nintr == 0) {  
 #if defined(__i386__)  
                 struct intrhand *intrhand[16], *ihp, ih;  
                 struct intrhand *apicintrhand[256];  
                 char iname[16];  
                 int namelen, n;  
   
                 NREAD(X_INTRHAND, intrhand, sizeof(intrhand));          mib[0] = CTL_KERN;
                 for (namelen = 0, i = 0; i < 16; i++) {          mib[1] = KERN_INTRCNT;
                         ihp = intrhand[i];          mib[2] = KERN_INTRCNT_NUM;
                         while (ihp) {          size = sizeof(nintr);
                                 nintr++;          if (sysctl(mib, 3, &nintr, &size, NULL, 0) < 0)
                                 KREAD(ihp, &ih, sizeof(ih));                  return (-1);
                                 KREAD(ih.ih_what, iname, 16);  
                                 namelen += strlen(iname) + 1;          intrloc = calloc(nintr, sizeof(long));
                                 ihp = ih.ih_next;          intrname = calloc(nintr, sizeof(char *));
                         }  
                 }          for (i = 0; i < nintr; i++) {
                 if (namelist[X_APICINTRHAND].n_value) {                  char name[128];
                         NREAD(X_APICINTRHAND, apicintrhand, sizeof(apicintrhand));  
                         for (namelen = 0, i = 0; i < 256; i++) {                  mib[0] = CTL_KERN;
                                 ihp = apicintrhand[i];                  mib[1] = KERN_INTRCNT;
                                 while (ihp) {                  mib[2] = KERN_INTRCNT_NAME;
                                         nintr++;                  mib[3] = i;
                                         KREAD(ihp, &ih, sizeof(ih));                  size = sizeof(name);
                                         KREAD(ih.ih_what, iname, 16);                  if (sysctl(mib, 4, name, &size, NULL, 0) < 0)
                                         namelen += strlen(iname) + 1;                          return (-1);
                                         printf("apic handler %x %s\n", i, iname);  
                                         ihp = ih.ih_next;                  intrname[i] = strdup(name);
                                 }                  if (intrname[i] == NULL)
                         }                          return (-1);
                 }  
                 intrloc = calloc(nintr, sizeof (long));  
                 intrname = calloc(nintr, sizeof (char *));  
                 cp = intrnamebuf = malloc(namelen);  
                 for (i = 0, n = 0; i < 16; i++) {  
                         ihp = intrhand[i];  
                         while (ihp) {  
                                 KREAD(ihp, &ih, sizeof(ih));  
                                 KREAD(ih.ih_what, iname, 16);  
                                 intrname[n++] = cp;  
                                 strlcpy(cp, iname, intrnamebuf + namelen - cp);  
                                 cp += strlen(iname) + 1;  
                                 ihp = ih.ih_next;  
                         }  
                 }  
                 if (namelist[X_APICINTRHAND].n_value) {  
                         for (i = 0, n = 0; i < 256; i++) {  
                                 ihp = apicintrhand[i];  
                                 while (ihp) {  
                                         KREAD(ihp, &ih, sizeof(ih));  
                                         KREAD(ih.ih_what, iname, 16);  
                                         intrname[n++] = cp;  
                                         strlcpy(cp, iname, intrnamebuf + namelen - cp);  
                                         cp += strlen(iname) + 1;  
                                         ihp = ih.ih_next;  
                                 }  
                         }  
                 }  
 #else  
                 nintr = (namelist[X_EINTRCNT].n_value -  
                     namelist[X_INTRCNT].n_value) / sizeof (int);  
                 intrloc = calloc(nintr, sizeof (long));  
                 intrname = calloc(nintr, sizeof (long));  
                 intrnamebuf = malloc(namelist[X_EINTRNAMES].n_value -  
                     namelist[X_INTRNAMES].n_value);  
                 if (intrnamebuf == 0 || intrname == 0 || intrloc == 0) {  
                         error("Out of memory\n");  
                         if (intrnamebuf)  
                                 free(intrnamebuf);  
                         if (intrname)  
                                 free(intrname);  
                         if (intrloc)  
                                 free(intrloc);  
                         nintr = 0;  
                         return(0);  
                 }  
                 NREAD(X_INTRNAMES, intrnamebuf, NVAL(X_EINTRNAMES) -  
                     NVAL(X_INTRNAMES));  
                 for (cp = intrnamebuf, i = 0; i < nintr; i++) {  
                         intrname[i] = cp;  
                         cp += strlen(cp) + 1;  
                 }  
 #endif  
                 nextintsrow = INTSROW + 2;  
                 allocinfo(&s);  
                 allocinfo(&s1);  
                 allocinfo(&s2);  
                 allocinfo(&z);  
         }          }
   
           nextintsrow = INTSROW + 2;
           allocinfo(&s);
           allocinfo(&s1);
           allocinfo(&s2);
           allocinfo(&z);
   
         getinfo(&s2, RUN);          getinfo(&s2, RUN);
         copyinfo(&s2, &s1);          copyinfo(&s2, &s1);
         return(1);          return(1);
Line 679 
Line 606 
         static int nchstats_mib[2] = { CTL_KERN, KERN_NCHSTATS };          static int nchstats_mib[2] = { CTL_KERN, KERN_NCHSTATS };
         static int uvmexp_mib[2] = { CTL_VM, VM_UVMEXP };          static int uvmexp_mib[2] = { CTL_VM, VM_UVMEXP };
         static int vmtotal_mib[2] = { CTL_VM, VM_METER };          static int vmtotal_mib[2] = { CTL_VM, VM_METER };
           int mib[4], i;
         size_t size;          size_t size;
 #if defined(__i386__)  
         struct intrhand *intrhand[16], *ihp, ih;  
         struct intrhand *apicintrhand[256];  
         int i, n;  
 #endif  
   
         dkreadstats();          dkreadstats();
 #if defined(__i386__)  
         NREAD(X_INTRHAND, intrhand, sizeof(intrhand));          for (i = 0; i < nintr; i++) {
         for (i = 0, n = 0; i < 16; i++) {                  mib[0] = CTL_KERN;
                 ihp = intrhand[i];                  mib[1] = KERN_INTRCNT;
                 while (ihp) {                  mib[2] = KERN_INTRCNT_CNT;
                         KREAD(ihp, &ih, sizeof(ih));                  mib[3] = i;
                         s->intrcnt[n++] = ih.ih_count;                  size = sizeof(s->intrcnt[i]);
                         ihp = ih.ih_next;                  if (sysctl(mib, 4, &s->intrcnt[i], &size, NULL, 0) < 0)
                 }                          s->intrcnt[i] = 0;
         }          }
         if (namelist[X_APICINTRHAND].n_value) {  
                 NREAD(X_APICINTRHAND, apicintrhand, sizeof(apicintrhand));  
                 for (i = 0, n = 0; i < 256; i++) {  
                         ihp = apicintrhand[i];  
                         while (ihp) {  
                                 KREAD(ihp, &ih, sizeof(ih));  
                                 s->intrcnt[n++] = ih.ih_count;  
                                 ihp = ih.ih_next;  
                         }  
                 }  
         }  
 #else  
         NREAD(X_INTRCNT, s->intrcnt, nintr * sizeof(int));  
 #endif  
         size = sizeof(s->time);          size = sizeof(s->time);
         if (sysctl(cp_time_mib, 2, &s->time, &size, NULL, 0) < 0) {          if (sysctl(cp_time_mib, 2, &s->time, &size, NULL, 0) < 0) {
                 error("Can't get KERN_CPTIME: %s\n", strerror(errno));                  error("Can't get KERN_CPTIME: %s\n", strerror(errno));

Legend:
Removed from v.1.50  
changed lines
  Added in v.1.51