int main(int argc, char **argv) { int num_cpus; int i ; num_cpus = get_num_cpus(); assert(num_cpus >= 1); num_devices = ps_list_devices(devices); if (num_devices == -1) { perror("ps_list_devices"); exit(1); } parse_opt(argc, argv); for (i = 0; i < num_cpus; i++) { int ret = fork(); assert(ret >= 0); my_cpu = i; if (ret == 0) { bind_cpu(i); signal(SIGINT, handle_signal); echo(); return 0; } } signal(SIGINT, SIG_IGN); while (1) { int ret = wait(NULL); if (ret == -1 && errno == ECHILD) break; } return 0; }
/** * do_rtas_errinjct * @brief Perform the actual call to inject errors * * Perform the actual call to RTAS. This routine will also bind us to * a specific processor (if requested) and open RTAS error injection if an * open token is not specified. * * @param ei_func errinjct functionality * @return 0 on success, !0 otherwise */ int do_rtas_errinjct(ei_function *ei_func) { int rc = 0; int close_errinjct = 0; /* First see if we should bind ourselves to a processor */ rc = bind_cpu(); if (rc) return rc; /* Now, see if we need to open the RTAS errinjct facility */ if (ei_token == -1) { rc = open_rtas_errinjct(ei_func); if (rc != 0) return rc; close_errinjct = 1; } /* Make the RTAS call */ rc = rtas_errinjct(ei_func->rtas_token, ei_token, (char *)err_buf); if (rc != 0) { perr(0, "RTAS error injection failed!"); check_librtas_returns(rc, ei_func); printf("This error may have occurred because error injection\n" "is disabled for this partition. Please check the\n" "FSP and ensure you have error injection enabled.\n"); } else if (!be_quiet) { printf("Call to RTAS errinjct succeeded!\n\n"); } if (close_errinjct) rc = close_rtas_errinjct(ei_func); return rc; }
int main(int argc, char **argv) { num_devices = ps_list_devices(devices); if (num_devices == -1) { perror("ps_list_devices"); exit(1); } parse_opt(argc, argv); num_cpus = get_num_cpus(); assert(num_cpus >= 1); for (my_cpu = 0; my_cpu < num_cpus; my_cpu++) { int ret = fork(); assert(ret >= 0); if (ret == 0) { bind_cpu(my_cpu); signal(SIGINT, stat_signal); attach(); dump(); return 0; } } signal(SIGINT, SIG_IGN); while(1) { int ret = wait(NULL); if(-1 == ret && ECHILD == errno) break; } return 0; }
int main(int argc, char **argv) { int vmefd; char cmd[sizeof(IFCONFIG_BIN) + sizeof(vmeif_name) + sizeof(vmeif_ipstr) + 50]; uint8_t *buf; int ch; while ((ch = getopt(argc, argv, "a:b:i:l:p:q")) != -1) { switch (ch) { case 'a': strlcpy(vmeif_ipstr, optarg, sizeof(vmeif_ipstr)); break; case 'b': sscanf(optarg, "%d", &cpu); break; case 'i': strlcpy(vmeif_name, optarg, sizeof(vmeif_name)); break; case 'l': sscanf(optarg, "%d", &pktsize); break; case 'p': payload = strdup(optarg); break; case 'q': quiet = 1; break; default: usage(argv[0]); break; } } if (!quiet) { printf("vme name: %s\n", vmeif_name); printf("vme ip: %s\n", vmeif_ipstr); printf("packet size: %d\n", pktsize); printf("payload: %s\n", payload); if (cpu != -1) printf("cpu: %d\n", cpu); } if (cpu != -1) bind_cpu(cpu); signal(SIGINT, signal_handler); snprintf(vmedev, sizeof(vmedev), "/dev/%s", vmeif_name); vmefd = open(vmedev, O_RDWR); if (vmefd == -1) { fprintf(stderr, "Failed to open %s: %s\n", vmedev, strerror(errno)); exit(EXIT_FAILURE); } snprintf(cmd, sizeof(cmd), IFCONFIG_BIN IFCONFIG_ARGS, vmeif_name, vmeif_ipstr); if (system(cmd) != 0) { fprintf(stderr, "Failed to setup %s\n", vmeif_name); exit(EXIT_FAILURE); } if ((vmeif_ip = inet_addr(vmeif_ipstr)) == INADDR_NONE) { fprintf(stderr, "Malformed address %s specified\n", vmeif_ipstr); exit(EXIT_FAILURE); } if (get_ifaddr(vmeif_name, vmeif_ether) != 0) { fprintf(stderr, "Failed to get %s's MAC address\n", vmeif_name); exit(EXIT_FAILURE); } if ((buf = malloc(pktsize)) == NULL) { perror("Failed to allocate memory for packet"); exit(EXIT_FAILURE); } /* Keep injecting packets to network stack */ while (1) { build_udp_packet(buf, pktsize); if (write(vmefd, buf, pktsize) == -1) { perror("write"); exit(EXIT_FAILURE); } total_sent++; } return (0); }
int main(int argc, char **argv) { int num_packets = 0; int chunk_size = 64; int packet_size = 60; int num_flows = 0; int i; ip_version = 4; struct timeval begin, end; num_cpus = get_num_cpus(); assert(num_cpus >= 1); num_devices = ps_list_devices(devices); assert(num_devices != -1); assert(num_devices > 0); for (i = 1; i < argc; i += 2) { if (i == argc - 1) print_usage(argv[0]); if (!strcmp(argv[i], "-n")) { num_packets = atoi(argv[i + 1]); assert(num_packets >= 0); } else if (!strcmp(argv[i], "-s")) { chunk_size = atoi(argv[i + 1]); assert(chunk_size >= 1 && chunk_size <= MAX_CHUNK_SIZE); } else if (!strcmp(argv[i], "-p")) { packet_size = atoi(argv[i + 1]); assert(packet_size >= 60 && packet_size <= 1514); } else if (!strcmp(argv[i], "-f")) { num_flows = atoi(argv[i + 1]); assert(num_flows >= 0 && num_flows <= MAX_FLOWS); } else if (!strcmp(argv[i], "-v")) { ip_version = atoi(argv[i + 1]); assert(ip_version == 4 || ip_version == 6); } else if (!strcmp(argv[i], "-i")) { int ifindex = -1; int j; if (!strcmp(argv[i + 1], "all")) { for (j = 0; j < num_devices; j++) devices_registered[j] = j; num_devices_registered = num_devices; continue; } for (j = 0; j < num_devices; j++) if (!strcmp(argv[i + 1], devices[j].name)) ifindex = j; if (ifindex == -1) { fprintf(stderr, "device %s does not exist!\n", argv[i + 1]); exit(1); } for (j = 0; j < num_devices_registered; j++) if (devices_registered[j] == ifindex) { fprintf(stderr, "device %s is registered more than once!\n", argv[i + 1]); exit(1); } devices_registered[num_devices_registered] = ifindex; num_devices_registered++; } else if (!strcmp(argv[i], "-t")) { time_limit = atoi(argv[i + 1]); assert(time_limit >= 0); } else print_usage(argv[0]); } if (num_devices_registered == 0) print_usage(argv[0]); printf("# of CPUs = %d\n", num_cpus); printf("# of packets to transmit = %d\n", num_packets); printf("chunk size = %d\n", chunk_size); printf("packet size = %d bytes\n", packet_size); printf("# of flows = %d\n", num_flows); printf("ip version = %d\n", ip_version); printf("time limit = %d seconds\n", time_limit); printf("interfaces: "); for (i = 0; i < num_devices_registered; i++) { if (i > 0) printf(", "); printf("%s", devices[devices_registered[i]].name); } printf("\n"); printf("----------\n"); if (num_flows > 0) srand(time(NULL)); assert(gettimeofday(&begin, NULL) == 0); for (my_cpu = 0; my_cpu < num_cpus; my_cpu++) { int ret = fork(); assert(ret >= 0); if (ret == 0) { bind_cpu(my_cpu); signal(SIGINT, handle_signal); send_packets(num_packets ? : LONG_MAX, chunk_size, packet_size, num_flows); return 0; } }
static void rtprio(pthread_attr_t *attr, int prio) { #ifdef PTHREAD_EXPLICIT_SCHED struct sched_param param = { .sched_priority = 99 }; pthread_attr_setinheritsched(attr, PTHREAD_EXPLICIT_SCHED); pthread_attr_setschedpolicy(attr, SCHED_FIFO); pthread_attr_setschedparam(attr, ¶m); #endif } static double l_estimate(igt_stats_t *stats) { if (stats->n_values > 9) return igt_stats_get_trimean(stats); else if (stats->n_values > 5) return igt_stats_get_median(stats); else return igt_stats_get_mean(stats); } static double min_measurement_error(void) { struct timespec start, end; int n; clock_gettime(CLOCK_MONOTONIC, &start); for (n = 0; n < 1024; n++) clock_gettime(CLOCK_MONOTONIC, &end); return elapsed(&start, &end) / n; } int main(int argc, char **argv) { struct gem_busyspin *busy; struct sys_wait *wait; pthread_attr_t attr; int ncpus = sysconf(_SC_NPROCESSORS_ONLN); igt_stats_t cycles, mean, max; double min; int time = 10; int field = -1; int enable_gem_sysbusy = 1; int n, c; while ((c = getopt(argc, argv, "t:f:n")) != -1) { switch (c) { case 'n': /* dry run, measure baseline system latency */ enable_gem_sysbusy = 0; break; case 't': /* How long to run the benchmark for (seconds) */ time = atoi(optarg); if (time < 0) time = INT_MAX; break; case 'f': /* Select an output field */ field = atoi(optarg); break; default: break; } } /* Prevent CPU sleeps so that busy and idle loads are consistent. */ force_low_latency(); min = min_measurement_error(); busy = calloc(ncpus, sizeof(*busy)); pthread_attr_init(&attr); if (enable_gem_sysbusy) { for (n = 0; n < ncpus; n++) { bind_cpu(&attr, n); pthread_create(&busy[n].thread, &attr, gem_busyspin, &busy[n]); } } wait = calloc(ncpus, sizeof(*wait)); pthread_attr_init(&attr); rtprio(&attr, 99); for (n = 0; n < ncpus; n++) { igt_mean_init(&wait[n].mean); bind_cpu(&attr, n); pthread_create(&wait[n].thread, &attr, sys_wait, &wait[n]); } sleep(time); done = 1; igt_stats_init_with_size(&cycles, ncpus); if (enable_gem_sysbusy) { for (n = 0; n < ncpus; n++) { pthread_join(busy[n].thread, NULL); igt_stats_push(&cycles, busy[n].count); } } igt_stats_init_with_size(&mean, ncpus); igt_stats_init_with_size(&max, ncpus); for (n = 0; n < ncpus; n++) { pthread_join(wait[n].thread, NULL); igt_stats_push_float(&mean, wait[n].mean.mean); igt_stats_push_float(&max, wait[n].mean.max); } switch (field) { default: printf("gem_syslatency: cycles=%.0f, latency mean=%.3fus max=%.0fus\n", igt_stats_get_mean(&cycles), (igt_stats_get_mean(&mean) - min)/ 1000, (l_estimate(&max) - min) / 1000); break; case 0: printf("%.0f\n", igt_stats_get_mean(&cycles)); break; case 1: printf("%.3f\n", (igt_stats_get_mean(&mean) - min) / 1000); break; case 2: printf("%.0f\n", (l_estimate(&max) - min) / 1000); break; } return 0; }
int main(int argc, char **argv) { int tapfd; char cmd[sizeof(IFCONFIG_BIN) + sizeof(tapif_name) + sizeof(tapif_ipstr) + 50]; uint8_t *buf; int ch; while ((ch = getopt(argc, argv, "a:b:i:l:n:s:p:fhq46")) != -1) { switch (ch) { case 'a': strlcpy(tapif_ipstr, optarg, sizeof(tapif_ipstr)); break; case 'b': sscanf(optarg, "%d", &cpu); break; case 'f': force_fragment = 1; break; case 'i': strlcpy(tapif_name, optarg, sizeof(tapif_name)); break; case 'l': sscanf(optarg, "%d", &payloadlen); break; case 'n': sscanf(optarg, "%d", &npackets); break; case 's': sscanf(optarg, "%d", &src_port); break; case 'p': strncpy(payload, optarg, sizeof(payload)); break; case 'q': quiet = 1; break; case '4': ipversion = 4; break; case '6': ipversion = 6; break; case 'h': default: usage(argv[0]); break; } } if (tapif_ipstr[0] == '\0') strlcpy(tapif_ipstr, (ipversion == 4) ? tapif_ipstr_v4 : tapif_ipstr_v6, sizeof(tapif_ipstr)); if (src_addr[0] == '\0') strlcpy(src_addr, (ipversion == 4) ? src_addr_v4: src_addr_v6, sizeof(src_addr)); if (!quiet) { printf("tap name: %s\n", tapif_name); printf("IP version: %d\n", ipversion); printf("tap IP: %s\n", tapif_ipstr); printf("src addr: %s\n", src_addr); printf("src port: %d\n", src_port); printf("packets: %d\n", npackets); printf("payload length: %d\n", payloadlen); printf("payload: %s\n", payload); if (cpu != -1) printf("cpu: %d\n", cpu); } if (cpu != -1) bind_cpu(cpu); signal(SIGINT, signal_handler); snprintf(tapdev, sizeof(tapdev), "/dev/%s", tapif_name); tapfd = open(tapdev, O_RDWR); if (tapfd == -1) { fprintf(stderr, "Failed to open %s: %s\n", tapdev, strerror(errno)); exit(EXIT_FAILURE); } switch (ipversion) { case 4: if (inet_pton(AF_INET, tapif_ipstr, &tapif_ip) != 1) { fprintf(stderr, "Malformed address %s specified\n", tapif_ipstr); exit(EXIT_FAILURE); } snprintf(cmd, sizeof(cmd), IFCONFIG_BIN IFCONFIG_ARGS, tapif_name, "inet", tapif_ipstr); build_udp_packet = build_udp_packet_v4; if (inet_pton(AF_INET, src_addr, &ip_src) != 1) { fprintf(stderr, "Malformed address %s specified\n", src_addr); exit(EXIT_FAILURE); } break; case 6: if (inet_pton(AF_INET6, tapif_ipstr, &tapif_ip6) != 1) { fprintf(stderr, "Malformed address %s specified\n", tapif_ipstr); exit(EXIT_FAILURE); } snprintf(cmd, sizeof(cmd), IFCONFIG_BIN IFCONFIG_ARGS, tapif_name, "inet6", tapif_ipstr); build_udp_packet = build_udp_packet_v6; if (inet_pton(AF_INET6, src_addr, &ip6_src) != 1) { fprintf(stderr, "Malformed address %s specified\n", src_addr); exit(EXIT_FAILURE); } break; default: fprintf(stderr, "Only support ipv4 and ipv6.\n"); exit(EXIT_FAILURE); } if (system(cmd) != 0) { fprintf(stderr, "Failed to setup %s\n", tapif_name); exit(EXIT_FAILURE); } if (get_ifaddr(tapif_name, tapif_ether) != 0) { fprintf(stderr, "Failed to get %s's MAC address\n", tapif_name); exit(EXIT_FAILURE); } if ((buf = malloc(payloadlen + 200)) == NULL) { perror("Failed to allocate memory for packet"); exit(EXIT_FAILURE); } /* Wait 1 second to make sure the ifa6 is ready */ sleep(1); /* Keep injecting packets to network stack */ while (1) { int off = 0; while (off != payloadlen) { int pktsize = build_udp_packet(buf, payloadlen, &off); if (write(tapfd, buf, pktsize) == -1) { perror("write"); exit(EXIT_FAILURE); } usleep(2); /* wait 2ms */ } if (++total_sent == npackets) break; } return (0); }
void thread_iter(int dram_refs, int nvm_refs, int interleave_dram, int interleave_nvm) { long it_n; unsigned long time_dram, time_nvm, total_time_dram_ns, total_time_nvm_ns; uint64_t seed; uint64_t j; chain_t *C_dram[MAX_NUM_CHAINS]; chain_t *C_nvm[MAX_NUM_CHAINS]; int missing_dram_refs, missing_nvm_refs; int dram_stalls, nvm_stalls; struct timespec task_time_start, task_time_end; unsigned long task_time_diff_ns; #ifndef NDEBUG pid_t tid = (pid_t) syscall(SYS_gettid); #endif assert(NELEMS < UINT64_MAX); for (j=0; j < NCHAINS; j++) { seed = SEED_IN + j*j; C_dram[j] = alloc_chain(seed, NELEMS, 64LLU, 0, 0); C_nvm[j] = alloc_chain(seed, NELEMS, 64LLU, 0, 1); __asm__(""); } bind_cpu(thread_self()); // cache must be trashed after bind_cpu() call trash_cache(NELEMS); total_time_dram_ns = 0; total_time_nvm_ns = 0; missing_dram_refs = dram_refs; missing_nvm_refs = nvm_refs; #ifndef NDEBUG printf("DRAM accesses to be made: %ld\n", dram_refs); printf("NVM accesses to be made: %ld\n", nvm_refs); #endif //delay_cycles(8000000000); //printf("STARTING MEASURES\n"); clock_gettime(CLOCK_MONOTONIC, &task_time_start); for (it_n = 0; (missing_dram_refs > 0) || (missing_nvm_refs > 0); ++it_n) { __asm__(""); // calculate the number o memory accesses to be made on each memory type if (missing_dram_refs > interleave_dram) { missing_dram_refs -= interleave_dram; dram_stalls = interleave_dram; } else { dram_stalls = missing_dram_refs; missing_dram_refs = 0; } if (missing_nvm_refs > interleave_nvm) { missing_nvm_refs -= interleave_nvm; nvm_stalls = interleave_nvm; } else { nvm_stalls = missing_nvm_refs; missing_nvm_refs = 0; } time_dram = 0; time_nvm = 0; // do memory accesses interleaved by dividing the number of accesses in smaller amount // as configured by user force_ldm_stalls((chain_t **)&C_dram, 64LLU, 8, dram_stalls, NELEMS, it_n, &time_dram); force_ldm_stalls((chain_t **)&C_nvm, 64LLU, 8, nvm_stalls, NELEMS, it_n, &time_nvm); total_time_dram_ns += time_dram; total_time_nvm_ns += time_nvm; #ifndef NDEBUG printf("%ld DRAM accesses took: %ld ns\n", dram_stalls, time_dram); printf("%ld NVM accesses took: %ld ns\n", nvm_stalls, time_nvm); #endif } clock_gettime(CLOCK_MONOTONIC, &task_time_end); task_time_diff_ns = ((task_time_end.tv_sec * 1000000000) + task_time_end.tv_nsec) - ((task_time_start.tv_sec * 1000000000) + task_time_start.tv_nsec); // the memory latency is the total time divided by the number of accesses for each memory type if (dram_refs > 0) total_time_dram_ns /= dram_refs; else total_time_dram_ns = 0; if (nvm_refs > 0) total_time_nvm_ns /= nvm_refs; else total_time_nvm_ns = 0; printf("DRAM latency: %ld ns\n", total_time_dram_ns); printf("NVM latency: %ld ns\n", total_time_nvm_ns); printf("Measure time: %.3lf ms\n", (double)task_time_diff_ns/1000000.0); printf("Expected time: %.3ld ms\n", ((total_time_dram_ns * dram_refs) + (total_time_nvm_ns * nvm_refs)) / 1000000); for (j=0; j < NCHAINS; j++) { free(C_dram[j]); free(C_nvm[j]); } }