您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ sysctlbyname函数代码示例

51自学网 2021-06-03 08:38:03
  C++
这篇教程C++ sysctlbyname函数代码示例写得很实用,希望能帮到您。

本文整理汇总了C++中sysctlbyname函数的典型用法代码示例。如果您正苦于以下问题:C++ sysctlbyname函数的具体用法?C++ sysctlbyname怎么用?C++ sysctlbyname使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了sysctlbyname函数的25个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: bpf_stats

voidbpf_stats(char *ifname){	struct xbpf_d *d, *bd, zerostat;	char *pname, flagbuf[12];	size_t size;	if (zflag) {		bzero(&zerostat, sizeof(zerostat));		if (sysctlbyname("net.bpf.stats", NULL, NULL,		    &zerostat, sizeof(zerostat)) < 0)			xo_warn("failed to zero bpf counters");		return;	}	if (sysctlbyname("net.bpf.stats", NULL, &size,	    NULL, 0) < 0) {		xo_warn("net.bpf.stats");		return;	}	if (size == 0)		return;	bd = malloc(size);	if (bd == NULL) {		xo_warn("malloc failed");		return;	}	if (sysctlbyname("net.bpf.stats", bd, &size,	    NULL, 0) < 0) {		xo_warn("net.bpf.stats");		free(bd);		return;	}	xo_emit("{T:/%5s} {T:/%6s} {T:/%7s} {T:/%9s} {T:/%9s} {T:/%9s} "	    "{T:/%5s} {T:/%5s} {T:/%s}/n",	    "Pid", "Netif", "Flags", "Recv", "Drop", "Match",	    "Sblen", "Hblen", "Command");	xo_open_container("bpf-statistics");	xo_open_list("bpf-entry");	for (d = &bd[0]; d < &bd[size / sizeof(*d)]; d++) {		if (d->bd_structsize != sizeof(*d)) {			xo_warnx("bpf_stats_extended: version mismatch");			return;		}		if (ifname && strcmp(ifname, d->bd_ifname) != 0)			continue;		xo_open_instance("bpf-entry");		pname = bpf_pidname(d->bd_pid);		xo_emit("{k:pid/%5d} {k:interface-name/%6s} ",		    d->bd_pid, d->bd_ifname);		bpf_flags(d, flagbuf);		xo_emit("{d:flags/%7s} {:received-packets/%9ju} "		    "{:dropped-packets/%9ju} {:filter-packets/%9ju} "		    "{:store-buffer-length/%5d} {:hold-buffer-length/%5d} "		    "{:process/%s}/n",		    flagbuf, (uintmax_t)d->bd_rcount, (uintmax_t)d->bd_dcount,		    (uintmax_t)d->bd_fcount, d->bd_slen, d->bd_hlen, pname);		free(pname);		xo_close_instance("bpf-entry");	}	xo_close_list("bpf-entry");	xo_close_container("bpf-statistics");	free(bd);}
开发者ID:2asoft,项目名称:freebsd,代码行数:63,


示例2: ngx_init_threads

ngx_int_tngx_init_threads(int n, size_t size, ngx_cycle_t *cycle){    char              *red_zone, *zone;    size_t             len;    ngx_int_t          i;    struct sigaction   sa;    max_threads = n + 1;    for (i = 0; i < n; i++) {        ngx_memzero(&sa, sizeof(struct sigaction));        sa.sa_handler = SIG_IGN;        sigemptyset(&sa.sa_mask);        if (sigaction(NGX_CV_SIGNAL, &sa, NULL) == -1) {            ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,                          "sigaction(%d, SIG_IGN) failed", NGX_CV_SIGNAL);            return NGX_ERROR;        }    }    len = sizeof(ngx_freebsd_kern_usrstack);    if (sysctlbyname("kern.usrstack", &ngx_freebsd_kern_usrstack, &len,                                                                NULL, 0) == -1)    {        ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,                      "sysctlbyname(kern.usrstack) failed");        return NGX_ERROR;    }    /* the main thread stack red zone */    rz_size = ngx_pagesize;    red_zone = ngx_freebsd_kern_usrstack - (size + rz_size);    ngx_log_debug2(NGX_LOG_DEBUG_CORE, cycle->log, 0,                   "usrstack: %p red zone: %p",                   ngx_freebsd_kern_usrstack, red_zone);    zone = mmap(red_zone, rz_size, PROT_NONE, MAP_ANON, -1, 0);    if (zone == MAP_FAILED) {        ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,                      "mmap(%p:%uz, PROT_NONE, MAP_ANON) red zone failed",                      red_zone, rz_size);        return NGX_ERROR;    }    if (zone != red_zone) {        ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,                      "red zone %p address was changed to %p", red_zone, zone);        return NGX_ERROR;    }    /* create the thread errno' array */    errnos = ngx_calloc(n * sizeof(int), cycle->log);    if (errnos == NULL) {        return NGX_ERROR;    }    /* create the thread tids array */    tids = ngx_calloc((n + 1) * sizeof(ngx_tid_t), cycle->log);    if (tids == NULL) {        return NGX_ERROR;    }    tids[0] = ngx_pid;    /* create the thread tls' array */    ngx_tls = ngx_calloc(NGX_THREAD_KEYS_MAX * (n + 1) * sizeof(void *),                         cycle->log);    if (ngx_tls == NULL) {        return NGX_ERROR;    }    nthreads = 1;    last_stack = zone + rz_size;    usable_stack_size = size;    ngx_thread_stack_size = size + rz_size;    /* allow the spinlock in libc malloc() */    __isthreaded = 1;    ngx_threaded = 1;    return NGX_OK;}
开发者ID:275958081,项目名称:nginx-1.0.14_comment,代码行数:89,


示例3: ngx_os_specific_init

ngx_int_tngx_os_specific_init(ngx_log_t *log){    size_t      size;    ngx_err_t   err;    ngx_uint_t  i;    size = sizeof(ngx_darwin_kern_ostype);    if (sysctlbyname("kern.ostype", ngx_darwin_kern_ostype, &size, NULL, 0)        == -1)    {        err = ngx_errno;        if (err != NGX_ENOENT) {            ngx_log_error(NGX_LOG_ALERT, log, err,                          "sysctlbyname(kern.ostype) failed");            if (err != NGX_ENOMEM) {                return NGX_ERROR;            }            ngx_darwin_kern_ostype[size - 1] = '/0';        }    }    size = sizeof(ngx_darwin_kern_osrelease);    if (sysctlbyname("kern.osrelease", ngx_darwin_kern_osrelease, &size,                     NULL, 0)        == -1)    {        err = ngx_errno;        if (err != NGX_ENOENT) {            ngx_log_error(NGX_LOG_ALERT, log, err,                          "sysctlbyname(kern.osrelease) failed");            if (err != NGX_ENOMEM) {                return NGX_ERROR;            }            ngx_darwin_kern_osrelease[size - 1] = '/0';        }    }    for (i = 0; sysctls[i].name; i++) {        size = sysctls[i].size;        if (sysctlbyname(sysctls[i].name, sysctls[i].value, &size, NULL, 0)            == 0)        {            sysctls[i].exists = 1;            continue;        }        err = ngx_errno;        if (err == NGX_ENOENT) {            continue;        }        ngx_log_error(NGX_LOG_ALERT, log, err,                      "sysctlbyname(%s) failed", sysctls[i].name);        return NGX_ERROR;    }    ngx_ncpu = ngx_darwin_hw_ncpu;    if (ngx_darwin_kern_ipc_somaxconn > 32767) {        ngx_log_error(NGX_LOG_ALERT, log, 0,                      "sysctl kern.ipc.somaxconn must be less than 32768");        return NGX_ERROR;    }    ngx_tcp_nodelay_and_tcp_nopush = 1;    ngx_os_io = ngx_darwin_io;    return NGX_OK;}
开发者ID:FangJianHust,项目名称:nginx-1.4.4,代码行数:81,


示例4: OslTableInitialize

static ACPI_STATUSOslTableInitialize (    void){#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)    char                    Buffer[32];#endif    ACPI_TABLE_HEADER       *MappedTable;    UINT8                   *TableAddress;    UINT8                   *RsdpAddress;    ACPI_PHYSICAL_ADDRESS   RsdpBase;    ACPI_SIZE               RsdpSize;    ACPI_STATUS             Status;    u_long                  Address = 0;    size_t                  Length = sizeof (Address);    /* Get main ACPI tables from memory on first invocation of this function */    if (Gbl_MainTableObtained)    {        return (AE_OK);    }    /* Attempt to use kenv or sysctl to find RSD PTR record. */    if (Gbl_RsdpBase)    {        Address = Gbl_RsdpBase;    }#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)    else if (kenv (KENV_GET, SYSTEM_KENV, Buffer, sizeof (Buffer)) > 0)    {        Address = ACPI_STRTOUL (Buffer, NULL, 0);    }#endif    if (!Address)    {        if (sysctlbyname (SYSTEM_SYSCTL, &Address, &Length, NULL, 0) != 0)        {            Address = 0;        }    }    if (Address)    {        RsdpBase = Address;        RsdpSize = sizeof (Gbl_Rsdp);    }    else    {        RsdpBase = ACPI_HI_RSDP_WINDOW_BASE;        RsdpSize = ACPI_HI_RSDP_WINDOW_SIZE;    }    /* Get RSDP from memory */    RsdpAddress = AcpiOsMapMemory (RsdpBase, RsdpSize);    if (!RsdpAddress)    {        return (AE_BAD_ADDRESS);    }    /* Search low memory for the RSDP */    TableAddress = AcpiTbScanMemoryForRsdp (RsdpAddress, RsdpSize);    if (!TableAddress)    {        AcpiOsUnmapMemory (RsdpAddress, RsdpSize);        return (AE_ERROR);    }    ACPI_MEMCPY (&Gbl_Rsdp, TableAddress, sizeof (Gbl_Rsdp));    AcpiOsUnmapMemory (RsdpAddress, RsdpSize);    /* Get XSDT from memory */    if (Gbl_Rsdp.Revision)    {        Status = OslMapTable (Gbl_Rsdp.XsdtPhysicalAddress,            ACPI_SIG_XSDT, &MappedTable);        if (ACPI_FAILURE (Status))        {            return (Status);        }        Gbl_Revision = 2;        Gbl_Xsdt = calloc (1, MappedTable->Length);        if (!Gbl_Xsdt)        {            fprintf (stderr,                "XSDT: Could not allocate buffer for table of length %X/n",                MappedTable->Length);            AcpiOsUnmapMemory (MappedTable, MappedTable->Length);            return (AE_NO_MEMORY);        }        ACPI_MEMCPY (Gbl_Xsdt, MappedTable, MappedTable->Length);        AcpiOsUnmapMemory (MappedTable, MappedTable->Length);    }//.........这里部分代码省略.........
开发者ID:Yuki-Judai,项目名称:acpica,代码行数:101,


示例5: conn_read

static int conn_read (void){  int status;  char *buffer;  size_t buffer_len;;  struct xinpgen *in_orig;  struct xinpgen *in_ptr;  conn_reset_port_entry ();  buffer_len = 0;  status = sysctlbyname ("net.inet.tcp.pcblist", NULL, &buffer_len, 0, 0);  if (status < 0)  {    ERROR ("tcpconns plugin: sysctlbyname failed.");    return (-1);  }  buffer = malloc (buffer_len);  if (buffer == NULL)  {    ERROR ("tcpconns plugin: malloc failed.");    return (-1);  }  status = sysctlbyname ("net.inet.tcp.pcblist", buffer, &buffer_len, 0, 0);  if (status < 0)  {    ERROR ("tcpconns plugin: sysctlbyname failed.");    sfree (buffer);    return (-1);  }  if (buffer_len <= sizeof (struct xinpgen))  {    ERROR ("tcpconns plugin: (buffer_len <= sizeof (struct xinpgen))");    sfree (buffer);    return (-1);  }  in_orig = (struct xinpgen *) buffer;  for (in_ptr = (struct xinpgen *) (((char *) in_orig) + in_orig->xig_len);      in_ptr->xig_len > sizeof (struct xinpgen);      in_ptr = (struct xinpgen *) (((char *) in_ptr) + in_ptr->xig_len))  {    struct tcpcb *tp = &((struct xtcpcb *) in_ptr)->xt_tp;    struct inpcb *inp = &((struct xtcpcb *) in_ptr)->xt_inp;    struct xsocket *so = &((struct xtcpcb *) in_ptr)->xt_socket;    /* Ignore non-TCP sockets */    if (so->xso_protocol != IPPROTO_TCP)      continue;    /* Ignore PCBs which were freed during copyout. */    if (inp->inp_gencnt > in_orig->xig_gen)      continue;    if (((inp->inp_vflag & INP_IPV4) == 0)	&& ((inp->inp_vflag & INP_IPV6) == 0))      continue;    conn_handle_ports (ntohs (inp->inp_lport), ntohs (inp->inp_fport),	tp->t_state);  } /* for (in_ptr) */  in_orig = NULL;  in_ptr = NULL;  sfree (buffer);  conn_submit_all ();  return (0);} /* int conn_read */
开发者ID:Whissi,项目名称:collectd,代码行数:74,


示例6: kget

voidkget(int idx, void *addr, size_t size){	const char *symn;		/* symbol name */	size_t tsiz;	int rv;	unsigned long kaddr;	const char *sym2sysctl[] = {	/* symbol to sysctl name table */		"kern.ipc.sema",		"kern.ipc.seminfo",		"kern.ipc.msginfo",		"kern.ipc.msqids",		"kern.ipc.shminfo",		"kern.ipc.shmsegs" };	assert((unsigned)idx <= sizeof(sym2sysctl) / sizeof(*sym2sysctl));	if (!use_sysctl) {		symn = symbols[idx].n_name;		if (*symn == '_')			symn++;		if (symbols[idx].n_type == 0 || symbols[idx].n_value == 0)			errx(1, "symbol %s undefined", symn);		/*		 * For some symbols, the value we retrieve is		 * actually a pointer; since we want the actual value,		 * we have to manually dereference it.		 */		switch (idx) {		case X_MSQIDS:			tsiz = sizeof(msqids);			rv = kvm_read(kd, symbols[idx].n_value,			    &msqids, tsiz);			kaddr = (u_long)msqids;			break;		case X_SHMSEGS:			tsiz = sizeof(shmsegs);			rv = kvm_read(kd, symbols[idx].n_value,			    &shmsegs, tsiz);			kaddr = (u_long)shmsegs;			break;		case X_SEMA:			tsiz = sizeof(sema);			rv = kvm_read(kd, symbols[idx].n_value,			    &sema, tsiz);			kaddr = (u_long)sema;			break;		default:			rv = tsiz = 0;			kaddr = symbols[idx].n_value;			break;		}		if ((unsigned)rv != tsiz)			errx(1, "%s: %s", symn, kvm_geterr(kd));		if ((unsigned)kvm_read(kd, kaddr, addr, size) != size)			errx(1, "%s: %s", symn, kvm_geterr(kd));	} else {		switch (idx) {		case X_SHMINFO:			sysctlgatherstruct(addr, size, shminfo_scgsv);			break;		case X_SEMINFO:			sysctlgatherstruct(addr, size, seminfo_scgsv);			break;		case X_MSGINFO:			sysctlgatherstruct(addr, size, msginfo_scgsv);			break;		default:			tsiz = size;			rv = sysctlbyname(sym2sysctl[idx], addr, &tsiz,			    NULL, 0);			if (rv == -1)				err(1, "sysctlbyname: %s", sym2sysctl[idx]);			if (tsiz != size)				errx(1, "%s size mismatch "				    "(expected %zu, got %zu)",				    sym2sysctl[idx], size, tsiz);			break;		}	}}
开发者ID:ppaeps,项目名称:freebsd-head,代码行数:80,


示例7: uint64_t

bool CCPUInfo::readProcStat(unsigned long long& user, unsigned long long& nice,    unsigned long long& system, unsigned long long& idle, unsigned long long& io){#ifdef TARGET_WINDOWS  FILETIME idleTime;  FILETIME kernelTime;  FILETIME userTime;  if (GetSystemTimes(&idleTime, &kernelTime, &userTime) == 0)    return false;  idle = (uint64_t(idleTime.dwHighDateTime) << 32) + uint64_t(idleTime.dwLowDateTime);  // returned "kernelTime" includes "idleTime"  system = (uint64_t(kernelTime.dwHighDateTime) << 32) + uint64_t(kernelTime.dwLowDateTime) - idle;  user = (uint64_t(userTime.dwHighDateTime) << 32) + uint64_t(userTime.dwLowDateTime);  nice = 0;  io = 0;  if (m_cpuFreqCounter && PdhCollectQueryData(m_cpuQueryLoad) == ERROR_SUCCESS)  {    for (std::map<int, CoreInfo>::iterator it = m_cores.begin(); it != m_cores.end(); ++it)    {      CoreInfo& curCore = it->second; // simplify usage      PDH_RAW_COUNTER cnt;      DWORD cntType;      if (curCore.m_coreCounter && PdhGetRawCounterValue(curCore.m_coreCounter, &cntType, &cnt) == ERROR_SUCCESS &&          (cnt.CStatus == PDH_CSTATUS_VALID_DATA || cnt.CStatus == PDH_CSTATUS_NEW_DATA))      {        const LONGLONG coreTotal = cnt.SecondValue,                       coreIdle  = cnt.FirstValue;        const LONGLONG deltaTotal = coreTotal - curCore.m_total,                       deltaIdle  = coreIdle - curCore.m_idle;        const double load = (double(deltaTotal - deltaIdle) * 100.0) / double(deltaTotal);                // win32 has some problems with calculation of load if load close to zero        curCore.m_fPct = (load < 0) ? 0 : load;        if (load >= 0 || deltaTotal > 5 * 10 * 1000 * 1000) // do not update (smooth) values for 5 seconds on negative loads        {          curCore.m_total = coreTotal;          curCore.m_idle = coreIdle;        }      }      else        curCore.m_fPct = double(m_lastUsedPercentage); // use CPU average as fallback    }  }  else    for (std::map<int, CoreInfo>::iterator it = m_cores.begin(); it != m_cores.end(); ++it)      it->second.m_fPct = double(m_lastUsedPercentage); // use CPU average as fallback#elif defined(TARGET_FREEBSD)  long *cptimes;  size_t len;  int i;  len = sizeof(long) * 32 * CPUSTATES;  if (sysctlbyname("kern.cp_times", NULL, &len, NULL, 0) != 0)    return false;  cptimes = (long*)malloc(len);  if (cptimes == NULL)    return false;  if (sysctlbyname("kern.cp_times", cptimes, &len, NULL, 0) != 0)  {    free(cptimes);    return false;  }  user = 0;  nice = 0;  system = 0;  idle = 0;  io = 0;  for (i = 0; i < m_cpuCount; i++)  {    long coreUser, coreNice, coreSystem, coreIdle, coreIO;    double total;    coreUser   = cptimes[i * CPUSTATES + CP_USER];    coreNice   = cptimes[i * CPUSTATES + CP_NICE];    coreSystem = cptimes[i * CPUSTATES + CP_SYS];    coreIO     = cptimes[i * CPUSTATES + CP_INTR];    coreIdle   = cptimes[i * CPUSTATES + CP_IDLE];    std::map<int, CoreInfo>::iterator iter = m_cores.find(i);    if (iter != m_cores.end())    {      coreUser -= iter->second.m_user;      coreNice -= iter->second.m_nice;      coreSystem -= iter->second.m_system;      coreIdle -= iter->second.m_idle;      coreIO -= iter->second.m_io;      total = (double)(coreUser + coreNice + coreSystem + coreIdle + coreIO);      if(total != 0.0f)        iter->second.m_fPct = ((double)(coreUser + coreNice + coreSystem) * 100.0) / total;      iter->second.m_user += coreUser;      iter->second.m_nice += coreNice;      iter->second.m_system += coreSystem;      iter->second.m_idle += coreIdle;      iter->second.m_io += coreIO;//.........这里部分代码省略.........
开发者ID:Karlson2k,项目名称:xbmc,代码行数:101,


示例8: __cpuid

void CCPUInfo::ReadCPUFeatures(){#ifdef TARGET_WINDOWS  int CPUInfo[4]; // receives EAX, EBX, ECD and EDX in that order  __cpuid(CPUInfo, 0);  int MaxStdInfoType = CPUInfo[0];  if (MaxStdInfoType >= CPUID_INFOTYPE_STANDARD)  {    __cpuid(CPUInfo, CPUID_INFOTYPE_STANDARD);    if (CPUInfo[CPUINFO_EDX] & CPUID_00000001_EDX_MMX)      m_cpuFeatures |= CPU_FEATURE_MMX;    if (CPUInfo[CPUINFO_EDX] & CPUID_00000001_EDX_SSE)      m_cpuFeatures |= CPU_FEATURE_SSE;    if (CPUInfo[CPUINFO_EDX] & CPUID_00000001_EDX_SSE2)      m_cpuFeatures |= CPU_FEATURE_SSE2;    if (CPUInfo[CPUINFO_ECX] & CPUID_00000001_ECX_SSE3)      m_cpuFeatures |= CPU_FEATURE_SSE3;    if (CPUInfo[CPUINFO_ECX] & CPUID_00000001_ECX_SSSE3)      m_cpuFeatures |= CPU_FEATURE_SSSE3;    if (CPUInfo[CPUINFO_ECX] & CPUID_00000001_ECX_SSE4)      m_cpuFeatures |= CPU_FEATURE_SSE4;    if (CPUInfo[CPUINFO_ECX] & CPUID_00000001_ECX_SSE42)      m_cpuFeatures |= CPU_FEATURE_SSE42;  }  __cpuid(CPUInfo, 0x80000000);  int MaxExtInfoType = CPUInfo[0];  if (MaxExtInfoType >= CPUID_INFOTYPE_EXTENDED)  {    __cpuid(CPUInfo, CPUID_INFOTYPE_EXTENDED);    if (CPUInfo[CPUINFO_EDX] & CPUID_80000001_EDX_MMX)      m_cpuFeatures |= CPU_FEATURE_MMX;    if (CPUInfo[CPUINFO_EDX] & CPUID_80000001_EDX_MMX2)      m_cpuFeatures |= CPU_FEATURE_MMX2;    if (CPUInfo[CPUINFO_EDX] & CPUID_80000001_EDX_3DNOW)      m_cpuFeatures |= CPU_FEATURE_3DNOW;    if (CPUInfo[CPUINFO_EDX] & CPUID_80000001_EDX_3DNOWEXT)      m_cpuFeatures |= CPU_FEATURE_3DNOWEXT;  }#elif defined(TARGET_DARWIN)  #if defined(__ppc__)    m_cpuFeatures |= CPU_FEATURE_ALTIVEC;  #elif defined(TARGET_DARWIN_IOS)  #else    size_t len = 512 - 1; // '-1' for trailing space    char buffer[512] ={0};    if (sysctlbyname("machdep.cpu.features", &buffer, &len, NULL, 0) == 0)    {      strcat(buffer, " ");      if (strstr(buffer,"MMX "))        m_cpuFeatures |= CPU_FEATURE_MMX;      if (strstr(buffer,"MMXEXT "))        m_cpuFeatures |= CPU_FEATURE_MMX2;      if (strstr(buffer,"SSE "))        m_cpuFeatures |= CPU_FEATURE_SSE;      if (strstr(buffer,"SSE2 "))        m_cpuFeatures |= CPU_FEATURE_SSE2;      if (strstr(buffer,"SSE3 "))        m_cpuFeatures |= CPU_FEATURE_SSE3;      if (strstr(buffer,"SSSE3 "))        m_cpuFeatures |= CPU_FEATURE_SSSE3;      if (strstr(buffer,"SSE4.1 "))        m_cpuFeatures |= CPU_FEATURE_SSE4;      if (strstr(buffer,"SSE4.2 "))        m_cpuFeatures |= CPU_FEATURE_SSE42;      if (strstr(buffer,"3DNOW "))        m_cpuFeatures |= CPU_FEATURE_3DNOW;      if (strstr(buffer,"3DNOWEXT "))       m_cpuFeatures |= CPU_FEATURE_3DNOWEXT;    }    else      m_cpuFeatures |= CPU_FEATURE_MMX;  #endif#elif defined(LINUX)// empty on purpose, the implementation is in the constructor#elif !defined(__powerpc__) && !defined(__ppc__) && !defined(__arm__)  m_cpuFeatures |= CPU_FEATURE_MMX;#elif defined(__powerpc__) || defined(__ppc__)  m_cpuFeatures |= CPU_FEATURE_ALTIVEC;#endif}
开发者ID:Karlson2k,项目名称:xbmc,代码行数:88,


示例9: defined

float CCPUInfo::getCPUFrequency(){  // Get CPU frequency, scaled to MHz.#if defined(TARGET_DARWIN)  long long hz = 0;  size_t len = sizeof(hz);  if (sysctlbyname("hw.cpufrequency", &hz, &len, NULL, 0) == -1)    return 0.f;  return hz / 1000000.0;#elif defined TARGET_WINDOWS  if (m_cpuFreqCounter && PdhCollectQueryData(m_cpuQueryFreq) == ERROR_SUCCESS)  {    PDH_RAW_COUNTER cnt;    DWORD cntType;    if (PdhGetRawCounterValue(m_cpuFreqCounter, &cntType, &cnt) == ERROR_SUCCESS &&        (cnt.CStatus == PDH_CSTATUS_VALID_DATA || cnt.CStatus == PDH_CSTATUS_NEW_DATA))    {      return float(cnt.FirstValue);    }  }    if (!m_cores.empty())    return float(m_cores.begin()->second.m_fSpeed);  else    return 0.f;#elif defined(TARGET_FREEBSD)  int hz = 0;  size_t len = sizeof(hz);  if (sysctlbyname("dev.cpu.0.freq", &hz, &len, NULL, 0) != 0)    hz = 0;  return (float)hz;#else  int value = 0;  if (m_fCPUFreq && !m_cpuInfoForFreq)  {    rewind(m_fCPUFreq);    fflush(m_fCPUFreq);    fscanf(m_fCPUFreq, "%d", &value);    value /= 1000.0;  }  if (m_fCPUFreq && m_cpuInfoForFreq)  {    rewind(m_fCPUFreq);    fflush(m_fCPUFreq);    float mhz, avg=0.0;    int n, cpus=0;    while(EOF!=(n=fscanf(m_fCPUFreq," MHz : %f ", &mhz)))    {      if (n>0) {        cpus++;        avg += mhz;      }      fscanf(m_fCPUFreq,"%*s");    }    if (cpus > 0)      value = avg/cpus;  }  return value;#endif}
开发者ID:Karlson2k,项目名称:xbmc,代码行数:61,


示例10: main

intmain(int argc, char *argv[]){	const char *cp, *tp;	const char *sep;	int op, i;	u_int32_t debug, ndebug;	size_t debuglen;	char oid[256];	progname = argv[0];	setoid(oid, sizeof(oid), "wlan0");	if (argc > 1) {		if (strcmp(argv[1], "-d") == 0) {			setoid(oid, sizeof(oid), NULL);			argc -= 1, argv += 1;		} else if (strcmp(argv[1], "-i") == 0) {			if (argc <= 2)				errx(1, "missing interface name for -i option");			get_orig_iface_name(oid, sizeof(oid), argv[2]);			argc -= 2, argv += 2;		} else if (strcmp(argv[1], "-?") == 0)			usage();	}	debuglen = sizeof(debug);	if (sysctlbyname(oid, &debug, &debuglen, NULL, 0) < 0)		err(1, "sysctl-get(%s)", oid);	ndebug = debug;	for (; argc > 1; argc--, argv++) {		cp = argv[1];		do {			u_int bit;			if (*cp == '-') {				cp++;				op = -1;			} else if (*cp == '+') {				cp++;				op = 1;			} else				op = 0;			for (tp = cp; *tp != '/0' && *tp != '+' && *tp != '-';)				tp++;			bit = getflag(cp, tp-cp);			if (op < 0)				ndebug &= ~bit;			else if (op > 0)				ndebug |= bit;			else {				if (bit == 0) {					int c = *cp;					if (isdigit(c))						bit = strtoul(cp, NULL, 0);					else						errx(1, "unknown flag %.*s",							(int)(tp-cp), cp);				}				ndebug = bit;			}		} while (*(cp = tp) != '/0');	}	if (debug != ndebug) {		printf("%s: 0x%x => ", oid, debug);		if (sysctlbyname(oid, NULL, NULL, &ndebug, sizeof(ndebug)) < 0)			err(1, "sysctl-set(%s)", oid);		printf("0x%x", ndebug);		debug = ndebug;	} else		printf("%s: 0x%x", oid, debug);	sep = "<";	for (i = 0; i < N(flags); i++)		if (debug & flags[i].bit) {			printf("%s%s", sep, flags[i].name);			sep = ",";		}	printf("%s/n", *sep != '<' ? ">" : "");	return 0;}
开发者ID:2trill2spill,项目名称:freebsd,代码行数:79,


示例11: netsnmp_mem_arch_load

    /*     * Load the latest memory usage statistics     */int netsnmp_mem_arch_load( netsnmp_cache *cache, void *magic ) {    netsnmp_memory_info *mem;    long           pagesize;    struct uvmexp  uvmexp;    size_t         uvmexp_size  = sizeof(uvmexp);    struct vmtotal total;    size_t         total_size  = sizeof(total);    quad_t          phys_mem;    quad_t          user_mem;    size_t          mem_size  = sizeof(phys_mem);#if defined(openbsd)    int             phys_mem_mib[] = { CTL_HW, HW_PHYSMEM64 };    int             user_mem_mib[] = { CTL_HW, HW_USERMEM64 };    int             uvmexp_mib[] = { CTL_VM, VM_UVMEXP };    int             total_mib[] = { CTL_VM, VM_METER };#else    unsigned int    bufspace;    unsigned int    maxbufspace;    size_t          buf_size  = sizeof(bufspace);#endif    /*     * Retrieve the memory information from the underlying O/S...     */#if defined(openbsd)    sysctl(uvmexp_mib,   2, &uvmexp,   &uvmexp_size,   NULL, 0);    sysctl(total_mib,    2, &total,    &total_size,    NULL, 0);    sysctl(phys_mem_mib, 2, &phys_mem, &mem_size,      NULL, 0);    sysctl(user_mem_mib, 2, &user_mem, &mem_size,      NULL, 0);#else    if (sysctlbyname("vm.uvmexp", &uvmexp, &uvmexp_size, NULL, 0) == -1) {        snmp_log(LOG_ERR, "sysctl vm.uvmexp failed (errno %d)/n", errno);        return -1;    }    if (sysctlbyname("vm.vmmeter", &total,  &total_size, NULL, 0) == -1) {        snmp_log(LOG_ERR, "sysctl vm.vmmeter failed (errno %d)/n", errno);        return -1;    }    if (sysctlbyname("hw.physmem64", &phys_mem, &mem_size, NULL, 0) == -1) {        snmp_log(LOG_ERR, "sysctl hw.physmem64 failed (errno %d)/n", errno);        return -1;    }    if (sysctlbyname("hw.usermem64", &user_mem, &mem_size, NULL, 0) == -1) {        snmp_log(LOG_ERR, "sysctl hw.usermem64 failed (errno %d)/n", errno);        return -1;    }    if (sysctlbyname("vm.bufmem", &bufspace, &buf_size, NULL, 0) == -1) {        snmp_log(LOG_ERR, "sysctl vm.bufmem failed (errno %d)/n", errno);        return -1;    }    if (sysctlbyname("vm.bufmem_hiwater", &maxbufspace, &buf_size, NULL, 0) == -1) {        snmp_log(LOG_ERR, "sysctl vm.bufmem_hiwater failed (errno %d)/n", errno);        return -1;    }#endif    pagesize = sysconf(_SC_PAGESIZE);    /*     * ... 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 = pagesize;        mem->size  = phys_mem/pagesize;        mem->free  = total.t_free;    }    mem = netsnmp_memory_get_byIdx( NETSNMP_MEM_TYPE_USERMEM, 1 );    if (!mem) {        snmp_log_perror("No (user) Memory info entry");    } else {        if (!mem->descr)             mem->descr = strdup("Real memory");        mem->units = pagesize;        mem->size  = user_mem/pagesize;        mem->free  = uvmexp.free;    }#if 1    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 = pagesize;        mem->size  = total.t_vm;        mem->free  = total.t_avm;//.........这里部分代码省略.........
开发者ID:ColdStart,项目名称:SNMPD,代码行数:101,


示例12: ngx_os_specific_init

ngx_int_tngx_os_specific_init(ngx_log_t *log){    int         version, somaxconn;    size_t      size;    ngx_err_t   err;    ngx_uint_t  i;    size = sizeof(ngx_freebsd_kern_ostype);    if (sysctlbyname("kern.ostype",                     ngx_freebsd_kern_ostype, &size, NULL, 0) == -1) {        ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,                      "sysctlbyname(kern.ostype) failed");        if (ngx_errno != NGX_ENOMEM) {            return NGX_ERROR;        }        ngx_freebsd_kern_ostype[size - 1] = '/0';    }    size = sizeof(ngx_freebsd_kern_osrelease);    if (sysctlbyname("kern.osrelease",                     ngx_freebsd_kern_osrelease, &size, NULL, 0) == -1) {        ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,                      "sysctlbyname(kern.osrelease) failed");        if (ngx_errno != NGX_ENOMEM) {            return NGX_ERROR;        }        ngx_freebsd_kern_osrelease[size - 1] = '/0';    }    size = sizeof(int);    if (sysctlbyname("kern.osreldate",                     &ngx_freebsd_kern_osreldate, &size, NULL, 0) == -1) {        ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,                      "sysctlbyname(kern.osreldate) failed");        return NGX_ERROR;    }    version = ngx_freebsd_kern_osreldate;#if (NGX_HAVE_SENDFILE)    /*     * The determination of the sendfile() "nbytes bug" is complex enough.     * There are two sendfile() syscalls: a new #393 has no bug while     * an old #336 has the bug in some versions and has not in others.     * Besides libc_r wrapper also emulates the bug in some versions.     * There is no way to say exactly if syscall #336 in FreeBSD circa 4.6     * has the bug.  We use the algorithm that is correct at least for     * RELEASEs and for syscalls only (not libc_r wrapper).     *     * 4.6.1-RELEASE and below have the bug     * 4.6.2-RELEASE and above have the new syscall     *     * We detect the new sendfile() syscall available at the compile time     * to allow an old binary to run correctly on an updated FreeBSD system.     */#if (__FreeBSD__ == 4 && __FreeBSD_version >= 460102) /    || __FreeBSD_version == 460002 || __FreeBSD_version >= 500039    /* a new syscall without the bug */    ngx_freebsd_sendfile_nbytes_bug = 0;#else    /* an old syscall that may have the bug */    ngx_freebsd_sendfile_nbytes_bug = 1;#endif#endif /* NGX_HAVE_SENDFILE */    if ((version < 500000 && version >= 440003) || version >= 500017) {        ngx_freebsd_use_tcp_nopush = 1;    }    for (i = 0; sysctls[i].name; i++) {        size = sysctls[i].size;        if (sysctlbyname(sysctls[i].name, sysctls[i].value, &size, NULL, 0)            == 0)        {            sysctls[i].exists = 1;            continue;        }        err = ngx_errno;        if (err == NGX_ENOENT) {//.........这里部分代码省略.........
开发者ID:sudorails,项目名称:e_verification,代码行数:101,


示例13: _mesa_check_os_sse_support

/** * Check if SSE is supported. * If not, turn off the X86_FEATURE_XMM flag in _mesa_x86_cpu_features. */void _mesa_check_os_sse_support( void ){#if defined(__FreeBSD__)   {      int ret, enabled;      unsigned int len;      len = sizeof(enabled);      ret = sysctlbyname("hw.instruction_sse", &enabled, &len, NULL, 0);      if (ret || !enabled)         _mesa_x86_cpu_features &= ~(X86_FEATURE_XMM);   }#elif defined (__NetBSD__)   {      int ret, enabled;      size_t len = sizeof(enabled);      ret = sysctlbyname("machdep.sse", &enabled, &len, (void *)NULL, 0);      if (ret || !enabled)         _mesa_x86_cpu_features &= ~(X86_FEATURE_XMM);   }#elif defined(__OpenBSD__)   {      int mib[2];      int ret, enabled;      size_t len = sizeof(enabled);      mib[0] = CTL_MACHDEP;      mib[1] = CPU_SSE;      ret = sysctl(mib, 2, &enabled, &len, NULL, 0);      if (ret || !enabled)         _mesa_x86_cpu_features &= ~(X86_FEATURE_XMM);   }#elif defined(_WIN32)   LPTOP_LEVEL_EXCEPTION_FILTER oldFilter;      /* Install our ExceptionFilter */   oldFilter = SetUnhandledExceptionFilter( ExceptionFilter );      if ( cpu_has_xmm ) {      _mesa_debug(NULL, "Testing OS support for SSE.../n");      _mesa_test_os_sse_support();      if ( cpu_has_xmm ) {	 _mesa_debug(NULL, "Yes./n");      } else {	 _mesa_debug(NULL, "No!/n");      }   }   if ( cpu_has_xmm ) {      _mesa_debug(NULL, "Testing OS support for SSE unmasked exceptions.../n");      _mesa_test_os_sse_exception_support();      if ( cpu_has_xmm ) {	 _mesa_debug(NULL, "Yes./n");      } else {	 _mesa_debug(NULL, "No!/n");      }   }   /* Restore previous exception filter */   SetUnhandledExceptionFilter( oldFilter );   if ( cpu_has_xmm ) {      _mesa_debug(NULL, "Tests of OS support for SSE passed./n");   } else {      _mesa_debug(NULL, "Tests of OS support for SSE failed!/n");   }#else   /* Do nothing on other platforms for now.    */   if (detection_debug)      _mesa_debug(NULL, "Not testing OS support for SSE, leaving enabled./n");#endif /* __FreeBSD__ */}
开发者ID:austriancoder,项目名称:mesa-1,代码行数:81,


示例14: GlobalMemoryStatusEx

void GlobalMemoryStatusEx(LPMEMORYSTATUSEX lpBuffer){  if (!lpBuffer)    return;  memset(lpBuffer, 0, sizeof(MEMORYSTATUSEX));  lpBuffer->dwLength = sizeof(MEMORYSTATUSEX);#ifdef __APPLE__  uint64_t physmem;  size_t len = sizeof physmem;  int mib[2] = { CTL_HW, HW_MEMSIZE };  size_t miblen = sizeof(mib) / sizeof(mib[0]);  // Total physical memory.  if (sysctl(mib, miblen, &physmem, &len, NULL, 0) == 0 && len == sizeof (physmem))      lpBuffer->ullTotalPhys = physmem;  // Virtual memory.  mib[0] = CTL_VM; mib[1] = VM_SWAPUSAGE;  struct xsw_usage swap;  len = sizeof(struct xsw_usage);  if (sysctl(mib, miblen, &swap, &len, NULL, 0) == 0)  {      lpBuffer->ullAvailPageFile = swap.xsu_avail;      lpBuffer->ullTotalVirtual = lpBuffer->ullTotalPhys + swap.xsu_total;  }  // In use.  mach_port_t stat_port = mach_host_self();  vm_statistics_data_t vm_stat;  mach_msg_type_number_t count = sizeof(vm_stat) / sizeof(natural_t);  if (host_statistics(stat_port, HOST_VM_INFO, (host_info_t)&vm_stat, &count) == 0)  {      // Find page size.      int pageSize;      mib[0] = CTL_HW; mib[1] = HW_PAGESIZE;      len = sizeof(int);      if (sysctl(mib, miblen, &pageSize, &len, NULL, 0) == 0)      {          uint64_t used = (vm_stat.active_count + vm_stat.inactive_count + vm_stat.wire_count) * pageSize;          lpBuffer->ullAvailPhys = lpBuffer->ullTotalPhys - used;          lpBuffer->ullAvailVirtual  = lpBuffer->ullAvailPhys; // FIXME.      }  }#elif defined(__FreeBSD__)  /* sysctl hw.physmem */  size_t physmem = 0, mem_free = 0, pagesize = 0, swap_free = 0;  size_t mem_avail = 0, mem_inactive = 0, mem_cache = 0, len = 0;  /* physmem */  len = sizeof(physmem);  if (sysctlbyname("hw.physmem", &physmem, &len, NULL, 0) == 0) {    lpBuffer->ullTotalPhys = physmem;    lpBuffer->ullTotalVirtual = physmem;  }  /* pagesize */  len = sizeof(pagesize);  if (sysctlbyname("hw.pagesize", &pagesize, &len, NULL, 0) != 0)    pagesize = 4096;  /* mem_inactive */  len = sizeof(mem_inactive);  if (sysctlbyname("vm.stats.vm.v_inactive_count", &mem_inactive, &len, NULL, 0) == 0)    mem_inactive *= pagesize;  /* mem_cache */  len = sizeof(mem_cache);  if (sysctlbyname("vm.stats.vm.v_cache_count", &mem_cache, &len, NULL, 0) == 0)    mem_cache *= pagesize;  /* mem_free */  len = sizeof(mem_free);  if (sysctlbyname("vm.stats.vm.v_free_count", &mem_free, &len, NULL, 0) == 0)    mem_free *= pagesize;  /* mem_avail = mem_inactive + mem_cache + mem_free */  lpBuffer->ullAvailPhys = mem_inactive + mem_cache + mem_free;  lpBuffer->ullAvailVirtual = mem_inactive + mem_cache + mem_free;  if (sysctlbyname("vm.stats.vm.v_swappgsout", &swap_free, &len, NULL, 0) == 0)    lpBuffer->ullAvailPageFile = swap_free * pagesize;#else  struct sysinfo info;  char name[32];  unsigned val;  if (!procMeminfoFP && (procMeminfoFP = fopen("/proc/meminfo", "r")) == NULL)    sysinfo(&info);  else  {    memset(&info, 0, sizeof(struct sysinfo));    info.mem_unit = 4096;    while (fscanf(procMeminfoFP, "%31s %u%*[^/n]/n", name, &val) != EOF)    {      if (strncmp("MemTotal:", name, 9) == 0)        info.totalram = val/4;      else if (strncmp("MemFree:", name, 8) == 0)        info.freeram = val/4;      else if (strncmp("Buffers:", name, 8) == 0)        info.bufferram += val/4;      else if (strncmp("Cached:", name, 7) == 0)        info.bufferram += val/4;//.........这里部分代码省略.........
开发者ID:Omel,项目名称:xbmc,代码行数:101,


示例15: hwloc_look_darwin

static inthwloc_look_darwin(struct hwloc_backend *backend){  struct hwloc_topology *topology = backend->topology;  int64_t _nprocs;  unsigned nprocs;  int64_t _npackages;  unsigned i, j, cpu;  struct hwloc_obj *obj;  size_t size;  int64_t l1dcachesize, l1icachesize;  int64_t cacheways[2];  int64_t l2cachesize;  int64_t cachelinesize;  int64_t memsize;  char cpumodel[64];  if (topology->levels[0][0]->cpuset)    /* somebody discovered things */    return 0;  hwloc_alloc_obj_cpusets(topology->levels[0][0]);  if (hwloc_get_sysctlbyname("hw.ncpu", &_nprocs) || _nprocs <= 0)    return -1;  nprocs = _nprocs;  topology->support.discovery->pu = 1;  hwloc_debug("%u procs/n", nprocs);  size = sizeof(cpumodel);  if (sysctlbyname("machdep.cpu.brand_string", cpumodel, &size, NULL, 0))    cpumodel[0] = '/0';  if (!hwloc_get_sysctlbyname("hw.packages", &_npackages) && _npackages > 0) {    unsigned npackages = _npackages;    int64_t _cores_per_package;    int64_t _logical_per_package;    unsigned logical_per_package;    hwloc_debug("%u packages/n", npackages);    if (!hwloc_get_sysctlbyname("machdep.cpu.logical_per_package", &_logical_per_package) && _logical_per_package > 0)      logical_per_package = _logical_per_package;    else      /* Assume the trivia.  */      logical_per_package = nprocs / npackages;    hwloc_debug("%u threads per package/n", logical_per_package);    if (nprocs == npackages * logical_per_package)      for (i = 0; i < npackages; i++) {        obj = hwloc_alloc_setup_object(HWLOC_OBJ_SOCKET, i);        obj->cpuset = hwloc_bitmap_alloc();        for (cpu = i*logical_per_package; cpu < (i+1)*logical_per_package; cpu++)          hwloc_bitmap_set(obj->cpuset, cpu);        hwloc_debug_1arg_bitmap("package %u has cpuset %s/n",                   i, obj->cpuset);        if (cpumodel[0] != '/0')          hwloc_obj_add_info(obj, "CPUModel", cpumodel);        hwloc_insert_object_by_cpuset(topology, obj);      }    else      if (cpumodel[0] != '/0')        hwloc_obj_add_info(topology->levels[0][0], "CPUModel", cpumodel);    if (!hwloc_get_sysctlbyname("machdep.cpu.cores_per_package", &_cores_per_package) && _cores_per_package > 0) {      unsigned cores_per_package = _cores_per_package;      hwloc_debug("%u cores per package/n", cores_per_package);      if (!(logical_per_package % cores_per_package))        for (i = 0; i < npackages * cores_per_package; i++) {          obj = hwloc_alloc_setup_object(HWLOC_OBJ_CORE, i);          obj->cpuset = hwloc_bitmap_alloc();          for (cpu = i*(logical_per_package/cores_per_package);               cpu < (i+1)*(logical_per_package/cores_per_package);               cpu++)            hwloc_bitmap_set(obj->cpuset, cpu);          hwloc_debug_1arg_bitmap("core %u has cpuset %s/n",                     i, obj->cpuset);          hwloc_insert_object_by_cpuset(topology, obj);        }    }  } else    if (cpumodel[0] != '/0')      hwloc_obj_add_info(topology->levels[0][0], "CPUModel", cpumodel);  if (hwloc_get_sysctlbyname("hw.l1dcachesize", &l1dcachesize))    l1dcachesize = 0;  if (hwloc_get_sysctlbyname("hw.l1icachesize", &l1icachesize))    l1icachesize = 0;  if (hwloc_get_sysctlbyname("hw.l2cachesize", &l2cachesize))    l2cachesize = 0;//.........这里部分代码省略.........
开发者ID:BlueBrain,项目名称:hwloc,代码行数:101,


示例16: sysapi_translate_arch

// find arch const char *sysapi_translate_arch( const char *machine, const char *){	char tmp[64];	char *tmparch;#if defined(AIX)	/* AIX machines have a ton of different models encoded into the uname		structure, so go to some other function to decode and group the		architecture together */	struct utsname buf;	if( uname(&buf) < 0 ) {		return NULL;	}	return( get_aix_arch( &buf ) );#elif defined(HPUX)	return( get_hpux_arch( ) );#else		// Get ARCH		//mikeu: I modified this to also accept values from Globus' LDAP server	if( !strcmp(machine, "alpha") ) {		sprintf( tmp, "ALPHA" );	}	else if( !strcmp(machine, "i86pc") ) {		sprintf( tmp, "INTEL" );	}	else if( !strcmp(machine, "i686") ) {		sprintf( tmp, "INTEL" );	}	else if( !strcmp(machine, "i586") ) {		sprintf( tmp, "INTEL" );	}	else if( !strcmp(machine, "i486") ) {		sprintf( tmp, "INTEL" );	}	else if( !strcmp(machine, "i386") ) { //LDAP entry#if defined(Darwin)		/* Mac OS X often claims to be i386 in uname, even if the		 * hardware is x86_64 and the OS can run 64-bit binaries.		 * We'll base our architecture name on the default build		 * target for gcc. In 10.5 and earlier, that's i386.		 * On 10.6, it's x86_64.		 * The value we're querying is the kernel version.		 * 10.6 kernels have a version that starts with "10."		 * Older versions have a lower first number.		 */		int ret;		char val[32];		size_t len = sizeof(val);		/* assume x86 */		sprintf( tmp, "INTEL" );		ret = sysctlbyname("kern.osrelease", &val, &len, NULL, 0);		if (ret == 0 && strncmp(val, "10.", 3) == 0) {			/* but we could be proven wrong */			sprintf( tmp, "X86_64" );		}#else		sprintf( tmp, "INTEL" );#endif	}	else if( !strcmp(machine, "ia64") ) {		sprintf( tmp, "IA64" );	}	else if( !strcmp(machine, "x86_64") ) {		sprintf( tmp, "X86_64" );	}	//	// FreeBSD 64-bit reports themselves as "amd64"	// Andy - 01/25/2008	//	else if( !strcmp(machine, "amd64") ) {		sprintf( tmp, "X86_64" );	}	else if( !strcmp(machine, "sun4u") ) {		sprintf( tmp, "SUN4u" );	}	else if( !strcmp(machine, "sun4m") ) {		sprintf( tmp, "SUN4x" );	}	else if( !strcmp(machine, "sun4c") ) {		sprintf( tmp, "SUN4x" );	}	else if( !strcmp(machine, "sparc") ) { //LDAP entry		sprintf( tmp, "SUN4x" );	}	else if( !strcmp(machine, "Power Macintosh") ) { //LDAP entry		sprintf( tmp, "PPC" );	}	else if( !strcmp(machine, "ppc") ) {		sprintf( tmp, "PPC" );	}	else if( !strcmp(machine, "ppc32") ) {		sprintf( tmp, "PPC" );//.........这里部分代码省略.........
开发者ID:AmesianX,项目名称:htcondor,代码行数:101,


示例17: init_private

static voidinit_private(void){	struct rlimit rlim;	size_t len;	int mib[2];	char *env, *env_bigstack, *env_splitstack;	_thr_umutex_init(&_mutex_static_lock);	_thr_umutex_init(&_cond_static_lock);	_thr_umutex_init(&_rwlock_static_lock);	_thr_umutex_init(&_keytable_lock);	_thr_urwlock_init(&_thr_atfork_lock);	_thr_umutex_init(&_thr_event_lock);	_thr_umutex_init(&_suspend_all_lock);	_thr_spinlock_init();	_thr_list_init();	_thr_wake_addr_init();	_sleepq_init();	_single_thread = NULL;	_suspend_all_waiters = 0;	/*	 * Avoid reinitializing some things if they don't need to be,	 * e.g. after a fork().	 */	if (init_once == 0) {		__thr_pshared_init();		/* Find the stack top */		mib[0] = CTL_KERN;		mib[1] = KERN_USRSTACK;		len = sizeof (_usrstack);		if (sysctl(mib, 2, &_usrstack, &len, NULL, 0) == -1)			PANIC("Cannot get kern.usrstack from sysctl");		env_bigstack = getenv("LIBPTHREAD_BIGSTACK_MAIN");		env_splitstack = getenv("LIBPTHREAD_SPLITSTACK_MAIN");		if (env_bigstack != NULL || env_splitstack == NULL) {			if (getrlimit(RLIMIT_STACK, &rlim) == -1)				PANIC("Cannot get stack rlimit");			_thr_stack_initial = rlim.rlim_cur;		}		len = sizeof(_thr_is_smp);		sysctlbyname("kern.smp.cpus", &_thr_is_smp, &len, NULL, 0);		_thr_is_smp = (_thr_is_smp > 1);		_thr_page_size = getpagesize();		_thr_guard_default = _thr_page_size;		_pthread_attr_default.guardsize_attr = _thr_guard_default;		_pthread_attr_default.stacksize_attr = _thr_stack_default;		env = getenv("LIBPTHREAD_SPINLOOPS");		if (env)			_thr_spinloops = atoi(env);		env = getenv("LIBPTHREAD_YIELDLOOPS");		if (env)			_thr_yieldloops = atoi(env);		env = getenv("LIBPTHREAD_QUEUE_FIFO");		if (env)			_thr_queuefifo = atoi(env);		TAILQ_INIT(&_thr_atfork_list);	}	init_once = 1;}
开发者ID:Hooman3,项目名称:freebsd,代码行数:61,


示例18: uv_cpu_info

int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {  unsigned int ticks = (unsigned int)sysconf(_SC_CLK_TCK),               multiplier = ((uint64_t)1000L / ticks), cpuspeed, maxcpus,               cur = 0;  uv_cpu_info_t* cpu_info;  const char* maxcpus_key;  const char* cptimes_key;  char model[512];  long* cp_times;  int numcpus;  size_t size;  int i;#if defined(__DragonFly__)  /* This is not quite correct but DragonFlyBSD doesn't seem to have anything   * comparable to kern.smp.maxcpus or kern.cp_times (kern.cp_time is a total,   * not per CPU). At least this stops uv_cpu_info() from failing completely.   */  maxcpus_key = "hw.ncpu";  cptimes_key = "kern.cp_time";#else  maxcpus_key = "kern.smp.maxcpus";  cptimes_key = "kern.cp_times";#endif  size = sizeof(model);  if (sysctlbyname("hw.model", &model, &size, NULL, 0))    return -errno;  size = sizeof(numcpus);  if (sysctlbyname("hw.ncpu", &numcpus, &size, NULL, 0))    return -errno;  *cpu_infos = uv__malloc(numcpus * sizeof(**cpu_infos));  if (!(*cpu_infos))    return -ENOMEM;  *count = numcpus;  size = sizeof(cpuspeed);  if (sysctlbyname("hw.clockrate", &cpuspeed, &size, NULL, 0)) {    SAVE_ERRNO(uv__free(*cpu_infos));    return -errno;  }  /* kern.cp_times on FreeBSD i386 gives an array up to maxcpus instead of   * ncpu.   */  size = sizeof(maxcpus);  if (sysctlbyname(maxcpus_key, &maxcpus, &size, NULL, 0)) {    SAVE_ERRNO(uv__free(*cpu_infos));    return -errno;  }  size = maxcpus * CPUSTATES * sizeof(long);  cp_times = uv__malloc(size);  if (cp_times == NULL) {    uv__free(*cpu_infos);    return -ENOMEM;  }  if (sysctlbyname(cptimes_key, cp_times, &size, NULL, 0)) {    SAVE_ERRNO(uv__free(cp_times));    SAVE_ERRNO(uv__free(*cpu_infos));    return -errno;  }  for (i = 0; i < numcpus; i++) {    cpu_info = &(*cpu_infos)[i];    cpu_info->cpu_times.user = (uint64_t)(cp_times[CP_USER+cur]) * multiplier;    cpu_info->cpu_times.nice = (uint64_t)(cp_times[CP_NICE+cur]) * multiplier;    cpu_info->cpu_times.sys = (uint64_t)(cp_times[CP_SYS+cur]) * multiplier;    cpu_info->cpu_times.idle = (uint64_t)(cp_times[CP_IDLE+cur]) * multiplier;    cpu_info->cpu_times.irq = (uint64_t)(cp_times[CP_INTR+cur]) * multiplier;    cpu_info->model = uv__strdup(model);    cpu_info->speed = cpuspeed;    cur+=CPUSTATES;  }  uv__free(cp_times);  return 0;}
开发者ID:0-wiz-0,项目名称:libuv,代码行数:86,


示例19: hwloc_look_darwin

voidhwloc_look_darwin(struct hwloc_topology *topology){  int64_t _nprocs;  unsigned nprocs;  int64_t _npackages;  unsigned i, j, cpu;  struct hwloc_obj *obj;  size_t size;  int64_t l1cachesize;  int64_t l2cachesize;  int64_t cachelinesize;  int64_t memsize;  if (hwloc_get_sysctlbyname("hw.ncpu", &_nprocs) || _nprocs <= 0)    return;  nprocs = _nprocs;  topology->support.discovery->pu = 1;  hwloc_debug("%u procs/n", nprocs);  if (!hwloc_get_sysctlbyname("hw.packages", &_npackages) && _npackages > 0) {    unsigned npackages = _npackages;    int64_t _cores_per_package;    int64_t _logical_per_package;    unsigned logical_per_package;    hwloc_debug("%u packages/n", npackages);    if (!hwloc_get_sysctlbyname("machdep.cpu.logical_per_package", &_logical_per_package) && _logical_per_package > 0)      logical_per_package = _logical_per_package;    else      /* Assume the trivia.  */      logical_per_package = nprocs / npackages;    hwloc_debug("%u threads per package/n", logical_per_package);    if (nprocs == npackages * logical_per_package)      for (i = 0; i < npackages; i++) {        obj = hwloc_alloc_setup_object(HWLOC_OBJ_SOCKET, i);        obj->cpuset = hwloc_bitmap_alloc();        for (cpu = i*logical_per_package; cpu < (i+1)*logical_per_package; cpu++)          hwloc_bitmap_set(obj->cpuset, cpu);        hwloc_debug_1arg_bitmap("package %u has cpuset %s/n",                   i, obj->cpuset);        hwloc_insert_object_by_cpuset(topology, obj);      }    if (!hwloc_get_sysctlbyname("machdep.cpu.cores_per_package", &_cores_per_package) && _cores_per_package > 0) {      unsigned cores_per_package = _cores_per_package;      hwloc_debug("%u cores per package/n", cores_per_package);      if (!(logical_per_package % cores_per_package))        for (i = 0; i < npackages * cores_per_package; i++) {          obj = hwloc_alloc_setup_object(HWLOC_OBJ_CORE, i);          obj->cpuset = hwloc_bitmap_alloc();          for (cpu = i*(logical_per_package/cores_per_package);               cpu < (i+1)*(logical_per_package/cores_per_package);               cpu++)            hwloc_bitmap_set(obj->cpuset, cpu);          hwloc_debug_1arg_bitmap("core %u has cpuset %s/n",                     i, obj->cpuset);          hwloc_insert_object_by_cpuset(topology, obj);        }    }  }  if (hwloc_get_sysctlbyname("hw.l1dcachesize", &l1cachesize))    l1cachesize = 0;  if (hwloc_get_sysctlbyname("hw.l2cachesize", &l2cachesize))    l2cachesize = 0;  if (hwloc_get_sysctlbyname("hw.cachelinesize", &cachelinesize))    cachelinesize = 0;  if (hwloc_get_sysctlbyname("hw.memsize", &memsize))    memsize = 0;  if (!sysctlbyname("hw.cacheconfig", NULL, &size, NULL, 0)) {    unsigned n = size / sizeof(uint32_t);    uint64_t *cacheconfig = NULL;    uint64_t *cachesize = NULL;    uint32_t *cacheconfig32 = NULL;    cacheconfig = malloc(sizeof(uint64_t) * n);    if (NULL == cacheconfig) {        goto out;    }    cachesize = malloc(sizeof(uint64_t) * n);    if (NULL == cachesize) {        goto out;    }    cacheconfig32 = malloc(sizeof(uint32_t) * n);    if (NULL == cacheconfig32) {        goto out;    }//.........这里部分代码省略.........
开发者ID:BlueBolt,项目名称:BB_GridEngine,代码行数:101,


示例20: ipfw_main

//.........这里部分代码省略.........                *av_p++ = '/0';                ac++;                l = 0;                first = i+1;            }        }    }    /*     * set the progname pointer to the original string     * and terminate the array with null     */    av[0] = oldav[0];    av[ac] = NULL;    /* Set the force flag for non-interactive processes */    if (!co.do_force)        co.do_force = !isatty(STDIN_FILENO);#ifdef EMULATE_SYSCTL /* sysctl emulation */    if ( ac >= 2 && !strcmp(av[1], "sysctl")) {        char *s;        int i;        if (ac != 3) {            printf(	"sysctl emulation usage:/n"                    "	ipfw sysctl name[=value]/n"                    "	ipfw sysctl -a/n");            return 0;        }        s = strchr(av[2], '=');        if (s == NULL) {            s = !strcmp(av[2], "-a") ? NULL : av[2];            sysctlbyname(s, NULL, NULL, NULL, 0);        } else {	/* ipfw sysctl x.y.z=value */            /* assume an INT value, will extend later */            if (s[1] == '/0') {                printf("ipfw sysctl: missing value/n/n");                return 0;            }            *s = '/0';            i = strtol(s+1, NULL, 0);            sysctlbyname(av[2], NULL, NULL, &i, sizeof(int));        }        return 0;    }#endif    /* Save arguments for final freeing of memory. */    save_av = av;    optind = optreset = 1;	/* restart getopt() */    while ((ch = getopt(ac, av, "abcdefhinNp:qs:STtv")) != -1)        switch (ch) {        case 'a':            do_acct = 1;            break;        case 'b':            co.comment_only = 1;            co.do_compact = 1;            break;        case 'c':            co.do_compact = 1;            break;
开发者ID:coyizumi,项目名称:cs111,代码行数:67,


示例21: makenetvfslist

static char *makenetvfslist(void){	char *str, *strptr, **listptr;	struct xvfsconf *xvfsp, *keep_xvfsp;	size_t buflen;	int cnt, i, maxvfsconf;	if (sysctlbyname("vfs.conflist", NULL, &buflen, NULL, 0) < 0) {		warn("sysctl(vfs.conflist)");		return (NULL);	}	xvfsp = malloc(buflen);	if (xvfsp == NULL) {		warnx("malloc failed");		return (NULL);	}	keep_xvfsp = xvfsp;	if (sysctlbyname("vfs.conflist", xvfsp, &buflen, NULL, 0) < 0) {		warn("sysctl(vfs.conflist)");		free(keep_xvfsp);		return (NULL);	}	maxvfsconf = buflen / sizeof(struct xvfsconf);	if ((listptr = malloc(sizeof(char*) * maxvfsconf)) == NULL) {		warnx("malloc failed");		free(keep_xvfsp);		return (NULL);	}	for (cnt = 0, i = 0; i < maxvfsconf; i++) {		if (xvfsp->vfc_flags & VFCF_NETWORK) {			listptr[cnt++] = strdup(xvfsp->vfc_name);			if (listptr[cnt-1] == NULL) {				warnx("malloc failed");				free(listptr);				free(keep_xvfsp);				return (NULL);			}		}		xvfsp++;	}	if (cnt == 0 ||	    (str = malloc(sizeof(char) * (32 * cnt + cnt + 2))) == NULL) {		if (cnt > 0)			warnx("malloc failed");		free(listptr);		free(keep_xvfsp);		return (NULL);	}	*str = 'n'; *(str + 1) = 'o';	for (i = 0, strptr = str + 2; i < cnt; i++, strptr++) {		strlcpy(strptr, listptr[i], 32);		strptr += strlen(listptr[i]);		*strptr = ',';		free(listptr[i]);	}	*(--strptr) = '/0';	free(keep_xvfsp);	free(listptr);	return (str);}
开发者ID:jhbsz,项目名称:JabirOS-source,代码行数:66,


示例22: get_zfs_value

const char zfs_arcstat[] = "kstat.zfs.misc.arcstats.";#if !defined(kstat_t)typedef void kstat_t;#endifstatic long long get_zfs_value(kstat_t *dummy __attribute__((unused)),                               char const *name){    char buffer[256];    long long value;    size_t valuelen = sizeof(value);    int rv;    ssnprintf (buffer, sizeof (buffer), "%s%s", zfs_arcstat, name);    rv = sysctlbyname (buffer, (void *) &value, &valuelen,                       /* new value = */ NULL, /* new length = */ (size_t) 0);    if (rv == 0)        return (value);    return (-1);}#endifstatic void za_submit (const char* type, const char* type_instance, value_t* values, int values_len){    value_list_t vl = VALUE_LIST_INIT;    vl.values = values;    vl.values_len = values_len;    sstrncpy (vl.host, hostname_g, sizeof (vl.host));
开发者ID:GoogleCloudPlatform,项目名称:collectd,代码行数:32,


示例23: ProcessList_new

ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId) {   FreeBSDProcessList* fpl = xCalloc(1, sizeof(FreeBSDProcessList));   ProcessList* pl = (ProcessList*) fpl;   ProcessList_init(pl, Class(FreeBSDProcess), usersTable, pidWhiteList, userId);   size_t len;   // physical memory in system: hw.physmem   // physical page size: hw.pagesize   // usable pagesize : vm.stats.vm.v_page_size   len = 2; sysctlnametomib("hw.physmem", MIB_hw_physmem, &len);   len = sizeof(pageSize);   if (sysctlbyname("vm.stats.vm.v_page_size", &pageSize, &len, NULL, 0) == -1) {      pageSize = PAGE_SIZE;      pageSizeKb = PAGE_SIZE_KB;   } else {      pageSizeKb = pageSize / ONE_K;   }   // usable page count vm.stats.vm.v_page_count   // actually usable memory : vm.stats.vm.v_page_count * vm.stats.vm.v_page_size   len = 4; sysctlnametomib("vm.stats.vm.v_page_count", MIB_vm_stats_vm_v_page_count, &len);   len = 4; sysctlnametomib("vm.stats.vm.v_wire_count", MIB_vm_stats_vm_v_wire_count, &len);   len = 4; sysctlnametomib("vm.stats.vm.v_active_count", MIB_vm_stats_vm_v_active_count, &len);   len = 4; sysctlnametomib("vm.stats.vm.v_cache_count", MIB_vm_stats_vm_v_cache_count, &len);   len = 4; sysctlnametomib("vm.stats.vm.v_inactive_count", MIB_vm_stats_vm_v_inactive_count, &len);   len = 4; sysctlnametomib("vm.stats.vm.v_free_count", MIB_vm_stats_vm_v_free_count, &len);   len = 2; sysctlnametomib("vfs.bufspace", MIB_vfs_bufspace, &len);   len = sizeof(fpl->memZfsArc);   if (sysctlbyname("kstat.zfs.misc.arcstats.size", &fpl->memZfsArc, &len,	    NULL, 0) == 0 && fpl->memZfsArc != 0) {      sysctlnametomib("kstat.zfs.misc.arcstats.size", MIB_kstat_zfs_misc_arcstats_size, &len);		  fpl->zfsArcEnabled = 1;   } else {		  fpl->zfsArcEnabled = 0;   }   int smp = 0;   len = sizeof(smp);   if (sysctlbyname("kern.smp.active", &smp, &len, NULL, 0) != 0 || len != sizeof(smp)) {      smp = 0;   }   int cpus = 1;   len = sizeof(cpus);   if (smp) {      int err = sysctlbyname("kern.smp.cpus", &cpus, &len, NULL, 0);      if (err) cpus = 1;   } else {      cpus = 1;   }   size_t sizeof_cp_time_array = sizeof(unsigned long) * CPUSTATES;   len = 2; sysctlnametomib("kern.cp_time", MIB_kern_cp_time, &len);   fpl->cp_time_o = xCalloc(cpus, sizeof_cp_time_array);   fpl->cp_time_n = xCalloc(cpus, sizeof_cp_time_array);   len = sizeof_cp_time_array;   // fetch intial single (or average) CPU clicks from kernel   sysctl(MIB_kern_cp_time, 2, fpl->cp_time_o, &len, NULL, 0);   // on smp box, fetch rest of intial CPU's clicks   if (cpus > 1) {      len = 2; sysctlnametomib("kern.cp_times", MIB_kern_cp_times, &len);      fpl->cp_times_o = xCalloc(cpus, sizeof_cp_time_array);      fpl->cp_times_n = xCalloc(cpus, sizeof_cp_time_array);      len = cpus * sizeof_cp_time_array;      sysctl(MIB_kern_cp_times, 2, fpl->cp_times_o, &len, NULL, 0);   }   pl->cpuCount = MAX(cpus, 1);   if (cpus == 1 ) {     fpl->cpus = xRealloc(fpl->cpus, sizeof(CPUData));   } else {     // on smp we need CPUs + 1 to store averages too (as kernel kindly provides that as well)     fpl->cpus = xRealloc(fpl->cpus, (pl->cpuCount + 1) * sizeof(CPUData));   }   len = sizeof(kernelFScale);   if (sysctlbyname("kern.fscale", &kernelFScale, &len, NULL, 0) == -1) {      //sane default for kernel provded CPU precentage scaling, at least on x86 machines, in case this sysctl call failed      kernelFScale = 2048;   }   fpl->kd = kvm_open(NULL, "/dev/null", NULL, 0, NULL);   assert(fpl->kd);   return pl;}
开发者ID:MofX,项目名称:htop,代码行数:98,


示例24: main

//.........这里部分代码省略.........	for (nusers = 0; (utmp = getutxent()) != NULL;) {		if (utmp->ut_type != USER_PROCESS)			continue;		if (!(stp = ttystat(utmp->ut_line)))			continue;	/* corrupted record */		++nusers;		if (wcmd == 0)			continue;		if (sel_users) {			int usermatch;			char **user;			usermatch = 0;			for (user = sel_users; !usermatch && *user; user++)				if (!strcmp(utmp->ut_user, *user))					usermatch = 1;			if (!usermatch)				continue;		}		if ((ep = calloc(1, sizeof(struct entry))) == NULL)			errx(1, "calloc");		*nextp = ep;		nextp = &ep->next;		memmove(&ep->utmp, utmp, sizeof *utmp);		ep->tdev = stp->st_rdev;		/*		 * If this is the console device, attempt to ascertain		 * the true console device dev_t.		 */		if (ep->tdev == 0) {			size_t size;			size = sizeof(dev_t);			(void)sysctlbyname("machdep.consdev", &ep->tdev, &size, NULL, 0);		}		touched = stp->st_atime;		if (touched < ep->utmp.ut_tv.tv_sec) {			/* tty untouched since before login */			touched = ep->utmp.ut_tv.tv_sec;		}		if ((ep->idle = now - touched) < 0)			ep->idle = 0;	}	endutxent();	if (header || wcmd == 0) {		pr_header(&now, nusers);		if (wcmd == 0) {			(void)kvm_close(kd);			exit(0);		}#define HEADER_USER		"USER"#define HEADER_TTY		"TTY"#define HEADER_FROM		"FROM"#define HEADER_LOGIN_IDLE	"[email
C++ sysctlnametomib函数代码示例
C++ sysctl_handle_int函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。