mirror of https://github.com/F-Stack/f-stack.git
add "idle_sleep" to reduce CPU usage when no pkts incomming.
This commit is contained in:
parent
e4983a3d6a
commit
c605f59579
|
@ -9,6 +9,10 @@ tso=0
|
|||
## HW vlan strip, default: enabled.
|
||||
vlan_strip=1
|
||||
|
||||
# sleep when no pkts incomming
|
||||
# unit: microseconds
|
||||
idle_sleep=100
|
||||
|
||||
# enabled port list
|
||||
#
|
||||
# EBNF grammar:
|
||||
|
|
|
@ -297,7 +297,7 @@ __parse_config_list(uint16_t *arr, int *sz, const char *value) {
|
|||
}
|
||||
}
|
||||
if (nr_ele <= 0) {
|
||||
printf("list %s is empty\n", value);
|
||||
fprintf(stderr, "list %s is empty\n", value);
|
||||
return 1;
|
||||
}
|
||||
sort_uint16_array(arr, nr_ele);
|
||||
|
@ -430,6 +430,8 @@ ini_parse_handler(void* user, const char* section, const char* name,
|
|||
pconfig->dpdk.tso = atoi(value);
|
||||
} else if (MATCH("dpdk", "vlan_strip")) {
|
||||
pconfig->dpdk.vlan_strip = atoi(value);
|
||||
} else if (MATCH("dpdk", "idle_sleep")) {
|
||||
pconfig->dpdk.idle_sleep = atoi(value);
|
||||
} else if (MATCH("kni", "enable")) {
|
||||
pconfig->kni.enable= atoi(value);
|
||||
} else if (MATCH("kni", "method")) {
|
||||
|
|
|
@ -31,8 +31,8 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
// dpdk argc, argv, max argc: 4, member of dpdk_config
|
||||
#define DPDK_CONFIG_NUM 4
|
||||
// dpdk argc, argv, max argc: 16, member of dpdk_config
|
||||
#define DPDK_CONFIG_NUM 16
|
||||
#define DPDK_CONFIG_MAXLEN 64
|
||||
#define DPDK_MAX_LCORE 128
|
||||
|
||||
|
@ -88,12 +88,16 @@ struct ff_config {
|
|||
int numa_on;
|
||||
int tso;
|
||||
int vlan_strip;
|
||||
|
||||
/* sleep x microseconds when no pkts incomming */
|
||||
unsigned idle_sleep;
|
||||
|
||||
/* list of proc-lcore */
|
||||
uint16_t *proc_lcore;
|
||||
|
||||
int nb_ports;
|
||||
uint16_t *portid_list;
|
||||
uint16_t max_portid;
|
||||
uint16_t *portid_list;
|
||||
// MAP(portid => struct ff_port_cfg*)
|
||||
struct ff_port_cfg *port_cfgs;
|
||||
} dpdk;
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
*
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <rte_common.h>
|
||||
#include <rte_byteorder.h>
|
||||
|
@ -98,6 +99,8 @@ static int kni_accept;
|
|||
|
||||
static int numa_on;
|
||||
|
||||
static unsigned idle_sleep;
|
||||
|
||||
static struct rte_timer freebsd_clock;
|
||||
|
||||
// Mellanox Linux's driver key
|
||||
|
@ -821,6 +824,8 @@ ff_dpdk_init(int argc, char **argv)
|
|||
|
||||
numa_on = ff_global_cfg.dpdk.numa_on;
|
||||
|
||||
idle_sleep = ff_global_cfg.dpdk.idle_sleep;
|
||||
|
||||
init_lcore_conf();
|
||||
|
||||
init_mem_pool();
|
||||
|
@ -1429,7 +1434,7 @@ main_loop(void *arg)
|
|||
struct loop_routine *lr = (struct loop_routine *)arg;
|
||||
|
||||
struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
|
||||
uint64_t prev_tsc, diff_tsc, cur_tsc, usch_tsc, div_tsc, usr_tsc, sys_tsc, end_tsc;
|
||||
uint64_t prev_tsc, diff_tsc, cur_tsc, usch_tsc, div_tsc, usr_tsc, sys_tsc, end_tsc, idle_sleep_tsc;
|
||||
int i, j, nb_rx, idle;
|
||||
uint16_t port_id, queue_id;
|
||||
struct lcore_conf *qconf;
|
||||
|
@ -1524,10 +1529,18 @@ main_loop(void *arg)
|
|||
lr->loop(lr->arg);
|
||||
}
|
||||
|
||||
idle_sleep_tsc = rte_rdtsc();
|
||||
if (likely(idle && idle_sleep)) {
|
||||
usleep(idle_sleep);
|
||||
end_tsc = rte_rdtsc();
|
||||
} else {
|
||||
end_tsc = idle_sleep_tsc;
|
||||
}
|
||||
|
||||
end_tsc = rte_rdtsc();
|
||||
|
||||
if (usch_tsc == cur_tsc) {
|
||||
usr_tsc = end_tsc - div_tsc;
|
||||
usr_tsc = idle_sleep_tsc - div_tsc;
|
||||
}
|
||||
|
||||
if (!idle) {
|
||||
|
|
Loading…
Reference in New Issue