diff options
| author | Qiuwen Lu <[email protected]> | 2016-12-06 11:12:29 +0800 |
|---|---|---|
| committer | Qiuwen Lu <[email protected]> | 2016-12-06 11:12:29 +0800 |
| commit | ad5279a1b6024e64545bf51200bd1e74c0907474 (patch) | |
| tree | c601cabf5c7634bfdb96a399a45ef48a7c1f2c01 /pag | |
| parent | 30f8b8f39815dcfbd50eb62d6f04df5eba909945 (diff) | |
许多改动,修正了很多问题。
Diffstat (limited to 'pag')
| -rw-r--r-- | pag/CMakeLists.txt | 4 | ||||
| -rw-r--r-- | pag/libpag.c | 127 |
2 files changed, 75 insertions, 56 deletions
diff --git a/pag/CMakeLists.txt b/pag/CMakeLists.txt index 5911903..46e1bc8 100644 --- a/pag/CMakeLists.txt +++ b/pag/CMakeLists.txt @@ -6,8 +6,8 @@ include_directories(${DPDK_INCLUDE_DIR}) add_definitions(${DPDK_C_PREDEFINED})
add_library(pag SHARED libpag.c)
-target_link_libraries(pag MESA_prof_load_static marsio core)
-target_link_libraries(pag rt pthread dl core)
+target_link_libraries(pag MESA_prof_load_static marsio)
+target_link_libraries(pag rt pthread dl)
set_target_properties(pag PROPERTIES LINK_FLAGS "-Wl,--version-script=${CMAKE_CURRENT_LIST_DIR}/version.map")
target_include_directories(pag INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}")
diff --git a/pag/libpag.c b/pag/libpag.c index 0a13912..d660c0c 100644 --- a/pag/libpag.c +++ b/pag/libpag.c @@ -4,24 +4,30 @@ * Date : 2016-09-12
*/
+#include <stdio.h>
#include <unistd.h>
+#include <stdlib.h>
#include <assert.h>
#include <netinet/in.h>
-#include <rte_string_fns.h>
-#include <rte_ether.h>
#include <MESA_prof_load.h>
+
+#include <rte_ether.h>
#include <mr_common.h>
-#include <mr_rawio.h>
-#include <mr_stat.h>
-#include <mrlib.h>
-#include <mr_mask.h>
+#include <marsio.h>
+
#include "libpag.h"
+#define PAG_SYMBOL_MAX 64
+#define PAG_STRING_MAX 1024
+#define PAG_BURST_MAX 64
+#define PAG_DEVICE_MAX 16
+#define PAG_CPU_ID_MAX 64
+
struct pag_instance
{
- char app_name[MR_SYMBOL_MAX];
- char dev_name[MR_STRING_MAX];
- raw_socket_t * raw_sockets[MR_DEVICE_MAX];
+ char app_name[PAG_SYMBOL_MAX];
+ char dev_name[PAG_STRING_MAX];
+ raw_socket_t * raw_sockets[PAG_DEVICE_MAX];
unsigned int nr_raw_sockets;
unsigned int nr_rx_stream;
unsigned int nr_tx_stream;
@@ -34,8 +40,8 @@ struct pag_instance struct pag_thread_instance
{
int thread_inited;
- struct rte_mbuf * rxmbuf[MR_BURST_MAX];
- struct rte_mbuf * txmbuf[MR_BURST_MAX];
+ marsio_buff_t * rxmbuf[PAG_BURST_MAX];
+ marsio_buff_t * txmbuf[PAG_BURST_MAX];
unsigned int rxmbuf_max;
unsigned int txmbuf_max;
unsigned int rxmbuf_used;
@@ -45,7 +51,7 @@ struct pag_thread_instance unsigned int cur_socket;
// ���������
- struct rte_mbuf * rxmbuf_ctx;
+ marsio_buff_t * rxmbuf_ctx;
};
static int __pag_inited = 0;
@@ -63,6 +69,33 @@ do { \ #define PAG_DEFAULT_TX_BURST 32
#define PAG_DEFAULT_AUTOEXIT 0
+int __strsplit(char *string, int stringlen, char **tokens, int maxtokens, char delim)
+{
+ int i, tok = 0;
+ int tokstart = 1; /* first token is right at start of string */
+
+ if (string == NULL || tokens == NULL)
+ goto einval_error;
+
+ for (i = 0; i < stringlen; i++) {
+ if (string[i] == '\0' || tok >= maxtokens)
+ break;
+ if (tokstart) {
+ tokstart = 0;
+ tokens[tok++] = &string[i];
+ }
+ if (string[i] == delim) {
+ string[i] = '\0';
+ tokstart = 1;
+ }
+ }
+ return tok;
+
+einval_error:
+ errno = EINVAL;
+ return -1;
+}
+
static int pag_config_load_app_info(struct pag_instance * instance)
{
int ret = MESA_load_profile_string_nodef(PAG_CFGFILE, "pag", "app_name",
@@ -79,31 +112,28 @@ static int pag_config_load_app_info(struct pag_instance * instance) static int pag_config_load_stream_info(struct pag_instance * instance)
{
- uint64_t coremask = 0;
- char * str_coremask_ptr = NULL;
- char str_coremask[MR_STRING_MAX];
-
- // ��CPU��������
- int ret = MESA_load_profile_string_nodef(PAG_CFGFILE, "pag", "coremask",
- str_coremask, sizeof(str_coremask));
-
- if(ret < 0)
+ unsigned int cpu_id_range[PAG_CPU_ID_MAX] = { 0 };
+
+ // ��CPU�����
+ int cpu_id_count = MESA_load_profile_uint_range(PAG_CFGFILE, "pag", "cpu_id",
+ PAG_CPU_ID_MAX, cpu_id_range);
+
+ if (cpu_id_count < 0)
{
- PAG_LOG("coremask is missing, please recheck %s", PAG_CFGFILE);
+ PAG_LOG("cpu_id is missing, please recheck %s", PAG_CFGFILE);
return -1;
}
-
- coremask = strtoull(str_coremask, &str_coremask_ptr, 0);
- if(coremask == 0 && str_coremask_ptr == NULL)
+
+ uint64_t coremask = 0;
+ for(int i = 0; i < cpu_id_count; i++)
{
- PAG_LOG("coremask is invalid, please recheck %s", PAG_CFGFILE);
- return -2;
+ coremask |= 1ULL << cpu_id_range[i];
}
-
+
// ��Ĭ���豸������û��ָ��ʹ���߳���
unsigned int nr_rx_stream;
unsigned int nr_tx_stream;
- unsigned int nr_stream_default = mask_popcnt(coremask);
+ unsigned int nr_stream_default = cpu_id_count;
MESA_load_profile_uint_def(PAG_CFGFILE, "pag", "rxstream",
&nr_rx_stream, nr_stream_default);
@@ -117,8 +147,8 @@ static int pag_config_load_stream_info(struct pag_instance * instance) MESA_load_profile_uint_def(PAG_CFGFILE, "pag", "autoexit",
&instance->autoexit, PAG_DEFAULT_AUTOEXIT);
- PAG_LOG("coremask=%"PRIx64", rxstream=%u, txstream=%u, autoexit=%d",
- instance->coremask, instance->nr_rx_stream, instance->nr_tx_stream,
+ PAG_LOG("coremask=%"PRIx64", rxstream=%u, txstream=%u, autoexit=%d",
+ instance->coremask, instance->nr_rx_stream, instance->nr_tx_stream,
instance->autoexit);
return 0;
@@ -131,17 +161,17 @@ static int pag_config_load_burst_info(struct pag_instance * instance) MESA_load_profile_uint_def(PAG_CFGFILE, "pag", "burst_tx", &instance->burst_tx,
PAG_DEFAULT_TX_BURST);
- if(instance->burst_rx > MR_BURST_MAX)
+ if(instance->burst_rx > PAG_BURST_MAX)
{
PAG_LOG("burst_rx=%d is larger than limit(limit=%d), please recheck %s",
- instance->burst_rx, MR_BURST_MAX, PAG_CFGFILE);
+ instance->burst_rx, PAG_BURST_MAX, PAG_CFGFILE);
return -1;
}
- if(instance->burst_tx > MR_BURST_MAX)
+ if(instance->burst_tx > PAG_BURST_MAX)
{
PAG_LOG("burst_tx=%d is larger than limit(limit=%d), please recheck %s",
- instance->burst_tx, MR_BURST_MAX, PAG_CFGFILE);
+ instance->burst_tx, PAG_BURST_MAX, PAG_CFGFILE);
return -2;
}
@@ -160,11 +190,11 @@ static int __open_all_device(struct pag_instance * instance) return -1;
}
- char * str_devices[MR_DEVICE_MAX];
+ char * str_devices[PAG_DEVICE_MAX];
int nr_devices;
- nr_devices = rte_strsplit(instance->dev_name, sizeof(instance->dev_name),
- str_devices, MR_DEVICE_MAX, ',');
+ nr_devices = __strsplit(instance->dev_name, sizeof(instance->dev_name),
+ str_devices, PAG_DEVICE_MAX, ',');
if (nr_devices <= 0)
{
@@ -258,7 +288,7 @@ int pag_open() }
if (instance->autoexit)
- mr_on_exit_register(__on_exit_pag_close, NULL);
+ marsio_on_exit_register(__on_exit_pag_close, NULL);
__pag_inited = 1;
return 0;
@@ -266,10 +296,7 @@ int pag_open() static void inline __free_frames(struct pag_thread_instance * tinstance)
{
- for (int i = 0; i < tinstance->rxmbuf_used; i++)
- {
- rte_pktmbuf_free(tinstance->rxmbuf[i]);
- }
+ marsio_buff_free(tinstance->rxmbuf, tinstance->rxmbuf_used);
return;
}
@@ -282,18 +309,13 @@ static int inline __get_frames_from_rtdevice(struct pag_instance * instance, // һ����rxmbuf_max����������һ��������
unsigned int cur_socket = tinstance->cur_socket;
- int ret = marsio_raw_recv(instance->raw_sockets[cur_socket], sid,
+ int ret = marsio_raw_recv_burst(instance->raw_sockets[cur_socket], sid,
tinstance->rxmbuf, tinstance->rxmbuf_max);
// ���û��������л��ձ��豸
tinstance->cur_socket = (cur_socket + 1) % instance->nr_raw_sockets;
tinstance->rxmbuf_cur = 0;
tinstance->rxmbuf_used = ret;
-
-#ifndef NDEBUG
- for (int i = 0; i < tinstance->rxmbuf_used; i++)
- rte_mbuf_sanity_check(tinstance->rxmbuf[i], 1);
-#endif
assert(tinstance->rxmbuf_used <= tinstance->rxmbuf_max);
return ret;
@@ -304,8 +326,6 @@ void * pag_get_frame(int sid) struct pag_thread_instance * tinstance = &thread_instance_;
struct pag_instance * instance = &pag_config_;
pag_thread_init(instance, tinstance);
-
- PERF_BEGIN(pag_get_frame);
// �����������ݰ������꣬���ͷţ�Ȼ���ٴ�����ȡ
if (unlikely((tinstance->rxmbuf_cur >= tinstance->rxmbuf_used)))
@@ -319,15 +339,14 @@ void * pag_get_frame(int sid) return NULL;
tinstance->rxmbuf_ctx = tinstance->rxmbuf[tinstance->rxmbuf_cur++];
- PERF_END(pag_get_frame);
- return rte_pktmbuf_mtod(tinstance->rxmbuf_ctx, void *);
+ return (void *)marsio_buff_mtod(tinstance->rxmbuf_ctx);
}
int pag_get_frame_length(int sid)
{
struct pag_thread_instance * tinstance = &thread_instance_;
if (unlikely(tinstance->rxmbuf_ctx == NULL)) return 0;
- return rte_pktmbuf_pkt_len(tinstance->rxmbuf_ctx);
+ return marsio_buff_datalen(tinstance->rxmbuf_ctx);
}
void * pag_get_frame_with_len(int sid, unsigned int * len)
|
