예제 #1
0
파일: reservation.c 프로젝트: JevonQ/spdk
int main(int argc, char **argv)
{
	struct pci_device_iterator	*pci_dev_iter;
	struct pci_device		*pci_dev;
	struct dev			*iter;
	struct pci_id_match		match;
	int				rc, i;

	rc = rte_eal_init(sizeof(ealargs) / sizeof(ealargs[0]),
			  (char **)(void *)(uintptr_t)ealargs);

	if (rc < 0) {
		fprintf(stderr, "could not initialize dpdk\n");
		exit(1);
	}

	request_mempool = rte_mempool_create("nvme_request", 8192,
					     nvme_request_size(), 128, 0,
					     NULL, NULL, NULL, NULL,
					     SOCKET_ID_ANY, 0);

	if (request_mempool == NULL) {
		fprintf(stderr, "could not initialize request mempool\n");
		exit(1);
	}

	pci_system_init();

	match.vendor_id =	PCI_MATCH_ANY;
	match.subvendor_id =	PCI_MATCH_ANY;
	match.subdevice_id =	PCI_MATCH_ANY;
	match.device_id =	PCI_MATCH_ANY;
	match.device_class =	NVME_CLASS_CODE;
	match.device_class_mask = 0xFFFFFF;

	pci_dev_iter = pci_id_match_iterator_create(&match);

	rc = 0;
	while ((pci_dev = pci_device_next(pci_dev_iter))) {
		struct nvme_controller *ctrlr;
		struct dev *dev;

		if (pci_device_has_non_uio_driver(pci_dev)) {
			fprintf(stderr, "non-uio kernel driver attached to nvme\n");
			fprintf(stderr, " controller at pci bdf %d:%d:%d\n",
				pci_dev->bus, pci_dev->dev, pci_dev->func);
			fprintf(stderr, " skipping...\n");
			continue;
		}

		pci_device_probe(pci_dev);

		ctrlr = nvme_attach(pci_dev);
		if (ctrlr == NULL) {
			fprintf(stderr, "failed to attach to NVMe controller at PCI BDF %d:%d:%d\n",
				pci_dev->bus, pci_dev->dev, pci_dev->func);
			rc = 1;
			continue;
		}
		/* add to dev list */
		dev = &devs[num_devs++];
		dev->pci_dev = pci_dev;
		dev->ctrlr = ctrlr;
	}

	pci_iterator_destroy(pci_dev_iter);

	if (num_devs) {
		rc = nvme_register_io_thread();
		if (rc != 0)
			return rc;
	}

	foreach_dev(iter) {
		reserve_controller(iter->ctrlr, iter->pci_dev);
	}

	printf("Cleaning up...\n");

	for (i = 0; i < num_devs; i++) {
		struct dev *dev = &devs[i];
		nvme_detach(dev->ctrlr);
	}

	if (num_devs)
		nvme_unregister_io_thread();

	return rc;
}
예제 #2
0
파일: perf.c 프로젝트: ninataki/spdk
int main(int argc, char **argv)
{
    int rc;
    struct worker_thread *worker;

    rc = parse_args(argc, argv);
    if (rc != 0) {
        return rc;
    }

    ealargs[1] = sprintf_alloc("-c %s", g_core_mask ? g_core_mask : "0x1");
    if (ealargs[1] == NULL) {
        perror("ealargs sprintf_alloc");
        return 1;
    }

    rc = rte_eal_init(sizeof(ealargs) / sizeof(ealargs[0]), ealargs);

    free(ealargs[1]);

    if (rc < 0) {
        fprintf(stderr, "could not initialize dpdk\n");
        return 1;
    }

    request_mempool = rte_mempool_create("nvme_request", 8192,
                                         nvme_request_size(), 128, 0,
                                         NULL, NULL, NULL, NULL,
                                         SOCKET_ID_ANY, 0);

    if (request_mempool == NULL) {
        fprintf(stderr, "could not initialize request mempool\n");
        return 1;
    }

    task_pool = rte_mempool_create("task_pool", 8192,
                                   sizeof(struct perf_task),
                                   64, 0, NULL, NULL, task_ctor, NULL,
                                   SOCKET_ID_ANY, 0);

    g_tsc_rate = rte_get_timer_hz();

    if (register_workers() != 0) {
        return 1;
    }

    if (register_aio_files(argc, argv) != 0) {
        return 1;
    }

    if (register_controllers() != 0) {
        return 1;
    }

    if (associate_workers_with_ns() != 0) {
        return 1;
    }

    printf("Initialization complete. Launching workers.\n");

    /* Launch all of the slave workers */
    worker = g_workers->next;
    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;
        }
        worker = worker->next;
    }

    print_stats();

    unregister_controllers();

    if (rc != 0) {
        fprintf(stderr, "%s: errors occured\n", argv[0]);
    }

    return rc;
}