Received: by 10.223.185.116 with SMTP id b49csp734714wrg; Wed, 21 Feb 2018 06:08:29 -0800 (PST) X-Google-Smtp-Source: AH8x226PIfWuqqDfryEWm1cgYlw0W96eaW3jTUNDjNF/cU/8ZFwgSHAxspNW8DOyKPI/hmGHHHC5 X-Received: by 2002:a17:902:2884:: with SMTP id f4-v6mr3240788plb.35.1519222109565; Wed, 21 Feb 2018 06:08:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519222109; cv=none; d=google.com; s=arc-20160816; b=u5ThUG6AeBuqLmqo4A/9Pl4ZZXfwc7zATHiGtg7Zw2jLdG15ZjamATxMEr70dg4lQk N9Dz2Fagh/Q7wctpPCjb6ebsTPwkA3cEHfdPo0sqFz77cPwtVdjyAQxrOQQO1giCGrwO qyrV/ngxxn4258uW8SgVYTg8VoSam8u8GpPebr/cUVvYVXdN9R0N/C9cLHyyJI97Vm0e N3xq4UF3iQv4x6bxQ95+YtNEe7Hufr9X7rfC9DLfioSjN5iiCl2NazbZWRw8buv8+Ba4 YjYZXLoZjesK4xMexxKK7xMCg0kmoVu3cDf/8lNZ8lZLjR0f1yFHaXxhnSwjgMwojwzn ONJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :organization:references:in-reply-to:date:cc:to:from:subject :message-id:arc-authentication-results; bh=fjFhQ0IE7jXBrS8+Qkcah+X1mZ6JvcYh7Ry4z0XMccY=; b=REZXH4PxnBBjJsK2TxBkP+QroK1k64RZANmKxnS3tN13VCHtqAx49CxQWsT4YBczW8 y/hkD7CTHeHss/pSSlgQFWCzm1IPEafiyio+YR9SUpcMk0JsgDOKzXDxDWZbMqM1rl32 mg2Mv+ImR+qv25FTxWF9rtouyPBzvZCh7Q5FaPtqu30+OWLrlQBRbM5e2jhVWPxePyrS rfrdGZXen9+JzmeXA9XfejbXFL8pKJa+nmeKXzAy0g6bO+xUaPgRR2y7OTaRTainMLDn kMEcCVFsc8t4YLK3MDAn07dzP2S97UtsRNpXjlN8Ocx82RFdE9DtTD+7icmVhcs23tk8 9Cyw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bb5-v6si88617plb.124.2018.02.21.06.08.10; Wed, 21 Feb 2018 06:08:29 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S937345AbeBUOCi (ORCPT + 99 others); Wed, 21 Feb 2018 09:02:38 -0500 Received: from mga18.intel.com ([134.134.136.126]:56847 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933186AbeBUOCf (ORCPT ); Wed, 21 Feb 2018 09:02:35 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Feb 2018 06:02:34 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,543,1511856000"; d="scan'208";a="36356081" Received: from smile.fi.intel.com (HELO smile) ([10.237.72.86]) by orsmga002.jf.intel.com with ESMTP; 21 Feb 2018 06:02:28 -0800 Message-ID: <1519221748.10722.34.camel@linux.intel.com> Subject: Re: [PATCH v2 01/21] lib/vsprintf: Print time and date in human readable format via %pt From: Andy Shevchenko To: Geert Uytterhoeven Cc: Rasmus Villemoes , Greg Kroah-Hartman , Andrew Morton , Linux Kernel Mailing List , Alessandro Zummo , Alexandre Belloni , linux-rtc@vger.kernel.org, Arnd Bergmann , Joe Perches , Mark Salyzyn , Bartlomiej Zolnierkiewicz , Dmitry Torokhov , Guan Xuetao , Ingo Molnar , Jason Wessel , Jonathan Corbet , Jonathan Hunter , Krzysztof Kozlowski , "Rafael J. Wysocki" , Thierry Reding Date: Wed, 21 Feb 2018 16:02:28 +0200 In-Reply-To: References: <20180220214400.66749-1-andriy.shevchenko@linux.intel.com> <20180220214400.66749-2-andriy.shevchenko@linux.intel.com> Organization: Intel Finland Oy Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.26.5-1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 2018-02-21 at 10:33 +0100, Geert Uytterhoeven wrote: > Hi Andy, > > On Tue, Feb 20, 2018 at 10:43 PM, Andy Shevchenko > wrote: > > There are users which print time and date represented by content of > > struct rtc_time in human readable format. > > > > Instead of open coding that each time introduce %ptR[dt][rv] > > specifier. > > Thanks for your patch! > > > Note, users have to select PRINTK_PEXT_TIMEDATE option in a Kconfig. > > Is it worthwhile making this an option? People were complaining before https://lists.01.org/pipermail/kbuild-all/2017-June/034950.html > > --- a/Documentation/core-api/printk-formats.rst > > +++ b/Documentation/core-api/printk-formats.rst > > @@ -412,6 +412,37 @@ Examples:: > > > > Passed by reference. > > > > +Time and date > > +------------- > > + > > +:: > > + > > + %pt[R] YYYY-mm-dd HH:MM:SS > > + %pt[R]d YYYY-mm-dd > > + %pt[R]t HH:MM:SS > > [R] suggests the "R" is optional? > But if it's missing, it prints the hex pointer value? Yes. > > + %pt[R][dt] > > What's the purpose of this? A place holder to extend. > > + > > + R for struct rtc_time > > + > > +Note, users have to select PRINTK_PEXT_TIMEDATE option in a > > Kconfig. > > + > > +struct rtc_time > > +~~~~~~~~~~~~~~~ > > + > > +:: > > + > > + %ptR[dt][rv] > > What's the purpose of this paragraph, compared to the previous one? This is first batch to make it working for struct rtc_time. We have several users (and I have some local patches WIP) to print time64_t / timespec64 which would use different letters and paragraphs to explain. I could remove it and return like it was in v1 (with the exception for new R letter added). TBH, I don't see much consensus among developers on this topic. I wouldn't like to send a new version until it would be a consensus. > > +static noinline_for_stack > > +char *date_str(char *buf, char *end, const struct rtc_time *tm, > > bool v, bool r) > > +{ > > + int year = tm->tm_year + (r ? 0 : 1900); > > + int mon = tm->tm_mon + (r ? 0 : 1); > > + > > + if (unlikely(v && (unsigned int)tm->tm_year > 200)) > > + buf = string(buf, end, "****", default_str_spec); > > + else > > + buf = number(buf, end, year, default_dec04_spec); > > + > > + if (buf < end) > > + *buf = '-'; > > Instead of all these checks to avoid overflowing the passed buffer, it > may be simpler to format everything in a fixed-size buffer on the > stack, > and copy whatever will fit in the target buffer at the end. I dropped that idea since the most heavier call is number(). We still need to do several of them one way or the other. So, I really don't see much benefit of doing your way. > > +static noinline_for_stack > > +char *rtc_str(char *buf, char *end, const struct rtc_time *tm, > > const char *fmt) > > +{ > > + bool have_t = true, have_d = true; > > + bool validate = false; > > + bool raw = false; > > + int count = 1; > > + bool found; > > + > > + switch (fmt[++count]) { > > + case 'd': > > + have_t = false; > > + break; > > + case 't': > > + have_d = false; > > + break; > > + } > > + > > + /* No %pt[dt] supplied */ > > + if (have_d && have_t) > > + --count; > > First increment count, then rollback. > What about: > > switch (fmt[count]) { > case 'd': > have_t = false; > count++; > break; > case 't': > have_d = false; > count++; > break; > } Or simple: default: --count; break; ? I really need to come up with the next pile for time64_t which I suppose will require rethinking of format parsing and printing functions here. -- Andy Shevchenko Intel Finland Oy