/* * 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; }
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); }