[ltt-dev] [UST PATCH 1/3] Remove hlist from kcompat's headers and code

David Goulet david.goulet at polymtl.ca
Fri Nov 26 14:28:06 EST 2010


The hlist structure is no longer needed since it's the exact
same implementation in liburcu.

Signed-off-by: David Goulet <david.goulet at polymtl.ca>
---
 include/Makefile.am           |    1 -
 include/ust/kcompat/hlist.h   |   73 -----------------------------------------
 include/ust/kcompat/kcompat.h |    2 -
 libust/marker.c               |   57 ++++++++++++++++----------------
 libust/tracepoint.c           |   21 ++++++------
 5 files changed, 40 insertions(+), 114 deletions(-)
 delete mode 100644 include/ust/kcompat/hlist.h

diff --git a/include/Makefile.am b/include/Makefile.am
index b89de20..dd000ba 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -14,7 +14,6 @@ nobase_include_HEADERS = \
 	ust/kcompat/kcompat.h \
 	ust/kcompat/compiler.h \
 	ust/kcompat/disable.h \
-	ust/kcompat/hlist.h \
 	ust/kcompat/jhash.h \
 	ust/kcompat/kref.h \
 	ust/kcompat/simple.h \
diff --git a/include/ust/kcompat/hlist.h b/include/ust/kcompat/hlist.h
deleted file mode 100644
index 1bec11a..0000000
--- a/include/ust/kcompat/hlist.h
+++ /dev/null
@@ -1,73 +0,0 @@
-#ifndef _KCOMPAT_HLIST_H
-#define _KCOMPAT_HLIST_H
-
-/*
- * Kernel sourcecode compatible lightweight single pointer list head useful
- * for implementing hash tables
- *
- * Copyright (C) 2009 Novell Inc.
- *
- * Author: Jan Blunck <jblunck at suse.de>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License version 2.1 as
- * published by the Free  Software Foundation.
- */
-
-struct hlist_head
-{
-	struct hlist_node *next;
-};
-
-struct hlist_node
-{
-	struct hlist_node *next;
-	struct hlist_node *prev;
-};
-
-/* Initialize a new list head.  */
-static inline void  INIT_HLIST_HEAD(struct hlist_head *ptr)
-{
-	ptr->next = NULL;
-}
-
-/* Get typed element from list at a given position.  */
-#define hlist_entry(ptr, type, member)					\
-	((type *) ((char *) (ptr) - (unsigned long) (&((type *) 0)->member)))
-
-/* Add new element at the head of the list.  */
-static inline void hlist_add_head (struct hlist_node *newp,
-				   struct hlist_head *head)
-{
-	if (head->next)
-		head->next->prev = newp;
-
-	newp->next = head->next;
-	newp->prev = (struct hlist_node *)head;
-	head->next = newp;
-}
-
-/* Remove element from list.  */
-static inline void hlist_del (struct hlist_node *elem)
-{
-	if (elem->next)
-		elem->next->prev = elem->prev;
-
-	elem->prev->next = elem->next;
-}
-
-#define hlist_for_each_entry(entry, pos, head, member)			\
-	for (pos = (head)->next,					\
-		     entry = hlist_entry(pos, typeof(*entry), member);	\
-	     pos != NULL;						\
-	     pos = pos->next,					\
-		     entry = hlist_entry(pos, typeof(*entry), member))
-
-#define hlist_for_each_entry_safe(entry, pos, p, head, member)		\
-	for (pos = (head)->next,					\
-		     entry = hlist_entry(pos, typeof(*entry), member);	\
-	     (pos != NULL) && ({ p = pos->next; 1;});			\
-	     pos = p,							\
-		     entry = hlist_entry(pos, typeof(*entry), member))
-
-#endif	/* _KCOMPAT_HLIST_H */
diff --git a/include/ust/kcompat/kcompat.h b/include/ust/kcompat/kcompat.h
index 4aea4cc..b506afa 100644
--- a/include/ust/kcompat/kcompat.h
+++ b/include/ust/kcompat/kcompat.h
@@ -59,8 +59,6 @@
 #include <ust/kcompat/simple.h>
 #include <ust/kcompat/compiler.h>
 #include <ust/kcompat/types.h>
-#include <ust/kcompat/hlist.h>
-
 #include <ust/kcompat/jhash.h>
 
 #include <ust/kcompat/disable.h>
diff --git a/libust/marker.c b/libust/marker.c
index 39e12bb..2618b1a 100644
--- a/libust/marker.c
+++ b/libust/marker.c
@@ -21,6 +21,7 @@
 #define _LGPL_SOURCE
 #include <urcu-bp.h>
 #include <urcu/rculist.h>
+#include <urcu/hlist.h>
 
 #include <ust/core.h>
 #include <ust/marker.h>
@@ -64,7 +65,7 @@ void unlock_markers(void)
  */
 #define MARKER_HASH_BITS 6
 #define MARKER_TABLE_SIZE (1 << MARKER_HASH_BITS)
-static struct hlist_head marker_table[MARKER_TABLE_SIZE];
+static struct cds_hlist_head marker_table[MARKER_TABLE_SIZE];
 
 /*
  * Note about RCU :
@@ -75,7 +76,7 @@ static struct hlist_head marker_table[MARKER_TABLE_SIZE];
  * marker entries modifications are protected by the markers_mutex.
  */
 struct marker_entry {
-	struct hlist_node hlist;
+	struct cds_hlist_node hlist;
 	char *format;
 	char *name;
 			/* Probe wrapper */
@@ -386,8 +387,8 @@ marker_entry_remove_probe(struct marker_entry *entry,
  */
 static struct marker_entry *get_marker(const char *channel, const char *name)
 {
-	struct hlist_head *head;
-	struct hlist_node *node;
+	struct cds_hlist_head *head;
+	struct cds_hlist_node *node;
 	struct marker_entry *e;
 	size_t channel_len = strlen(channel) + 1;
 	size_t name_len = strlen(name) + 1;
@@ -395,7 +396,7 @@ static struct marker_entry *get_marker(const char *channel, const char *name)
 
 	hash = jhash(channel, channel_len-1, 0) ^ jhash(name, name_len-1, 0);
 	head = &marker_table[hash & ((1 << MARKER_HASH_BITS)-1)];
-	hlist_for_each_entry(e, node, head, hlist) {
+	cds_hlist_for_each_entry(e, node, head, hlist) {
 		if (!strcmp(channel, e->channel) && !strcmp(name, e->name))
 			return e;
 	}
@@ -409,8 +410,8 @@ static struct marker_entry *get_marker(const char *channel, const char *name)
 static struct marker_entry *add_marker(const char *channel, const char *name,
 		const char *format)
 {
-	struct hlist_head *head;
-	struct hlist_node *node;
+	struct cds_hlist_head *head;
+	struct cds_hlist_node *node;
 	struct marker_entry *e;
 	size_t channel_len = strlen(channel) + 1;
 	size_t name_len = strlen(name) + 1;
@@ -421,7 +422,7 @@ static struct marker_entry *add_marker(const char *channel, const char *name,
 	if (format)
 		format_len = strlen(format) + 1;
 	head = &marker_table[hash & ((1 << MARKER_HASH_BITS)-1)];
-	hlist_for_each_entry(e, node, head, hlist) {
+	cds_hlist_for_each_entry(e, node, head, hlist) {
 		if (!strcmp(channel, e->channel) && !strcmp(name, e->name)) {
 			DBG("Marker %s.%s busy", channel, name);
 			return ERR_PTR(-EBUSY);	/* Already there */
@@ -459,7 +460,7 @@ static struct marker_entry *add_marker(const char *channel, const char *name,
 	e->format_allocated = 0;
 	e->refcount = 0;
 	e->rcu_pending = 0;
-	hlist_add_head(&e->hlist, head);
+	cds_hlist_add_head(&e->hlist, head);
 	return e;
 }
 
@@ -469,8 +470,8 @@ static struct marker_entry *add_marker(const char *channel, const char *name,
  */
 static int remove_marker(const char *channel, const char *name)
 {
-	struct hlist_head *head;
-	struct hlist_node *node;
+	struct cds_hlist_head *head;
+	struct cds_hlist_node *node;
 	struct marker_entry *e;
 	int found = 0;
 	size_t channel_len = strlen(channel) + 1;
@@ -480,7 +481,7 @@ static int remove_marker(const char *channel, const char *name)
 
 	hash = jhash(channel, channel_len-1, 0) ^ jhash(name, name_len-1, 0);
 	head = &marker_table[hash & ((1 << MARKER_HASH_BITS)-1)];
-	hlist_for_each_entry(e, node, head, hlist) {
+	cds_hlist_for_each_entry(e, node, head, hlist) {
 		if (!strcmp(channel, e->channel) && !strcmp(name, e->name)) {
 			found = 1;
 			break;
@@ -490,7 +491,7 @@ static int remove_marker(const char *channel, const char *name)
 		return -ENOENT;
 	if (e->single.func != __mark_empty_function)
 		return -EBUSY;
-	hlist_del(&e->hlist);
+	cds_hlist_del(&e->hlist);
 	if (e->format_allocated)
 		free(e->format);
 	ret = ltt_channels_unregister(e->channel);
@@ -912,12 +913,12 @@ get_marker_from_private_data(marker_probe_func *probe, void *probe_private)
 {
 	struct marker_entry *entry;
 	unsigned int i;
-	struct hlist_head *head;
-	struct hlist_node *node;
+	struct cds_hlist_head *head;
+	struct cds_hlist_node *node;
 
 	for (i = 0; i < MARKER_TABLE_SIZE; i++) {
 		head = &marker_table[i];
-		hlist_for_each_entry(entry, node, head, hlist) {
+		cds_hlist_for_each_entry(entry, node, head, hlist) {
 			if (!entry->ptype) {
 				if (entry->single.func == probe
 						&& entry->single.probe_private
@@ -1013,8 +1014,8 @@ end:
 void *marker_get_private_data(const char *channel, const char *name,
 			      marker_probe_func *probe, int num)
 {
-	struct hlist_head *head;
-	struct hlist_node *node;
+	struct cds_hlist_head *head;
+	struct cds_hlist_node *node;
 	struct marker_entry *e;
 	size_t channel_len = strlen(channel) + 1;
 	size_t name_len = strlen(name) + 1;
@@ -1023,7 +1024,7 @@ void *marker_get_private_data(const char *channel, const char *name,
 
 	hash = jhash(channel, channel_len-1, 0) ^ jhash(name, name_len-1, 0);
 	head = &marker_table[hash & ((1 << MARKER_HASH_BITS)-1)];
-	hlist_for_each_entry(e, node, head, hlist) {
+	cds_hlist_for_each_entry(e, node, head, hlist) {
 		if (!strcmp(channel, e->channel) && !strcmp(name, e->name)) {
 			if (!e->ptype) {
 				if (num == 0 && e->single.func == probe)
@@ -1178,14 +1179,14 @@ void marker_iter_reset(struct marker_iter *iter)
 /*
  * must be called with current->user_markers_mutex held
  */
-static void free_user_marker(char __user *state, struct hlist_head *head)
+static void free_user_marker(char __user *state, struct cds_hlist_head *head)
 {
 	struct user_marker *umark;
-	struct hlist_node *pos, *n;
+	struct cds_hlist_node *pos, *n;
 
-	hlist_for_each_entry_safe(umark, pos, n, head, hlist) {
+	cds_hlist_for_each_entry_safe(umark, pos, n, head, hlist) {
 		if (umark->state == state) {
-			hlist_del(&umark->hlist);
+			cds_hlist_del(&umark->hlist);
 			free(umark);
 		}
 	}
@@ -1243,12 +1244,12 @@ static void free_user_marker(char __user *state, struct hlist_head *head)
 void exit_user_markers(struct task_struct *p)
 {
 	struct user_marker *umark;
-	struct hlist_node *pos, *n;
+	struct cds_hlist_node *pos, *n;
 
 	if (thread_group_leader(p)) {
 		pthread_mutex_lock(&markers_mutex);
 		pthread_mutex_lock(&p->user_markers_mutex);
-		hlist_for_each_entry_safe(umark, pos, n, &p->user_markers,
+		cds_hlist_for_each_entry_safe(umark, pos, n, &p->user_markers,
 			hlist)
 		    free(umark);
 		INIT_HLIST_HEAD(&p->user_markers);
@@ -1306,8 +1307,8 @@ void ltt_dump_marker_state(struct ust_trace *trace)
 {
 	struct marker_entry *entry;
 	struct ltt_probe_private_data call_data;
-	struct hlist_head *head;
-	struct hlist_node *node;
+	struct cds_hlist_head *head;
+	struct cds_hlist_node *node;
 	unsigned int i;
 
 	pthread_mutex_lock(&markers_mutex);
@@ -1316,7 +1317,7 @@ void ltt_dump_marker_state(struct ust_trace *trace)
 
 	for (i = 0; i < MARKER_TABLE_SIZE; i++) {
 		head = &marker_table[i];
-		hlist_for_each_entry(entry, node, head, hlist) {
+		cds_hlist_for_each_entry(entry, node, head, hlist) {
 			__trace_mark(0, metadata, core_marker_id,
 				&call_data,
 				"channel %s name %s event_id %hu "
diff --git a/libust/tracepoint.c b/libust/tracepoint.c
index dbaca6f..47d3785 100644
--- a/libust/tracepoint.c
+++ b/libust/tracepoint.c
@@ -27,6 +27,7 @@
 
 #define _LGPL_SOURCE
 #include <urcu-bp.h>
+#include <urcu/hlist.h>
 
 //extern struct tracepoint __start___tracepoints[] __attribute__((visibility("hidden")));
 //extern struct tracepoint __stop___tracepoints[] __attribute__((visibility("hidden")));
@@ -49,7 +50,7 @@ static DEFINE_MUTEX(tracepoints_mutex);
  */
 #define TRACEPOINT_HASH_BITS 6
 #define TRACEPOINT_TABLE_SIZE (1 << TRACEPOINT_HASH_BITS)
-static struct hlist_head tracepoint_table[TRACEPOINT_TABLE_SIZE];
+static struct cds_hlist_head tracepoint_table[TRACEPOINT_TABLE_SIZE];
 
 /*
  * Note about RCU :
@@ -58,7 +59,7 @@ static struct hlist_head tracepoint_table[TRACEPOINT_TABLE_SIZE];
  * Tracepoint entries modifications are protected by the tracepoints_mutex.
  */
 struct tracepoint_entry {
-	struct hlist_node hlist;
+	struct cds_hlist_node hlist;
 	struct probe *probes;
 	int refcount;	/* Number of times armed. 0 if disarmed. */
 	char name[0];
@@ -192,13 +193,13 @@ tracepoint_entry_remove_probe(struct tracepoint_entry *entry, void *probe,
  */
 static struct tracepoint_entry *get_tracepoint(const char *name)
 {
-	struct hlist_head *head;
-	struct hlist_node *node;
+	struct cds_hlist_head *head;
+	struct cds_hlist_node *node;
 	struct tracepoint_entry *e;
 	u32 hash = jhash(name, strlen(name), 0);
 
 	head = &tracepoint_table[hash & (TRACEPOINT_TABLE_SIZE - 1)];
-	hlist_for_each_entry(e, node, head, hlist) {
+	cds_hlist_for_each_entry(e, node, head, hlist) {
 		if (!strcmp(name, e->name))
 			return e;
 	}
@@ -211,14 +212,14 @@ static struct tracepoint_entry *get_tracepoint(const char *name)
  */
 static struct tracepoint_entry *add_tracepoint(const char *name)
 {
-	struct hlist_head *head;
-	struct hlist_node *node;
+	struct cds_hlist_head *head;
+	struct cds_hlist_node *node;
 	struct tracepoint_entry *e;
 	size_t name_len = strlen(name) + 1;
 	u32 hash = jhash(name, name_len-1, 0);
 
 	head = &tracepoint_table[hash & (TRACEPOINT_TABLE_SIZE - 1)];
-	hlist_for_each_entry(e, node, head, hlist) {
+	cds_hlist_for_each_entry(e, node, head, hlist) {
 		if (!strcmp(name, e->name)) {
 			DBG("tracepoint %s busy", name);
 			return ERR_PTR(-EEXIST);	/* Already there */
@@ -234,7 +235,7 @@ static struct tracepoint_entry *add_tracepoint(const char *name)
 	memcpy(&e->name[0], name, name_len);
 	e->probes = NULL;
 	e->refcount = 0;
-	hlist_add_head(&e->hlist, head);
+	cds_hlist_add_head(&e->hlist, head);
 	return e;
 }
 
@@ -244,7 +245,7 @@ static struct tracepoint_entry *add_tracepoint(const char *name)
  */
 static inline void remove_tracepoint(struct tracepoint_entry *e)
 {
-	hlist_del(&e->hlist);
+	cds_hlist_del(&e->hlist);
 	free(e);
 }
 
-- 
1.7.3.2





More information about the lttng-dev mailing list