PERFORCE change 44662 for review
Sam Leffler
sam at FreeBSD.org
Thu Jan 1 20:37:38 PST 2004
http://perforce.freebsd.org/chv.cgi?CH=44662
Change 44662 by sam at sam_ebb on 2004/01/01 20:36:55
o mbuf tag inlining optimizations
o add free method to mbuf tags for zone allocation
Affected files ...
.. //depot/projects/netperf+sockets/sys/kern/uipc_mbuf2.c#3 edit
.. //depot/projects/netperf+sockets/sys/sys/mbuf.h#5 edit
Differences ...
==== //depot/projects/netperf+sockets/sys/kern/uipc_mbuf2.c#3 (text+ko) ====
@@ -310,6 +310,17 @@
return n;
}
+/* Free a packet tag. */
+static void
+_m_tag_free(struct m_tag *t)
+{
+#ifdef MAC
+ if (t->m_tag_id == PACKET_TAG_MACLABEL)
+ mac_destroy_mbuf_tag(t);
+#endif
+ free(t, M_PACKET_TAGS);
+}
+
/* Get a packet tag structure along with specified data following. */
struct m_tag *
m_tag_alloc(u_int32_t cookie, int type, int len, int wait)
@@ -321,39 +332,11 @@
t = malloc(len + sizeof(struct m_tag), M_PACKET_TAGS, wait);
if (t == NULL)
return NULL;
- t->m_tag_id = type;
- t->m_tag_len = len;
- t->m_tag_cookie = cookie;
+ m_tag_setup(t, cookie, type, len);
+ t->m_tag_free = _m_tag_free;
return t;
}
-/* Free a packet tag. */
-void
-m_tag_free(struct m_tag *t)
-{
-#ifdef MAC
- if (t->m_tag_id == PACKET_TAG_MACLABEL)
- mac_destroy_mbuf_tag(t);
-#endif
- free(t, M_PACKET_TAGS);
-}
-
-/* Prepend a packet tag. */
-void
-m_tag_prepend(struct mbuf *m, struct m_tag *t)
-{
- KASSERT(m && t, ("m_tag_prepend: null argument, m %p t %p", m, t));
- SLIST_INSERT_HEAD(&m->m_pkthdr.tags, t, m_tag_link);
-}
-
-/* Unlink a packet tag. */
-void
-m_tag_unlink(struct mbuf *m, struct m_tag *t)
-{
- KASSERT(m && t, ("m_tag_unlink: null argument, m %p t %p", m, t));
- SLIST_REMOVE(&m->m_pkthdr.tags, t, m_tag, m_tag_link);
-}
-
/* Unlink and free a packet tag. */
void
m_tag_delete(struct mbuf *m, struct m_tag *t)
@@ -473,24 +456,3 @@
}
return 1;
}
-
-/* Initialize tags on an mbuf. */
-void
-m_tag_init(struct mbuf *m)
-{
- SLIST_INIT(&m->m_pkthdr.tags);
-}
-
-/* Get first tag in chain. */
-struct m_tag *
-m_tag_first(struct mbuf *m)
-{
- return SLIST_FIRST(&m->m_pkthdr.tags);
-}
-
-/* Get next tag in chain. */
-struct m_tag *
-m_tag_next(struct mbuf *m, struct m_tag *t)
-{
- return SLIST_NEXT(t, m_tag_link);
-}
==== //depot/projects/netperf+sockets/sys/sys/mbuf.h#5 (text+ko) ====
@@ -83,6 +83,7 @@
u_int16_t m_tag_id; /* Tag ID */
u_int16_t m_tag_len; /* Length of data */
u_int32_t m_tag_cookie; /* ABI/Module ID */
+ void (*m_tag_free)(struct m_tag *);
};
/*
@@ -552,19 +553,82 @@
/* Packet tag routines. */
struct m_tag *m_tag_alloc(u_int32_t, int, int, int);
-void m_tag_free(struct m_tag *);
-void m_tag_prepend(struct mbuf *, struct m_tag *);
-void m_tag_unlink(struct mbuf *, struct m_tag *);
void m_tag_delete(struct mbuf *, struct m_tag *);
void m_tag_delete_chain(struct mbuf *, struct m_tag *);
struct m_tag *m_tag_locate(struct mbuf *, u_int32_t, int, struct m_tag *);
struct m_tag *m_tag_copy(struct m_tag *, int);
int m_tag_copy_chain(struct mbuf *, struct mbuf *, int);
-void m_tag_init(struct mbuf *);
-struct m_tag *m_tag_first(struct mbuf *);
-struct m_tag *m_tag_next(struct mbuf *, struct m_tag *);
void m_tag_delete_nonpersistent(struct mbuf *);
+/*
+ * Initialize the list of tags associated with an mbuf.
+ */
+static __inline void
+m_tag_init(struct mbuf *m)
+{
+ SLIST_INIT(&m->m_pkthdr.tags);
+}
+
+/*
+ * Setup the contents of a tag. Note that this does not
+ * fillin the free method; the caller is expected to do that.
+ *
+ * XXX probably should be called m_tag_init; but that was
+ * already taken.
+ */
+static __inline void
+m_tag_setup(struct m_tag *t, u_int32_t cookie, int type, int len)
+{
+ t->m_tag_id = type;
+ t->m_tag_len = len;
+ t->m_tag_cookie = cookie;
+}
+
+/*
+ * Reclaim resources associated with a tag.
+ */
+static __inline void
+m_tag_free(struct m_tag *t)
+{
+ (*t->m_tag_free)(t);
+}
+
+/*
+ * Return the first tag associated with an mbuf.
+ */
+static __inline struct m_tag *
+m_tag_first(struct mbuf *m)
+{
+ return SLIST_FIRST(&m->m_pkthdr.tags);
+}
+
+/*
+ * Return the next tag in the list of tags associated with an mbuf.
+ */
+static __inline struct m_tag *
+m_tag_next(struct mbuf *m, struct m_tag *t)
+{
+ return SLIST_NEXT(t, m_tag_link);
+}
+
+/*
+ * Prepend a tag to the list of tags associated with an mbuf.
+ */
+static __inline void
+m_tag_prepend(struct mbuf *m, struct m_tag *t)
+{
+ SLIST_INSERT_HEAD(&m->m_pkthdr.tags, t, m_tag_link);
+}
+
+/*
+ * Unlink a tag from the list of tags associated with an mbuf.
+ */
+static __inline void
+m_tag_unlink(struct mbuf *m, struct m_tag *t)
+{
+ SLIST_REMOVE(&m->m_pkthdr.tags, t, m_tag, m_tag_link);
+}
+
/* These are for OpenBSD compatibility. */
#define MTAG_ABI_COMPAT 0 /* compatibility ABI */
@@ -577,7 +641,8 @@
static __inline struct m_tag *
m_tag_find(struct mbuf *m, int type, struct m_tag *start)
{
- return m_tag_locate(m, MTAG_ABI_COMPAT, type, start);
+ return SLIST_EMPTY(&m->m_pkthdr.tags) ?
+ NULL : m_tag_locate(m, MTAG_ABI_COMPAT, type, start);
}
#endif /* _KERNEL */
More information about the p4-projects
mailing list