<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux/lib/vsprintf.c, branch v2.6.25</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/
</subtitle>
<id>https://git.shady.money/linux/atom?h=v2.6.25</id>
<link rel='self' href='https://git.shady.money/linux/atom?h=v2.6.25'/>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/'/>
<updated>2008-02-24T01:12:14Z</updated>
<entry>
<title>lib/vsprintf.c: fix bug omitting minus sign of numbers (module_param)</title>
<updated>2008-02-24T01:12:14Z</updated>
<author>
<name>Hoang-Nam Nguyen</name>
<email>hnguyen@linux.vnet.ibm.com</email>
</author>
<published>2008-02-23T23:23:37Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=4f9d5f4a353440f2265781bfa641587964901861'/>
<id>urn:sha1:4f9d5f4a353440f2265781bfa641587964901861</id>
<content type='text'>
lib/vsprintf.c: Fix bug omitting minus sign of numbers (module_param)

Signed-off-by: Hoang-Nam Nguyen &lt;hnguyen@de.ibm.com&gt;
Cc: Yi Yang &lt;yi.y.yang@intel.com&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>x86: trivial printk optimizations</title>
<updated>2008-02-09T22:24:09Z</updated>
<author>
<name>Denys Vlasenko</name>
<email>vda.linux@googlemail.com</email>
</author>
<published>2008-02-09T22:24:09Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=9b706aee7d92d6ac3002547aea12e3eaa0a750ae'/>
<id>urn:sha1:9b706aee7d92d6ac3002547aea12e3eaa0a750ae</id>
<content type='text'>
In arch/x86/boot/printf.c gets rid of unused tail of digits: const char
*digits = "0123456789abcdefghijklmnopqrstuvwxyz"; (we are using 0-9a-f
only)

Uses smaller/faster lowercasing (by ORing with 0x20)
if we know that we work on numbers/digits. Makes
strtoul smaller, and also we are getting rid of

  static const char small_digits[] = "0123456789abcdefx";
  static const char large_digits[] = "0123456789ABCDEFX";

since this works equally well:

  static const char digits[16] = "0123456789ABCDEF";

Size savings:

$ size vmlinux.org vmlinux
   text    data     bss     dec     hex filename
 877320  112252   90112 1079684  107984 vmlinux.org
 877048  112252   90112 1079412  107874 vmlinux

It may be also a tiny bit faster because code has less
branches now, but I doubt it is measurable.

[ hugh@veritas.com: uppercase pointers fix ]

Signed-off-by: Denys Vlasenko &lt;vda.linux@googlemail.com&gt;
Cc: Andi Kleen &lt;ak@suse.de&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Ingo Molnar &lt;mingo@elte.hu&gt;
Signed-off-by: Thomas Gleixner &lt;tglx@linutronix.de&gt;
</content>
</entry>
<entry>
<title>Add new string functions strict_strto* and convert kernel params to use them</title>
<updated>2008-02-08T17:22:41Z</updated>
<author>
<name>Yi Yang</name>
<email>yi.y.yang@intel.com</email>
</author>
<published>2008-02-08T12:21:57Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=06b2a76d25d3cfbd14680021c1d356c91be6904e'/>
<id>urn:sha1:06b2a76d25d3cfbd14680021c1d356c91be6904e</id>
<content type='text'>
Currently, for every sysfs node, the callers will be responsible for
implementing store operation, so many many callers are doing duplicate
things to validate input, they have the same mistakes because they are
calling simple_strtol/ul/ll/uul, especially for module params, they are
just numeric, but you can echo such values as 0x1234xxx, 07777888 and
1234aaa, for these cases, module params store operation just ignores
succesive invalid char and converts prefix part to a numeric although input
is acctually invalid.

This patch tries to fix the aforementioned issues and implements
strict_strtox serial functions, kernel/params.c uses them to strictly
validate input, so module params will reject such values as 0x1234xxxx and
returns an error:

write error: Invalid argument

Any modules which export numeric sysfs node can use strict_strtox instead of
simple_strtox to reject any invalid input.

Here are some test results:

Before applying this patch:

[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 0x1000 &gt; /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 0x1000g &gt; /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 0x1000gggggggg &gt; /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 010000 &gt; /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 0100008 &gt; /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 010000aaaaa &gt; /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]#

After applying this patch:

[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 0x1000 &gt; /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 0x1000g &gt; /sys/module/e1000/parameters/copybreak
-bash: echo: write error: Invalid argument
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 0x1000gggggggg &gt; /sys/module/e1000/parameters/copybreak
-bash: echo: write error: Invalid argument
[root@yangyi-dev /]# echo 010000 &gt; /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# echo 0100008 &gt; /sys/module/e1000/parameters/copybreak
-bash: echo: write error: Invalid argument
[root@yangyi-dev /]# echo 010000aaaaa &gt; /sys/module/e1000/parameters/copybreak
-bash: echo: write error: Invalid argument
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo -n 4096 &gt; /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]#

[akpm@linux-foundation.org: fix compiler warnings]
[akpm@linux-foundation.org: fix off-by-one found by tiwai@suse.de]
Signed-off-by: Yi Yang &lt;yi.y.yang@intel.com&gt;
Cc: Greg KH &lt;greg@kroah.com&gt;
Cc: "Randy.Dunlap" &lt;rdunlap@xenotime.net&gt;
Cc: Takashi Iwai &lt;tiwai@suse.de&gt;
Cc: Hugh Dickins &lt;hugh@veritas.com&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>lib: move kasprintf to a separate file</title>
<updated>2007-07-31T22:39:39Z</updated>
<author>
<name>Sam Ravnborg</name>
<email>sam@ravnborg.org</email>
</author>
<published>2007-07-31T07:38:13Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=96e3e18eed3b48f6d4377dee0326a106e8a04569'/>
<id>urn:sha1:96e3e18eed3b48f6d4377dee0326a106e8a04569</id>
<content type='text'>
kasprintf pulls in kmalloc which proved to be fatal for at least
bootimage target on alpha.
Move it to a separate file so only users of kasprintf are exposed
to the dependency on kmalloc.

Signed-off-by: Sam Ravnborg &lt;sam@ravnborg.org&gt;
Cc: Jeremy Fitzhardinge &lt;jeremy@goop.org&gt;
Cc: Meelis Roos &lt;mroos@linux.ee&gt;
Cc: Richard Henderson &lt;rth@twiddle.net&gt;
Cc: Ivan Kokshaysky &lt;ink@jurassic.park.msu.ru&gt;
Cc: Jay Estabrook &lt;jay.estabrook@hp.com&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>vsprintf.c: optimizing, part 2: base 10 conversion speedup, v2</title>
<updated>2007-07-16T16:05:52Z</updated>
<author>
<name>Denis Vlasenko</name>
<email>vda.linux@googlemail.com</email>
</author>
<published>2007-07-16T06:41:56Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=4277eedd7908a0ca8b66fad46ee76b0ad96e6ef2'/>
<id>urn:sha1:4277eedd7908a0ca8b66fad46ee76b0ad96e6ef2</id>
<content type='text'>
Optimize integer-to-string conversion in vsprintf.c for base 10.  This is
by far the most used conversion, and in some use cases it impacts
performance.  For example, top reads /proc/$PID/stat for every process, and
with 4000 processes decimal conversion alone takes noticeable time.

Using code from

http://www.cs.uiowa.edu/~jones/bcd/decimal.html
(with permission from the author, Douglas W. Jones)

binary-to-decimal-string conversion is done in groups of five digits at
once, using only additions/subtractions/shifts (with -O2; -Os throws in
some multiply instructions).

On i386 arch gcc 4.1.2 -O2 generates ~500 bytes of code.

This patch is run tested. Userspace benchmark/test is also attached.
I tested it on PIII and AMD64 and new code is generally ~2.5 times
faster. On AMD64:

# ./vsprintf_verify-O2
Original decimal conv: .......... 151 ns per iteration
Patched decimal conv:  .......... 62 ns per iteration
Testing correctness
12895992590592 ok...        [Ctrl-C]
# ./vsprintf_verify-O2
Original decimal conv: .......... 151 ns per iteration
Patched decimal conv:  .......... 62 ns per iteration
Testing correctness
26025406464 ok...        [Ctrl-C]

More realistic test: top from busybox project was modified to
report how many us it took to scan /proc (this does not account
any processing done after that, like sorting process list),
and then I test it with 4000 processes:

#!/bin/sh
i=4000
while test $i != 0; do
    sleep 30 &amp;
    let i--
done
busybox top -b -n3 &gt;/dev/null

on unpatched kernel:

top: 4120 processes took 102864 microseconds to scan
top: 4120 processes took 91757 microseconds to scan
top: 4120 processes took 92517 microseconds to scan
top: 4120 processes took 92581 microseconds to scan

on patched kernel:

top: 4120 processes took 75460 microseconds to scan
top: 4120 processes took 66451 microseconds to scan
top: 4120 processes took 67267 microseconds to scan
top: 4120 processes took 67618 microseconds to scan

The speedup comes from much faster generation of /proc/PID/stat
by sprintf() calls inside the kernel.

Signed-off-by: Douglas W Jones &lt;jones@cs.uiowa.edu&gt;
Signed-off-by: Denys Vlasenko &lt;vda.linux@googlemail.com&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>vsprintf.c: optimizing, part 1 (easy and obvious stuff)</title>
<updated>2007-07-16T16:05:52Z</updated>
<author>
<name>Denis Vlasenko</name>
<email>vda.linux@googlemail.com</email>
</author>
<published>2007-07-16T06:41:54Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=b39a734097d5095d63eb9c709a6aaf965633bb01'/>
<id>urn:sha1:b39a734097d5095d63eb9c709a6aaf965633bb01</id>
<content type='text'>
* There is no point in having full "0...9a...z" constant vector,
  if we use only "0...9a...f" (and "x" for "0x").

* Post-decrement usually needs a few more instructions, so use
  pre decrement instead where makes sense:
-       while (i &lt; precision--) {
+       while (i &lt;= --precision) {

* if base != 10 (=&gt; base 8 or 16), we can avoid using division
  in a loop and use mask/shift, obtaining much faster conversion.
  (More complex optimization for base 10 case is in the second patch).

Overall, size vsprintf.o shows ~80 bytes smaller text section
with this patch applied.

Signed-off-by: Douglas W Jones &lt;jones@cs.uiowa.edu&gt;
Signed-off-by: Denys Vlasenko &lt;vda.linux@googlemail.com&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>fix sscanf %n match at end of input string</title>
<updated>2007-05-08T18:15:05Z</updated>
<author>
<name>Johannes Berg</name>
<email>johannes@sipsolutions.net</email>
</author>
<published>2007-05-08T07:27:20Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=c6b40d16d1cfa1a01158049bb887a9bbe48ef7ba'/>
<id>urn:sha1:c6b40d16d1cfa1a01158049bb887a9bbe48ef7ba</id>
<content type='text'>
I was playing with some code that sometimes got a string where a %n
match should have been done where the input string ended, for example
like this:

  sscanf("abc123", "abc%d%n", &amp;a, &amp;n);  /* doesn't work */
  sscanf("abc123a", "abc%d%n", &amp;a, &amp;n); /* works */

However, the scanf function in the kernel doesn't convert the %n in that
case because it has already matched the complete input after %d and just
completely stops matching then. This patch fixes that.

[akpm@linux-foundation.org: cleanups]
Signed-off-by: Johannes Berg &lt;johannes@sipsolutions.net&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>Add kvasprintf()</title>
<updated>2007-04-30T23:40:40Z</updated>
<author>
<name>Jeremy Fitzhardinge</name>
<email>jeremy@goop.org</email>
</author>
<published>2007-04-30T22:09:56Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=11443ec7d9286dd25663516436a14edfb5f43857'/>
<id>urn:sha1:11443ec7d9286dd25663516436a14edfb5f43857</id>
<content type='text'>
Add a kvasprintf() function to complement kasprintf().

No in-tree users yet, but I have some coming up.

[akpm@linux-foundation.org: EXPORT it]
Signed-off-by: Jeremy Fitzhardinge &lt;jeremy@xensource.com&gt;
Cc: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Cc: Keir Fraser &lt;keir@xensource.com&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>[PATCH] scnprintf(): fix a comment</title>
<updated>2007-02-12T17:48:28Z</updated>
<author>
<name>Martin Peschke</name>
<email>mp3@de.ibm.com</email>
</author>
<published>2007-02-12T08:51:56Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=ea6f3281a145d16ed53e88b0627f78d5cde6068f'/>
<id>urn:sha1:ea6f3281a145d16ed53e88b0627f78d5cde6068f</id>
<content type='text'>
The return value of scnprintf() never exceeds @size.

Signed-off-by: Martin Peschke &lt;mp3@de.ibm.com&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>[PATCH] Numerous fixes to kernel-doc info in source files.</title>
<updated>2007-02-11T18:51:32Z</updated>
<author>
<name>Robert P. J. Day</name>
<email>rpjday@mindspring.com</email>
</author>
<published>2007-02-10T09:45:59Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=72fd4a35a824331d7a0f4168d7576502d95d34b3'/>
<id>urn:sha1:72fd4a35a824331d7a0f4168d7576502d95d34b3</id>
<content type='text'>
A variety of (mostly) innocuous fixes to the embedded kernel-doc content in
source files, including:

  * make multi-line initial descriptions single line
  * denote some function names, constants and structs as such
  * change erroneous opening '/*' to '/**' in a few places
  * reword some text for clarity

Signed-off-by: Robert P. J. Day &lt;rpjday@mindspring.com&gt;
Cc: "Randy.Dunlap" &lt;rdunlap@xenotime.net&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
</feed>
