/* Multithreading support */ int getNumberOfProcessors() { #if defined(_SC_NPROCESSORS_CONF) return sysconf(_SC_NPROCESSORS_CONF); #elif defined(_SC_NPROCESSORS_ONLN) return sysconf(_SC_NPROCESSORS_ONLN); #elif defined(__FreeBSD__) || defined(__APPLE__) unsigned int len, count; len = sizeof(count); return sysctlbyname("hw.ncpu", &count, &len, NULL, 0); #elif defined(_GNU_SOURCE) return get_nprocs_conf(); #elif defined(_WIN32) SYSTEM_INFO sysinfo; GetSystemInfo(&sysinfo); return sysinfo.dwNumberOfProcessors; #elif defined(PTW32_VERSION) || defined(__hpux) return pthread_num_processors_np(); #else return 1; #endif }
int testprog_set_affinity(int start_cpu, int end_cpu) { cpu_set_t cpu_set; CPU_ZERO(&cpu_set); int i; int retval; int n_cpus = get_nprocs(); int n_cpus_conf = get_nprocs_conf(); if (n_cpus != n_cpus_conf) { printf("uh, ncpus=%d but ncpus_conf=%d\n", n_cpus, n_cpus_conf); } if (start_cpu < 0) start_cpu=0; if (end_cpu < 0 || end_cpu > n_cpus_conf) { end_cpu = n_cpus_conf; } for (i=start_cpu; i<end_cpu; i++) { CPU_SET(i,&cpu_set); } if ((retval = sched_setaffinity(0, sizeof(cpu_set), &cpu_set)) == 0) { printf("Set affinity for CPUs %d-%d OK\n", start_cpu, end_cpu-1); } return retval; }
long sysconfupd(int name) { long *ptr = sysconftab - MINSYSCONF; long ret = -1; switch (name) { case _SC_NPROCESSORS_ONLN: ret = ptr[_SC_NPROCESSORS_ONLN] = get_nprocs(); break; case _SC_NPROCESSORS_CONF: ret = ptr[_SC_NPROCESSORS_CONF] = get_nprocs_conf(); break; case _SC_AVPHYS_PAGES: ret = ptr[_SC_AVPHYS_PAGES] = get_avphys_pages(); break; case _SC_PHYS_PAGES: ret = ptr[_SC_PHYS_PAGES] = get_phys_pages(); break; } return ret; }
void main() { printf("get_nprocs_conf %d get_nproc %d\n", get_nprocs_conf(), get_nprocs()); printf("---- N_CONF %d ---N_ONLN %d\n", NPCONF, NPONLN ); return; }
void testValues() { f = 2; int result = get_nprocs_conf(); //@ assert result > 0; //@ assert f == 2; //@ assert vacuous: \false; }
static void dump_cpu_common() { char *path = malloc(255); int i; fprintf(env_file, "CPU_FREQ,%i", get_nprocs_conf()); for (i = 0; i < get_nprocs_conf(); i++) { char *min, *max; snprintf(path, 255, "/sys/devices/system/cpu/cpu%i/cpufreq/scaling_min_freq", i); min = _env_dump_read_file(path, 20, NULL); snprintf(path, 255, "/sys/devices/system/cpu/cpu%i/cpufreq/scaling_max_freq", i); max = _env_dump_read_file(path, 20, NULL); fprintf(env_file, ",%s,%s", min, max); free(min); free(max); } fprintf(env_file, "\n"); fprintf(env_file, "CPU_GOVERNOR,%i", get_nprocs_conf()); for (i = 0; i < get_nprocs_conf(); i++) { char *governor; snprintf(path, 255, "/sys/devices/system/cpu/cpu%i/cpufreq/scaling_governor", i); governor = _env_dump_read_file(path, 20, NULL); fprintf(env_file, ",%s", governor); free(governor); } fprintf(env_file, "\n"); free(path); }
int info_print() { char str[STR_SIZE]; unsigned int a, b, c, d, max; char brand_string[4*4*3 + 1]; /* Hostname */ gethostname(str, STR_SIZE); OM_COMMENT; printf("local hostname: %s\n", str); /* CPU info */ asm volatile ( "mov $0x80000000, %%eax\ncpuid" : "=a"(a), "=b"(b), "=c"(c), "=d"(d) ); max = a; if (max >= 0x80000002) { asm volatile ( "mov $0x80000002, %%eax\ncpuid" : "=a"(((unsigned int *)&brand_string)[0]), "=b"(((unsigned int *)&brand_string)[1]), "=c"(((unsigned int *)&brand_string)[2]), "=d"(((unsigned int *)&brand_string)[3]) ); } if (max >= 0x80000003) { asm volatile ( "mov $0x80000003, %%eax\ncpuid" : "=a"(((unsigned int *)&brand_string)[4]), "=b"(((unsigned int *)&brand_string)[5]), "=c"(((unsigned int *)&brand_string)[6]), "=d"(((unsigned int *)&brand_string)[7]) ); brand_string[4*4*2] = '\0'; } if (max >= 0x80000004) { asm volatile ( "mov $0x80000004, %%eax\ncpuid" : "=a"(((unsigned int *)&brand_string)[8]), "=b"(((unsigned int *)&brand_string)[9]), "=c"(((unsigned int *)&brand_string)[10]), "=d"(((unsigned int *)&brand_string)[11]) ); brand_string[4*4*3] = '\0'; } OM_COMMENT; printf("CPU brand string: %s\n", brand_string); /* total memory */ // ... OM_COMMENT; printf("Invariant TSC: %d\n", information.invariant_tsc); OM_COMMENT; printf("TSC per usec: %ld\n", information.tsc_per_usec); OM_COMMENT; printf("TSC read overhead: %ld\n", information.tsc_diff); if (information.nbr_cpus > -1) { OM_COMMENT; printf("Nbr. of CPUs: %d\n", information.nbr_cpus); OM_COMMENT; printf("Nbr. CPUs conf.: %d\n", get_nprocs_conf()); /* sys/sysinfo.h */ //OM_COMMENT; printf("Nbr. phys. pages: %ld\n", get_phys_pages()); //OM_COMMENT; printf("Nbr. avail. p. p.:%ld\n", get_avphys_pages()); OM_COMMENT; printf("Mem in System: %ld MiB\n", get_phys_pages() * 4 / 1024); /* sys/sysinfo.h */ OM_COMMENT; printf("Mem available: %ld MiB\n", get_avphys_pages() * 4 / 1024); /* sys/sysinfo.h */ } /* Optimizing */ #if defined (CC) && defined(OPT) OM_COMMENT; printf("Compiler: %s -O%s\n", CC, OPT); #endif return 0; }
static void dump_throttling_common() { char *package, *path = malloc(255); int i; package = _env_dump_read_file("/sys/devices/system/cpu/cpu0/thermal_throttle/package_throttle_count", 20, NULL); fprintf(env_file, "THROTTLING,%i,%s", get_nprocs_conf(), package); for (i = 0; i < get_nprocs_conf(); i++) { char *core; snprintf(path, 255, "/sys/devices/system/cpu/cpu%i/thermal_throttle/core_throttle_count", i); core = _env_dump_read_file(path, 20, NULL); fprintf(env_file, ",%s", core); free(core); } fprintf(env_file, "\n"); free(path); }
long sysGetCpuCount(void) { #if defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_CONF) return sysconf(_SC_NPROCESSORS_CONF); #elif defined(HAVE_SYSCONF) && defined(_SC_NPROC_CONF) return sysconf(_SC_NPROC_CONF); #elif defined(HAVE_GET_NPROCS_CONF) return get_nprocs_conf(); #else return sysGetCpuOnline(); #endif }
void check_procs() { int min_procs = 2; int nprocs = 0; nprocs = get_nprocs_conf(); if (nprocs < min_procs) { dprintf("[-] system has less than %d processor cores\n", min_procs); exit(EXIT_FAILURE); } dprintf("[.] system has %d processor cores\n", nprocs); }
int main( int argc, char** argv ) { (void) argc; (void) argv; thread_free = get_nprocs_conf(); printf("%d\n",thread_free ); InitFic(); starter(); moyenneCSV(); return 0; }
int getNumberOfProcessors() { #ifdef ANDROID int cpuId = 0; while (true) { FILE* fd = _getIntFd(SYS_DEVICES_SYSTEM_CPU_CPUID_CPUFREQ_CPUINFO_MAX_FREQ, cpuId); if (NULL != fd) { fclose(fd); } else { break; } cpuId++; }; return MAX(1, cpuId); #else return get_nprocs_conf(); #endif }
static void dump_shed_common() { uint64_t affinity = 0; const char *sched_str; int prio, sched, i; cpu_set_t cpu_set; /* FIXME: This does not work when having more than 64 CPUs */ sched_getaffinity(0, sizeof(cpu_set), &cpu_set); for (i = 0; i < 64; i++) { affinity |= (CPU_ISSET(i, &cpu_set) != 0) << i; } sched = sched_getscheduler(0); switch (sched) { case SCHED_OTHER: sched_str = "SCHED_OTHER"; break; case SCHED_BATCH: sched_str = "SCHED_BATCH"; break; case SCHED_IDLE: sched_str = "SCHED_IDLE"; break; case SCHED_FIFO: sched_str = "SCHED_FIFO"; break; case SCHED_RR: sched_str = "SCHED_RR"; break; case -1: sched_str = "ERROR"; break; default: sched_str = "UNKNOWN"; break; } prio = getpriority(PRIO_PROCESS, 0); fprintf(env_file, "SCHED,%s,%i,%i,%"PRIu64",%i\n", sched_str, get_nprocs_conf(), get_nprocs(), affinity, prio); }
int main(int argc, char **argv) { int nr = get_nprocs(); int c, ign, all = 0; struct option opts[5] = { {"version", 0, 0, 0}, {"help", 0, 0, 1}, {"all", 0, 0, 2}, {"ignore", 1, 0, 3}, {0, 0, 0, 0} }; while ((c = getopt_long(argc, argv, "", opts, NULL)) != -1) { switch (c) { case 0: printf("%s v0.1\n", argv[0]); return 0; case 1: printf("%s --version|--help|--all|--ignore=N\n", argv[0]); return 0; case 2: all = 1; break; case 3: ign = atoi(optarg); break; case '?': printf("wrong option, %s --help\n", argv[0]); return 1; } } if (all == 1) nr = get_nprocs_conf(); nr = nr - ign; if (nr <= 0) nr = 1; printf("%d\n", nr); return 0; }
int main(void) { int nthr = get_nprocs_conf(); int ndx; int delta = ASIZE / nthr; int ofs = 0; struct mandelthr *args; pthread_t *thrtab = calloc(nthr, sizeof(pthread_t)); pthread_t **thrptrtab = calloc(nthr, sizeof(pthread_t *)); /* Make a window! */ init_x11(ASIZE); init_colours(); g_nthr = nthr; for (ndx = 0 ; ndx < nthr ; ndx++) { args = calloc(1, sizeof(struct mandelthr)); args->yofs = ofs; args->ylim = ofs + delta; pthread_create(&thrtab[ndx], NULL, mandel_start, args); ofs += delta; } for (ndx = 0 ; ndx < nthr ; ndx++) { pthread_join(thrtab[ndx], (void **)&thrptrtab[ndx]); } do { pthread_yield(); } while (g_nthr); XPutImage(dpy, win, gc, bitmap, 0, 0, 0, 0, ASIZE, ASIZE); XFlush(dpy); // display_double(ASIZE, xmin, xmax, ymin, ymax); #ifdef WAIT_EXIT while(1) { XEvent event; KeySym key; char text[255]; XNextEvent(dpy, &event); /* Just redraw everything on expose */ if ((event.type == Expose) && !event.xexpose.count) { XPutImage(dpy, win, gc, bitmap, 0, 0, 0, 0, ASIZE, ASIZE); } /* Press 'q' to quit */ if ((event.type == KeyPress) && XLookupString(&event.xkey, text, 255, &key, 0) == 1) { if (text[0] == 'q') break; } /* Or simply close the window */ if ((event.type == ClientMessage) && ((Atom) event.xclient.data.l[0] == wmDeleteMessage)) { break; } } #endif /* Done! */ exit_x11(); return 0; }
// Determine number of locks based on number of cores. StripedLock() : StripedLock(get_nprocs_conf() * kLockPoolSizeExpansionFactor) { }
void runSuccess() { get_nprocs_conf(); }
int main(int argc, char *argv[]){ //int interval=300; //sec int interval=atoi(argv[2]); //sec float input=atof(argv[1]); int cores=(int)input+1; float cpuUsage=input/cores; pid_t *pids = (pid_t*)malloc(sizeof(pid_t)*cores); int noCpu=get_nprocs_conf(); if(cores>noCpu) { cores=noCpu; cpuUsage=1.0; } int i=0; long magicPer01 = 4233779; int ratioCpu; int sleepTime; int elapsedTime=0; clock_t start; clock_t end; double time; FILE *tax_info = fopen("tax_info.txt", "r"); FILE *tax_report = fopen("tax_report.txt", "w+"); int tax_state; int tax_fed; int tax_total; int *tax_additional = (int*)malloc(sizeof(int)*3); tax_additional[0]=2; tax_additional[1]=4; tax_additional[2]=0; for(i=0; i<cores; i++){ pids[i]=fork(); if(pids[i]==0){ while(1){ //long myId=(long)getpid(); start=clock(); fscanf(tax_info, "%d %d", &tax_state, &tax_fed); ratioCpu = (int)(cpuUsage*100); sleepTime = (100-ratioCpu)*10000; for(i=0; i<magicPer01*ratioCpu; i++){ tax_total=tax_state+tax_fed; tax_additional[2]=tax_additional[0] * tax_additional[1]; tax_total=tax_total+tax_additional[2]; } fprintf(tax_report, "%d\n", tax_total); end=clock(); time=(double)(end-start)/(CLOCKS_PER_SEC); //printf("core: %d process ID: %d usage: %.2f calc time: %.2f\n", cores, myId, cpuUsage, time); usleep(sleepTime); elapsedTime++; if(elapsedTime>=interval){ elapsedTime=0; //break; return 0; } } fclose(tax_info); fclose(tax_report); return 0; } } fclose(tax_info); fclose(tax_report); return 0; }
int main(int argc, char **argv) { struct percpu_net_cnt *percpu_netcnt; struct bpf_cgroup_storage_key key; int map_fd, percpu_map_fd; int error = EXIT_FAILURE; struct net_cnt netcnt; struct bpf_object *obj; int prog_fd, cgroup_fd; unsigned long packets; unsigned long bytes; int cpu, nproc; __u32 prog_cnt; nproc = get_nprocs_conf(); percpu_netcnt = malloc(sizeof(*percpu_netcnt) * nproc); if (!percpu_netcnt) { printf("Not enough memory for per-cpu area (%d cpus)\n", nproc); goto err; } if (bpf_prog_load(BPF_PROG, BPF_PROG_TYPE_CGROUP_SKB, &obj, &prog_fd)) { printf("Failed to load bpf program\n"); goto out; } if (setup_cgroup_environment()) { printf("Failed to load bpf program\n"); goto err; } /* Create a cgroup, get fd, and join it */ cgroup_fd = create_and_get_cgroup(TEST_CGROUP); if (!cgroup_fd) { printf("Failed to create test cgroup\n"); goto err; } if (join_cgroup(TEST_CGROUP)) { printf("Failed to join cgroup\n"); goto err; } /* Attach bpf program */ if (bpf_prog_attach(prog_fd, cgroup_fd, BPF_CGROUP_INET_EGRESS, 0)) { printf("Failed to attach bpf program"); goto err; } if (system("which ping6 &>/dev/null") == 0) assert(!system("ping6 localhost -c 10000 -f -q > /dev/null")); else assert(!system("ping -6 localhost -c 10000 -f -q > /dev/null")); if (bpf_prog_query(cgroup_fd, BPF_CGROUP_INET_EGRESS, 0, NULL, NULL, &prog_cnt)) { printf("Failed to query attached programs"); goto err; } map_fd = bpf_find_map(__func__, obj, "netcnt"); if (map_fd < 0) { printf("Failed to find bpf map with net counters"); goto err; } percpu_map_fd = bpf_find_map(__func__, obj, "percpu_netcnt"); if (percpu_map_fd < 0) { printf("Failed to find bpf map with percpu net counters"); goto err; } if (bpf_map_get_next_key(map_fd, NULL, &key)) { printf("Failed to get key in cgroup storage\n"); goto err; } if (bpf_map_lookup_elem(map_fd, &key, &netcnt)) { printf("Failed to lookup cgroup storage\n"); goto err; } if (bpf_map_lookup_elem(percpu_map_fd, &key, &percpu_netcnt[0])) { printf("Failed to lookup percpu cgroup storage\n"); goto err; } /* Some packets can be still in per-cpu cache, but not more than * MAX_PERCPU_PACKETS. */ packets = netcnt.packets; bytes = netcnt.bytes; for (cpu = 0; cpu < nproc; cpu++) { if (percpu_netcnt[cpu].packets > MAX_PERCPU_PACKETS) { printf("Unexpected percpu value: %llu\n", percpu_netcnt[cpu].packets); goto err; } packets += percpu_netcnt[cpu].packets; bytes += percpu_netcnt[cpu].bytes; } /* No packets should be lost */ if (packets != 10000) { printf("Unexpected packet count: %lu\n", packets); goto err; } /* Let's check that bytes counter matches the number of packets * multiplied by the size of ipv6 ICMP packet. */ if (bytes != packets * 104) { printf("Unexpected bytes count: %lu\n", bytes); goto err; } error = 0; printf("test_netcnt:PASS\n"); err: cleanup_cgroup_environment(); free(percpu_netcnt); out: return error; }
long sysconf(int name) { switch (name) { case _SC_ARG_MAX: return _POSIX_ARG_MAX; case _SC_CHILD_MAX: return CHILD_MAX; case _SC_CLK_TCK: return SYSTEM_CLK_TCK; case _SC_LINE_MAX: return _POSIX2_LINE_MAX; case _SC_NGROUPS_MAX: return NGROUPS_MAX; case _SC_OPEN_MAX: return OPEN_MAX; case _SC_PASS_MAX: return PASS_MAX; case _SC_2_C_BIND: return SYSTEM_2_C_BIND; case _SC_2_C_DEV: return SYSTEM_2_C_DEV; case _SC_2_C_VERSION: return SYSTEM_2_C_VER; //case _SC_2_CHAR_TERM: return ; case _SC_2_FORT_DEV: return SYSTEM_2_FORT_DEV; case _SC_2_FORT_RUN: return SYSTEM_2_FORT_RUN; case _SC_2_LOCALEDEF: return SYSTEM_2_LOCALEDEF; case _SC_2_SW_DEV: return SYSTEM_2_SW_DEV; case _SC_2_UPE: return SYSTEM_2_UPE; case _SC_2_VERSION: return SYSTEM_2_VERSION; case _SC_JOB_CONTROL: return _POSIX_JOB_CONTROL; case _SC_SAVED_IDS: return _POSIX_SAVED_IDS; case _SC_VERSION: return _POSIX_VERSION; case _SC_RE_DUP_MAX: return _POSIX_RE_DUP_MAX; case _SC_STREAM_MAX: return FOPEN_MAX; case _SC_TZNAME_MAX: return _POSIX_TZNAME_MAX; case _SC_XOPEN_CRYPT: return _XOPEN_CRYPT; case _SC_XOPEN_ENH_I18N: return _XOPEN_ENH_I18N; //case _SC_XOPEN_SHM: return _XOPEN_SHM; case _SC_XOPEN_VERSION: return _XOPEN_VERSION; case _SC_XOPEN_XCU_VERSION: return _XOPEN_XCU_VERSION; case _SC_XOPEN_REALTIME: return _XOPEN_REALTIME; case _SC_XOPEN_REALTIME_THREADS: return _XOPEN_REALTIME_THREADS; case _SC_XOPEN_LEGACY: return _XOPEN_LEGACY; case _SC_ATEXIT_MAX: return SYSTEM_ATEXIT_MAX; case _SC_IOV_MAX: return SYSTEM_IOV_MAX; case _SC_PAGESIZE: case _SC_PAGE_SIZE: return PAGE_SIZE; case _SC_XOPEN_UNIX: return _XOPEN_UNIX; // XXX: TODO: XBS5 nonsense //case _SC_AIO_LISTIO_MAX: return AIO_LISTIO_MAX; //case _SC_AIO_MAX: return AIO_MAX; //case _SC_AIO_PRIO_DELTA_MAX: return AIO_PRIO_DELTA_MAX; case _SC_DELAYTIMER_MAX: return SYSTEM_DELAYTIMER_MAX; case _SC_MQ_OPEN_MAX: return SYSTEM_MQ_OPEN_MAX; case _SC_MQ_PRIO_MAX: return SYSTEM_MQ_PRIO_MAX; case _SC_RTSIG_MAX: return RTSIG_MAX; case _SC_SEM_NSEMS_MAX: return SYSTEM_SEM_NSEMS_MAX; case _SC_SEM_VALUE_MAX: return SEM_VALUE_MAX; case _SC_SIGQUEUE_MAX: return SYSTEM_SIGQUEUE_MAX; case _SC_TIMER_MAX: return SYSTEM_TIMER_MAX; //case _SC_ASYNCHRONOUS_IO: return _POSIX_ASYNCHRONOUS_IO; case _SC_FSYNC: return _POSIX_FSYNC; case _SC_MAPPED_FILES: return _POSIX_MAPPED_FILES; //case _SC_MEMLOCK: return _POSIX_MEMLOCK; //case _SC_MEMLOCK_RANGE: return _POSIX_MEMLOCK_RANGE; //case _SC_MEMORY_PROTECTION: return _POSIX_MEMORY_PROTECTION; //case _SC_MESSAGE_PASSING: return _POSIX_MESSAGE_PASSING; //case _SC_PRIORITIZED_IO: return _POSIX_PRIORITIZED_IO; case _SC_PRIORITY_SCHEDULING: return _POSIX_PRIORITY_SCHEDULING; case _SC_REALTIME_SIGNALS: return _POSIX_REALTIME_SIGNALS; case _SC_SEMAPHORES: return _POSIX_SEMAPHORES; //case _SC_SHARED_MEMORY_OBJECTS: return _POSIX_SHARED_MEMORY_OBJECTS; case _SC_SYNCHRONIZED_IO: return _POSIX_SYNCHRONIZED_IO; case _SC_TIMERS: return _POSIX_TIMERS; case _SC_GETGR_R_SIZE_MAX: return 1024; case _SC_GETPW_R_SIZE_MAX: return 1024; case _SC_LOGIN_NAME_MAX: return SYSTEM_LOGIN_NAME_MAX; case _SC_THREAD_DESTRUCTOR_ITERATIONS: return _POSIX_THREAD_DESTRUCTOR_ITERATIONS; case _SC_THREAD_KEYS_MAX: return (BIONIC_TLS_SLOTS - TLS_SLOT_FIRST_USER_SLOT - BIONIC_TLS_RESERVED_SLOTS); case _SC_THREAD_STACK_MIN: return PTHREAD_STACK_MIN; case _SC_THREAD_THREADS_MAX: return SYSTEM_THREAD_THREADS_MAX; case _SC_TTY_NAME_MAX: return SYSTEM_TTY_NAME_MAX; case _SC_THREADS: return _POSIX_THREADS; case _SC_THREAD_ATTR_STACKADDR: return -1; // Removed in POSIX 2008 case _SC_THREAD_ATTR_STACKSIZE: return -1; // Removed in POSIX 2008 //case _SC_THREAD_PRIORITY_SCHEDULING: return _POSIX_THREAD_PRIORITY_SCHEDULING; case _SC_THREAD_PRIO_INHERIT: return _POSIX_THREAD_PRIO_INHERIT; case _SC_THREAD_PRIO_PROTECT: return _POSIX_THREAD_PRIO_PROTECT; //case _SC_THREAD_SAFE_FUNCTIONS: return _POSIX_THREAD_SAFE_FUNCTIONS case _SC_MONOTONIC_CLOCK: return __sysconf_monotonic_clock(); case _SC_NPROCESSORS_CONF: return get_nprocs_conf(); case _SC_NPROCESSORS_ONLN: return get_nprocs(); case _SC_PHYS_PAGES: return get_phys_pages(); case _SC_AVPHYS_PAGES: return get_avphys_pages(); default: // Posix says EINVAL is the only error that shall be returned, // but glibc uses ENOSYS. errno = ENOSYS; return -1; } }
long sysconf(int name) { switch (name) { case _SC_ARG_MAX: return ARG_MAX; case _SC_BC_BASE_MAX: return _POSIX2_BC_BASE_MAX; // Minimum requirement. case _SC_BC_DIM_MAX: return _POSIX2_BC_DIM_MAX; // Minimum requirement. case _SC_BC_SCALE_MAX: return _POSIX2_BC_SCALE_MAX; // Minimum requirement. case _SC_BC_STRING_MAX: return _POSIX2_BC_STRING_MAX; // Minimum requirement. case _SC_CHILD_MAX: return __sysconf_rlimit(RLIMIT_NPROC); case _SC_CLK_TCK: return static_cast<long>(getauxval(AT_CLKTCK)); case _SC_COLL_WEIGHTS_MAX: return _POSIX2_COLL_WEIGHTS_MAX; // Minimum requirement. case _SC_EXPR_NEST_MAX: return _POSIX2_EXPR_NEST_MAX; // Minimum requirement. case _SC_LINE_MAX: return _POSIX2_LINE_MAX; // Minimum requirement. case _SC_NGROUPS_MAX: return NGROUPS_MAX; case _SC_OPEN_MAX: return __sysconf_rlimit(RLIMIT_NOFILE); case _SC_PASS_MAX: return PASS_MAX; case _SC_2_C_BIND: return _POSIX2_C_BIND; case _SC_2_C_DEV: return _POSIX2_C_DEV; case _SC_2_CHAR_TERM: return _POSIX2_CHAR_TERM; case _SC_2_FORT_DEV: return -1; case _SC_2_FORT_RUN: return -1; case _SC_2_LOCALEDEF: return _POSIX2_LOCALEDEF; case _SC_2_SW_DEV: return _POSIX2_SW_DEV; case _SC_2_UPE: return _POSIX2_UPE; case _SC_2_VERSION: return _POSIX2_VERSION; case _SC_JOB_CONTROL: return _POSIX_JOB_CONTROL; case _SC_SAVED_IDS: return _POSIX_SAVED_IDS; case _SC_VERSION: return _POSIX_VERSION; case _SC_RE_DUP_MAX: return _POSIX_RE_DUP_MAX; // Minimum requirement. case _SC_STREAM_MAX: return FOPEN_MAX; case _SC_TZNAME_MAX: return _POSIX_TZNAME_MAX; // Minimum requirement. case _SC_XOPEN_CRYPT: return _XOPEN_CRYPT; case _SC_XOPEN_ENH_I18N: return _XOPEN_ENH_I18N; case _SC_XOPEN_SHM: return _XOPEN_SHM; case _SC_XOPEN_VERSION: return _XOPEN_VERSION; case _SC_XOPEN_REALTIME: return _XOPEN_REALTIME; case _SC_XOPEN_REALTIME_THREADS: return _XOPEN_REALTIME_THREADS; case _SC_XOPEN_LEGACY: return _XOPEN_LEGACY; case _SC_ATEXIT_MAX: return LONG_MAX; // Unlimited. case _SC_IOV_MAX: return UIO_MAXIOV; // _SC_PAGESIZE and _SC_PAGE_SIZE are distinct, but return the same value. case _SC_PAGESIZE: case _SC_PAGE_SIZE: return static_cast<long>(getauxval(AT_PAGESZ)); case _SC_XOPEN_UNIX: return _XOPEN_UNIX; case _SC_AIO_LISTIO_MAX: return _POSIX_AIO_LISTIO_MAX; // Minimum requirement. case _SC_AIO_MAX: return _POSIX_AIO_MAX; // Minimum requirement. case _SC_AIO_PRIO_DELTA_MAX:return 0; // Minimum requirement. case _SC_DELAYTIMER_MAX: return INT_MAX; case _SC_MQ_OPEN_MAX: return _POSIX_MQ_OPEN_MAX; // Minimum requirement. case _SC_MQ_PRIO_MAX: return _POSIX_MQ_PRIO_MAX; // Minimum requirement. case _SC_RTSIG_MAX: return RTSIG_MAX; case _SC_SEM_NSEMS_MAX: return _POSIX_SEM_NSEMS_MAX; // Minimum requirement. case _SC_SEM_VALUE_MAX: return SEM_VALUE_MAX; case _SC_SIGQUEUE_MAX: return _POSIX_SIGQUEUE_MAX; // Minimum requirement. case _SC_TIMER_MAX: return _POSIX_TIMER_MAX; // Minimum requirement. case _SC_ASYNCHRONOUS_IO: return _POSIX_ASYNCHRONOUS_IO; case _SC_FSYNC: return _POSIX_FSYNC; case _SC_MAPPED_FILES: return _POSIX_MAPPED_FILES; case _SC_MEMLOCK: return _POSIX_MEMLOCK; case _SC_MEMLOCK_RANGE: return _POSIX_MEMLOCK_RANGE; case _SC_MEMORY_PROTECTION: return _POSIX_MEMORY_PROTECTION; case _SC_MESSAGE_PASSING: return _POSIX_MESSAGE_PASSING; case _SC_PRIORITIZED_IO: return _POSIX_PRIORITIZED_IO; case _SC_PRIORITY_SCHEDULING: return _POSIX_PRIORITY_SCHEDULING; case _SC_REALTIME_SIGNALS: return _POSIX_REALTIME_SIGNALS; case _SC_SEMAPHORES: return _POSIX_SEMAPHORES; case _SC_SHARED_MEMORY_OBJECTS: return _POSIX_SHARED_MEMORY_OBJECTS; case _SC_SYNCHRONIZED_IO: return _POSIX_SYNCHRONIZED_IO; case _SC_TIMERS: return _POSIX_TIMERS; case _SC_GETGR_R_SIZE_MAX: return 1024; case _SC_GETPW_R_SIZE_MAX: return 1024; case _SC_LOGIN_NAME_MAX: return 256; // Seems default on linux. case _SC_THREAD_DESTRUCTOR_ITERATIONS: return PTHREAD_DESTRUCTOR_ITERATIONS; case _SC_THREAD_KEYS_MAX: return PTHREAD_KEYS_MAX; case _SC_THREAD_STACK_MIN: return PTHREAD_STACK_MIN; case _SC_THREAD_THREADS_MAX: return PTHREAD_THREADS_MAX; case _SC_TTY_NAME_MAX: return 32; // Seems default on linux. case _SC_THREADS: return _POSIX_THREADS; case _SC_THREAD_ATTR_STACKADDR: return _POSIX_THREAD_ATTR_STACKADDR; case _SC_THREAD_ATTR_STACKSIZE: return _POSIX_THREAD_ATTR_STACKSIZE; case _SC_THREAD_PRIORITY_SCHEDULING: return _POSIX_THREAD_PRIORITY_SCHEDULING; case _SC_THREAD_PRIO_INHERIT: return _POSIX_THREAD_PRIO_INHERIT; case _SC_THREAD_PRIO_PROTECT: return _POSIX_THREAD_PRIO_PROTECT; case _SC_THREAD_SAFE_FUNCTIONS: return _POSIX_THREAD_SAFE_FUNCTIONS; case _SC_NPROCESSORS_CONF: return get_nprocs_conf(); case _SC_NPROCESSORS_ONLN: return get_nprocs(); case _SC_PHYS_PAGES: return get_phys_pages(); case _SC_AVPHYS_PAGES: return get_avphys_pages(); case _SC_MONOTONIC_CLOCK: return __sysconf_monotonic_clock(); case _SC_2_PBS: return -1; // Obsolescent in POSIX.1-2008. case _SC_2_PBS_ACCOUNTING: return -1; // Obsolescent in POSIX.1-2008. case _SC_2_PBS_CHECKPOINT: return -1; // Obsolescent in POSIX.1-2008. case _SC_2_PBS_LOCATE: return -1; // Obsolescent in POSIX.1-2008. case _SC_2_PBS_MESSAGE: return -1; // Obsolescent in POSIX.1-2008. case _SC_2_PBS_TRACK: return -1; // Obsolescent in POSIX.1-2008. case _SC_ADVISORY_INFO: return _POSIX_ADVISORY_INFO; case _SC_BARRIERS: return _POSIX_BARRIERS; case _SC_CLOCK_SELECTION: return _POSIX_CLOCK_SELECTION; case _SC_CPUTIME: return __sysconf_has_clock(CLOCK_PROCESS_CPUTIME_ID) ?_POSIX_VERSION : -1; case _SC_HOST_NAME_MAX: return _POSIX_HOST_NAME_MAX; // Minimum requirement. case _SC_IPV6: return _POSIX_IPV6; case _SC_RAW_SOCKETS: return _POSIX_RAW_SOCKETS; case _SC_READER_WRITER_LOCKS: return _POSIX_READER_WRITER_LOCKS; case _SC_REGEXP: return _POSIX_REGEXP; case _SC_SHELL: return _POSIX_SHELL; case _SC_SPAWN: return _POSIX_SPAWN; case _SC_SPIN_LOCKS: return _POSIX_SPIN_LOCKS; case _SC_SPORADIC_SERVER: return _POSIX_SPORADIC_SERVER; case _SC_SS_REPL_MAX: return -1; case _SC_SYMLOOP_MAX: return _POSIX_SYMLOOP_MAX; // Minimum requirement. case _SC_THREAD_CPUTIME: return __sysconf_has_clock(CLOCK_THREAD_CPUTIME_ID) ? _POSIX_VERSION : -1; case _SC_THREAD_PROCESS_SHARED: return _POSIX_THREAD_PROCESS_SHARED; case _SC_THREAD_ROBUST_PRIO_INHERIT: return _POSIX_THREAD_ROBUST_PRIO_INHERIT; case _SC_THREAD_ROBUST_PRIO_PROTECT: return _POSIX_THREAD_ROBUST_PRIO_PROTECT; case _SC_THREAD_SPORADIC_SERVER: return _POSIX_THREAD_SPORADIC_SERVER; case _SC_TIMEOUTS: return _POSIX_TIMEOUTS; case _SC_TRACE: return -1; // Obsolescent in POSIX.1-2008. case _SC_TRACE_EVENT_FILTER: return -1; // Obsolescent in POSIX.1-2008. case _SC_TRACE_EVENT_NAME_MAX: return -1; case _SC_TRACE_INHERIT: return -1; // Obsolescent in POSIX.1-2008. case _SC_TRACE_LOG: return -1; // Obsolescent in POSIX.1-2008. case _SC_TRACE_NAME_MAX: return -1; case _SC_TRACE_SYS_MAX: return -1; case _SC_TRACE_USER_EVENT_MAX: return -1; case _SC_TYPED_MEMORY_OBJECTS: return _POSIX_TYPED_MEMORY_OBJECTS; case _SC_V7_ILP32_OFF32: return _POSIX_V7_ILP32_OFF32; case _SC_V7_ILP32_OFFBIG: return _POSIX_V7_ILP32_OFFBIG; case _SC_V7_LP64_OFF64: return _POSIX_V7_LP64_OFF64; case _SC_V7_LPBIG_OFFBIG: return _POSIX_V7_LPBIG_OFFBIG; case _SC_XOPEN_STREAMS: return -1; // Obsolescent in POSIX.1-2008. case _SC_XOPEN_UUCP: return -1; // We do not have actual implementations for cache queries. // It's valid to return 0 as the result is unknown. case _SC_LEVEL1_ICACHE_SIZE: return 0; case _SC_LEVEL1_ICACHE_ASSOC: return 0; case _SC_LEVEL1_ICACHE_LINESIZE: return 0; case _SC_LEVEL1_DCACHE_SIZE: return 0; case _SC_LEVEL1_DCACHE_ASSOC: return 0; case _SC_LEVEL1_DCACHE_LINESIZE: return 0; case _SC_LEVEL2_CACHE_SIZE: return 0; case _SC_LEVEL2_CACHE_ASSOC: return 0; case _SC_LEVEL2_CACHE_LINESIZE: return 0; case _SC_LEVEL3_CACHE_SIZE: return 0; case _SC_LEVEL3_CACHE_ASSOC: return 0; case _SC_LEVEL3_CACHE_LINESIZE: return 0; case _SC_LEVEL4_CACHE_SIZE: return 0; case _SC_LEVEL4_CACHE_ASSOC: return 0; case _SC_LEVEL4_CACHE_LINESIZE: return 0; default: // Posix says EINVAL is the only error that shall be returned, // but glibc uses ENOSYS. errno = ENOSYS; return -1; } }
int getDetails() { int max; int min = 1000000; int i; unsigned int MM_EXTENSION = 0x00800000; unsigned int SSE_EXTENSION = 0x02000000; unsigned int SSE2_EXTENSION = 0x04000000; unsigned int SSE3_EXTENSION = 0x00000001; unsigned int _3DNOW_FEATURE = 0x80000000; printf(" ####################################################\n getDetails and MHz\n\n"); struct sysinfo sysdata; struct utsname udetails; _cpuida(); sprintf(configdata[1], " Assembler CPUID and RDTSC "); sprintf(configdata[2], " CPU %s, Features Code %8.8X, Model Code %8.8X", idString1, edxCode1, eaxCode1); sprintf(configdata[3], " %s", idString2); max = 0; for (i=0; i<10; i++) { startCount = 0; endCount = 0; start_time(); _calculateMHz(); end_time(); megaHz = (int)((double)cycleCount / 1000000.0 / secs + 0.5); if (megaHz > max) max = megaHz; if (megaHz < min) min = megaHz; } sprintf(configdata[4], " Measured - Minimum %d MHz, Maximum %d MHz", min, max); megaHz = max; sprintf(configdata[5], " Linux Functions"); CPUconf = get_nprocs_conf(); CPUavail = get_nprocs(); sprintf(configdata[6], " get_nprocs() - CPUs %d, Configured CPUs %d", CPUconf, CPUavail); pages = get_phys_pages(); pagesize = getpagesize(); ramGB = ((double)pages * (double)pagesize / 1024 / 1024 / 1024); sprintf(configdata[7], " get_phys_pages() and size - RAM Size %5.2f GB, Page Size %d Bytes", ramGB, pagesize); if (uname(&udetails) > -1) { sprintf(configdata[8], " uname() - %s, %s, %s", udetails.sysname, udetails.nodename, udetails.release); sprintf(configdata[9], " %s, %s", udetails.version, udetails.machine); } else { sprintf(configdata[8], " uname() - No details"); sprintf(configdata[9], " "); } if (edxCode1 & MM_EXTENSION) { hasMMX = 1; } if (edxCode1 & SSE_EXTENSION) { hasSSE = 1; } if (edxCode1 & SSE2_EXTENSION) { hasSSE2 = 1; } if (ecxCode1 & SSE3_EXTENSION) { hasSSE3 = 1; } if (intel1amd2 == 0x68747541) { if (ext81edx & _3DNOW_FEATURE) { has3DNow = 1; } } return 0; }