int main(int argc, char** argv) { printf(PIPEMENU_BEGIN); print_cpu(0, count_cpus()); printf(PIPEMENU_END); return 0; }
static void report_cpumask(struct buffer_instance *instance) { char *str; char *cont; int cpus; int n; int i; str = get_instance_file_content(instance, "tracing_cpumask"); if (!str) return; cont = strstrip(str); /* check to make sure all CPUs on this machine are set */ cpus = count_cpus(); for (i = strlen(cont) - 1; i >= 0 && cpus > 0; i--) { if (cont[i] == ',') continue; if (cont[i] == 'f') { cpus -= 4; continue; } if (cpus >= 4) break; if (cont[i] >= '0' && cont[i] <= '9') n = cont[i] - '0'; else n = 10 + (cont[i] - 'a'); while (cpus > 0) { if (!(n & 1)) break; n >>= 1; cpus--; } break; } /* If cpus is greater than zero, one isn't set */ if (cpus > 0) printf("\nCPU mask: %s\n", cont); free(str); }
int main (int argc, char **argv) { pthread_t *threads; long i; int ret; struct timespec intv; struct sched_param param; parse_options(argc, argv); signal(SIGINT, stop_log); if (argc >= (optind + 1)) nr_tasks = atoi(argv[optind]); else nr_tasks = count_cpus() + 1; threads = malloc(sizeof(*threads) * nr_tasks); if (!threads) perr("malloc"); memset(threads, 0, sizeof(*threads) * nr_tasks); ret = pthread_barrier_init(&start_barrier, NULL, nr_tasks + 1); ret = pthread_barrier_init(&end_barrier, NULL, nr_tasks + 1); if (ret < 0) perr("pthread_barrier_init"); intervals = malloc(sizeof(void*) * nr_runs); if (!intervals) perr("malloc intervals array"); intervals_length = malloc(sizeof(void*) * nr_runs); if (!intervals_length) perr("malloc intervals length array"); intervals_loops = malloc(sizeof(void*) * nr_runs); if (!intervals_loops) perr("malloc intervals loops array"); thread_pids = malloc(sizeof(long) * nr_tasks); if (!thread_pids) perr("malloc thread_pids"); for (i=0; i < nr_runs; i++) { intervals[i] = malloc(sizeof(unsigned long long)*nr_tasks); if (!intervals[i]) perr("malloc intervals"); memset(intervals[i], 0, sizeof(unsigned long long)*nr_tasks); intervals_length[i] = malloc(sizeof(unsigned long long)*nr_tasks); if (!intervals_length[i]) perr("malloc length intervals"); memset(intervals_length[i], 0, sizeof(unsigned long long)*nr_tasks); intervals_loops[i] = malloc(sizeof(unsigned long)*nr_tasks); if (!intervals_loops[i]) perr("malloc loops intervals"); memset(intervals_loops[i], 0, sizeof(unsigned long)*nr_tasks); } for (i=0; i < nr_tasks; i++) { if (pthread_create(&threads[i], NULL, start_task, (void *)i)) perr("pthread_create"); } /* * Progress bar uses stderr to let users see it when * redirecting output. So we convert stderr to use line * buffering so the progress bar doesn't flicker. */ setlinebuf(stderr); /* up our prio above all tasks */ memset(¶m, 0, sizeof(param)); param.sched_priority = nr_tasks + prio_start; if (sched_setscheduler(0, SCHED_FIFO, ¶m)) fprintf(stderr, "Warning, can't set priority of main thread!\n"); intv.tv_sec = nano2sec(INTERVAL); intv.tv_nsec = INTERVAL % sec2nano(1); print_progress_bar(0); lfd = do_logdev_open(); logdev_print_set(1); logdev_switch_set(1); for (loop=0; loop < nr_runs; loop++) { unsigned long long end; now = get_time(); lgprint(lfd, "Loop %d now=%lld\n", loop, now); pthread_barrier_wait(&start_barrier); lgprint(lfd, "All running!!!\n"); nanosleep(&intv, NULL); print_progress_bar((loop * 100)/ nr_runs); end = get_time(); lgprint(lfd, "Loop %d end now=%lld diff=%lld\n", loop, end, end - now); pthread_barrier_wait(&end_barrier); if (stop || (check && check_times(loop))) { loop++; nr_runs = loop; break; } } do_logdev_close(lfd); putc('\n', stderr); pthread_barrier_wait(&start_barrier); done = 1; pthread_barrier_wait(&end_barrier); for (i=0; i < nr_tasks; i++) pthread_join(threads[i], (void*)&thread_pids[i]); logdev_print_set(0); logdev_switch_set(0); print_results(); if (stop) { /* * We use this test in bash while loops * So if we hit Ctrl-C then let the while * loop know to break. */ if (check < 0) exit(-1); else exit(1); } if (check < 0) exit(-1); else exit(0); return 0; }
int main(int argc, char *argv[]) { int c; int errs; int ncpus; int nthreads; cpu_set_t cpus; extern int opterr; extern int optind; extern char *optarg; unsigned long long pci_mem_addr = 0; if ((program = strrchr(argv[0], '/')) != NULL) ++program; else program = argv[0]; set_program_name(program); /* * default to checking all cpus */ for (c = 0; c < CPU_SETSIZE; c++) { CPU_SET(c, &cpus); } opterr = 0; errs = 0; while ((c = getopt_long(argc, argv, optstring, options, NULL)) != EOF) { switch (c) { case 'a': ascii = 1; break; case 't': transmitter = 1; break; case 'c': if (parse_cpu_set(optarg, &cpus) != 0) ++errs; break; case 'm': pci_mem_addr = strtoul(optarg, NULL, 16); break; default: ERROR(0, "unknown option '%c'", c); ++errs; break; } } open_channel(pci_mem_addr); if (errs) { usage(); exit(1); } /* * limit the set of CPUs to the ones that are currently available * (Note that on some kernel versions sched_setaffinity() will fail * if you specify CPUs that are not currently online so we ignore * the return value and hope for the best) */ sched_setaffinity(0, sizeof cpus, &cpus); if (sched_getaffinity(0, sizeof cpus, &cpus) < 0) { ERROR(errno, "sched_getaffinity() failed"); exit(1); } /* * create the threads */ ncpus = count_cpus(&cpus); nthreads = create_per_cpu_threads(&cpus, worker_thread, NULL); if (nthreads != ncpus) { ERROR(0, "failed to create threads: expected %d, got %d", ncpus, nthreads); if (nthreads) { join_threads(); } return 1; } join_threads(); }