uintmax_t test_vfork_exec(uintmax_t num, uintmax_t int_arg, const char *path) { pid_t pid; uintmax_t i; pid = vfork(); if (pid < 0) err(-1, "test_vfork_exec: vfork"); if (pid == 0) { (void)execve(USR_BIN_TRUE, execve_args, environ); err(-1, "test_vfork_exec: execve"); } if (waitpid(pid, NULL, 0) < 0) err(-1, "test_vfork_exec: waitpid"); benchmark_start(); for (i = 0; i < num; i++) { if (alarm_fired) break; pid = vfork(); if (pid < 0) err(-1, "test_vfork_exec: vfork"); if (pid == 0) { (void)execve(USR_BIN_TRUE, execve_args, environ); err(-1, "execve"); } if (waitpid(pid, NULL, 0) < 0) err(-1, "test_vfork_exec: waitpid"); } benchmark_stop(); return (i); }
uintmax_t test_open_read_close(uintmax_t num, uintmax_t int_arg, const char *path) { char buf[int_arg]; uintmax_t i; int fd; fd = open(path, O_RDONLY); if (fd < 0) err(-1, "test_open_read_close: %s", path); (void)read(fd, buf, int_arg); close(fd); benchmark_start(); for (i = 0; i < num; i++) { if (alarm_fired) break; fd = open(path, O_RDONLY); if (fd < 0) err(-1, "test_open_read_close: %s", path); (void)read(fd, buf, int_arg); close(fd); } benchmark_stop(); return (i); }
uintmax_t test_vfork(uintmax_t num, uintmax_t int_arg, const char *path) { pid_t pid; uintmax_t i; pid = vfork(); if (pid < 0) err(-1, "test_vfork: vfork"); if (pid == 0) _exit(0); if (waitpid(pid, NULL, 0) < 0) err(-1, "test_vfork: waitpid"); benchmark_start(); for (i = 0; i < num; i++) { if (alarm_fired) break; pid = vfork(); if (pid < 0) err(-1, "test_vfork: vfork"); if (pid == 0) _exit(0); if (waitpid(pid, NULL, 0) < 0) err(-1, "test_vfork: waitpid"); } benchmark_stop(); return (i); }
uintmax_t test_create_unlink(uintmax_t num, uintmax_t int_arg, const char *path) { uintmax_t i; int fd; (void)unlink(path); fd = open(path, O_RDWR | O_CREAT, 0600); if (fd < 0) err(-1, "test_create_unlink: create: %s", path); close(fd); if (unlink(path) < 0) err(-1, "test_create_unlink: unlink: %s", path); benchmark_start(); for (i = 0; i < num; i++) { if (alarm_fired) break; fd = open(path, O_RDWR | O_CREAT, 0600); if (fd < 0) err(-1, "test_create_unlink: create: %s", path); close(fd); if (unlink(path) < 0) err(-1, "test_create_unlink: unlink: %s", path); } benchmark_stop(); return (i); }
uintmax_t test_pipe(uintmax_t num, uintmax_t int_arg, const char *path) { int fd[2], i; /* * pipe creation is expensive, as it will allocate a new file * descriptor, allocate a new pipe, hook it all up, and return. * Destroying is also expensive, as we now have to free up * the file descriptors and return the pipe. */ if (pipe(fd) < 0) err(-1, "test_pipe: pipe"); close(fd[0]); close(fd[1]); benchmark_start(); for (i = 0; i < num; i++) { if (alarm_fired) break; if (pipe(fd) == -1) err(-1, "test_pipe: pipe"); close(fd[0]); close(fd[1]); } benchmark_stop(); return (i); }
void VisionSet8(image_t *pSrc, image_t *pDst) { benchmark_t bench; // 1. Start a benchmark, execute vision operation and send info to PC benchmark_start(&bench, "Copy"); vCopy(pSrc, pDst); benchmark_stop(&bench); pc_send_benchmark(&bench); pDst->lut = LUT_STRETCH; pc_send_image(pDst); pc_send_string("1. Copy"); // 2. Start a benchmark, execute vision operation and send info to PC benchmark_start(&bench, "Erase"); vErase(pDst); benchmark_stop(&bench); pc_send_benchmark(&bench); pDst->lut = LUT_BINARY; pc_send_image(pDst); pc_send_string("2. Erase"); }
uintmax_t test_bad_open(uintmax_t num, uintmax_t int_arg, const char *path) { uintmax_t i; benchmark_start(); for (i = 0; i < num; i++) { if (alarm_fired) break; open("", O_RDONLY); } benchmark_stop(); return (i); }
uintmax_t test_getpriority(uintmax_t num, uintmax_t int_arg, const char *path) { uintmax_t i; benchmark_start(); for (i = 0; i < num; i++) { if (alarm_fired) break; (void)getpriority(PRIO_PROCESS, 0); } benchmark_stop(); return (i); }
uintmax_t test_getresuid(uintmax_t num, uintmax_t int_arg, const char *path) { uid_t ruid, euid, suid; uintmax_t i; benchmark_start(); for (i = 0; i < num; i++) { if (alarm_fired) break; (void)getresuid(&ruid, &euid, &suid); } benchmark_stop(); return (i); }
uintmax_t test_clock_gettime(uintmax_t num, uintmax_t int_arg, const char *path) { struct timespec ts; uintmax_t i; benchmark_start(); for (i = 0; i < num; i++) { if (alarm_fired) break; (void)clock_gettime(CLOCK_REALTIME, &ts); } benchmark_stop(); return (i); }
uintmax_t test_gettimeofday(uintmax_t num, uintmax_t int_arg, const char *path) { struct timeval tv; uintmax_t i; benchmark_start(); for (i = 0; i < num; i++) { if (alarm_fired) break; (void)gettimeofday(&tv, NULL); } benchmark_stop(); return (i); }
uintmax_t test_chroot(uintmax_t num, uintmax_t int_arg, const char *path) { uintmax_t i; if (chroot("/") < 0) err(-1, "test_chroot: chroot"); benchmark_start(); for (i = 0; i < num; i++) { if (alarm_fired) break; if (chroot("/") < 0) err(-1, "test_chroot: chroot"); } benchmark_stop(); return (i); }
uintmax_t test_getppid(uintmax_t num, uintmax_t int_arg, const char *path) { uintmax_t i; /* * This is process-local, but can change, so will require a * lock. */ benchmark_start(); for (i = 0; i < num; i++) { if (alarm_fired) break; getppid(); } benchmark_stop(); return (i); }
uintmax_t test_getuid(uintmax_t num, uintmax_t int_arg, const char *path) { uintmax_t i; /* * Thread-local data should require no locking if system * call is MPSAFE. */ benchmark_start(); for (i = 0; i < num; i++) { if (alarm_fired) break; getuid(); } benchmark_stop(); return (i); }
uintmax_t test_setuid(uintmax_t num, uintmax_t int_arg, const char *path) { uid_t uid; uintmax_t i; uid = getuid(); if (setuid(uid) < 0) err(-1, "test_setuid: setuid"); benchmark_start(); for (i = 0; i < num; i++) { if (alarm_fired) break; if (setuid(uid) < 0) err(-1, "test_setuid: setuid"); } benchmark_stop(); return (i); }
uintmax_t test_socket_dgram(uintmax_t num, uintmax_t int_arg, const char *path) { uintmax_t i, so; so = socket(int_arg, SOCK_DGRAM, 0); if (so < 0) err(-1, "test_socket_dgram: socket"); close(so); benchmark_start(); for (i = 0; i < num; i++) { if (alarm_fired) break; so = socket(int_arg, SOCK_DGRAM, 0); if (so == -1) err(-1, "test_socket_dgram: socket"); close(so); } benchmark_stop(); return (i); }
uintmax_t test_access(uintmax_t num, uintmax_t int_arg, const char *path) { uintmax_t i; int fd; fd = access(path, O_RDONLY); if (fd < 0) err(-1, "test_access: %s", path); close(fd); benchmark_start(); for (i = 0; i < num; i++) { if (alarm_fired) break; access(path, O_RDONLY); close(fd); } benchmark_stop(); return (i); }
uintmax_t test_fstat_shmfd(uintmax_t num, uintmax_t int_arg, const char *path) { struct stat sb; uintmax_t i, shmfd; shmfd = shm_open(SHM_ANON, O_CREAT | O_RDWR, 0600); if (shmfd < 0) err(-1, "test_fstat_shmfd: shm_open"); if (fstat(shmfd, &sb) < 0) err(-1, "test_fstat_shmfd: fstat"); benchmark_start(); for (i = 0; i < num; i++) { if (alarm_fired) break; (void)fstat(shmfd, &sb); } benchmark_stop(); close(shmfd); return (i); }
uintmax_t test_shmfd(uintmax_t num, uintmax_t int_arg, const char *path) { uintmax_t i; int shmfd; shmfd = shm_open(SHM_ANON, O_CREAT | O_RDWR, 0600); if (shmfd < 0) err(-1, "test_shmfd: shm_open"); close(shmfd); benchmark_start(); for (i = 0; i < num; i++) { if (alarm_fired) break; shmfd = shm_open(SHM_ANON, O_CREAT | O_RDWR, 0600); if (shmfd < 0) err(-1, "test_shmfd: shm_open"); close(shmfd); } benchmark_stop(); return (i); }
uintmax_t test_socketpair_dgram(uintmax_t num, uintmax_t int_arg, const char *path) { uintmax_t i; int so[2]; if (socketpair(PF_LOCAL, SOCK_DGRAM, 0, so) == -1) err(-1, "test_socketpair_dgram: socketpair"); close(so[0]); close(so[1]); benchmark_start(); for (i = 0; i < num; i++) { if (alarm_fired) break; if (socketpair(PF_LOCAL, SOCK_DGRAM, 0, so) == -1) err(-1, "test_socketpair_dgram: socketpair"); close(so[0]); close(so[1]); } benchmark_stop(); return (i); }
uintmax_t test_select(uintmax_t num, uintmax_t int_arg, const char *path) { fd_set readfds, writefds, exceptfds; struct timeval tv; uintmax_t i; int error; FD_ZERO(&readfds); FD_ZERO(&writefds); FD_ZERO(&exceptfds); tv.tv_sec = 0; tv.tv_usec = 0; benchmark_start(); for (i = 0; i < num; i++) { if (alarm_fired) break; (void)select(0, &readfds, &writefds, &exceptfds, &tv); } benchmark_stop(); return (i); }
int main (int argc, char **argv) { int status = 0; int i; char *filename = NULL; progname = argv[0]; bufsiz = resolv_number (BGPDUMP_BUFSIZ_DEFAULT, NULL); nroutes = resolv_number (ROUTE_LIMIT_DEFAULT, NULL); status = bgpdump_getopt (argc, argv); argc -= optind; argv += optind; if (status) return status; if (argc == 0) { printf ("specify rib files.\n"); usage (); exit (-1); } if (verbose) { printf ("bufsiz = %llu\n", bufsiz); printf ("nroutes = %llu\n", nroutes); } /* default cmd */ if (! brief && ! show && ! route_count && ! plen_dist && ! udiff && ! lookup && ! peer_table_only && ! stat && ! compat_mode && ! autsiz && ! heatmap) show++; if (stat) peer_stat_init (); char *buf; buf = malloc (bufsiz); if (! buf) { printf ("can't malloc %lluB-size buf: %s\n", bufsiz, strerror (errno)); exit (-1); } peer_table_init (); if (peer_spec_size) { for (i = 0; i < peer_spec_size; i++) { peer_route_table[i] = route_table_create (); peer_route_size[i] = 0; peer_ptree[i] = ptree_create (); } } if (lookup) { route_init (); ptree[AF_INET] = ptree_create (); ptree[AF_INET6] = ptree_create (); } if (udiff) { diff_table[0] = malloc (nroutes * sizeof (struct bgp_route)); diff_table[1] = malloc (nroutes * sizeof (struct bgp_route)); assert (diff_table[0] && diff_table[1]); memset (diff_table[0], 0, nroutes * sizeof (struct bgp_route)); memset (diff_table[1], 0, nroutes * sizeof (struct bgp_route)); if (udiff_lookup) { diff_ptree[0] = ptree_create (); diff_ptree[1] = ptree_create (); } } /* for each rib files. */ for (i = 0; i < argc; i++) { filename = argv[i]; file_format_t format; struct access_method *method; void *file; size_t ret; format = get_file_format (filename); method = get_access_method (format); file = method->fopen (filename, "r"); if (! file) { fprintf (stderr, "# could not open file: %s\n", filename); continue; } size_t datalen = 0; while (1) { ret = method->fread (buf + datalen, bufsiz - datalen, 1, file); if (debug) printf ("read: %lu bytes to buf[%lu]. total %lu bytes\n", ret, datalen, ret + datalen); datalen += ret; /* end of file. */ if (ret == 0 && method->feof (file)) { if (debug) printf ("read: end-of-file.\n"); break; } bgpdump_process (buf, &datalen); if (debug) printf ("process rest: %lu bytes\n", datalen); } if (datalen) { printf ("warning: %lu bytes unprocessed data remains: %s\n", datalen, filename); } method->fclose (file); /* For each end of the processing of files. */ if (route_count) { peer_route_count_show (); peer_route_count_clear (); } if (plen_dist) { peer_route_count_by_plen_show (); peer_route_count_by_plen_clear (); } } /* query_table construction. */ if (lookup) { query_limit = 0; if (lookup_file) query_limit = query_file_count (lookup_file); if (lookup_addr) query_limit++; query_init (); if (lookup_addr) query_addr (lookup_addr); if (lookup_file) query_file (lookup_file); if (debug) query_list (); } /* query to route_table (ptree). */ if (lookup) { if (benchmark) benchmark_start (); if (peer_spec_size) { for (i = 0; i < peer_spec_size; i++) { printf ("peer %d:\n", peer_spec_index[i]); if (verbose) ptree_list (peer_ptree[i]); ptree_query (peer_ptree[i], query_table, query_size); } } else { if (verbose) ptree_list (ptree[qaf]); ptree_query (ptree[qaf], query_table, query_size); } if (benchmark) { benchmark_stop (); benchmark_print (query_size); } } if (heatmap) { for (i = 0; i < peer_spec_size; i++) { heatmap_image_hilbert_gplot (i); heatmap_image_hilbert_data (i); //heatmap_image_hilbert_data_aspath_max_distance (i); } } if (lookup) { free (query_table); ptree_delete (ptree[AF_INET]); ptree_delete (ptree[AF_INET6]); route_finish (); } if (udiff) { free (diff_table[0]); free (diff_table[1]); if (lookup) { ptree_delete (diff_ptree[0]); ptree_delete (diff_ptree[1]); } } if (stat) { peer_stat_show (); //peer_stat_finish (); } free (buf); return status; }
// ---------------------------------------------------------------------------- // Main program // ---------------------------------------------------------------------------- int main(void) { // Declare variables image_t *src; image_t *dst; benchmark_t bench; // FPU: Set CP10 and CP11 Full Access SCB->CPACR |= ((3U << 10*2)|(3U << 11*2)); // Initialize hardware led_init(); mem_manager_init(); camera_init(); timer_init(); pc_interface_init(); // Allocate memory for images src = mem_manager_alloc(); dst = mem_manager_alloc(); while(1) { led_toggle(LED_GREEN); // Set the maximum frame rate and reset the time timer_set_fps(10); timer_reset(); // Reset image counter to make sure it starts at zero pc_reset_image_counter(); // Start a benchmark benchmark_start(&bench,"Frame"); // Receive image from PC? if(pc_mode_from_pc()) { // Yes, get image from the PC interface pc_receive_image(src); } else { // No, get image from the camera module camera_snapshot(&src); // The camera module is mounted upside down, therefore the image // is rotated vRotate180(src); } // Execute selected vision set programma_start(src, dst); // Sleep until timer expires timer_sleep(); // Stop and send the benchmark benchmark_stop(&bench); pc_send_benchmark(&bench); } }