creates a distributor instance */
| 708 | |
| 709 | /* creates a distributor instance */ |
| 710 | struct rte_distributor * |
| 711 | rte_distributor_create(const char *name, |
| 712 | unsigned int socket_id, |
| 713 | unsigned int num_workers, |
| 714 | unsigned int alg_type) |
| 715 | { |
| 716 | struct rte_distributor *d; |
| 717 | struct rte_dist_burst_list *dist_burst_list; |
| 718 | char mz_name[RTE_MEMZONE_NAMESIZE]; |
| 719 | const struct rte_memzone *mz; |
| 720 | unsigned int i; |
| 721 | |
| 722 | /* TODO Reorganise function properly around RTE_DIST_ALG_SINGLE/BURST */ |
| 723 | |
| 724 | /* compilation-time checks */ |
| 725 | RTE_BUILD_BUG_ON((sizeof(*d) & RTE_CACHE_LINE_MASK) != 0); |
| 726 | RTE_BUILD_BUG_ON((RTE_DISTRIB_MAX_WORKERS & 7) != 0); |
| 727 | |
| 728 | if (name == NULL || num_workers >= |
| 729 | (unsigned int)RTE_MIN(RTE_DISTRIB_MAX_WORKERS, RTE_MAX_LCORE)) { |
| 730 | rte_errno = EINVAL; |
| 731 | return NULL; |
| 732 | } |
| 733 | |
| 734 | if (alg_type == RTE_DIST_ALG_SINGLE) { |
| 735 | d = malloc(sizeof(struct rte_distributor)); |
| 736 | if (d == NULL) { |
| 737 | rte_errno = ENOMEM; |
| 738 | return NULL; |
| 739 | } |
| 740 | d->d_single = rte_distributor_create_single(name, |
| 741 | socket_id, num_workers); |
| 742 | if (d->d_single == NULL) { |
| 743 | free(d); |
| 744 | /* rte_errno will have been set */ |
| 745 | return NULL; |
| 746 | } |
| 747 | d->alg_type = alg_type; |
| 748 | return d; |
| 749 | } |
| 750 | |
| 751 | snprintf(mz_name, sizeof(mz_name), RTE_DISTRIB_PREFIX"%s", name); |
| 752 | mz = rte_memzone_reserve(mz_name, sizeof(*d), socket_id, NO_FLAGS); |
| 753 | if (mz == NULL) { |
| 754 | rte_errno = ENOMEM; |
| 755 | return NULL; |
| 756 | } |
| 757 | |
| 758 | d = mz->addr; |
| 759 | strlcpy(d->name, name, sizeof(d->name)); |
| 760 | d->num_workers = num_workers; |
| 761 | d->alg_type = alg_type; |
| 762 | |
| 763 | d->dist_match_fn = RTE_DIST_MATCH_SCALAR; |
| 764 | #if defined(RTE_ARCH_X86) |
| 765 | if (rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_128) |
| 766 | d->dist_match_fn = RTE_DIST_MATCH_VECTOR; |
| 767 | #endif |