02 Oct, 2009

1 commit

  • When using %*s, sscanf should honor conversion specifiers immediately
    following the %*s. For example, the following code should find the
    position of the end of the string "hello".

    int end;
    char buf[] = "hello world";
    sscanf(buf, "%*s%n", &end);
    printf("%d\n", end);

    Ideally, sscanf would advance the fmt and str pointers the same as it
    would without the *, but the code for that is rather complicated and is
    not included in the patch.

    Signed-off-by: Andy Spencer
    Acked-by: WANG Cong
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Andy Spencer
     

25 Sep, 2009

1 commit


23 Sep, 2009

1 commit


22 Sep, 2009

1 commit


18 Sep, 2009

2 commits

  • Remove the duplicate comment of bstr_printf that is the same as the
    vsnprintf.

    Add the 's' option to the comment for the pointer function. This is
    more of an internal function so the little duplication of the comment
    here is OK.

    Reported-by: Zhaolei
    Cc: Linus Torvalds
    Signed-off-by: Steven Rostedt

    Steven Rostedt
     
  • On PowerPC64 function pointers do not point directly at the functions,
    but instead point to pointers to the functions. The output of %pF expects
    to point to a pointer to the function, whereas %pS will show the function
    itself.

    mcount returns the direct pointer to the function and not the pointer to
    the pointer. Thus %pS must be used to show this. The function tracer
    requires printing of the functions without offsets and uses the %pf
    instead.

    %pF produces run_local_timers+0x4/0x1f
    %pf produces just run_local_timers

    For PowerPC64, we need to use the direct pointer, and we only have
    %pS which will produce .run_local_timers+0x4/0x1f

    This patch creates a %ps that matches the %pf as %pS matches %pF.

    Cc: Linus Torvalds
    Cc: Zhao Lei
    Acked-by: Benjamin Herrenschmidt
    Signed-off-by: Steven Rostedt

    Steven Rostedt
     

29 Aug, 2009

1 commit


30 Apr, 2009

1 commit

  • A printf format specifier which would allow us to print a pure
    function name has been suggested by Andrew Morton a couple of
    months ago.

    The current %pF is very convenient to print a function symbol,
    but often we only want to print the name of the function, without
    its asm offset.

    That's what %pf does in this patch. The lowecase f has been chosen
    for its intuitive meaning of a 'weak kind of %pF'.

    The support for this new format would be welcome by the tracing code
    where the need to print pure function names is often needed. This is
    also true for other parts of the kernel:

    $ git-grep -E "kallsyms_lookup\(.+?\)"
    arch/blackfin/kernel/traps.c: symname = kallsyms_lookup(address, &symsize, &offset, &modname, namebuf);
    arch/powerpc/xmon/xmon.c: name = kallsyms_lookup(pc, &size, &offset, NULL, tmpstr);
    arch/sh/kernel/cpu/sh5/unwind.c: sym = kallsyms_lookup(pc, NULL, &offset, NULL, namebuf);
    arch/x86/kernel/ftrace.c: kallsyms_lookup((unsigned long) syscall, NULL, NULL, NULL, str);
    kernel/kprobes.c: sym = kallsyms_lookup((unsigned long)p->addr, NULL,
    kernel/lockdep.c: return kallsyms_lookup((unsigned long)key, NULL, NULL, NULL, str);
    kernel/trace/ftrace.c: kallsyms_lookup(rec->ip, NULL, NULL, NULL, str);
    kernel/trace/ftrace.c: kallsyms_lookup(rec->ip, NULL, NULL, NULL, str);
    kernel/trace/ftrace.c: kallsyms_lookup((unsigned long)rec->ops->func, NULL, NULL, NULL, str);
    kernel/trace/ftrace.c: kallsyms_lookup(rec->ip, NULL, NULL, NULL, str);
    kernel/trace/ftrace.c: kallsyms_lookup(rec->ip, NULL, NULL, NULL, str);
    kernel/trace/ftrace.c: kallsyms_lookup(rec->ip, NULL, NULL, &modname, str);
    kernel/trace/ftrace.c: kallsyms_lookup(*ptr, NULL, NULL, NULL, str);
    kernel/trace/trace_functions.c: kallsyms_lookup(ip, NULL, NULL, NULL, str);
    kernel/trace/trace_output.c: kallsyms_lookup(address, NULL, NULL, NULL, str);

    Changes in v2:

    - Add the explanation of the %pf role for vsnprintf() and bstr_printf()

    - Change the comments by dropping the "asm offset" notion and only
    define the %pf against the actual function offset notion.

    Signed-off-by: Frederic Weisbecker
    Acked-by: Mike Frysinger
    Cc: Linus Torvalds
    Cc: Zhaolei
    Cc: Tom Zanussi
    Cc: Li Zefan
    Cc: Andrew Morton
    Cc: Steven Rostedt
    LKML-Reference:
    Signed-off-by: Ingo Molnar

    Frederic Weisbecker
     

08 Apr, 2009

2 commits

  • Impact: new feature, extend vsprintf format strings

    hh is used as length modifier for signed char or unsigned char.
    It is supported by glibc, we add kernel support now.

    Signed-off-by: Zhao Lei
    Acked-by: Lai Jiangshan
    Acked-by: Frederic Weisbecker
    Cc: torvalds@linux-foundation.org
    Cc: Steven Rostedt
    LKML-Reference:
    Signed-off-by: Ingo Molnar

    Zhaolei
     
  • printk("%Q");

    Output before patch: %QQ
    Output after patch: %Q

    Signed-off-by: Zhao Lei
    Acked-by: Lai Jiangshan
    Acked-by: Frederic Weisbecker
    Cc: torvalds@linux-foundation.org
    Cc: Steven Rostedt
    LKML-Reference:
    Signed-off-by: Ingo Molnar

    Zhaolei
     

14 Mar, 2009

2 commits


10 Mar, 2009

1 commit

  • Sitsofe Wheeler found and bisected that while unifying the
    vsprintf format decoding in:

    fef20d9: vsprintf: unify the format decoding layer for its 3 users

    The sign flag has been dropped out in favour of
    precise types (ie: LONG/ULONG).

    But the format helper number() still needs this flag to keep track of
    the signedness unless it will consider all numbers as unsigned.

    Also add an explicit cast to int (for %d) while parsing with va_arg()
    to ensure the highest bit is well extended on the 64 bits number that
    hosts the value in case of negative values.

    Reported-Bisected-Tested-by: Sitsofe Wheeler
    Signed-off-by: Frederic Weisbecker
    Cc: Lai Jiangshan
    Cc: Steven Rostedt
    Cc: Linus Torvalds
    LKML-Reference:
    Signed-off-by: Ingo Molnar

    Frederic Weisbecker
     

07 Mar, 2009

2 commits

  • An new optimization is making its way to ftrace. Its purpose is to
    make trace_printk() consuming less memory and be faster.

    Written by Lai Jiangshan, the approach is to delay the formatting
    job from tracing time to output time.

    Currently, a call to trace_printk() will format the whole string and
    insert it into the ring buffer. Then you can read it on /debug/tracing/trace
    file.

    The new implementation stores the address of the format string and
    the binary parameters into the ring buffer, making the packet more compact
    and faster to insert.
    Later, when the user exports the traces, the format string is retrieved
    with the binary parameters and the formatting job is eventually done.

    The new implementation rewrites a lot of format decoding bits from
    vsnprintf() function, making now 3 differents functions to maintain
    in their duplicated parts of printf format decoding bits.

    Suggested by Ingo Molnar, this patch tries to factorize the most
    possible common bits from these functions.
    The real common part between them is the format decoding. Although
    they do somewhat similar jobs, their way to export or import the parameters
    is very different. Thus, only the decoding layer is extracted, unless you see
    other parts that could be worth factorized.

    Changes in V2:

    - Address a suggestion from Linus to group the format_decode() parameters inside
    a structure.

    Changes in v3:

    - Address other cleanups suggested by Ingo and Linus such as passing the
    printf_spec struct to the format helpers: pointer()/number()/string()
    Note that this struct is passed by copy and not by address. This is to
    avoid side effects because these functions often change these values and the
    changes shoudn't be persistant when a callee helper returns.
    It would be too risky.

    - Various cleanups (code alignement, switch/case instead of if/else fountains).

    - Fix a bug that printed the first format specifier following a %p

    Changes in v4:

    - drop unapropriate const qualifier loss while casting fmt to a char *
    (thanks to Vegard Nossum for having pointed this out).

    Signed-off-by: Frederic Weisbecker
    Cc: Linus Torvalds
    Acked-by: Steven Rostedt
    LKML-Reference:
    Signed-off-by: Ingo Molnar

    Frederic Weisbecker
     
  • Impact: add new APIs for binary trace printk infrastructure

    vbin_printf(): write args to binary buffer, string is copied
    when "%s" is occurred.

    bstr_printf(): read from binary buffer for args and format a string

    [fweisbec@gmail.com: rebase]

    Signed-off-by: Lai Jiangshan
    Signed-off-by: Frederic Weisbecker
    Cc: Linus Torvalds
    LKML-Reference:
    Signed-off-by: Ingo Molnar

    Lai Jiangshan
     

07 Jan, 2009

1 commit


04 Jan, 2009

1 commit

  • Before, when we only ever printed out the pointer value itself, a NULL
    pointer would never cause issues and might as well be printed out as
    just its numeric value.

    However, with the extended %p formats, especially %pR, we might validly
    want to print out resources for debugging. And sometimes they don't
    even exist, and the resource pointer is just NULL. Print it out as
    such, rather than oopsing.

    This is a more generic version of a patch done by Trent Piepho (catching
    all %p cases rather than just %pR, and using "(null)" instead of
    "[NULL]" to match glibc).

    Requested-by: Trent Piepho
    Acked-by: Harvey Harrison
    Signed-off-by: Linus Torvalds

    Linus Torvalds
     

25 Nov, 2008

1 commit


04 Nov, 2008

1 commit


30 Oct, 2008

2 commits


29 Oct, 2008

1 commit

  • Takes a pointer to a IPv6 address and formats it in the usual
    colon-separated hex format:
    xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx

    Each 16 bit word is printed in network-endian byteorder.

    %#p6 is also supported and will omit the colons.

    %p6 is a replacement for NIP6_FMT and NIP6()
    %#p6 is a replacement for NIP6_SEQFMT and NIP6()

    Note that NIP6() took a struct in6_addr whereas this takes a pointer
    to a struct in6_addr.

    Signed-off-by: Harvey Harrison
    Signed-off-by: David S. Miller

    Harvey Harrison
     

28 Oct, 2008

1 commit


21 Oct, 2008

1 commit


17 Oct, 2008

4 commits

  • Open-code them rather than using defining macros. The function bodies are now
    next to their kerneldoc comments as a bonus.

    Add casts to the signed cases as they call into the unsigned versions.

    Avoids the sparse warnings:
    lib/vsprintf.c:249:1: warning: incorrect type in argument 3 (different signedness)
    lib/vsprintf.c:249:1: expected unsigned long *res
    lib/vsprintf.c:249:1: got long *res
    lib/vsprintf.c:249:1: warning: incorrect type in argument 3 (different signedness)
    lib/vsprintf.c:249:1: expected unsigned long *res
    lib/vsprintf.c:249:1: got long *res
    lib/vsprintf.c:251:1: warning: incorrect type in argument 3 (different signedness)
    lib/vsprintf.c:251:1: expected unsigned long long *res
    lib/vsprintf.c:251:1: got long long *res
    lib/vsprintf.c:251:1: warning: incorrect type in argument 3 (different signedness)
    lib/vsprintf.c:251:1: expected unsigned long long *res
    lib/vsprintf.c:251:1: got long long *res

    Signed-off-by: Harvey Harrison
    Signed-off-by: Linus Torvalds

    Harvey Harrison
     
  • Remove extra lines before the EXPORT_SYMBOL()s

    Signed-off-by: Harvey Harrison
    Signed-off-by: Linus Torvalds

    Harvey Harrison
     
  • The default base is 10 unless there is a leading zero, in which
    case the base will be guessed as 8.

    The base will only be guesed as 16 when the string starts with '0x'
    the third character is a valid hex digit.

    Signed-off-by: Harvey Harrison
    Signed-off-by: Linus Torvalds

    Harvey Harrison
     
  • Add documentation in kerneldoc for new printk format extensions

    This patch documents the new %pS/%pF options in printk in kernel doc.

    Hope I didn't miss any other extension.

    Signed-off-by: Andi Kleen
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Andi Kleen
     

10 Sep, 2008

1 commit

  • It was introduced by "vsprintf: add support for '%pS' and '%pF' pointer
    formats" in commit 0fe1ef24f7bd0020f29ffe287dfdb9ead33ca0b2. However,
    the current way its coded doesn't work on parisc64. For two reasons: 1)
    parisc isn't in the #ifdef and 2) parisc has a different format for
    function descriptors

    Make dereference_function_descriptor() more accommodating by allowing
    architecture overrides. I put the three overrides (for parisc64, ppc64
    and ia64) in arch/kernel/module.c because that's where the kernel
    internal linker which knows how to deal with function descriptors sits.

    Signed-off-by: James Bottomley
    Acked-by: Benjamin Herrenschmidt
    Acked-by: Tony Luck
    Acked-by: Kyle McMartin
    Signed-off-by: Linus Torvalds

    James Bottomley
     

13 Aug, 2008

1 commit


07 Jul, 2008

4 commits

  • They print out a pointer in symbolic format, if possible (ie using
    symbolic KALLSYMS information). The '%pS' format is for regular direct
    pointers (which can point to data or code and that you find on the stack
    during backtraces etc), while '%pF' is for C function pointer types.

    On most architectures, the two mean exactly the same thing, but some
    architectures use an indirect pointer for C function pointers, where the
    function pointer points to a function descriptor (which in turn contains
    the actual pointer to the code). The '%pF' code automatically does the
    appropriate function descriptor dereference on such architectures.

    Signed-off-by: Linus Torvalds

    Linus Torvalds
     
  • This expands the kernel '%p' handling with an arbitrary alphanumberic
    specifier extension string immediately following the '%p'. Right now
    it's just being ignored, but the next commit will start adding some
    specific pointer type extensions.

    NOTE! The reason the extension is appended to the '%p' is to allow
    minimal gcc type checking: gcc will still see the '%p' and will check
    that the argument passed in is indeed a pointer, and yet will not
    complain about the extended information that gcc doesn't understand
    about (on the other hand, it also won't actually check that the pointer
    type and the extension are compatible).

    Alphanumeric characters were chosen because there is no sane existing
    use for a string format with a hex pointer representation immediately
    followed by alphanumerics (which is what such a format string would have
    traditionally resulted in).

    Signed-off-by: Linus Torvalds

    Linus Torvalds
     
  • The actual code is the same, just split out into a helper function.
    This makes it easier to read, and allows for simple future extension
    of %p handling.

    Signed-off-by: Linus Torvalds

    Linus Torvalds
     
  • The actual code is the same, just split out into a helper function.
    This makes it easier to read, and allows for future sharing of the
    string code.

    Signed-off-by: Linus Torvalds

    Linus Torvalds
     

24 Feb, 2008

1 commit


10 Feb, 2008

1 commit

  • 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
    Cc: Andi Kleen
    Signed-off-by: Andrew Morton
    Signed-off-by: Ingo Molnar
    Signed-off-by: Thomas Gleixner

    Denys Vlasenko
     

09 Feb, 2008

1 commit

  • 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 > /sys/module/e1000/parameters/copybreak
    [root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
    4096
    [root@yangyi-dev /]# echo 0x1000g > /sys/module/e1000/parameters/copybreak
    [root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
    4096
    [root@yangyi-dev /]# echo 0x1000gggggggg > /sys/module/e1000/parameters/copybreak
    [root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
    4096
    [root@yangyi-dev /]# echo 010000 > /sys/module/e1000/parameters/copybreak
    [root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
    4096
    [root@yangyi-dev /]# echo 0100008 > /sys/module/e1000/parameters/copybreak
    [root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
    4096
    [root@yangyi-dev /]# echo 010000aaaaa > /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 > /sys/module/e1000/parameters/copybreak
    [root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
    4096
    [root@yangyi-dev /]# echo 0x1000g > /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 > /sys/module/e1000/parameters/copybreak
    -bash: echo: write error: Invalid argument
    [root@yangyi-dev /]# echo 010000 > /sys/module/e1000/parameters/copybreak
    [root@yangyi-dev /]# echo 0100008 > /sys/module/e1000/parameters/copybreak
    -bash: echo: write error: Invalid argument
    [root@yangyi-dev /]# echo 010000aaaaa > /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 > /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
    Cc: Greg KH
    Cc: "Randy.Dunlap"
    Cc: Takashi Iwai
    Cc: Hugh Dickins
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Yi Yang
     

01 Aug, 2007

1 commit

  • 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
    Cc: Jeremy Fitzhardinge
    Cc: Meelis Roos
    Cc: Richard Henderson
    Cc: Ivan Kokshaysky
    Cc: Jay Estabrook
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Sam Ravnborg
     

17 Jul, 2007

2 commits

  • 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 &
    let i--
    done
    busybox top -b -n3 >/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
    Signed-off-by: Denys Vlasenko
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Denis Vlasenko
     
  • * 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 < precision--) {
    +       while (i 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
    Signed-off-by: Denys Vlasenko
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Denis Vlasenko