From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751983AbdHHAS4 (ORCPT ); Mon, 7 Aug 2017 20:18:56 -0400 Received: from mail-pg0-f67.google.com ([74.125.83.67]:35867 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751891AbdHHASy (ORCPT ); Mon, 7 Aug 2017 20:18:54 -0400 Date: Tue, 8 Aug 2017 09:19:08 +0900 From: Sergey Senozhatsky To: Prarit Bhargava Cc: linux-kernel@vger.kernel.org, Mark Salyzyn , Jonathan Corbet , Petr Mladek , Sergey Senozhatsky , Steven Rostedt , John Stultz , Thomas Gleixner , Stephen Boyd , Andrew Morton , Greg Kroah-Hartman , "Paul E. McKenney" , Christoffer Dall , Deepa Dinamani , Ingo Molnar , Joel Fernandes , Kees Cook , Peter Zijlstra , Geert Uytterhoeven , "Luis R. Rodriguez" , Nicholas Piggin , "Jason A. Donenfeld" , Olof Johansson , Josh Poimboeuf , linux-doc@vger.kernel.org Subject: Re: [PATCH v4] printk: Add monotonic, boottime, and realtime timestamps Message-ID: <20170808001908.GA7765@jagdpanzerIV.localdomain> References: <1502121162-27981-1-git-send-email-prarit@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1502121162-27981-1-git-send-email-prarit@redhat.com> User-Agent: Mutt/1.8.3 (2017-05-23) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On (08/07/17 11:52), Prarit Bhargava wrote: [..] > +/** > + * enum printk_time_type - Timestamp types for printk() messages. > + * @PRINTK_TIME_DISABLE: No time stamp. > + * @PRINTK_TIME_LOCAL: Local hardware clock timestamp. > + * @PRINTK_TIME_BOOT: Boottime clock timestamp. > + * @PRINTK_TIME_MONO: Monotonic clock timestamp. > + * @PRINTK_TIME_REAL: Realtime clock timestamp. On 32-bit > + * systems selecting the real clock printk timestamp may lead to unlikely > + * situations where a timestamp is wrong because the real time offset is read > + * without the protection of a sequence lock in the call to ktime_get_log_ts() > + * in printk_get_ts() below. > + */ > +enum printk_time_type { > + PRINTK_TIME_DISABLE = 0, > + PRINTK_TIME_LOCAL = 1, > + PRINTK_TIME_BOOT = 2, > + PRINTK_TIME_MONO = 3, > + PRINTK_TIME_REAL = 4, > +}; may be call the entire thing 'timestamp surces' or something? [..] > + if (strlen(param) == 1) { > + /* Preserve legacy boolean settings */ > + if (!strcmp("0", param) || !strcmp("n", param) || > + !strcmp("N", param)) > + _printk_time = PRINTK_TIME_DISABLE; > + if (!strcmp("1", param) || !strcmp("y", param) || > + !strcmp("Y", param)) > + _printk_time = PRINTK_TIME_LOCAL; > + } > + if (_printk_time == -1) { > + for (stamp = 0; stamp <= 4; stamp++) { > + if (!strncmp(printk_time_str[stamp], param, > + strlen(param))) { > + _printk_time = stamp; > + break; > + } > + } > + } you can use match_string() here. > + if (_printk_time == -1) { > + pr_warn("printk: invalid timestamp value %s\n", param); > + return -EINVAL; > + } `invalid timestamp value' is confusing. > + } else if ((printk_time_setting != _printk_time) && > + (_printk_time != 0)) { > + pr_warn("printk: timestamp can only be set to 0(disabled) or %s\n", > + printk_time_str[printk_time_setting]); ditto. > + return -EINVAL; > + } > + > + printk_time = _printk_time; > + pr_info("printk: timestamp set to %s\n", printk_time_str[printk_time]); ditto. [..] > +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; > +} this looks hard... > +static int printk_time; > +static int printk_time_setting; how about s/printk_time_setting/printk_time_source/? or something similar? -ss