Skip to contentSkip to conversation

klist: implement KLIST_INIT() and DEFINE_KLIST()

PATCH Applied Tejun Heo 4 participants 12 messages Apr 22, 2008 – Apr 28, 2008 Library code

lore
Share & tools
lore

Tejun Heo

author
#0 lore raw

PATCH 1/2 klist: implement KLIST_INIT() and DEFINE_KLIST()

klist is missing static initializers and definition helper. Add them.

---
I can't tell who's in charge of this code, so I'm including last two people who made changes and Andrew :-) This will be used by later USB mode switch support, so I'm cc'ing USB people too.

Thanks.

include/linux/klist.h | 8 ++++++++

1 files changed, 8 insertions(+), 0 deletions(-)
include/linux/klist.h +0 -0
index 7407125..c6b697c 100644
@@ -25,6 +25,14 @@ struct klist {
	void			(*put)(struct klist_node *);
};

+#define KLIST_INIT(_name, _get, _put) \
+ { .k_lock = __SPIN_LOCK_UNLOCKED(klist.k_lock), \

+	  .k_list	= LIST_HEAD_INIT(_name.k_list),			\
+	  .get		= _get,						\
+	  .put		= _put, }

+
+#define DEFINE_KLIST(_name, _get, _put) \
+ struct klist _name = KLIST_INIT(_name, _get, _put)

extern void klist_init(struct klist * k, void (*get)(struct klist_node *),

		       void (*put)(struct klist_node *));
Signature · 1 line
1.5.2.4
author
#1 lore raw

PATCH 1/1 klist: implement klist_add_{after|before}()

Add klist_add_after() and klist_add_before() which puts a new node after and before an existing node, respectively. This is useful for callers which need to keep klist ordered. Note that synchronizing between simultaneous additions for ordering is the caller's responsibility.

---
include/linux/klist.h | 2 ++
lib/klist.c | 38 ++++++++++++++++++++++++++++++++++++++

2 files changed, 40 insertions(+), 0 deletions(-)
include/linux/klist.h +0 -0
index c6b697c..80658c4 100644
@@ -46,6 +46,8 @@ struct klist_node {
 

extern void klist_add_tail(struct klist_node * n, struct klist * k); extern void klist_add_head(struct klist_node * n, struct klist * k); +extern void klist_add_after(struct klist_node * n, struct klist_node * pos); +extern void klist_add_before(struct klist_node * n, struct klist_node * pos);

extern void klist_del(struct klist_node * n);
extern void klist_remove(struct klist_node * n);

lib/klist.c +0 -0
index 120bd17..ffe9cb6 100644
@@ -120,6 +120,44 @@ void klist_add_tail(struct klist_node * n, struct klist * k)

EXPORT_SYMBOL_GPL(klist_add_tail);

+/**
+ * klist_add_after - Init a klist_node and add it after an existing node
+ * @n: node we're adding.
+ * @pos: node to put @n after
+ */
+
+void klist_add_after(struct klist_node * n, struct klist_node * pos) +{
+ struct klist *k = pos->n_klist;
+
+ klist_node_init(k, n);
+ spin_lock(&k->k_lock);
+ list_add(&n->n_node, &pos->n_node);
+ spin_unlock(&k->k_lock);
+}
+
+EXPORT_SYMBOL_GPL(klist_add_after);
+
+
+/**
+ * klist_add_before - Init a klist_node and add it before an existing node
+ * @n: node we're adding.
+ * @pos: node to put @n after
+ */
+
+void klist_add_before(struct klist_node * n, struct klist_node * pos) +{
+ struct klist *k = pos->n_klist;
+
+ klist_node_init(k, n);
+ spin_lock(&k->k_lock);
+ list_add_tail(&n->n_node, &pos->n_node);
+ spin_unlock(&k->k_lock);
+}
+
+EXPORT_SYMBOL_GPL(klist_add_before);
+
+
static void klist_release(struct kref * kref)

{
	struct klist_node * n = container_of(kref, struct klist_node, n_ref);
Signature · 1 line
1.5.2.4
#3 lore raw
In reply to Tejun Heo
Quoted 18 lines · Tejun Heo

klist is missing static initializers and definition helper. Add them.

---
I can't tell who's in charge of this code, so I'm including last two people who made changes and Andrew :-) This will be used by later USB mode switch support, so I'm cc'ing USB people too.

Thanks.

 include/linux/klist.h |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
include/linux/klist.h +0 -0
index 7407125..c6b697c 100644

include/linux/klist.h struct klist { · line 29

Quoted 5 lines
include/linux/klist.h +2 -0
@@ -25,6 +25,14 @@ struct klist {
 	void			(*put)(struct klist_node *);
 };
 
+#define KLIST_INIT(_name, _get, _put)					\
+	{ .k_lock	= __SPIN_LOCK_UNLOCKED(klist.k_lock),		\

May I ask you make that: __SPIN_LOCK_UNLOCKED(_name.k_lock)

Otherwise we'll end up with multiple classes that have the same name.

Quoted 9 lines
include/linux/klist.h +6 -0
+	  .k_list	= LIST_HEAD_INIT(_name.k_list),			\
+	  .get		= _get,						\
+	  .put		= _put, }
+
+#define DEFINE_KLIST(_name, _get, _put)					\
+	struct klist _name = KLIST_INIT(_name, _get, _put)
 
 extern void klist_init(struct klist * k, void (*get)(struct klist_node *),
 		       void (*put)(struct klist_node *));
author
#4 lore raw
Quoted 22 lines · Peter Zijlstra
Quoted 21 lines · Tejun Heo

klist is missing static initializers and definition helper. Add them.

---
I can't tell who's in charge of this code, so I'm including last two people who made changes and Andrew :-) This will be used by later USB mode switch support, so I'm cc'ing USB people too.

Thanks.

 include/linux/klist.h |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
include/linux/klist.h +0 -0
index 7407125..c6b697c 100644
@@ -25,6 +25,14 @@ struct klist {
 	void			(*put)(struct klist_node *);
 };
 
Quoted 6 lines

include/linux/klist.h struct klist { · line 29

Quoted 2 lines
include/linux/klist.h +2 -0
+#define KLIST_INIT(_name, _get, _put)					\
+	{ .k_lock	= __SPIN_LOCK_UNLOCKED(klist.k_lock),		\

May I ask you make that: __SPIN_LOCK_UNLOCKED(_name.k_lock)

Otherwise we'll end up with multiple classes that have the same name.

These locks don't nest so being in the same class should be okay and I was following what (at least some of) other __SPIN_LOCK_UNLOCKED users are doing. If putting these locks into separate classes is the RTTD, sure.

Thanks.

Signature · 1 line
tejun
#5 lore raw
Quoted 28 lines · Tejun Heo
Quoted 27 lines · Peter Zijlstra
Quoted 18 lines · Tejun Heo

klist is missing static initializers and definition helper. Add them.

---
I can't tell who's in charge of this code, so I'm including last two people who made changes and Andrew :-) This will be used by later USB mode switch support, so I'm cc'ing USB people too.

Thanks.

 include/linux/klist.h |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
include/linux/klist.h +0 -0
index 7407125..c6b697c 100644

include/linux/klist.h struct klist { · line 29

Quoted 5 lines
include/linux/klist.h +2 -0
@@ -25,6 +25,14 @@ struct klist {
 	void			(*put)(struct klist_node *);
 };
 
+#define KLIST_INIT(_name, _get, _put)					\
+	{ .k_lock	= __SPIN_LOCK_UNLOCKED(klist.k_lock),		\

May I ask you make that: __SPIN_LOCK_UNLOCKED(_name.k_lock)

Quoted 5 lines
Quoted 1 line

Otherwise we'll end up with multiple classes that have the same name.

These locks don't nest so being in the same class should be okay and I was following what (at least some of) other __SPIN_LOCK_UNLOCKED users are doing. If putting these locks into separate classes is the RTTD, sure.

Ah, they'll actually be in seprate classes all of the same name. So I think it is cleaner to cause them to have separate names too.

see look_up_lock_class() in kernel/lockdep.c:

        /*
         * Static locks do not have their class-keys yet - for them the key
         * is the lock object itself:
         */
        if (unlikely(!lock->key))
                lock->key = (void *)lock;
author
#6 lore raw
Quoted 5 lines · Peter Zijlstra
Quoted 1 line

These locks don't nest so being in the same class should be okay and I was following what (at least some of) other __SPIN_LOCK_UNLOCKED users are doing. If putting these locks into separate classes is the RTTD, sure.

Ah, they'll actually be in seprate classes all of the same name. So I think it is cleaner to cause them to have separate names too.

Quoted 8 lines

see look_up_lock_class() in kernel/lockdep.c:

        /*
         * Static locks do not have their class-keys yet - for them the key
         * is the lock object itself:
         */
        if (unlikely(!lock->key))
                lock->key = (void *)lock;

Ah.. I'll put change it to name. Thanks.

Signature · 1 line
tejun
#7 lore raw
Quoted 16 lines · Tejun Heo
Quoted 10 lines · Peter Zijlstra
Quoted 4 lines

These locks don't nest so being in the same class should be okay and I was following what (at least some of) other __SPIN_LOCK_UNLOCKED users are doing. If putting these locks into separate classes is the RTTD, sure.

Ah, they'll actually be in seprate classes all of the same name. So I think it is cleaner to cause them to have separate names too. see look_up_lock_class() in kernel/lockdep.c:
/*
* Static locks do not have their class-keys yet - for them the
key

Quoted 4 lines
         * is the lock object itself:
         */
        if (unlikely(!lock->key))
                lock->key = (void *)lock;
Quoted 1 line

Ah.. I'll put change it to name. Thanks.

Do you have a new revision of this patch series that I can apply to my trees?

thanks,

greg k-h

author
#8 lore raw

PATCH 1/2 klist: implement KLIST_INIT() and DEFINE_KLIST()

klist is missing static initializers and definition helper. Add them.

Cc Peter Zijlstra <[email protected]>

---
Updated to use _name.k_lock as advised.

Thanks.

include/linux/klist.h | 8 ++++++++

1 file changed, 8 insertions(+)
include/linux/klist.h +0 -0
Index: work/include/linux/klist.h
===================================================================
@@ -25,6 +25,14 @@ struct klist {
	void			(*put)(struct klist_node *);
};

+#define KLIST_INIT(_name, _get, _put) \
+ { .k_lock = __SPIN_LOCK_UNLOCKED(_name.k_lock), \

+	  .k_list	= LIST_HEAD_INIT(_name.k_list),			\
+	  .get		= _get,						\
+	  .put		= _put, }

+
+#define DEFINE_KLIST(_name, _get, _put) \
+ struct klist _name = KLIST_INIT(_name, _get, _put)

extern void klist_init(struct klist * k, void (*get)(struct klist_node *),

		       void (*put)(struct klist_node *));
#9 lore raw
Quoted 6 lines · Tejun Heo

klist is missing static initializers and definition helper. Add them.

Cc Peter Zijlstra <[email protected]>

---
Updated to use _name.k_lock as advised.

Thanks, was there a 2/2 patch in this series as well that I should be applying?

greg k-h

author
#10 lore raw
Quoted 10 lines · Greg KH
Quoted 6 lines · Tejun Heo

klist is missing static initializers and definition helper. Add them.

Cc Peter Zijlstra <[email protected]>

---
Updated to use _name.k_lock as advised.

Thanks, was there a 2/2 patch in this series as well that I should be applying?

Yeap, it's named "[PATCH] klist: implement klist_add_{after|before}()".
I forgot to add "2/2".

Thanks.

Signature · 1 line
tejun
#2 lore raw

patch klist-implement-klist_add_-after-before.patch added to gregkh-2.6 tree

In reply to Tejun Heo

This is a note to let you know that I've just added the patch titled

Subject: klist: implement klist_add_{after|before}()

to my gregkh-2.6 tree. Its filename is

klist-implement-klist_add_-after-before.patch

This tree can be found at
http://www.kernel.org/pub/linux/kernel/people/gregkh/gregkh-2.6/patches/

Quoted 1 line

From [email protected] Tue Apr 22 02:58:55 2008

From: Tejun Heo <[email protected]>
Date: Tue, 22 Apr 2008 18:58:46 +0900
Subject: klist: implement klist_add_{after|before}()
To: James Bottomley <[email protected]>, Alan Stern <[email protected]>, Andrew Morton <[email protected]>, Greg KH <[email protected]>, [email protected], Alan Cox <[email protected]>, [email protected], Linux Kernel Mailing List <[email protected]>, [email protected]
Message-ID: <[email protected]>

Add klist_add_after() and klist_add_before() which puts a new node after and before an existing node, respectively. This is useful for callers which need to keep klist ordered. Note that synchronizing between simultaneous additions for ordering is the caller's responsibility.

---
 include/linux/klist.h |    2 ++
 lib/klist.c           |   38 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+)
include/linux/klist.h +2 -0
@@ -46,6 +46,8 @@ struct klist_node {
 
 extern void klist_add_tail(struct klist_node * n, struct klist * k);
 extern void klist_add_head(struct klist_node * n, struct klist * k);
+extern void klist_add_after(struct klist_node * n, struct klist_node * pos);
+extern void klist_add_before(struct klist_node * n, struct klist_node * pos);
 
 extern void klist_del(struct klist_node * n);
 extern void klist_remove(struct klist_node * n);
lib/klist.c +38 -0
@@ -120,6 +120,44 @@ void klist_add_tail(struct klist_node * 
 EXPORT_SYMBOL_GPL(klist_add_tail);
 
 
+/**
+ *	klist_add_after - Init a klist_node and add it after an existing node
+ *	@n:	node we're adding.
+ *	@pos:	node to put @n after
+ */
+
+void klist_add_after(struct klist_node * n, struct klist_node * pos)
+{
+	struct klist *k = pos->n_klist;
+
+	klist_node_init(k, n);
+	spin_lock(&k->k_lock);
+	list_add(&n->n_node, &pos->n_node);
+	spin_unlock(&k->k_lock);
+}
+
+EXPORT_SYMBOL_GPL(klist_add_after);
+
+
+/**
+ *	klist_add_before - Init a klist_node and add it before an existing node
+ *	@n:	node we're adding.
+ *	@pos:	node to put @n after
+ */
+
+void klist_add_before(struct klist_node * n, struct klist_node * pos)
+{
+	struct klist *k = pos->n_klist;
+
+	klist_node_init(k, n);
+	spin_lock(&k->k_lock);
+	list_add_tail(&n->n_node, &pos->n_node);
+	spin_unlock(&k->k_lock);
+}
+
+EXPORT_SYMBOL_GPL(klist_add_before);
+
+
 static void klist_release(struct kref * kref)
 {
 	struct klist_node * n = container_of(kref, struct klist_node, n_ref);

Patches currently in gregkh-2.6 which might be from [email protected] are

driver-core/sysfs-add-sys-dev-char-block-to-lookup-sysfs-path-by-major-minor.patch driver-core/klist-implement-klist_add_-after-before.patch driver-core/klist-implement-klist_init-and-define_klist.patch

#11 lore raw

patch klist-implement-klist_init-and-define_klist.patch added to gregkh-2.6 tree

In reply to Tejun Heo

This is a note to let you know that I've just added the patch titled

Subject: klist: implement KLIST_INIT() and DEFINE_KLIST()

to my gregkh-2.6 tree. Its filename is

klist-implement-klist_init-and-define_klist.patch

This tree can be found at
http://www.kernel.org/pub/linux/kernel/people/gregkh/gregkh-2.6/patches/

Quoted 1 line

From [email protected] Fri Apr 25 11:19:08 2008

From: Tejun Heo <[email protected]>
Date: Sat, 26 Apr 2008 03:16:04 +0900
Subject: klist: implement KLIST_INIT() and DEFINE_KLIST()
To: Greg KH <[email protected]>
Cc: Peter Zijlstra <[email protected]>, James Bottomley <[email protected]>, Alan Stern <[email protected]>, Andrew Morton <[email protected]>, [email protected], Alan Cox <[email protected]>, [email protected], Linux Kernel Mailing List <[email protected]>, [email protected]
Message-ID: <[email protected]>

klist is missing static initializers and definition helper. Add them.

---
 include/linux/klist.h |    8 ++++++++
 1 file changed, 8 insertions(+)
include/linux/klist.h +8 -0
@@ -25,6 +25,14 @@ struct klist {
 	void			(*put)(struct klist_node *);
 };
 
+#define KLIST_INIT(_name, _get, _put)					\
+	{ .k_lock	= __SPIN_LOCK_UNLOCKED(_name.k_lock),		\
+	  .k_list	= LIST_HEAD_INIT(_name.k_list),			\
+	  .get		= _get,						\
+	  .put		= _put, }
+
+#define DEFINE_KLIST(_name, _get, _put)					\
+	struct klist _name = KLIST_INIT(_name, _get, _put)
 
 extern void klist_init(struct klist * k, void (*get)(struct klist_node *),
 		       void (*put)(struct klist_node *));

Patches currently in gregkh-2.6 which might be from [email protected] are

driver-core/sysfs-add-sys-dev-char-block-to-lookup-sysfs-path-by-major-minor.patch driver-core/klist-implement-klist_add_-after-before.patch driver-core/klist-implement-klist_init-and-define_klist.patch