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

Diff for /src/usr.bin/top/machine.c between version 1.93 and 1.94

version 1.93, 2018/09/26 17:23:13 version 1.94, 2018/10/05 18:56:57
Line 111 
Line 111 
         "user", "nice", "sys", "spin", "intr", "idle", NULL          "user", "nice", "sys", "spin", "intr", "idle", NULL
 };  };
   
 /* this tracks which cpus are online */  
 int *cpu_online;  
   
 /* these are for detailing the memory statistics */  /* these are for detailing the memory statistics */
 int memory_stats[10];  int memory_stats[10];
 char *memorynames[] = {  char *memorynames[] = {
Line 173 
Line 170 
 }  }
   
 int  int
 getncpuonline(void)  
 {  
         int mib[] = { CTL_HW, HW_NCPUONLINE };  
         int numcpu;  
         size_t size = sizeof(numcpu);  
   
         if (sysctl(mib, sizeof(mib) / sizeof(mib[0]),  
             &numcpu, &size, NULL, 0) == -1)  
                 return (-1);  
   
         return (numcpu);  
 }  
   
 int  
 machine_init(struct statics *statics)  machine_init(struct statics *statics)
 {  {
         int pagesize, cpu;          int pagesize, cpu;
Line 199 
Line 182 
         cpu_states = calloc(ncpu, CPUSTATES * sizeof(int64_t));          cpu_states = calloc(ncpu, CPUSTATES * sizeof(int64_t));
         if (cpu_states == NULL)          if (cpu_states == NULL)
                 err(1, NULL);                  err(1, NULL);
         cpu_online = calloc(ncpu, sizeof(*cpu_online));  
         if (cpu_online == NULL)  
                 err(1, NULL);  
         cp_time = calloc(ncpu, sizeof(int64_t *));          cp_time = calloc(ncpu, sizeof(int64_t *));
         cp_old  = calloc(ncpu, sizeof(int64_t *));          cp_old  = calloc(ncpu, sizeof(int64_t *));
         cp_diff = calloc(ncpu, sizeof(int64_t *));          cp_diff = calloc(ncpu, sizeof(int64_t *));
Line 263 
Line 243 
 void  void
 get_system_info(struct system_info *si)  get_system_info(struct system_info *si)
 {  {
         static int cp_time_mib[] = {CTL_KERN, KERN_CPTIME2, /*fillme*/0};  
         static int sysload_mib[] = {CTL_VM, VM_LOADAVG};          static int sysload_mib[] = {CTL_VM, VM_LOADAVG};
         static int uvmexp_mib[] = {CTL_VM, VM_UVMEXP};          static int uvmexp_mib[] = {CTL_VM, VM_UVMEXP};
         static int bcstats_mib[] = {CTL_VFS, VFS_GENERIC, VFS_BCACHESTAT};          static int bcstats_mib[] = {CTL_VFS, VFS_GENERIC, VFS_BCACHESTAT};
Line 275 
Line 254 
         int i;          int i;
         int64_t *tmpstate;          int64_t *tmpstate;
   
         size = CPUSTATES * sizeof(int64_t);          if (ncpu > 1) {
         for (i = 0; i < ncpu; i++) {                  int cp_time_mib[] = {CTL_KERN, KERN_CPTIME2, /*fillme*/0};
                 cp_time_mib[2] = i;  
                 tmpstate = cpu_states + (CPUSTATES * i);                  size = CPUSTATES * sizeof(int64_t);
                 if (sysctl(cp_time_mib, 3, cp_time[i], &size, NULL, 0) < 0) {                  for (i = 0; i < ncpu; i++) {
                         if (errno != ENODEV)                          cp_time_mib[2] = i;
                           tmpstate = cpu_states + (CPUSTATES * i);
                           if (sysctl(cp_time_mib, 3, cp_time[i], &size, NULL, 0) < 0)
                                 warn("sysctl kern.cp_time2 failed");                                  warn("sysctl kern.cp_time2 failed");
                         cpu_online[i] = 0;                          /* convert cp_time2 counts to percentages */
                         continue;                          (void) percentages(CPUSTATES, tmpstate, cp_time[i],
                               cp_old[i], cp_diff[i]);
                 }                  }
                 cpu_online[i] = 1;          } else {
                 /* convert cp_time2 counts to percentages */                  int cp_time_mib[] = {CTL_KERN, KERN_CPTIME};
                 (void) percentages(CPUSTATES, tmpstate, cp_time[i],                  long cp_time_tmp[CPUSTATES];
                     cp_old[i], cp_diff[i]);  
                   size = sizeof(cp_time_tmp);
                   if (sysctl(cp_time_mib, 2, cp_time_tmp, &size, NULL, 0) < 0)
                           warn("sysctl kern.cp_time failed");
                   for (i = 0; i < CPUSTATES; i++)
                           cp_time[0][i] = cp_time_tmp[i];
                   /* convert cp_time counts to percentages */
                   (void) percentages(CPUSTATES, cpu_states, cp_time[0],
                       cp_old[0], cp_diff[0]);
         }          }
   
         size = sizeof(sysload);          size = sizeof(sysload);
Line 327 
Line 317 
   
         /* set arrays and strings */          /* set arrays and strings */
         si->cpustates = cpu_states;          si->cpustates = cpu_states;
         si->cpuonline = cpu_online;  
         si->memory = memory_stats;          si->memory = memory_stats;
         si->last_pid = -1;          si->last_pid = -1;
 }  }

Legend:
Removed from v.1.93  
changed lines
  Added in v.1.94