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

From: Peter Zijlstra
Date: Mon Aug 07 2017 - 13:19:01 EST


On Mon, Aug 07, 2017 at 11:52:42AM -0400, Prarit Bhargava wrote:
> +static u64 printk_get_ts(void)
> +{
> + u64 mono, offset_real;
> +
> + if (printk_time <= PRINTK_TIME_LOCAL)
> + return local_clock();
> +
> + if (printk_time == PRINTK_TIME_BOOT)
> + return ktime_get_boot_log_ts();
> +
> + mono = ktime_get_real_log_ts(&offset_real);
> +
> + if (printk_time == PRINTK_TIME_MONO)
> + return mono;
> +
> + return mono + offset_real;
> +}
>
> static size_t print_time(u64 ts, char *buf)
> {
> @@ -1643,7 +1750,7 @@ static bool cont_add(int facility, int level, enum log_flags flags, const char *
> cont.facility = facility;
> cont.level = level;
> cont.owner = current;
> - cont.ts_nsec = local_clock();
> + cont.ts_nsec = printk_get_ts();
> cont.flags = flags;
> }
>

So you really want to do all those branches every single time you
printk() ? I know printk() is somewhat of a slow path, but shees that's
ugly.

Why not have that setup function of yours set a function pointer?