2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* linux/lib/vsprintf.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 1991, 1992 Linus Torvalds
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* vsprintf.c -- Lars Wirzenius & Linus Torvalds. */
|
|
|
|
/*
|
|
|
|
* Wirzenius wrote this portably, Torvalds fucked it up :-)
|
|
|
|
*/
|
|
|
|
|
2009-12-15 10:00:57 +08:00
|
|
|
/*
|
2005-04-17 06:20:36 +08:00
|
|
|
* Fri Jul 13 2001 Crutcher Dunnavant <crutcher+kernel@datastacks.com>
|
|
|
|
* - changed to provide snprintf and vsnprintf functions
|
|
|
|
* So Feb 1 16:51:32 CET 2004 Juergen Quade <quade@hsnr.de>
|
|
|
|
* - scnprintf and vscnprintf
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
2011-11-17 10:29:17 +08:00
|
|
|
#include <linux/module.h> /* for KSYM_SYMBOL_LEN */
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/ctype.h>
|
|
|
|
#include <linux/kernel.h>
|
2008-07-07 07:43:12 +08:00
|
|
|
#include <linux/kallsyms.h>
|
2012-12-18 08:01:31 +08:00
|
|
|
#include <linux/math64.h>
|
2008-07-07 07:43:12 +08:00
|
|
|
#include <linux/uaccess.h>
|
2008-10-20 12:07:34 +08:00
|
|
|
#include <linux/ioport.h>
|
2013-09-04 00:00:44 +08:00
|
|
|
#include <linux/dcache.h>
|
2013-11-13 07:08:51 +08:00
|
|
|
#include <linux/cred.h>
|
2009-08-17 20:29:44 +08:00
|
|
|
#include <net/addrconf.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-10-31 07:03:48 +08:00
|
|
|
#include <asm/page.h> /* for PAGE_SIZE */
|
2008-09-04 09:43:36 +08:00
|
|
|
#include <asm/sections.h> /* for dereference_function_descriptor() */
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2011-11-01 08:12:28 +08:00
|
|
|
#include "kstrtox.h"
|
2008-10-17 04:40:34 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/**
|
2009-12-15 10:01:01 +08:00
|
|
|
* simple_strtoull - convert a string to an unsigned long long
|
2005-04-17 06:20:36 +08:00
|
|
|
* @cp: The start of the string
|
|
|
|
* @endp: A pointer to the end of the parsed string will be placed here
|
|
|
|
* @base: The number base to use
|
2012-12-18 08:03:05 +08:00
|
|
|
*
|
|
|
|
* This function is obsolete. Please use kstrtoull instead.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2009-12-15 10:01:01 +08:00
|
|
|
unsigned long long simple_strtoull(const char *cp, char **endp, unsigned int base)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2011-11-01 08:12:28 +08:00
|
|
|
unsigned long long result;
|
|
|
|
unsigned int rv;
|
2008-10-17 04:40:34 +08:00
|
|
|
|
2011-11-01 08:12:28 +08:00
|
|
|
cp = _parse_integer_fixup_radix(cp, &base);
|
|
|
|
rv = _parse_integer(cp, base, &result);
|
|
|
|
/* FIXME */
|
|
|
|
cp += (rv & ~KSTRTOX_OVERFLOW);
|
2008-10-17 04:40:34 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (endp)
|
|
|
|
*endp = (char *)cp;
|
2009-12-15 10:00:57 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return result;
|
|
|
|
}
|
2009-12-15 10:01:01 +08:00
|
|
|
EXPORT_SYMBOL(simple_strtoull);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/**
|
2009-12-15 10:01:01 +08:00
|
|
|
* simple_strtoul - convert a string to an unsigned long
|
2005-04-17 06:20:36 +08:00
|
|
|
* @cp: The start of the string
|
|
|
|
* @endp: A pointer to the end of the parsed string will be placed here
|
|
|
|
* @base: The number base to use
|
2012-12-18 08:03:05 +08:00
|
|
|
*
|
|
|
|
* This function is obsolete. Please use kstrtoul instead.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2009-12-15 10:01:01 +08:00
|
|
|
unsigned long simple_strtoul(const char *cp, char **endp, unsigned int base)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2009-12-15 10:01:01 +08:00
|
|
|
return simple_strtoull(cp, endp, base);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2009-12-15 10:01:01 +08:00
|
|
|
EXPORT_SYMBOL(simple_strtoul);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/**
|
2009-12-15 10:01:01 +08:00
|
|
|
* simple_strtol - convert a string to a signed long
|
2005-04-17 06:20:36 +08:00
|
|
|
* @cp: The start of the string
|
|
|
|
* @endp: A pointer to the end of the parsed string will be placed here
|
|
|
|
* @base: The number base to use
|
2012-12-18 08:03:05 +08:00
|
|
|
*
|
|
|
|
* This function is obsolete. Please use kstrtol instead.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2009-12-15 10:01:01 +08:00
|
|
|
long simple_strtol(const char *cp, char **endp, unsigned int base)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2009-12-15 10:01:01 +08:00
|
|
|
if (*cp == '-')
|
|
|
|
return -simple_strtoul(cp + 1, endp, base);
|
2009-12-15 10:00:57 +08:00
|
|
|
|
2009-12-15 10:01:01 +08:00
|
|
|
return simple_strtoul(cp, endp, base);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2009-12-15 10:01:01 +08:00
|
|
|
EXPORT_SYMBOL(simple_strtol);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* simple_strtoll - convert a string to a signed long long
|
|
|
|
* @cp: The start of the string
|
|
|
|
* @endp: A pointer to the end of the parsed string will be placed here
|
|
|
|
* @base: The number base to use
|
2012-12-18 08:03:05 +08:00
|
|
|
*
|
|
|
|
* This function is obsolete. Please use kstrtoll instead.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2008-10-17 04:40:35 +08:00
|
|
|
long long simple_strtoll(const char *cp, char **endp, unsigned int base)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2009-12-15 10:00:57 +08:00
|
|
|
if (*cp == '-')
|
2008-10-17 04:40:35 +08:00
|
|
|
return -simple_strtoull(cp + 1, endp, base);
|
2009-12-15 10:00:57 +08:00
|
|
|
|
2008-10-17 04:40:35 +08:00
|
|
|
return simple_strtoull(cp, endp, base);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2010-04-24 01:18:04 +08:00
|
|
|
EXPORT_SYMBOL(simple_strtoll);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-05-25 05:33:16 +08:00
|
|
|
static noinline_for_stack
|
|
|
|
int skip_atoi(const char **s)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2009-12-15 10:00:57 +08:00
|
|
|
int i = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
while (isdigit(**s))
|
|
|
|
i = i*10 + *((*s)++) - '0';
|
2009-12-15 10:00:57 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2007-07-16 14:41:56 +08:00
|
|
|
/* Decimal conversion is by far the most typical, and is used
|
|
|
|
* for /proc and /sys data. This directly impacts e.g. top performance
|
|
|
|
* with many processes running. We optimize it for speed
|
vsprintf: further optimize decimal conversion
Previous code was using optimizations which were developed to work well
even on narrow-word CPUs (by today's standards). But Linux runs only on
32-bit and wider CPUs. We can use that.
First: using 32x32->64 multiply and trivial 32-bit shift, we can correctly
divide by 10 much larger numbers, and thus we can print groups of 9 digits
instead of groups of 5 digits.
Next: there are two algorithms to print larger numbers. One is generic:
divide by 1000000000 and repeatedly print groups of (up to) 9 digits.
It's conceptually simple, but requires an (unsigned long long) /
1000000000 division.
Second algorithm splits 64-bit unsigned long long into 16-bit chunks,
manipulates them cleverly and generates groups of 4 decimal digits. It so
happens that it does NOT require long long division.
If long is > 32 bits, division of 64-bit values is relatively easy, and we
will use the first algorithm. If long long is > 64 bits (strange
architecture with VERY large long long), second algorithm can't be used,
and we again use the first one.
Else (if long is 32 bits and long long is 64 bits) we use second one.
And third: there is a simple optimization which takes fast path not only
for zero as was done before, but for all one-digit numbers.
In all tested cases new code is faster than old one, in many cases by 30%,
in few cases by more than 50% (for example, on x86-32, conversion of
12345678). Code growth is ~0 in 32-bit case and ~130 bytes in 64-bit
case.
This patch is based upon an original from Michal Nazarewicz.
[akpm@linux-foundation.org: checkpatch fixes]
Signed-off-by: Michal Nazarewicz <mina86@mina86.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Cc: Douglas W Jones <jones@cs.uiowa.edu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-06-01 07:26:08 +08:00
|
|
|
* using ideas described at <http://www.cs.uiowa.edu/~jones/bcd/divide.html>
|
|
|
|
* (with permission from the author, Douglas W. Jones).
|
|
|
|
*/
|
2007-07-16 14:41:56 +08:00
|
|
|
|
vsprintf: further optimize decimal conversion
Previous code was using optimizations which were developed to work well
even on narrow-word CPUs (by today's standards). But Linux runs only on
32-bit and wider CPUs. We can use that.
First: using 32x32->64 multiply and trivial 32-bit shift, we can correctly
divide by 10 much larger numbers, and thus we can print groups of 9 digits
instead of groups of 5 digits.
Next: there are two algorithms to print larger numbers. One is generic:
divide by 1000000000 and repeatedly print groups of (up to) 9 digits.
It's conceptually simple, but requires an (unsigned long long) /
1000000000 division.
Second algorithm splits 64-bit unsigned long long into 16-bit chunks,
manipulates them cleverly and generates groups of 4 decimal digits. It so
happens that it does NOT require long long division.
If long is > 32 bits, division of 64-bit values is relatively easy, and we
will use the first algorithm. If long long is > 64 bits (strange
architecture with VERY large long long), second algorithm can't be used,
and we again use the first one.
Else (if long is 32 bits and long long is 64 bits) we use second one.
And third: there is a simple optimization which takes fast path not only
for zero as was done before, but for all one-digit numbers.
In all tested cases new code is faster than old one, in many cases by 30%,
in few cases by more than 50% (for example, on x86-32, conversion of
12345678). Code growth is ~0 in 32-bit case and ~130 bytes in 64-bit
case.
This patch is based upon an original from Michal Nazarewicz.
[akpm@linux-foundation.org: checkpatch fixes]
Signed-off-by: Michal Nazarewicz <mina86@mina86.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Cc: Douglas W Jones <jones@cs.uiowa.edu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-06-01 07:26:08 +08:00
|
|
|
#if BITS_PER_LONG != 32 || BITS_PER_LONG_LONG != 64
|
|
|
|
/* Formats correctly any integer in [0, 999999999] */
|
2010-05-25 05:33:16 +08:00
|
|
|
static noinline_for_stack
|
vsprintf: further optimize decimal conversion
Previous code was using optimizations which were developed to work well
even on narrow-word CPUs (by today's standards). But Linux runs only on
32-bit and wider CPUs. We can use that.
First: using 32x32->64 multiply and trivial 32-bit shift, we can correctly
divide by 10 much larger numbers, and thus we can print groups of 9 digits
instead of groups of 5 digits.
Next: there are two algorithms to print larger numbers. One is generic:
divide by 1000000000 and repeatedly print groups of (up to) 9 digits.
It's conceptually simple, but requires an (unsigned long long) /
1000000000 division.
Second algorithm splits 64-bit unsigned long long into 16-bit chunks,
manipulates them cleverly and generates groups of 4 decimal digits. It so
happens that it does NOT require long long division.
If long is > 32 bits, division of 64-bit values is relatively easy, and we
will use the first algorithm. If long long is > 64 bits (strange
architecture with VERY large long long), second algorithm can't be used,
and we again use the first one.
Else (if long is 32 bits and long long is 64 bits) we use second one.
And third: there is a simple optimization which takes fast path not only
for zero as was done before, but for all one-digit numbers.
In all tested cases new code is faster than old one, in many cases by 30%,
in few cases by more than 50% (for example, on x86-32, conversion of
12345678). Code growth is ~0 in 32-bit case and ~130 bytes in 64-bit
case.
This patch is based upon an original from Michal Nazarewicz.
[akpm@linux-foundation.org: checkpatch fixes]
Signed-off-by: Michal Nazarewicz <mina86@mina86.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Cc: Douglas W Jones <jones@cs.uiowa.edu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-06-01 07:26:08 +08:00
|
|
|
char *put_dec_full9(char *buf, unsigned q)
|
2007-07-16 14:41:56 +08:00
|
|
|
{
|
vsprintf: further optimize decimal conversion
Previous code was using optimizations which were developed to work well
even on narrow-word CPUs (by today's standards). But Linux runs only on
32-bit and wider CPUs. We can use that.
First: using 32x32->64 multiply and trivial 32-bit shift, we can correctly
divide by 10 much larger numbers, and thus we can print groups of 9 digits
instead of groups of 5 digits.
Next: there are two algorithms to print larger numbers. One is generic:
divide by 1000000000 and repeatedly print groups of (up to) 9 digits.
It's conceptually simple, but requires an (unsigned long long) /
1000000000 division.
Second algorithm splits 64-bit unsigned long long into 16-bit chunks,
manipulates them cleverly and generates groups of 4 decimal digits. It so
happens that it does NOT require long long division.
If long is > 32 bits, division of 64-bit values is relatively easy, and we
will use the first algorithm. If long long is > 64 bits (strange
architecture with VERY large long long), second algorithm can't be used,
and we again use the first one.
Else (if long is 32 bits and long long is 64 bits) we use second one.
And third: there is a simple optimization which takes fast path not only
for zero as was done before, but for all one-digit numbers.
In all tested cases new code is faster than old one, in many cases by 30%,
in few cases by more than 50% (for example, on x86-32, conversion of
12345678). Code growth is ~0 in 32-bit case and ~130 bytes in 64-bit
case.
This patch is based upon an original from Michal Nazarewicz.
[akpm@linux-foundation.org: checkpatch fixes]
Signed-off-by: Michal Nazarewicz <mina86@mina86.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Cc: Douglas W Jones <jones@cs.uiowa.edu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-06-01 07:26:08 +08:00
|
|
|
unsigned r;
|
2009-12-15 10:00:57 +08:00
|
|
|
|
vsprintf: further optimize decimal conversion
Previous code was using optimizations which were developed to work well
even on narrow-word CPUs (by today's standards). But Linux runs only on
32-bit and wider CPUs. We can use that.
First: using 32x32->64 multiply and trivial 32-bit shift, we can correctly
divide by 10 much larger numbers, and thus we can print groups of 9 digits
instead of groups of 5 digits.
Next: there are two algorithms to print larger numbers. One is generic:
divide by 1000000000 and repeatedly print groups of (up to) 9 digits.
It's conceptually simple, but requires an (unsigned long long) /
1000000000 division.
Second algorithm splits 64-bit unsigned long long into 16-bit chunks,
manipulates them cleverly and generates groups of 4 decimal digits. It so
happens that it does NOT require long long division.
If long is > 32 bits, division of 64-bit values is relatively easy, and we
will use the first algorithm. If long long is > 64 bits (strange
architecture with VERY large long long), second algorithm can't be used,
and we again use the first one.
Else (if long is 32 bits and long long is 64 bits) we use second one.
And third: there is a simple optimization which takes fast path not only
for zero as was done before, but for all one-digit numbers.
In all tested cases new code is faster than old one, in many cases by 30%,
in few cases by more than 50% (for example, on x86-32, conversion of
12345678). Code growth is ~0 in 32-bit case and ~130 bytes in 64-bit
case.
This patch is based upon an original from Michal Nazarewicz.
[akpm@linux-foundation.org: checkpatch fixes]
Signed-off-by: Michal Nazarewicz <mina86@mina86.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Cc: Douglas W Jones <jones@cs.uiowa.edu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-06-01 07:26:08 +08:00
|
|
|
/*
|
|
|
|
* Possible ways to approx. divide by 10
|
|
|
|
* (x * 0x1999999a) >> 32 x < 1073741829 (multiply must be 64-bit)
|
|
|
|
* (x * 0xcccd) >> 19 x < 81920 (x < 262149 when 64-bit mul)
|
|
|
|
* (x * 0x6667) >> 18 x < 43699
|
|
|
|
* (x * 0x3334) >> 17 x < 16389
|
|
|
|
* (x * 0x199a) >> 16 x < 16389
|
|
|
|
* (x * 0x0ccd) >> 15 x < 16389
|
|
|
|
* (x * 0x0667) >> 14 x < 2739
|
|
|
|
* (x * 0x0334) >> 13 x < 1029
|
|
|
|
* (x * 0x019a) >> 12 x < 1029
|
|
|
|
* (x * 0x00cd) >> 11 x < 1029 shorter code than * 0x67 (on i386)
|
|
|
|
* (x * 0x0067) >> 10 x < 179
|
|
|
|
* (x * 0x0034) >> 9 x < 69 same
|
|
|
|
* (x * 0x001a) >> 8 x < 69 same
|
|
|
|
* (x * 0x000d) >> 7 x < 69 same, shortest code (on i386)
|
|
|
|
* (x * 0x0007) >> 6 x < 19
|
|
|
|
* See <http://www.cs.uiowa.edu/~jones/bcd/divide.html>
|
|
|
|
*/
|
|
|
|
r = (q * (uint64_t)0x1999999a) >> 32;
|
|
|
|
*buf++ = (q - 10 * r) + '0'; /* 1 */
|
|
|
|
q = (r * (uint64_t)0x1999999a) >> 32;
|
|
|
|
*buf++ = (r - 10 * q) + '0'; /* 2 */
|
|
|
|
r = (q * (uint64_t)0x1999999a) >> 32;
|
|
|
|
*buf++ = (q - 10 * r) + '0'; /* 3 */
|
|
|
|
q = (r * (uint64_t)0x1999999a) >> 32;
|
|
|
|
*buf++ = (r - 10 * q) + '0'; /* 4 */
|
|
|
|
r = (q * (uint64_t)0x1999999a) >> 32;
|
|
|
|
*buf++ = (q - 10 * r) + '0'; /* 5 */
|
|
|
|
/* Now value is under 10000, can avoid 64-bit multiply */
|
|
|
|
q = (r * 0x199a) >> 16;
|
|
|
|
*buf++ = (r - 10 * q) + '0'; /* 6 */
|
|
|
|
r = (q * 0xcd) >> 11;
|
|
|
|
*buf++ = (q - 10 * r) + '0'; /* 7 */
|
|
|
|
q = (r * 0xcd) >> 11;
|
|
|
|
*buf++ = (r - 10 * q) + '0'; /* 8 */
|
|
|
|
*buf++ = q + '0'; /* 9 */
|
2007-07-16 14:41:56 +08:00
|
|
|
return buf;
|
|
|
|
}
|
vsprintf: further optimize decimal conversion
Previous code was using optimizations which were developed to work well
even on narrow-word CPUs (by today's standards). But Linux runs only on
32-bit and wider CPUs. We can use that.
First: using 32x32->64 multiply and trivial 32-bit shift, we can correctly
divide by 10 much larger numbers, and thus we can print groups of 9 digits
instead of groups of 5 digits.
Next: there are two algorithms to print larger numbers. One is generic:
divide by 1000000000 and repeatedly print groups of (up to) 9 digits.
It's conceptually simple, but requires an (unsigned long long) /
1000000000 division.
Second algorithm splits 64-bit unsigned long long into 16-bit chunks,
manipulates them cleverly and generates groups of 4 decimal digits. It so
happens that it does NOT require long long division.
If long is > 32 bits, division of 64-bit values is relatively easy, and we
will use the first algorithm. If long long is > 64 bits (strange
architecture with VERY large long long), second algorithm can't be used,
and we again use the first one.
Else (if long is 32 bits and long long is 64 bits) we use second one.
And third: there is a simple optimization which takes fast path not only
for zero as was done before, but for all one-digit numbers.
In all tested cases new code is faster than old one, in many cases by 30%,
in few cases by more than 50% (for example, on x86-32, conversion of
12345678). Code growth is ~0 in 32-bit case and ~130 bytes in 64-bit
case.
This patch is based upon an original from Michal Nazarewicz.
[akpm@linux-foundation.org: checkpatch fixes]
Signed-off-by: Michal Nazarewicz <mina86@mina86.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Cc: Douglas W Jones <jones@cs.uiowa.edu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-06-01 07:26:08 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Similar to above but do not pad with zeros.
|
|
|
|
* Code can be easily arranged to print 9 digits too, but our callers
|
|
|
|
* always call put_dec_full9() instead when the number has 9 decimal digits.
|
|
|
|
*/
|
2010-05-25 05:33:16 +08:00
|
|
|
static noinline_for_stack
|
vsprintf: further optimize decimal conversion
Previous code was using optimizations which were developed to work well
even on narrow-word CPUs (by today's standards). But Linux runs only on
32-bit and wider CPUs. We can use that.
First: using 32x32->64 multiply and trivial 32-bit shift, we can correctly
divide by 10 much larger numbers, and thus we can print groups of 9 digits
instead of groups of 5 digits.
Next: there are two algorithms to print larger numbers. One is generic:
divide by 1000000000 and repeatedly print groups of (up to) 9 digits.
It's conceptually simple, but requires an (unsigned long long) /
1000000000 division.
Second algorithm splits 64-bit unsigned long long into 16-bit chunks,
manipulates them cleverly and generates groups of 4 decimal digits. It so
happens that it does NOT require long long division.
If long is > 32 bits, division of 64-bit values is relatively easy, and we
will use the first algorithm. If long long is > 64 bits (strange
architecture with VERY large long long), second algorithm can't be used,
and we again use the first one.
Else (if long is 32 bits and long long is 64 bits) we use second one.
And third: there is a simple optimization which takes fast path not only
for zero as was done before, but for all one-digit numbers.
In all tested cases new code is faster than old one, in many cases by 30%,
in few cases by more than 50% (for example, on x86-32, conversion of
12345678). Code growth is ~0 in 32-bit case and ~130 bytes in 64-bit
case.
This patch is based upon an original from Michal Nazarewicz.
[akpm@linux-foundation.org: checkpatch fixes]
Signed-off-by: Michal Nazarewicz <mina86@mina86.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Cc: Douglas W Jones <jones@cs.uiowa.edu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-06-01 07:26:08 +08:00
|
|
|
char *put_dec_trunc8(char *buf, unsigned r)
|
2007-07-16 14:41:56 +08:00
|
|
|
{
|
vsprintf: further optimize decimal conversion
Previous code was using optimizations which were developed to work well
even on narrow-word CPUs (by today's standards). But Linux runs only on
32-bit and wider CPUs. We can use that.
First: using 32x32->64 multiply and trivial 32-bit shift, we can correctly
divide by 10 much larger numbers, and thus we can print groups of 9 digits
instead of groups of 5 digits.
Next: there are two algorithms to print larger numbers. One is generic:
divide by 1000000000 and repeatedly print groups of (up to) 9 digits.
It's conceptually simple, but requires an (unsigned long long) /
1000000000 division.
Second algorithm splits 64-bit unsigned long long into 16-bit chunks,
manipulates them cleverly and generates groups of 4 decimal digits. It so
happens that it does NOT require long long division.
If long is > 32 bits, division of 64-bit values is relatively easy, and we
will use the first algorithm. If long long is > 64 bits (strange
architecture with VERY large long long), second algorithm can't be used,
and we again use the first one.
Else (if long is 32 bits and long long is 64 bits) we use second one.
And third: there is a simple optimization which takes fast path not only
for zero as was done before, but for all one-digit numbers.
In all tested cases new code is faster than old one, in many cases by 30%,
in few cases by more than 50% (for example, on x86-32, conversion of
12345678). Code growth is ~0 in 32-bit case and ~130 bytes in 64-bit
case.
This patch is based upon an original from Michal Nazarewicz.
[akpm@linux-foundation.org: checkpatch fixes]
Signed-off-by: Michal Nazarewicz <mina86@mina86.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Cc: Douglas W Jones <jones@cs.uiowa.edu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-06-01 07:26:08 +08:00
|
|
|
unsigned q;
|
|
|
|
|
|
|
|
/* Copy of previous function's body with added early returns */
|
2012-10-05 08:12:30 +08:00
|
|
|
while (r >= 10000) {
|
|
|
|
q = r + '0';
|
|
|
|
r = (r * (uint64_t)0x1999999a) >> 32;
|
|
|
|
*buf++ = q - 10*r;
|
|
|
|
}
|
|
|
|
|
2012-10-05 08:12:32 +08:00
|
|
|
q = (r * 0x199a) >> 16; /* r <= 9999 */
|
|
|
|
*buf++ = (r - 10 * q) + '0';
|
vsprintf: further optimize decimal conversion
Previous code was using optimizations which were developed to work well
even on narrow-word CPUs (by today's standards). But Linux runs only on
32-bit and wider CPUs. We can use that.
First: using 32x32->64 multiply and trivial 32-bit shift, we can correctly
divide by 10 much larger numbers, and thus we can print groups of 9 digits
instead of groups of 5 digits.
Next: there are two algorithms to print larger numbers. One is generic:
divide by 1000000000 and repeatedly print groups of (up to) 9 digits.
It's conceptually simple, but requires an (unsigned long long) /
1000000000 division.
Second algorithm splits 64-bit unsigned long long into 16-bit chunks,
manipulates them cleverly and generates groups of 4 decimal digits. It so
happens that it does NOT require long long division.
If long is > 32 bits, division of 64-bit values is relatively easy, and we
will use the first algorithm. If long long is > 64 bits (strange
architecture with VERY large long long), second algorithm can't be used,
and we again use the first one.
Else (if long is 32 bits and long long is 64 bits) we use second one.
And third: there is a simple optimization which takes fast path not only
for zero as was done before, but for all one-digit numbers.
In all tested cases new code is faster than old one, in many cases by 30%,
in few cases by more than 50% (for example, on x86-32, conversion of
12345678). Code growth is ~0 in 32-bit case and ~130 bytes in 64-bit
case.
This patch is based upon an original from Michal Nazarewicz.
[akpm@linux-foundation.org: checkpatch fixes]
Signed-off-by: Michal Nazarewicz <mina86@mina86.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Cc: Douglas W Jones <jones@cs.uiowa.edu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-06-01 07:26:08 +08:00
|
|
|
if (q == 0)
|
|
|
|
return buf;
|
2012-10-05 08:12:32 +08:00
|
|
|
r = (q * 0xcd) >> 11; /* q <= 999 */
|
|
|
|
*buf++ = (q - 10 * r) + '0';
|
vsprintf: further optimize decimal conversion
Previous code was using optimizations which were developed to work well
even on narrow-word CPUs (by today's standards). But Linux runs only on
32-bit and wider CPUs. We can use that.
First: using 32x32->64 multiply and trivial 32-bit shift, we can correctly
divide by 10 much larger numbers, and thus we can print groups of 9 digits
instead of groups of 5 digits.
Next: there are two algorithms to print larger numbers. One is generic:
divide by 1000000000 and repeatedly print groups of (up to) 9 digits.
It's conceptually simple, but requires an (unsigned long long) /
1000000000 division.
Second algorithm splits 64-bit unsigned long long into 16-bit chunks,
manipulates them cleverly and generates groups of 4 decimal digits. It so
happens that it does NOT require long long division.
If long is > 32 bits, division of 64-bit values is relatively easy, and we
will use the first algorithm. If long long is > 64 bits (strange
architecture with VERY large long long), second algorithm can't be used,
and we again use the first one.
Else (if long is 32 bits and long long is 64 bits) we use second one.
And third: there is a simple optimization which takes fast path not only
for zero as was done before, but for all one-digit numbers.
In all tested cases new code is faster than old one, in many cases by 30%,
in few cases by more than 50% (for example, on x86-32, conversion of
12345678). Code growth is ~0 in 32-bit case and ~130 bytes in 64-bit
case.
This patch is based upon an original from Michal Nazarewicz.
[akpm@linux-foundation.org: checkpatch fixes]
Signed-off-by: Michal Nazarewicz <mina86@mina86.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Cc: Douglas W Jones <jones@cs.uiowa.edu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-06-01 07:26:08 +08:00
|
|
|
if (r == 0)
|
|
|
|
return buf;
|
2012-10-05 08:12:32 +08:00
|
|
|
q = (r * 0xcd) >> 11; /* r <= 99 */
|
|
|
|
*buf++ = (r - 10 * q) + '0';
|
vsprintf: further optimize decimal conversion
Previous code was using optimizations which were developed to work well
even on narrow-word CPUs (by today's standards). But Linux runs only on
32-bit and wider CPUs. We can use that.
First: using 32x32->64 multiply and trivial 32-bit shift, we can correctly
divide by 10 much larger numbers, and thus we can print groups of 9 digits
instead of groups of 5 digits.
Next: there are two algorithms to print larger numbers. One is generic:
divide by 1000000000 and repeatedly print groups of (up to) 9 digits.
It's conceptually simple, but requires an (unsigned long long) /
1000000000 division.
Second algorithm splits 64-bit unsigned long long into 16-bit chunks,
manipulates them cleverly and generates groups of 4 decimal digits. It so
happens that it does NOT require long long division.
If long is > 32 bits, division of 64-bit values is relatively easy, and we
will use the first algorithm. If long long is > 64 bits (strange
architecture with VERY large long long), second algorithm can't be used,
and we again use the first one.
Else (if long is 32 bits and long long is 64 bits) we use second one.
And third: there is a simple optimization which takes fast path not only
for zero as was done before, but for all one-digit numbers.
In all tested cases new code is faster than old one, in many cases by 30%,
in few cases by more than 50% (for example, on x86-32, conversion of
12345678). Code growth is ~0 in 32-bit case and ~130 bytes in 64-bit
case.
This patch is based upon an original from Michal Nazarewicz.
[akpm@linux-foundation.org: checkpatch fixes]
Signed-off-by: Michal Nazarewicz <mina86@mina86.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Cc: Douglas W Jones <jones@cs.uiowa.edu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-06-01 07:26:08 +08:00
|
|
|
if (q == 0)
|
|
|
|
return buf;
|
2012-10-05 08:12:32 +08:00
|
|
|
*buf++ = q + '0'; /* q <= 9 */
|
vsprintf: further optimize decimal conversion
Previous code was using optimizations which were developed to work well
even on narrow-word CPUs (by today's standards). But Linux runs only on
32-bit and wider CPUs. We can use that.
First: using 32x32->64 multiply and trivial 32-bit shift, we can correctly
divide by 10 much larger numbers, and thus we can print groups of 9 digits
instead of groups of 5 digits.
Next: there are two algorithms to print larger numbers. One is generic:
divide by 1000000000 and repeatedly print groups of (up to) 9 digits.
It's conceptually simple, but requires an (unsigned long long) /
1000000000 division.
Second algorithm splits 64-bit unsigned long long into 16-bit chunks,
manipulates them cleverly and generates groups of 4 decimal digits. It so
happens that it does NOT require long long division.
If long is > 32 bits, division of 64-bit values is relatively easy, and we
will use the first algorithm. If long long is > 64 bits (strange
architecture with VERY large long long), second algorithm can't be used,
and we again use the first one.
Else (if long is 32 bits and long long is 64 bits) we use second one.
And third: there is a simple optimization which takes fast path not only
for zero as was done before, but for all one-digit numbers.
In all tested cases new code is faster than old one, in many cases by 30%,
in few cases by more than 50% (for example, on x86-32, conversion of
12345678). Code growth is ~0 in 32-bit case and ~130 bytes in 64-bit
case.
This patch is based upon an original from Michal Nazarewicz.
[akpm@linux-foundation.org: checkpatch fixes]
Signed-off-by: Michal Nazarewicz <mina86@mina86.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Cc: Douglas W Jones <jones@cs.uiowa.edu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-06-01 07:26:08 +08:00
|
|
|
return buf;
|
|
|
|
}
|
2007-07-16 14:41:56 +08:00
|
|
|
|
vsprintf: further optimize decimal conversion
Previous code was using optimizations which were developed to work well
even on narrow-word CPUs (by today's standards). But Linux runs only on
32-bit and wider CPUs. We can use that.
First: using 32x32->64 multiply and trivial 32-bit shift, we can correctly
divide by 10 much larger numbers, and thus we can print groups of 9 digits
instead of groups of 5 digits.
Next: there are two algorithms to print larger numbers. One is generic:
divide by 1000000000 and repeatedly print groups of (up to) 9 digits.
It's conceptually simple, but requires an (unsigned long long) /
1000000000 division.
Second algorithm splits 64-bit unsigned long long into 16-bit chunks,
manipulates them cleverly and generates groups of 4 decimal digits. It so
happens that it does NOT require long long division.
If long is > 32 bits, division of 64-bit values is relatively easy, and we
will use the first algorithm. If long long is > 64 bits (strange
architecture with VERY large long long), second algorithm can't be used,
and we again use the first one.
Else (if long is 32 bits and long long is 64 bits) we use second one.
And third: there is a simple optimization which takes fast path not only
for zero as was done before, but for all one-digit numbers.
In all tested cases new code is faster than old one, in many cases by 30%,
in few cases by more than 50% (for example, on x86-32, conversion of
12345678). Code growth is ~0 in 32-bit case and ~130 bytes in 64-bit
case.
This patch is based upon an original from Michal Nazarewicz.
[akpm@linux-foundation.org: checkpatch fixes]
Signed-off-by: Michal Nazarewicz <mina86@mina86.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Cc: Douglas W Jones <jones@cs.uiowa.edu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-06-01 07:26:08 +08:00
|
|
|
/* There are two algorithms to print larger numbers.
|
|
|
|
* One is generic: divide by 1000000000 and repeatedly print
|
|
|
|
* groups of (up to) 9 digits. It's conceptually simple,
|
|
|
|
* but requires a (unsigned long long) / 1000000000 division.
|
|
|
|
*
|
|
|
|
* Second algorithm splits 64-bit unsigned long long into 16-bit chunks,
|
|
|
|
* manipulates them cleverly and generates groups of 4 decimal digits.
|
|
|
|
* It so happens that it does NOT require long long division.
|
|
|
|
*
|
|
|
|
* If long is > 32 bits, division of 64-bit values is relatively easy,
|
|
|
|
* and we will use the first algorithm.
|
|
|
|
* If long long is > 64 bits (strange architecture with VERY large long long),
|
|
|
|
* second algorithm can't be used, and we again use the first one.
|
|
|
|
*
|
|
|
|
* Else (if long is 32 bits and long long is 64 bits) we use second one.
|
|
|
|
*/
|
2009-12-15 10:00:57 +08:00
|
|
|
|
vsprintf: further optimize decimal conversion
Previous code was using optimizations which were developed to work well
even on narrow-word CPUs (by today's standards). But Linux runs only on
32-bit and wider CPUs. We can use that.
First: using 32x32->64 multiply and trivial 32-bit shift, we can correctly
divide by 10 much larger numbers, and thus we can print groups of 9 digits
instead of groups of 5 digits.
Next: there are two algorithms to print larger numbers. One is generic:
divide by 1000000000 and repeatedly print groups of (up to) 9 digits.
It's conceptually simple, but requires an (unsigned long long) /
1000000000 division.
Second algorithm splits 64-bit unsigned long long into 16-bit chunks,
manipulates them cleverly and generates groups of 4 decimal digits. It so
happens that it does NOT require long long division.
If long is > 32 bits, division of 64-bit values is relatively easy, and we
will use the first algorithm. If long long is > 64 bits (strange
architecture with VERY large long long), second algorithm can't be used,
and we again use the first one.
Else (if long is 32 bits and long long is 64 bits) we use second one.
And third: there is a simple optimization which takes fast path not only
for zero as was done before, but for all one-digit numbers.
In all tested cases new code is faster than old one, in many cases by 30%,
in few cases by more than 50% (for example, on x86-32, conversion of
12345678). Code growth is ~0 in 32-bit case and ~130 bytes in 64-bit
case.
This patch is based upon an original from Michal Nazarewicz.
[akpm@linux-foundation.org: checkpatch fixes]
Signed-off-by: Michal Nazarewicz <mina86@mina86.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Cc: Douglas W Jones <jones@cs.uiowa.edu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-06-01 07:26:08 +08:00
|
|
|
#if BITS_PER_LONG != 32 || BITS_PER_LONG_LONG != 64
|
|
|
|
|
|
|
|
/* First algorithm: generic */
|
|
|
|
|
|
|
|
static
|
|
|
|
char *put_dec(char *buf, unsigned long long n)
|
|
|
|
{
|
|
|
|
if (n >= 100*1000*1000) {
|
|
|
|
while (n >= 1000*1000*1000)
|
|
|
|
buf = put_dec_full9(buf, do_div(n, 1000*1000*1000));
|
|
|
|
if (n >= 100*1000*1000)
|
|
|
|
return put_dec_full9(buf, n);
|
|
|
|
}
|
|
|
|
return put_dec_trunc8(buf, n);
|
2007-07-16 14:41:56 +08:00
|
|
|
}
|
vsprintf: further optimize decimal conversion
Previous code was using optimizations which were developed to work well
even on narrow-word CPUs (by today's standards). But Linux runs only on
32-bit and wider CPUs. We can use that.
First: using 32x32->64 multiply and trivial 32-bit shift, we can correctly
divide by 10 much larger numbers, and thus we can print groups of 9 digits
instead of groups of 5 digits.
Next: there are two algorithms to print larger numbers. One is generic:
divide by 1000000000 and repeatedly print groups of (up to) 9 digits.
It's conceptually simple, but requires an (unsigned long long) /
1000000000 division.
Second algorithm splits 64-bit unsigned long long into 16-bit chunks,
manipulates them cleverly and generates groups of 4 decimal digits. It so
happens that it does NOT require long long division.
If long is > 32 bits, division of 64-bit values is relatively easy, and we
will use the first algorithm. If long long is > 64 bits (strange
architecture with VERY large long long), second algorithm can't be used,
and we again use the first one.
Else (if long is 32 bits and long long is 64 bits) we use second one.
And third: there is a simple optimization which takes fast path not only
for zero as was done before, but for all one-digit numbers.
In all tested cases new code is faster than old one, in many cases by 30%,
in few cases by more than 50% (for example, on x86-32, conversion of
12345678). Code growth is ~0 in 32-bit case and ~130 bytes in 64-bit
case.
This patch is based upon an original from Michal Nazarewicz.
[akpm@linux-foundation.org: checkpatch fixes]
Signed-off-by: Michal Nazarewicz <mina86@mina86.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Cc: Douglas W Jones <jones@cs.uiowa.edu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-06-01 07:26:08 +08:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
/* Second algorithm: valid only for 64-bit long longs */
|
|
|
|
|
2012-10-05 08:12:27 +08:00
|
|
|
/* See comment in put_dec_full9 for choice of constants */
|
2010-05-25 05:33:16 +08:00
|
|
|
static noinline_for_stack
|
2012-10-05 08:12:29 +08:00
|
|
|
void put_dec_full4(char *buf, unsigned q)
|
2007-07-16 14:41:56 +08:00
|
|
|
{
|
vsprintf: further optimize decimal conversion
Previous code was using optimizations which were developed to work well
even on narrow-word CPUs (by today's standards). But Linux runs only on
32-bit and wider CPUs. We can use that.
First: using 32x32->64 multiply and trivial 32-bit shift, we can correctly
divide by 10 much larger numbers, and thus we can print groups of 9 digits
instead of groups of 5 digits.
Next: there are two algorithms to print larger numbers. One is generic:
divide by 1000000000 and repeatedly print groups of (up to) 9 digits.
It's conceptually simple, but requires an (unsigned long long) /
1000000000 division.
Second algorithm splits 64-bit unsigned long long into 16-bit chunks,
manipulates them cleverly and generates groups of 4 decimal digits. It so
happens that it does NOT require long long division.
If long is > 32 bits, division of 64-bit values is relatively easy, and we
will use the first algorithm. If long long is > 64 bits (strange
architecture with VERY large long long), second algorithm can't be used,
and we again use the first one.
Else (if long is 32 bits and long long is 64 bits) we use second one.
And third: there is a simple optimization which takes fast path not only
for zero as was done before, but for all one-digit numbers.
In all tested cases new code is faster than old one, in many cases by 30%,
in few cases by more than 50% (for example, on x86-32, conversion of
12345678). Code growth is ~0 in 32-bit case and ~130 bytes in 64-bit
case.
This patch is based upon an original from Michal Nazarewicz.
[akpm@linux-foundation.org: checkpatch fixes]
Signed-off-by: Michal Nazarewicz <mina86@mina86.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Cc: Douglas W Jones <jones@cs.uiowa.edu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-06-01 07:26:08 +08:00
|
|
|
unsigned r;
|
2012-10-05 08:12:27 +08:00
|
|
|
r = (q * 0xccd) >> 15;
|
2012-10-05 08:12:29 +08:00
|
|
|
buf[0] = (q - 10 * r) + '0';
|
2012-10-05 08:12:27 +08:00
|
|
|
q = (r * 0xcd) >> 11;
|
2012-10-05 08:12:29 +08:00
|
|
|
buf[1] = (r - 10 * q) + '0';
|
vsprintf: further optimize decimal conversion
Previous code was using optimizations which were developed to work well
even on narrow-word CPUs (by today's standards). But Linux runs only on
32-bit and wider CPUs. We can use that.
First: using 32x32->64 multiply and trivial 32-bit shift, we can correctly
divide by 10 much larger numbers, and thus we can print groups of 9 digits
instead of groups of 5 digits.
Next: there are two algorithms to print larger numbers. One is generic:
divide by 1000000000 and repeatedly print groups of (up to) 9 digits.
It's conceptually simple, but requires an (unsigned long long) /
1000000000 division.
Second algorithm splits 64-bit unsigned long long into 16-bit chunks,
manipulates them cleverly and generates groups of 4 decimal digits. It so
happens that it does NOT require long long division.
If long is > 32 bits, division of 64-bit values is relatively easy, and we
will use the first algorithm. If long long is > 64 bits (strange
architecture with VERY large long long), second algorithm can't be used,
and we again use the first one.
Else (if long is 32 bits and long long is 64 bits) we use second one.
And third: there is a simple optimization which takes fast path not only
for zero as was done before, but for all one-digit numbers.
In all tested cases new code is faster than old one, in many cases by 30%,
in few cases by more than 50% (for example, on x86-32, conversion of
12345678). Code growth is ~0 in 32-bit case and ~130 bytes in 64-bit
case.
This patch is based upon an original from Michal Nazarewicz.
[akpm@linux-foundation.org: checkpatch fixes]
Signed-off-by: Michal Nazarewicz <mina86@mina86.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Cc: Douglas W Jones <jones@cs.uiowa.edu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-06-01 07:26:08 +08:00
|
|
|
r = (q * 0xcd) >> 11;
|
2012-10-05 08:12:29 +08:00
|
|
|
buf[2] = (q - 10 * r) + '0';
|
|
|
|
buf[3] = r + '0';
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Call put_dec_full4 on x % 10000, return x / 10000.
|
|
|
|
* The approximation x/10000 == (x * 0x346DC5D7) >> 43
|
|
|
|
* holds for all x < 1,128,869,999. The largest value this
|
|
|
|
* helper will ever be asked to convert is 1,125,520,955.
|
|
|
|
* (d1 in the put_dec code, assuming n is all-ones).
|
|
|
|
*/
|
|
|
|
static
|
|
|
|
unsigned put_dec_helper4(char *buf, unsigned x)
|
|
|
|
{
|
|
|
|
uint32_t q = (x * (uint64_t)0x346DC5D7) >> 43;
|
|
|
|
|
|
|
|
put_dec_full4(buf, x - q * 10000);
|
|
|
|
return q;
|
2007-07-16 14:41:56 +08:00
|
|
|
}
|
|
|
|
|
vsprintf: further optimize decimal conversion
Previous code was using optimizations which were developed to work well
even on narrow-word CPUs (by today's standards). But Linux runs only on
32-bit and wider CPUs. We can use that.
First: using 32x32->64 multiply and trivial 32-bit shift, we can correctly
divide by 10 much larger numbers, and thus we can print groups of 9 digits
instead of groups of 5 digits.
Next: there are two algorithms to print larger numbers. One is generic:
divide by 1000000000 and repeatedly print groups of (up to) 9 digits.
It's conceptually simple, but requires an (unsigned long long) /
1000000000 division.
Second algorithm splits 64-bit unsigned long long into 16-bit chunks,
manipulates them cleverly and generates groups of 4 decimal digits. It so
happens that it does NOT require long long division.
If long is > 32 bits, division of 64-bit values is relatively easy, and we
will use the first algorithm. If long long is > 64 bits (strange
architecture with VERY large long long), second algorithm can't be used,
and we again use the first one.
Else (if long is 32 bits and long long is 64 bits) we use second one.
And third: there is a simple optimization which takes fast path not only
for zero as was done before, but for all one-digit numbers.
In all tested cases new code is faster than old one, in many cases by 30%,
in few cases by more than 50% (for example, on x86-32, conversion of
12345678). Code growth is ~0 in 32-bit case and ~130 bytes in 64-bit
case.
This patch is based upon an original from Michal Nazarewicz.
[akpm@linux-foundation.org: checkpatch fixes]
Signed-off-by: Michal Nazarewicz <mina86@mina86.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Cc: Douglas W Jones <jones@cs.uiowa.edu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-06-01 07:26:08 +08:00
|
|
|
/* Based on code by Douglas W. Jones found at
|
|
|
|
* <http://www.cs.uiowa.edu/~jones/bcd/decimal.html#sixtyfour>
|
|
|
|
* (with permission from the author).
|
|
|
|
* Performs no 64-bit division and hence should be fast on 32-bit machines.
|
|
|
|
*/
|
|
|
|
static
|
|
|
|
char *put_dec(char *buf, unsigned long long n)
|
|
|
|
{
|
|
|
|
uint32_t d3, d2, d1, q, h;
|
|
|
|
|
|
|
|
if (n < 100*1000*1000)
|
|
|
|
return put_dec_trunc8(buf, n);
|
|
|
|
|
|
|
|
d1 = ((uint32_t)n >> 16); /* implicit "& 0xffff" */
|
|
|
|
h = (n >> 32);
|
|
|
|
d2 = (h ) & 0xffff;
|
|
|
|
d3 = (h >> 16); /* implicit "& 0xffff" */
|
|
|
|
|
|
|
|
q = 656 * d3 + 7296 * d2 + 5536 * d1 + ((uint32_t)n & 0xffff);
|
2012-10-05 08:12:29 +08:00
|
|
|
q = put_dec_helper4(buf, q);
|
|
|
|
|
|
|
|
q += 7671 * d3 + 9496 * d2 + 6 * d1;
|
|
|
|
q = put_dec_helper4(buf+4, q);
|
|
|
|
|
|
|
|
q += 4749 * d3 + 42 * d2;
|
|
|
|
q = put_dec_helper4(buf+8, q);
|
vsprintf: further optimize decimal conversion
Previous code was using optimizations which were developed to work well
even on narrow-word CPUs (by today's standards). But Linux runs only on
32-bit and wider CPUs. We can use that.
First: using 32x32->64 multiply and trivial 32-bit shift, we can correctly
divide by 10 much larger numbers, and thus we can print groups of 9 digits
instead of groups of 5 digits.
Next: there are two algorithms to print larger numbers. One is generic:
divide by 1000000000 and repeatedly print groups of (up to) 9 digits.
It's conceptually simple, but requires an (unsigned long long) /
1000000000 division.
Second algorithm splits 64-bit unsigned long long into 16-bit chunks,
manipulates them cleverly and generates groups of 4 decimal digits. It so
happens that it does NOT require long long division.
If long is > 32 bits, division of 64-bit values is relatively easy, and we
will use the first algorithm. If long long is > 64 bits (strange
architecture with VERY large long long), second algorithm can't be used,
and we again use the first one.
Else (if long is 32 bits and long long is 64 bits) we use second one.
And third: there is a simple optimization which takes fast path not only
for zero as was done before, but for all one-digit numbers.
In all tested cases new code is faster than old one, in many cases by 30%,
in few cases by more than 50% (for example, on x86-32, conversion of
12345678). Code growth is ~0 in 32-bit case and ~130 bytes in 64-bit
case.
This patch is based upon an original from Michal Nazarewicz.
[akpm@linux-foundation.org: checkpatch fixes]
Signed-off-by: Michal Nazarewicz <mina86@mina86.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Cc: Douglas W Jones <jones@cs.uiowa.edu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-06-01 07:26:08 +08:00
|
|
|
|
2012-10-05 08:12:29 +08:00
|
|
|
q += 281 * d3;
|
|
|
|
buf += 12;
|
|
|
|
if (q)
|
|
|
|
buf = put_dec_trunc8(buf, q);
|
|
|
|
else while (buf[-1] == '0')
|
vsprintf: further optimize decimal conversion
Previous code was using optimizations which were developed to work well
even on narrow-word CPUs (by today's standards). But Linux runs only on
32-bit and wider CPUs. We can use that.
First: using 32x32->64 multiply and trivial 32-bit shift, we can correctly
divide by 10 much larger numbers, and thus we can print groups of 9 digits
instead of groups of 5 digits.
Next: there are two algorithms to print larger numbers. One is generic:
divide by 1000000000 and repeatedly print groups of (up to) 9 digits.
It's conceptually simple, but requires an (unsigned long long) /
1000000000 division.
Second algorithm splits 64-bit unsigned long long into 16-bit chunks,
manipulates them cleverly and generates groups of 4 decimal digits. It so
happens that it does NOT require long long division.
If long is > 32 bits, division of 64-bit values is relatively easy, and we
will use the first algorithm. If long long is > 64 bits (strange
architecture with VERY large long long), second algorithm can't be used,
and we again use the first one.
Else (if long is 32 bits and long long is 64 bits) we use second one.
And third: there is a simple optimization which takes fast path not only
for zero as was done before, but for all one-digit numbers.
In all tested cases new code is faster than old one, in many cases by 30%,
in few cases by more than 50% (for example, on x86-32, conversion of
12345678). Code growth is ~0 in 32-bit case and ~130 bytes in 64-bit
case.
This patch is based upon an original from Michal Nazarewicz.
[akpm@linux-foundation.org: checkpatch fixes]
Signed-off-by: Michal Nazarewicz <mina86@mina86.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Cc: Douglas W Jones <jones@cs.uiowa.edu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-06-01 07:26:08 +08:00
|
|
|
--buf;
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2012-03-24 06:02:54 +08:00
|
|
|
/*
|
|
|
|
* Convert passed number to decimal string.
|
|
|
|
* Returns the length of string. On buffer overflow, returns 0.
|
|
|
|
*
|
|
|
|
* If speed is not important, use snprintf(). It's easy to read the code.
|
|
|
|
*/
|
|
|
|
int num_to_str(char *buf, int size, unsigned long long num)
|
|
|
|
{
|
vsprintf: further optimize decimal conversion
Previous code was using optimizations which were developed to work well
even on narrow-word CPUs (by today's standards). But Linux runs only on
32-bit and wider CPUs. We can use that.
First: using 32x32->64 multiply and trivial 32-bit shift, we can correctly
divide by 10 much larger numbers, and thus we can print groups of 9 digits
instead of groups of 5 digits.
Next: there are two algorithms to print larger numbers. One is generic:
divide by 1000000000 and repeatedly print groups of (up to) 9 digits.
It's conceptually simple, but requires an (unsigned long long) /
1000000000 division.
Second algorithm splits 64-bit unsigned long long into 16-bit chunks,
manipulates them cleverly and generates groups of 4 decimal digits. It so
happens that it does NOT require long long division.
If long is > 32 bits, division of 64-bit values is relatively easy, and we
will use the first algorithm. If long long is > 64 bits (strange
architecture with VERY large long long), second algorithm can't be used,
and we again use the first one.
Else (if long is 32 bits and long long is 64 bits) we use second one.
And third: there is a simple optimization which takes fast path not only
for zero as was done before, but for all one-digit numbers.
In all tested cases new code is faster than old one, in many cases by 30%,
in few cases by more than 50% (for example, on x86-32, conversion of
12345678). Code growth is ~0 in 32-bit case and ~130 bytes in 64-bit
case.
This patch is based upon an original from Michal Nazarewicz.
[akpm@linux-foundation.org: checkpatch fixes]
Signed-off-by: Michal Nazarewicz <mina86@mina86.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Cc: Douglas W Jones <jones@cs.uiowa.edu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-06-01 07:26:08 +08:00
|
|
|
char tmp[sizeof(num) * 3];
|
2012-03-24 06:02:54 +08:00
|
|
|
int idx, len;
|
|
|
|
|
vsprintf: further optimize decimal conversion
Previous code was using optimizations which were developed to work well
even on narrow-word CPUs (by today's standards). But Linux runs only on
32-bit and wider CPUs. We can use that.
First: using 32x32->64 multiply and trivial 32-bit shift, we can correctly
divide by 10 much larger numbers, and thus we can print groups of 9 digits
instead of groups of 5 digits.
Next: there are two algorithms to print larger numbers. One is generic:
divide by 1000000000 and repeatedly print groups of (up to) 9 digits.
It's conceptually simple, but requires an (unsigned long long) /
1000000000 division.
Second algorithm splits 64-bit unsigned long long into 16-bit chunks,
manipulates them cleverly and generates groups of 4 decimal digits. It so
happens that it does NOT require long long division.
If long is > 32 bits, division of 64-bit values is relatively easy, and we
will use the first algorithm. If long long is > 64 bits (strange
architecture with VERY large long long), second algorithm can't be used,
and we again use the first one.
Else (if long is 32 bits and long long is 64 bits) we use second one.
And third: there is a simple optimization which takes fast path not only
for zero as was done before, but for all one-digit numbers.
In all tested cases new code is faster than old one, in many cases by 30%,
in few cases by more than 50% (for example, on x86-32, conversion of
12345678). Code growth is ~0 in 32-bit case and ~130 bytes in 64-bit
case.
This patch is based upon an original from Michal Nazarewicz.
[akpm@linux-foundation.org: checkpatch fixes]
Signed-off-by: Michal Nazarewicz <mina86@mina86.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Cc: Douglas W Jones <jones@cs.uiowa.edu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-06-01 07:26:08 +08:00
|
|
|
/* put_dec() may work incorrectly for num = 0 (generate "", not "0") */
|
|
|
|
if (num <= 9) {
|
|
|
|
tmp[0] = '0' + num;
|
|
|
|
len = 1;
|
|
|
|
} else {
|
|
|
|
len = put_dec(tmp, num) - tmp;
|
|
|
|
}
|
2012-03-24 06:02:54 +08:00
|
|
|
|
|
|
|
if (len > size)
|
|
|
|
return 0;
|
|
|
|
for (idx = 0; idx < len; ++idx)
|
|
|
|
buf[idx] = tmp[len - idx - 1];
|
vsprintf: further optimize decimal conversion
Previous code was using optimizations which were developed to work well
even on narrow-word CPUs (by today's standards). But Linux runs only on
32-bit and wider CPUs. We can use that.
First: using 32x32->64 multiply and trivial 32-bit shift, we can correctly
divide by 10 much larger numbers, and thus we can print groups of 9 digits
instead of groups of 5 digits.
Next: there are two algorithms to print larger numbers. One is generic:
divide by 1000000000 and repeatedly print groups of (up to) 9 digits.
It's conceptually simple, but requires an (unsigned long long) /
1000000000 division.
Second algorithm splits 64-bit unsigned long long into 16-bit chunks,
manipulates them cleverly and generates groups of 4 decimal digits. It so
happens that it does NOT require long long division.
If long is > 32 bits, division of 64-bit values is relatively easy, and we
will use the first algorithm. If long long is > 64 bits (strange
architecture with VERY large long long), second algorithm can't be used,
and we again use the first one.
Else (if long is 32 bits and long long is 64 bits) we use second one.
And third: there is a simple optimization which takes fast path not only
for zero as was done before, but for all one-digit numbers.
In all tested cases new code is faster than old one, in many cases by 30%,
in few cases by more than 50% (for example, on x86-32, conversion of
12345678). Code growth is ~0 in 32-bit case and ~130 bytes in 64-bit
case.
This patch is based upon an original from Michal Nazarewicz.
[akpm@linux-foundation.org: checkpatch fixes]
Signed-off-by: Michal Nazarewicz <mina86@mina86.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Cc: Douglas W Jones <jones@cs.uiowa.edu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-06-01 07:26:08 +08:00
|
|
|
return len;
|
2012-03-24 06:02:54 +08:00
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#define ZEROPAD 1 /* pad with zero */
|
|
|
|
#define SIGN 2 /* unsigned/signed long */
|
|
|
|
#define PLUS 4 /* show plus */
|
|
|
|
#define SPACE 8 /* space if plus */
|
|
|
|
#define LEFT 16 /* left justified */
|
2010-03-06 01:47:31 +08:00
|
|
|
#define SMALL 32 /* use lowercase in hex (must be 32 == 0x20) */
|
|
|
|
#define SPECIAL 64 /* prefix hex with "0x", octal with "0" */
|
2005-04-17 06:20:36 +08:00
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
enum format_type {
|
|
|
|
FORMAT_TYPE_NONE, /* Just a string part */
|
2009-03-14 19:08:50 +08:00
|
|
|
FORMAT_TYPE_WIDTH,
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
FORMAT_TYPE_PRECISION,
|
|
|
|
FORMAT_TYPE_CHAR,
|
|
|
|
FORMAT_TYPE_STR,
|
|
|
|
FORMAT_TYPE_PTR,
|
|
|
|
FORMAT_TYPE_PERCENT_CHAR,
|
|
|
|
FORMAT_TYPE_INVALID,
|
|
|
|
FORMAT_TYPE_LONG_LONG,
|
|
|
|
FORMAT_TYPE_ULONG,
|
|
|
|
FORMAT_TYPE_LONG,
|
2009-03-27 17:07:05 +08:00
|
|
|
FORMAT_TYPE_UBYTE,
|
|
|
|
FORMAT_TYPE_BYTE,
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
FORMAT_TYPE_USHORT,
|
|
|
|
FORMAT_TYPE_SHORT,
|
|
|
|
FORMAT_TYPE_UINT,
|
|
|
|
FORMAT_TYPE_INT,
|
|
|
|
FORMAT_TYPE_NRCHARS,
|
|
|
|
FORMAT_TYPE_SIZE_T,
|
|
|
|
FORMAT_TYPE_PTRDIFF
|
|
|
|
};
|
|
|
|
|
|
|
|
struct printf_spec {
|
2010-04-15 00:27:40 +08:00
|
|
|
u8 type; /* format_type enum */
|
2010-03-07 09:10:14 +08:00
|
|
|
u8 flags; /* flags to number() */
|
2010-04-15 00:27:40 +08:00
|
|
|
u8 base; /* number base, 8, 10 or 16 only */
|
|
|
|
u8 qualifier; /* number qualifier, one of 'hHlLtzZ' */
|
|
|
|
s16 field_width; /* width of output field */
|
|
|
|
s16 precision; /* # of digits/chars */
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
};
|
|
|
|
|
2010-05-25 05:33:16 +08:00
|
|
|
static noinline_for_stack
|
|
|
|
char *number(char *buf, char *end, unsigned long long num,
|
|
|
|
struct printf_spec spec)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-02-10 06:24:09 +08:00
|
|
|
/* we are called with base 8, 10 or 16, only, thus don't need "G..." */
|
|
|
|
static const char digits[16] = "0123456789ABCDEF"; /* "GHIJKLMNOPQRSTUVWXYZ"; */
|
|
|
|
|
|
|
|
char tmp[66];
|
|
|
|
char sign;
|
|
|
|
char locase;
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
int need_pfx = ((spec.flags & SPECIAL) && spec.base != 10);
|
2005-04-17 06:20:36 +08:00
|
|
|
int i;
|
2012-05-30 06:07:35 +08:00
|
|
|
bool is_zero = num == 0LL;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-02-10 06:24:09 +08:00
|
|
|
/* locase = 0 or 0x20. ORing digits or letters with 'locase'
|
|
|
|
* produces same digits or (maybe lowercased) letters */
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
locase = (spec.flags & SMALL);
|
|
|
|
if (spec.flags & LEFT)
|
|
|
|
spec.flags &= ~ZEROPAD;
|
2005-04-17 06:20:36 +08:00
|
|
|
sign = 0;
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
if (spec.flags & SIGN) {
|
2009-12-15 10:00:57 +08:00
|
|
|
if ((signed long long)num < 0) {
|
2005-04-17 06:20:36 +08:00
|
|
|
sign = '-';
|
2009-12-15 10:00:57 +08:00
|
|
|
num = -(signed long long)num;
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
spec.field_width--;
|
|
|
|
} else if (spec.flags & PLUS) {
|
2005-04-17 06:20:36 +08:00
|
|
|
sign = '+';
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
spec.field_width--;
|
|
|
|
} else if (spec.flags & SPACE) {
|
2005-04-17 06:20:36 +08:00
|
|
|
sign = ' ';
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
spec.field_width--;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
2007-07-16 14:41:54 +08:00
|
|
|
if (need_pfx) {
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
if (spec.base == 16)
|
2012-05-30 06:07:35 +08:00
|
|
|
spec.field_width -= 2;
|
|
|
|
else if (!is_zero)
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
spec.field_width--;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2007-07-16 14:41:54 +08:00
|
|
|
|
|
|
|
/* generate full string in tmp[], in reverse order */
|
2005-04-17 06:20:36 +08:00
|
|
|
i = 0;
|
vsprintf: further optimize decimal conversion
Previous code was using optimizations which were developed to work well
even on narrow-word CPUs (by today's standards). But Linux runs only on
32-bit and wider CPUs. We can use that.
First: using 32x32->64 multiply and trivial 32-bit shift, we can correctly
divide by 10 much larger numbers, and thus we can print groups of 9 digits
instead of groups of 5 digits.
Next: there are two algorithms to print larger numbers. One is generic:
divide by 1000000000 and repeatedly print groups of (up to) 9 digits.
It's conceptually simple, but requires an (unsigned long long) /
1000000000 division.
Second algorithm splits 64-bit unsigned long long into 16-bit chunks,
manipulates them cleverly and generates groups of 4 decimal digits. It so
happens that it does NOT require long long division.
If long is > 32 bits, division of 64-bit values is relatively easy, and we
will use the first algorithm. If long long is > 64 bits (strange
architecture with VERY large long long), second algorithm can't be used,
and we again use the first one.
Else (if long is 32 bits and long long is 64 bits) we use second one.
And third: there is a simple optimization which takes fast path not only
for zero as was done before, but for all one-digit numbers.
In all tested cases new code is faster than old one, in many cases by 30%,
in few cases by more than 50% (for example, on x86-32, conversion of
12345678). Code growth is ~0 in 32-bit case and ~130 bytes in 64-bit
case.
This patch is based upon an original from Michal Nazarewicz.
[akpm@linux-foundation.org: checkpatch fixes]
Signed-off-by: Michal Nazarewicz <mina86@mina86.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Cc: Douglas W Jones <jones@cs.uiowa.edu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-06-01 07:26:08 +08:00
|
|
|
if (num < spec.base)
|
|
|
|
tmp[i++] = digits[num] | locase;
|
2007-07-16 14:41:56 +08:00
|
|
|
/* Generic code, for any base:
|
|
|
|
else do {
|
2008-02-10 06:24:09 +08:00
|
|
|
tmp[i++] = (digits[do_div(num,base)] | locase);
|
2007-07-16 14:41:56 +08:00
|
|
|
} while (num != 0);
|
|
|
|
*/
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
else if (spec.base != 10) { /* 8 or 16 */
|
|
|
|
int mask = spec.base - 1;
|
2007-07-16 14:41:54 +08:00
|
|
|
int shift = 3;
|
2009-12-15 10:00:57 +08:00
|
|
|
|
|
|
|
if (spec.base == 16)
|
|
|
|
shift = 4;
|
2007-07-16 14:41:54 +08:00
|
|
|
do {
|
2008-02-10 06:24:09 +08:00
|
|
|
tmp[i++] = (digits[((unsigned char)num) & mask] | locase);
|
2007-07-16 14:41:54 +08:00
|
|
|
num >>= shift;
|
|
|
|
} while (num);
|
2007-07-16 14:41:56 +08:00
|
|
|
} else { /* base 10 */
|
|
|
|
i = put_dec(tmp, num) - tmp;
|
|
|
|
}
|
2007-07-16 14:41:54 +08:00
|
|
|
|
|
|
|
/* printing 100 using %2d gives "100", not "00" */
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
if (i > spec.precision)
|
|
|
|
spec.precision = i;
|
2007-07-16 14:41:54 +08:00
|
|
|
/* leading space padding */
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
spec.field_width -= spec.precision;
|
|
|
|
if (!(spec.flags & (ZEROPAD+LEFT))) {
|
2009-12-15 10:00:57 +08:00
|
|
|
while (--spec.field_width >= 0) {
|
2006-06-25 20:49:17 +08:00
|
|
|
if (buf < end)
|
2005-04-17 06:20:36 +08:00
|
|
|
*buf = ' ';
|
|
|
|
++buf;
|
|
|
|
}
|
|
|
|
}
|
2007-07-16 14:41:54 +08:00
|
|
|
/* sign */
|
2005-04-17 06:20:36 +08:00
|
|
|
if (sign) {
|
2006-06-25 20:49:17 +08:00
|
|
|
if (buf < end)
|
2005-04-17 06:20:36 +08:00
|
|
|
*buf = sign;
|
|
|
|
++buf;
|
|
|
|
}
|
2007-07-16 14:41:54 +08:00
|
|
|
/* "0x" / "0" prefix */
|
|
|
|
if (need_pfx) {
|
2012-05-30 06:07:35 +08:00
|
|
|
if (spec.base == 16 || !is_zero) {
|
|
|
|
if (buf < end)
|
|
|
|
*buf = '0';
|
|
|
|
++buf;
|
|
|
|
}
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
if (spec.base == 16) {
|
2006-06-25 20:49:17 +08:00
|
|
|
if (buf < end)
|
2008-02-10 06:24:09 +08:00
|
|
|
*buf = ('X' | locase);
|
2005-04-17 06:20:36 +08:00
|
|
|
++buf;
|
|
|
|
}
|
|
|
|
}
|
2007-07-16 14:41:54 +08:00
|
|
|
/* zero or space padding */
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
if (!(spec.flags & LEFT)) {
|
|
|
|
char c = (spec.flags & ZEROPAD) ? '0' : ' ';
|
|
|
|
while (--spec.field_width >= 0) {
|
2006-06-25 20:49:17 +08:00
|
|
|
if (buf < end)
|
2005-04-17 06:20:36 +08:00
|
|
|
*buf = c;
|
|
|
|
++buf;
|
|
|
|
}
|
|
|
|
}
|
2007-07-16 14:41:54 +08:00
|
|
|
/* hmm even more zero padding? */
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
while (i <= --spec.precision) {
|
2006-06-25 20:49:17 +08:00
|
|
|
if (buf < end)
|
2005-04-17 06:20:36 +08:00
|
|
|
*buf = '0';
|
|
|
|
++buf;
|
|
|
|
}
|
2007-07-16 14:41:54 +08:00
|
|
|
/* actual digits of result */
|
|
|
|
while (--i >= 0) {
|
2006-06-25 20:49:17 +08:00
|
|
|
if (buf < end)
|
2005-04-17 06:20:36 +08:00
|
|
|
*buf = tmp[i];
|
|
|
|
++buf;
|
|
|
|
}
|
2007-07-16 14:41:54 +08:00
|
|
|
/* trailing space padding */
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
while (--spec.field_width >= 0) {
|
2006-06-25 20:49:17 +08:00
|
|
|
if (buf < end)
|
2005-04-17 06:20:36 +08:00
|
|
|
*buf = ' ';
|
|
|
|
++buf;
|
|
|
|
}
|
2009-12-15 10:00:57 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2010-05-25 05:33:16 +08:00
|
|
|
static noinline_for_stack
|
|
|
|
char *string(char *buf, char *end, const char *s, struct printf_spec spec)
|
2008-07-07 07:06:25 +08:00
|
|
|
{
|
|
|
|
int len, i;
|
|
|
|
|
|
|
|
if ((unsigned long)s < PAGE_SIZE)
|
2009-12-15 10:00:55 +08:00
|
|
|
s = "(null)";
|
2008-07-07 07:06:25 +08:00
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
len = strnlen(s, spec.precision);
|
2008-07-07 07:06:25 +08:00
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
if (!(spec.flags & LEFT)) {
|
|
|
|
while (len < spec.field_width--) {
|
2008-07-07 07:06:25 +08:00
|
|
|
if (buf < end)
|
|
|
|
*buf = ' ';
|
|
|
|
++buf;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (i = 0; i < len; ++i) {
|
|
|
|
if (buf < end)
|
|
|
|
*buf = *s;
|
|
|
|
++buf; ++s;
|
|
|
|
}
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
while (len < spec.field_width--) {
|
2008-07-07 07:06:25 +08:00
|
|
|
if (buf < end)
|
|
|
|
*buf = ' ';
|
|
|
|
++buf;
|
|
|
|
}
|
2009-12-15 10:00:57 +08:00
|
|
|
|
2008-07-07 07:06:25 +08:00
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2013-09-04 00:00:44 +08:00
|
|
|
static void widen(char *buf, char *end, unsigned len, unsigned spaces)
|
|
|
|
{
|
|
|
|
size_t size;
|
|
|
|
if (buf >= end) /* nowhere to put anything */
|
|
|
|
return;
|
|
|
|
size = end - buf;
|
|
|
|
if (size <= spaces) {
|
|
|
|
memset(buf, ' ', size);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (len) {
|
|
|
|
if (len > size - spaces)
|
|
|
|
len = size - spaces;
|
|
|
|
memmove(buf + spaces, buf, len);
|
|
|
|
}
|
|
|
|
memset(buf, ' ', spaces);
|
|
|
|
}
|
|
|
|
|
|
|
|
static noinline_for_stack
|
|
|
|
char *dentry_name(char *buf, char *end, const struct dentry *d, struct printf_spec spec,
|
|
|
|
const char *fmt)
|
|
|
|
{
|
|
|
|
const char *array[4], *s;
|
|
|
|
const struct dentry *p;
|
|
|
|
int depth;
|
|
|
|
int i, n;
|
|
|
|
|
|
|
|
switch (fmt[1]) {
|
|
|
|
case '2': case '3': case '4':
|
|
|
|
depth = fmt[1] - '0';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
depth = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
for (i = 0; i < depth; i++, d = p) {
|
|
|
|
p = ACCESS_ONCE(d->d_parent);
|
|
|
|
array[i] = ACCESS_ONCE(d->d_name.name);
|
|
|
|
if (p == d) {
|
|
|
|
if (i)
|
|
|
|
array[i] = "";
|
|
|
|
i++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s = array[--i];
|
|
|
|
for (n = 0; n != spec.precision; n++, buf++) {
|
|
|
|
char c = *s++;
|
|
|
|
if (!c) {
|
|
|
|
if (!i)
|
|
|
|
break;
|
|
|
|
c = '/';
|
|
|
|
s = array[--i];
|
|
|
|
}
|
|
|
|
if (buf < end)
|
|
|
|
*buf = c;
|
|
|
|
}
|
|
|
|
rcu_read_unlock();
|
|
|
|
if (n < spec.field_width) {
|
|
|
|
/* we want to pad the sucker */
|
|
|
|
unsigned spaces = spec.field_width - n;
|
|
|
|
if (!(spec.flags & LEFT)) {
|
|
|
|
widen(buf - n, end, n, spaces);
|
|
|
|
return buf + spaces;
|
|
|
|
}
|
|
|
|
while (spaces--) {
|
|
|
|
if (buf < end)
|
|
|
|
*buf = ' ';
|
|
|
|
++buf;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2010-05-25 05:33:16 +08:00
|
|
|
static noinline_for_stack
|
|
|
|
char *symbol_string(char *buf, char *end, void *ptr,
|
2012-12-13 02:18:50 +08:00
|
|
|
struct printf_spec spec, const char *fmt)
|
2008-07-07 07:43:12 +08:00
|
|
|
{
|
2012-12-13 02:18:50 +08:00
|
|
|
unsigned long value;
|
2008-07-07 07:43:12 +08:00
|
|
|
#ifdef CONFIG_KALLSYMS
|
|
|
|
char sym[KSYM_SYMBOL_LEN];
|
2012-12-13 02:18:50 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (fmt[1] == 'R')
|
|
|
|
ptr = __builtin_extract_return_addr(ptr);
|
|
|
|
value = (unsigned long)ptr;
|
|
|
|
|
|
|
|
#ifdef CONFIG_KALLSYMS
|
|
|
|
if (*fmt == 'B')
|
2011-03-24 10:42:29 +08:00
|
|
|
sprint_backtrace(sym, value);
|
2012-12-13 02:18:50 +08:00
|
|
|
else if (*fmt != 'f' && *fmt != 's')
|
vsprintf: introduce %pf format specifier
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 <fweisbec@gmail.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Zhaolei <zhaolei@cn.fujitsu.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
Cc: Li Zefan <lizf@cn.fujitsu.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <20090415154817.GC5989@nowhere>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-15 23:48:18 +08:00
|
|
|
sprint_symbol(sym, value);
|
|
|
|
else
|
2012-05-30 06:07:33 +08:00
|
|
|
sprint_symbol_no_offset(sym, value);
|
2009-12-15 10:00:57 +08:00
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
return string(buf, end, sym, spec);
|
2008-07-07 07:43:12 +08:00
|
|
|
#else
|
2009-12-15 10:00:57 +08:00
|
|
|
spec.field_width = 2 * sizeof(void *);
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
spec.flags |= SPECIAL | SMALL | ZEROPAD;
|
|
|
|
spec.base = 16;
|
2009-12-15 10:00:57 +08:00
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
return number(buf, end, value, spec);
|
2008-07-07 07:43:12 +08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-05-25 05:33:16 +08:00
|
|
|
static noinline_for_stack
|
|
|
|
char *resource_string(char *buf, char *end, struct resource *res,
|
|
|
|
struct printf_spec spec, const char *fmt)
|
2008-10-20 12:07:34 +08:00
|
|
|
{
|
|
|
|
#ifndef IO_RSRC_PRINTK_SIZE
|
2009-10-07 05:33:29 +08:00
|
|
|
#define IO_RSRC_PRINTK_SIZE 6
|
2008-10-20 12:07:34 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef MEM_RSRC_PRINTK_SIZE
|
2009-10-07 05:33:29 +08:00
|
|
|
#define MEM_RSRC_PRINTK_SIZE 10
|
2008-10-20 12:07:34 +08:00
|
|
|
#endif
|
2010-03-06 01:47:37 +08:00
|
|
|
static const struct printf_spec io_spec = {
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
.base = 16,
|
2010-03-06 01:47:37 +08:00
|
|
|
.field_width = IO_RSRC_PRINTK_SIZE,
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
.precision = -1,
|
|
|
|
.flags = SPECIAL | SMALL | ZEROPAD,
|
|
|
|
};
|
2010-03-06 01:47:37 +08:00
|
|
|
static const struct printf_spec mem_spec = {
|
|
|
|
.base = 16,
|
|
|
|
.field_width = MEM_RSRC_PRINTK_SIZE,
|
|
|
|
.precision = -1,
|
|
|
|
.flags = SPECIAL | SMALL | ZEROPAD,
|
|
|
|
};
|
2010-03-06 01:47:42 +08:00
|
|
|
static const struct printf_spec bus_spec = {
|
|
|
|
.base = 16,
|
|
|
|
.field_width = 2,
|
|
|
|
.precision = -1,
|
|
|
|
.flags = SMALL | ZEROPAD,
|
|
|
|
};
|
2010-03-06 01:47:37 +08:00
|
|
|
static const struct printf_spec dec_spec = {
|
2009-10-07 05:33:34 +08:00
|
|
|
.base = 10,
|
|
|
|
.precision = -1,
|
|
|
|
.flags = 0,
|
|
|
|
};
|
2010-03-06 01:47:37 +08:00
|
|
|
static const struct printf_spec str_spec = {
|
2009-10-07 05:33:39 +08:00
|
|
|
.field_width = -1,
|
|
|
|
.precision = 10,
|
|
|
|
.flags = LEFT,
|
|
|
|
};
|
2010-03-06 01:47:37 +08:00
|
|
|
static const struct printf_spec flag_spec = {
|
2009-10-07 05:33:39 +08:00
|
|
|
.base = 16,
|
|
|
|
.precision = -1,
|
|
|
|
.flags = SPECIAL | SMALL,
|
|
|
|
};
|
2009-10-28 03:26:47 +08:00
|
|
|
|
|
|
|
/* 32-bit res (sizeof==4): 10 chars in dec, 10 in hex ("0x" + 8)
|
|
|
|
* 64-bit res (sizeof==8): 20 chars in dec, 18 in hex ("0x" + 16) */
|
|
|
|
#define RSRC_BUF_SIZE ((2 * sizeof(resource_size_t)) + 4)
|
|
|
|
#define FLAG_BUF_SIZE (2 * sizeof(res->flags))
|
2010-03-06 01:47:47 +08:00
|
|
|
#define DECODED_BUF_SIZE sizeof("[mem - 64bit pref window disabled]")
|
2009-10-28 03:26:47 +08:00
|
|
|
#define RAW_BUF_SIZE sizeof("[mem - flags 0x]")
|
|
|
|
char sym[max(2*RSRC_BUF_SIZE + DECODED_BUF_SIZE,
|
|
|
|
2*RSRC_BUF_SIZE + FLAG_BUF_SIZE + RAW_BUF_SIZE)];
|
|
|
|
|
2008-10-20 12:07:34 +08:00
|
|
|
char *p = sym, *pend = sym + sizeof(sym);
|
2009-10-28 03:26:47 +08:00
|
|
|
int decode = (fmt[0] == 'R') ? 1 : 0;
|
2010-03-06 01:47:37 +08:00
|
|
|
const struct printf_spec *specp;
|
2008-10-20 12:07:34 +08:00
|
|
|
|
|
|
|
*p++ = '[';
|
2010-03-06 01:47:37 +08:00
|
|
|
if (res->flags & IORESOURCE_IO) {
|
2009-10-28 03:26:47 +08:00
|
|
|
p = string(p, pend, "io ", str_spec);
|
2010-03-06 01:47:37 +08:00
|
|
|
specp = &io_spec;
|
|
|
|
} else if (res->flags & IORESOURCE_MEM) {
|
2009-10-28 03:26:47 +08:00
|
|
|
p = string(p, pend, "mem ", str_spec);
|
2010-03-06 01:47:37 +08:00
|
|
|
specp = &mem_spec;
|
|
|
|
} else if (res->flags & IORESOURCE_IRQ) {
|
2009-10-28 03:26:47 +08:00
|
|
|
p = string(p, pend, "irq ", str_spec);
|
2010-03-06 01:47:37 +08:00
|
|
|
specp = &dec_spec;
|
|
|
|
} else if (res->flags & IORESOURCE_DMA) {
|
2009-10-28 03:26:47 +08:00
|
|
|
p = string(p, pend, "dma ", str_spec);
|
2010-03-06 01:47:37 +08:00
|
|
|
specp = &dec_spec;
|
2010-03-06 01:47:42 +08:00
|
|
|
} else if (res->flags & IORESOURCE_BUS) {
|
|
|
|
p = string(p, pend, "bus ", str_spec);
|
|
|
|
specp = &bus_spec;
|
2010-03-06 01:47:37 +08:00
|
|
|
} else {
|
2009-10-28 03:26:47 +08:00
|
|
|
p = string(p, pend, "??? ", str_spec);
|
2010-03-06 01:47:37 +08:00
|
|
|
specp = &mem_spec;
|
2009-10-28 03:26:47 +08:00
|
|
|
decode = 0;
|
2009-10-07 05:33:39 +08:00
|
|
|
}
|
2010-03-06 01:47:37 +08:00
|
|
|
p = number(p, pend, res->start, *specp);
|
2009-10-07 05:33:34 +08:00
|
|
|
if (res->start != res->end) {
|
|
|
|
*p++ = '-';
|
2010-03-06 01:47:37 +08:00
|
|
|
p = number(p, pend, res->end, *specp);
|
2009-10-07 05:33:34 +08:00
|
|
|
}
|
2009-10-28 03:26:47 +08:00
|
|
|
if (decode) {
|
2009-10-07 05:33:39 +08:00
|
|
|
if (res->flags & IORESOURCE_MEM_64)
|
|
|
|
p = string(p, pend, " 64bit", str_spec);
|
|
|
|
if (res->flags & IORESOURCE_PREFETCH)
|
|
|
|
p = string(p, pend, " pref", str_spec);
|
2010-03-06 01:47:47 +08:00
|
|
|
if (res->flags & IORESOURCE_WINDOW)
|
|
|
|
p = string(p, pend, " window", str_spec);
|
2009-10-07 05:33:39 +08:00
|
|
|
if (res->flags & IORESOURCE_DISABLED)
|
|
|
|
p = string(p, pend, " disabled", str_spec);
|
2009-10-28 03:26:47 +08:00
|
|
|
} else {
|
|
|
|
p = string(p, pend, " flags ", str_spec);
|
|
|
|
p = number(p, pend, res->flags, flag_spec);
|
2009-10-07 05:33:39 +08:00
|
|
|
}
|
2008-10-20 12:07:34 +08:00
|
|
|
*p++ = ']';
|
2009-10-28 03:26:47 +08:00
|
|
|
*p = '\0';
|
2008-10-20 12:07:34 +08:00
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
return string(buf, end, sym, spec);
|
2008-10-20 12:07:34 +08:00
|
|
|
}
|
|
|
|
|
2012-07-31 05:40:27 +08:00
|
|
|
static noinline_for_stack
|
|
|
|
char *hex_string(char *buf, char *end, u8 *addr, struct printf_spec spec,
|
|
|
|
const char *fmt)
|
|
|
|
{
|
2013-05-29 03:47:39 +08:00
|
|
|
int i, len = 1; /* if we pass '%ph[CDN]', field width remains
|
2012-07-31 05:40:27 +08:00
|
|
|
negative value, fallback to the default */
|
|
|
|
char separator;
|
|
|
|
|
|
|
|
if (spec.field_width == 0)
|
|
|
|
/* nothing to print */
|
|
|
|
return buf;
|
|
|
|
|
|
|
|
if (ZERO_OR_NULL_PTR(addr))
|
|
|
|
/* NULL pointer */
|
|
|
|
return string(buf, end, NULL, spec);
|
|
|
|
|
|
|
|
switch (fmt[1]) {
|
|
|
|
case 'C':
|
|
|
|
separator = ':';
|
|
|
|
break;
|
|
|
|
case 'D':
|
|
|
|
separator = '-';
|
|
|
|
break;
|
|
|
|
case 'N':
|
|
|
|
separator = 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
separator = ' ';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (spec.field_width > 0)
|
|
|
|
len = min_t(int, spec.field_width, 64);
|
|
|
|
|
|
|
|
for (i = 0; i < len && buf < end - 1; i++) {
|
|
|
|
buf = hex_byte_pack(buf, addr[i]);
|
|
|
|
|
|
|
|
if (buf < end && separator && i != len - 1)
|
|
|
|
*buf++ = separator;
|
|
|
|
}
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2010-05-25 05:33:16 +08:00
|
|
|
static noinline_for_stack
|
|
|
|
char *mac_address_string(char *buf, char *end, u8 *addr,
|
|
|
|
struct printf_spec spec, const char *fmt)
|
2008-10-28 06:47:12 +08:00
|
|
|
{
|
2009-08-17 20:29:44 +08:00
|
|
|
char mac_addr[sizeof("xx:xx:xx:xx:xx:xx")];
|
2008-10-28 06:47:12 +08:00
|
|
|
char *p = mac_addr;
|
|
|
|
int i;
|
2010-01-07 19:43:50 +08:00
|
|
|
char separator;
|
2012-07-31 05:40:23 +08:00
|
|
|
bool reversed = false;
|
2010-01-07 19:43:50 +08:00
|
|
|
|
2012-07-31 05:40:23 +08:00
|
|
|
switch (fmt[1]) {
|
|
|
|
case 'F':
|
2010-01-07 19:43:50 +08:00
|
|
|
separator = '-';
|
2012-07-31 05:40:23 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'R':
|
|
|
|
reversed = true;
|
|
|
|
/* fall through */
|
|
|
|
|
|
|
|
default:
|
2010-01-07 19:43:50 +08:00
|
|
|
separator = ':';
|
2012-07-31 05:40:23 +08:00
|
|
|
break;
|
2010-01-07 19:43:50 +08:00
|
|
|
}
|
2008-10-28 06:47:12 +08:00
|
|
|
|
|
|
|
for (i = 0; i < 6; i++) {
|
2012-07-31 05:40:23 +08:00
|
|
|
if (reversed)
|
|
|
|
p = hex_byte_pack(p, addr[5 - i]);
|
|
|
|
else
|
|
|
|
p = hex_byte_pack(p, addr[i]);
|
|
|
|
|
2009-08-17 20:29:44 +08:00
|
|
|
if (fmt[0] == 'M' && i != 5)
|
2010-01-07 19:43:50 +08:00
|
|
|
*p++ = separator;
|
2008-10-28 06:47:12 +08:00
|
|
|
}
|
|
|
|
*p = '\0';
|
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
return string(buf, end, mac_addr, spec);
|
2008-10-28 06:47:12 +08:00
|
|
|
}
|
|
|
|
|
2010-05-25 05:33:16 +08:00
|
|
|
static noinline_for_stack
|
|
|
|
char *ip4_string(char *p, const u8 *addr, const char *fmt)
|
2009-08-17 20:29:44 +08:00
|
|
|
{
|
|
|
|
int i;
|
2010-01-14 12:23:30 +08:00
|
|
|
bool leading_zeros = (fmt[0] == 'i');
|
|
|
|
int index;
|
|
|
|
int step;
|
|
|
|
|
|
|
|
switch (fmt[2]) {
|
|
|
|
case 'h':
|
|
|
|
#ifdef __BIG_ENDIAN
|
|
|
|
index = 0;
|
|
|
|
step = 1;
|
|
|
|
#else
|
|
|
|
index = 3;
|
|
|
|
step = -1;
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case 'l':
|
|
|
|
index = 3;
|
|
|
|
step = -1;
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
case 'b':
|
|
|
|
default:
|
|
|
|
index = 0;
|
|
|
|
step = 1;
|
|
|
|
break;
|
|
|
|
}
|
2009-08-17 20:29:44 +08:00
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
char temp[3]; /* hold each IP quad in reverse order */
|
vsprintf: further optimize decimal conversion
Previous code was using optimizations which were developed to work well
even on narrow-word CPUs (by today's standards). But Linux runs only on
32-bit and wider CPUs. We can use that.
First: using 32x32->64 multiply and trivial 32-bit shift, we can correctly
divide by 10 much larger numbers, and thus we can print groups of 9 digits
instead of groups of 5 digits.
Next: there are two algorithms to print larger numbers. One is generic:
divide by 1000000000 and repeatedly print groups of (up to) 9 digits.
It's conceptually simple, but requires an (unsigned long long) /
1000000000 division.
Second algorithm splits 64-bit unsigned long long into 16-bit chunks,
manipulates them cleverly and generates groups of 4 decimal digits. It so
happens that it does NOT require long long division.
If long is > 32 bits, division of 64-bit values is relatively easy, and we
will use the first algorithm. If long long is > 64 bits (strange
architecture with VERY large long long), second algorithm can't be used,
and we again use the first one.
Else (if long is 32 bits and long long is 64 bits) we use second one.
And third: there is a simple optimization which takes fast path not only
for zero as was done before, but for all one-digit numbers.
In all tested cases new code is faster than old one, in many cases by 30%,
in few cases by more than 50% (for example, on x86-32, conversion of
12345678). Code growth is ~0 in 32-bit case and ~130 bytes in 64-bit
case.
This patch is based upon an original from Michal Nazarewicz.
[akpm@linux-foundation.org: checkpatch fixes]
Signed-off-by: Michal Nazarewicz <mina86@mina86.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Cc: Douglas W Jones <jones@cs.uiowa.edu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-06-01 07:26:08 +08:00
|
|
|
int digits = put_dec_trunc8(temp, addr[index]) - temp;
|
2009-08-17 20:29:44 +08:00
|
|
|
if (leading_zeros) {
|
|
|
|
if (digits < 3)
|
|
|
|
*p++ = '0';
|
|
|
|
if (digits < 2)
|
|
|
|
*p++ = '0';
|
|
|
|
}
|
|
|
|
/* reverse the digits in the quad */
|
|
|
|
while (digits--)
|
|
|
|
*p++ = temp[digits];
|
|
|
|
if (i < 3)
|
|
|
|
*p++ = '.';
|
2010-01-14 12:23:30 +08:00
|
|
|
index += step;
|
2009-08-17 20:29:44 +08:00
|
|
|
}
|
|
|
|
*p = '\0';
|
2009-12-15 10:00:57 +08:00
|
|
|
|
2009-08-17 20:29:44 +08:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2010-05-25 05:33:16 +08:00
|
|
|
static noinline_for_stack
|
|
|
|
char *ip6_compressed_string(char *p, const char *addr)
|
2008-10-29 07:04:44 +08:00
|
|
|
{
|
2009-12-15 10:00:57 +08:00
|
|
|
int i, j, range;
|
2009-08-17 20:29:44 +08:00
|
|
|
unsigned char zerolength[8];
|
|
|
|
int longest = 1;
|
|
|
|
int colonpos = -1;
|
|
|
|
u16 word;
|
2009-12-15 10:00:57 +08:00
|
|
|
u8 hi, lo;
|
2009-08-17 20:29:44 +08:00
|
|
|
bool needcolon = false;
|
2009-09-18 21:04:06 +08:00
|
|
|
bool useIPv4;
|
|
|
|
struct in6_addr in6;
|
|
|
|
|
|
|
|
memcpy(&in6, addr, sizeof(struct in6_addr));
|
|
|
|
|
|
|
|
useIPv4 = ipv6_addr_v4mapped(&in6) || ipv6_addr_is_isatap(&in6);
|
2009-08-17 20:29:44 +08:00
|
|
|
|
|
|
|
memset(zerolength, 0, sizeof(zerolength));
|
|
|
|
|
|
|
|
if (useIPv4)
|
|
|
|
range = 6;
|
|
|
|
else
|
|
|
|
range = 8;
|
|
|
|
|
|
|
|
/* find position of longest 0 run */
|
|
|
|
for (i = 0; i < range; i++) {
|
|
|
|
for (j = i; j < range; j++) {
|
2009-09-18 21:04:06 +08:00
|
|
|
if (in6.s6_addr16[j] != 0)
|
2009-08-17 20:29:44 +08:00
|
|
|
break;
|
|
|
|
zerolength[i]++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (i = 0; i < range; i++) {
|
|
|
|
if (zerolength[i] > longest) {
|
|
|
|
longest = zerolength[i];
|
|
|
|
colonpos = i;
|
|
|
|
}
|
|
|
|
}
|
2011-06-10 02:23:37 +08:00
|
|
|
if (longest == 1) /* don't compress a single 0 */
|
|
|
|
colonpos = -1;
|
2008-10-29 07:04:44 +08:00
|
|
|
|
2009-08-17 20:29:44 +08:00
|
|
|
/* emit address */
|
|
|
|
for (i = 0; i < range; i++) {
|
|
|
|
if (i == colonpos) {
|
|
|
|
if (needcolon || i == 0)
|
|
|
|
*p++ = ':';
|
|
|
|
*p++ = ':';
|
|
|
|
needcolon = false;
|
|
|
|
i += longest - 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (needcolon) {
|
|
|
|
*p++ = ':';
|
|
|
|
needcolon = false;
|
|
|
|
}
|
|
|
|
/* hex u16 without leading 0s */
|
2009-09-18 21:04:06 +08:00
|
|
|
word = ntohs(in6.s6_addr16[i]);
|
2009-08-17 20:29:44 +08:00
|
|
|
hi = word >> 8;
|
|
|
|
lo = word & 0xff;
|
|
|
|
if (hi) {
|
|
|
|
if (hi > 0x0f)
|
2011-11-01 08:12:41 +08:00
|
|
|
p = hex_byte_pack(p, hi);
|
2009-08-17 20:29:44 +08:00
|
|
|
else
|
|
|
|
*p++ = hex_asc_lo(hi);
|
2011-11-01 08:12:41 +08:00
|
|
|
p = hex_byte_pack(p, lo);
|
2009-08-17 20:29:44 +08:00
|
|
|
}
|
2009-12-15 10:00:59 +08:00
|
|
|
else if (lo > 0x0f)
|
2011-11-01 08:12:41 +08:00
|
|
|
p = hex_byte_pack(p, lo);
|
2009-08-17 20:29:44 +08:00
|
|
|
else
|
|
|
|
*p++ = hex_asc_lo(lo);
|
|
|
|
needcolon = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (useIPv4) {
|
|
|
|
if (needcolon)
|
|
|
|
*p++ = ':';
|
2010-01-14 12:23:30 +08:00
|
|
|
p = ip4_string(p, &in6.s6_addr[12], "I4");
|
2009-08-17 20:29:44 +08:00
|
|
|
}
|
|
|
|
*p = '\0';
|
2009-12-15 10:00:57 +08:00
|
|
|
|
2009-08-17 20:29:44 +08:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2010-05-25 05:33:16 +08:00
|
|
|
static noinline_for_stack
|
|
|
|
char *ip6_string(char *p, const char *addr, const char *fmt)
|
2009-08-17 20:29:44 +08:00
|
|
|
{
|
|
|
|
int i;
|
2009-12-15 10:00:57 +08:00
|
|
|
|
2008-10-29 07:04:44 +08:00
|
|
|
for (i = 0; i < 8; i++) {
|
2011-11-01 08:12:41 +08:00
|
|
|
p = hex_byte_pack(p, *addr++);
|
|
|
|
p = hex_byte_pack(p, *addr++);
|
2009-08-17 20:29:44 +08:00
|
|
|
if (fmt[0] == 'I' && i != 7)
|
2008-10-29 07:04:44 +08:00
|
|
|
*p++ = ':';
|
|
|
|
}
|
|
|
|
*p = '\0';
|
2009-12-15 10:00:57 +08:00
|
|
|
|
2009-08-17 20:29:44 +08:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2010-05-25 05:33:16 +08:00
|
|
|
static noinline_for_stack
|
|
|
|
char *ip6_addr_string(char *buf, char *end, const u8 *addr,
|
|
|
|
struct printf_spec spec, const char *fmt)
|
2009-08-17 20:29:44 +08:00
|
|
|
{
|
|
|
|
char ip6_addr[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255")];
|
|
|
|
|
|
|
|
if (fmt[0] == 'I' && fmt[2] == 'c')
|
2009-09-18 21:04:06 +08:00
|
|
|
ip6_compressed_string(ip6_addr, addr);
|
2009-08-17 20:29:44 +08:00
|
|
|
else
|
2009-09-18 21:04:06 +08:00
|
|
|
ip6_string(ip6_addr, addr, fmt);
|
2008-10-29 07:04:44 +08:00
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
return string(buf, end, ip6_addr, spec);
|
2008-10-29 07:04:44 +08:00
|
|
|
}
|
|
|
|
|
2010-05-25 05:33:16 +08:00
|
|
|
static noinline_for_stack
|
|
|
|
char *ip4_addr_string(char *buf, char *end, const u8 *addr,
|
|
|
|
struct printf_spec spec, const char *fmt)
|
2008-10-30 03:49:58 +08:00
|
|
|
{
|
2009-08-17 20:29:44 +08:00
|
|
|
char ip4_addr[sizeof("255.255.255.255")];
|
2008-10-30 03:49:58 +08:00
|
|
|
|
2010-01-14 12:23:30 +08:00
|
|
|
ip4_string(ip4_addr, addr, fmt);
|
2008-10-30 03:49:58 +08:00
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
return string(buf, end, ip4_addr, spec);
|
2008-10-30 03:49:58 +08:00
|
|
|
}
|
|
|
|
|
lib: vsprintf: add IPv4/v6 generic %p[Ii]S[pfs] format specifier
In order to avoid making code that deals with printing both, IPv4 and
IPv6 addresses, unnecessary complicated as for example ...
if (sa.sa_family == AF_INET6)
printk("... %pI6 ...", ..sin6_addr);
else
printk("... %pI4 ...", ..sin_addr.s_addr);
... it would be better to introduce a format specifier that can deal
with those kind of situations internally; just as we have a "struct
sockaddr" for generic mapping into "struct sockaddr_in" or "struct
sockaddr_in6" as e.g. done in "union sctp_addr". Then, we could
reduce the above statement into something like:
printk("... %pIS ..", &sockaddr);
In case our pointer is NULL, pointer() then deals with that already at
an earlier point in time internally. While we're at it, support for both
%piS/%pIS, where 'S' stands for sockaddr, comes (almost) for free.
Additionally to that, postfix specifiers 'p', 'f' and 's' are supported
as suggested and initially implemented in 2009 by Joe Perches [1].
Handling of those additional specifiers orientate on the initial RFC that
was proposed. Also we support IPv6 compressed format specified by 'c' and
various other IPv4 extensions as stated in the documentation part.
Likely, there are many other areas than just SCTP in the kernel to make
use of this extension as well.
[1] http://patchwork.ozlabs.org/patch/31480/
Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
CC: Joe Perches <joe@perches.com>
CC: linux-kernel@vger.kernel.org
Signed-off-by: David S. Miller <davem@davemloft.net>
2013-06-29 01:49:39 +08:00
|
|
|
static noinline_for_stack
|
|
|
|
char *ip6_addr_string_sa(char *buf, char *end, const struct sockaddr_in6 *sa,
|
|
|
|
struct printf_spec spec, const char *fmt)
|
|
|
|
{
|
|
|
|
bool have_p = false, have_s = false, have_f = false, have_c = false;
|
|
|
|
char ip6_addr[sizeof("[xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255]") +
|
|
|
|
sizeof(":12345") + sizeof("/123456789") +
|
|
|
|
sizeof("%1234567890")];
|
|
|
|
char *p = ip6_addr, *pend = ip6_addr + sizeof(ip6_addr);
|
|
|
|
const u8 *addr = (const u8 *) &sa->sin6_addr;
|
|
|
|
char fmt6[2] = { fmt[0], '6' };
|
|
|
|
u8 off = 0;
|
|
|
|
|
|
|
|
fmt++;
|
|
|
|
while (isalpha(*++fmt)) {
|
|
|
|
switch (*fmt) {
|
|
|
|
case 'p':
|
|
|
|
have_p = true;
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
have_f = true;
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
have_s = true;
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
have_c = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (have_p || have_s || have_f) {
|
|
|
|
*p = '[';
|
|
|
|
off = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fmt6[0] == 'I' && have_c)
|
|
|
|
p = ip6_compressed_string(ip6_addr + off, addr);
|
|
|
|
else
|
|
|
|
p = ip6_string(ip6_addr + off, addr, fmt6);
|
|
|
|
|
|
|
|
if (have_p || have_s || have_f)
|
|
|
|
*p++ = ']';
|
|
|
|
|
|
|
|
if (have_p) {
|
|
|
|
*p++ = ':';
|
|
|
|
p = number(p, pend, ntohs(sa->sin6_port), spec);
|
|
|
|
}
|
|
|
|
if (have_f) {
|
|
|
|
*p++ = '/';
|
|
|
|
p = number(p, pend, ntohl(sa->sin6_flowinfo &
|
|
|
|
IPV6_FLOWINFO_MASK), spec);
|
|
|
|
}
|
|
|
|
if (have_s) {
|
|
|
|
*p++ = '%';
|
|
|
|
p = number(p, pend, sa->sin6_scope_id, spec);
|
|
|
|
}
|
|
|
|
*p = '\0';
|
|
|
|
|
|
|
|
return string(buf, end, ip6_addr, spec);
|
|
|
|
}
|
|
|
|
|
|
|
|
static noinline_for_stack
|
|
|
|
char *ip4_addr_string_sa(char *buf, char *end, const struct sockaddr_in *sa,
|
|
|
|
struct printf_spec spec, const char *fmt)
|
|
|
|
{
|
|
|
|
bool have_p = false;
|
|
|
|
char *p, ip4_addr[sizeof("255.255.255.255") + sizeof(":12345")];
|
|
|
|
char *pend = ip4_addr + sizeof(ip4_addr);
|
|
|
|
const u8 *addr = (const u8 *) &sa->sin_addr.s_addr;
|
|
|
|
char fmt4[3] = { fmt[0], '4', 0 };
|
|
|
|
|
|
|
|
fmt++;
|
|
|
|
while (isalpha(*++fmt)) {
|
|
|
|
switch (*fmt) {
|
|
|
|
case 'p':
|
|
|
|
have_p = true;
|
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
case 'l':
|
|
|
|
case 'n':
|
|
|
|
case 'b':
|
|
|
|
fmt4[2] = *fmt;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
p = ip4_string(ip4_addr, addr, fmt4);
|
|
|
|
if (have_p) {
|
|
|
|
*p++ = ':';
|
|
|
|
p = number(p, pend, ntohs(sa->sin_port), spec);
|
|
|
|
}
|
|
|
|
*p = '\0';
|
|
|
|
|
|
|
|
return string(buf, end, ip4_addr, spec);
|
|
|
|
}
|
|
|
|
|
2010-05-25 05:33:16 +08:00
|
|
|
static noinline_for_stack
|
|
|
|
char *uuid_string(char *buf, char *end, const u8 *addr,
|
|
|
|
struct printf_spec spec, const char *fmt)
|
2009-12-15 10:01:09 +08:00
|
|
|
{
|
|
|
|
char uuid[sizeof("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")];
|
|
|
|
char *p = uuid;
|
|
|
|
int i;
|
|
|
|
static const u8 be[16] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
|
|
|
|
static const u8 le[16] = {3,2,1,0,5,4,7,6,8,9,10,11,12,13,14,15};
|
|
|
|
const u8 *index = be;
|
|
|
|
bool uc = false;
|
|
|
|
|
|
|
|
switch (*(++fmt)) {
|
|
|
|
case 'L':
|
|
|
|
uc = true; /* fall-through */
|
|
|
|
case 'l':
|
|
|
|
index = le;
|
|
|
|
break;
|
|
|
|
case 'B':
|
|
|
|
uc = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < 16; i++) {
|
2011-11-01 08:12:41 +08:00
|
|
|
p = hex_byte_pack(p, addr[index[i]]);
|
2009-12-15 10:01:09 +08:00
|
|
|
switch (i) {
|
|
|
|
case 3:
|
|
|
|
case 5:
|
|
|
|
case 7:
|
|
|
|
case 9:
|
|
|
|
*p++ = '-';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*p = 0;
|
|
|
|
|
|
|
|
if (uc) {
|
|
|
|
p = uuid;
|
|
|
|
do {
|
|
|
|
*p = toupper(*p);
|
|
|
|
} while (*(++p));
|
|
|
|
}
|
|
|
|
|
|
|
|
return string(buf, end, uuid, spec);
|
|
|
|
}
|
|
|
|
|
2011-11-15 23:29:55 +08:00
|
|
|
static
|
|
|
|
char *netdev_feature_string(char *buf, char *end, const u8 *addr,
|
|
|
|
struct printf_spec spec)
|
|
|
|
{
|
|
|
|
spec.flags |= SPECIAL | SMALL | ZEROPAD;
|
|
|
|
if (spec.field_width == -1)
|
|
|
|
spec.field_width = 2 + 2 * sizeof(netdev_features_t);
|
|
|
|
spec.base = 16;
|
|
|
|
|
|
|
|
return number(buf, end, *(const netdev_features_t *)addr, spec);
|
|
|
|
}
|
|
|
|
|
2011-05-13 05:00:28 +08:00
|
|
|
int kptr_restrict __read_mostly;
|
kptr_restrict for hiding kernel pointers from unprivileged users
Add the %pK printk format specifier and the /proc/sys/kernel/kptr_restrict
sysctl.
The %pK format specifier is designed to hide exposed kernel pointers,
specifically via /proc interfaces. Exposing these pointers provides an
easy target for kernel write vulnerabilities, since they reveal the
locations of writable structures containing easily triggerable function
pointers. The behavior of %pK depends on the kptr_restrict sysctl.
If kptr_restrict is set to 0, no deviation from the standard %p behavior
occurs. If kptr_restrict is set to 1, the default, if the current user
(intended to be a reader via seq_printf(), etc.) does not have CAP_SYSLOG
(currently in the LSM tree), kernel pointers using %pK are printed as 0's.
If kptr_restrict is set to 2, kernel pointers using %pK are printed as
0's regardless of privileges. Replacing with 0's was chosen over the
default "(null)", which cannot be parsed by userland %p, which expects
"(nil)".
[akpm@linux-foundation.org: check for IRQ context when !kptr_restrict, save an indent level, s/WARN/WARN_ONCE/]
[akpm@linux-foundation.org: coding-style fixup]
[randy.dunlap@oracle.com: fix kernel/sysctl.c warning]
Signed-off-by: Dan Rosenberg <drosenberg@vsecurity.com>
Signed-off-by: Randy Dunlap <randy.dunlap@oracle.com>
Cc: James Morris <jmorris@namei.org>
Cc: Eric Dumazet <eric.dumazet@gmail.com>
Cc: Thomas Graf <tgraf@infradead.org>
Cc: Eugene Teo <eugeneteo@kernel.org>
Cc: Kees Cook <kees.cook@canonical.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: David S. Miller <davem@davemloft.net>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Eric Paris <eparis@parisplace.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-01-13 08:59:41 +08:00
|
|
|
|
2008-07-07 07:24:57 +08:00
|
|
|
/*
|
|
|
|
* Show a '%p' thing. A kernel extension is that the '%p' is followed
|
|
|
|
* by an extra set of alphanumeric characters that are extended format
|
|
|
|
* specifiers.
|
|
|
|
*
|
2008-10-20 12:07:34 +08:00
|
|
|
* Right now we handle:
|
|
|
|
*
|
vsprintf: introduce %pf format specifier
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 <fweisbec@gmail.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Zhaolei <zhaolei@cn.fujitsu.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
Cc: Li Zefan <lizf@cn.fujitsu.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <20090415154817.GC5989@nowhere>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-15 23:48:18 +08:00
|
|
|
* - 'F' For symbolic function descriptor pointers with offset
|
|
|
|
* - 'f' For simple symbolic function names without offset
|
2009-09-17 21:27:29 +08:00
|
|
|
* - 'S' For symbolic direct pointers with offset
|
|
|
|
* - 's' For symbolic direct pointers without offset
|
2012-12-13 02:18:50 +08:00
|
|
|
* - '[FfSs]R' as above with __builtin_extract_return_addr() translation
|
2011-03-24 10:42:29 +08:00
|
|
|
* - 'B' For backtraced symbolic direct pointers with offset
|
2009-10-28 03:26:47 +08:00
|
|
|
* - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
|
|
|
|
* - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
|
2008-10-28 06:47:12 +08:00
|
|
|
* - 'M' For a 6-byte MAC address, it prints the address in the
|
|
|
|
* usual colon-separated hex notation
|
2009-08-17 20:29:44 +08:00
|
|
|
* - 'm' For a 6-byte MAC address, it prints the hex address without colons
|
2010-01-07 19:43:50 +08:00
|
|
|
* - 'MF' For a 6-byte MAC FDDI address, it prints the address
|
2010-01-11 16:44:14 +08:00
|
|
|
* with a dash-separated hex notation
|
2012-10-05 08:12:33 +08:00
|
|
|
* - '[mM]R' For a 6-byte MAC address, Reverse order (Bluetooth)
|
2009-08-17 20:29:44 +08:00
|
|
|
* - 'I' [46] for IPv4/IPv6 addresses printed in the usual way
|
|
|
|
* IPv4 uses dot-separated decimal without leading 0's (1.2.3.4)
|
|
|
|
* IPv6 uses colon separated network-order 16 bit hex with leading 0's
|
lib: vsprintf: add IPv4/v6 generic %p[Ii]S[pfs] format specifier
In order to avoid making code that deals with printing both, IPv4 and
IPv6 addresses, unnecessary complicated as for example ...
if (sa.sa_family == AF_INET6)
printk("... %pI6 ...", ..sin6_addr);
else
printk("... %pI4 ...", ..sin_addr.s_addr);
... it would be better to introduce a format specifier that can deal
with those kind of situations internally; just as we have a "struct
sockaddr" for generic mapping into "struct sockaddr_in" or "struct
sockaddr_in6" as e.g. done in "union sctp_addr". Then, we could
reduce the above statement into something like:
printk("... %pIS ..", &sockaddr);
In case our pointer is NULL, pointer() then deals with that already at
an earlier point in time internally. While we're at it, support for both
%piS/%pIS, where 'S' stands for sockaddr, comes (almost) for free.
Additionally to that, postfix specifiers 'p', 'f' and 's' are supported
as suggested and initially implemented in 2009 by Joe Perches [1].
Handling of those additional specifiers orientate on the initial RFC that
was proposed. Also we support IPv6 compressed format specified by 'c' and
various other IPv4 extensions as stated in the documentation part.
Likely, there are many other areas than just SCTP in the kernel to make
use of this extension as well.
[1] http://patchwork.ozlabs.org/patch/31480/
Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
CC: Joe Perches <joe@perches.com>
CC: linux-kernel@vger.kernel.org
Signed-off-by: David S. Miller <davem@davemloft.net>
2013-06-29 01:49:39 +08:00
|
|
|
* [S][pfs]
|
|
|
|
* Generic IPv4/IPv6 address (struct sockaddr *) that falls back to
|
|
|
|
* [4] or [6] and is able to print port [p], flowinfo [f], scope [s]
|
2009-08-17 20:29:44 +08:00
|
|
|
* - 'i' [46] for 'raw' IPv4/IPv6 addresses
|
|
|
|
* IPv6 omits the colons (01020304...0f)
|
|
|
|
* IPv4 uses dot-separated decimal with leading 0's (010.123.045.006)
|
lib: vsprintf: add IPv4/v6 generic %p[Ii]S[pfs] format specifier
In order to avoid making code that deals with printing both, IPv4 and
IPv6 addresses, unnecessary complicated as for example ...
if (sa.sa_family == AF_INET6)
printk("... %pI6 ...", ..sin6_addr);
else
printk("... %pI4 ...", ..sin_addr.s_addr);
... it would be better to introduce a format specifier that can deal
with those kind of situations internally; just as we have a "struct
sockaddr" for generic mapping into "struct sockaddr_in" or "struct
sockaddr_in6" as e.g. done in "union sctp_addr". Then, we could
reduce the above statement into something like:
printk("... %pIS ..", &sockaddr);
In case our pointer is NULL, pointer() then deals with that already at
an earlier point in time internally. While we're at it, support for both
%piS/%pIS, where 'S' stands for sockaddr, comes (almost) for free.
Additionally to that, postfix specifiers 'p', 'f' and 's' are supported
as suggested and initially implemented in 2009 by Joe Perches [1].
Handling of those additional specifiers orientate on the initial RFC that
was proposed. Also we support IPv6 compressed format specified by 'c' and
various other IPv4 extensions as stated in the documentation part.
Likely, there are many other areas than just SCTP in the kernel to make
use of this extension as well.
[1] http://patchwork.ozlabs.org/patch/31480/
Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
CC: Joe Perches <joe@perches.com>
CC: linux-kernel@vger.kernel.org
Signed-off-by: David S. Miller <davem@davemloft.net>
2013-06-29 01:49:39 +08:00
|
|
|
* [S][pfs]
|
|
|
|
* Generic IPv4/IPv6 address (struct sockaddr *) that falls back to
|
|
|
|
* [4] or [6] and is able to print port [p], flowinfo [f], scope [s]
|
|
|
|
* - '[Ii][4S][hnbl]' IPv4 addresses in host, network, big or little endian order
|
|
|
|
* - 'I[6S]c' for IPv6 addresses printed as specified by
|
2011-06-10 02:23:37 +08:00
|
|
|
* http://tools.ietf.org/html/rfc5952
|
2009-12-15 10:01:09 +08:00
|
|
|
* - 'U' For a 16 byte UUID/GUID, it prints the UUID/GUID in the form
|
|
|
|
* "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
|
|
* Options for %pU are:
|
|
|
|
* b big endian lower case hex (default)
|
|
|
|
* B big endian UPPER case hex
|
|
|
|
* l little endian lower case hex
|
|
|
|
* L little endian UPPER case hex
|
|
|
|
* big endian output byte order is:
|
|
|
|
* [0][1][2][3]-[4][5]-[6][7]-[8][9]-[10][11][12][13][14][15]
|
|
|
|
* little endian output byte order is:
|
|
|
|
* [3][2][1][0]-[5][4]-[7][6]-[8][9]-[10][11][12][13][14][15]
|
2010-06-27 09:02:33 +08:00
|
|
|
* - 'V' For a struct va_format which contains a format string * and va_list *,
|
|
|
|
* call vsnprintf(->format, *->va_list).
|
|
|
|
* Implements a "recursive vsnprintf".
|
|
|
|
* Do not use this feature without some mechanism to verify the
|
|
|
|
* correctness of the format string and va_list arguments.
|
kptr_restrict for hiding kernel pointers from unprivileged users
Add the %pK printk format specifier and the /proc/sys/kernel/kptr_restrict
sysctl.
The %pK format specifier is designed to hide exposed kernel pointers,
specifically via /proc interfaces. Exposing these pointers provides an
easy target for kernel write vulnerabilities, since they reveal the
locations of writable structures containing easily triggerable function
pointers. The behavior of %pK depends on the kptr_restrict sysctl.
If kptr_restrict is set to 0, no deviation from the standard %p behavior
occurs. If kptr_restrict is set to 1, the default, if the current user
(intended to be a reader via seq_printf(), etc.) does not have CAP_SYSLOG
(currently in the LSM tree), kernel pointers using %pK are printed as 0's.
If kptr_restrict is set to 2, kernel pointers using %pK are printed as
0's regardless of privileges. Replacing with 0's was chosen over the
default "(null)", which cannot be parsed by userland %p, which expects
"(nil)".
[akpm@linux-foundation.org: check for IRQ context when !kptr_restrict, save an indent level, s/WARN/WARN_ONCE/]
[akpm@linux-foundation.org: coding-style fixup]
[randy.dunlap@oracle.com: fix kernel/sysctl.c warning]
Signed-off-by: Dan Rosenberg <drosenberg@vsecurity.com>
Signed-off-by: Randy Dunlap <randy.dunlap@oracle.com>
Cc: James Morris <jmorris@namei.org>
Cc: Eric Dumazet <eric.dumazet@gmail.com>
Cc: Thomas Graf <tgraf@infradead.org>
Cc: Eugene Teo <eugeneteo@kernel.org>
Cc: Kees Cook <kees.cook@canonical.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: David S. Miller <davem@davemloft.net>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Eric Paris <eparis@parisplace.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-01-13 08:59:41 +08:00
|
|
|
* - 'K' For a kernel pointer that should be hidden from unprivileged users
|
2011-11-15 23:29:55 +08:00
|
|
|
* - 'NF' For a netdev_features_t
|
2012-07-31 05:40:27 +08:00
|
|
|
* - 'h[CDN]' For a variable-length buffer, it prints it as a hex string with
|
|
|
|
* a certain separator (' ' by default):
|
|
|
|
* C colon
|
|
|
|
* D dash
|
|
|
|
* N no separator
|
|
|
|
* The maximum supported length is 64 bytes of the input. Consider
|
|
|
|
* to use print_hex_dump() for the larger input.
|
2013-02-22 08:43:09 +08:00
|
|
|
* - 'a' For a phys_addr_t type and its derivative types (passed by reference)
|
2009-12-15 10:01:09 +08:00
|
|
|
*
|
2008-10-20 12:07:34 +08:00
|
|
|
* Note: The difference between 'S' and 'F' is that on ia64 and ppc64
|
|
|
|
* function pointers are really function descriptors, which contain a
|
|
|
|
* pointer to the real address.
|
2008-07-07 07:24:57 +08:00
|
|
|
*/
|
2010-05-25 05:33:16 +08:00
|
|
|
static noinline_for_stack
|
|
|
|
char *pointer(const char *fmt, char *buf, char *end, void *ptr,
|
|
|
|
struct printf_spec spec)
|
2008-07-07 07:16:15 +08:00
|
|
|
{
|
2012-06-01 07:26:08 +08:00
|
|
|
int default_width = 2 * sizeof(void *) + (spec.flags & SPECIAL ? 2 : 0);
|
|
|
|
|
2011-03-23 07:34:22 +08:00
|
|
|
if (!ptr && *fmt != 'K') {
|
2010-10-27 05:22:50 +08:00
|
|
|
/*
|
|
|
|
* Print (null) with the same width as a pointer so it makes
|
|
|
|
* tabular output look nice.
|
|
|
|
*/
|
|
|
|
if (spec.field_width == -1)
|
2012-06-01 07:26:08 +08:00
|
|
|
spec.field_width = default_width;
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
return string(buf, end, "(null)", spec);
|
2010-10-27 05:22:50 +08:00
|
|
|
}
|
2009-01-04 03:46:17 +08:00
|
|
|
|
2008-07-07 07:43:12 +08:00
|
|
|
switch (*fmt) {
|
|
|
|
case 'F':
|
vsprintf: introduce %pf format specifier
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 <fweisbec@gmail.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Zhaolei <zhaolei@cn.fujitsu.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
Cc: Li Zefan <lizf@cn.fujitsu.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <20090415154817.GC5989@nowhere>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-15 23:48:18 +08:00
|
|
|
case 'f':
|
2008-07-07 07:43:12 +08:00
|
|
|
ptr = dereference_function_descriptor(ptr);
|
|
|
|
/* Fallthrough */
|
|
|
|
case 'S':
|
2009-12-15 10:01:09 +08:00
|
|
|
case 's':
|
2011-03-24 10:42:29 +08:00
|
|
|
case 'B':
|
2012-12-13 02:18:50 +08:00
|
|
|
return symbol_string(buf, end, ptr, spec, fmt);
|
2008-10-20 12:07:34 +08:00
|
|
|
case 'R':
|
2009-10-28 03:26:47 +08:00
|
|
|
case 'r':
|
2009-10-07 05:33:39 +08:00
|
|
|
return resource_string(buf, end, ptr, spec, fmt);
|
2012-07-31 05:40:27 +08:00
|
|
|
case 'h':
|
|
|
|
return hex_string(buf, end, ptr, spec, fmt);
|
2009-08-17 20:29:44 +08:00
|
|
|
case 'M': /* Colon separated: 00:01:02:03:04:05 */
|
|
|
|
case 'm': /* Contiguous: 000102030405 */
|
2012-07-31 05:40:23 +08:00
|
|
|
/* [mM]F (FDDI) */
|
|
|
|
/* [mM]R (Reverse order; Bluetooth) */
|
2009-08-17 20:29:44 +08:00
|
|
|
return mac_address_string(buf, end, ptr, spec, fmt);
|
|
|
|
case 'I': /* Formatted IP supported
|
|
|
|
* 4: 1.2.3.4
|
|
|
|
* 6: 0001:0203:...:0708
|
|
|
|
* 6c: 1::708 or 1::1.2.3.4
|
|
|
|
*/
|
|
|
|
case 'i': /* Contiguous:
|
|
|
|
* 4: 001.002.003.004
|
|
|
|
* 6: 000102...0f
|
|
|
|
*/
|
|
|
|
switch (fmt[1]) {
|
|
|
|
case '6':
|
|
|
|
return ip6_addr_string(buf, end, ptr, spec, fmt);
|
|
|
|
case '4':
|
|
|
|
return ip4_addr_string(buf, end, ptr, spec, fmt);
|
lib: vsprintf: add IPv4/v6 generic %p[Ii]S[pfs] format specifier
In order to avoid making code that deals with printing both, IPv4 and
IPv6 addresses, unnecessary complicated as for example ...
if (sa.sa_family == AF_INET6)
printk("... %pI6 ...", ..sin6_addr);
else
printk("... %pI4 ...", ..sin_addr.s_addr);
... it would be better to introduce a format specifier that can deal
with those kind of situations internally; just as we have a "struct
sockaddr" for generic mapping into "struct sockaddr_in" or "struct
sockaddr_in6" as e.g. done in "union sctp_addr". Then, we could
reduce the above statement into something like:
printk("... %pIS ..", &sockaddr);
In case our pointer is NULL, pointer() then deals with that already at
an earlier point in time internally. While we're at it, support for both
%piS/%pIS, where 'S' stands for sockaddr, comes (almost) for free.
Additionally to that, postfix specifiers 'p', 'f' and 's' are supported
as suggested and initially implemented in 2009 by Joe Perches [1].
Handling of those additional specifiers orientate on the initial RFC that
was proposed. Also we support IPv6 compressed format specified by 'c' and
various other IPv4 extensions as stated in the documentation part.
Likely, there are many other areas than just SCTP in the kernel to make
use of this extension as well.
[1] http://patchwork.ozlabs.org/patch/31480/
Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
CC: Joe Perches <joe@perches.com>
CC: linux-kernel@vger.kernel.org
Signed-off-by: David S. Miller <davem@davemloft.net>
2013-06-29 01:49:39 +08:00
|
|
|
case 'S': {
|
|
|
|
const union {
|
|
|
|
struct sockaddr raw;
|
|
|
|
struct sockaddr_in v4;
|
|
|
|
struct sockaddr_in6 v6;
|
|
|
|
} *sa = ptr;
|
|
|
|
|
|
|
|
switch (sa->raw.sa_family) {
|
|
|
|
case AF_INET:
|
|
|
|
return ip4_addr_string_sa(buf, end, &sa->v4, spec, fmt);
|
|
|
|
case AF_INET6:
|
|
|
|
return ip6_addr_string_sa(buf, end, &sa->v6, spec, fmt);
|
|
|
|
default:
|
|
|
|
return string(buf, end, "(invalid address)", spec);
|
|
|
|
}}
|
2009-08-17 20:29:44 +08:00
|
|
|
}
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
break;
|
2009-12-15 10:01:09 +08:00
|
|
|
case 'U':
|
|
|
|
return uuid_string(buf, end, ptr, spec, fmt);
|
2010-06-27 09:02:33 +08:00
|
|
|
case 'V':
|
2012-03-06 00:49:24 +08:00
|
|
|
{
|
|
|
|
va_list va;
|
|
|
|
|
|
|
|
va_copy(va, *((struct va_format *)ptr)->va);
|
|
|
|
buf += vsnprintf(buf, end > buf ? end - buf : 0,
|
|
|
|
((struct va_format *)ptr)->fmt, va);
|
|
|
|
va_end(va);
|
|
|
|
return buf;
|
|
|
|
}
|
kptr_restrict for hiding kernel pointers from unprivileged users
Add the %pK printk format specifier and the /proc/sys/kernel/kptr_restrict
sysctl.
The %pK format specifier is designed to hide exposed kernel pointers,
specifically via /proc interfaces. Exposing these pointers provides an
easy target for kernel write vulnerabilities, since they reveal the
locations of writable structures containing easily triggerable function
pointers. The behavior of %pK depends on the kptr_restrict sysctl.
If kptr_restrict is set to 0, no deviation from the standard %p behavior
occurs. If kptr_restrict is set to 1, the default, if the current user
(intended to be a reader via seq_printf(), etc.) does not have CAP_SYSLOG
(currently in the LSM tree), kernel pointers using %pK are printed as 0's.
If kptr_restrict is set to 2, kernel pointers using %pK are printed as
0's regardless of privileges. Replacing with 0's was chosen over the
default "(null)", which cannot be parsed by userland %p, which expects
"(nil)".
[akpm@linux-foundation.org: check for IRQ context when !kptr_restrict, save an indent level, s/WARN/WARN_ONCE/]
[akpm@linux-foundation.org: coding-style fixup]
[randy.dunlap@oracle.com: fix kernel/sysctl.c warning]
Signed-off-by: Dan Rosenberg <drosenberg@vsecurity.com>
Signed-off-by: Randy Dunlap <randy.dunlap@oracle.com>
Cc: James Morris <jmorris@namei.org>
Cc: Eric Dumazet <eric.dumazet@gmail.com>
Cc: Thomas Graf <tgraf@infradead.org>
Cc: Eugene Teo <eugeneteo@kernel.org>
Cc: Kees Cook <kees.cook@canonical.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: David S. Miller <davem@davemloft.net>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Eric Paris <eparis@parisplace.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-01-13 08:59:41 +08:00
|
|
|
case 'K':
|
|
|
|
/*
|
|
|
|
* %pK cannot be used in IRQ context because its test
|
|
|
|
* for CAP_SYSLOG would be meaningless.
|
|
|
|
*/
|
2012-07-31 05:40:26 +08:00
|
|
|
if (kptr_restrict && (in_irq() || in_serving_softirq() ||
|
|
|
|
in_nmi())) {
|
kptr_restrict for hiding kernel pointers from unprivileged users
Add the %pK printk format specifier and the /proc/sys/kernel/kptr_restrict
sysctl.
The %pK format specifier is designed to hide exposed kernel pointers,
specifically via /proc interfaces. Exposing these pointers provides an
easy target for kernel write vulnerabilities, since they reveal the
locations of writable structures containing easily triggerable function
pointers. The behavior of %pK depends on the kptr_restrict sysctl.
If kptr_restrict is set to 0, no deviation from the standard %p behavior
occurs. If kptr_restrict is set to 1, the default, if the current user
(intended to be a reader via seq_printf(), etc.) does not have CAP_SYSLOG
(currently in the LSM tree), kernel pointers using %pK are printed as 0's.
If kptr_restrict is set to 2, kernel pointers using %pK are printed as
0's regardless of privileges. Replacing with 0's was chosen over the
default "(null)", which cannot be parsed by userland %p, which expects
"(nil)".
[akpm@linux-foundation.org: check for IRQ context when !kptr_restrict, save an indent level, s/WARN/WARN_ONCE/]
[akpm@linux-foundation.org: coding-style fixup]
[randy.dunlap@oracle.com: fix kernel/sysctl.c warning]
Signed-off-by: Dan Rosenberg <drosenberg@vsecurity.com>
Signed-off-by: Randy Dunlap <randy.dunlap@oracle.com>
Cc: James Morris <jmorris@namei.org>
Cc: Eric Dumazet <eric.dumazet@gmail.com>
Cc: Thomas Graf <tgraf@infradead.org>
Cc: Eugene Teo <eugeneteo@kernel.org>
Cc: Kees Cook <kees.cook@canonical.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: David S. Miller <davem@davemloft.net>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Eric Paris <eparis@parisplace.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-01-13 08:59:41 +08:00
|
|
|
if (spec.field_width == -1)
|
2012-06-01 07:26:08 +08:00
|
|
|
spec.field_width = default_width;
|
kptr_restrict for hiding kernel pointers from unprivileged users
Add the %pK printk format specifier and the /proc/sys/kernel/kptr_restrict
sysctl.
The %pK format specifier is designed to hide exposed kernel pointers,
specifically via /proc interfaces. Exposing these pointers provides an
easy target for kernel write vulnerabilities, since they reveal the
locations of writable structures containing easily triggerable function
pointers. The behavior of %pK depends on the kptr_restrict sysctl.
If kptr_restrict is set to 0, no deviation from the standard %p behavior
occurs. If kptr_restrict is set to 1, the default, if the current user
(intended to be a reader via seq_printf(), etc.) does not have CAP_SYSLOG
(currently in the LSM tree), kernel pointers using %pK are printed as 0's.
If kptr_restrict is set to 2, kernel pointers using %pK are printed as
0's regardless of privileges. Replacing with 0's was chosen over the
default "(null)", which cannot be parsed by userland %p, which expects
"(nil)".
[akpm@linux-foundation.org: check for IRQ context when !kptr_restrict, save an indent level, s/WARN/WARN_ONCE/]
[akpm@linux-foundation.org: coding-style fixup]
[randy.dunlap@oracle.com: fix kernel/sysctl.c warning]
Signed-off-by: Dan Rosenberg <drosenberg@vsecurity.com>
Signed-off-by: Randy Dunlap <randy.dunlap@oracle.com>
Cc: James Morris <jmorris@namei.org>
Cc: Eric Dumazet <eric.dumazet@gmail.com>
Cc: Thomas Graf <tgraf@infradead.org>
Cc: Eugene Teo <eugeneteo@kernel.org>
Cc: Kees Cook <kees.cook@canonical.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: David S. Miller <davem@davemloft.net>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Eric Paris <eparis@parisplace.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-01-13 08:59:41 +08:00
|
|
|
return string(buf, end, "pK-error", spec);
|
|
|
|
}
|
2013-11-13 07:08:51 +08:00
|
|
|
|
|
|
|
switch (kptr_restrict) {
|
|
|
|
case 0:
|
|
|
|
/* Always print %pK values */
|
|
|
|
break;
|
|
|
|
case 1: {
|
|
|
|
/*
|
|
|
|
* Only print the real pointer value if the current
|
|
|
|
* process has CAP_SYSLOG and is running with the
|
|
|
|
* same credentials it started with. This is because
|
|
|
|
* access to files is checked at open() time, but %pK
|
|
|
|
* checks permission at read() time. We don't want to
|
|
|
|
* leak pointer values if a binary opens a file using
|
|
|
|
* %pK and then elevates privileges before reading it.
|
|
|
|
*/
|
|
|
|
const struct cred *cred = current_cred();
|
|
|
|
|
|
|
|
if (!has_capability_noaudit(current, CAP_SYSLOG) ||
|
|
|
|
!uid_eq(cred->euid, cred->uid) ||
|
|
|
|
!gid_eq(cred->egid, cred->gid))
|
|
|
|
ptr = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 2:
|
|
|
|
default:
|
|
|
|
/* Always print 0's for %pK */
|
2011-03-23 07:34:19 +08:00
|
|
|
ptr = NULL;
|
2013-11-13 07:08:51 +08:00
|
|
|
break;
|
|
|
|
}
|
2011-03-23 07:34:19 +08:00
|
|
|
break;
|
2013-11-13 07:08:51 +08:00
|
|
|
|
2011-11-15 23:29:55 +08:00
|
|
|
case 'N':
|
|
|
|
switch (fmt[1]) {
|
|
|
|
case 'F':
|
|
|
|
return netdev_feature_string(buf, end, ptr, spec);
|
|
|
|
}
|
|
|
|
break;
|
2013-02-22 08:43:09 +08:00
|
|
|
case 'a':
|
|
|
|
spec.flags |= SPECIAL | SMALL | ZEROPAD;
|
|
|
|
spec.field_width = sizeof(phys_addr_t) * 2 + 2;
|
|
|
|
spec.base = 16;
|
|
|
|
return number(buf, end,
|
|
|
|
(unsigned long long) *((phys_addr_t *)ptr), spec);
|
2013-09-04 00:00:44 +08:00
|
|
|
case 'd':
|
|
|
|
return dentry_name(buf, end, ptr, spec, fmt);
|
|
|
|
case 'D':
|
|
|
|
return dentry_name(buf, end,
|
|
|
|
((const struct file *)ptr)->f_path.dentry,
|
|
|
|
spec, fmt);
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
}
|
|
|
|
spec.flags |= SMALL;
|
|
|
|
if (spec.field_width == -1) {
|
2012-06-01 07:26:08 +08:00
|
|
|
spec.field_width = default_width;
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
spec.flags |= ZEROPAD;
|
|
|
|
}
|
|
|
|
spec.base = 16;
|
|
|
|
|
|
|
|
return number(buf, end, (unsigned long) ptr, spec);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Helper function to decode printf style format.
|
|
|
|
* Each call decode a token from the format and return the
|
|
|
|
* number of characters read (or likely the delta where it wants
|
|
|
|
* to go on the next call).
|
|
|
|
* The decoded token is returned through the parameters
|
|
|
|
*
|
|
|
|
* 'h', 'l', or 'L' for integer fields
|
|
|
|
* 'z' support added 23/7/1999 S.H.
|
|
|
|
* 'z' changed to 'Z' --davidm 1/25/99
|
|
|
|
* 't' added for ptrdiff_t
|
|
|
|
*
|
|
|
|
* @fmt: the format string
|
|
|
|
* @type of the token returned
|
|
|
|
* @flags: various flags such as +, -, # tokens..
|
|
|
|
* @field_width: overwritten width
|
|
|
|
* @base: base of the number (octal, hex, ...)
|
|
|
|
* @precision: precision of a number
|
|
|
|
* @qualifier: qualifier of a number (long, size_t, ...)
|
|
|
|
*/
|
2010-05-25 05:33:16 +08:00
|
|
|
static noinline_for_stack
|
|
|
|
int format_decode(const char *fmt, struct printf_spec *spec)
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
{
|
|
|
|
const char *start = fmt;
|
|
|
|
|
|
|
|
/* we finished early by reading the field width */
|
2009-03-14 19:08:50 +08:00
|
|
|
if (spec->type == FORMAT_TYPE_WIDTH) {
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
if (spec->field_width < 0) {
|
|
|
|
spec->field_width = -spec->field_width;
|
|
|
|
spec->flags |= LEFT;
|
|
|
|
}
|
|
|
|
spec->type = FORMAT_TYPE_NONE;
|
|
|
|
goto precision;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we finished early by reading the precision */
|
|
|
|
if (spec->type == FORMAT_TYPE_PRECISION) {
|
|
|
|
if (spec->precision < 0)
|
|
|
|
spec->precision = 0;
|
|
|
|
|
|
|
|
spec->type = FORMAT_TYPE_NONE;
|
|
|
|
goto qualifier;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* By default */
|
|
|
|
spec->type = FORMAT_TYPE_NONE;
|
|
|
|
|
|
|
|
for (; *fmt ; ++fmt) {
|
|
|
|
if (*fmt == '%')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the current non-format string */
|
|
|
|
if (fmt != start || !*fmt)
|
|
|
|
return fmt - start;
|
|
|
|
|
|
|
|
/* Process flags */
|
|
|
|
spec->flags = 0;
|
|
|
|
|
|
|
|
while (1) { /* this also skips first '%' */
|
|
|
|
bool found = true;
|
|
|
|
|
|
|
|
++fmt;
|
|
|
|
|
|
|
|
switch (*fmt) {
|
|
|
|
case '-': spec->flags |= LEFT; break;
|
|
|
|
case '+': spec->flags |= PLUS; break;
|
|
|
|
case ' ': spec->flags |= SPACE; break;
|
|
|
|
case '#': spec->flags |= SPECIAL; break;
|
|
|
|
case '0': spec->flags |= ZEROPAD; break;
|
|
|
|
default: found = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get field width */
|
|
|
|
spec->field_width = -1;
|
|
|
|
|
|
|
|
if (isdigit(*fmt))
|
|
|
|
spec->field_width = skip_atoi(&fmt);
|
|
|
|
else if (*fmt == '*') {
|
|
|
|
/* it's the next argument */
|
2009-03-14 19:08:50 +08:00
|
|
|
spec->type = FORMAT_TYPE_WIDTH;
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
return ++fmt - start;
|
|
|
|
}
|
|
|
|
|
|
|
|
precision:
|
|
|
|
/* get the precision */
|
|
|
|
spec->precision = -1;
|
|
|
|
if (*fmt == '.') {
|
|
|
|
++fmt;
|
|
|
|
if (isdigit(*fmt)) {
|
|
|
|
spec->precision = skip_atoi(&fmt);
|
|
|
|
if (spec->precision < 0)
|
|
|
|
spec->precision = 0;
|
|
|
|
} else if (*fmt == '*') {
|
|
|
|
/* it's the next argument */
|
2009-03-14 19:08:50 +08:00
|
|
|
spec->type = FORMAT_TYPE_PRECISION;
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
return ++fmt - start;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
qualifier:
|
|
|
|
/* get the conversion qualifier */
|
|
|
|
spec->qualifier = -1;
|
2011-07-26 08:13:20 +08:00
|
|
|
if (*fmt == 'h' || _tolower(*fmt) == 'l' ||
|
|
|
|
_tolower(*fmt) == 'z' || *fmt == 't') {
|
2009-03-27 17:07:05 +08:00
|
|
|
spec->qualifier = *fmt++;
|
|
|
|
if (unlikely(spec->qualifier == *fmt)) {
|
|
|
|
if (spec->qualifier == 'l') {
|
|
|
|
spec->qualifier = 'L';
|
|
|
|
++fmt;
|
|
|
|
} else if (spec->qualifier == 'h') {
|
|
|
|
spec->qualifier = 'H';
|
|
|
|
++fmt;
|
|
|
|
}
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* default base */
|
|
|
|
spec->base = 10;
|
|
|
|
switch (*fmt) {
|
|
|
|
case 'c':
|
|
|
|
spec->type = FORMAT_TYPE_CHAR;
|
|
|
|
return ++fmt - start;
|
|
|
|
|
|
|
|
case 's':
|
|
|
|
spec->type = FORMAT_TYPE_STR;
|
|
|
|
return ++fmt - start;
|
|
|
|
|
|
|
|
case 'p':
|
|
|
|
spec->type = FORMAT_TYPE_PTR;
|
|
|
|
return fmt - start;
|
|
|
|
/* skip alnum */
|
|
|
|
|
|
|
|
case 'n':
|
|
|
|
spec->type = FORMAT_TYPE_NRCHARS;
|
|
|
|
return ++fmt - start;
|
|
|
|
|
|
|
|
case '%':
|
|
|
|
spec->type = FORMAT_TYPE_PERCENT_CHAR;
|
|
|
|
return ++fmt - start;
|
|
|
|
|
|
|
|
/* integer number formats - set up the flags and "break" */
|
|
|
|
case 'o':
|
|
|
|
spec->base = 8;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'x':
|
|
|
|
spec->flags |= SMALL;
|
|
|
|
|
|
|
|
case 'X':
|
|
|
|
spec->base = 16;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'd':
|
|
|
|
case 'i':
|
2009-03-10 04:15:04 +08:00
|
|
|
spec->flags |= SIGN;
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
case 'u':
|
2008-10-30 03:49:58 +08:00
|
|
|
break;
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
|
|
|
|
default:
|
|
|
|
spec->type = FORMAT_TYPE_INVALID;
|
|
|
|
return fmt - start;
|
2008-07-07 07:43:12 +08:00
|
|
|
}
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
|
|
|
|
if (spec->qualifier == 'L')
|
|
|
|
spec->type = FORMAT_TYPE_LONG_LONG;
|
|
|
|
else if (spec->qualifier == 'l') {
|
2009-03-10 04:15:04 +08:00
|
|
|
if (spec->flags & SIGN)
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
spec->type = FORMAT_TYPE_LONG;
|
|
|
|
else
|
|
|
|
spec->type = FORMAT_TYPE_ULONG;
|
2011-07-26 08:13:20 +08:00
|
|
|
} else if (_tolower(spec->qualifier) == 'z') {
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
spec->type = FORMAT_TYPE_SIZE_T;
|
|
|
|
} else if (spec->qualifier == 't') {
|
|
|
|
spec->type = FORMAT_TYPE_PTRDIFF;
|
2009-03-27 17:07:05 +08:00
|
|
|
} else if (spec->qualifier == 'H') {
|
|
|
|
if (spec->flags & SIGN)
|
|
|
|
spec->type = FORMAT_TYPE_BYTE;
|
|
|
|
else
|
|
|
|
spec->type = FORMAT_TYPE_UBYTE;
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
} else if (spec->qualifier == 'h') {
|
2009-03-10 04:15:04 +08:00
|
|
|
if (spec->flags & SIGN)
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
spec->type = FORMAT_TYPE_SHORT;
|
|
|
|
else
|
|
|
|
spec->type = FORMAT_TYPE_USHORT;
|
|
|
|
} else {
|
2009-03-10 04:15:04 +08:00
|
|
|
if (spec->flags & SIGN)
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
spec->type = FORMAT_TYPE_INT;
|
|
|
|
else
|
|
|
|
spec->type = FORMAT_TYPE_UINT;
|
2008-07-07 07:16:15 +08:00
|
|
|
}
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
|
|
|
|
return ++fmt - start;
|
2008-07-07 07:16:15 +08:00
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/**
|
|
|
|
* vsnprintf - Format a string and place it in a buffer
|
|
|
|
* @buf: The buffer to place the result into
|
|
|
|
* @size: The size of the buffer, including the trailing null space
|
|
|
|
* @fmt: The format string to use
|
|
|
|
* @args: Arguments for the format string
|
|
|
|
*
|
2008-10-16 13:02:02 +08:00
|
|
|
* This function follows C99 vsnprintf, but has some extensions:
|
2009-09-17 08:03:06 +08:00
|
|
|
* %pS output the name of a text symbol with offset
|
|
|
|
* %ps output the name of a text symbol without offset
|
vsprintf: introduce %pf format specifier
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 <fweisbec@gmail.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Zhaolei <zhaolei@cn.fujitsu.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
Cc: Li Zefan <lizf@cn.fujitsu.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <20090415154817.GC5989@nowhere>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-15 23:48:18 +08:00
|
|
|
* %pF output the name of a function pointer with its offset
|
|
|
|
* %pf output the name of a function pointer without its offset
|
2011-03-24 10:42:29 +08:00
|
|
|
* %pB output the name of a backtrace symbol with its offset
|
2009-12-18 07:27:12 +08:00
|
|
|
* %pR output the address range in a struct resource with decoded flags
|
|
|
|
* %pr output the address range in a struct resource with raw flags
|
|
|
|
* %pM output a 6-byte MAC address with colons
|
2012-10-05 08:12:33 +08:00
|
|
|
* %pMR output a 6-byte MAC address with colons in reversed order
|
|
|
|
* %pMF output a 6-byte MAC address with dashes
|
2009-12-18 07:27:12 +08:00
|
|
|
* %pm output a 6-byte MAC address without colons
|
2012-10-05 08:12:33 +08:00
|
|
|
* %pmR output a 6-byte MAC address without colons in reversed order
|
2009-12-18 07:27:12 +08:00
|
|
|
* %pI4 print an IPv4 address without leading zeros
|
|
|
|
* %pi4 print an IPv4 address with leading zeros
|
|
|
|
* %pI6 print an IPv6 address with colons
|
|
|
|
* %pi6 print an IPv6 address without colons
|
2011-07-15 00:48:56 +08:00
|
|
|
* %pI6c print an IPv6 address as specified by RFC 5952
|
lib: vsprintf: add IPv4/v6 generic %p[Ii]S[pfs] format specifier
In order to avoid making code that deals with printing both, IPv4 and
IPv6 addresses, unnecessary complicated as for example ...
if (sa.sa_family == AF_INET6)
printk("... %pI6 ...", ..sin6_addr);
else
printk("... %pI4 ...", ..sin_addr.s_addr);
... it would be better to introduce a format specifier that can deal
with those kind of situations internally; just as we have a "struct
sockaddr" for generic mapping into "struct sockaddr_in" or "struct
sockaddr_in6" as e.g. done in "union sctp_addr". Then, we could
reduce the above statement into something like:
printk("... %pIS ..", &sockaddr);
In case our pointer is NULL, pointer() then deals with that already at
an earlier point in time internally. While we're at it, support for both
%piS/%pIS, where 'S' stands for sockaddr, comes (almost) for free.
Additionally to that, postfix specifiers 'p', 'f' and 's' are supported
as suggested and initially implemented in 2009 by Joe Perches [1].
Handling of those additional specifiers orientate on the initial RFC that
was proposed. Also we support IPv6 compressed format specified by 'c' and
various other IPv4 extensions as stated in the documentation part.
Likely, there are many other areas than just SCTP in the kernel to make
use of this extension as well.
[1] http://patchwork.ozlabs.org/patch/31480/
Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
CC: Joe Perches <joe@perches.com>
CC: linux-kernel@vger.kernel.org
Signed-off-by: David S. Miller <davem@davemloft.net>
2013-06-29 01:49:39 +08:00
|
|
|
* %pIS depending on sa_family of 'struct sockaddr *' print IPv4/IPv6 address
|
|
|
|
* %piS depending on sa_family of 'struct sockaddr *' print IPv4/IPv6 address
|
2009-12-18 07:27:12 +08:00
|
|
|
* %pU[bBlL] print a UUID/GUID in big or little endian using lower or upper
|
|
|
|
* case.
|
2012-07-31 05:40:27 +08:00
|
|
|
* %*ph[CDN] a variable-length hex string with a separator (supports up to 64
|
|
|
|
* bytes of the input)
|
2009-09-17 21:27:29 +08:00
|
|
|
* %n is ignored
|
2008-10-16 13:02:02 +08:00
|
|
|
*
|
2012-07-31 05:40:25 +08:00
|
|
|
* ** Please update Documentation/printk-formats.txt when making changes **
|
|
|
|
*
|
2005-04-17 06:20:36 +08:00
|
|
|
* The return value is the number of characters which would
|
|
|
|
* be generated for the given input, excluding the trailing
|
|
|
|
* '\0', as per ISO C99. If you want to have the exact
|
|
|
|
* number of characters written into @buf as return value
|
2007-02-10 17:45:59 +08:00
|
|
|
* (not including the trailing '\0'), use vscnprintf(). If the
|
2005-04-17 06:20:36 +08:00
|
|
|
* return is greater than or equal to @size, the resulting
|
|
|
|
* string is truncated.
|
|
|
|
*
|
2011-04-06 22:49:04 +08:00
|
|
|
* If you're not already dealing with a va_list consider using snprintf().
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
|
|
|
|
{
|
|
|
|
unsigned long long num;
|
2009-12-15 10:00:59 +08:00
|
|
|
char *str, *end;
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
struct printf_spec spec = {0};
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-06-25 20:49:17 +08:00
|
|
|
/* Reject out-of-range values early. Large positive sizes are
|
|
|
|
used for unknown buffer sizes. */
|
2009-09-22 08:04:29 +08:00
|
|
|
if (WARN_ON_ONCE((int) size < 0))
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
str = buf;
|
2006-06-25 20:49:17 +08:00
|
|
|
end = buf + size;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-06-25 20:49:17 +08:00
|
|
|
/* Make sure end is always >= buf */
|
|
|
|
if (end < buf) {
|
|
|
|
end = ((void *)-1);
|
|
|
|
size = end - buf;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
while (*fmt) {
|
|
|
|
const char *old_fmt = fmt;
|
2009-12-15 10:00:59 +08:00
|
|
|
int read = format_decode(fmt, &spec);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
fmt += read;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
switch (spec.type) {
|
|
|
|
case FORMAT_TYPE_NONE: {
|
|
|
|
int copy = read;
|
|
|
|
if (str < end) {
|
|
|
|
if (copy > end - str)
|
|
|
|
copy = end - str;
|
|
|
|
memcpy(str, old_fmt, copy);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
str += read;
|
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2009-03-14 19:08:50 +08:00
|
|
|
case FORMAT_TYPE_WIDTH:
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
spec.field_width = va_arg(args, int);
|
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
case FORMAT_TYPE_PRECISION:
|
|
|
|
spec.precision = va_arg(args, int);
|
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-12-15 10:00:59 +08:00
|
|
|
case FORMAT_TYPE_CHAR: {
|
|
|
|
char c;
|
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
if (!(spec.flags & LEFT)) {
|
|
|
|
while (--spec.field_width > 0) {
|
2006-06-25 20:49:17 +08:00
|
|
|
if (str < end)
|
2005-04-17 06:20:36 +08:00
|
|
|
*str = ' ';
|
|
|
|
++str;
|
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
c = (unsigned char) va_arg(args, int);
|
|
|
|
if (str < end)
|
|
|
|
*str = c;
|
|
|
|
++str;
|
|
|
|
while (--spec.field_width > 0) {
|
2006-06-25 20:49:17 +08:00
|
|
|
if (str < end)
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
*str = ' ';
|
2005-04-17 06:20:36 +08:00
|
|
|
++str;
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
}
|
|
|
|
break;
|
2009-12-15 10:00:59 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
case FORMAT_TYPE_STR:
|
|
|
|
str = string(str, end, va_arg(args, char *), spec);
|
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
case FORMAT_TYPE_PTR:
|
|
|
|
str = pointer(fmt+1, str, end, va_arg(args, void *),
|
|
|
|
spec);
|
|
|
|
while (isalnum(*fmt))
|
|
|
|
fmt++;
|
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
case FORMAT_TYPE_PERCENT_CHAR:
|
|
|
|
if (str < end)
|
|
|
|
*str = '%';
|
|
|
|
++str;
|
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
case FORMAT_TYPE_INVALID:
|
|
|
|
if (str < end)
|
|
|
|
*str = '%';
|
|
|
|
++str;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FORMAT_TYPE_NRCHARS: {
|
2010-03-07 09:10:14 +08:00
|
|
|
u8 qualifier = spec.qualifier;
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
|
|
|
|
if (qualifier == 'l') {
|
|
|
|
long *ip = va_arg(args, long *);
|
|
|
|
*ip = (str - buf);
|
2011-07-26 08:13:20 +08:00
|
|
|
} else if (_tolower(qualifier) == 'z') {
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
size_t *ip = va_arg(args, size_t *);
|
|
|
|
*ip = (str - buf);
|
|
|
|
} else {
|
|
|
|
int *ip = va_arg(args, int *);
|
|
|
|
*ip = (str - buf);
|
|
|
|
}
|
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
|
|
|
|
default:
|
|
|
|
switch (spec.type) {
|
|
|
|
case FORMAT_TYPE_LONG_LONG:
|
|
|
|
num = va_arg(args, long long);
|
|
|
|
break;
|
|
|
|
case FORMAT_TYPE_ULONG:
|
|
|
|
num = va_arg(args, unsigned long);
|
|
|
|
break;
|
|
|
|
case FORMAT_TYPE_LONG:
|
|
|
|
num = va_arg(args, long);
|
|
|
|
break;
|
|
|
|
case FORMAT_TYPE_SIZE_T:
|
2012-12-18 07:59:58 +08:00
|
|
|
if (spec.flags & SIGN)
|
|
|
|
num = va_arg(args, ssize_t);
|
|
|
|
else
|
|
|
|
num = va_arg(args, size_t);
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
break;
|
|
|
|
case FORMAT_TYPE_PTRDIFF:
|
|
|
|
num = va_arg(args, ptrdiff_t);
|
|
|
|
break;
|
2009-03-27 17:07:05 +08:00
|
|
|
case FORMAT_TYPE_UBYTE:
|
|
|
|
num = (unsigned char) va_arg(args, int);
|
|
|
|
break;
|
|
|
|
case FORMAT_TYPE_BYTE:
|
|
|
|
num = (signed char) va_arg(args, int);
|
|
|
|
break;
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
case FORMAT_TYPE_USHORT:
|
|
|
|
num = (unsigned short) va_arg(args, int);
|
|
|
|
break;
|
|
|
|
case FORMAT_TYPE_SHORT:
|
|
|
|
num = (short) va_arg(args, int);
|
|
|
|
break;
|
2009-03-10 04:15:04 +08:00
|
|
|
case FORMAT_TYPE_INT:
|
|
|
|
num = (int) va_arg(args, int);
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
num = va_arg(args, unsigned int);
|
|
|
|
}
|
|
|
|
|
|
|
|
str = number(str, end, num, spec);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
|
2006-06-25 20:49:17 +08:00
|
|
|
if (size > 0) {
|
|
|
|
if (str < end)
|
|
|
|
*str = '\0';
|
|
|
|
else
|
2006-06-29 08:09:34 +08:00
|
|
|
end[-1] = '\0';
|
2006-06-25 20:49:17 +08:00
|
|
|
}
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
|
2006-06-25 20:49:17 +08:00
|
|
|
/* the trailing null byte doesn't count towards the total */
|
2005-04-17 06:20:36 +08:00
|
|
|
return str-buf;
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(vsnprintf);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* vscnprintf - Format a string and place it in a buffer
|
|
|
|
* @buf: The buffer to place the result into
|
|
|
|
* @size: The size of the buffer, including the trailing null space
|
|
|
|
* @fmt: The format string to use
|
|
|
|
* @args: Arguments for the format string
|
|
|
|
*
|
|
|
|
* The return value is the number of characters which have been written into
|
2011-01-13 08:59:49 +08:00
|
|
|
* the @buf not including the trailing '\0'. If @size is == 0 the function
|
2005-04-17 06:20:36 +08:00
|
|
|
* returns 0.
|
|
|
|
*
|
2011-04-06 22:49:04 +08:00
|
|
|
* If you're not already dealing with a va_list consider using scnprintf().
|
2008-10-16 13:02:02 +08:00
|
|
|
*
|
|
|
|
* See the vsnprintf() documentation for format string extensions over C99.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
int vscnprintf(char *buf, size_t size, const char *fmt, va_list args)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2009-12-15 10:00:57 +08:00
|
|
|
i = vsnprintf(buf, size, fmt, args);
|
|
|
|
|
2011-01-13 08:59:49 +08:00
|
|
|
if (likely(i < size))
|
|
|
|
return i;
|
|
|
|
if (size != 0)
|
|
|
|
return size - 1;
|
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(vscnprintf);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* snprintf - Format a string and place it in a buffer
|
|
|
|
* @buf: The buffer to place the result into
|
|
|
|
* @size: The size of the buffer, including the trailing null space
|
|
|
|
* @fmt: The format string to use
|
|
|
|
* @...: Arguments for the format string
|
|
|
|
*
|
|
|
|
* The return value is the number of characters which would be
|
|
|
|
* generated for the given input, excluding the trailing null,
|
|
|
|
* as per ISO C99. If the return is greater than or equal to
|
|
|
|
* @size, the resulting string is truncated.
|
2008-10-16 13:02:02 +08:00
|
|
|
*
|
|
|
|
* See the vsnprintf() documentation for format string extensions over C99.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2009-12-15 10:00:57 +08:00
|
|
|
int snprintf(char *buf, size_t size, const char *fmt, ...)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
va_start(args, fmt);
|
2009-12-15 10:00:57 +08:00
|
|
|
i = vsnprintf(buf, size, fmt, args);
|
2005-04-17 06:20:36 +08:00
|
|
|
va_end(args);
|
2009-12-15 10:00:57 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(snprintf);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* scnprintf - Format a string and place it in a buffer
|
|
|
|
* @buf: The buffer to place the result into
|
|
|
|
* @size: The size of the buffer, including the trailing null space
|
|
|
|
* @fmt: The format string to use
|
|
|
|
* @...: Arguments for the format string
|
|
|
|
*
|
|
|
|
* The return value is the number of characters written into @buf not including
|
2010-10-27 05:22:50 +08:00
|
|
|
* the trailing '\0'. If @size is == 0 the function returns 0.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
|
2009-12-15 10:00:57 +08:00
|
|
|
int scnprintf(char *buf, size_t size, const char *fmt, ...)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
va_start(args, fmt);
|
2011-01-13 08:59:49 +08:00
|
|
|
i = vscnprintf(buf, size, fmt, args);
|
2005-04-17 06:20:36 +08:00
|
|
|
va_end(args);
|
2009-12-15 10:00:57 +08:00
|
|
|
|
2011-01-13 08:59:49 +08:00
|
|
|
return i;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(scnprintf);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* vsprintf - Format a string and place it in a buffer
|
|
|
|
* @buf: The buffer to place the result into
|
|
|
|
* @fmt: The format string to use
|
|
|
|
* @args: Arguments for the format string
|
|
|
|
*
|
|
|
|
* The function returns the number of characters written
|
2007-02-10 17:45:59 +08:00
|
|
|
* into @buf. Use vsnprintf() or vscnprintf() in order to avoid
|
2005-04-17 06:20:36 +08:00
|
|
|
* buffer overflows.
|
|
|
|
*
|
2011-04-06 22:49:04 +08:00
|
|
|
* If you're not already dealing with a va_list consider using sprintf().
|
2008-10-16 13:02:02 +08:00
|
|
|
*
|
|
|
|
* See the vsnprintf() documentation for format string extensions over C99.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
int vsprintf(char *buf, const char *fmt, va_list args)
|
|
|
|
{
|
|
|
|
return vsnprintf(buf, INT_MAX, fmt, args);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(vsprintf);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* sprintf - Format a string and place it in a buffer
|
|
|
|
* @buf: The buffer to place the result into
|
|
|
|
* @fmt: The format string to use
|
|
|
|
* @...: Arguments for the format string
|
|
|
|
*
|
|
|
|
* The function returns the number of characters written
|
2007-02-10 17:45:59 +08:00
|
|
|
* into @buf. Use snprintf() or scnprintf() in order to avoid
|
2005-04-17 06:20:36 +08:00
|
|
|
* buffer overflows.
|
2008-10-16 13:02:02 +08:00
|
|
|
*
|
|
|
|
* See the vsnprintf() documentation for format string extensions over C99.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2009-12-15 10:00:57 +08:00
|
|
|
int sprintf(char *buf, const char *fmt, ...)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
va_start(args, fmt);
|
2009-12-15 10:00:57 +08:00
|
|
|
i = vsnprintf(buf, INT_MAX, fmt, args);
|
2005-04-17 06:20:36 +08:00
|
|
|
va_end(args);
|
2009-12-15 10:00:57 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(sprintf);
|
|
|
|
|
2009-03-07 00:21:46 +08:00
|
|
|
#ifdef CONFIG_BINARY_PRINTF
|
|
|
|
/*
|
|
|
|
* bprintf service:
|
|
|
|
* vbin_printf() - VA arguments to binary data
|
|
|
|
* bstr_printf() - Binary data to text string
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* vbin_printf - Parse a format string and place args' binary value in a buffer
|
|
|
|
* @bin_buf: The buffer to place args' binary value
|
|
|
|
* @size: The size of the buffer(by words(32bits), not characters)
|
|
|
|
* @fmt: The format string to use
|
|
|
|
* @args: Arguments for the format string
|
|
|
|
*
|
|
|
|
* The format follows C99 vsnprintf, except %n is ignored, and its argument
|
|
|
|
* is skiped.
|
|
|
|
*
|
|
|
|
* The return value is the number of words(32bits) which would be generated for
|
|
|
|
* the given input.
|
|
|
|
*
|
|
|
|
* NOTE:
|
|
|
|
* If the return value is greater than @size, the resulting bin_buf is NOT
|
|
|
|
* valid for bstr_printf().
|
|
|
|
*/
|
|
|
|
int vbin_printf(u32 *bin_buf, size_t size, const char *fmt, va_list args)
|
|
|
|
{
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
struct printf_spec spec = {0};
|
2009-03-07 00:21:46 +08:00
|
|
|
char *str, *end;
|
|
|
|
|
|
|
|
str = (char *)bin_buf;
|
|
|
|
end = (char *)(bin_buf + size);
|
|
|
|
|
|
|
|
#define save_arg(type) \
|
|
|
|
do { \
|
|
|
|
if (sizeof(type) == 8) { \
|
|
|
|
unsigned long long value; \
|
|
|
|
str = PTR_ALIGN(str, sizeof(u32)); \
|
|
|
|
value = va_arg(args, unsigned long long); \
|
|
|
|
if (str + sizeof(type) <= end) { \
|
|
|
|
*(u32 *)str = *(u32 *)&value; \
|
|
|
|
*(u32 *)(str + 4) = *((u32 *)&value + 1); \
|
|
|
|
} \
|
|
|
|
} else { \
|
|
|
|
unsigned long value; \
|
|
|
|
str = PTR_ALIGN(str, sizeof(type)); \
|
|
|
|
value = va_arg(args, int); \
|
|
|
|
if (str + sizeof(type) <= end) \
|
|
|
|
*(typeof(type) *)str = (type)value; \
|
|
|
|
} \
|
|
|
|
str += sizeof(type); \
|
|
|
|
} while (0)
|
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
while (*fmt) {
|
2009-12-15 10:00:59 +08:00
|
|
|
int read = format_decode(fmt, &spec);
|
2009-03-07 00:21:46 +08:00
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
fmt += read;
|
2009-03-07 00:21:46 +08:00
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
switch (spec.type) {
|
|
|
|
case FORMAT_TYPE_NONE:
|
2009-12-15 10:00:59 +08:00
|
|
|
case FORMAT_TYPE_INVALID:
|
|
|
|
case FORMAT_TYPE_PERCENT_CHAR:
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
break;
|
|
|
|
|
2009-03-14 19:08:50 +08:00
|
|
|
case FORMAT_TYPE_WIDTH:
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
case FORMAT_TYPE_PRECISION:
|
|
|
|
save_arg(int);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FORMAT_TYPE_CHAR:
|
2009-03-07 00:21:46 +08:00
|
|
|
save_arg(char);
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FORMAT_TYPE_STR: {
|
2009-03-07 00:21:46 +08:00
|
|
|
const char *save_str = va_arg(args, char *);
|
|
|
|
size_t len;
|
2009-12-15 10:00:56 +08:00
|
|
|
|
2009-03-07 00:21:46 +08:00
|
|
|
if ((unsigned long)save_str > (unsigned long)-PAGE_SIZE
|
|
|
|
|| (unsigned long)save_str < PAGE_SIZE)
|
2009-12-15 10:00:55 +08:00
|
|
|
save_str = "(null)";
|
2009-12-15 10:00:56 +08:00
|
|
|
len = strlen(save_str) + 1;
|
|
|
|
if (str + len < end)
|
|
|
|
memcpy(str, save_str, len);
|
|
|
|
str += len;
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
break;
|
2009-03-07 00:21:46 +08:00
|
|
|
}
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
|
|
|
|
case FORMAT_TYPE_PTR:
|
2009-03-07 00:21:46 +08:00
|
|
|
save_arg(void *);
|
|
|
|
/* skip all alphanumeric pointer suffixes */
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
while (isalnum(*fmt))
|
2009-03-07 00:21:46 +08:00
|
|
|
fmt++;
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FORMAT_TYPE_NRCHARS: {
|
2009-03-07 00:21:46 +08:00
|
|
|
/* skip %n 's argument */
|
2010-03-07 09:10:14 +08:00
|
|
|
u8 qualifier = spec.qualifier;
|
2009-03-07 00:21:46 +08:00
|
|
|
void *skip_arg;
|
|
|
|
if (qualifier == 'l')
|
|
|
|
skip_arg = va_arg(args, long *);
|
2011-07-26 08:13:20 +08:00
|
|
|
else if (_tolower(qualifier) == 'z')
|
2009-03-07 00:21:46 +08:00
|
|
|
skip_arg = va_arg(args, size_t *);
|
|
|
|
else
|
|
|
|
skip_arg = va_arg(args, int *);
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
break;
|
2009-03-07 00:21:46 +08:00
|
|
|
}
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
|
|
|
|
default:
|
|
|
|
switch (spec.type) {
|
|
|
|
|
|
|
|
case FORMAT_TYPE_LONG_LONG:
|
2009-03-07 00:21:46 +08:00
|
|
|
save_arg(long long);
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
break;
|
|
|
|
case FORMAT_TYPE_ULONG:
|
|
|
|
case FORMAT_TYPE_LONG:
|
2009-03-07 00:21:46 +08:00
|
|
|
save_arg(unsigned long);
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
break;
|
|
|
|
case FORMAT_TYPE_SIZE_T:
|
2009-03-07 00:21:46 +08:00
|
|
|
save_arg(size_t);
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
break;
|
|
|
|
case FORMAT_TYPE_PTRDIFF:
|
2009-03-07 00:21:46 +08:00
|
|
|
save_arg(ptrdiff_t);
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
break;
|
2009-03-27 17:07:05 +08:00
|
|
|
case FORMAT_TYPE_UBYTE:
|
|
|
|
case FORMAT_TYPE_BYTE:
|
|
|
|
save_arg(char);
|
|
|
|
break;
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
case FORMAT_TYPE_USHORT:
|
|
|
|
case FORMAT_TYPE_SHORT:
|
2009-03-07 00:21:46 +08:00
|
|
|
save_arg(short);
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
break;
|
|
|
|
default:
|
2009-03-07 00:21:46 +08:00
|
|
|
save_arg(int);
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
}
|
2009-03-07 00:21:46 +08:00
|
|
|
}
|
|
|
|
}
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
|
2009-12-15 10:00:57 +08:00
|
|
|
return (u32 *)(PTR_ALIGN(str, sizeof(u32))) - bin_buf;
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
#undef save_arg
|
2009-03-07 00:21:46 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(vbin_printf);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* bstr_printf - Format a string from binary arguments and place it in a buffer
|
|
|
|
* @buf: The buffer to place the result into
|
|
|
|
* @size: The size of the buffer, including the trailing null space
|
|
|
|
* @fmt: The format string to use
|
|
|
|
* @bin_buf: Binary arguments for the format string
|
|
|
|
*
|
|
|
|
* This function like C99 vsnprintf, but the difference is that vsnprintf gets
|
|
|
|
* arguments from stack, and bstr_printf gets arguments from @bin_buf which is
|
|
|
|
* a binary buffer that generated by vbin_printf.
|
|
|
|
*
|
|
|
|
* The format follows C99 vsnprintf, but has some extensions:
|
2009-09-17 21:27:29 +08:00
|
|
|
* see vsnprintf comment for details.
|
2009-03-07 00:21:46 +08:00
|
|
|
*
|
|
|
|
* The return value is the number of characters which would
|
|
|
|
* be generated for the given input, excluding the trailing
|
|
|
|
* '\0', as per ISO C99. If you want to have the exact
|
|
|
|
* number of characters written into @buf as return value
|
|
|
|
* (not including the trailing '\0'), use vscnprintf(). If the
|
|
|
|
* return is greater than or equal to @size, the resulting
|
|
|
|
* string is truncated.
|
|
|
|
*/
|
|
|
|
int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
|
|
|
|
{
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
struct printf_spec spec = {0};
|
2009-12-15 10:00:59 +08:00
|
|
|
char *str, *end;
|
|
|
|
const char *args = (const char *)bin_buf;
|
2009-03-07 00:21:46 +08:00
|
|
|
|
2009-09-22 08:04:29 +08:00
|
|
|
if (WARN_ON_ONCE((int) size < 0))
|
2009-03-07 00:21:46 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
str = buf;
|
|
|
|
end = buf + size;
|
|
|
|
|
|
|
|
#define get_arg(type) \
|
|
|
|
({ \
|
|
|
|
typeof(type) value; \
|
|
|
|
if (sizeof(type) == 8) { \
|
|
|
|
args = PTR_ALIGN(args, sizeof(u32)); \
|
|
|
|
*(u32 *)&value = *(u32 *)args; \
|
|
|
|
*((u32 *)&value + 1) = *(u32 *)(args + 4); \
|
|
|
|
} else { \
|
|
|
|
args = PTR_ALIGN(args, sizeof(type)); \
|
|
|
|
value = *(typeof(type) *)args; \
|
|
|
|
} \
|
|
|
|
args += sizeof(type); \
|
|
|
|
value; \
|
|
|
|
})
|
|
|
|
|
|
|
|
/* Make sure end is always >= buf */
|
|
|
|
if (end < buf) {
|
|
|
|
end = ((void *)-1);
|
|
|
|
size = end - buf;
|
|
|
|
}
|
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
while (*fmt) {
|
|
|
|
const char *old_fmt = fmt;
|
2009-12-15 10:00:59 +08:00
|
|
|
int read = format_decode(fmt, &spec);
|
2009-03-07 00:21:46 +08:00
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
fmt += read;
|
2009-03-07 00:21:46 +08:00
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
switch (spec.type) {
|
|
|
|
case FORMAT_TYPE_NONE: {
|
|
|
|
int copy = read;
|
|
|
|
if (str < end) {
|
|
|
|
if (copy > end - str)
|
|
|
|
copy = end - str;
|
|
|
|
memcpy(str, old_fmt, copy);
|
2009-03-07 00:21:46 +08:00
|
|
|
}
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
str += read;
|
|
|
|
break;
|
2009-03-07 00:21:46 +08:00
|
|
|
}
|
|
|
|
|
2009-03-14 19:08:50 +08:00
|
|
|
case FORMAT_TYPE_WIDTH:
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
spec.field_width = get_arg(int);
|
|
|
|
break;
|
2009-03-07 00:21:46 +08:00
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
case FORMAT_TYPE_PRECISION:
|
|
|
|
spec.precision = get_arg(int);
|
|
|
|
break;
|
2009-03-07 00:21:46 +08:00
|
|
|
|
2009-12-15 10:00:59 +08:00
|
|
|
case FORMAT_TYPE_CHAR: {
|
|
|
|
char c;
|
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
if (!(spec.flags & LEFT)) {
|
|
|
|
while (--spec.field_width > 0) {
|
2009-03-07 00:21:46 +08:00
|
|
|
if (str < end)
|
|
|
|
*str = ' ';
|
|
|
|
++str;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
c = (unsigned char) get_arg(char);
|
|
|
|
if (str < end)
|
|
|
|
*str = c;
|
|
|
|
++str;
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
while (--spec.field_width > 0) {
|
2009-03-07 00:21:46 +08:00
|
|
|
if (str < end)
|
|
|
|
*str = ' ';
|
|
|
|
++str;
|
|
|
|
}
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
break;
|
2009-12-15 10:00:59 +08:00
|
|
|
}
|
2009-03-07 00:21:46 +08:00
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
case FORMAT_TYPE_STR: {
|
2009-03-07 00:21:46 +08:00
|
|
|
const char *str_arg = args;
|
2009-12-15 10:00:59 +08:00
|
|
|
args += strlen(str_arg) + 1;
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
str = string(str, end, (char *)str_arg, spec);
|
|
|
|
break;
|
2009-03-07 00:21:46 +08:00
|
|
|
}
|
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
case FORMAT_TYPE_PTR:
|
|
|
|
str = pointer(fmt+1, str, end, get_arg(void *), spec);
|
|
|
|
while (isalnum(*fmt))
|
2009-03-07 00:21:46 +08:00
|
|
|
fmt++;
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
break;
|
2009-03-07 00:21:46 +08:00
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
case FORMAT_TYPE_PERCENT_CHAR:
|
|
|
|
case FORMAT_TYPE_INVALID:
|
2009-03-07 00:21:46 +08:00
|
|
|
if (str < end)
|
|
|
|
*str = '%';
|
|
|
|
++str;
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FORMAT_TYPE_NRCHARS:
|
|
|
|
/* skip */
|
|
|
|
break;
|
|
|
|
|
2009-12-15 10:00:59 +08:00
|
|
|
default: {
|
|
|
|
unsigned long long num;
|
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
switch (spec.type) {
|
|
|
|
|
|
|
|
case FORMAT_TYPE_LONG_LONG:
|
|
|
|
num = get_arg(long long);
|
|
|
|
break;
|
|
|
|
case FORMAT_TYPE_ULONG:
|
|
|
|
case FORMAT_TYPE_LONG:
|
|
|
|
num = get_arg(unsigned long);
|
|
|
|
break;
|
|
|
|
case FORMAT_TYPE_SIZE_T:
|
|
|
|
num = get_arg(size_t);
|
|
|
|
break;
|
|
|
|
case FORMAT_TYPE_PTRDIFF:
|
|
|
|
num = get_arg(ptrdiff_t);
|
|
|
|
break;
|
2009-03-27 17:07:05 +08:00
|
|
|
case FORMAT_TYPE_UBYTE:
|
|
|
|
num = get_arg(unsigned char);
|
|
|
|
break;
|
|
|
|
case FORMAT_TYPE_BYTE:
|
|
|
|
num = get_arg(signed char);
|
|
|
|
break;
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
case FORMAT_TYPE_USHORT:
|
|
|
|
num = get_arg(unsigned short);
|
|
|
|
break;
|
|
|
|
case FORMAT_TYPE_SHORT:
|
|
|
|
num = get_arg(short);
|
|
|
|
break;
|
|
|
|
case FORMAT_TYPE_UINT:
|
|
|
|
num = get_arg(unsigned int);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
num = get_arg(int);
|
|
|
|
}
|
|
|
|
|
|
|
|
str = number(str, end, num, spec);
|
2009-12-15 10:00:59 +08:00
|
|
|
} /* default: */
|
|
|
|
} /* switch(spec.type) */
|
|
|
|
} /* while(*fmt) */
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
|
2009-03-07 00:21:46 +08:00
|
|
|
if (size > 0) {
|
|
|
|
if (str < end)
|
|
|
|
*str = '\0';
|
|
|
|
else
|
|
|
|
end[-1] = '\0';
|
|
|
|
}
|
vsprintf: unify the format decoding layer for its 3 users
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 <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-07 00:21:50 +08:00
|
|
|
|
2009-03-07 00:21:46 +08:00
|
|
|
#undef get_arg
|
|
|
|
|
|
|
|
/* the trailing null byte doesn't count towards the total */
|
|
|
|
return str - buf;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(bstr_printf);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* bprintf - Parse a format string and place args' binary value in a buffer
|
|
|
|
* @bin_buf: The buffer to place args' binary value
|
|
|
|
* @size: The size of the buffer(by words(32bits), not characters)
|
|
|
|
* @fmt: The format string to use
|
|
|
|
* @...: Arguments for the format string
|
|
|
|
*
|
|
|
|
* The function returns the number of words(u32) written
|
|
|
|
* into @bin_buf.
|
|
|
|
*/
|
|
|
|
int bprintf(u32 *bin_buf, size_t size, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
va_start(args, fmt);
|
|
|
|
ret = vbin_printf(bin_buf, size, fmt, args);
|
|
|
|
va_end(args);
|
2009-12-15 10:00:57 +08:00
|
|
|
|
2009-03-07 00:21:46 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(bprintf);
|
|
|
|
|
|
|
|
#endif /* CONFIG_BINARY_PRINTF */
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/**
|
|
|
|
* vsscanf - Unformat a buffer into a list of arguments
|
|
|
|
* @buf: input buffer
|
|
|
|
* @fmt: format of buffer
|
|
|
|
* @args: arguments
|
|
|
|
*/
|
2009-12-15 10:00:57 +08:00
|
|
|
int vsscanf(const char *buf, const char *fmt, va_list args)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
const char *str = buf;
|
|
|
|
char *next;
|
|
|
|
char digit;
|
|
|
|
int num = 0;
|
2010-03-07 09:10:14 +08:00
|
|
|
u8 qualifier;
|
2012-12-18 08:01:31 +08:00
|
|
|
unsigned int base;
|
|
|
|
union {
|
|
|
|
long long s;
|
|
|
|
unsigned long long u;
|
|
|
|
} val;
|
2010-03-07 09:10:14 +08:00
|
|
|
s16 field_width;
|
2009-12-15 10:00:59 +08:00
|
|
|
bool is_sign;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-10-05 08:13:24 +08:00
|
|
|
while (*fmt) {
|
2005-04-17 06:20:36 +08:00
|
|
|
/* skip any white space in format */
|
|
|
|
/* white space in format matchs any amount of
|
|
|
|
* white space, including none, in the input.
|
|
|
|
*/
|
|
|
|
if (isspace(*fmt)) {
|
2009-12-15 10:01:06 +08:00
|
|
|
fmt = skip_spaces(++fmt);
|
|
|
|
str = skip_spaces(str);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* anything that is not a conversion must match exactly */
|
|
|
|
if (*fmt != '%' && *fmt) {
|
|
|
|
if (*fmt++ != *str++)
|
|
|
|
break;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!*fmt)
|
|
|
|
break;
|
|
|
|
++fmt;
|
2009-12-15 10:00:57 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* skip this conversion.
|
|
|
|
* advance both strings to next white space
|
|
|
|
*/
|
|
|
|
if (*fmt == '*') {
|
2012-10-05 08:13:24 +08:00
|
|
|
if (!*str)
|
|
|
|
break;
|
2009-10-02 06:44:27 +08:00
|
|
|
while (!isspace(*fmt) && *fmt != '%' && *fmt)
|
2005-04-17 06:20:36 +08:00
|
|
|
fmt++;
|
|
|
|
while (!isspace(*str) && *str)
|
|
|
|
str++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get field width */
|
|
|
|
field_width = -1;
|
2012-12-18 08:01:31 +08:00
|
|
|
if (isdigit(*fmt)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
field_width = skip_atoi(&fmt);
|
2012-12-18 08:01:31 +08:00
|
|
|
if (field_width <= 0)
|
|
|
|
break;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* get conversion qualifier */
|
|
|
|
qualifier = -1;
|
2011-07-26 08:13:20 +08:00
|
|
|
if (*fmt == 'h' || _tolower(*fmt) == 'l' ||
|
|
|
|
_tolower(*fmt) == 'z') {
|
2005-04-17 06:20:36 +08:00
|
|
|
qualifier = *fmt++;
|
|
|
|
if (unlikely(qualifier == *fmt)) {
|
|
|
|
if (qualifier == 'h') {
|
|
|
|
qualifier = 'H';
|
|
|
|
fmt++;
|
|
|
|
} else if (qualifier == 'l') {
|
|
|
|
qualifier = 'L';
|
|
|
|
fmt++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-05 08:13:24 +08:00
|
|
|
if (!*fmt)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (*fmt == 'n') {
|
|
|
|
/* return number of characters read so far */
|
|
|
|
*va_arg(args, int *) = str - buf;
|
|
|
|
++fmt;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!*str)
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
|
2009-12-15 10:00:59 +08:00
|
|
|
base = 10;
|
|
|
|
is_sign = 0;
|
|
|
|
|
2009-12-15 10:00:57 +08:00
|
|
|
switch (*fmt++) {
|
2005-04-17 06:20:36 +08:00
|
|
|
case 'c':
|
|
|
|
{
|
2009-12-15 10:00:57 +08:00
|
|
|
char *s = (char *)va_arg(args, char*);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (field_width == -1)
|
|
|
|
field_width = 1;
|
|
|
|
do {
|
|
|
|
*s++ = *str++;
|
|
|
|
} while (--field_width > 0 && *str);
|
|
|
|
num++;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
case 's':
|
|
|
|
{
|
2009-12-15 10:00:57 +08:00
|
|
|
char *s = (char *)va_arg(args, char *);
|
|
|
|
if (field_width == -1)
|
2010-05-25 05:33:03 +08:00
|
|
|
field_width = SHRT_MAX;
|
2005-04-17 06:20:36 +08:00
|
|
|
/* first, skip leading white space in buffer */
|
2009-12-15 10:01:06 +08:00
|
|
|
str = skip_spaces(str);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* now copy until next white space */
|
2009-12-15 10:00:57 +08:00
|
|
|
while (*str && !isspace(*str) && field_width--)
|
2005-04-17 06:20:36 +08:00
|
|
|
*s++ = *str++;
|
|
|
|
*s = '\0';
|
|
|
|
num++;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
case 'o':
|
|
|
|
base = 8;
|
|
|
|
break;
|
|
|
|
case 'x':
|
|
|
|
case 'X':
|
|
|
|
base = 16;
|
|
|
|
break;
|
|
|
|
case 'i':
|
2009-12-15 10:00:57 +08:00
|
|
|
base = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
case 'd':
|
|
|
|
is_sign = 1;
|
|
|
|
case 'u':
|
|
|
|
break;
|
|
|
|
case '%':
|
|
|
|
/* looking for '%' in str */
|
2009-12-15 10:00:57 +08:00
|
|
|
if (*str++ != '%')
|
2005-04-17 06:20:36 +08:00
|
|
|
return num;
|
|
|
|
continue;
|
|
|
|
default:
|
|
|
|
/* invalid format; stop here */
|
|
|
|
return num;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* have some sort of integer conversion.
|
|
|
|
* first, skip white space in buffer.
|
|
|
|
*/
|
2009-12-15 10:01:06 +08:00
|
|
|
str = skip_spaces(str);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
digit = *str;
|
|
|
|
if (is_sign && digit == '-')
|
|
|
|
digit = *(str + 1);
|
|
|
|
|
|
|
|
if (!digit
|
2009-12-15 10:00:57 +08:00
|
|
|
|| (base == 16 && !isxdigit(digit))
|
|
|
|
|| (base == 10 && !isdigit(digit))
|
|
|
|
|| (base == 8 && (!isdigit(digit) || digit > '7'))
|
|
|
|
|| (base == 0 && !isdigit(digit)))
|
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-12-18 08:01:31 +08:00
|
|
|
if (is_sign)
|
|
|
|
val.s = qualifier != 'L' ?
|
|
|
|
simple_strtol(str, &next, base) :
|
|
|
|
simple_strtoll(str, &next, base);
|
|
|
|
else
|
|
|
|
val.u = qualifier != 'L' ?
|
|
|
|
simple_strtoul(str, &next, base) :
|
|
|
|
simple_strtoull(str, &next, base);
|
|
|
|
|
|
|
|
if (field_width > 0 && next - str > field_width) {
|
|
|
|
if (base == 0)
|
|
|
|
_parse_integer_fixup_radix(str, &base);
|
|
|
|
while (next - str > field_width) {
|
|
|
|
if (is_sign)
|
|
|
|
val.s = div_s64(val.s, base);
|
|
|
|
else
|
|
|
|
val.u = div_u64(val.u, base);
|
|
|
|
--next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-15 10:00:57 +08:00
|
|
|
switch (qualifier) {
|
2005-04-17 06:20:36 +08:00
|
|
|
case 'H': /* that's 'hh' in format */
|
2012-12-18 08:01:31 +08:00
|
|
|
if (is_sign)
|
|
|
|
*va_arg(args, signed char *) = val.s;
|
|
|
|
else
|
|
|
|
*va_arg(args, unsigned char *) = val.u;
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
case 'h':
|
2012-12-18 08:01:31 +08:00
|
|
|
if (is_sign)
|
|
|
|
*va_arg(args, short *) = val.s;
|
|
|
|
else
|
|
|
|
*va_arg(args, unsigned short *) = val.u;
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
case 'l':
|
2012-12-18 08:01:31 +08:00
|
|
|
if (is_sign)
|
|
|
|
*va_arg(args, long *) = val.s;
|
|
|
|
else
|
|
|
|
*va_arg(args, unsigned long *) = val.u;
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
case 'L':
|
2012-12-18 08:01:31 +08:00
|
|
|
if (is_sign)
|
|
|
|
*va_arg(args, long long *) = val.s;
|
|
|
|
else
|
|
|
|
*va_arg(args, unsigned long long *) = val.u;
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
case 'Z':
|
|
|
|
case 'z':
|
2012-12-18 08:01:31 +08:00
|
|
|
*va_arg(args, size_t *) = val.u;
|
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
default:
|
2012-12-18 08:01:31 +08:00
|
|
|
if (is_sign)
|
|
|
|
*va_arg(args, int *) = val.s;
|
|
|
|
else
|
|
|
|
*va_arg(args, unsigned int *) = val.u;
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
num++;
|
|
|
|
|
|
|
|
if (!next)
|
|
|
|
break;
|
|
|
|
str = next;
|
|
|
|
}
|
2007-05-08 15:27:20 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return num;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(vsscanf);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* sscanf - Unformat a buffer into a list of arguments
|
|
|
|
* @buf: input buffer
|
|
|
|
* @fmt: formatting of buffer
|
|
|
|
* @...: resulting arguments
|
|
|
|
*/
|
2009-12-15 10:00:57 +08:00
|
|
|
int sscanf(const char *buf, const char *fmt, ...)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
int i;
|
|
|
|
|
2009-12-15 10:00:57 +08:00
|
|
|
va_start(args, fmt);
|
|
|
|
i = vsscanf(buf, fmt, args);
|
2005-04-17 06:20:36 +08:00
|
|
|
va_end(args);
|
2009-12-15 10:00:57 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(sscanf);
|