void rte_hexdump(const char * title, const void * buf, unsigned int len) { unsigned int i, out, ofs; const unsigned char *data = buf; char line[LINE_LEN]; /* space needed 8+16*3+3+16 == 75 */ printf("%s at [%p], len=%u\n", (title)? title : " Dump data", data, len); ofs = 0; while (ofs < len) { /* format the line in the buffer, then use printf to output to screen */ out = rte_snprintf(line, LINE_LEN, "%08X:", ofs); for (i = 0; ((ofs + i) < len) && (i < 16); i++) out += rte_snprintf(line+out, LINE_LEN - out, " %02X", (data[ofs+i] & 0xff)); for(; i <= 16; i++) out += rte_snprintf(line+out, LINE_LEN - out, " | "); for(i = 0; (ofs < len) && (i < 16); i++, ofs++) { unsigned char c = data[ofs]; if ( (c < ' ') || (c > '~')) c = '.'; out += rte_snprintf(line+out, LINE_LEN - out, "%c", c); } printf("%s\n", line); } fflush(stdout); }
int cmdline_get_help_string(cmdline_parse_token_hdr_t *tk, char *dstbuf, unsigned int size) { struct cmdline_token_string *tk2; struct cmdline_token_string_data *sd; const char *s; if (!tk || !dstbuf) return -1; tk2 = (struct cmdline_token_string *)tk; sd = &tk2->string_data; s = sd->str; if (s) { if (get_next_token(s)) rte_snprintf(dstbuf, size, MULTISTRING_HELP); else rte_snprintf(dstbuf, size, FIXEDSTRING_HELP); } else rte_snprintf(dstbuf, size, ANYSTRING_HELP); return 0; }
/* * Allocates memory for LPM object */ struct rte_lpm * rte_lpm_create(const char *name, int socket_id, int max_rules, __rte_unused int flags) { char mem_name[RTE_LPM_NAMESIZE]; struct rte_lpm *lpm = NULL; uint32_t mem_size; struct rte_lpm_list *lpm_list; /* check that we have an initialised tail queue */ if ((lpm_list = RTE_TAILQ_LOOKUP_BY_IDX(RTE_TAILQ_LPM, rte_lpm_list)) == NULL) { rte_errno = E_RTE_NO_TAILQ; return NULL; } RTE_BUILD_BUG_ON(sizeof(struct rte_lpm_tbl24_entry) != 2); RTE_BUILD_BUG_ON(sizeof(struct rte_lpm_tbl8_entry) != 2); /* Check user arguments. */ if ((name == NULL) || (socket_id < -1) || (max_rules == 0)){ rte_errno = EINVAL; return NULL; } rte_snprintf(mem_name, sizeof(mem_name), "LPM_%s", name); /* Determine the amount of memory to allocate. */ mem_size = sizeof(*lpm) + (sizeof(lpm->rules_tbl[0]) * max_rules); rte_rwlock_write_lock(RTE_EAL_TAILQ_RWLOCK); /* guarantee there's no existing */ TAILQ_FOREACH(lpm, lpm_list, next) { if (strncmp(name, lpm->name, RTE_LPM_NAMESIZE) == 0) break; } if (lpm != NULL) goto exit; /* Allocate memory to store the LPM data structures. */ lpm = (struct rte_lpm *)rte_zmalloc_socket(mem_name, mem_size, CACHE_LINE_SIZE, socket_id); if (lpm == NULL) { RTE_LOG(ERR, LPM, "LPM memory allocation failed\n"); goto exit; } /* Save user arguments. */ lpm->max_rules = max_rules; rte_snprintf(lpm->name, sizeof(lpm->name), "%s", name); TAILQ_INSERT_TAIL(lpm_list, lpm, next); exit: rte_rwlock_write_unlock(RTE_EAL_TAILQ_RWLOCK); return lpm; }
/* * cuse_info is populated and used to register the cuse device. vhost_net_device_ops are * also passed when the device is registered in main.c. */ int register_cuse_device(const char *base_name, int index, struct vhost_net_device_ops const * const pops) { struct cuse_info cuse_info; char device_name[PATH_MAX] = ""; char char_device_name[PATH_MAX] = ""; const char *device_argv[] = { device_name }; char fuse_opt_dummy[] = FUSE_OPT_DUMMY; char fuse_opt_fore[] = FUSE_OPT_FORE; char fuse_opt_nomulti[] = FUSE_OPT_NOMULTI; char *fuse_argv[] = {fuse_opt_dummy, fuse_opt_fore, fuse_opt_nomulti}; if (access(cuse_device_name, R_OK | W_OK) < 0) { RTE_LOG(ERR, CONFIG, "Character device %s can't be accessed, maybe not exist\n", cuse_device_name); return -1; } /* * The device name is created. This is passed to QEMU so that it can register * the device with our application. The index allows us to have multiple instances * of userspace vhost which we can then add devices to separately. */ if (strncmp(base_name, default_cdev, PATH_MAX)!=0) { rte_snprintf(device_name, PATH_MAX, "DEVNAME=%s-%d", base_name, index); rte_snprintf(char_device_name, PATH_MAX, "/dev/%s-%d", base_name, index); } else { rte_snprintf(device_name, PATH_MAX, "DEVNAME=%s", base_name); rte_snprintf(char_device_name, PATH_MAX, "/dev/%s", base_name); } /* Check if device already exists. */ if (access(char_device_name, F_OK) != -1) { RTE_LOG(ERR, CONFIG, "Character device %s already exists\n", char_device_name); return -1; } memset(&cuse_info, 0, sizeof(cuse_info)); cuse_info.dev_major = default_major; cuse_info.dev_minor = default_minor + index; cuse_info.dev_info_argc = 1; cuse_info.dev_info_argv = device_argv; cuse_info.flags = CUSE_UNRESTRICTED_IOCTL; ops = pops; session = cuse_lowlevel_setup(3, fuse_argv, &cuse_info, &vhost_net_ops, 0, NULL); if (session == NULL) return -1; return 0; }
/* * Test that the app doesn't run without the -n flag. In all cases * should give an error and fail to run. * Since -n is not compulsory for MP, we instead use --no-huge and --no-shconf * flags. */ static int test_missing_n_flag(void) { char prefix[PATH_MAX], tmp[PATH_MAX]; if (get_current_prefix(tmp, sizeof(tmp)) == NULL) { printf("Error - unable to get current prefix!\n"); return -1; } rte_snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp); /* -n flag but no value */ const char *argv1[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n"}; /* No -n flag at all */ const char *argv2[] = { prgname, prefix, no_huge, no_shconf, "-c", "1"}; /* bad numeric value */ const char *argv3[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "e" }; /* out-of-range value */ const char *argv4[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "9" }; /* sanity test - check with good value */ const char *argv5[] = { prgname, prefix, no_huge, no_shconf, "-c", "1", "-n", "2" }; if (launch_proc(argv1) == 0 || launch_proc(argv2) == 0 || launch_proc(argv3) == 0 || launch_proc(argv4) == 0) { printf("Error - process ran without error when missing -n flag\n"); return -1; } if (launch_proc(argv5) != 0) { printf("Error - process did not run ok with valid num-channel value\n"); return -1; } return 0; }
/* * Test that the app runs with HPET, and without HPET */ static int test_no_hpet_flag(void) { char prefix[PATH_MAX], tmp[PATH_MAX]; if (get_current_prefix(tmp, sizeof(tmp)) == NULL) { printf("Error - unable to get current prefix!\n"); return -1; } rte_snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp); /* With --no-hpet */ const char *argv1[] = {prgname, prefix, mp_flag, no_hpet, "-c", "1", "-n", "2"}; /* Without --no-hpet */ const char *argv2[] = {prgname, prefix, mp_flag, "-c", "1", "-n", "2"}; if (launch_proc(argv1) != 0) { printf("Error - process did not run ok with --no-hpet flag\n"); return -1; } if (launch_proc(argv2) != 0) { printf("Error - process did not run ok without --no-hpet flag\n"); return -1; } return 0; }
void rte_memdump(const char * title, const void * buf, unsigned int len) { unsigned int i, out; const unsigned char *data = buf; char line[LINE_LEN]; if ( title ) printf("%s: ", title); line[0] = '\0'; for (i = 0, out = 0; i < len; i++) { // Make sure we do not overrun the line buffer length. if ( out >= (LINE_LEN - 4) ) { printf("%s", line); out = 0; line[out] = '\0'; } out += rte_snprintf(line+out, LINE_LEN - out, "%02x%s", (data[i] & 0xff), ((i+1) < len)? ":" : ""); } if ( out > 0 ) printf("%s", line); printf("\n"); fflush(stdout); }
/* * Test that the app doesn't run without the coremask flag. In all cases * should give an error and fail to run */ static int test_missing_c_flag(void) { char prefix[PATH_MAX], tmp[PATH_MAX]; if (get_current_prefix(tmp, sizeof(tmp)) == NULL) { printf("Error - unable to get current prefix!\n"); return -1; } rte_snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp); /* -c flag but no coremask value */ const char *argv1[] = { prgname, prefix, mp_flag, "-n", "3", "-c"}; /* No -c flag at all */ const char *argv2[] = { prgname, prefix, mp_flag, "-n", "3"}; /* bad coremask value */ const char *argv3[] = { prgname, prefix, mp_flag, "-n", "3", "-c", "error" }; /* sanity check of tests - valid coremask value */ const char *argv4[] = { prgname, prefix, mp_flag, "-n", "3", "-c", "1" }; if (launch_proc(argv1) == 0 || launch_proc(argv2) == 0 || launch_proc(argv3) == 0) { printf("Error - process ran without error when missing -c flag\n"); return -1; } if (launch_proc(argv4) != 0) { printf("Error - process did not run ok with valid coremask value\n"); return -1; } return 0; }
/* * Returns MAC address for port in a string */ static const char * get_printable_mac_addr(uint8_t port) { static const char err_address[] = "00:00:00:00:00:00"; static char addresses[RTE_MAX_ETHPORTS][sizeof(err_address)] = {{0}}; struct ether_addr mac = {{0}}; int ether_addr_len = sizeof(err_address) - NEWLINE_CHAR_OFFSET; int i = 0; int j = 0; if (unlikely(port >= RTE_MAX_ETHPORTS)) return err_address; /* first time run for this port so we populate addresses */ if (unlikely(addresses[port][0] == '\0')) { rte_eth_macaddr_get(port, &mac); while(j < NUM_BYTES_MAC_ADDR) { rte_snprintf(&addresses[port][0] + i, MAC_ADDR_STR_INT_L + NEWLINE_CHAR_OFFSET, "%02x:", mac.addr_bytes[j]); i += MAC_ADDR_STR_INT_L; j++; } /* Overwrite last ":" and null terminate the string */ addresses[port][ether_addr_len] = '\0'; } return addresses[port]; }
static int32_t get_num_hugepages(const char *subdir) { char path[PATH_MAX]; long unsigned num_pages = 0; const char *nr_hp_file; /* if secondary process, just look at the number of hugepages, * otherwise look at number of free hugepages */ if (internal_config.process_type == RTE_PROC_SECONDARY) nr_hp_file = "nr_hugepages"; else nr_hp_file = "free_hugepages"; rte_snprintf(path, sizeof(path), "%s/%s/%s", sys_dir_path, subdir, nr_hp_file); if (eal_parse_sysfs_value(path, &num_pages) < 0) return 0; if (num_pages == 0) RTE_LOG(WARNING, EAL, "No free hugepages reported in %s\n", subdir); return (int32_t)num_pages; }
/* test invalid parameters */ int test_parse_string_invalid_param(void) { cmdline_parse_token_string_t token; int result; char buf[CMDLINE_TEST_BUFSIZE]; memset(&token, 0, sizeof(token)); rte_snprintf(buf, sizeof(buf), "buffer"); /* test null token */ if (cmdline_get_help_string( NULL, buf, 0) != -1) { printf("Error: function accepted null token!\n"); return -1; } if (cmdline_complete_get_elt_string( NULL, 0, buf, 0) != -1) { printf("Error: function accepted null token!\n"); return -1; } if (cmdline_complete_get_nb_string(NULL) != -1) { printf("Error: function accepted null token!\n"); return -1; } if (cmdline_parse_string(NULL, buf, NULL) != -1) { printf("Error: function accepted null token!\n"); return -1; } /* test null buffer */ if (cmdline_complete_get_elt_string( (cmdline_parse_token_hdr_t*)&token, 0, NULL, 0) != -1) { printf("Error: function accepted null buffer!\n"); return -1; } if (cmdline_parse_string( (cmdline_parse_token_hdr_t*)&token, NULL, (void*)&result) != -1) { printf("Error: function accepted null buffer!\n"); return -1; } if (cmdline_get_help_string( (cmdline_parse_token_hdr_t*)&token, NULL, 0) != -1) { printf("Error: function accepted null buffer!\n"); return -1; } /* test null result */ if (cmdline_parse_string( (cmdline_parse_token_hdr_t*)&token, buf, NULL) == -1) { printf("Error: function rejected null result!\n"); return -1; } /* test negative index */ if (cmdline_complete_get_elt_string( (cmdline_parse_token_hdr_t*)&token, -1, buf, 0) != -1) { printf("Error: function accepted negative index!\n"); return -1; } return 0; }
static int str_to_unsigned_array( const char *s, size_t sbuflen, char separator, unsigned num_vals, unsigned *vals) { char str[sbuflen+1]; char *splits[num_vals]; char *endptr = NULL; int i, num_splits = 0; /* copy s so we don't modify original string */ rte_snprintf(str, sizeof(str), "%s", s); num_splits = rte_strsplit(str, sizeof(str), splits, num_vals, separator); errno = 0; for (i = 0; i < num_splits; i++) { vals[i] = strtoul(splits[i], &endptr, 0); if (errno != 0 || *endptr != '\0') return -1; } return num_splits; }
/* * Test that the app doesn't run with invalid -r option. */ static int test_invalid_r_flag(void) { char prefix[PATH_MAX], tmp[PATH_MAX]; if (get_current_prefix(tmp, sizeof(tmp)) == NULL) { printf("Error - unable to get current prefix!\n"); return -1; } rte_snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp); const char *rinval[][9] = { {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "error"}, {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "0"}, {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "-1"}, {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "17"}, }; /* Test with valid blacklist option */ const char *rval[] = {prgname, prefix, mp_flag, "-n", "1", "-c", "1", "-r", "16"}; int i; for (i = 0; i != sizeof (rinval) / sizeof (rinval[0]); i++) { if (launch_proc(rinval[i]) == 0) { printf("Error - process did run ok with invalid " "-r (rank) parameter\n"); return -1; } } if (launch_proc(rval) != 0) { printf("Error - process did not run ok with valid -r (rank) value\n"); return -1; } return 0; }
/* Get CPU socket id (NUMA node) by reading directory * /sys/devices/system/cpu/cpuX looking for symlink "nodeY" * which gives the NUMA topology information. * Note: physical package id != NUMA node, but we use it as a * fallback for kernels which don't create a nodeY link */ static unsigned cpu_socket_id(unsigned lcore_id) { const char node_prefix[] = "node"; const size_t prefix_len = sizeof(node_prefix) - 1; char path[PATH_MAX]; DIR *d; unsigned long id = 0; struct dirent *e; char *endptr = NULL; int len = rte_snprintf(path, sizeof(path), SYS_CPU_DIR, lcore_id); if (len <= 0 || (unsigned)len >= sizeof(path)) goto err; d = opendir(path); if (!d) goto err; while ((e = readdir(d)) != NULL) { if (strncmp(e->d_name, node_prefix, prefix_len) == 0) { id = strtoul(e->d_name+prefix_len, &endptr, 0); break; } } closedir(d); if (endptr == NULL || *endptr!='\0' || endptr == e->d_name+prefix_len) { RTE_LOG(ERR, EAL, "Error reading numa node link " "for lcore %u - using physical package id instead\n", lcore_id); len = rte_snprintf(path, sizeof(path), SYS_CPU_DIR "/%s", lcore_id, PHYS_PKG_FILE); if (len <= 0 || (unsigned)len >= sizeof(path)) goto err; if (eal_parse_sysfs_value(path, &id) != 0) goto err; } return (unsigned)id; err: RTE_LOG(ERR, EAL, "Error getting NUMA socket information from %s " "for lcore %u - assuming NUMA socket 0\n", SYS_CPU_DIR, lcore_id); return 0; }
/* * Given the tx queue name template above, get the queue name. */ static inline const char * get_tx_queue_name(unsigned id) { /* Buffer for return value. Size calculated by %u being replaced * by maximum 3 digits (plus an extra byte for safety). */ static char buffer[sizeof(MP_CLIENT_TXQ_NAME) + 2]; rte_snprintf(buffer, sizeof(buffer) - 1, MP_CLIENT_TXQ_NAME, id); return buffer; }
/* * It is deprecated and just for backward compatibility. */ struct rte_kni * rte_kni_info_get(uint8_t port_id) { char name[RTE_MEMZONE_NAMESIZE]; if (port_id >= RTE_MAX_ETHPORTS) return NULL; rte_snprintf(name, RTE_MEMZONE_NAMESIZE, "vEth%u", port_id); return rte_kni_get(name); }
/* Check if a cpu is present by the presence of the cpu information for it */ static int cpu_detected(unsigned lcore_id) { char path[PATH_MAX]; int len = rte_snprintf(path, sizeof(path), SYS_CPU_DIR "/"CORE_ID_FILE, lcore_id); if (len <= 0 || (unsigned)len >= sizeof(path)) return 0; if (access(path, F_OK) != 0) return 0; return 1; }
static char* get_current_prefix(char * prefix, int size) { char path[PATH_MAX] = {0}; char buf[PATH_MAX] = {0}; /* get file for config (fd is always 3) */ rte_snprintf(path, sizeof(path), "/proc/self/fd/%d", 3); /* return NULL on error */ if (readlink(path, buf, sizeof(buf)) == -1) return NULL; /* get the basename */ rte_snprintf(buf, sizeof(buf), "%s", basename(buf)); /* copy string all the way from second char up to start of _config */ rte_snprintf(prefix, size, "%.*s", strnlen(buf, sizeof(buf)) - sizeof("_config"), &buf[1]); return prefix; }
static int parse_portnuma_config(const char *q_arg) { char s[256]; const char *p, *p0 = q_arg; char *end; uint8_t i,port_id,socket_id; unsigned size; enum fieldnames { FLD_PORT = 0, FLD_SOCKET, _NUM_FLD }; unsigned long int_fld[_NUM_FLD]; char *str_fld[_NUM_FLD]; /* reset from value set at definition */ while ((p = strchr(p0,'(')) != NULL) { ++p; if((p0 = strchr(p,')')) == NULL) return -1; size = p0 - p; if(size >= sizeof(s)) return -1; rte_snprintf(s, sizeof(s), "%.*s", size, p); if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD) return -1; for (i = 0; i < _NUM_FLD; i++) { errno = 0; int_fld[i] = strtoul(str_fld[i], &end, 0); if (errno != 0 || end == str_fld[i] || int_fld[i] > 255) return -1; } port_id = (uint8_t)int_fld[FLD_PORT]; if (port_id >= nb_ports) { printf("Invalid port, range is [0, %d]\n", nb_ports - 1); return -1; } socket_id = (uint8_t)int_fld[FLD_SOCKET]; if(socket_id >= MAX_SOCKET) { printf("Invalid socket id, range is [0, %d]\n", MAX_SOCKET - 1); return -1; } port_numa[port_id] = socket_id; } return 0; }
/* if string contains a hugepage path */ static int get_hugepage_path(char * src, int src_len, char * dst, int dst_len) { #define NUM_TOKENS 4 char *tokens[NUM_TOKENS]; /* if we couldn't properly split the string */ if (rte_strsplit(src, src_len, tokens, NUM_TOKENS, ' ') < NUM_TOKENS) return 0; if (strncmp(tokens[2], "hugetlbfs", sizeof("hugetlbfs")) == 0) { rte_snprintf(dst, dst_len, "%s", tokens[1]); return 1; } return 0; }
void init_ring(int lcore_id, uint8_t port_id) { struct rte_ring *ring; char ring_name[RTE_RING_NAMESIZE]; rte_snprintf(ring_name, RTE_RING_NAMESIZE, "core%d_port%d", lcore_id, port_id); ring = rte_ring_create(ring_name, RING_SIZE, rte_socket_id(), RING_F_SP_ENQ | RING_F_SC_DEQ); if (ring == NULL) rte_exit(EXIT_FAILURE, "%s\n", rte_strerror(rte_errno)); rte_ring_set_water_mark(ring, 80 * RING_SIZE / 100); rings[lcore_id][port_id] = ring; }
const char * rte_strerror(int errnum) { #define RETVAL_SZ 256 static RTE_DEFINE_PER_LCORE(char[RETVAL_SZ], retval); /* since some implementations of strerror_r throw an error * themselves if errnum is too big, we handle that case here */ if (errnum > RTE_MAX_ERRNO) rte_snprintf(RTE_PER_LCORE(retval), RETVAL_SZ, #ifdef RTE_EXEC_ENV_BSDAPP "Unknown error: %d", errnum); #else "Unknown error %d", errnum); #endif else switch (errnum){
static const struct rte_memzone * gpa_zone_reserve(struct rte_eth_dev *dev, uint32_t size, const char *post_string, int socket_id, uint16_t align) { char z_name[RTE_MEMZONE_NAMESIZE]; const struct rte_memzone *mz; rte_snprintf(z_name, sizeof(z_name), "%s_%d_%s", dev->driver->pci_drv.name, dev->data->port_id, post_string); mz = rte_memzone_lookup(z_name); if (mz) return mz; return rte_memzone_reserve_aligned(z_name, size, socket_id, 0, align); }
static const char * get_printable_mac_addr(uint8_t port) { static const char err_address[] = "00:00:00:00:00:00"; static char addresses[RTE_MAX_ETHPORTS][sizeof(err_address)]; if (unlikely(port >= RTE_MAX_ETHPORTS)) return err_address; if (unlikely(addresses[port][0]=='\0')){ struct ether_addr mac; rte_eth_macaddr_get(port, &mac); rte_snprintf(addresses[port], sizeof(addresses[port]), "%02x:%02x:%02x:%02x:%02x:%02x\n", mac.addr_bytes[0], mac.addr_bytes[1], mac.addr_bytes[2], mac.addr_bytes[3], mac.addr_bytes[4], mac.addr_bytes[5]); } return addresses[port]; }
/* Get the cpu core id value from the /sys/.../cpuX core_id value */ static unsigned cpu_core_id(unsigned lcore_id) { char path[PATH_MAX]; unsigned long id; int len = rte_snprintf(path, sizeof(path), SYS_CPU_DIR "/%s", lcore_id, CORE_ID_FILE); if (len <= 0 || (unsigned)len >= sizeof(path)) goto err; if (eal_parse_sysfs_value(path, &id) != 0) goto err; return (unsigned)id; err: RTE_LOG(ERR, EAL, "Error reading core id value from %s " "for lcore %u - assuming core 0\n", SYS_CPU_DIR, lcore_id); return 0; }
/* returns total number of cores presented in a system */ static uint32_t app_cpu_core_count(void) { int i, len; char path[PATH_MAX]; uint32_t ncores = 0; for(i = 0; i < RTE_MAX_LCORE; i++) { len = rte_snprintf(path, sizeof(path), SYS_CPU_DIR, i); if (len <= 0 || (unsigned)len >= sizeof(path)) continue; if (access(path, F_OK) == 0) ncores++; } return ncores; }
/* * Test that the app runs with --no-huge and doesn't run when either * -m or --socket-mem are specified with --no-huge. */ static int test_no_huge_flag(void) { char prefix[PATH_MAX], tmp[PATH_MAX]; if (get_current_prefix(tmp, sizeof(tmp)) == NULL) { printf("Error - unable to get current prefix!\n"); return -1; } rte_snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp); /* With --no-huge */ const char *argv1[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2", "--file-prefix=nohuge"}; /* With --no-huge and -m */ const char *argv2[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2", "-m", "2", "--file-prefix=nohuge"}; /* With --no-huge and --socket-mem */ const char *argv3[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2", "--socket-mem=2", "--file-prefix=nohuge"}; /* With --no-huge, -m and --socket-mem */ const char *argv4[] = {prgname, prefix, no_huge, "-c", "1", "-n", "2", "-m", "2", "--socket-mem=2", "--file-prefix=nohuge"}; if (launch_proc(argv1) != 0) { printf("Error - process did not run ok with --no-huge flag\n"); return -1; } if (launch_proc(argv2) == 0) { printf("Error - process run ok with --no-huge and -m flags\n"); return -1; } if (launch_proc(argv3) == 0) { printf("Error - process run ok with --no-huge and --socket-mem " "flags\n"); return -1; } if (launch_proc(argv4) == 0) { printf("Error - process run ok with --no-huge, -m and " "--socket-mem flags\n"); return -1; } return 0; }
static struct rte_sched_port * app_init_sched_port(uint32_t portid, uint32_t socketid) { static char port_name[32]; /* static as referenced from global port_params*/ struct rte_eth_link link; struct rte_sched_port *port = NULL; uint32_t pipe, subport; int err; rte_eth_link_get((uint8_t)portid, &link); port_params.socket = socketid; port_params.rate = (uint64_t) link.link_speed * 1000 * 1000 / 8; rte_snprintf(port_name, sizeof(port_name), "port_%d", portid); port_params.name = port_name; port = rte_sched_port_config(&port_params); if (port == NULL){ rte_exit(EXIT_FAILURE, "Unable to config sched port\n"); } for (subport = 0; subport < port_params.n_subports_per_port; subport ++) { err = rte_sched_subport_config(port, subport, &subport_params[subport]); if (err) { rte_exit(EXIT_FAILURE, "Unable to config sched subport %u, err=%d\n", subport, err); } for (pipe = 0; pipe < port_params.n_pipes_per_subport; pipe ++) { if (app_pipe_to_profile[subport][pipe] != -1) { err = rte_sched_pipe_config(port, subport, pipe, app_pipe_to_profile[subport][pipe]); if (err) { rte_exit(EXIT_FAILURE, "Unable to config sched pipe %u " "for profile %d, err=%d\n", pipe, app_pipe_to_profile[subport][pipe], err); } } } } return port; }
struct rte_kni * rte_kni_get(const char *name) { struct rte_kni *kni; const struct rte_memzone *mz; char mz_name[RTE_MEMZONE_NAMESIZE]; if (!name || !name[0]) return NULL; rte_snprintf(mz_name, RTE_MEMZONE_NAMESIZE, "KNI_INFO_%s", name); mz = rte_memzone_lookup(mz_name); if (!mz) return NULL; kni = mz->addr; if (!kni->in_use) return NULL; return kni; }
static void app_init_mbuf_pools(void) { uint32_t socket, lcore; /* Init the buffer pools */ for (socket = 0; socket < APP_MAX_SOCKETS; socket ++) { char name[32]; if (app_is_socket_used(socket) == 0) { continue; } rte_snprintf(name, sizeof(name), "mbuf_pool_%u", socket); printf("Creating the mbuf pool for socket %u ...\n", socket); app.pools[socket] = rte_mempool_create( name, APP_DEFAULT_MEMPOOL_BUFFERS, APP_DEFAULT_MBUF_SIZE, APP_DEFAULT_MEMPOOL_CACHE_SIZE, sizeof(struct rte_pktmbuf_pool_private), rte_pktmbuf_pool_init, NULL, rte_pktmbuf_init, NULL, socket, 0); if (app.pools[socket] == NULL) { rte_panic("Cannot create mbuf pool on socket %u\n", socket); } } for (lcore = 0; lcore < APP_MAX_LCORES; lcore ++) { if (app.lcore_params[lcore].type == e_APP_LCORE_DISABLED) { continue; } socket = rte_lcore_to_socket_id(lcore); app.lcore_params[lcore].pool = app.pools[socket]; } }