diff options
| author | Qiuwen Lu <[email protected]> | 2016-09-14 16:54:59 +0800 |
|---|---|---|
| committer | Qiuwen Lu <[email protected]> | 2016-09-14 16:54:59 +0800 |
| commit | f17959305de8b96f1a666ca7ca801ae1125ada71 (patch) | |
| tree | 47f23109a520ac6b6bd143d20fa9fe755ef6f2be | |
| parent | 4782c14d52af2fe4e4f153b5b5b9f44f7561e3ee (diff) | |
增加性能分析使用的运行Cycles记录功能
| -rw-r--r-- | CMakeLists.txt | 1 | ||||
| -rw-r--r-- | core/include/mr_stat.h | 42 | ||||
| -rw-r--r-- | core/src/stat.c | 7 | ||||
| -rw-r--r-- | pag/libpag.c | 10 | ||||
| -rw-r--r-- | service/src/rxtx.c | 14 |
5 files changed, 68 insertions, 6 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index db8bc9f..f7fe045 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,6 +31,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CXX_FLAGS}") # Default Install Destination Directory #set(CMAKE_INSTALL_PREFIX /opt/iiesoft/marsio) add_definitions(-fPIC) +add_definitions(-D_GNU_SOURCE) add_subdirectory(${CMAKE_SOURCE_DIR}/support ${CMAKE_BINARY_DIR}/support) add_subdirectory(${CMAKE_SOURCE_DIR}/core) diff --git a/core/include/mr_stat.h b/core/include/mr_stat.h index bafcb33..9a20194 100644 --- a/core/include/mr_stat.h +++ b/core/include/mr_stat.h @@ -1,6 +1,7 @@ #pragma once #include <rte_config.h> +#include <rte_cycles.h> #include <rte_memory.h> #include <mr_ctx.h> #include <rte_mbuf.h> @@ -50,9 +51,29 @@ struct mr_app_stat } __per_app[MR_APP_MAX]; }; +struct mr_perf_item +{ + volatile uint64_t begin; + volatile uint64_t runtime; + volatile uint64_t cycles; +}; + +struct mr_perf_stat +{ + struct + { + struct mr_perf_item sc_rx_loop_all; + struct mr_perf_item sc_rx_loop_eth_rx_burst; + struct mr_perf_item sc_rx_loop_hash_calc; + struct mr_perf_item sc_rx_loop_dispatch; + struct mr_perf_item pag_get_frame; + struct mr_perf_item pag_get; + } __rte_cache_aligned _per_thread[MR_MAX_GSID]; +}; extern struct mr_vnode_stat * mr_vnode_stat_get(); extern struct mr_device_stat * mr_device_stat_get(); +extern struct mr_perf_stat * mr_perf_stat_get(); #define UPDATE_DEV_STAT(_s, _p, _n) \ do { \ @@ -66,6 +87,27 @@ do { \ if(st) st->_per_thread[mr_thread_id()]._s += _n; \ }while(0) \ +#define PERF_BEGIN(_s) \ +do { \ + struct mr_perf_stat * st = mr_perf_stat_get(); \ + uint64_t _tsc = rte_rdtsc(); \ + if(st) st->_per_thread[mr_thread_id()]._s.begin = _tsc; \ +}while(0) \ + + +#define PERF_END(_s) \ +do { \ + struct mr_perf_stat * st = mr_perf_stat_get(); \ + if(st) \ + { \ + thread_id_t _tid = mr_thread_id(); \ + uint64_t _tsc = rte_rdtsc(); \ + uint64_t _begin = st->_per_thread[_tid]._s.begin; \ + uint64_t _delta = _tsc - _begin; \ + st->_per_thread[_tid]._s.runtime += _delta; \ + st->_per_thread[_tid]._s.cycles++; \ + } \ +} while(0) \ // Tools Functions static inline int pktslen(struct rte_mbuf * mbufs[], unsigned nr_mbufs) diff --git a/core/src/stat.c b/core/src/stat.c index 9295193..cd36101 100644 --- a/core/src/stat.c +++ b/core/src/stat.c @@ -17,6 +17,7 @@ struct stat_ctx unsigned int vnode_stat_enable; struct mr_device_stat device_stat_handle; struct mr_vnode_stat vnode_stat_handle; + struct mr_perf_stat perf_stat_handle; }; static struct stat_ctx * module_ctx; @@ -34,6 +35,12 @@ struct mr_vnode_stat * mr_vnode_stat_get() return &module_ctx->vnode_stat_handle; } +struct mr_perf_stat * mr_perf_stat_get() +{ + //TODO: ���ÿ��� + return &module_ctx->perf_stat_handle; +} + static int stat_preinit(struct mr_module * m_desc, struct mr_config * g_cfg, struct mr_global_ctx * g_ctx) { diff --git a/pag/libpag.c b/pag/libpag.c index 6f8aedf..3233949 100644 --- a/pag/libpag.c +++ b/pag/libpag.c @@ -6,15 +6,15 @@ #include <unistd.h>
#include <assert.h>
+#include <netinet/in.h>
#include <rte_string_fns.h>
#include <rte_ether.h>
#include <MESA_prof_load.h>
#include <mr_common.h>
#include <mr_rawio.h>
+#include <mr_stat.h>
#include <mrlib.h>
-
#include "libpag.h"
-#include <netinet/in.h>
struct pag_instance
{
@@ -125,6 +125,8 @@ int pag_open() return 0;
}
+//TODO: �ձ��ķ�ʽ�Ľ�����������һ�����ػ�������
+//TODO: ��һ��rtdevice����n���������ϲ�ȡ�á�
void * pag_get_frame(int sid __rte_unused)
{
if (unlikely(__pag_thread_inited == 0))
@@ -132,7 +134,8 @@ void * pag_get_frame(int sid __rte_unused) mrlib_thread_init();
__pag_thread_inited = 1;
}
-
+
+ PERF_BEGIN(pag_get_frame);
struct pag_thread_instance * tinstance = &thread_instance_;
struct pag_instance * instance = &pag_config_;
@@ -149,6 +152,7 @@ void * pag_get_frame(int sid __rte_unused) int ret = marsio_raw_recv(instance->raw_sockets[cur_socket], &tinstance->rxmbuf, 1);
tinstance->cur_socket = (cur_socket + 1) % instance->nr_raw_sockets;
+ PERF_END(pag_get_frame);
if (ret != 1) return NULL;
return rte_pktmbuf_mtod(tinstance->rxmbuf, void *);
}
diff --git a/service/src/rxtx.c b/service/src/rxtx.c index 303c330..e8b8c68 100644 --- a/service/src/rxtx.c +++ b/service/src/rxtx.c @@ -23,13 +23,16 @@ void sc_thread_rx_loop(struct sc_instance * instance, hash_t hash_result[MR_BURST_MAX]; int nr_rx_burst = instance->sz_rx_burst; - for(int i =0; i < tinstance->nr_devices; i++) + PERF_BEGIN(sc_rx_loop_all); + for(unsigned int i =0; i < tinstance->nr_devices; i++) { mr_devq_t * devq; devq = tinstance->rt_dev[i].devq; - int nr_rx_bufs = rte_eth_rx_burst(devq->port_id, + PERF_BEGIN(sc_rx_loop_eth_rx_burst); + uint16_t nr_rx_bufs = rte_eth_rx_burst(devq->port_id, devq->rx_queue_id, rx_bufs, nr_rx_burst); + PERF_END(sc_rx_loop_eth_rx_burst); // û�����ݰ�ֱ������ if (unlikely(nr_rx_bufs == 0)) continue; @@ -38,16 +41,21 @@ void sc_thread_rx_loop(struct sc_instance * instance, UPDATE_DEV_STAT(dev_rx_bit, devq->port_id, pktslen(rx_bufs, nr_rx_bufs)); // �������ݰ����طֵ�ʹ�õ�Hashֵ + PERF_BEGIN(sc_rx_loop_hash_calc); distributer_hash_caculate(instance->distmode, rx_bufs, nr_rx_bufs, hash_result); + PERF_END(sc_rx_loop_hash_calc); // ����VNode�У��ַ�����Ӧ�� struct vnodeman_attach_desc * attach_desc; attach_desc = tinstance->rt_dev[i].rxvnode_desc; + PERF_BEGIN(sc_rx_loop_dispatch); vnode_enqueue_burst_with_hash(attach_desc->prod, &vnodeman_ops, attach_desc->queue_id, (void **)rx_bufs, hash_result, nr_rx_bufs); + PERF_END(sc_rx_loop_dispatch); } - + + PERF_END(sc_rx_loop_all); return; } |
