Exemplo n.º 1
0
/*
 *  stress_rdrand()
 *      stress Intel rdrand instruction
 */
static int stress_rdrand(const args_t *args)
{
	if (rdrand_supported) {
		double time_start, duration, billion_bits;
		bool lock = false;

		time_start = time_now();
		do {
#if defined(__x86_64__) || defined(__x86_64)
			RDRAND64x32();
#else
			RDRAND32x64();
#endif
			inc_counter(args);
		} while (keep_stressing());

		duration = time_now() - time_start;
		billion_bits = ((double)get_counter(args) * 64.0 * 32.0) / 1000000000.0;

		pr_lock(&lock);
		pr_dbg_lock(&lock, "%s: %.3f billion random bits read "
			"(instance %" PRIu32")\n",
			args->name, billion_bits, args->instance);
		if (duration > 0.0) {
			pr_dbg_lock(&lock, "%s: %.3f billion random bits per "
				"second (instance %" PRIu32")\n",
				args->name,
				(double)billion_bits / duration,
				args->instance);
		}
		pr_unlock(&lock);
	}
	return EXIT_SUCCESS;
}
Exemplo n.º 2
0
void process_command_connections(int port, int bus, bool verbose)
{
	int i2c_handle, sock, result, con;
	socklen_t client_address_size;
	struct sockaddr_storage client_address;
	char client_ip[INET6_ADDRSTRLEN];

	if (verbose) printf("Opening command I2C handle\n");
	i2c_handle = open_i2c(bus, 1); 
	if (i2c_handle == -1) {
		perror("ERROR => Couldn't open i2c bus. The error was:");
		exit(1);
	}

	sock = create_and_bind_tcp_socket(port);
	if (sock == -1) {
		exit(1);
	}

	while (1) {
		
		if (verbose) printf("Listening for incoming command connections\n");

		result = listen(sock, 20);
		if (result != 0) {
			fprintf(stderr, "ERROR: Error attempting to listen on socket");
			continue;
		}

		client_address_size = sizeof(client_address);
		con = accept(sock, (struct sockaddr *) &client_address, &client_address_size);
		if (con < 0) {
			fprintf(stderr, "ERROR: Error attempting to accept connection");
			continue;
		}

		get_address_ip((struct sockaddr*)&client_address, client_ip, sizeof(client_ip));
		printf("Command connection accepted from %s\n", client_ip);

		process_command_connection(con, i2c_handle, verbose);

		printf("Closing command connection\n");
		close(con);

		printf("Removing all poll records\n");
		pr_lock("pcc");
		pr_clear_and_free_all();
		pr_unlock();
	}

	printf("Closing command socket\n");
	close(sock);

	printf("Closing command I2C handle\n");
	close(i2c_handle);
}
Exemplo n.º 3
0
/* PR_SETCACHE -- Set the size of the process cache.  This is automatically
 * called whenever the value of the parameter cl.szprcache is set.  Changing
 * the cache size on an active cache causes the cache to be flushed and all
 * locked processes to be reconnected.
 */
void 
pr_setcache (int new_szprcache)
{
	struct	process *pr;
	char	pname[MAXSUBPROC][SZ_PATHNAME+1];
	int	nprocs=0, pid, i;
	FILE	*fdummy;

	if (pr_head == NULL)
	    pr_initcache();
	else {
	    /* Get the names of any processes currently locked into the cache,
	     * then dump the cache.
	     */
	    for (pr=pr_head;  pr != NULL;  pr=pr->pr_dn)
		if (pr->pr_pid != NULL && (pr->pr_flags & P_LOCKED))
		    strcpy (pname[nprocs++], pr->pr_name);
	    pr_dumpcache (0, 1);
	}

	/* Set the new value of sz_prcache. */
	sz_prcache = new_szprcache;
	if (sz_prcache < 2)
	    sz_prcache = 2;
	else if (sz_prcache > MAXSUBPROC)
	    sz_prcache = MAXSUBPROC;

	/* Relink the empty cache for sz_prcache cache slots. */
	pr_initcache();

	/* Attempt to recache the formerly locked processes.  There must be
	 * at least one empty slot left for new subprocesses.
	 */
	if (nprocs+1 > sz_prcache)
	    nprocs = sz_prcache-1;

	for (i=0;  i < nprocs;  i++) {
	    pid = pr_connect (findexe(NULL,pname[i]), "\n", &fdummy, &fdummy,
		stdin, stdout, stderr, 0,0,0, 0);
	    pr_disconnect (pid);
	    pr_lock (pid);
	}
}