/** * @brief * initialize the platform-dependent topology information * * @return Void * */ void dep_initialize() { int i; static char mem[] = "/dev/kmem"; pagesize = getpagesize(); if ((pdir = opendir(procfs)) == NULL) { log_err(errno, __func__, "opendir"); return; } kern_addr[KSYM_PHYS] = SEEKLIMIT & sysmp(MP_KERNADDR, MPKA_PHYSMEM); kern_addr[KSYM_LOAD] = SEEKLIMIT & sysmp(MP_KERNADDR, MPKA_AVENRUN); if ((kfd = open(mem, O_RDONLY)) == -1) { log_err(errno, __func__, mem); return; } /* insure /dev/kmem closed on exec */ if ((i = fcntl(kfd, F_GETFD)) == -1) { log_err(errno, __func__, "F_GETFD"); } i |= FD_CLOEXEC; if (fcntl(kfd, F_SETFD, i) == -1) { log_err(errno, __func__, "F_SETFD"); } return; }
void KMemoryWidget::update() { int pagesize = getpagesize(); struct rminfo rmi; if( sysmp(MP_SAGET, MPSA_RMINFO, &rmi, sizeof(rmi)) == -1 ) return; Memory_Info[TOTAL_MEM] = MEMORY(rmi.physmem) * pagesize; // total physical memory (without swaps) Memory_Info[FREE_MEM] = MEMORY(rmi.freemem) * pagesize; // total free physical memory (without swaps) Memory_Info[BUFFER_MEM] = MEMORY(rmi.bufmem) * pagesize; //FIXME: Memory_Info[CACHED_MEM]" Memory_Info[CACHED_MEM] = NO_MEMORY_INFO; // cached memory in ram long val; swapctl(SC_GETSWAPTOT, &val); Memory_Info[SWAP_MEM] = MEMORY(val) * UBSIZE; // total size of all swap-partitions swapctl(SC_GETFREESWAP, &val); Memory_Info[FREESWAP_MEM] = MEMORY(val) * UBSIZE; // free memory in swap-partitions #ifndef MPKA_SHMINFO /* Irix 6.5 (also 6.4?) */ Memory_Info[SHARED_MEM] = NO_MEMORY_INFO; #else FILE *kmem = fopen("/dev/kmem", "r"); if( kmem == 0 ) { Memory_Info[SHARED_MEM] = NO_MEMORY_INFO; return; } long shmip = sysmp(MP_KERNADDR, MPKA_SHMINFO); fseek( kmem, shmip, 0 ); struct shminfo shmi; fread( &shmi, sizeof(shmi), 1, kmem ); long shmem = sysmp(MP_KERNADDR, MPKA_SHM); val = 0; long pos; struct shmid_ds shmid; for( int i=0 ; i<shmi.shmmni ; i++ ) { fseek( kmem, shmem, 0 ); shmem += sizeof(shmem); fread( &pos, sizeof(shmem), 1, kmem ); if(pos != 0) { fseek( kmem, pos, 0 ); fread( &shmid, sizeof(shmid), 1, kmem ); val += shmid.shm_segsz; } } Memory_Info[SHARED_MEM] = MEMORY(val); fclose(kmem); #endif }
void get_system_info(struct system_info * si) { int i; int avenrun[3]; struct rminfo realmem; struct sysinfo sysinfo; static time_t cp_old[CPU_STATES]; static time_t cp_diff[CPU_STATES]; /* for cpu state percentages */ off_t fswap; /* current free swap in blocks */ off_t tswap; /* total swap in blocks */ (void) getkval(avenrun_offset, (int *) avenrun, sizeof(avenrun), "avenrun"); for (i = 0; i < 3; i++) { si->load_avg[i] = loaddouble(avenrun[i]); si->load_avg[i] /= 1024.0; } if ((numcpus = sysmp(MP_NPROCS)) == -1) { perror("sysmp(MP_NPROCS)"); return; } if (sysmp(MP_SAGET, MPSA_RMINFO, &realmem, sizeof(realmem)) == -1) { perror("sysmp(MP_SAGET,MPSA_RMINFO, ...)"); return; } swapctl(SC_GETFREESWAP, &fswap); swapctl(SC_GETSWAPTOT, &tswap); memory_stats[0] = pagetok(realmem.physmem); memory_stats[1] = pagetok(realmem.availrmem); memory_stats[2] = pagetok(realmem.freemem); memory_stats[3] = tswap / 2; memory_stats[4] = fswap / 2; if (sysmp(MP_SAGET, MPSA_SINFO, &sysinfo, sizeof(struct sysinfo)) == -1) { perror("sysmp(MP_SAGET,MPSA_SINFO)"); return; } (void) percentages(CPU_STATES, cpu_states, sysinfo.cpu, cp_old, cp_diff); si->cpustates = cpu_states; si->memory = memory_stats; si->last_pid = -1; return; }
int ip_load(netsnmp_cache *cache, void *vmagic) { long ret_value = -1; int magic = (int) vmagic; switch (magic) { case IPFORWARDING: if (!auto_nlist (IP_FORWARDING_SYMBOL, (char *) &ret_value, sizeof(ret_value))) return -1; else return (ret_value ? 1 /* GATEWAY */ : 2 /* HOST */ ); case IPDEFAULTTTL: if (!auto_nlist (TCP_TTL_SYMBOL, (char *) &ret_value, sizeof(ret_value))) return -1; else return ret_value; default: ret_value = sysmp(MP_SAGET, MPSA_TCPIPSTATS, &ipstat, sizeof ipstat); if ( ret_value < 0 ) { DEBUGMSGTL(("mibII/ip", "Failed to load IP Group (tcpipstats)\n")); } else { DEBUGMSGTL(("mibII/ip", "Loaded IP Group (tcpipstats)\n")); } return ret_value; } }
double get_cpu_load() { static long cpu_new[CPUSTATES]; static long cpu_old[CPUSTATES]; static long cpu_diff[CPUSTATES]; double cpu_states[CPUSTATES]; double cpu_load; struct sysinfo sys_info; int i; if (sysmp(MP_SAGET, MPSA_SINFO, &sys_info, sizeof(struct sysinfo)) == -1) { return -1.0; } for (i = 0; i < CPUSTATES; i++) { cpu_new[i] = sys_info.cpu[i]; } percentages(CPUSTATES, cpu_states, cpu_new, cpu_old, cpu_diff); cpu_load = cpu_states[1] + cpu_states[2] + cpu_states[3] + cpu_states[4] + cpu_states[5]; if (cpu_load < 0.0) { cpu_load = -1.0; } return cpu_load; }
/* * System statistics collection routine */ void ComputeStatistics(void) { memcpy(&LastSysInfo, &SysInfo, sizeof(SysInfo)); sysmp(MP_SAGET, MPSA_SINFO, &SysInfo, sizeof(SysInfo)); sginap(nPeriod); glutPostRedisplay(); }
int main(int ac, char **av) { int i, prog; #ifdef sgi int ncpus = sysmp(MP_NPROCS); #endif for (i = 1; i < ac; ++i) { if (av[i][0] != '-') { break; } switch (av[i][1]) { case 'D': Dflg = 1; break; /* Allow directories */ case 'd': dflg = 1; break; /* debugging */ case 'f': fflg = atoi(&av[i][2]); break; /* # of threads */ case 'l': lflg = 1; break; /* logging */ case 'n': nflg = 1; break; /* fake file i/o */ case 'z': zflg = 1; break; /* all files are 0 size */ default: fprintf(stderr, "Barf.\n"); exit(1); } } if (getenv("DOCROOT")) { if (chdir(getenv("DOCROOT")) == -1) { perror(getenv("DOCROOT")); exit(1); } } if (atoi(av[ac - 1]) != 0) { prog = -atoi(av[ac - 1]); } else { prog = -80; } /* * Steve - why is this here? */ signal(SIGPIPE, SIG_IGN); data = tcp_server(prog, SOCKOPT_REUSE); bufs[0] = valloc(XFERSIZE); bufs[1] = valloc(XFERSIZE); bufs[2] = valloc(XFERSIZE); logfile = open(LOGFILE, O_CREAT|O_APPEND|O_WRONLY, 0666); signal(SIGINT, die); signal(SIGHUP, die); signal(SIGTERM, die); for (i = 1; i < fflg; ++i) { if (fork() <= 0) { break; } } handle_scheduler(i, 0, 0); worker(); return(0); }
wxMemorySize wxGetFreeMemory() { #if defined(__LINUX__) // get it from /proc/meminfo FILE *fp = fopen("/proc/meminfo", "r"); if ( fp ) { long memFree = -1; char buf[1024]; if ( fgets(buf, WXSIZEOF(buf), fp) && fgets(buf, WXSIZEOF(buf), fp) ) { // /proc/meminfo changed its format in kernel 2.6 if ( wxPlatformInfo().CheckOSVersion(2, 6) ) { unsigned long cached, buffers; sscanf(buf, "MemFree: %ld", &memFree); fgets(buf, WXSIZEOF(buf), fp); sscanf(buf, "Buffers: %lu", &buffers); fgets(buf, WXSIZEOF(buf), fp); sscanf(buf, "Cached: %lu", &cached); // add to "MemFree" also the "Buffers" and "Cached" values as // free(1) does as otherwise the value never makes sense: for // kernel 2.6 it's always almost 0 memFree += buffers + cached; // values here are always expressed in kB and we want bytes memFree *= 1024; } else // Linux 2.4 (or < 2.6, anyhow) { long memTotal, memUsed; sscanf(buf, "Mem: %ld %ld %ld", &memTotal, &memUsed, &memFree); } } fclose(fp); return (wxMemorySize)memFree; } #elif defined(__SGI__) struct rminfo realmem; if ( sysmp(MP_SAGET, MPSA_RMINFO, &realmem, sizeof realmem) == 0 ) return ((wxMemorySize)realmem.physmem * sysconf(_SC_PAGESIZE)); #elif defined(_SC_AVPHYS_PAGES) return ((wxMemorySize)sysconf(_SC_AVPHYS_PAGES))*sysconf(_SC_PAGESIZE); //#elif defined(__FREEBSD__) -- might use sysctl() to find it out, probably #endif // can't find it out return -1; }
static int get_extended_mem_sgi(memory_ext *me) { struct rminfo rmi; if (sysmp(MP_SAGET, MPSA_RMINFO, &rmi, sizeof(rmi)) < 0) return -1; me->total = (unsigned long)(rmi.physmem); me->free = (unsigned long)(rmi.freemem); me->pagesize = (unsigned long)getpagesize(); me->flag = F_MEM_TOTAL | F_MEM_FREE; return 1; }
/** * @brief * query_cpusets() * Ask for a list of cpusets currently running on the system. If a pointer * to a Bitfield was given, fill in the nodes in the bitfield with the union * of the nodes used in the current cpusets. The input bitfield is not * cleared. * * @param[in] listp - pointer to cpusets * @param[in] maskp - pointer to bit mask * * @par Note: * Cpusets are added to the tail of the list pointed to by listp if non-NULL, * and the total number of cpusets found is returned. * * @return int * @retval -1 error(with errno left as set by sysmp()) * @retval count of cpuset */ int query_cpusets(cpusetlist **listp, Bitfield *maskp) { cpuset_NameList_t *names; char qname[QNAME_STRING_LEN + 1]; int i, ret, count = 0; Bitfield nodes; if (sysmp(MP_NPROCS) < 1) { log_err(errno, __func__, "sysmp(MP_NPROCS"); return -1; /* "This can't happen." */ } /* Get the list of names else print error & exit */ if ((names = cpusetGetNameList()) == NULL) { log_err(errno, __func__, "cpusetGetNameList"); return (-1); } for (i = 0; i < names->count; i++) { if (names->status[i] != CPUSET_QUEUE_NAME) continue; if (listp) { /* Add to supplied list? */ (void)strncpy(qname, names->list[i], QNAME_STRING_LEN); qname[QNAME_STRING_LEN] = '\0'; /* Query the kernel for the nodes for this cpuset. */ if (cpuset2bitfield(qname, &nodes)) continue; ret = add_to_cpusetlist(listp, qname, &nodes, NULL); if (ret < 0) /* Cpuset not found -- race condition? */ continue; if (ret > 0) /* Error in list manipulation - give up. */ break; /* Add the nodes for this cpuset into the specified bitmask. */ if (maskp) BITFIELD_SETM(maskp, &nodes); } count ++; } return count; }
int udp_load(netsnmp_cache *cache, void *vmagic) { long ret_value = -1; ret_value = sysmp(MP_SAGET, MPSA_TCPIPSTATS, &udpstat, sizeof(udpstat)); if ( ret_value < 0 ) { DEBUGMSGTL(("mibII/udpScalar", "Failed to load UDP scalar Group (tcpipstats)\n")); } else { DEBUGMSGTL(("mibII/udpScalar", "Loaded UDP scalar Group (tcpipstats)\n")); } return ret_value; }
/* * Sets up for later queries. Open the kernel memory file and find the * address of the necessary variable. Exits on error. */ static int kernel_open(void) { int ldav_off; kmem_fd = open("/dev/kmem", O_RDONLY); if (kmem_fd < 0) sysdie("cannot open /dev/kmem"); ldav_off = sysmp(MP_KERNADDR, MPKA_AVENRUN); if (ldav_off < 0) sysdie("sysmp failed"); kernel_offset = (long) ldav_off & 0x7fffffff; kernel_init = 1; }
int icmp_load(netsnmp_cache *cache, void *vmagic) { long ret_value = -1; ret_value = sysmp(MP_SAGET, MPSA_TCPIPSTATS, &icmpstat, sizeof icmpstat); if ( ret_value < 0 ) { DEBUGMSGTL(("mibII/icmp", "Failed to load ICMP Group (tcpipstats)\n")); } else { DEBUGMSGTL(("mibII/icmp", "Loaded ICMP Group (tcpipstats)\n")); } return ret_value; }
int create_daemons(int p[][2], int pids[], int procs) { int i, j; int msg; /* * Use the pipes as a ring, and fork off a bunch of processes * to pass the byte through their part of the ring. * * Do the sum in each process and get that time before moving on. */ signal(SIGTERM, SIG_IGN); bzero(pids, procs * sizeof(pid_t)); for (i = 1; i < procs; ++i) { switch (pids[i] = fork()) { case -1: /* could not fork, out of processes? */ procs = i; break; case 0: /* child */ #if defined(sgi) && defined(PIN) sysmp(MP_MUSTRUN, i % ncpus); #endif for (j = 0; j < procs; ++j) { if (j != i-1) close(p[j][0]); if (j != i) close(p[j][1]); } doit(p, i-1, i); /* NOTREACHED */ default: /* parent */ ; } } /* * Go once around the loop to make sure that everyone is ready and * to get the token in the pipeline. */ if (write(p[0][1], &msg, sizeof(msg)) != sizeof(msg) || read(p[procs-1][0], &msg, sizeof(msg)) != sizeof(msg)) { if (errno) perror("write/read/write on pipe"); exit(1); } if (data) bzero((void*)data, process_size); return procs; }
static void get_basic_mem(unsigned long *tot, unsigned long *used, unsigned long *pagesize){ #if defined(_SC_AVPHYS_PAGES) /* Does this exist on others than Solaris2? */ unsigned long avPhys, phys, pgSz; phys = sysconf(_SC_PHYS_PAGES); avPhys = sysconf(_SC_AVPHYS_PAGES); *used = (phys - avPhys); *tot = phys; *pagesize = sysconf(_SC_PAGESIZE); #elif defined(__linux__) && !defined(_SC_AVPHYS_PAGES) memory_ext me; if (get_mem_procfs(&me) < 0) { print_error("ProcFS read error"); exit(1); } *tot = me.total; *pagesize = me.pagesize; *used = me.total - me.free; #elif defined(BSD4_4) struct vmtotal vt; long pgsz; if (!get_vmtotal(&vt)) goto fail; if ((pgsz = sysconf(_SC_PAGESIZE)) == -1) goto fail; *tot = (vt.t_free + vt.t_rm); *used = vt.t_rm; *pagesize = pgsz; return; fail: print_error("%s", strerror(errno)); exit(1); #elif defined(sgi) || defined(__sgi) || defined(__sgi__) struct rminfo rmi; if (sysmp(MP_SAGET, MPSA_RMINFO, &rmi, sizeof(rmi)) != -1) { *tot = (unsigned long)(rmi.physmem); *used = (unsigned long)(rmi.physmem - rmi.freemem); *pagesize = (unsigned long)getpagesize(); } else { print_error("%s", strerror(errno)); exit(1); } #else /* SunOS4 */ *used = (1<<27); /* Fake! 128 MB used */ *tot = (1<<28); /* Fake! 256 MB total */ *pagesize = 1; #endif }
static int sge_get_kernel_address(char *name, long *address) { int ret = 0; DENTER(TOP_LAYER, "sge_get_kernel_address"); #if defined(IRIX) if (!strcmp(KERNEL_AVG_NAME, name)) { *address = sysmp(MP_KERNADDR, MPKA_AVENRUN); ret = 1; } else { *address = 0; ret = 0; } #else { # if defined(AIX51) struct nlist64 kernel_nlist[2]; # else struct nlist kernel_nlist[2]; # endif kernel_nlist[0].n_name = name; kernel_nlist[1].n_name = NULL; # if defined(ALPHA4) || defined(ALPHA5) || defined(HPUX) if (nlist(KERNEL_NAME_FILE, kernel_nlist) >= 0) # elif defined(AIX51) if (nlist64(KERNEL_NAME_FILE, kernel_nlist) >= 0) # else if (kernel_initialized && (kvm_nlist(kernel_fd, kernel_nlist) >= 0)) # endif { *address = kernel_nlist[0].n_value; ret = 1; } else { DPRINTF(("nlist(%s) failed: %s\n", name, strerror(errno))); *address = 0; ret = 0; } } #endif DEXIT; return ret; }
double taucs_system_memory_size() { double m; struct rminfo p; m = (double) sysconf(_SC_PAGESIZE); /*m = (double) getpagesize();*/ taucs_printf("***************** %.0lf ************\n",m); if (sysmp(MP_SAGET, MPSA_RMINFO, &p) == -1) { perror("sysmp"); exit(1); } m = (double) (p.physmem); taucs_printf("**$$$* %.0lf\n",m); return m; }
int getla(void) { static int kmem = -1; int avenrun[3]; if (kmem < 0) { kmem = open(_PATH_KMEM, 0, 0); if (kmem < 0) return -1; (void) fcntl(kmem, F_SETFD, 1); } if (lseek(kmem, (sysmp(MP_KERNADDR, MPKA_AVENRUN) & 0x7fffffff), SEEK_SET) == -1 || read(kmem, (char *) avenrun, sizeof(avenrun)) < sizeof(avenrun)) return -1; return ((int) (avenrun[0] + FSCALE / 2) >> FSHIFT); }
long read_ip_stat(IP_STAT_STRUCTURE * ipstat, int magic) { long ret_value = 0; #if (defined(CAN_USE_SYSCTL) && defined(IPCTL_STATS)) int i; #endif #if !(defined (linux) || defined(solaris2)) static int ttl, forward; #endif #ifdef hpux11 int fd; struct nmparms p; unsigned int ulen; #endif #if (defined(CAN_USE_SYSCTL) && defined(IPCTL_STATS)) static int sname[4] = { CTL_NET, PF_INET, IPPROTO_IP, 0 }; size_t len; #endif #ifdef hpux11 if ((fd = open_mib("/dev/ip", O_RDONLY, 0, NM_ASYNC_OFF)) < 0) return (-1); /* error */ switch (magic) { case IPFORWARDING: p.objid = ID_ipForwarding; break; case IPDEFAULTTTL: p.objid = ID_ipDefaultTTL; break; case IPINRECEIVES: p.objid = ID_ipInReceives; break; case IPINHDRERRORS: p.objid = ID_ipInHdrErrors; break; case IPINADDRERRORS: p.objid = ID_ipInAddrErrors; break; case IPFORWDATAGRAMS: p.objid = ID_ipForwDatagrams; break; case IPINUNKNOWNPROTOS: p.objid = ID_ipInUnknownProtos; break; case IPINDISCARDS: p.objid = ID_ipInDiscards; break; case IPINDELIVERS: p.objid = ID_ipInDelivers; break; case IPOUTREQUESTS: p.objid = ID_ipOutRequests; break; case IPOUTDISCARDS: p.objid = ID_ipOutDiscards; break; case IPOUTNOROUTES: p.objid = ID_ipOutNoRoutes; break; case IPREASMTIMEOUT: p.objid = ID_ipReasmTimeout; break; case IPREASMREQDS: p.objid = ID_ipReasmReqds; break; case IPREASMOKS: p.objid = ID_ipReasmOKs; break; case IPREASMFAILS: p.objid = ID_ipReasmFails; break; case IPFRAGOKS: p.objid = ID_ipFragOKs; break; case IPFRAGFAILS: p.objid = ID_ipFragFails; break; case IPFRAGCREATES: p.objid = ID_ipFragCreates; break; case IPROUTEDISCARDS: p.objid = ID_ipRoutingDiscards; break; default: *ipstat = 0; close_mib(fd); return (0); } p.buffer = (void *) ipstat; ulen = sizeof(IP_STAT_STRUCTURE); p.len = &ulen; ret_value = get_mib_info(fd, &p); close_mib(fd); return (ret_value); /* 0: ok, < 0: error */ #else /* hpux11 */ if (ip_stats_cache_marker && (!atime_ready (ip_stats_cache_marker, IP_STATS_CACHE_TIMEOUT * 1000))) #if !(defined(linux) || defined(solaris2)) return ((magic == IPFORWARDING ? forward : (magic == IPDEFAULTTTL ? ttl : 0))); #else return 0; #endif if (ip_stats_cache_marker) atime_setMarker(ip_stats_cache_marker); else ip_stats_cache_marker = atime_newMarker(); #ifdef linux ret_value = linux_read_ip_stat(ipstat); #endif #ifdef solaris2 ret_value = getMibstat(MIB_IP, ipstat, sizeof(mib2_ip_t), GET_FIRST, &Get_everything, NULL); #endif #ifdef WIN32 ret_value = GetIpStatistics(ipstat); #endif #if !(defined(linux) || defined(solaris2) || defined(WIN32)) if (magic == IPFORWARDING) { #if defined(CAN_USE_SYSCTL) && defined(IPCTL_STATS) len = sizeof i; sname[3] = IPCTL_FORWARDING; if (sysctl(sname, 4, &i, &len, 0, 0) < 0) forward = -1; else forward = (i ? 1 /* GATEWAY */ : 2 /* HOST */ ); #else if (!auto_nlist (IP_FORWARDING_SYMBOL, (char *) &ret_value, sizeof(ret_value))) forward = -1; else forward = (ret_value ? 1 /* GATEWAY */ : 2 /* HOST */ ); #endif if (forward == -1) { free(ip_stats_cache_marker); ip_stats_cache_marker = NULL; } return forward; } if (magic == IPDEFAULTTTL) { #if (defined(CAN_USE_SYSCTL) && defined(IPCTL_STATS)) len = sizeof i; sname[3] = IPCTL_DEFTTL; if (sysctl(sname, 4, &i, &len, 0, 0) < 0) ttl = -1; else ttl = i; #else if (!auto_nlist (TCP_TTL_SYMBOL, (char *) &ret_value, sizeof(ret_value))) ttl = -1; else ttl = ret_value; #endif if (ttl == -1) { free(ip_stats_cache_marker); ip_stats_cache_marker = NULL; } return ttl; } #ifdef HAVE_SYS_TCPIPSTATS_H ret_value = sysmp(MP_SAGET, MPSA_TCPIPSTATS, ipstat, sizeof *ipstat); #endif #if (defined(CAN_USE_SYSCTL) && defined(IPCTL_STATS)) len = sizeof *ipstat; sname[3] = IPCTL_STATS; ret_value = sysctl(sname, 4, ipstat, &len, 0, 0); #endif #ifdef IPSTAT_SYMBOL if (auto_nlist(IPSTAT_SYMBOL, (char *) ipstat, sizeof(*ipstat))) ret_value = 0; #endif #endif /* !(defined(linux) || defined(solaris2)) */ if (ret_value == -1) { free(ip_stats_cache_marker); ip_stats_cache_marker = NULL; } return ret_value; #endif /* hpux11 */ }
wxMemorySize wxGetFreeMemory() { #if defined(__LINUX__) // get it from /proc/meminfo FILE *fp = fopen("/proc/meminfo", "r"); if ( fp ) { wxMemorySize memFreeBytes = (wxMemorySize)-1; char buf[1024]; if ( fgets(buf, WXSIZEOF(buf), fp) && fgets(buf, WXSIZEOF(buf), fp) ) { // /proc/meminfo changed its format in kernel 2.6 if ( wxPlatformInfo().CheckOSVersion(2, 6) ) { unsigned long memFree; if ( sscanf(buf, "MemFree: %lu", &memFree) == 1 ) { // We consider memory used by the IO buffers and cache as // being "free" too as Linux aggressively uses free memory // for caching and the amount of memory reported as really // free is far too low for lightly loaded system. if ( fgets(buf, WXSIZEOF(buf), fp) ) { unsigned long buffers; if ( sscanf(buf, "Buffers: %lu", &buffers) == 1 ) memFree += buffers; } if ( fgets(buf, WXSIZEOF(buf), fp) ) { unsigned long cached; if ( sscanf(buf, "Cached: %lu", &cached) == 1 ) memFree += cached; } // values here are always expressed in kB and we want bytes memFreeBytes = memFree; memFreeBytes *= 1024; } } else // Linux 2.4 (or < 2.6, anyhow) { long memTotal, memUsed, memFree; if ( sscanf(buf, "Mem: %ld %ld %ld", &memTotal, &memUsed, &memFree) == 3 ) { memFreeBytes = memFree; } } } fclose(fp); return memFreeBytes; } #elif defined(__SGI__) struct rminfo realmem; if ( sysmp(MP_SAGET, MPSA_RMINFO, &realmem, sizeof realmem) == 0 ) return ((wxMemorySize)realmem.physmem * sysconf(_SC_PAGESIZE)); #elif defined(_SC_AVPHYS_PAGES) return ((wxMemorySize)sysconf(_SC_AVPHYS_PAGES))*sysconf(_SC_PAGESIZE); //#elif defined(__FREEBSD__) -- might use sysctl() to find it out, probably #endif // can't find it out return -1; }
int getloadavg (double loadavg[], int nelem) { int elem = 0; /* Return value. */ #ifdef NO_GET_LOAD_AVG #define LDAV_DONE /* Set errno to zero to indicate that there was no particular error; this function just can't work at all on this system. */ errno = 0; elem = -2; #endif /* NO_GET_LOAD_AVG */ #if ! defined (LDAV_DONE) && defined (HAVE_KSTAT_H) && defined (HAVE_LIBKSTAT) #define LDAV_DONE /* getloadavg is best implemented using kstat (kernel stats), on systems (like SunOS5) that support it, since you don't need special privileges to use it. Initial implementation courtesy Zlatko Calusic <*****@*****.**>. Integrated to XEmacs by Hrvoje Niksic <*****@*****.**>. Additional cleanup by Hrvoje Niksic, based on code published by Casper Dik <*****@*****.**>. */ kstat_ctl_t *kc; kstat_t *ksp; static char *avestrings[] = { "avenrun_1min", "avenrun_5min", "avenrun_15min" }; if (nelem > countof (avestrings)) nelem = countof (avestrings); kc = kstat_open (); if (!kc) return -1; ksp = kstat_lookup (kc, "unix", 0, "system_misc"); if (!ksp) { kstat_close (kc); return -1; } if (kstat_read (kc, ksp, 0) < 0) { kstat_close (kc); return -1; } for (elem = 0; elem < nelem; elem++) { kstat_named_t *kn = (kstat_named_t *) kstat_data_lookup (ksp, avestrings[elem]); if (!kn) { kstat_close (kc); return -1; } loadavg[elem] = (double)kn->value.ul / FSCALE; } kstat_close (kc); #endif /* HAVE_KSTAT_H && HAVE_LIBKSTAT */ #if !defined (LDAV_DONE) && defined (HAVE_SYS_PSTAT_H) #define LDAV_DONE /* This is totally undocumented, and is not guaranteed to work, but mayhap it might .... If it does work, it will work only on HP-UX 8.0 or later. -- Darryl Okahata <*****@*****.**> */ #undef LOAD_AVE_TYPE /* Make sure these don't exist. */ #undef LOAD_AVE_CVT #undef LDAV_SYMBOL struct pst_dynamic procinfo; union pstun statbuf; statbuf.pst_dynamic = &procinfo; if (pstat (PSTAT_DYNAMIC, statbuf, sizeof (struct pst_dynamic), 0, 0) == -1) return (-1); loadavg[elem++] = procinfo.psd_avg_1_min; loadavg[elem++] = procinfo.psd_avg_5_min; loadavg[elem++] = procinfo.psd_avg_15_min; #endif /* HPUX */ #if !defined (LDAV_DONE) && defined (__linux__) #define LDAV_DONE #undef LOAD_AVE_TYPE #ifndef LINUX_LDAV_FILE #define LINUX_LDAV_FILE "/proc/loadavg" #endif char ldavgbuf[40]; double load_ave[3]; int fd, count; fd = open (LINUX_LDAV_FILE, O_RDONLY); if (fd == -1) return -1; count = read (fd, ldavgbuf, 40); (void) close (fd); if (count <= 0) return -1; count = sscanf (ldavgbuf, "%lf %lf %lf", &load_ave[0], &load_ave[1], &load_ave[2]); if (count < 1) return -1; for (elem = 0; elem < nelem && elem < count; elem++) loadavg[elem] = load_ave[elem]; #endif /* __linux__ */ #if !defined (LDAV_DONE) && defined (__NetBSD__) || defined (__OpenBSD__) #define LDAV_DONE #undef LOAD_AVE_TYPE #ifndef NETBSD_LDAV_FILE #define NETBSD_LDAV_FILE "/kern/loadavg" #endif unsigned long int load_ave[3], scale; int count; FILE *fp; fp = fopen (NETBSD_LDAV_FILE, "r"); if (fp == NULL) return -1; count = fscanf (fp, "%lu %lu %lu %lu\n", &load_ave[0], &load_ave[1], &load_ave[2], &scale); (void) fclose (fp); if (count != 4) return -1; for (elem = 0; elem < nelem; elem++) loadavg[elem] = (double) load_ave[elem] / (double) scale; #endif /* __NetBSD__ or __OpenBSD__ */ #if !defined (LDAV_DONE) && defined (NeXT) #define LDAV_DONE /* The NeXT code was adapted from iscreen 3.2. */ host_t host; struct processor_set_basic_info info; unsigned info_count; /* We only know how to get the 1-minute average for this system, so even if the caller asks for more than 1, we only return 1. */ if (!getloadavg_initialized) { if (processor_set_default (host_self (), &default_set) == KERN_SUCCESS) getloadavg_initialized = 1; } if (getloadavg_initialized) { info_count = PROCESSOR_SET_BASIC_INFO_COUNT; if (processor_set_info (default_set, PROCESSOR_SET_BASIC_INFO, &host, (processor_set_info_t) &info, &info_count) != KERN_SUCCESS) getloadavg_initialized = 0; else { if (nelem > 0) loadavg[elem++] = (double) info.load_average / LOAD_SCALE; } } if (!getloadavg_initialized) return -1; #endif /* NeXT */ #if !defined (LDAV_DONE) && defined (UMAX) #define LDAV_DONE /* UMAX 4.2, which runs on the Encore Multimax multiprocessor, does not have a /dev/kmem. Information about the workings of the running kernel can be gathered with inq_stats system calls. We only know how to get the 1-minute average for this system. */ struct proc_summary proc_sum_data; struct stat_descr proc_info; double load; REGISTER unsigned int i, j; if (cpus == 0) { REGISTER unsigned int c, i; struct cpu_config conf; struct stat_descr desc; desc.sd_next = 0; desc.sd_subsys = SUBSYS_CPU; desc.sd_type = CPUTYPE_CONFIG; desc.sd_addr = (char *) &conf; desc.sd_size = sizeof conf; if (inq_stats (1, &desc)) return -1; c = 0; for (i = 0; i < conf.config_maxclass; ++i) { struct class_stats stats; memset ((char *) &stats, 0, sizeof stats); desc.sd_type = CPUTYPE_CLASS; desc.sd_objid = i; desc.sd_addr = (char *) &stats; desc.sd_size = sizeof stats; if (inq_stats (1, &desc)) return -1; c += stats.class_numcpus; } cpus = c; samples = cpus < 2 ? 3 : (2 * cpus / 3); } proc_info.sd_next = 0; proc_info.sd_subsys = SUBSYS_PROC; proc_info.sd_type = PROCTYPE_SUMMARY; proc_info.sd_addr = (char *) &proc_sum_data; proc_info.sd_size = sizeof (struct proc_summary); proc_info.sd_sizeused = 0; if (inq_stats (1, &proc_info) != 0) return -1; load = proc_sum_data.ps_nrunnable; j = 0; for (i = samples - 1; i > 0; --i) { load += proc_sum_data.ps_nrun[j]; if (j++ == PS_NRUNSIZE) j = 0; } if (nelem > 0) loadavg[elem++] = load / samples / cpus; #endif /* UMAX */ #if !defined (LDAV_DONE) && defined (DGUX) #define LDAV_DONE /* This call can return -1 for an error, but with good args it's not supposed to fail. The first argument is for no apparent reason of type `long int *'. */ dg_sys_info ((long int *) &load_info, DG_SYS_INFO_LOAD_INFO_TYPE, DG_SYS_INFO_LOAD_VERSION_0); if (nelem > 0) loadavg[elem++] = load_info.one_minute; if (nelem > 1) loadavg[elem++] = load_info.five_minute; if (nelem > 2) loadavg[elem++] = load_info.fifteen_minute; #endif /* DGUX */ #if !defined (LDAV_DONE) && defined (OSF_MIPS) #define LDAV_DONE struct tbl_loadavg load_ave; table (TBL_LOADAVG, 0, &load_ave, 1, sizeof (load_ave)); loadavg[elem++] = (load_ave.tl_lscale == 0 ? load_ave.tl_avenrun.d[0] : (load_ave.tl_avenrun.l[0] / (double) load_ave.tl_lscale)); #endif /* OSF_MIPS */ #if !defined (LDAV_DONE) && (defined (WIN32_NATIVE) || defined (CYGWIN)) #define LDAV_DONE /* A faithful emulation is going to have to be saved for a rainy day. */ for ( ; elem < nelem; elem++) { loadavg[elem] = 0.0; } #endif /* WIN32_NATIVE or CYGWIN */ #if !defined (LDAV_DONE) && defined (OSF_ALPHA) #define LDAV_DONE struct tbl_loadavg load_ave; table (TBL_LOADAVG, 0, &load_ave, 1, sizeof (load_ave)); for (elem = 0; elem < nelem; elem++) loadavg[elem] = (load_ave.tl_lscale == 0 ? load_ave.tl_avenrun.d[elem] : (load_ave.tl_avenrun.l[elem] / (double) load_ave.tl_lscale)); #endif /* OSF_ALPHA */ #if !defined (LDAV_DONE) && defined(LOAD_AVE_TYPE) /* UNIX-specific code -- read the average from /dev/kmem. */ #define LDAV_PRIVILEGED /* This code requires special installation. */ LOAD_AVE_TYPE load_ave[3]; /* Get the address of LDAV_SYMBOL. */ if (offset == 0) { #ifndef sgi #ifndef NLIST_STRUCT strcpy (nl[0].n_name, LDAV_SYMBOL); strcpy (nl[1].n_name, ""); #else /* NLIST_STRUCT */ #ifdef NLIST_NAME_UNION nl[0].n_un.n_name = LDAV_SYMBOL; nl[1].n_un.n_name = 0; #else /* not NLIST_NAME_UNION */ nl[0].n_name = (char *) LDAV_SYMBOL; nl[1].n_name = 0; #endif /* not NLIST_NAME_UNION */ #endif /* NLIST_STRUCT */ #ifndef SUNOS_5 if ( #if !(defined (_AIX) && !defined (ps2)) nlist (KERNEL_FILE, nl) #else /* _AIX */ knlist (nl, 1, sizeof (nl[0])) #endif >= 0) /* Omit "&& nl[0].n_type != 0 " -- it breaks on Sun386i. */ { #ifdef FIXUP_KERNEL_SYMBOL_ADDR FIXUP_KERNEL_SYMBOL_ADDR (nl); #endif offset = nl[0].n_value; } #endif /* !SUNOS_5 */ #else /* sgi */ int ldav_off; ldav_off = sysmp (MP_KERNADDR, MPKA_AVENRUN); if (ldav_off != -1) offset = (long) ldav_off & 0x7fffffff; #endif /* sgi */ } /* Make sure we have /dev/kmem open. */ if (!getloadavg_initialized) { #ifndef SUNOS_5 channel = open ("/dev/kmem", 0); if (channel >= 0) { /* Set the channel to close on exec, so it does not litter any child's descriptor table. */ #ifdef FD_SETFD #ifndef FD_CLOEXEC #define FD_CLOEXEC 1 #endif (void) fcntl (channel, F_SETFD, FD_CLOEXEC); #endif getloadavg_initialized = 1; } #else /* SUNOS_5 */ /* We pass 0 for the kernel, corefile, and swapfile names to use the currently running kernel. */ kd = kvm_open (0, 0, 0, O_RDONLY, 0); if (kd != 0) { /* nlist the currently running kernel. */ kvm_nlist (kd, nl); offset = nl[0].n_value; getloadavg_initialized = 1; } #endif /* SUNOS_5 */ } /* If we can, get the load average values. */ if (offset && getloadavg_initialized) { /* Try to read the load. */ #ifndef SUNOS_5 if (lseek (channel, offset, 0) == -1L || read (channel, (char *) load_ave, sizeof (load_ave)) != sizeof (load_ave)) { close (channel); getloadavg_initialized = 0; } #else /* SUNOS_5 */ if (kvm_read (kd, offset, (char *) load_ave, sizeof (load_ave)) != sizeof (load_ave)) { kvm_close (kd); getloadavg_initialized = 0; } #endif /* SUNOS_5 */ } if (offset == 0 || !getloadavg_initialized) return -1; if (nelem > 0) loadavg[elem++] = LDAV_CVT (load_ave[0]); if (nelem > 1) loadavg[elem++] = LDAV_CVT (load_ave[1]); if (nelem > 2) loadavg[elem++] = LDAV_CVT (load_ave[2]); #define LDAV_DONE #endif /* !LDAV_DONE && LOAD_AVE_TYPE */ return elem; }
int main(int ac, char **av) { int i, max_procs; double overhead = 0; if (ac < 2) { usage: printf("Usage: %s [-s kbytes] processes [processes ...]\n", av[0]); exit(1); } /* * Need 4 byte ints. */ if (sizeof(int) != 4) { fprintf(stderr, "Fix sumit() in ctx.c.\n"); exit(1); } /* * If they specified a context size, get it. */ if (!strcmp(av[1], "-s")) { if (ac < 4) { goto usage; } process_size = atoi(av[2]) * 1024; if (process_size > 0) { data = (int *)calloc(1, max(process_size, CHUNK)); BENCHO(sumit(CHUNK), sumit(0), 0); overhead = gettime(); overhead /= get_n(); overhead *= process_size; overhead /= CHUNK; } ac -= 2; av += 2; } #if defined(sgi) && defined(PIN) ncpus = sysmp(MP_NPROCS); sysmp(MP_MUSTRUN, 0); #endif for (max_procs = atoi(av[1]), i = 1; i < ac; ++i) { int procs = atoi(av[i]); if (max_procs < procs) max_procs = procs; } max_procs = create_pipes(p, max_procs); overhead += pipe_cost(p, max_procs); max_procs = create_daemons(p, pids, max_procs); fprintf(stderr, "\n\"size=%dk ovr=%.2f\n", process_size/1024, overhead); for (i = 1; i < ac; ++i) { double time; int procs = atoi(av[i]); if (procs > max_procs) continue; BENCH(ctx(procs, max_procs), 0); time = usecs_spent(); time /= get_n(); time /= procs; time /= TRIPS; time -= overhead; fprintf(stderr, "%d %.2f\n", procs, time); } /* * Close the pipes and kill the children. */ killem(max_procs); for (i = 0; i < max_procs; ++i) { close(p[i][0]); close(p[i][1]); if (i > 0) { wait(0); } } return (0); }
int machine_init(struct statics * statics) { struct oldproc *op, *endbase; int pcnt = 0; struct utsname utsname; char tmpbuf[20]; uname(&utsname); irix_ver = (float) atof((const char *) utsname.release); strncpy(tmpbuf, utsname.release, 9); tmpbuf[9] = '\0'; sprintf(uname_str, "%s %-.14s %s %s", utsname.sysname, utsname.nodename, tmpbuf, utsname.machine); pagesize = getpagesize(); if ((kmem = open(KMEM, O_RDONLY)) == -1) { perror(KMEM); return -1; } if (chdir(_PATH_PROCFSPI)) { /* handy for later on when we're reading it */ (void) fprintf(stderr, "%s: Unable to chdir to %s\n", myname, _PATH_PROCFSPI); return -1; } if ((procdir = opendir(".")) == NULL) { (void) fprintf(stderr, "%s: Unable to open %s\n", myname, _PATH_PROCFSPI); return -1; } if ((avenrun_offset = sysmp(MP_KERNADDR, MPKA_AVENRUN)) == -1) { perror("sysmp(MP_KERNADDR, MPKA_AVENRUN)"); return -1; } allocate_proc_tables(); oldprocs = 2 * nproc; endbase = oldbase + oldprocs; for (op = oldbase; op < endbase; op++) { op->oldpid = -1; } statics->cpustate_names = cpustatenames; statics->memory_names = memorynames; statics->order_names = ordernames; statics->procstate_names = procstatenames; return (0); }
/* Return the amount of physical memory available. */ double physmem_available (void) { #if defined _SC_AVPHYS_PAGES && defined _SC_PAGESIZE { /* This works on linux-gnu, solaris2 and cygwin. */ double pages = sysconf (_SC_AVPHYS_PAGES); double pagesize = sysconf (_SC_PAGESIZE); if (0 <= pages && 0 <= pagesize) return pages * pagesize; } #endif #if HAVE_PSTAT_GETSTATIC && HAVE_PSTAT_GETDYNAMIC { /* This works on hpux11. */ struct pst_static pss; struct pst_dynamic psd; if (0 <= pstat_getstatic (&pss, sizeof pss, 1, 0) && 0 <= pstat_getdynamic (&psd, sizeof psd, 1, 0)) { double pages = psd.psd_free; double pagesize = pss.page_size; if (0 <= pages && 0 <= pagesize) return pages * pagesize; } } #endif #if HAVE_SYSMP && defined MP_SAGET && defined MPSA_RMINFO && defined _SC_PAGESIZE { /* This works on irix6. */ struct rminfo realmem; if (sysmp (MP_SAGET, MPSA_RMINFO, &realmem, sizeof realmem) == 0) { double pagesize = sysconf (_SC_PAGESIZE); double pages = realmem.availrmem; if (0 <= pages && 0 <= pagesize) return pages * pagesize; } } #endif #if HAVE_TABLE && defined TBL_VMSTATS { /* This works on Tru64 UNIX V4/5. */ struct tbl_vmstats vmstats; if (table (TBL_VMSTATS, 0, &vmstats, 1, sizeof (vmstats)) == 1) { double pages = vmstats.free_count; double pagesize = vmstats.pagesize; if (0 <= pages && 0 <= pagesize) return pages * pagesize; } } #endif #if HAVE_SYSCTL && defined HW_USERMEM { /* This works on *bsd and darwin. */ unsigned int usermem; size_t len = sizeof usermem; static int mib[2] = { CTL_HW, HW_USERMEM }; if (sysctl (mib, ARRAY_SIZE (mib), &usermem, &len, NULL, 0) == 0 && len == sizeof (usermem)) return (double) usermem; } #endif #if defined _WIN32 { /* this works on windows */ PFN_MS_EX pfnex; HMODULE h = GetModuleHandle ("kernel32.dll"); if (!h) return 0.0; /* Use GlobalMemoryStatusEx if available. */ if ((pfnex = (PFN_MS_EX) GetProcAddress (h, "GlobalMemoryStatusEx"))) { lMEMORYSTATUSEX lms_ex; lms_ex.dwLength = sizeof lms_ex; if (!pfnex (&lms_ex)) return 0.0; return (double) lms_ex.ullAvailPhys; } /* Fall back to GlobalMemoryStatus which is always available. but returns wrong results for physical memory > 4GB */ else { MEMORYSTATUS ms; GlobalMemoryStatus (&ms); return (double) ms.dwAvailPhys; } } #endif /* Guess 25% of physical memory. */ return physmem_total () / 4; }
/** * @brief * read nodes and get topology * */ void schd_get_topology(void) { char *whoami = "schd_get_topology"; DIR *dirp; struct dirent *dent; char *digits ="0123456789"; char path[MAXPATHLEN]; char realpath[MAXPATHLEN]; char realpath2[MAXPATHLEN]; int len; struct node *p; int i; int j; char *s; int max_nasid = -1; #ifdef HAVE_HUBSTAT_H int fd; hubstat_t hs; #endif /*================================================*/ /* if not our first time, we need to give back a */ /* bunch of heap space before we get started here */ /*================================================*/ cleanup_topology_data(); n_cpus = sysmp(MP_NPROCS); /*=======================================*/ /* figure out just which nodes we've got */ /*=======================================*/ if ((dirp=opendir(HW_NODENUM_PATH)) == NULL) { sprintf(log_bfr, "opendir(%s)", HW_NODENUM_PATH); log_err(errno, whoami, log_bfr); exit(EXIT_FAILURE); } rewinddir(dirp); while (dent=readdir(dirp)) { /* only want those whose names consist solely of digits */ if (strspn(dent->d_name, digits) < strlen(dent->d_name)) continue; sprintf(path, "%s/%s", HW_NODENUM_PATH, dent->d_name); if ((len = readlink(path, realpath, sizeofrealpath)) < 0) { sprintf(log_bfr, "readlink(%s)", path); log_err(errno, whoami, log_bfr); continue; } realpath[len] = '\0'; /* 'readlink()' punts on this */ p = malloc(sizeof*p); if (p == NULL) { strcpy(log_bfr, "malloc failed"); log_err(errno, whoami, log_bfr); return; /* probably a BAD choice */ } p->logical_nbr = atoi(dent->d_name); strcat(path, HW_PATH_SUFFIX); #ifdef HAVE_HUBSTAT_H if ((fd=open(path, O_RDONLY)) < 0) { sprintf(log_bfr, "open(%s)", path); log_err(errno, whoami, log_bfr); continue; /* ??? */ } if (ioctl(fd, SN0DRV_GET_HUBINFO, &hs) < 0) { sprintf(log_bfr, "ioctl(%s,GET_HUBINFO)", path); log_err(errno, whoami, log_bfr); continue; /* as before: ??? */ } close(fd); p->physical_nbr = hs.hs_nasid; #else p->physical_nbr = p->logical_nbr; #endif if (max_nasid < p->physical_nbr) max_nasid = p->physical_nbr; p->next = NULL; s = strstr(realpath, "slot/"); if (s) { /* Origin2000 */ p->slot = atoi(s+5); s = strstr(realpath, "module/"); p->module = atoi(s+7); p->rack = 0; } else { /* Origin3000 */ s = strstr(realpath, "module/"); p->rack = atoi(s+7); p->module = 0; p->slot = 0; } for (i=0 ; i < MAX_CPUS_PER_NODE ; ++i) p->cpu[i] = -1; strcpy(realpath2, realpath); strcat(realpath, "/cpu"); get_cpus(realpath, p->cpu); strcat(realpath2, "/memory"); get_mem(realpath2, &p->memory); /* add this one to our list */ if (n_nodes == 0) first_node = p; else last_node->next = p; last_node = p; ++n_nodes; } closedir(dirp); /* linearize */ if (n_nodes) { Nodes = malloc(n_nodes*sizeof*Nodes); if (Nodes == NULL) { sprintf(log_bfr, "malloc(%d nodes)", n_nodes); log_err(errno, whoami, log_bfr); return; } i = 0; p = first_node; while (p) { Nodes[i] = *p; free(p); p = Nodes[i++].next; } first_node = last_node = NULL; /* empirically, next is *unnecessary* */ qsort(Nodes, n_nodes, sizeof*Nodes, cmp_nodes); } /*===========================================================*/ /* now for the Whole Point(tm): determine the permutation */ /* that maps "logical" to "physical" node numbers. And its */ /* inverse, while we're at it [as it's useful down the road] */ /*===========================================================*/ ++max_nasid; schd_nodes_log2phys = malloc(max_nasid*sizeof*schd_nodes_log2phys); if (schd_nodes_log2phys == NULL) { strcpy(log_bfr, "malloc(schd_nodes_log2phys)"); log_err(errno, whoami, log_bfr); return; } schd_nodes_phys2log = malloc(max_nasid*sizeof*schd_nodes_phys2log); if (schd_nodes_phys2log == NULL) { strcpy(log_bfr, "malloc(schd_nodes_phys2log)"); log_err(errno, whoami, log_bfr); return; } for (j=0 ; j < max_nasid ; ++j) schd_nodes_log2phys[j] = schd_nodes_phys2log[j] = -1; for (i=0 ; i < n_nodes ; ++i) { j = Nodes[i].physical_nbr; schd_nodes_log2phys[i] = j; schd_nodes_phys2log[j] = i; } return; }
long read_udp_stat(UDP_STAT_STRUCTURE * udpstat, int magic) { long ret_value = -1; #if (defined(CAN_USE_SYSCTL) && defined(UDPCTL_STATS)) static int sname[4] = { CTL_NET, PF_INET, IPPROTO_UDP, UDPCTL_STATS }; size_t len = sizeof(*udpstat); #endif #ifdef solaris2 static mib2_ip_t ipstat; #endif #ifdef hpux11 int fd; struct nmparms p; unsigned int ulen; if ((fd = open_mib("/dev/ip", O_RDONLY, 0, NM_ASYNC_OFF)) < 0) return (-1); /* error */ switch (magic) { case UDPINDATAGRAMS: p.objid = ID_udpInDatagrams; break; case UDPNOPORTS: p.objid = ID_udpNoPorts; break; case UDPOUTDATAGRAMS: p.objid = ID_udpOutDatagrams; break; case UDPINERRORS: p.objid = ID_udpInErrors; break; default: *udpstat = 0; close_mib(fd); return (0); } p.buffer = (void *) udpstat; ulen = sizeof(UDP_STAT_STRUCTURE); p.len = &ulen; ret_value = get_mib_info(fd, &p); close_mib(fd); return (ret_value); /* 0: ok, < 0: error */ #else /* hpux11 */ if (udp_stats_cache_marker && (!atime_ready (udp_stats_cache_marker, UDP_STATS_CACHE_TIMEOUT * 1000))) #ifdef solaris2 return (magic == UDPNOPORTS ? ipstat.udpNoPorts : 0); #else return 0; #endif if (udp_stats_cache_marker) atime_setMarker(udp_stats_cache_marker); else udp_stats_cache_marker = atime_newMarker(); #ifdef linux ret_value = linux_read_udp_stat(udpstat); #endif #ifdef WIN32 ret_value = GetUdpStatistics(udpstat); #endif #ifdef solaris2 if (magic == UDPNOPORTS) { if (getMibstat (MIB_IP, &ipstat, sizeof(mib2_ip_t), GET_FIRST, &Get_everything, NULL) < 0) ret_value = -1; else ret_value = ipstat.udpNoPorts; } else ret_value = getMibstat(MIB_UDP, udpstat, sizeof(mib2_udp_t), GET_FIRST, &Get_everything, NULL); #endif #ifdef HAVE_SYS_TCPIPSTATS_H ret_value = sysmp(MP_SAGET, MPSA_TCPIPSTATS, udpstat, sizeof *udpstat); #endif #if defined(CAN_USE_SYSCTL) && defined(UDPCTL_STATS) ret_value = sysctl(sname, 4, udpstat, &len, 0, 0); #endif #ifdef UDPSTAT_SYMBOL if (auto_nlist(UDPSTAT_SYMBOL, (char *) udpstat, sizeof(*udpstat))) ret_value = 0; #endif if (ret_value == -1) { free(udp_stats_cache_marker); udp_stats_cache_marker = NULL; } return ret_value; #endif /* hpux11 */ }
int getloadavg (double loadavg[], int nelem) { int elem = 0; /* Return value. */ # ifdef NO_GET_LOAD_AVG # define LDAV_DONE /* Set errno to zero to indicate that there was no particular error; this function just can't work at all on this system. */ errno = 0; elem = -1; # endif # if !defined (LDAV_DONE) && defined (HAVE_LIBKSTAT) /* Use libkstat because we don't have to be root. */ # define LDAV_DONE kstat_ctl_t *kc; kstat_t *ksp; kstat_named_t *kn; kc = kstat_open (); if (kc == 0) return -1; ksp = kstat_lookup (kc, "unix", 0, "system_misc"); if (ksp == 0) return -1; if (kstat_read (kc, ksp, 0) == -1) return -1; kn = kstat_data_lookup (ksp, "avenrun_1min"); if (kn == 0) { /* Return -1 if no load average information is available. */ nelem = 0; elem = -1; } if (nelem >= 1) loadavg[elem++] = (double) kn->value.ul / FSCALE; if (nelem >= 2) { kn = kstat_data_lookup (ksp, "avenrun_5min"); if (kn != 0) { loadavg[elem++] = (double) kn->value.ul / FSCALE; if (nelem >= 3) { kn = kstat_data_lookup (ksp, "avenrun_15min"); if (kn != 0) loadavg[elem++] = (double) kn->value.ul / FSCALE; } } } kstat_close (kc); # endif /* HAVE_LIBKSTAT */ # if !defined (LDAV_DONE) && defined (hpux) && defined (HAVE_PSTAT_GETDYNAMIC) /* Use pstat_getdynamic() because we don't have to be root. */ # define LDAV_DONE # undef LOAD_AVE_TYPE struct pst_dynamic dyn_info; if (pstat_getdynamic (&dyn_info, sizeof (dyn_info), 0, 0) < 0) return -1; if (nelem > 0) loadavg[elem++] = dyn_info.psd_avg_1_min; if (nelem > 1) loadavg[elem++] = dyn_info.psd_avg_5_min; if (nelem > 2) loadavg[elem++] = dyn_info.psd_avg_15_min; # endif /* hpux && HAVE_PSTAT_GETDYNAMIC */ # if ! defined LDAV_DONE && defined HAVE_LIBPERFSTAT # define LDAV_DONE # undef LOAD_AVE_TYPE /* Use perfstat_cpu_total because we don't have to be root. */ { perfstat_cpu_total_t cpu_stats; int result = perfstat_cpu_total (NULL, &cpu_stats, sizeof cpu_stats, 1); if (result == -1) return result; loadavg[0] = cpu_stats.loadavg[0] / (double)(1 << SBITS); loadavg[1] = cpu_stats.loadavg[1] / (double)(1 << SBITS); loadavg[2] = cpu_stats.loadavg[2] / (double)(1 << SBITS); elem = 3; } # endif # if !defined (LDAV_DONE) && (defined (__linux__) || defined (__CYGWIN__)) # define LDAV_DONE # undef LOAD_AVE_TYPE # ifndef LINUX_LDAV_FILE # define LINUX_LDAV_FILE "/proc/loadavg" # endif char ldavgbuf[3 * (INT_STRLEN_BOUND (int) + sizeof ".00 ")]; char const *ptr = ldavgbuf; int fd, count; fd = open (LINUX_LDAV_FILE, O_RDONLY); if (fd == -1) return -1; count = read (fd, ldavgbuf, sizeof ldavgbuf - 1); (void) close (fd); if (count <= 0) return -1; ldavgbuf[count] = '\0'; for (elem = 0; elem < nelem; elem++) { char *endptr; double d; errno = 0; d = c_strtod (ptr, &endptr); if (ptr == endptr || (d == 0 && errno != 0)) { if (elem == 0) return -1; break; } loadavg[elem] = d; ptr = endptr; } return elem; # endif /* __linux__ || __CYGWIN__ */ # if !defined (LDAV_DONE) && defined (__NetBSD__) # define LDAV_DONE # undef LOAD_AVE_TYPE # ifndef NETBSD_LDAV_FILE # define NETBSD_LDAV_FILE "/kern/loadavg" # endif unsigned long int load_ave[3], scale; int count; FILE *fp; fp = fopen (NETBSD_LDAV_FILE, "r"); if (fp == NULL) return -1; count = fscanf (fp, "%lu %lu %lu %lu\n", &load_ave[0], &load_ave[1], &load_ave[2], &scale); (void) fclose (fp); if (count != 4) return -1; for (elem = 0; elem < nelem; elem++) loadavg[elem] = (double) load_ave[elem] / (double) scale; return elem; # endif /* __NetBSD__ */ # if !defined (LDAV_DONE) && defined (NeXT) # define LDAV_DONE /* The NeXT code was adapted from iscreen 3.2. */ host_t host; struct processor_set_basic_info info; unsigned int info_count; /* We only know how to get the 1-minute average for this system, so even if the caller asks for more than 1, we only return 1. */ if (!getloadavg_initialized) { if (processor_set_default (host_self (), &default_set) == KERN_SUCCESS) getloadavg_initialized = true; } if (getloadavg_initialized) { info_count = PROCESSOR_SET_BASIC_INFO_COUNT; if (processor_set_info (default_set, PROCESSOR_SET_BASIC_INFO, &host, (processor_set_info_t) &info, &info_count) != KERN_SUCCESS) getloadavg_initialized = false; else { if (nelem > 0) loadavg[elem++] = (double) info.load_average / LOAD_SCALE; } } if (!getloadavg_initialized) return -1; # endif /* NeXT */ # if !defined (LDAV_DONE) && defined (UMAX) # define LDAV_DONE /* UMAX 4.2, which runs on the Encore Multimax multiprocessor, does not have a /dev/kmem. Information about the workings of the running kernel can be gathered with inq_stats system calls. We only know how to get the 1-minute average for this system. */ struct proc_summary proc_sum_data; struct stat_descr proc_info; double load; register unsigned int i, j; if (cpus == 0) { register unsigned int c, i; struct cpu_config conf; struct stat_descr desc; desc.sd_next = 0; desc.sd_subsys = SUBSYS_CPU; desc.sd_type = CPUTYPE_CONFIG; desc.sd_addr = (char *) &conf; desc.sd_size = sizeof conf; if (inq_stats (1, &desc)) return -1; c = 0; for (i = 0; i < conf.config_maxclass; ++i) { struct class_stats stats; bzero ((char *) &stats, sizeof stats); desc.sd_type = CPUTYPE_CLASS; desc.sd_objid = i; desc.sd_addr = (char *) &stats; desc.sd_size = sizeof stats; if (inq_stats (1, &desc)) return -1; c += stats.class_numcpus; } cpus = c; samples = cpus < 2 ? 3 : (2 * cpus / 3); } proc_info.sd_next = 0; proc_info.sd_subsys = SUBSYS_PROC; proc_info.sd_type = PROCTYPE_SUMMARY; proc_info.sd_addr = (char *) &proc_sum_data; proc_info.sd_size = sizeof (struct proc_summary); proc_info.sd_sizeused = 0; if (inq_stats (1, &proc_info) != 0) return -1; load = proc_sum_data.ps_nrunnable; j = 0; for (i = samples - 1; i > 0; --i) { load += proc_sum_data.ps_nrun[j]; if (j++ == PS_NRUNSIZE) j = 0; } if (nelem > 0) loadavg[elem++] = load / samples / cpus; # endif /* UMAX */ # if !defined (LDAV_DONE) && defined (DGUX) # define LDAV_DONE /* This call can return -1 for an error, but with good args it's not supposed to fail. The first argument is for no apparent reason of type `long int *'. */ dg_sys_info ((long int *) &load_info, DG_SYS_INFO_LOAD_INFO_TYPE, DG_SYS_INFO_LOAD_VERSION_0); if (nelem > 0) loadavg[elem++] = load_info.one_minute; if (nelem > 1) loadavg[elem++] = load_info.five_minute; if (nelem > 2) loadavg[elem++] = load_info.fifteen_minute; # endif /* DGUX */ # if !defined (LDAV_DONE) && defined (apollo) # define LDAV_DONE /* Apollo code from [email protected] (Ray Lischner). This system call is not documented. The load average is obtained as three long integers, for the load average over the past minute, five minutes, and fifteen minutes. Each value is a scaled integer, with 16 bits of integer part and 16 bits of fraction part. I'm not sure which operating system first supported this system call, but I know that SR10.2 supports it. */ extern void proc1_$get_loadav (); unsigned long load_ave[3]; proc1_$get_loadav (load_ave); if (nelem > 0) loadavg[elem++] = load_ave[0] / 65536.0; if (nelem > 1) loadavg[elem++] = load_ave[1] / 65536.0; if (nelem > 2) loadavg[elem++] = load_ave[2] / 65536.0; # endif /* apollo */ # if !defined (LDAV_DONE) && defined (OSF_MIPS) # define LDAV_DONE struct tbl_loadavg load_ave; table (TBL_LOADAVG, 0, &load_ave, 1, sizeof (load_ave)); loadavg[elem++] = (load_ave.tl_lscale == 0 ? load_ave.tl_avenrun.d[0] : (load_ave.tl_avenrun.l[0] / (double) load_ave.tl_lscale)); # endif /* OSF_MIPS */ # if !defined (LDAV_DONE) && (defined (__MSDOS__) || defined (WINDOWS32)) # define LDAV_DONE /* A faithful emulation is going to have to be saved for a rainy day. */ for ( ; elem < nelem; elem++) { loadavg[elem] = 0.0; } # endif /* __MSDOS__ || WINDOWS32 */ # if !defined (LDAV_DONE) && defined (OSF_ALPHA) # define LDAV_DONE struct tbl_loadavg load_ave; table (TBL_LOADAVG, 0, &load_ave, 1, sizeof (load_ave)); for (elem = 0; elem < nelem; elem++) loadavg[elem] = (load_ave.tl_lscale == 0 ? load_ave.tl_avenrun.d[elem] : (load_ave.tl_avenrun.l[elem] / (double) load_ave.tl_lscale)); # endif /* OSF_ALPHA */ # if ! defined LDAV_DONE && defined __VMS /* VMS specific code -- read from the Load Ave driver. */ LOAD_AVE_TYPE load_ave[3]; static bool getloadavg_initialized; # ifdef eunice struct { int dsc$w_length; char *dsc$a_pointer; } descriptor; # endif /* Ensure that there is a channel open to the load ave device. */ if (!getloadavg_initialized) { /* Attempt to open the channel. */ # ifdef eunice descriptor.dsc$w_length = 18; descriptor.dsc$a_pointer = "$$VMS_LOAD_AVERAGE"; # else $DESCRIPTOR (descriptor, "LAV0:"); # endif if (sys$assign (&descriptor, &channel, 0, 0) & 1) getloadavg_initialized = true; } /* Read the load average vector. */ if (getloadavg_initialized && !(sys$qiow (0, channel, IO$_READVBLK, 0, 0, 0, load_ave, 12, 0, 0, 0, 0) & 1)) { sys$dassgn (channel); getloadavg_initialized = false; } if (!getloadavg_initialized) return -1; # endif /* ! defined LDAV_DONE && defined __VMS */ # if ! defined LDAV_DONE && defined LOAD_AVE_TYPE && ! defined __VMS /* UNIX-specific code -- read the average from /dev/kmem. */ # define LDAV_PRIVILEGED /* This code requires special installation. */ LOAD_AVE_TYPE load_ave[3]; /* Get the address of LDAV_SYMBOL. */ if (offset == 0) { # ifndef sgi # if ! defined NLIST_STRUCT || ! defined N_NAME_POINTER strcpy (nl[0].n_name, LDAV_SYMBOL); strcpy (nl[1].n_name, ""); # else /* NLIST_STRUCT */ # ifdef HAVE_STRUCT_NLIST_N_UN_N_NAME nl[0].n_un.n_name = LDAV_SYMBOL; nl[1].n_un.n_name = 0; # else /* not HAVE_STRUCT_NLIST_N_UN_N_NAME */ nl[0].n_name = LDAV_SYMBOL; nl[1].n_name = 0; # endif /* not HAVE_STRUCT_NLIST_N_UN_N_NAME */ # endif /* NLIST_STRUCT */ # ifndef SUNOS_5 if ( # if !(defined (_AIX) && !defined (ps2)) nlist (KERNEL_FILE, nl) # else /* _AIX */ knlist (nl, 1, sizeof (nl[0])) # endif >= 0) /* Omit "&& nl[0].n_type != 0 " -- it breaks on Sun386i. */ { # ifdef FIXUP_KERNEL_SYMBOL_ADDR FIXUP_KERNEL_SYMBOL_ADDR (nl); # endif offset = nl[0].n_value; } # endif /* !SUNOS_5 */ # else /* sgi */ int ldav_off; ldav_off = sysmp (MP_KERNADDR, MPKA_AVENRUN); if (ldav_off != -1) offset = (long int) ldav_off & 0x7fffffff; # endif /* sgi */ } /* Make sure we have /dev/kmem open. */ if (!getloadavg_initialized) { # ifndef SUNOS_5 channel = open ("/dev/kmem", O_RDONLY); if (channel >= 0) { /* Set the channel to close on exec, so it does not litter any child's descriptor table. */ set_cloexec_flag (channel, true); getloadavg_initialized = true; } # else /* SUNOS_5 */ /* We pass 0 for the kernel, corefile, and swapfile names to use the currently running kernel. */ kd = kvm_open (0, 0, 0, O_RDONLY, 0); if (kd != 0) { /* nlist the currently running kernel. */ kvm_nlist (kd, nl); offset = nl[0].n_value; getloadavg_initialized = true; } # endif /* SUNOS_5 */ } /* If we can, get the load average values. */ if (offset && getloadavg_initialized) { /* Try to read the load. */ # ifndef SUNOS_5 if (lseek (channel, offset, 0) == -1L || read (channel, (char *) load_ave, sizeof (load_ave)) != sizeof (load_ave)) { close (channel); getloadavg_initialized = false; } # else /* SUNOS_5 */ if (kvm_read (kd, offset, (char *) load_ave, sizeof (load_ave)) != sizeof (load_ave)) { kvm_close (kd); getloadavg_initialized = false; } # endif /* SUNOS_5 */ } if (offset == 0 || !getloadavg_initialized) return -1; # endif /* ! defined LDAV_DONE && defined LOAD_AVE_TYPE && ! defined __VMS */ # if !defined (LDAV_DONE) && defined (LOAD_AVE_TYPE) /* Including VMS. */ if (nelem > 0) loadavg[elem++] = LDAV_CVT (load_ave[0]); if (nelem > 1) loadavg[elem++] = LDAV_CVT (load_ave[1]); if (nelem > 2) loadavg[elem++] = LDAV_CVT (load_ave[2]); # define LDAV_DONE # endif /* !LDAV_DONE && LOAD_AVE_TYPE */ # if !defined LDAV_DONE /* Set errno to zero to indicate that there was no particular error; this function just can't work at all on this system. */ errno = 0; elem = -1; # endif return elem; }
/* * Load the latest memory usage statistics */ int netsnmp_mem_arch_load( netsnmp_cache *cache, void *magic ) { netsnmp_memory_info *mem; struct rminfo meminfo; /* struct for getting memory info, see sys/sysmp.h */ int pagesz, rminfosz; off_t swaptotal, swapfree; /* * Retrieve the memory information from the underlying O/S... */ DEBUGMSGTL(("hardware/memory/memory_irix", "Start retrieving values from OS\n")); pagesz = getpagesize(); DEBUGMSGTL(("hardware/memory/memory_irix", "Page size: %d\n", pagesz)); rminfosz = (int)sysmp(MP_SASZ, MPSA_RMINFO); DEBUGMSGTL(("hardware/memory/memory_irix", "rminfo size: %d\n", rminfosz)); if (sysmp(MP_SAGET, MPSA_RMINFO, &meminfo, rminfosz) < 0) { snmp_log(LOG_ERR, "memory_irix: sysmp failed!\n"); return -1; } swapctl(SC_GETSWAPTOT, &swaptotal); swapctl(SC_GETFREESWAP, &swapfree); /* * ... and save this in a standard form. */ mem = netsnmp_memory_get_byIdx( NETSNMP_MEM_TYPE_PHYSMEM, 1 ); if (!mem) { snmp_log_perror("No Physical Memory info entry"); } else { if (!mem->descr) mem->descr = strdup("Physical memory"); mem->units = pagesz; mem->size = meminfo.physmem; mem->free = meminfo.availrmem; mem->other = -1; DEBUGMSGTL(("hardware/memory/memory_irix", "Physical memory: size %u, free %u\n", mem->size, mem->free)); } mem = netsnmp_memory_get_byIdx( NETSNMP_MEM_TYPE_VIRTMEM, 1 ); if (!mem) { snmp_log_perror("No Virtual Memory info entry"); } else { if (!mem->descr) mem->descr = strdup("Virtual memory"); mem->units = pagesz; /* swaptotal is in blocks, so adjust below */ mem->size = meminfo.physmem + (swaptotal*512/pagesz); mem->free = meminfo.availsmem; mem->other = -1; DEBUGMSGTL(("hardware/memory/memory_irix", "Virtual memory: size %u, free %u\n", mem->size, mem->free)); } mem = netsnmp_memory_get_byIdx( NETSNMP_MEM_TYPE_SWAP, 1 ); if (!mem) { snmp_log_perror("No Swap info entry"); } else { if (!mem->descr) mem->descr = strdup("Swap space"); mem->units = 1024; mem->size = swaptotal/2; /* blocks to KB */ mem->free = swapfree/2; /* blocks to KB */ mem->other = -1; DEBUGMSGTL(("hardware/memory/memory_irix", "Swap: size %u, free %u\n", mem->size, mem->free)); } return 0; }
/* Return the total amount of physical memory. */ double physmem_total (void) { #if defined _SC_PHYS_PAGES && defined _SC_PAGESIZE { /* This works on linux-gnu, solaris2 and cygwin. */ double pages = sysconf (_SC_PHYS_PAGES); double pagesize = sysconf (_SC_PAGESIZE); if (0 <= pages && 0 <= pagesize) return pages * pagesize; } #endif #if HAVE_PSTAT_GETSTATIC { /* This works on hpux11. */ struct pst_static pss; if (0 <= pstat_getstatic (&pss, sizeof pss, 1, 0)) { double pages = pss.physical_memory; double pagesize = pss.page_size; if (0 <= pages && 0 <= pagesize) return pages * pagesize; } } #endif #if HAVE_SYSMP && defined MP_SAGET && defined MPSA_RMINFO && defined _SC_PAGESIZE { /* This works on irix6. */ struct rminfo realmem; if (sysmp (MP_SAGET, MPSA_RMINFO, &realmem, sizeof realmem) == 0) { double pagesize = sysconf (_SC_PAGESIZE); double pages = realmem.physmem; if (0 <= pages && 0 <= pagesize) return pages * pagesize; } } #endif #if HAVE_GETSYSINFO && defined GSI_PHYSMEM { /* This works on Tru64 UNIX V4/5. */ int physmem; if (getsysinfo (GSI_PHYSMEM, (caddr_t) &physmem, sizeof (physmem), NULL, NULL, NULL) == 1) { double kbytes = physmem; if (0 <= kbytes) return kbytes * 1024.0; } } #endif #if HAVE_SYSCTL && defined HW_PHYSMEM { /* This works on *bsd and darwin. */ unsigned int physmem; size_t len = sizeof physmem; static int mib[2] = { CTL_HW, HW_PHYSMEM }; if (sysctl (mib, ARRAY_SIZE (mib), &physmem, &len, NULL, 0) == 0 && len == sizeof (physmem)) return (double) physmem; } #endif #if HAVE__SYSTEM_CONFIGURATION /* This works on AIX 4.3.3+. */ return _system_configuration.physmem; #endif #if defined _WIN32 { /* this works on windows */ PFN_MS_EX pfnex; HMODULE h = GetModuleHandle ("kernel32.dll"); if (!h) return 0.0; /* Use GlobalMemoryStatusEx if available. */ if ((pfnex = (PFN_MS_EX) GetProcAddress (h, "GlobalMemoryStatusEx"))) { lMEMORYSTATUSEX lms_ex; lms_ex.dwLength = sizeof lms_ex; if (!pfnex (&lms_ex)) return 0.0; return (double) lms_ex.ullTotalPhys; } /* Fall back to GlobalMemoryStatus which is always available. but returns wrong results for physical memory > 4GB. */ else { MEMORYSTATUS ms; GlobalMemoryStatus (&ms); return (double) ms.dwTotalPhys; } } #endif /* Return 0 if we can't determine the value. */ return 0; }
u_char * var_ip(struct variable *vp, oid *name, int *length, int exact, int *var_len, WriteMethod **write_method) { static struct kna tcpipstats; int i; if (header_ip(vp, name, length, exact, var_len, write_method) == MATCH_FAILED ) return NULL; /* * Get the IP statistics from the kernel... */ if (sysmp (MP_SAGET, MPSA_TCPIPSTATS, &tcpipstats, sizeof tcpipstats) == -1) { perror ("sysmp(MP_SAGET)(MPSA_TCPIPSTATS)"); } #define ipstat tcpipstats.ipstat switch (vp->magic){ case IPFORWARDING: #if defined(HAVE_SYS_SYSCTL_H) && defined(CTL_NET) { int name[] = { CTL_NET, PF_INET, IPPROTO_IP, IPCTL_FORWARDING }; int result; size_t result_size = sizeof (int); if (sysctl (name, sizeof (name) / sizeof (int), &result, &result_size, 0, 0) == -1) { fprintf (stderr, "sysctl(CTL_NET,PF_NET,IPPROTO_IP,IPCTL_FORWARDING)\n"); } else { if (result) { long_return = 1; /* GATEWAY */ } else { long_return = 2; /* HOST */ } } } #else /* not (HAVE_SYS_SYSCTL_H && CTL_NET) */ #ifndef sparc auto_nlist(IP_FORWARDING_SYMBOL,(char *) &i, sizeof(i)); fflush(stderr); if (i) { long_return = 1; /* GATEWAY */ } else { long_return = 2; /* HOST */ } #else /* sparc */ long_return = 0; #endif /* sparc */ #endif /* not (HAVE_SYS_SYSCTL_H && CTL_NET) */ return (u_char *) &long_return; case IPDEFAULTTTL: /* * Allow for a kernel w/o TCP. */ if (!auto_nlist(TCP_TTL_SYMBOL,(char *) &long_return, sizeof(long_return))) long_return = 60; /* XXX */ return (u_char *) &long_return; case IPINRECEIVES: long_return = ipstat.ips_total; return (u_char *) &long_return; case IPINHDRERRORS: long_return = ipstat.ips_badsum + ipstat.ips_tooshort + ipstat.ips_toosmall + ipstat.ips_badhlen + ipstat.ips_badlen; return (u_char *) &long_return; case IPINADDRERRORS: long_return = ipstat.ips_cantforward; return (u_char *) &long_return; case IPFORWDATAGRAMS: long_return = ipstat.ips_forward; return (u_char *) &long_return; case IPINUNKNOWNPROTOS: long_return = ipstat.ips_noproto; return (u_char *) &long_return; case IPINDISCARDS: long_return = ipstat.ips_fragdropped; return (u_char *) &long_return; case IPINDELIVERS: long_return = ipstat.ips_delivered; return (u_char *) &long_return; case IPOUTREQUESTS: long_return = ipstat.ips_localout; return (u_char *) &long_return; case IPOUTDISCARDS: long_return = ipstat.ips_odropped; return (u_char *) &long_return; case IPOUTNOROUTES: long_return = ipstat.ips_noroute; return (u_char *) &long_return; case IPREASMTIMEOUT: long_return = ipstat.ips_fragtimeout; return (u_char *) &long_return; case IPREASMREQDS: long_return = ipstat.ips_fragments; return (u_char *) &long_return; case IPREASMOKS: long_return = ipstat.ips_reassembled; return (u_char *) &long_return; case IPREASMFAILS: long_return = ipstat.ips_fragdropped + ipstat.ips_fragtimeout; return (u_char *) &long_return; case IPFRAGOKS: long_return = ipstat.ips_fragments - (ipstat.ips_fragdropped + ipstat.ips_fragtimeout); return (u_char *) &long_return; case IPFRAGFAILS: long_return = 0; return (u_char *) &long_return; case IPFRAGCREATES: long_return = ipstat.ips_ofragments; return (u_char *) &long_return; case IPROUTEDISCARDS: long_return = ipstat.ips_noroute; return (u_char *) &long_return; default: ERROR_MSG(""); } }