* [PATCH net-2.6.26 2/5][SOCK]: Introduce a percpu inuse counters array (v2).
@ 2008-03-28 12:33 Pavel Emelyanov
2008-03-28 17:17 ` Eric Dumazet
0 siblings, 1 reply; 3+ messages in thread
From: Pavel Emelyanov @ 2008-03-28 12:33 UTC (permalink / raw)
To: David Miller; +Cc: Eric Dumazet, Linux Netdev List
And redirect sock_prot_inuse_add and _get to use one.
As far as the dereferences are concerned. Before the patch we made
1 dereference to proto->inuse.add call, the call itself and then
called the __get_cpu_var() on a static variable. After the patch we
make a direct call, then one dereference to proto->inuse_idx and
then the same __get_cpu_var() on a still static variable. So this
patch doesn't seem to produce performance penalty on SMP.
This is not per-net yet, but I will deliberately make NET_NS=y case
separated from NET_NS=n one, since it'll cost us one-or-two more
dereferences to get the struct net and the inuse counter.
Signed-off-by: Pavel Emelyanov <xemul@openvz.org>
---
include/net/sock.h | 13 +++++--------
net/core/sock.c | 22 ++++++++++++++++++++++
2 files changed, 27 insertions(+), 8 deletions(-)
diff --git a/include/net/sock.h b/include/net/sock.h
index abc6341..ebf9552 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -639,18 +639,15 @@ static inline void sk_refcnt_debug_release(const struct sock *sk)
# define DEFINE_PROTO_INUSE(NAME) DEFINE_PCOUNTER(NAME)
# define REF_PROTO_INUSE(NAME) PCOUNTER_MEMBER_INITIALIZER(NAME, .inuse)
/* Called with local bh disabled */
-static inline void sock_prot_inuse_add(struct proto *prot, int inc)
-{
- pcounter_add(&prot->inuse, inc);
-}
+extern void sock_prot_inuse_add(struct proto *prot, int inc);
+
static inline int sock_prot_inuse_init(struct proto *proto)
{
return pcounter_alloc(&proto->inuse);
}
-static inline int sock_prot_inuse_get(struct proto *proto)
-{
- return pcounter_getval(&proto->inuse);
-}
+
+extern int sock_prot_inuse_get(struct proto *proto);
+
static inline void sock_prot_inuse_free(struct proto *proto)
{
pcounter_free(&proto->inuse);
diff --git a/net/core/sock.c b/net/core/sock.c
index 7d2c8ad..174c64b 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -1942,8 +1942,30 @@ static LIST_HEAD(proto_list);
#ifdef CONFIG_PROC_FS
#define PROTO_INUSE_NR 64 /* should be enough for the first time */
+struct prot_inuse {
+ int val[PROTO_INUSE_NR];
+};
static DECLARE_BITMAP(proto_inuse_idx, PROTO_INUSE_NR);
+static DEFINE_PER_CPU(struct prot_inuse, prot_inuse);
+
+void sock_prot_inuse_add(struct proto *prot, int val)
+{
+ __get_cpu_var(prot_inuse).val[prot->inuse_idx] += val;
+}
+EXPORT_SYMBOL_GPL(sock_prot_inuse_add);
+
+int sock_prot_inuse_get(struct proto *prot)
+{
+ int cpu, idx = prot->inuse_idx;
+ int res = 0;
+
+ for_each_possible_cpu(cpu)
+ res += per_cpu(prot_inuse, cpu).val[idx];
+
+ return res >= 0 ? res : 0;
+}
+EXPORT_SYMBOL_GPL(sock_prot_inuse_get);
static void assign_proto_idx(struct proto *prot)
{
--
1.5.3.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net-2.6.26 2/5][SOCK]: Introduce a percpu inuse counters array (v2).
2008-03-28 12:33 [PATCH net-2.6.26 2/5][SOCK]: Introduce a percpu inuse counters array (v2) Pavel Emelyanov
@ 2008-03-28 17:17 ` Eric Dumazet
2008-03-28 23:40 ` David Miller
0 siblings, 1 reply; 3+ messages in thread
From: Eric Dumazet @ 2008-03-28 17:17 UTC (permalink / raw)
To: Pavel Emelyanov; +Cc: David Miller, Linux Netdev List
Pavel Emelyanov a écrit :
> And redirect sock_prot_inuse_add and _get to use one.
>
> As far as the dereferences are concerned. Before the patch we made
> 1 dereference to proto->inuse.add call, the call itself and then
> called the __get_cpu_var() on a static variable. After the patch we
> make a direct call, then one dereference to proto->inuse_idx and
> then the same __get_cpu_var() on a still static variable. So this
> patch doesn't seem to produce performance penalty on SMP.
>
> This is not per-net yet, but I will deliberately make NET_NS=y case
> separated from NET_NS=n one, since it'll cost us one-or-two more
> dereferences to get the struct net and the inuse counter.
>
> Signed-off-by: Pavel Emelyanov <xemul@openvz.org>
>
>
Acked-by: Eric Dumazet <dada1@cosmosbay.com>
> ---
> include/net/sock.h | 13 +++++--------
> net/core/sock.c | 22 ++++++++++++++++++++++
> 2 files changed, 27 insertions(+), 8 deletions(-)
>
> diff --git a/include/net/sock.h b/include/net/sock.h
> index abc6341..ebf9552 100644
> --- a/include/net/sock.h
> +++ b/include/net/sock.h
> @@ -639,18 +639,15 @@ static inline void sk_refcnt_debug_release(const struct sock *sk)
> # define DEFINE_PROTO_INUSE(NAME) DEFINE_PCOUNTER(NAME)
> # define REF_PROTO_INUSE(NAME) PCOUNTER_MEMBER_INITIALIZER(NAME, .inuse)
> /* Called with local bh disabled */
> -static inline void sock_prot_inuse_add(struct proto *prot, int inc)
> -{
> - pcounter_add(&prot->inuse, inc);
> -}
> +extern void sock_prot_inuse_add(struct proto *prot, int inc);
> +
> static inline int sock_prot_inuse_init(struct proto *proto)
> {
> return pcounter_alloc(&proto->inuse);
> }
> -static inline int sock_prot_inuse_get(struct proto *proto)
> -{
> - return pcounter_getval(&proto->inuse);
> -}
> +
> +extern int sock_prot_inuse_get(struct proto *proto);
> +
> static inline void sock_prot_inuse_free(struct proto *proto)
> {
> pcounter_free(&proto->inuse);
> diff --git a/net/core/sock.c b/net/core/sock.c
> index 7d2c8ad..174c64b 100644
> --- a/net/core/sock.c
> +++ b/net/core/sock.c
> @@ -1942,8 +1942,30 @@ static LIST_HEAD(proto_list);
>
> #ifdef CONFIG_PROC_FS
> #define PROTO_INUSE_NR 64 /* should be enough for the first time */
> +struct prot_inuse {
> + int val[PROTO_INUSE_NR];
> +};
>
> static DECLARE_BITMAP(proto_inuse_idx, PROTO_INUSE_NR);
> +static DEFINE_PER_CPU(struct prot_inuse, prot_inuse);
> +
> +void sock_prot_inuse_add(struct proto *prot, int val)
> +{
> + __get_cpu_var(prot_inuse).val[prot->inuse_idx] += val;
> +}
> +EXPORT_SYMBOL_GPL(sock_prot_inuse_add);
> +
> +int sock_prot_inuse_get(struct proto *prot)
> +{
> + int cpu, idx = prot->inuse_idx;
> + int res = 0;
> +
> + for_each_possible_cpu(cpu)
> + res += per_cpu(prot_inuse, cpu).val[idx];
> +
> + return res >= 0 ? res : 0;
> +}
> +EXPORT_SYMBOL_GPL(sock_prot_inuse_get);
>
> static void assign_proto_idx(struct proto *prot)
> {
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net-2.6.26 2/5][SOCK]: Introduce a percpu inuse counters array (v2).
2008-03-28 17:17 ` Eric Dumazet
@ 2008-03-28 23:40 ` David Miller
0 siblings, 0 replies; 3+ messages in thread
From: David Miller @ 2008-03-28 23:40 UTC (permalink / raw)
To: dada1; +Cc: xemul, netdev
From: Eric Dumazet <dada1@cosmosbay.com>
Date: Fri, 28 Mar 2008 18:17:49 +0100
> Pavel Emelyanov a écrit :
> > And redirect sock_prot_inuse_add and _get to use one.
> >
> > As far as the dereferences are concerned. Before the patch we made
> > 1 dereference to proto->inuse.add call, the call itself and then
> > called the __get_cpu_var() on a static variable. After the patch we
> > make a direct call, then one dereference to proto->inuse_idx and
> > then the same __get_cpu_var() on a still static variable. So this
> > patch doesn't seem to produce performance penalty on SMP.
> >
> > This is not per-net yet, but I will deliberately make NET_NS=y case
> > separated from NET_NS=n one, since it'll cost us one-or-two more
> > dereferences to get the struct net and the inuse counter.
> >
> > Signed-off-by: Pavel Emelyanov <xemul@openvz.org>
> >
> >
>
> Acked-by: Eric Dumazet <dada1@cosmosbay.com>
Applied.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-03-28 23:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-03-28 12:33 [PATCH net-2.6.26 2/5][SOCK]: Introduce a percpu inuse counters array (v2) Pavel Emelyanov
2008-03-28 17:17 ` Eric Dumazet
2008-03-28 23:40 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).