Re: [PATCH RFC V2 2/2] net: Optimize snmp stat aggregation by walking all the percpu data at once

From: Joe Perches
Date: Fri Aug 28 2015 - 15:21:05 EST


On Fri, 2015-08-28 at 11:24 -0700, David Miller wrote:
> From: Raghavendra K T <raghavendra.kt@xxxxxxxxxxxxxxxxxx>
> Date: Fri, 28 Aug 2015 12:09:52 +0530
>
> > On 08/28/2015 12:08 AM, David Miller wrote:
> >> From: Raghavendra K T <raghavendra.kt@xxxxxxxxxxxxxxxxxx>
> >> Date: Wed, 26 Aug 2015 23:07:33 +0530
> >>
> >>> @@ -4641,10 +4647,12 @@ static inline void __snmp6_fill_stats64(u64
> >>> *stats, void __percpu *mib,
> >>> static void snmp6_fill_stats(u64 *stats, struct inet6_dev *idev, int
> >>> attrtype,
> >>> int bytes)
> >>> {
> >>> + u64 buff[IPSTATS_MIB_MAX] = {0,};
> >>> +
> ...
> > hope you wanted to know the overhead than to change the current
> > patch. please let me know..
>
> I want you to change that variable initializer to an explicit memset().
>
> The compiler is emitting a memset() or similar _anyways_.
>
> Not because it will have any impact at all upon performance, but because
> of how it looks to people trying to read and understand the code.

I don't read it as particularly different.

There are > 100 uses of the not quite a memset initialization
style using "= { <0,> }" in net/

$ git grep -E "=\s*\{\s*0?\s*,?\s*\}" net | wc -l
138

There is a difference though if a struct is copied to
user-space as a {} initialization only guarantees that
struct members are initialized to 0 where memset also
zeros any alignment padding.

Maybe a checkpatch rule like this?
---
scripts/checkpatch.pl | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index e14dcdb..f79e5c9 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -3237,6 +3237,13 @@ sub process {
next;
}

+# check for non-global initializations that could be memset
+ if ($realfile =~ m@^(drivers/net/|net/)@ &&
+ $sline =~ /^.\s+$Declare\s*$Ident\s*=\s*\{\s*0?\s*,?\s*\}/) {
+ CHK("BRACE_INITIALIZATION",
+ "Prefer an explicit memset to a declaration initialization\n" . $herecurr);
+ }
+
# check for initialisation to aggregates open brace on the next line
if ($line =~ /^.\s*{/ &&
$prevline =~ /(?:^|[^=])=\s*$/) {



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/