summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
author童宗振 <[email protected]>2024-02-28 13:54:01 +0000
committer童宗振 <[email protected]>2024-02-28 13:54:01 +0000
commit5bedad46cda4df8b5c1fe01e28c07732ae7b1b99 (patch)
tree0ccf3089acbe205cf6fd5b374a27548a72e1b8b8 /include
parent6a8a4fe6a4e28b134696028222d789059a010548 (diff)
Basic API implementation for recording trace
Diffstat (limited to 'include')
-rw-r--r--include/external/marsio.h10
-rw-r--r--include/internal/mrb_define.h4
-rw-r--r--include/internal/protect.h101
3 files changed, 70 insertions, 45 deletions
diff --git a/include/external/marsio.h b/include/external/marsio.h
index c993d74..d16d139 100644
--- a/include/external/marsio.h
+++ b/include/external/marsio.h
@@ -10,6 +10,7 @@
*/
#pragma once
+#include <limits.h>
typedef enum
{
@@ -123,6 +124,7 @@ extern "C"
#endif
#include <netinet/in.h>
+#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
@@ -293,6 +295,14 @@ int marsio_buff_append_sid_list(marsio_buff_t * m, sid_t * slist, uint8_t sz_sli
int marsio_buff_prepend_sid_list(marsio_buff_t * m, sid_t * slist, uint8_t sz_slist);
int marsio_buff_get_current_sid(marsio_buff_t * m, sid_t * sid);
+/******************************** data path trace**************************************/
+int marsio_dp_trace_record_can_emit(const marsio_buff_t * mbuf);
+int marsio_dp_trace_record_emit_str(struct mr_instance * instance, marsio_buff_t * mbuf, const char * module,
+ const char * str);
+int marsio_dp_trace_record_emit_fmt(struct mr_instance * instance, marsio_buff_t * mbuf, const char * module,
+ const char * format, ...);
+/***********************************************************************************/
+
#ifdef __cplusplus
}
#endif
diff --git a/include/internal/mrb_define.h b/include/internal/mrb_define.h
index 7bb23ab..ccabd61 100644
--- a/include/internal/mrb_define.h
+++ b/include/internal/mrb_define.h
@@ -1,5 +1,6 @@
#pragma once
#include <common.h>
+#include <dp_trace.h>
#include <ldbc.h>
#include <stdint.h>
#include <sys/types.h>
@@ -48,6 +49,9 @@ struct mrb_metadata
/* pkt_parser result */
struct pkt_parser_result pkt_parser_result;
+
+ /* data path trace buffer */
+ struct dp_trace_buffer * dp_trace_buffer;
} __rte_cache_aligned;
static inline void mrb_metadata_clear(struct mrb_metadata * mrb_meta)
diff --git a/include/internal/protect.h b/include/internal/protect.h
index 6dff4e7..e159e9f 100644
--- a/include/internal/protect.h
+++ b/include/internal/protect.h
@@ -1,7 +1,7 @@
#pragma once
-#include <rte_mempool.h>
#include <rte_mbuf.h>
+#include <rte_mempool.h>
#include <rte_spinlock.h>
/* 全局asan开关 */
@@ -13,56 +13,62 @@ extern rte_spinlock_t g_in_protect_lock;
/* TODO: 这些定义应通过包含GCC的头文件来实现,不应通过这种方式 */
#if defined(__SANITIZE_ADDRESS__)
-void __asan_poison_memory_region(void const volatile *addr, size_t size);
-void __asan_unpoison_memory_region(void const volatile *addr, size_t size);
+void __asan_poison_memory_region(void const volatile * addr, size_t size);
+void __asan_unpoison_memory_region(void const volatile * addr, size_t size);
#endif
#if defined(__SANITIZE_ADDRESS__)
-#define MR_ASAN_POISON_MEMORY_REGION(addr, size) do { \
-if(g_in_protect_mode) \
-{ \
- rte_spinlock_lock(&g_in_protect_lock); \
- __asan_poison_memory_region((addr), (size)); \
- rte_spinlock_unlock(&g_in_protect_lock); \
-}} while(0)
-
-#define MR_ASAN_UNPOISON_MEMORY_REGION(addr, size) do { \
-if(g_in_protect_mode) \
-{ \
- rte_spinlock_lock(&g_in_protect_lock); \
- __asan_unpoison_memory_region((addr), (size)); \
- rte_spinlock_unlock(&g_in_protect_lock); \
-}} while(0)
+#define MR_ASAN_POISON_MEMORY_REGION(addr, size) \
+ do \
+ { \
+ if (g_in_protect_mode) \
+ { \
+ rte_spinlock_lock(&g_in_protect_lock); \
+ __asan_poison_memory_region((addr), (size)); \
+ rte_spinlock_unlock(&g_in_protect_lock); \
+ } \
+ } while (0)
+
+#define MR_ASAN_UNPOISON_MEMORY_REGION(addr, size) \
+ do \
+ { \
+ if (g_in_protect_mode) \
+ { \
+ rte_spinlock_lock(&g_in_protect_lock); \
+ __asan_unpoison_memory_region((addr), (size)); \
+ rte_spinlock_unlock(&g_in_protect_lock); \
+ } \
+ } while (0)
#else
#define MR_ASAN_POISON_MEMORY_REGION(addr, size) ((void)(addr), (void)(size))
#define MR_ASAN_UNPOISON_MEMORY_REGION(addr, size) ((void)(addr), (void)(size))
#endif
-static inline void PROTECT_rte_mempool_unpoison(struct rte_mempool *pool)
+static inline void PROTECT_rte_mempool_unpoison(struct rte_mempool * pool)
{
MR_ASAN_UNPOISON_MEMORY_REGION(pool, sizeof(struct rte_mempool));
MR_ASAN_UNPOISON_MEMORY_REGION(pool, RTE_MEMPOOL_HEADER_SIZE(pool, pool->cache_size));
}
-static inline void PROTECT_rte_mbuf_unpoison_meta(struct rte_mbuf *mbuf)
+static inline void PROTECT_rte_mbuf_unpoison_meta(struct rte_mbuf * mbuf)
{
MR_ASAN_UNPOISON_MEMORY_REGION(mbuf, sizeof(struct rte_mbuf));
MR_ASAN_UNPOISON_MEMORY_REGION((const char *)mbuf + sizeof(struct rte_mbuf), mbuf->priv_size);
}
-static inline void PROTECT_rte_mbuf_poison_meta(struct rte_mbuf *mbuf)
+static inline void PROTECT_rte_mbuf_poison_meta(struct rte_mbuf * mbuf)
{
MR_ASAN_POISON_MEMORY_REGION((const char *)mbuf + sizeof(struct rte_mbuf), mbuf->priv_size);
MR_ASAN_POISON_MEMORY_REGION(mbuf, sizeof(struct rte_mbuf));
}
-static inline void PROTECT_rte_mbuf_poison_buff(struct rte_mbuf *mbuf)
+static inline void PROTECT_rte_mbuf_poison_buff(struct rte_mbuf * mbuf)
{
MR_ASAN_POISON_MEMORY_REGION(mbuf->buf_addr, mbuf->buf_len);
}
-static inline void PROTECT_rte_mbuf_unpoison_buff(struct rte_mbuf *mbuf)
+static inline void PROTECT_rte_mbuf_unpoison_buff(struct rte_mbuf * mbuf)
{
MR_ASAN_UNPOISON_MEMORY_REGION(mbuf->buf_addr, mbuf->buf_len);
}
@@ -81,15 +87,17 @@ static inline void PROTECT_rte_mbuf_unpoison(struct rte_mbuf * mbuf)
static inline void PROTECT_rte_mbuf_poison_bulk(struct rte_mbuf * mbufs[], int nr_mbufs)
{
- for(unsigned int i = 0; i < nr_mbufs; i++) PROTECT_rte_mbuf_poison(mbufs[i]);
+ for (unsigned int i = 0; i < nr_mbufs; i++)
+ PROTECT_rte_mbuf_poison(mbufs[i]);
}
static inline void PROTECT_rte_mbuf_unpoison_bulk(struct rte_mbuf * mbufs[], int nr_mbufs)
{
- for(unsigned int i = 0; i < nr_mbufs; i++) PROTECT_rte_mbuf_unpoison(mbufs[i]);
+ for (unsigned int i = 0; i < nr_mbufs; i++)
+ PROTECT_rte_mbuf_unpoison(mbufs[i]);
}
-static inline void PROTECT_rte_mbuf_unpoison_data(struct rte_mbuf *mbuf)
+static inline void PROTECT_rte_mbuf_unpoison_data(struct rte_mbuf * mbuf)
{
/* Poison all buff area, because some area may be unpoison before. */
PROTECT_rte_mbuf_poison_buff(mbuf);
@@ -103,10 +111,10 @@ static inline void PROTECT_rte_mbuf_unpoison_data(struct rte_mbuf *mbuf)
/* 从DPDK17.05中移植rte_pktmbuf_alloc
* 该函数在申请mbuf的同时还要修改mbuf中的元数据,此时由于还没有拿到mbuf的指针,
* 也就无法去保护,函数功能无法实现。现移植,在拿到mbuf的指针后立即去保护,继续后面的初始化流程 */
-static inline struct rte_mbuf * __PROTECT_PORT_rte_mbuf_raw_alloc(struct rte_mempool *mp)
+static inline struct rte_mbuf * __PROTECT_PORT_rte_mbuf_raw_alloc(struct rte_mempool * mp)
{
- struct rte_mbuf *m;
- void *mb = NULL;
+ struct rte_mbuf * m;
+ void * mb = NULL;
if (rte_mempool_get(mp, &mb) < 0)
return NULL;
@@ -117,9 +125,9 @@ static inline struct rte_mbuf * __PROTECT_PORT_rte_mbuf_raw_alloc(struct rte_mem
return m;
}
-static inline struct rte_mbuf * __PROTECT_PORT_rte_pktmbuf_alloc(struct rte_mempool *mp)
+static inline struct rte_mbuf * __PROTECT_PORT_rte_pktmbuf_alloc(struct rte_mempool * mp)
{
- struct rte_mbuf *m;
+ struct rte_mbuf * m;
if ((m = __PROTECT_PORT_rte_mbuf_raw_alloc(mp)) != NULL)
rte_pktmbuf_reset(m);
return m;
@@ -127,7 +135,7 @@ static inline struct rte_mbuf * __PROTECT_PORT_rte_pktmbuf_alloc(struct rte_memp
/* 移植完毕,以后DPDK版本升级时,要格外注意以上的实现是否发生了变化 */
-static inline struct rte_mbuf * PROTECT_rte_pktmbuf_alloc(struct rte_mempool *mp)
+static inline struct rte_mbuf * PROTECT_rte_pktmbuf_alloc(struct rte_mempool * mp)
{
#ifndef __SANITIZE_ADDRESS__
return rte_pktmbuf_alloc(mp);
@@ -138,31 +146,33 @@ static inline struct rte_mbuf * PROTECT_rte_pktmbuf_alloc(struct rte_mempool *mp
#endif
}
-static inline void PROTECT_rte_pktmbuf_free(struct rte_mbuf *mbuf)
+#if 0
+static inline void PROTECT_rte_pktmbuf_free(struct rte_mbuf * mbuf)
{
PROTECT_rte_mbuf_unpoison_meta(mbuf);
rte_pktmbuf_free(mbuf);
/* TODO: 应重新对释放的mbuf区域进行保护,需要在释放前计算mbuf的指针,长度,再执行保护 */
}
-static inline int PROTECT_rte_pktmbuf_alloc_bulk(struct rte_mempool *pool, struct rte_mbuf **mbufs, unsigned count)
+static inline int PROTECT_rte_pktmbuf_alloc_bulk(struct rte_mempool * pool, struct rte_mbuf ** mbufs, unsigned count)
{
#ifndef __SANITIZE_ADDRESS__
return rte_pktmbuf_alloc_bulk(pool, mbufs, count);
#else
unsigned int alloc_count;
- for(alloc_count = 0; alloc_count < count; alloc_count++)
+ for (alloc_count = 0; alloc_count < count; alloc_count++)
{
struct rte_mbuf * m = PROTECT_rte_pktmbuf_alloc(pool);
- if(unlikely(m == NULL)) goto errout;
+ if (unlikely(m == NULL))
+ goto errout;
mbufs[alloc_count] = m;
}
return 0;
errout:
- for(unsigned i = 0; i < alloc_count; i++)
+ for (unsigned i = 0; i < alloc_count; i++)
{
PROTECT_rte_pktmbuf_free(mbufs[i]);
mbufs[i] = NULL;
@@ -171,8 +181,9 @@ errout:
return -1;
#endif
}
+#endif
-static inline char * PROTECT_rte_pktmbuf_append(struct rte_mbuf *m, uint16_t len)
+static inline char * PROTECT_rte_pktmbuf_append(struct rte_mbuf * m, uint16_t len)
{
PROTECT_rte_mbuf_unpoison_meta(m);
char * ret = rte_pktmbuf_append(m, len);
@@ -180,7 +191,7 @@ static inline char * PROTECT_rte_pktmbuf_append(struct rte_mbuf *m, uint16_t len
return ret;
}
-static inline char * PROTECT_rte_pktmbuf_prepend(struct rte_mbuf *m, uint16_t len)
+static inline char * PROTECT_rte_pktmbuf_prepend(struct rte_mbuf * m, uint16_t len)
{
PROTECT_rte_mbuf_unpoison_meta(m);
char * ret = rte_pktmbuf_prepend(m, len);
@@ -188,7 +199,7 @@ static inline char * PROTECT_rte_pktmbuf_prepend(struct rte_mbuf *m, uint16_t le
return ret;
}
-static inline char * PROTECT_rte_pktmbuf_adj(struct rte_mbuf *m, uint16_t len)
+static inline char * PROTECT_rte_pktmbuf_adj(struct rte_mbuf * m, uint16_t len)
{
PROTECT_rte_mbuf_unpoison_meta(m);
char * ret = rte_pktmbuf_adj(m, len);
@@ -196,35 +207,35 @@ static inline char * PROTECT_rte_pktmbuf_adj(struct rte_mbuf *m, uint16_t len)
return ret;
}
-static inline int PROTECT_rte_pktmbuf_trim(struct rte_mbuf *m, uint16_t len)
+static inline int PROTECT_rte_pktmbuf_trim(struct rte_mbuf * m, uint16_t len)
{
PROTECT_rte_mbuf_unpoison_meta(m);
int ret = rte_pktmbuf_trim(m, len);
return ret;
}
-static inline uint16_t PROTECT_rte_pktmbuf_data_len(struct rte_mbuf *m)
+static inline uint16_t PROTECT_rte_pktmbuf_data_len(struct rte_mbuf * m)
{
PROTECT_rte_mbuf_unpoison_meta(m);
uint16_t ret = rte_pktmbuf_data_len(m);
return ret;
}
-static inline uint32_t PROTECT_rte_pktmbuf_pkt_len(struct rte_mbuf *m)
+static inline uint32_t PROTECT_rte_pktmbuf_pkt_len(struct rte_mbuf * m)
{
PROTECT_rte_mbuf_unpoison_meta(m);
uint32_t ret = rte_pktmbuf_pkt_len(m);
return ret;
}
-static inline uint16_t PROTECT_rte_mbuf_refcnt_update(struct rte_mbuf *m, int16_t value)
+static inline uint16_t PROTECT_rte_mbuf_refcnt_update(struct rte_mbuf * m, int16_t value)
{
PROTECT_rte_mbuf_unpoison_meta(m);
uint16_t ret = rte_mbuf_refcnt_update(m, value);
return ret;
}
-static inline uint16_t PROTECT_rte_mbuf_refcnt_read(const struct rte_mbuf *m)
+static inline uint16_t PROTECT_rte_mbuf_refcnt_read(const struct rte_mbuf * m)
{
PROTECT_rte_mbuf_unpoison_meta((struct rte_mbuf *)m);
uint16_t ret = rte_mbuf_refcnt_read(m);