diff options
| author | Qiuwen Lu <[email protected]> | 2017-09-22 20:02:06 +0800 |
|---|---|---|
| committer | Qiuwen Lu <[email protected]> | 2017-09-22 20:02:06 +0800 |
| commit | 493696b853a72a7ba3f6c8a6c0c64ca65f34dd2e (patch) | |
| tree | 257f2fb1f86235c0a0d7ee62cd410a6478e2faf3 | |
| parent | a9f17b9de38f0b8a37c143b0d2a1a4a76ff85b1b (diff) | |
报文时间戳功能改进、增加延迟测量等功能;v4.2.21-20170922
- 用clock_gettime()函数替换rdtsc()测量时间,避免跨核心导致rdtsc基线时间不一致;
- 增加报文延迟测量功能
| -rw-r--r-- | app/src/mrb.c | 2 | ||||
| -rw-r--r-- | service/include/sc_common.h | 8 | ||||
| -rw-r--r-- | service/src/core.c | 54 | ||||
| -rw-r--r-- | service/src/fwd.c | 25 |
4 files changed, 77 insertions, 12 deletions
diff --git a/app/src/mrb.c b/app/src/mrb.c index 1353986..f247e51 100644 --- a/app/src/mrb.c +++ b/app/src/mrb.c @@ -508,7 +508,7 @@ uint64_t marsio_buff_get_timestamp(marsio_buff_t *m) } void marsio_buff_set_timestamp(marsio_buff_t *m, uint64_t timestamp) -{
+{ struct rte_mbuf * __m = (struct rte_mbuf *)m; __m->timestamp = timestamp; }
\ No newline at end of file diff --git a/service/include/sc_common.h b/service/include/sc_common.h index 56b9a5c..fc076e2 100644 --- a/service/include/sc_common.h +++ b/service/include/sc_common.h @@ -64,8 +64,14 @@ struct sc_main unsigned int en_spinlock_check; /* 异常状态检测标志位,内存泄露检测 */ unsigned int en_memleak_check; - /* 报文处理延迟监测 */ + /* 软件报文时间戳 */ unsigned int en_pkt_timestamp; + /* 捕包支持 */ + unsigned int en_pkt_dumper; + /* 延迟统计 */ + unsigned int en_pkt_latency; + /* 延迟统计核心 */ + unsigned int pkt_latency_lcore_id; /* 负载均衡器 */ struct distributer * dist_object; diff --git a/service/src/core.c b/service/src/core.c index 1e9530e..87180ae 100644 --- a/service/src/core.c +++ b/service/src/core.c @@ -10,6 +10,7 @@ #include <rte_malloc.h> #include <rte_launch.h> #include <rte_pdump.h> +#include <rte_latencystats.h> #include <MESA_prof_load.h> #include <sc_common.h> @@ -81,6 +82,17 @@ const char service_git_version[] = ""; #define MR_SERVICE_DEFAULT_PKT_TIMESTAMP 0 #endif +#ifndef MR_SERVICE_DEFAULT_PKT_DUMPER +#define MR_SERVICE_DEFAULT_PKT_DUMPER 1 +#endif + +#ifndef MR_SERVICE_DEFAULT_PKT_LATENCY +#define MR_SERVICE_DEFAULT_PKT_LATENCY 0 +#endif + +#ifndef MR_SERVICE_DEFAULT_PKT_LATENCY_LCORE_ID +#define MR_SERVICE_DEFAULT_PKT_LATENCY_LCORE_ID 0 +#endif unsigned int g_logger_to_stdout = 1; unsigned int g_logger_level = LOG_DEBUG; @@ -214,6 +226,16 @@ int sc_dataplane_thread(void * arg) idle_counter++; sw_forward_rxtx_loop(sc_main, lcore_id); + +#if MR_SERVICE_DEFAULT_PKT_LATENCY + if (likely(sc_main->en_pkt_latency) +#else + if(unlikely(sc_main->en_pkt_latency) +#endif + && lcore_id == sc_main->pkt_latency_lcore_id) + { + rte_latencystats_update(); + } } return 0; @@ -430,10 +452,22 @@ static int sc_g_config_init(struct sc_main * sc) MESA_load_profile_uint_def(sc->local_cfgfile, "keepalive", "check_memleak", &sc->en_memleak_check, MR_SERVICE_DEFAULT_CHECK_MEMLEAK); - /* 报文时间戳选项,监测报文处理延迟 */ - MESA_load_profile_uint_def(sc->local_cfgfile, "service", "en_pkt_timestamp", + /* 报文捕获 */ + MESA_load_profile_uint_def(sc->local_cfgfile, "debug", "pkt_dumper", + &sc->en_pkt_dumper, MR_SERVICE_DEFAULT_PKT_DUMPER); + + /* 报文时间戳 */ + MESA_load_profile_uint_def(sc->local_cfgfile, "debug", "pkt_timestamp", &sc->en_pkt_timestamp, MR_SERVICE_DEFAULT_PKT_TIMESTAMP); - + + /* 报文延迟统计 */ + MESA_load_profile_uint_def(sc->local_cfgfile, "debug", "pkt_latency", + &sc->en_pkt_latency, MR_SERVICE_DEFAULT_PKT_LATENCY); + + /* 报文延迟统计核心 */ + MESA_load_profile_uint_def(sc->local_cfgfile, "debug", "pkt_latency_lcore_id", + &sc->pkt_latency_lcore_id, MR_SERVICE_DEFAULT_PKT_LATENCY); + return RT_SUCCESS; } @@ -726,6 +760,20 @@ int main(int argc, char * argv[]) ret = EXIT_FAILURE; goto quit; } + rte_metrics_init(SOCKET_ID_ANY); + + /* 延迟监测 */ + if (sc->en_pkt_latency) + { + ret = rte_latencystats_init(1, NULL); + } + + if (sc->en_pkt_latency && ret != 0) + { + MR_ERROR("Lantency stats module init failed, ret = %d", ret); + ret = EXIT_FAILURE; goto quit; + } + unsigned int lcore_id; RTE_LCORE_FOREACH_SLAVE(lcore_id) { diff --git a/service/src/fwd.c b/service/src/fwd.c index 6b7af5f..f4a7949 100644 --- a/service/src/fwd.c +++ b/service/src/fwd.c @@ -67,6 +67,23 @@ struct sw_forward_main unsigned int nr_fwd_rule; }; +#include <sys/time.h> + +void timestamp_caculate(struct sc_main * sc, struct rte_mbuf * mbufs[], unsigned int nr_mbufs) +{ + if (!sc->en_pkt_timestamp) return; + + struct timespec __timespec; + clock_gettime(CLOCK_MONOTONIC, &__timespec); + + uint64_t __timespec_conv = *(uint64_t *)&__timespec.tv_nsec; + for (int i = 0; i < nr_mbufs; i++) + { + mbufs[i]->timestamp = __timespec_conv; + } + + return; +} void sw_forward_pp(struct sc_main * sc, struct fwd_rule * fwd_rule, unsigned int lcore_id) { @@ -114,7 +131,6 @@ void sw_forward_vv(struct sc_main * sc, struct fwd_rule * fwd_rule, unsigned int return; } - void sw_forward_pv(struct sc_main * sc, struct fwd_rule * fwd_rule, unsigned int lcore_id) { struct rte_mbuf * mbufs[MR_BURST_MAX]; @@ -128,12 +144,7 @@ void sw_forward_pv(struct sc_main * sc, struct fwd_rule * fwd_rule, unsigned int unsigned int rx_nr_mbufs = rte_eth_rx_burst(phydev_from->port_id, local_rxq_id, mbufs, nr_rx_burst); if (unlikely(rx_nr_mbufs == 0)) return; - /* 报文时间戳 */ - if (unlikely(sc->en_pkt_timestamp)) - { - for (int i = 0; i < rx_nr_mbufs; i++) mbufs[i]->timestamp = rte_rdtsc(); - } - + timestamp_caculate(sc, mbufs, rx_nr_mbufs); distributer_caculate(sc->dist_object, mbufs, rx_nr_mbufs); vdev_dispatch(vdev_to, local_txq_id, mbufs, rx_nr_mbufs, 0); return; |
