Skip to contentSkip to conversation

: Enumerate struct proto-s to facilitate percpu inuse accounting.

PATCH In review Pavel Emelyanov 2 participants 3 messages Mar 28, 2008

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/5 : Enumerate struct proto-s to facilitate percpu inuse accounting.

This add the inuse_idx to struct proto and generates one in proto_register. The ++ in generator is protected with write-locked proto_list_lock.

---
 include/net/sock.h |    1 +
 net/core/sock.c    |   10 ++++++++++
 2 files changed, 11 insertions(+), 0 deletions(-)
include/net/sock.h +1 -0
index 1c9d059..abc6341 100644
@@ -562,6 +562,7 @@ struct proto {
 
 	/* Keeping track of sockets in use */
 #ifdef CONFIG_PROC_FS
+	unsigned int		inuse_idx;
 	struct pcounter		inuse;
 #endif
 
net/core/sock.c +10 -0
index 3ee9506..a7faf30 100644
@@ -1940,6 +1940,15 @@ EXPORT_SYMBOL(sk_common_release);
 static DEFINE_RWLOCK(proto_list_lock);
 static LIST_HEAD(proto_list);
 
+static void assign_proto_idx(struct proto *prot)
+{
+#ifdef CONFIG_PROC_FS
+	static unsigned int idx = 0;
+
+	prot->inuse_idx = idx++;
+#endif
+}
+
 int proto_register(struct proto *prot, int alloc_slab)
 {
 	char *request_sock_slab_name = NULL;
@@ -2000,6 +2009,7 @@ int proto_register(struct proto *prot, int alloc_slab)
 
 	write_lock(&proto_list_lock);
 	list_add(&prot->node, &proto_list);
+	assign_proto_idx(prot);
 	write_unlock(&proto_list_lock);
 	return 0;
 
Signature · 1 line
1.5.3.4
#1 lore raw
Quoted 27 lines · Pavel Emelyanov

This add the inuse_idx to struct proto and generates one in proto_register. The ++ in generator is protected with write-locked proto_list_lock.

---
 include/net/sock.h |    1 +
 net/core/sock.c    |   10 ++++++++++
 2 files changed, 11 insertions(+), 0 deletions(-)
include/net/sock.h +1 -0
index 1c9d059..abc6341 100644
@@ -562,6 +562,7 @@ struct proto {
 
 	/* Keeping track of sockets in use */
 #ifdef CONFIG_PROC_FS
+	unsigned int		inuse_idx;
 	struct pcounter		inuse;
 #endif
 
net/core/sock.c +0 -0
index 3ee9506..a7faf30 100644

net/core/sock.c EXPORT_SYMBOL(sk_common_release); · line 1948

Quoted 9 lines
net/core/sock.c +5 -0
@@ -1940,6 +1940,15 @@ EXPORT_SYMBOL(sk_common_release);
 static DEFINE_RWLOCK(proto_list_lock);
 static LIST_HEAD(proto_list);
 
+static void assign_proto_idx(struct proto *prot)
+{
+#ifdef CONFIG_PROC_FS
+	static unsigned int idx = 0;
+
 

I believe some protocols can be registered, then unregistered, then re-registered (module loads, unloads, ...)

So you probably want to use a bitmap instead of a counter that will eventually reach PROTO_INUSE_NR

assign_proto_idx() should find a zero bit, and you should free this bit at proto_unregister() time

Quoted 16 lines
net/core/sock.c +4 -0
+	prot->inuse_idx = idx++;
+#endif
+}
+
 int proto_register(struct proto *prot, int alloc_slab)
 {
net/core/sock.c +1 -0
 	char *request_sock_slab_name = NULL;
@@ -2000,6 +2009,7 @@ int proto_register(struct proto *prot, int alloc_slab)
 
 	write_lock(&proto_list_lock);
 	list_add(&prot->node, &proto_list);
+	assign_proto_idx(prot);
 	write_unlock(&proto_list_lock);
 	return 0;
 
#2 lore raw
Quoted 31 lines · Eric Dumazet
Quoted 30 lines · Pavel Emelyanov

This add the inuse_idx to struct proto and generates one in proto_register. The ++ in generator is protected with write-locked proto_list_lock.

---
 include/net/sock.h |    1 +
 net/core/sock.c    |   10 ++++++++++
 2 files changed, 11 insertions(+), 0 deletions(-)
include/net/sock.h +1 -0
index 1c9d059..abc6341 100644
@@ -562,6 +562,7 @@ struct proto {
 
 	/* Keeping track of sockets in use */
 #ifdef CONFIG_PROC_FS
+	unsigned int		inuse_idx;
 	struct pcounter		inuse;
 #endif
 
net/core/sock.c +0 -0
index 3ee9506..a7faf30 100644
@@ -1940,6 +1940,15 @@ EXPORT_SYMBOL(sk_common_release);
 static DEFINE_RWLOCK(proto_list_lock);
 static LIST_HEAD(proto_list);
 
Quoted 8 lines

net/core/sock.c EXPORT_SYMBOL(sk_common_release);

Quoted 6 lines
net/core/sock.c +5 -0
+static void assign_proto_idx(struct proto *prot)
+{
+#ifdef CONFIG_PROC_FS
+	static unsigned int idx = 0;
+
 

I believe some protocols can be registered, then unregistered, then re-registered (module loads, unloads, ...)

Well yes :) I found this soon after I'd sent this set. If you don't have other objections I'll send the v2 do Dave.

Quoted 31 lines

So you probably want to use a bitmap instead of a counter that will eventually reach PROTO_INUSE_NR

assign_proto_idx() should find a zero bit, and you should free this bit at proto_unregister() time

Quoted 9 lines
net/core/sock.c +4 -0
+	prot->inuse_idx = idx++;
+#endif
+}
+
 int proto_register(struct proto *prot, int alloc_slab)
 {
net/core/sock.c +0 -0
 	char *request_sock_slab_name = NULL;

net/core/sock.c int proto_register(struct proto *prot, int alloc_slab) · line 2015

Quoted 7 lines
net/core/sock.c +1 -0
@@ -2000,6 +2009,7 @@ int proto_register(struct proto *prot, int alloc_slab)
 
 	write_lock(&proto_list_lock);
 	list_add(&prot->node, &proto_list);
+	assign_proto_idx(prot);
 	write_unlock(&proto_list_lock);
 	return 0;
 

--
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html