diff --git a/examples/ioat/perf/perf.c b/examples/ioat/perf/perf.c index ba756bacc..1c8439468 100644 --- a/examples/ioat/perf/perf.c +++ b/examples/ioat/perf/perf.c @@ -31,6 +31,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include #include @@ -161,31 +162,20 @@ register_workers(void) { unsigned lcore; struct worker_thread *worker; - struct worker_thread *prev_worker; - worker = malloc(sizeof(struct worker_thread)); - if (worker == NULL) { - perror("worker_thread malloc"); - return -1; - } + g_workers = NULL; + g_num_workers = 0; - memset(worker, 0, sizeof(struct worker_thread)); - worker->lcore = rte_get_master_lcore(); - - g_workers = worker; - g_num_workers = 1; - - RTE_LCORE_FOREACH_SLAVE(lcore) { - prev_worker = worker; - worker = malloc(sizeof(struct worker_thread)); + RTE_LCORE_FOREACH(lcore) { + worker = calloc(1, sizeof(*worker)); if (worker == NULL) { - perror("worker_thread malloc"); + fprintf(stderr, "Unable to allocate worker\n"); return -1; } - memset(worker, 0, sizeof(struct worker_thread)); worker->lcore = lcore; - prev_worker->next = worker; + worker->next = g_workers; + g_workers = worker; g_num_workers++; } @@ -515,7 +505,8 @@ int main(int argc, char **argv) { int rc; - struct worker_thread *worker; + struct worker_thread *worker, *master_worker; + unsigned master_core; if (parse_args(argc, argv) != 0) { return 1; @@ -557,25 +548,26 @@ main(int argc, char **argv) } /* Launch all of the slave workers */ - worker = g_workers->next; + master_core = rte_get_master_lcore(); + master_worker = NULL; + worker = g_workers; while (worker != NULL) { - rte_eal_remote_launch(work_fn, worker, worker->lcore); + if (worker->lcore != master_core) { + rte_eal_remote_launch(work_fn, worker, worker->lcore); + } else { + assert(master_worker == NULL); + master_worker = worker; + } worker = worker->next; } - rc = work_fn(g_workers); + assert(master_worker != NULL); + rc = work_fn(master_worker); if (rc < 0) { goto cleanup; } - worker = g_workers->next; - while (worker != NULL) { - if (rte_eal_wait_lcore(worker->lcore) < 0) { - rc = -1; - goto cleanup; - } - worker = worker->next; - } + rte_eal_mp_wait_lcore(); rc = dump_result(); diff --git a/examples/nvme/arbitration/arbitration.c b/examples/nvme/arbitration/arbitration.c index 44e0c1572..e92e43bcb 100644 --- a/examples/nvme/arbitration/arbitration.c +++ b/examples/nvme/arbitration/arbitration.c @@ -430,18 +430,18 @@ cleanup(void) struct worker_thread *next_worker = NULL; struct arb_task *task = NULL; - do { + while (entry) { next_entry = entry->next; free(entry); entry = next_entry; - } while (entry); + }; - do { + while (worker) { next_worker = worker->next; free(worker->ns_ctx); free(worker); worker = next_worker; - } while (worker); + }; if (rte_mempool_get(task_pool, (void **)&task) == 0) { spdk_free(task->buf); @@ -827,38 +827,27 @@ register_workers(void) { unsigned lcore; struct worker_thread *worker; - struct worker_thread *prev_worker; enum spdk_nvme_qprio qprio = SPDK_NVME_QPRIO_URGENT; - worker = malloc(sizeof(struct worker_thread)); - if (worker == NULL) { - perror("worker_thread malloc"); - return 1; - } + g_workers = NULL; + g_arbitration.num_workers = 0; - memset(worker, 0, sizeof(struct worker_thread)); - worker->lcore = rte_get_master_lcore(); - - g_workers = worker; - worker->qprio = qprio; - g_arbitration.num_workers = 1; - - RTE_LCORE_FOREACH_SLAVE(lcore) { - prev_worker = worker; - worker = malloc(sizeof(struct worker_thread)); + RTE_LCORE_FOREACH(lcore) { + worker = calloc(1, sizeof(*worker)); if (worker == NULL) { - perror("worker_thread malloc"); - return 1; + fprintf(stderr, "Unable to allocate worker\n"); + return -1; } - memset(worker, 0, sizeof(struct worker_thread)); worker->lcore = lcore; - prev_worker->next = worker; + worker->next = g_workers; + g_workers = worker; g_arbitration.num_workers++; if (g_arbitration.arbitration_mechanism == SPDK_NVME_CAP_AMS_WRR) { qprio++; } + worker->qprio = qprio % SPDK_NVME_QPRIO_MAX; } @@ -1090,7 +1079,8 @@ int main(int argc, char **argv) { int rc; - struct worker_thread *worker; + struct worker_thread *worker, *master_worker; + unsigned master_core; char task_pool_name[30]; uint32_t task_count; struct spdk_env_opts opts; @@ -1145,22 +1135,24 @@ main(int argc, char **argv) printf("Initialization complete. Launching workers.\n"); /* Launch all of the slave workers */ - worker = g_workers->next; + master_core = rte_get_master_lcore(); + master_worker = NULL; + worker = g_workers; while (worker != NULL) { - rte_eal_remote_launch(work_fn, worker, worker->lcore); - worker = worker->next; - } - - rc = work_fn(g_workers); - - worker = g_workers->next; - while (worker != NULL) { - if (rte_eal_wait_lcore(worker->lcore) < 0) { - rc = 1; + if (worker->lcore != master_core) { + rte_eal_remote_launch(work_fn, worker, worker->lcore); + } else { + assert(master_worker == NULL); + master_worker = worker; } worker = worker->next; } + assert(master_worker != NULL); + rc = work_fn(master_worker); + + rte_eal_mp_wait_lcore(); + print_stats(); unregister_controllers(); diff --git a/examples/nvme/perf/perf.c b/examples/nvme/perf/perf.c index f8a206536..9fe357346 100644 --- a/examples/nvme/perf/perf.c +++ b/examples/nvme/perf/perf.c @@ -989,31 +989,20 @@ register_workers(void) { unsigned lcore; struct worker_thread *worker; - struct worker_thread *prev_worker; - worker = malloc(sizeof(struct worker_thread)); - if (worker == NULL) { - perror("worker_thread malloc"); - return -1; - } + g_workers = NULL; + g_num_workers = 0; - memset(worker, 0, sizeof(struct worker_thread)); - worker->lcore = rte_get_master_lcore(); - - g_workers = worker; - g_num_workers = 1; - - RTE_LCORE_FOREACH_SLAVE(lcore) { - prev_worker = worker; - worker = malloc(sizeof(struct worker_thread)); + RTE_LCORE_FOREACH(lcore) { + worker = calloc(1, sizeof(*worker)); if (worker == NULL) { - perror("worker_thread malloc"); + fprintf(stderr, "Unable to allocate worker\n"); return -1; } - memset(worker, 0, sizeof(struct worker_thread)); worker->lcore = lcore; - prev_worker->next = worker; + worker->next = g_workers; + g_workers = worker; g_num_workers++; } @@ -1204,7 +1193,8 @@ associate_workers_with_ns(void) int main(int argc, char **argv) { int rc; - struct worker_thread *worker; + struct worker_thread *worker, *master_worker; + unsigned master_core; char task_pool_name[30]; uint32_t task_count; struct spdk_env_opts opts; @@ -1271,22 +1261,24 @@ int main(int argc, char **argv) printf("Initialization complete. Launching workers.\n"); /* Launch all of the slave workers */ - worker = g_workers->next; + master_core = rte_get_master_lcore(); + master_worker = NULL; + worker = g_workers; while (worker != NULL) { - rte_eal_remote_launch(work_fn, worker, worker->lcore); - worker = worker->next; - } - - rc = work_fn(g_workers); - - worker = g_workers->next; - while (worker != NULL) { - if (rte_eal_wait_lcore(worker->lcore) < 0) { - rc = -1; + if (worker->lcore != master_core) { + rte_eal_remote_launch(work_fn, worker, worker->lcore); + } else { + assert(master_worker == NULL); + master_worker = worker; } worker = worker->next; } + assert(master_worker != NULL); + rc = work_fn(master_worker); + + rte_eal_mp_wait_lcore(); + print_stats(); cleanup: