Esempio n. 1
0
unsigned int get_timer_clock(void)
{
	unsigned int timer_clk = 0;
	if (get_cpuinfo()->get_clock)
		get_cpuinfo()->get_clock(NULL, &timer_clk);
	return timer_clk;
}
Esempio n. 2
0
static void
_print_config(void)
{
	int days, hours, mins, secs;
	char name[128];

	gethostname_short(name, sizeof(name));
	printf("NodeName=%s ", name);

	get_cpuinfo(&conf->actual_cpus,
		    &conf->actual_boards,
	            &conf->actual_sockets,
	            &conf->actual_cores,
	            &conf->actual_threads,
	            &conf->block_map_size,
	            &conf->block_map, &conf->block_map_inv);
	printf("CPUs=%u Boards=%u SocketsPerBoard=%u CoresPerSocket=%u "
	       "ThreadsPerCore=%u ",
	       conf->actual_cpus, conf->actual_boards, conf->actual_sockets,
	       conf->actual_cores, conf->actual_threads);

	get_memory(&conf->real_memory_size);
	get_tmp_disk(&conf->tmp_disk_space, "/tmp");
	printf("RealMemory=%u TmpDisk=%u\n",
	       conf->real_memory_size, conf->tmp_disk_space);

	get_up_time(&conf->up_time);
	secs  =  conf->up_time % 60;
	mins  = (conf->up_time / 60) % 60;
	hours = (conf->up_time / 3600) % 24;
	days  = (conf->up_time / 86400);
	printf("UpTime=%u-%2.2u:%2.2u:%2.2u\n", days, hours, mins, secs);
}
Esempio n. 3
0
int get_cpudevs(void)
{
	static unsigned int devs;
	if (!devs)
		devs = get_cpuinfo()->devs;
	return (int) devs;
}
Esempio n. 4
0
File: cpu.c Progetto: 1c0n/xbmc
int ff_get_cpu_flags_arm(void)
{
    int flags = CORE_CPU_FLAGS;
    uint32_t hwcap;

    if (get_hwcap(&hwcap) < 0)
        if (get_cpuinfo(&hwcap) < 0)
            return flags;

#define check_cap(cap, flag) do {               \
        if (hwcap & HWCAP_ ## cap)              \
            flags |= AV_CPU_FLAG_ ## flag;      \
    } while (0)

    /* No flags explicitly indicate v6 or v6T2 so check others which
       imply support. */
    check_cap(EDSP,    ARMV5TE);
    check_cap(TLS,     ARMV6);
    check_cap(THUMBEE, ARMV6T2);
    check_cap(VFP,     VFP);
    check_cap(VFPv3,   VFPV3);
    check_cap(NEON,    NEON);

    /* The v6 checks above are not reliable so let higher flags
       trickle down. */
    if (flags & (AV_CPU_FLAG_VFPV3 | AV_CPU_FLAG_NEON))
        flags |= AV_CPU_FLAG_ARMV6T2;
    if (flags & AV_CPU_FLAG_ARMV6T2)
        flags |= AV_CPU_FLAG_ARMV6;

    return flags;
}
Esempio n. 5
0
void pa_cpu_init_arm (void) {
#if defined (__arm__)
#if defined (__linux__)
    char *cpuinfo, *line;
    int arch;
    pa_cpu_arm_flag_t flags = 0;

    /* We need to read the CPU flags from /proc/cpuinfo because there is no user
     * space support to get the CPU features. This only works on linux AFAIK. */
    if (!(cpuinfo = get_cpuinfo ())) {
        pa_log ("Can't read cpuinfo");
        return;
    }

    /* get the CPU architecture */
    if ((line = get_cpuinfo_line (cpuinfo, "CPU architecture"))) {
        arch = strtoul (line, NULL, 0);
        if (arch >= 6)
            flags |= PA_CPU_ARM_V6;
        if (arch >= 7)
            flags |= PA_CPU_ARM_V7;

        pa_xfree(line);
    }
    /* get the CPU features */
    if ((line = get_cpuinfo_line (cpuinfo, "Features"))) {
        const char *state = NULL;
        char *current;

        while ((current = pa_split_spaces (line, &state))) {
            if (!strcmp (current, "vfp"))
                flags |= PA_CPU_ARM_VFP;
            else if (!strcmp (current, "edsp"))
                flags |= PA_CPU_ARM_EDSP;
            else if (!strcmp (current, "neon"))
                flags |= PA_CPU_ARM_NEON;
            else if (!strcmp (current, "vfpv3"))
                flags |= PA_CPU_ARM_VFPV3;

            pa_xfree(current);
        }
    }
    pa_xfree(cpuinfo);

    pa_log_info ("CPU flags: %s%s%s%s%s%s",
          (flags & PA_CPU_ARM_V6) ? "V6 " : "",
          (flags & PA_CPU_ARM_V7) ? "V7 " : "",
          (flags & PA_CPU_ARM_VFP) ? "VFP " : "",
          (flags & PA_CPU_ARM_EDSP) ? "EDSP " : "",
          (flags & PA_CPU_ARM_NEON) ? "NEON " : "",
          (flags & PA_CPU_ARM_VFPV3) ? "VFPV3 " : "");
#else /* defined (__linux__) */
    pa_log ("ARM cpu features not yet supported on this OS");
#endif /* defined (__linux__) */

    if (flags & PA_CPU_ARM_V6)
        pa_volume_func_init_arm (flags);
#endif /* defined (__arm__) */
}
Esempio n. 6
0
/* % gcc -DDEBUG_MODULE get_mach_stat.c -I../../.. -g -DUSE_CPU_SPEED	*/
int
main(int argc, char * argv[])
{
	int error_code;
	uint16_t sockets, cores, threads;
	uint16_t block_map_size;
	uint16_t *block_map, *block_map_inv;
	struct config_record this_node;
	char node_name[MAX_SLURM_NAME];
	float speed;
	uint16_t testnumproc = 0;
	uint32_t up_time = 0;
	int days, hours, mins, secs;
	char* _cpuinfo_path = "/proc/cpuinfo";

	if (argc > 1) {
	    	_cpuinfo_path = argv[1];
		testnumproc = 1024;	/* since may not match test host */
	}
	debug3("%s:", _cpuinfo_path);

	error_code = get_mach_name(node_name);
	if (error_code != 0)
		exit(1);    /* The show is all over without a node name */

	error_code += get_procs(&this_node.cpus);
	error_code += get_cpuinfo(MAX(this_node.cpus, testnumproc),
				  &this_node.sockets,
				  &this_node.cores,
				  &this_node.threads,
				  &block_map_size,
				  &block_map, &block_map_inv);
	xfree(block_map);	/* not used here */
	xfree(block_map_inv);	/* not used here */
	error_code += get_memory(&this_node.real_memory);
	error_code += get_tmp_disk(&this_node.tmp_disk, "/tmp");
	error_code += get_up_time(&up_time);
#ifdef USE_CPU_SPEED
	error_code += get_speed(&speed);
#endif

	debug3("");
	debug3("NodeName=%s CPUs=%u Sockets=%u Cores=%u Threads=%u",
		node_name, this_node.cpus,
		this_node.sockets, this_node.cores, this_node.threads);
	debug3("\tRealMemory=%u TmpDisk=%u Speed=%f",
		this_node.real_memory, this_node.tmp_disk, speed);
	secs  = up_time % 60;
	mins  = (up_time / 60) % 60;
	hours = (up_time / 3600) % 24;
	days  = (up_time / 86400);
	debug3("\tUpTime=%u=%u-%2.2u:%2.2u:%2.2u",
	       up_time, days, hours, mins, secs);
	if (error_code != 0)
		debug3("get_mach_stat error_code=%d encountered", error_code);
	exit (error_code);
}
Esempio n. 7
0
void refresh_perf_data_block(PERF_DATA_BLOCK *data, RuntimeSettings rt)
{
    data->PerfTime100nSec = 0;
    get_meminfo(data);
    get_cpuinfo(data);
    get_processinfo(data);
    get_diskinfo(data);
    return;
}
Esempio n. 8
0
const int get_cpu_version(char **version)
{
	static char *cpu_ver_str;
	static int cpu_ver;

	if (cpu_ver_str)
		goto exit;

	if (get_cpuinfo()->get_cpu_version)
		cpu_ver = get_cpuinfo()->get_cpu_version(&cpu_ver_str);
	else
		cpu_ver_str = "";

exit:
	if (version)
		(*version) = cpu_ver_str;

	return cpu_ver;
}
Esempio n. 9
0
long long get_chipid(void)
{
	static long long chipid;

	if (!chipid) {
		struct cpu_info_t *info = get_cpuinfo();
		chipid = (info->chipid & info->chipid_mask);
	}

	return chipid;
}
Esempio n. 10
0
int get_bootmedia(char **media, void *arg)
{
	static char *media_name;
	static unsigned int media_type;

	if (!media_name)
		media_type = get_cpuinfo()->boot_media(&media_name);
	if (media)
		(*media) = media_name;

	return media_type;
}
Esempio n. 11
0
numa_node::numa_node(

    const char *node_path,
    int         index) : my_index(index)

{
    char path[MAXLINE];

    snprintf(path, sizeof(path), "%s/cpulist", node_path);
    get_cpuinfo(path);

    snprintf(path, sizeof(path), "%s/meminfo", node_path);
    get_meminfo(path);
}
Esempio n. 12
0
int
xcpuinfo_init(void)
{
	if ( initialized )
		return XCPUINFO_SUCCESS;

	if ( get_cpuinfo(&procs,&boards,&sockets,&cores,&threads,
			 &block_map_size,&block_map,&block_map_inv) )
		return XCPUINFO_ERROR;

	initialized = true ;

	return XCPUINFO_SUCCESS;
}
Esempio n. 13
0
/* function: getting some systems informations
 * return: nothing, yust fill the struct statistics
 */
int get_sysinfos(void)
{
    // getting the hostname
    statistics.hostname=Strdup(read_hostname());
    // the revision of the image
    statistics.rev=Strdup(read_hardware(1));
    // the vendor + model
    statistics.vendor=Strdup(read_hardware(2));
    // the uptime
    statistics.uptime=Strdup(get_uptime());
    // the kernel version
    statistics.kernel=Strdup(kernelversion());
    // the CPU version
    statistics.cpu=Strdup(get_cpuinfo());
    return 0;
}
Esempio n. 14
0
static int
do_test (int argc, char **argv)
{
  int fails;

  get_cpuinfo ();
  fails = check_proc ("avx", HAS_AVX, "HAS_AVX");
  fails += check_proc ("fma4", HAS_FMA4, "HAS_FMA4");
  fails += check_proc ("sse4_2", HAS_SSE4_2, "HAS_SSE4_2");
  fails += check_proc ("sse4_1", HAS_SSE4_1, "HAS_SSE4_1");
  fails += check_proc ("ssse3", HAS_SSSE3, "HAS_SSSE3");
  fails += check_proc ("popcnt", HAS_POPCOUNT, "HAS_POPCOUNT");

  printf ("%d differences between /proc/cpuinfo and glibc code.\n", fails);

  return (fails != 0);
}
Esempio n. 15
0
File: cpu.c Progetto: 0day-ci/FFmpeg
int ff_get_cpu_flags_arm(void)
{
    int flags = CORE_CPU_FLAGS;
    uint32_t hwcap;

    if (get_hwcap(&hwcap) < 0)
        if (get_cpuinfo(&hwcap) < 0)
            return flags;

#define check_cap(cap, flag) do {               \
        if (hwcap & HWCAP_ ## cap)              \
            flags |= AV_CPU_FLAG_ ## flag;      \
    } while (0)

    /* No flags explicitly indicate v6 or v6T2 so check others which
       imply support. */
    check_cap(EDSP,    ARMV5TE);
    check_cap(TLS,     ARMV6);
    check_cap(THUMBEE, ARMV6T2);
    check_cap(VFP,     VFP);
    check_cap(VFPv3,   VFPV3);
    check_cap(NEON,    NEON);

    /* The v6 checks above are not reliable so let higher flags
       trickle down. */
    if (flags & (AV_CPU_FLAG_VFPV3 | AV_CPU_FLAG_NEON))
        flags |= AV_CPU_FLAG_ARMV6T2;
    else if (flags & (AV_CPU_FLAG_ARMV6T2 | AV_CPU_FLAG_ARMV6))
    /* Some functions use the 'setend' instruction which is deprecated on ARMv8
     * and serializing on some ARMv7 cores. This ensures such functions
     * are only enabled on ARMv6. */
        flags |= AV_CPU_FLAG_SETEND;

    if (flags & AV_CPU_FLAG_ARMV6T2)
        flags |= AV_CPU_FLAG_ARMV6;

    /* set the virtual VFPv2 vector mode flag */
    if ((flags & AV_CPU_FLAG_VFP) && !(flags & (AV_CPU_FLAG_VFPV3 | AV_CPU_FLAG_NEON)))
        flags |= AV_CPU_FLAG_VFP_VM;

    return flags;
}
Esempio n. 16
0
static int
do_test (int argc, char **argv)
{
  int fails;

  get_cpuinfo ();
  fails = check_proc ("avx", HAS_ARCH_FEATURE (AVX_Usable),
		      "HAS_ARCH_FEATURE (AVX_Usable)");
  fails += check_proc ("fma4", HAS_ARCH_FEATURE (FMA4_Usable),
		       "HAS_ARCH_FEATURE (FMA4_Usable)");
  fails += check_proc ("sse4_2", HAS_CPU_FEATURE (SSE4_2),
		       "HAS_CPU_FEATURE (SSE4_2)");
  fails += check_proc ("sse4_1", HAS_CPU_FEATURE (SSE4_1)
		       , "HAS_CPU_FEATURE (SSE4_1)");
  fails += check_proc ("ssse3", HAS_CPU_FEATURE (SSSE3),
		       "HAS_CPU_FEATURE (SSSE3)");
  fails += check_proc ("popcnt", HAS_CPU_FEATURE (POPCOUNT),
		       "HAS_CPU_FEATURE (POPCOUNT)");

  printf ("%d differences between /proc/cpuinfo and glibc code.\n", fails);

  return (fails != 0);
}
Esempio n. 17
0
int get_hardware_list(char *buffer)
{
	extern int get_cpuinfo(char *buffer);
	int len = 0;
	char model[80];
	u_long mem;
	int i;

	if (mach_get_model)
		mach_get_model(model);
	else
		strcpy(model, "Unknown PowerPC");

	len += sprintf(buffer+len, "Model:\t\t%s\n", model);
	len += get_cpuinfo(buffer+len);
	for (mem = 0, i = 0; i < m68k_realnum_memory; i++)
		mem += m68k_memory[i].size;
	len += sprintf(buffer+len, "System Memory:\t%ldK\n", mem>>10);

	if (mach_get_hardware_list)
		len += mach_get_hardware_list(buffer+len);

	return(len);
}
Esempio n. 18
0
int main(int argc, char **argv) {

	int i;
	char *logfile_name=NULL;
	unsigned int seed=0;
	int sample_rate,paranoid,kernel_watchdog;
	FILE *fff;
	struct utsname uname_info;
	char cpuinfo[BUFSIZ];
	int seed_specified=0;
	int c,j,missing=0;
	time_t timer;
	char buffer[26];
	struct tm* tm_info;
	struct timeval current_time;
	long long interval_start=0;
	double rate;

	/*********************************/
	/* Parse command line parameters */
	/*********************************/

	while ((c=getopt(argc, argv,"hvl:r:s:t:"))!=-1) {
		switch(c) {
			case 'h':	/* help */
				usage(argv[0],1);
				exit(0);
				break;
			case 'v':	/* version */
				usage(argv[0],0);
				exit(0);
				break;
			case 'l':	/* log */
				logging=TYPE_ALL;
				logfile_name=strdup(optarg);
				break;
			case 'r':	/* seed */
				seed=atoi(optarg);
				seed_specified=1;
				printf("Using user-specified random seed of %d\n",seed);
				break;
			case 's':	/* stop */
				stop_after=atoi(optarg);
				break;

			case 't':	/* type */
				type=0;

				for(j=0;j<strlen(optarg);j++) {
					switch(optarg[j]) {
					case 'O': type|=TYPE_OPEN; break;
					case 'C': type|=TYPE_CLOSE; break;
					case 'I': type|=TYPE_IOCTL; break;
					case 'R': type|=TYPE_READ; break;
					case 'M': type|=TYPE_MMAP; break;
					case 'F': type|=TYPE_FORK; break;
					case 'Q': type|=TYPE_TRASH_MMAP; break;
					case 'W': type|=TYPE_WRITE; break;
					case 'P': type|=TYPE_PRCTL; break;
					case 'p': type|=TYPE_POLL; break;
					case 'A': type|=TYPE_ACCESS; break;
					case 'o': type|=TYPE_OVERFLOW; break;
					case 'i': type|=TYPE_MILLION; break;
					default: printf("Unknown type %c\n",
							optarg[j]);
					}
				}
				break;
			default:
				usage(argv[0],1);
				exit(1);
				break;
		}

	}

	/****************/
	/* Open logfile */
	/****************/

	if (logging) {

		if (!strcmp(logfile_name,"-")) {
			log_fd=1;		/* stdout */
		}
		else {
			log_fd=open(logfile_name,O_WRONLY|O_CREAT,0660);
			if (log_fd<0) {
				fprintf(stderr,"Error opening %s: %s\n",
					logfile_name,strerror(errno));
				exit(1);
			}
			fprintf(stderr,"Warning! Using a named log file might disrupt determinism due to the extra file descriptor created.  Consider logging to stdout instead\n\n");
		}
	}

	/****************/
	/* Print banner */
	/****************/

	printf("\n*** perf_fuzzer %s *** by Vince Weaver\n\n",VERSION);

	/*****************/
	/* Print OS info */
	/*****************/

	uname(&uname_info);

	printf("\t%s version %s %s\n",
		uname_info.sysname,uname_info.release,uname_info.machine);

	/*****************/
	/* Print cpuinfo */
	/*****************/

	get_cpuinfo(cpuinfo);
	printf("\tProcessor: %s\n",cpuinfo);

	/*****************/
	/* Print options */
	/*****************/

	if (stop_after)	printf("\tStopping after %d\n",stop_after);
	/* TODO: Make these configurable */
	printf("\tWatchdog enabled with timeout %ds\n",WATCHDOG_TIMEOUT);
	printf("\tWill auto-exit if signal storm detected\n");

	/**********************/
	/* Print logging info */
	/**********************/
	if (logging) {
		printf("\tLogging to file: %s\n",logfile_name);
		printf("\tLogging perf_event_open() failures: %s\n",
			LOG_FAILURES?"yes":"no");
		printf("\tRunning fsync after every syscall: %s\n",
			FSYNC_EVERY?"yes":"no");
	}

	/************************************/
	/* Seed the random number generator */
	/************************************/

	/* should read /dev/urandom instead? */
	if (!seed) {
		seed=time(NULL);
		printf("\tSeeding RNG from time %d\n",seed);
	}
	else {
		printf("\tSeeding RNG with supplied seed %d\n",seed);
	}
	srand(seed);

	/* Write seed to disk so we can find it later */
	fff=fopen("last.seed","w");
	if (fff!=NULL) {
		fprintf(fff,"%d\n",seed);
		fclose(fff);
	}

	if (logging) {
		sprintf(log_buffer,"S %d\n",seed);
		write(log_fd,log_buffer,strlen(log_buffer));
	}

	/************************/
	/* setup watchdog timer */
	/************************/

	/* FIXME: make optional */
        struct sigaction watchdog;

        memset(&watchdog, 0, sizeof(struct sigaction));
        watchdog.sa_sigaction = alarm_handler;
        watchdog.sa_flags = SA_SIGINFO | SA_RESTART;

        if (sigaction( SIGALRM, &watchdog, NULL) < 0) {
                printf("Error setting up alarm handler\n");
        }

        alarm(WATCHDOG_TIMEOUT);

	/******************************/
	/* Initialize data structures */
	/******************************/

	/* Clear errnos count */
	for(i=0;i<MAX_ERRNOS;i++) {
		stats.open_errno_count[i]=0;
		stats.fork_errno_count[i]=0;
	}

	/* Clear type counts */
	for(i=0;i<MAX_OPEN_TYPE;i++) {
		stats.open_type_success[i]=0;
		stats.open_type_fail[i]=0;
	}

	/* Save our pid so we can re-map on replay */
	if (logging) {
		sprintf(log_buffer,"G %d\n",getpid());
		write(log_fd,log_buffer,strlen(log_buffer));
	}

	/* Save the content of /proc/sys/kernel/perf_event_max_sample_rate */
	/* If it has been changed, a replay might not be perfect */
	sample_rate=get_sample_rate();
	if (logging) {
		sprintf(log_buffer,"r %d\n",sample_rate);
		write(log_fd,log_buffer,strlen(log_buffer));
	}

	/* Check kernel watchdog */
	kernel_watchdog=get_kernel_watchdog_value();

	/* Check paranoid setting */
	paranoid=get_paranoid_value();

	/*******************************/
	/* Print reproduce information */
	/*******************************/

	printf("\n\tTo reproduce, try:\n");
	printf("\t\techo %d > /proc/sys/kernel/nmi_watchdog\n",
		kernel_watchdog);
	printf("\t\techo %d > /proc/sys/kernel/perf_event_paranoid\n",
		paranoid);
	printf("\t\techo %d > /proc/sys/kernel/perf_event_max_sample_rate\n",
		sample_rate);

	printf("\t\t");
	for(i=0;i<argc;i++) {
		printf("%s ",argv[i]);
	}

	if (!seed_specified) printf("-r %d",seed);

	printf("\n\n");



	/* Print what we are actually fuzzing */
	/* Sometimes I comment out code and forget */

	missing=0;

	printf("\tFuzzing the following syscalls: ");
	if (type&TYPE_MMAP)  printf("mmap "); else missing++;
	if (type&TYPE_OPEN)  printf("perf_event_open "); else missing++;
	if (type&TYPE_CLOSE) printf("close "); else missing++;
	if (type&TYPE_READ)  printf("read "); else missing++;
	if (type&TYPE_WRITE) printf("write "); else missing++;
	if (type&TYPE_IOCTL) printf("ioctl "); else missing++;
	if (type&TYPE_FORK)  printf("fork "); else missing++;
	if (type&TYPE_PRCTL) printf("prctl "); else missing++;
	if (type&TYPE_POLL)  printf("poll "); else missing++;
	printf("\n");

	if (missing) {
		printf("\t*NOT* Fuzzing the following syscalls: ");
		if (!(type&TYPE_MMAP)) printf("mmap ");
		if (!(type&TYPE_OPEN)) printf("perf_event_open ");
		if (!(type&TYPE_CLOSE)) printf("close ");
		if (!(type&TYPE_READ)) printf("read ");
		if (!(type&TYPE_WRITE)) printf("write ");
		if (!(type&TYPE_IOCTL)) printf("ioctl ");
		if (!(type&TYPE_FORK)) printf("fork ");
		if (!(type&TYPE_PRCTL)) printf("prctl ");
		if (!(type&TYPE_POLL)) printf("poll ");
		printf("\n");
	}

	missing=0;

	printf("\tAlso attempting the following: ");
	if (type&TYPE_OVERFLOW) printf("signal-handler-on-overflow "); else missing++;
	if (type&TYPE_MILLION) printf("busy-instruction-loop "); else missing++;
	if (type&TYPE_ACCESS) printf("accessing-perf-proc-and-sys-files "); else missing++;
	if (type&TYPE_TRASH_MMAP) printf("trashing-the-mmap-page "); else missing++;
	printf("\n");

	if (missing) {
		printf("\t*NOT* attempting the following: ");
		if (!(type&TYPE_OVERFLOW)) printf("signal-handler-on-overflow ");
		if (!(type&TYPE_MILLION)) printf("busy-instruction-loop ");
		if (!(type&TYPE_ACCESS)) printf("accessing-perf-proc-and-sys-files ");
		if (!(type&TYPE_TRASH_MMAP)) printf("trashing-the-mmap-page ");
		printf("\n");
	}

	if (attempt_determinism) {
		printf("\n\tAttempting more deterministic results by:\n\t");
		printf("waitpid-after-killing-child ");
		printf("disabling-overflow-signal-handler ");
		printf("\n");

		/* Disable overflows if trying for determinism */
		if (attempt_determinism) {
			type&=~TYPE_OVERFLOW;
		}
	}

	/******************************************/
	/* Set up to match trinity setup, vaguely */
	/******************************************/

	page_size=getpagesize();
	//printf("Page size=%d\n",page_size);
	num_online_cpus = sysconf(_SC_NPROCESSORS_ONLN);

	create_shm();
	create_shm_arrays();
	init_shm();

//	init_shared_pages();

	syscall_perf_event_open.init();

	/* Initialize PMU names if possible */
	/* This depends on trinity exporting the values */
	if (pmus!=NULL) {
		for(i=0;i<num_pmus;i++) {
			if (pmus[i].type<MAX_OPEN_TYPE) {
				stats_set_pmu_name(pmus[i].type,pmus[i].name);
			}
		}
	}


	/************************/
	/* Set up SIGIO handler */
	/************************/

	/* In theory we shouldn't get SIGIO as we set up SIGRT for overflow */
	/* But if the RT queue overflows we will get a SIGIO */
	memset(&sigio, 0, sizeof(struct sigaction));
	sigio.sa_sigaction = sigio_handler;
	sigio.sa_flags = SA_SIGINFO;

	if (sigaction( SIGIO, &sigio, NULL) < 0) {
		printf("Error setting up SIGIO signal handler\n");
     	}


	/* Set up SIGQUIT handler */
	memset(&sigquit, 0, sizeof(struct sigaction));
	sigquit.sa_sigaction = sigquit_handler;
	sigquit.sa_flags = SA_SIGINFO;

	if (sigaction( SIGQUIT, &sigquit, NULL) < 0) {
		printf("Error setting up SIGQUIT signal handler\n");
     	}


	/* Initialize Event Structure */
	for(i=0;i<NUM_EVENTS;i++) {
		event_data[i].active=0;
		event_data[i].fd=0;
		event_data[i].read_size=rand();
	}

	/* Sleep to make it easier to ftrace/ptrace */
	printf("\n\tPid=%d, sleeping 1s\n\n",getpid());
	sleep(1);

	/* Print start time */

	time(&timer);
	tm_info = localtime(&timer);

	strftime(buffer, 26, "%Y-%m-%d %H:%M:%S", tm_info);
	printf("==================================================\n");
	printf("Starting fuzzing at %s\n",buffer);
	printf("==================================================\n");


	gettimeofday(&current_time,NULL);
	interval_start=current_time.tv_sec;

	/****************/
	/* MAIN LOOP	*/
	/****************/

	while(1) {

		switch(rand()%11) {
			case 0:	if (type&TYPE_OPEN) {
					open_random_event(type&TYPE_MMAP,
							type&TYPE_OVERFLOW);
				}
				break;
			case 1: if (type&TYPE_CLOSE) {
//					if (rand()%3==0)
						close_random_event();
				}
				break;
			case 2: if (type&TYPE_IOCTL) {
					ioctl_random_event();
				}
				break;
			case 3: if (type&TYPE_PRCTL) {
					prctl_random_event();
				}
				break;
			case 4: if (type&TYPE_READ) {
					read_random_event();
				}
				break;
			case 5: if (type&TYPE_WRITE) {
					write_random_event();
				}
				break;
			case 6: if (type&TYPE_ACCESS) {
					access_random_file();
				}
				break;
			case 7: if (type&TYPE_FORK) {
					fork_random_event();
				}
				break;
			case 8: if (type&TYPE_POLL) {
					poll_random_event();
				}
				break;
			case 9:if (type&TYPE_MMAP) {
					mmap_random_event(type);
				}
				break;
			default:
				if (type&TYPE_MILLION) {
					run_a_million_instructions();
				}
				break;
		}

#if FSYNC_EVERY
		if (logging) fsync(log_fd);
#endif

		if (throttle_close_event) {
			printf("Closing stuck event %d\n",
				throttle_close_event);
			close_event(throttle_close_event,1);
			throttle_close_event=0;
		}

		next_overflow_refresh=rand()%2;
		next_refresh=rand_refresh();
		stats.total_iterations++;
		watchdog_counter++;

		if ((stop_after) && (stats.total_iterations>=stop_after)) {
			long long end_count;

			end_count=stats.total_iterations%
                                        STATUS_UPDATE_INTERVAL;
			if ((end_count==0) && (stats.total_iterations>0)) {
				end_count=STATUS_UPDATE_INTERVAL;
			}

			gettimeofday(&current_time,NULL);
			rate=((double)(end_count))/
				(current_time.tv_sec-interval_start);

			dump_summary(stderr,1,rate);

			/* Kill child, doesn't happen automatically? */
			if (already_forked) {
				int status;
				kill(forked_pid,SIGKILL);
				waitpid(forked_pid, &status, 0);
			}
			return 0;
		}

		/* Print status update every 10000 iterations      */
		/* Don't print if logging to stdout as it clutters */
		/* up the trace file.				   */
		if (stats.total_iterations%STATUS_UPDATE_INTERVAL==0) {

			gettimeofday(&current_time,NULL);
			rate=((double)STATUS_UPDATE_INTERVAL)/
				(current_time.tv_sec-interval_start);

			if (log_fd!=1) {
				dump_summary(stderr,1,rate);
			}
			else {
				dump_summary(stderr,0,rate);
			}

			interval_start=current_time.tv_sec;
		}
//		fsync(log_fd);
	}

	return 0;

}
Esempio n. 19
0
/*
 * Read the slurm configuration file (slurm.conf) and substitute some
 * values into the slurmd configuration in preference of the defaults.
 */
static void
_read_config(void)
{
	char *path_pubkey = NULL;
	slurm_ctl_conf_t *cf = NULL;
	uint16_t tmp16 = 0;

#ifndef HAVE_FRONT_END
	bool cr_flag = false, gang_flag = false;
#endif

	cf = slurm_conf_lock();

	slurm_mutex_lock(&conf->config_mutex);

	if (conf->conffile == NULL)
		conf->conffile = xstrdup(cf->slurm_conf);

	conf->slurm_user_id =  cf->slurm_user_id;

	conf->cr_type = cf->select_type_param;

	path_pubkey = xstrdup(cf->job_credential_public_certificate);

	if (!conf->logfile)
		conf->logfile = xstrdup(cf->slurmd_logfile);

#ifndef HAVE_FRONT_END
	if (!strcmp(cf->select_type, "select/cons_res"))
		cr_flag = true;
	if (cf->preempt_mode & PREEMPT_MODE_GANG)
		gang_flag = true;
#endif

	slurm_conf_unlock();
	/* node_name may already be set from a command line parameter */
	if (conf->node_name == NULL)
		conf->node_name = slurm_conf_get_nodename(conf->hostname);
	/* if we didn't match the form of the hostname already
	 * stored in conf->hostname, check to see if we match any
	 * valid aliases */
	if (conf->node_name == NULL)
		conf->node_name = slurm_conf_get_aliased_nodename();

	if (conf->node_name == NULL)
		conf->node_name = slurm_conf_get_nodename("localhost");

	if (conf->node_name == NULL)
		fatal("Unable to determine this slurmd's NodeName");

	_massage_pathname(&conf->logfile);

	/* set node_addr if relevant */
	if ((conf->node_addr == NULL) &&
	    (conf->node_addr = slurm_conf_get_nodeaddr(conf->hostname)) &&
	    (strcmp(conf->node_addr, conf->hostname) == 0)) {
		xfree(conf->node_addr);	/* Sets to NULL */
	}

	conf->port = slurm_conf_get_port(conf->node_name);
	slurm_conf_get_cpus_bsct(conf->node_name,
				 &conf->conf_cpus, &conf->conf_boards,
				 &conf->conf_sockets, &conf->conf_cores,
				 &conf->conf_threads);

	/* store hardware properties in slurmd_config */
	xfree(conf->block_map);
	xfree(conf->block_map_inv);

	_update_logging();
	_update_nice();

	get_cpuinfo(&conf->actual_cpus,
		    &conf->actual_boards,
	            &conf->actual_sockets,
	            &conf->actual_cores,
	            &conf->actual_threads,
	            &conf->block_map_size,
	            &conf->block_map, &conf->block_map_inv);
#ifdef HAVE_FRONT_END
	/*
	 * When running with multiple frontends, the slurmd S:C:T values are not
	 * relevant, hence ignored by both _register_front_ends (sets all to 1)
	 * and validate_nodes_via_front_end (uses slurm.conf values).
	 * Report actual hardware configuration, irrespective of FastSchedule.
	 */
	conf->cpus    = conf->actual_cpus;
	conf->boards  = conf->actual_boards;
	conf->sockets = conf->actual_sockets;
	conf->cores   = conf->actual_cores;
	conf->threads = conf->actual_threads;
#else
	/* If the actual resources on a node differ than what is in
	 * the configuration file and we are using
	 * cons_res or gang scheduling we have to use what is in the
	 * configuration file because the slurmctld creates bitmaps
	 * for scheduling before these nodes check in.
	 */
	if (((cf->fast_schedule == 0) && !cr_flag && !gang_flag) ||
	    ((cf->fast_schedule == 1) &&
	     (conf->actual_cpus < conf->conf_cpus))) {
		conf->cpus    = conf->actual_cpus;
		conf->boards  = conf->actual_boards;
		conf->sockets = conf->actual_sockets;
		conf->cores   = conf->actual_cores;
		conf->threads = conf->actual_threads;
	} else {
		conf->cpus    = conf->conf_cpus;
		conf->boards  = conf->conf_boards;
		conf->sockets = conf->conf_sockets;
		conf->cores   = conf->conf_cores;
		conf->threads = conf->conf_threads;
	}

	if ((conf->cpus    != conf->actual_cpus)    ||
	    (conf->sockets != conf->actual_sockets) ||
	    (conf->cores   != conf->actual_cores)   ||
	    (conf->threads != conf->actual_threads)) {
		if (cf->fast_schedule) {
			info("Node configuration differs from hardware: "
			     "CPUs=%u:%u(hw) Boards=%u:%u(hw) "
			     "SocketsPerBoard=%u:%u(hw) CoresPerSocket=%u:%u(hw) "
			     "ThreadsPerCore=%u:%u(hw)",
			     conf->cpus,    conf->actual_cpus,
			     conf->boards,  conf->actual_boards,
			     conf->sockets, conf->actual_sockets,
			     conf->cores,   conf->actual_cores,
			     conf->threads, conf->actual_threads);
		} else if ((cf->fast_schedule == 0) && (cr_flag || gang_flag)) {
			error("You are using cons_res or gang scheduling with "
			      "Fastschedule=0 and node configuration differs "
			      "from hardware.  The node configuration used "
			      "will be what is in the slurm.conf because of "
			      "the bitmaps the slurmctld must create before "
			      "the slurmd registers.\n"
			      "   CPUs=%u:%u(hw) Boards=%u:%u(hw) "
			      "SocketsPerBoard=%u:%u(hw) CoresPerSocket=%u:%u(hw) "
			      "ThreadsPerCore=%u:%u(hw)",
			      conf->cpus,    conf->actual_cpus,
			      conf->boards,  conf->actual_boards,
			      conf->sockets, conf->actual_sockets,
			      conf->cores,   conf->actual_cores,
			      conf->threads, conf->actual_threads);
		}
	}
#endif

	get_memory(&conf->real_memory_size);
	get_up_time(&conf->up_time);

	cf = slurm_conf_lock();
	get_tmp_disk(&conf->tmp_disk_space, cf->tmp_fs);
	_free_and_set(&conf->epilog,   xstrdup(cf->epilog));
	_free_and_set(&conf->prolog,   xstrdup(cf->prolog));
	_free_and_set(&conf->tmpfs,    xstrdup(cf->tmp_fs));
	_free_and_set(&conf->health_check_program,
		      xstrdup(cf->health_check_program));
	_free_and_set(&conf->spooldir, xstrdup(cf->slurmd_spooldir));
	_massage_pathname(&conf->spooldir);
	_free_and_set(&conf->pidfile,  xstrdup(cf->slurmd_pidfile));
	_massage_pathname(&conf->pidfile);
	_free_and_set(&conf->select_type, xstrdup(cf->select_type));
	_free_and_set(&conf->task_prolog, xstrdup(cf->task_prolog));
	_free_and_set(&conf->task_epilog, xstrdup(cf->task_epilog));
	_free_and_set(&conf->pubkey,   path_pubkey);

	conf->debug_flags = cf->debug_flags;
	conf->propagate_prio = cf->propagate_prio_process;

	_free_and_set(&conf->job_acct_gather_freq,
		      xstrdup(cf->job_acct_gather_freq));

	conf->acct_freq_task = (uint16_t)NO_VAL;
	tmp16 = acct_gather_parse_freq(PROFILE_TASK,
				       conf->job_acct_gather_freq);
	if (tmp16 != -1)
		conf->acct_freq_task = tmp16;

	_free_and_set(&conf->acct_gather_energy_type,
		      xstrdup(cf->acct_gather_energy_type));
	_free_and_set(&conf->acct_gather_filesystem_type,
		      xstrdup(cf->acct_gather_filesystem_type));
	_free_and_set(&conf->acct_gather_infiniband_type,
		      xstrdup(cf->acct_gather_infiniband_type));
	_free_and_set(&conf->acct_gather_profile_type,
		      xstrdup(cf->acct_gather_profile_type));
	_free_and_set(&conf->job_acct_gather_type,
		      xstrdup(cf->job_acct_gather_type));

	if ( (conf->node_name == NULL) ||
	     (conf->node_name[0] == '\0') )
		fatal("Node name lookup failure");

	if (cf->control_addr == NULL)
		fatal("Unable to establish controller machine");
	if (cf->slurmctld_port == 0)
		fatal("Unable to establish controller port");
	conf->slurmd_timeout = cf->slurmd_timeout;
	conf->use_pam = cf->use_pam;
	conf->task_plugin_param = cf->task_plugin_param;

	slurm_mutex_unlock(&conf->config_mutex);
	slurm_conf_unlock();
}
Esempio n. 20
0
const char *get_cpu_name(void)
{
	return get_cpuinfo()->name;
}
Esempio n. 21
0
unsigned int get_max_ddr_size(void)
{
	return get_cpuinfo()->max_ddr_size;
}
Esempio n. 22
0
static int _task_cgroup_cpuset_dist_cyclic(
	hwloc_topology_t topology, hwloc_obj_type_t hwtype,
	hwloc_obj_type_t req_hwtype, stepd_step_rec_t *job, int bind_verbose,
	hwloc_bitmap_t cpuset)
{
	hwloc_obj_t obj;
	uint32_t  s_ix;		/* socket index */
	uint32_t *c_ixc;	/* core index by socket (current taskid) */
	uint32_t *c_ixn;	/* core index by socket (next taskid) */
	uint32_t *t_ix;		/* thread index by core by socket */
	uint16_t npus = 0, nboards = 0, nthreads = 0, ncores = 0, nsockets = 0;
	uint32_t taskid = job->envtp->localid;
	int spec_thread_cnt = 0;
	bitstr_t *spec_threads = NULL;
	uint32_t obj_idxs[3], cps, tpc, i, j, sock_loop, ntskip, npdist;
	bool core_cyclic, core_fcyclic, sock_fcyclic;
	bool hwloc_success = true;

	/*
	 * We can't trust the slurmd_conf_t *conf here as we need actual
	 * hardware instead of whatever is possibly configured.  So we need to
	 * look it up again.
	 */
	if (get_cpuinfo(&npus, &nboards, &nsockets, &ncores, &nthreads,
			NULL, NULL, NULL) != SLURM_SUCCESS) {
		/*
		 * Fall back to use allocated resources, but this may result
		 * in incorrect layout due to a uneven task distribution
		 * (e.g. 4 cores on socket 0 and 3 cores on socket 1)
		 */
		nsockets = (uint16_t) hwloc_get_nbobjs_by_type(topology,
							HWLOC_OBJ_SOCKET);
		ncores = (uint16_t) hwloc_get_nbobjs_by_type(topology,
							HWLOC_OBJ_CORE);
		nthreads = (uint16_t) hwloc_get_nbobjs_by_type(topology,
							HWLOC_OBJ_PU);
		npus = (uint16_t) hwloc_get_nbobjs_by_type(topology,
							   HWLOC_OBJ_PU);
	} else {
		/* Translate cores-per-socket to total core count, etc. */
		nsockets *= nboards;
		ncores *= nsockets;
		nthreads *= ncores;
	}

	if ((nsockets == 0) || (ncores == 0))
		return XCGROUP_ERROR;
	cps = (ncores + nsockets - 1) / nsockets;
	tpc = (nthreads + ncores - 1) / ncores;

	sock_fcyclic = (job->task_dist & SLURM_DIST_SOCKMASK) ==
		SLURM_DIST_SOCKCFULL ? true : false;
	core_cyclic = (job->task_dist & SLURM_DIST_COREMASK) ==
		SLURM_DIST_CORECYCLIC ? true : false;
	core_fcyclic = (job->task_dist & SLURM_DIST_COREMASK) ==
		SLURM_DIST_CORECFULL ? true : false;

	if (bind_verbose) {
		info("task/cgroup: task[%u] using %s distribution "
		     "(task_dist=0x%x)", taskid,
		     format_task_dist_states(job->task_dist), job->task_dist);
	}

	t_ix = xmalloc(ncores * sizeof(uint32_t));
	c_ixc = xmalloc(nsockets * sizeof(uint32_t));
	c_ixn = xmalloc(nsockets * sizeof(uint32_t));

	if (hwloc_compare_types(hwtype, HWLOC_OBJ_CORE) >= 0) {
		/* cores or threads granularity */
		ntskip = taskid;
		npdist = job->cpus_per_task;
	} else {
		/* sockets or ldoms granularity */
		ntskip = taskid;
		npdist = 1;
	}
	if ((job->job_core_spec != NO_VAL16) &&
	    (job->job_core_spec &  CORE_SPEC_THREAD)  &&
	    (job->job_core_spec != CORE_SPEC_THREAD)) {
		/* Skip specialized threads as needed */
		int i, t, c, s;
		int cores = (ncores + nsockets - 1) / nsockets;
		int threads = (npus + cores - 1) / cores;
		spec_thread_cnt = job->job_core_spec & (~CORE_SPEC_THREAD);
		spec_threads = bit_alloc(npus);
		for (t = threads - 1;
		     ((t >= 0) && (spec_thread_cnt > 0)); t--) {
			for (c = cores - 1;
			     ((c >= 0) && (spec_thread_cnt > 0)); c--) {
				for (s = nsockets - 1;
				     ((s >= 0) && (spec_thread_cnt > 0)); s--) {
					i = s * cores + c;
					i = (i * threads) + t;
					bit_set(spec_threads, i);
					spec_thread_cnt--;
				}
			}
		}
		if (hwtype == HWLOC_OBJ_PU) {
			for (i = 0; i <= ntskip && i < npus; i++) {
				if (bit_test(spec_threads, i))
					ntskip++;
			};
		}
	}

	/* skip objs for lower taskids, then add them to the
	   current task cpuset. To prevent infinite loop, check
	   that we do not loop more than npdist times around the available
	   sockets, which is the worst scenario we should afford here. */
	i = j = s_ix = sock_loop = 0;
	while (i < ntskip + 1 && (sock_loop/tpc) < npdist + 1) {
		/* fill one or multiple sockets using block mode, unless
		   otherwise stated in the job->task_dist field */
		while ((s_ix < nsockets) && (j < npdist)) {
			obj = hwloc_get_obj_below_by_type(
				topology, HWLOC_OBJ_SOCKET, s_ix,
				hwtype, c_ixc[s_ix]);
			if ((obj == NULL) && (s_ix == 0) && (c_ixc[s_ix] == 0))
				hwloc_success = false;	/* Complete failure */
			if ((obj != NULL) &&
			    (hwloc_bitmap_first(obj->allowed_cpuset) != -1)) {
				if (hwloc_compare_types(hwtype, HWLOC_OBJ_PU)
									>= 0) {
					/* granularity is thread */
					obj_idxs[0]=s_ix;
					obj_idxs[1]=c_ixc[s_ix];
					obj_idxs[2]=t_ix[(s_ix*cps)+c_ixc[s_ix]];
					obj = hwloc_get_obj_below_array_by_type(
						topology, 3, obj_types, obj_idxs);
					if ((obj != NULL) &&
					    (hwloc_bitmap_first(
					     obj->allowed_cpuset) != -1)) {
						t_ix[(s_ix*cps)+c_ixc[s_ix]]++;
						j++;
						if (i == ntskip)
							_add_hwloc_cpuset(hwtype,
							req_hwtype, obj, taskid,
							bind_verbose, cpuset);
						if (j < npdist) {
							if (core_cyclic) {
								c_ixn[s_ix] =
								c_ixc[s_ix] + 1;
							} else if (core_fcyclic){
								c_ixc[s_ix]++;
								c_ixn[s_ix] =
								c_ixc[s_ix];
							}
							if (sock_fcyclic)
								s_ix++;
						}
					} else {
						c_ixc[s_ix]++;
						if (c_ixc[s_ix] == cps)
							s_ix++;
					}
				} else {
					/* granularity is core or larger */
					c_ixc[s_ix]++;
					j++;
					if (i == ntskip)
						_add_hwloc_cpuset(hwtype,
							req_hwtype, obj, taskid,
						  	bind_verbose, cpuset);
					if ((j < npdist) && (sock_fcyclic))
						s_ix++;
				}
			} else
				s_ix++;
		}
		/* if it succeeds, switch to the next task, starting
		 * with the next available socket, otherwise, loop back
		 * from the first socket trying to find available slots. */
		if (j == npdist) {
			i++;
			j = 0;
			s_ix++; // no validity check, handled by the while
			sock_loop = 0;
		} else {
			sock_loop++;
			s_ix = 0;
		}
	}
	xfree(t_ix);
	xfree(c_ixc);
	xfree(c_ixn);

	if (spec_threads) {
		for (i = 0; i < npus; i++) {
			if (bit_test(spec_threads, i)) {
				hwloc_bitmap_clr(cpuset, i);
			}
		};
		FREE_NULL_BITMAP(spec_threads);
	}

	/* should never happen in normal scenario */
	if ((sock_loop > npdist) && !hwloc_success) {
		/* hwloc_get_obj_below_by_type() fails if no CPU set
		 * configured, see hwloc documentation for details */
		error("task/cgroup: hwloc_get_obj_below_by_type() failing, "
		      "task/affinity plugin may be required to address bug "
		      "fixed in HWLOC version 1.11.5");
		return XCGROUP_ERROR;
	} else if (sock_loop > npdist) {
		char buf[128] = "";
		hwloc_bitmap_snprintf(buf, sizeof(buf), cpuset);
		error("task/cgroup: task[%u] infinite loop broken while trying "
		      "to provision compute elements using %s (bitmap:%s)",
		      taskid, format_task_dist_states(job->task_dist), buf);
		return XCGROUP_ERROR;
	} else
		return XCGROUP_SUCCESS;
}
Esempio n. 23
0
static int get_root_array(char * page, int type, char **start, off_t offset, int length)
{
    switch (type) {
    case PROC_LOADAVG:
        return get_loadavg(page);

    case PROC_UPTIME:
        return get_uptime(page);

    case PROC_MEMINFO:
        return get_meminfo(page);

#ifdef CONFIG_PCI
    case PROC_PCI:
        return get_pci_list(page);
#endif

    case PROC_CPUINFO:
        return get_cpuinfo(page);

    case PROC_VERSION:
        return get_version(page);

#ifdef CONFIG_DEBUG_MALLOC
    case PROC_MALLOC:
        return get_malloc(page);
#endif

#ifdef CONFIG_MODULES
    case PROC_MODULES:
        return get_module_list(page);

    case PROC_KSYMS:
        return get_ksyms_list(page, start, offset, length);
#endif

    case PROC_STAT:
        return get_kstat(page);

    case PROC_DEVICES:
        return get_device_list(page);

    case PROC_INTERRUPTS:
        return get_irq_list(page);

    case PROC_FILESYSTEMS:
        return get_filesystem_list(page);

    case PROC_DMA:
        return get_dma_list(page);

    case PROC_IOPORTS:
        return get_ioport_list(page);
#ifdef CONFIG_BLK_DEV_MD
    case PROC_MD:
        return get_md_status(page);
#endif
#ifdef __SMP_PROF__
    case PROC_SMP_PROF:
        return get_smp_prof_list(page);
#endif
    case PROC_CMDLINE:
        return get_cmdline(page);

    case PROC_MTAB:
        return get_filesystem_info( page );
#ifdef CONFIG_RTC
    case PROC_RTC:
        return get_rtc_status(page);
#endif
    case PROC_LOCKS:
        return get_locks_status(page);
    }
    return -EBADF;
}