From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A8953C25B75 for ; Wed, 29 May 2024 09:01:08 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3770C10F894; Wed, 29 May 2024 09:01:07 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="kyQ2JUX6"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.16]) by gabe.freedesktop.org (Postfix) with ESMTPS id E00CB1135D7 for ; Wed, 29 May 2024 09:01:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1716973266; x=1748509266; h=from:to:cc:subject:in-reply-to:references:date: message-id:mime-version; bh=z7atjvqtxVBxrq/vLyb0CPY1PtWVpC3PSAsdBuPUt04=; b=kyQ2JUX6CLHnn112ytR0NSh0HQldEOspxjkRo8oNaenl6jTGgMU1cb9X HXEhcdoTRAVzcyD/065inDzw33xm/UFvbVVPXefGBxcTVULr3IBlIZv1K bs0vj2pexYQ2O9Q1rq5w/kb5xpIZKxjrkwlEDfoduvVqvVEHdgFbVBZuy QQrdpOeolwJgcR29QOFQ/kLRuYqrMkpPuco4VJrU5Vcqw62feAhHMdFKs rzUWfQ9OTflLoc9RXDb4+ZsBnwQaUz5e9tSC9cXYQTTBEWyG+8zKIjWE/ 1LUNqW7rs+QYsh+t3eRyAnxaCTA9h9Pw4TRED68D2u+VrrtlGaduVowyn Q==; X-CSE-ConnectionGUID: zDAvfbhYTQ6hgp8Iq9nPsQ== X-CSE-MsgGUID: T0mdH4uuR6+cvvFJ7ixZnw== X-IronPort-AV: E=McAfee;i="6600,9927,11085"; a="11746162" X-IronPort-AV: E=Sophos;i="6.08,197,1712646000"; d="scan'208";a="11746162" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by fmvoesa110.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 May 2024 02:01:04 -0700 X-CSE-ConnectionGUID: gYCFt5kjQwGzAJWy/eRMsQ== X-CSE-MsgGUID: af7w2ugDRV+Zyi/DBJliew== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,197,1712646000"; d="scan'208";a="35453266" Received: from ncintean-mobl1.ger.corp.intel.com (HELO localhost) ([10.245.246.86]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 May 2024 02:01:03 -0700 From: Jani Nikula To: Michal Wajdeczko , dri-devel@lists.freedesktop.org Cc: Michal Wajdeczko , John Harrison Subject: Re: [PATCH v2] drm/print: Introduce drm_line_printer In-Reply-To: <20240528130622.1152-1-michal.wajdeczko@intel.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo References: <20240528130622.1152-1-michal.wajdeczko@intel.com> Date: Wed, 29 May 2024 12:01:02 +0300 Message-ID: <871q5lkn5d.fsf@intel.com> MIME-Version: 1.0 Content-Type: text/plain X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" On Tue, 28 May 2024, Michal Wajdeczko wrote: > This drm printer wrapper can be used to increase the robustness of > the captured output generated by any other drm_printer to make sure > we didn't lost any intermediate lines of the output by adding line > numbers to each output line. Helpful for capturing some crash data. > > Signed-off-by: Michal Wajdeczko > Cc: Jani Nikula > Cc: John Harrison Reviewed-by: Jani Nikula > --- > v2: don't abuse prefix, use union instead (Jani) > don't use 'dp' as name, prefer 'p' (Jani) > add support for unique series identifier (John) > --- > drivers/gpu/drm/drm_print.c | 14 ++++++++ > include/drm/drm_print.h | 68 ++++++++++++++++++++++++++++++++++++- > 2 files changed, 81 insertions(+), 1 deletion(-) > > diff --git a/drivers/gpu/drm/drm_print.c b/drivers/gpu/drm/drm_print.c > index cf2efb44722c..be9cbebff5b3 100644 > --- a/drivers/gpu/drm/drm_print.c > +++ b/drivers/gpu/drm/drm_print.c > @@ -214,6 +214,20 @@ void __drm_printfn_err(struct drm_printer *p, struct va_format *vaf) > } > EXPORT_SYMBOL(__drm_printfn_err); > > +void __drm_printfn_line(struct drm_printer *p, struct va_format *vaf) > +{ > + unsigned int counter = ++p->line.counter; > + const char *prefix = p->prefix ?: ""; > + const char *pad = p->prefix ? " " : ""; > + > + if (p->line.series) > + drm_printf(p->arg, "%s%s%u.%u: %pV", > + prefix, pad, p->line.series, counter, vaf); > + else > + drm_printf(p->arg, "%s%s%u: %pV", prefix, pad, counter, vaf); > +} > +EXPORT_SYMBOL(__drm_printfn_line); > + > /** > * drm_puts - print a const string to a &drm_printer stream > * @p: the &drm printer > diff --git a/include/drm/drm_print.h b/include/drm/drm_print.h > index 089950ad8681..f4d9b98d7909 100644 > --- a/include/drm/drm_print.h > +++ b/include/drm/drm_print.h > @@ -176,7 +176,13 @@ struct drm_printer { > void (*puts)(struct drm_printer *p, const char *str); > void *arg; > const char *prefix; > - enum drm_debug_category category; > + union { > + enum drm_debug_category category; > + struct { > + unsigned short series; > + unsigned short counter; > + } line; > + }; > }; > > void __drm_printfn_coredump(struct drm_printer *p, struct va_format *vaf); > @@ -186,6 +192,7 @@ void __drm_puts_seq_file(struct drm_printer *p, const char *str); > void __drm_printfn_info(struct drm_printer *p, struct va_format *vaf); > void __drm_printfn_dbg(struct drm_printer *p, struct va_format *vaf); > void __drm_printfn_err(struct drm_printer *p, struct va_format *vaf); > +void __drm_printfn_line(struct drm_printer *p, struct va_format *vaf); > > __printf(2, 3) > void drm_printf(struct drm_printer *p, const char *f, ...); > @@ -357,6 +364,65 @@ static inline struct drm_printer drm_err_printer(struct drm_device *drm, > return p; > } > > +/** > + * drm_line_printer - construct a &drm_printer that prefixes outputs with line numbers > + * @p: the &struct drm_printer which actually generates the output > + * @prefix: optional output prefix, or NULL for no prefix > + * @series: optional unique series identifier, or 0 to omit identifier in the output > + * > + * This printer can be used to increase the robustness of the captured output > + * to make sure we didn't lost any intermediate lines of the output. Helpful > + * while capturing some crash data. > + * > + * Example 1:: > + * > + * void crash_dump(struct drm_device *drm) > + * { > + * static unsigned short id; > + * struct drm_printer p = drm_err_printer(drm, "crash"); > + * struct drm_printer lp = drm_line_printer(&p, "dump", ++id); > + * > + * drm_printf(&lp, "foo"); > + * drm_printf(&lp, "bar"); > + * } > + * > + * Above code will print into the dmesg something like:: > + * > + * [ ] 0000:00:00.0: [drm] *ERROR* crash dump 1.1: foo > + * [ ] 0000:00:00.0: [drm] *ERROR* crash dump 1.2: bar > + * > + * Example 2:: > + * > + * void line_dump(struct device *dev) > + * { > + * struct drm_printer p = drm_info_printer(dev); > + * struct drm_printer lp = drm_line_printer(&p, NULL, 0); > + * > + * drm_printf(&lp, "foo"); > + * drm_printf(&lp, "bar"); > + * } > + * > + * Above code will print:: > + * > + * [ ] 0000:00:00.0: [drm] 1: foo > + * [ ] 0000:00:00.0: [drm] 2: bar > + * > + * RETURNS: > + * The &drm_printer object > + */ > +static inline struct drm_printer drm_line_printer(struct drm_printer *p, > + const char *prefix, > + unsigned short series) > +{ > + struct drm_printer lp = { > + .printfn = __drm_printfn_line, > + .arg = p, > + .prefix = prefix, > + .line = { .series = series, }, > + }; > + return lp; > +} > + > /* > * struct device based logging > * -- Jani Nikula, Intel