Re: [PATCH] printk: Add monotonic, boottime, and realtime timestamps

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Aug 16, 2017 at 9:46 PM, John Stultz <john.stultz@xxxxxxxxxx> wrote:
> From: Prarit Bhargava <prarit@xxxxxxxxxx>
>
>
> Prarit,
>   So I took my own shot at cleaning up the Kconfig settings to make
> it a bit more sane in my opinion. This should allow the legacy
> defconfigs to just work, and avoids all the defconfig churn in the
> patch.
>
> I almost went through to try to simplify the code and make
> PRINTK_TIME_DISABLE = 0 and to get rid of PRINTK_TIME_UNDEFINED,
> as that seems like extra complexity that could probably be done
> simpler, but I didn't quite have the time to get my head around
> it all, so I left it be. But you might want to see if it can't
> be further simplified (ie: initialize it to CONFIG_PRINTK_TIME_VAL
> and then override it by the boot parameter if specified).
>
> Anwyay, let me know what you think, and feel free to adopt this
> along with any other changes you have planned.
>
> thanks
> -john
>
>
> printk.time=1/CONFIG_PRINTK_TIME=1 adds a unmodified local hardware clock
> timestamp to printk messages.  The local hardware clock loses time each
> day making it difficult to determine exactly when an issue has occurred in
> the kernel log, and making it difficult to determine how kernel and
> hardware issues relate to each other in real time.
>
> Make printk output different timestamps by adding options for no
> timestamp, the local hardware clock, the monotonic clock, the boottime
> clock, and the real clock.  Allow a user to pick one of the clocks by
> using the printk.time kernel parameter.  Output the type of clock in
> /sys/module/printk/parameters/time so userspace programs can interpret the
> timestamp.
>
> Real clock & 32-bit systems:  Selecting the real clock printk timestamp may
> lead to unlikely situations where a timestamp is wrong because the real time
> without the protection of a sequence lock when printk_get_ts() is set
> printk_get_real_ns().
>
> v2: Use peterz's suggested Kconfig options.  Merge patchset together.
> Fix i386 !CONFIG_PRINTK builds.
>
> v3: Fixed x86_64_defconfig. Added printk_time_type enum and
> printk_time_str for better output. Added BOOTTIME clock functionality.
>
> v4: Fix messages, add additional printk.time options, and fix configs.
>
> v5: Renaming of structures, and allow printk_time_set() to
> evaluate substrings of entries (eg: allow 'r', 'real', 'realtime').  From
> peterz, make fast functions return 0 until timekeeping is initialized
> (removes timekeeping_active & ktime_get_boot|real_log_ts() suggested by
>  tglx and adds ktime_get_real_offset()).  Switch to a function pointer
> for printk_get_ts() and reference fast functions.  Make timestamp_sources enum
> match choice options for CONFIG_PRINTK_TIME (adds PRINTK_TIME_UNDEFINED).
>
> v6: Define PRINTK_TIME_UNDEFINED for !CONFIG_PRINTK builds.  Separate
> timekeeping changes into separate patch.  Minor include file cleanup.
>
> Signed-off-by: Prarit Bhargava <prarit@xxxxxxxxxx>
> Cc: Mark Salyzyn <salyzyn@xxxxxxxxxxx>
> Cc: Jonathan Corbet <corbet@xxxxxxx>
> Cc: Petr Mladek <pmladek@xxxxxxxx>
> Cc: Sergey Senozhatsky <sergey.senozhatsky@xxxxxxxxx>
> Cc: Steven Rostedt <rostedt@xxxxxxxxxxx>
> Cc: John Stultz <john.stultz@xxxxxxxxxx>
> Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
> Cc: Stephen Boyd <sboyd@xxxxxxxxxxxxxx>
> Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
> Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
> Cc: "Paul E. McKenney" <paulmck@xxxxxxxxxxxxxxxxxx>
> Cc: Christoffer Dall <cdall@xxxxxxxxxx>
> Cc: Deepa Dinamani <deepa.kernel@xxxxxxxxx>
> Cc: Ingo Molnar <mingo@xxxxxxxxxx>
> Cc: Joel Fernandes <joelaf@xxxxxxxxxx>
> Cc: Prarit Bhargava <prarit@xxxxxxxxxx>
> Cc: Kees Cook <keescook@xxxxxxxxxxxx>
> Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
> Cc: Geert Uytterhoeven <geert+renesas@xxxxxxxxx>
> Cc: "Luis R. Rodriguez" <mcgrof@xxxxxxxxxx>
> Cc: Nicholas Piggin <npiggin@xxxxxxxxx>
> Cc: "Jason A. Donenfeld" <Jason@xxxxxxxxx>
> Cc: Olof Johansson <olof@xxxxxxxxx>
> Cc: Josh Poimboeuf <jpoimboe@xxxxxxxxxx>
> Cc: linux-doc@xxxxxxxxxxxxxxx
> [jstultz: reworked Kconfig settings to avoid defconfig noise]
> Signed-off-by: John Stultz <john.stultz@xxxxxxxxxx>
> ---
>  Documentation/admin-guide/kernel-parameters.txt |   6 +-
>  include/linux/timekeeping.h                     |   1 +
>  kernel/printk/printk.c                          | 147 +++++++++++++++++++++++-
>  kernel/time/timekeeping.c                       |   5 +
>  lib/Kconfig.debug                               |  54 ++++++++-
>  5 files changed, 205 insertions(+), 8 deletions(-)
>
> diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
> index d9c171c..1ba277e 100644
> --- a/Documentation/admin-guide/kernel-parameters.txt
> +++ b/Documentation/admin-guide/kernel-parameters.txt
> @@ -3188,8 +3188,10 @@
>                         ratelimit - ratelimit the logging
>                         Default: ratelimit
>
> -       printk.time=    Show timing data prefixed to each printk message line
> -                       Format: <bool>  (1/Y/y=enable, 0/N/n=disable)
> +       printk.time=    Show timestamp prefixed to each printk message line
> +                       Format: <string>
> +                               (0/N/n/disable, 1/Y/y/local,
> +                                b/boot, m/monotonic, r/realtime)
>
>         processor.max_cstate=   [HW,ACPI]
>                         Limit processor to maximum C-state
> diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h
> index ddc229f..80ca2fa 100644
> --- a/include/linux/timekeeping.h
> +++ b/include/linux/timekeeping.h
> @@ -239,6 +239,7 @@ static inline u64 ktime_get_raw_ns(void)
>  extern u64 ktime_get_mono_fast_ns(void);
>  extern u64 ktime_get_raw_fast_ns(void);
>  extern u64 ktime_get_boot_fast_ns(void);
> +extern u64 ktime_get_real_offset(void);
>
>  /*
>   * Timespec interfaces utilizing the ktime based ones
> diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
> index fc47863..fe208dc 100644
> --- a/kernel/printk/printk.c
> +++ b/kernel/printk/printk.c
> @@ -576,6 +576,9 @@ static u32 truncate_msg(u16 *text_len, u16 *trunc_msg_len,
>         return msg_used_size(*text_len + *trunc_msg_len, 0, pad_len);
>  }
>
> +static u64 printk_set_timestamp(void);
> +static u64 (*printk_get_ts)(void) = printk_set_timestamp;
> +
>  /* insert record into the buffer, discard old ones, update heads */
>  static int log_store(int facility, int level,
>                      enum log_flags flags, u64 ts_nsec,
> @@ -624,7 +627,7 @@ static int log_store(int facility, int level,
>         if (ts_nsec > 0)
>                 msg->ts_nsec = ts_nsec;
>         else
> -               msg->ts_nsec = local_clock();
> +               msg->ts_nsec = printk_get_ts();
>         memset(log_dict(msg) + dict_len, 0, pad_len);
>         msg->len = size;
>
> @@ -1202,14 +1205,141 @@ static inline void boot_delay_msec(int level)
>  }
>  #endif
>
> -static bool printk_time = IS_ENABLED(CONFIG_PRINTK_TIME);
> -module_param_named(time, printk_time, bool, S_IRUGO | S_IWUSR);
> +static int printk_time = CONFIG_PRINTK_TIME_VAL;

Crud.. That should be CONFIG_PRINTK_TIME_TYPE.

Apologies, forgot to commit that bit.

thanks
-john
--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux FS]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]     [Linux Resources]

  Powered by Linux