[dpdk-dev] [PATCH v3 03/35] mempool: uninline function to check cookies
Olivier Matz
olivier.matz at 6wind.com
Wed May 18 13:04:24 CEST 2016
There's no reason to keep this function inlined. Move it to
rte_mempool.c. We need to export the function for when compiling
with shared libraries + debug. We also need to keep the macro,
because we don't want to call an empty function when debug is
disabled.
Signed-off-by: Olivier Matz <olivier.matz at 6wind.com>
---
lib/librte_mempool/rte_mempool.c | 82 ++++++++++++++++++++++++++++--
lib/librte_mempool/rte_mempool.h | 78 ++--------------------------
lib/librte_mempool/rte_mempool_version.map | 8 +++
3 files changed, 90 insertions(+), 78 deletions(-)
diff --git a/lib/librte_mempool/rte_mempool.c b/lib/librte_mempool/rte_mempool.c
index fe90ed3..46a5d59 100644
--- a/lib/librte_mempool/rte_mempool.c
+++ b/lib/librte_mempool/rte_mempool.c
@@ -699,8 +699,6 @@ rte_mempool_dump_cache(FILE *f, const struct rte_mempool *mp)
return count;
}
-#ifdef RTE_LIBRTE_MEMPOOL_DEBUG
-/* check cookies before and after objects */
#ifndef __INTEL_COMPILER
#pragma GCC diagnostic ignored "-Wcast-qual"
#endif
@@ -711,6 +709,80 @@ struct mempool_audit_arg {
uint32_t obj_num;
};
+/* check and update cookies or panic (internal) */
+void rte_mempool_check_cookies(const struct rte_mempool *mp,
+ void * const *obj_table_const, unsigned n, int free)
+{
+#ifdef RTE_LIBRTE_MEMPOOL_DEBUG
+ struct rte_mempool_objhdr *hdr;
+ struct rte_mempool_objtlr *tlr;
+ uint64_t cookie;
+ void *tmp;
+ void *obj;
+ void **obj_table;
+
+ /* Force to drop the "const" attribute. This is done only when
+ * DEBUG is enabled */
+ tmp = (void *) obj_table_const;
+ obj_table = (void **) tmp;
+
+ while (n--) {
+ obj = obj_table[n];
+
+ if (rte_mempool_from_obj(obj) != mp)
+ rte_panic("MEMPOOL: object is owned by another "
+ "mempool\n");
+
+ hdr = __mempool_get_header(obj);
+ cookie = hdr->cookie;
+
+ if (free == 0) {
+ if (cookie != RTE_MEMPOOL_HEADER_COOKIE1) {
+ rte_log_set_history(0);
+ RTE_LOG(CRIT, MEMPOOL,
+ "obj=%p, mempool=%p, cookie=%" PRIx64 "\n",
+ obj, (const void *) mp, cookie);
+ rte_panic("MEMPOOL: bad header cookie (put)\n");
+ }
+ hdr->cookie = RTE_MEMPOOL_HEADER_COOKIE2;
+ } else if (free == 1) {
+ if (cookie != RTE_MEMPOOL_HEADER_COOKIE2) {
+ rte_log_set_history(0);
+ RTE_LOG(CRIT, MEMPOOL,
+ "obj=%p, mempool=%p, cookie=%" PRIx64 "\n",
+ obj, (const void *) mp, cookie);
+ rte_panic("MEMPOOL: bad header cookie (get)\n");
+ }
+ hdr->cookie = RTE_MEMPOOL_HEADER_COOKIE1;
+ } else if (free == 2) {
+ if (cookie != RTE_MEMPOOL_HEADER_COOKIE1 &&
+ cookie != RTE_MEMPOOL_HEADER_COOKIE2) {
+ rte_log_set_history(0);
+ RTE_LOG(CRIT, MEMPOOL,
+ "obj=%p, mempool=%p, cookie=%" PRIx64 "\n",
+ obj, (const void *) mp, cookie);
+ rte_panic("MEMPOOL: bad header cookie (audit)\n");
+ }
+ }
+ tlr = __mempool_get_trailer(obj);
+ cookie = tlr->cookie;
+ if (cookie != RTE_MEMPOOL_TRAILER_COOKIE) {
+ rte_log_set_history(0);
+ RTE_LOG(CRIT, MEMPOOL,
+ "obj=%p, mempool=%p, cookie=%" PRIx64 "\n",
+ obj, (const void *) mp, cookie);
+ rte_panic("MEMPOOL: bad trailer cookie\n");
+ }
+ }
+#else
+ RTE_SET_USED(mp);
+ RTE_SET_USED(obj_table_const);
+ RTE_SET_USED(n);
+ RTE_SET_USED(free);
+#endif
+}
+
+#ifdef RTE_LIBRTE_MEMPOOL_DEBUG
static void
mempool_obj_audit(void *arg, void *start, void *end, uint32_t idx)
{
@@ -753,13 +825,13 @@ mempool_audit_cookies(const struct rte_mempool *mp)
arg.obj_num, mp->size);
}
}
+#else
+#define mempool_audit_cookies(mp) do {} while(0)
+#endif
#ifndef __INTEL_COMPILER
#pragma GCC diagnostic error "-Wcast-qual"
#endif
-#else
-#define mempool_audit_cookies(mp) do {} while(0)
-#endif
/* check cookies before and after objects */
static void
diff --git a/lib/librte_mempool/rte_mempool.h b/lib/librte_mempool/rte_mempool.h
index 640f622..a6b82cf 100644
--- a/lib/librte_mempool/rte_mempool.h
+++ b/lib/librte_mempool/rte_mempool.h
@@ -312,80 +312,12 @@ static inline struct rte_mempool_objtlr *__mempool_get_trailer(void *obj)
* - 1: object is supposed to be free, mark it as allocated
* - 2: just check that cookie is valid (free or allocated)
*/
+void rte_mempool_check_cookies(const struct rte_mempool *mp,
+ void * const *obj_table_const, unsigned n, int free);
+
#ifdef RTE_LIBRTE_MEMPOOL_DEBUG
-#ifndef __INTEL_COMPILER
-#pragma GCC diagnostic ignored "-Wcast-qual"
-#endif
-static inline void __mempool_check_cookies(const struct rte_mempool *mp,
- void * const *obj_table_const,
- unsigned n, int free)
-{
- struct rte_mempool_objhdr *hdr;
- struct rte_mempool_objtlr *tlr;
- uint64_t cookie;
- void *tmp;
- void *obj;
- void **obj_table;
-
- /* Force to drop the "const" attribute. This is done only when
- * DEBUG is enabled */
- tmp = (void *) obj_table_const;
- obj_table = (void **) tmp;
-
- while (n--) {
- obj = obj_table[n];
-
- if (rte_mempool_from_obj(obj) != mp)
- rte_panic("MEMPOOL: object is owned by another "
- "mempool\n");
-
- hdr = __mempool_get_header(obj);
- cookie = hdr->cookie;
-
- if (free == 0) {
- if (cookie != RTE_MEMPOOL_HEADER_COOKIE1) {
- rte_log_set_history(0);
- RTE_LOG(CRIT, MEMPOOL,
- "obj=%p, mempool=%p, cookie=%" PRIx64 "\n",
- obj, (const void *) mp, cookie);
- rte_panic("MEMPOOL: bad header cookie (put)\n");
- }
- hdr->cookie = RTE_MEMPOOL_HEADER_COOKIE2;
- }
- else if (free == 1) {
- if (cookie != RTE_MEMPOOL_HEADER_COOKIE2) {
- rte_log_set_history(0);
- RTE_LOG(CRIT, MEMPOOL,
- "obj=%p, mempool=%p, cookie=%" PRIx64 "\n",
- obj, (const void *) mp, cookie);
- rte_panic("MEMPOOL: bad header cookie (get)\n");
- }
- hdr->cookie = RTE_MEMPOOL_HEADER_COOKIE1;
- }
- else if (free == 2) {
- if (cookie != RTE_MEMPOOL_HEADER_COOKIE1 &&
- cookie != RTE_MEMPOOL_HEADER_COOKIE2) {
- rte_log_set_history(0);
- RTE_LOG(CRIT, MEMPOOL,
- "obj=%p, mempool=%p, cookie=%" PRIx64 "\n",
- obj, (const void *) mp, cookie);
- rte_panic("MEMPOOL: bad header cookie (audit)\n");
- }
- }
- tlr = __mempool_get_trailer(obj);
- cookie = tlr->cookie;
- if (cookie != RTE_MEMPOOL_TRAILER_COOKIE) {
- rte_log_set_history(0);
- RTE_LOG(CRIT, MEMPOOL,
- "obj=%p, mempool=%p, cookie=%" PRIx64 "\n",
- obj, (const void *) mp, cookie);
- rte_panic("MEMPOOL: bad trailer cookie\n");
- }
- }
-}
-#ifndef __INTEL_COMPILER
-#pragma GCC diagnostic error "-Wcast-qual"
-#endif
+#define __mempool_check_cookies(mp, obj_table_const, n, free) \
+ rte_mempool_check_cookies(mp, obj_table_const, n, free)
#else
#define __mempool_check_cookies(mp, obj_table_const, n, free) do {} while(0)
#endif /* RTE_LIBRTE_MEMPOOL_DEBUG */
diff --git a/lib/librte_mempool/rte_mempool_version.map b/lib/librte_mempool/rte_mempool_version.map
index 17151e0..ff80ac2 100644
--- a/lib/librte_mempool/rte_mempool_version.map
+++ b/lib/librte_mempool/rte_mempool_version.map
@@ -17,3 +17,11 @@ DPDK_2.0 {
local: *;
};
+
+DPDK_16.07 {
+ global:
+
+ rte_mempool_check_cookies;
+
+ local: *;
+} DPDK_2.0;
--
2.8.0.rc3
More information about the dev
mailing list