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 97721C25B75 for ; Wed, 15 May 2024 12:47:55 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D148610E147; Wed, 15 May 2024 12:47:54 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="C26UTya6"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.13]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2403210E147 for ; Wed, 15 May 2024 12:47:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715777274; x=1747313274; h=message-id:date:mime-version:subject:to:references:from: in-reply-to:content-transfer-encoding; bh=7mWFjzQfUtolv9JFfV4TZHTFb0+Mg14GC8X79/Gas4U=; b=C26UTya67QqQvdnBFiKynianvUaFhzxECc8FyMn9F4I5xjTdN3UhAHkk ubqgwxKAfr0CC1Bk4qGRltuwUQEi+QziurAfnLiz7lA7QS8ss8gTaKkug HOVOhbBsfJEWAnLtpRp4ZXUwDeyZcEV2cclPIjlWXIqRikHP9Bv8t8SGt D3lKxwl55or7y6ecPYC6gjwgEaOk9SVwWJu2zcowOV19xtVuJ95qz7a4s jag1Tq9j7N0ETnkSBwTUY+p8Qndy5qjWGzy2/AS4m2xyWuGCLfykbt8He FQb5WXpRRlyAQrJlLr+A4XgTML3Ea8HWkVQCoE7N9EaxS5cEmPufJO7Sx A==; X-CSE-ConnectionGUID: unYVRzl3RlGWtQaQ5949ng== X-CSE-MsgGUID: 0Mvpj43/QJeSgd/LMQZPKA== X-IronPort-AV: E=McAfee;i="6600,9927,11073"; a="14770146" X-IronPort-AV: E=Sophos;i="6.08,161,1712646000"; d="scan'208";a="14770146" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2024 05:47:53 -0700 X-CSE-ConnectionGUID: 39mbfQXoQVGzmA/Qmj2Fiw== X-CSE-MsgGUID: gtKS4U9yQ76iS0pLnqZrUA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,161,1712646000"; d="scan'208";a="31067610" Received: from irvmail002.ir.intel.com ([10.43.11.120]) by fmviesa009.fm.intel.com with ESMTP; 15 May 2024 05:47:52 -0700 Received: from [10.245.119.62] (mwajdecz-MOBL.ger.corp.intel.com [10.245.119.62]) by irvmail002.ir.intel.com (Postfix) with ESMTP id C208A28169; Wed, 15 May 2024 13:47:50 +0100 (IST) Message-ID: <08831b00-7af1-4f06-b0fd-4ed4179fa528@intel.com> Date: Wed, 15 May 2024 14:47:49 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC] drm/print: Introduce drm_line_printer To: Jani Nikula , dri-devel@lists.freedesktop.org References: <20240514145631.2128-1-michal.wajdeczko@intel.com> <87seyjcsay.fsf@intel.com> Content-Language: en-US From: Michal Wajdeczko In-Reply-To: <87seyjcsay.fsf@intel.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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 15.05.2024 11:56, Jani Nikula wrote: > On Tue, 14 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. > > Interesting. Nothing another level of abstraction can't solve. ;) > > Except maybe it'll make adding function names to debug printers harder. but why? primary printer should work in the same way with or without this line printer > > No strong feelings either way about it, I'll let others chime in. forgot to mention that this new printer was aimed to simplify the manual and error prone work done as part of [1] but I'm afraid there is little traction to have any kind of generic solution at all, since it is considered as 'over engineering', even at the cost of trashing other printers that don't need extra robustness [1] https://patchwork.freedesktop.org/patch/593223/?series=133349&rev=1 > > A few comments inline. > > > BR, > Jani. > >> >> Signed-off-by: Michal Wajdeczko >> --- >> drivers/gpu/drm/drm_print.c | 9 +++++++++ >> include/drm/drm_print.h | 37 +++++++++++++++++++++++++++++++++++++ >> 2 files changed, 46 insertions(+) >> >> diff --git a/drivers/gpu/drm/drm_print.c b/drivers/gpu/drm/drm_print.c >> index cf2efb44722c..d6fb50d3407a 100644 >> --- a/drivers/gpu/drm/drm_print.c >> +++ b/drivers/gpu/drm/drm_print.c >> @@ -214,6 +214,15 @@ 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 line = (uintptr_t)(++p->prefix); > > Subtle. Might warrant adding a union in struct drm_printer for clarity. good idea > >> + struct drm_printer *dp = p->arg; >> + >> + drm_printf(dp, "%u: %pV", line, 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..58cc73c53853 100644 >> --- a/include/drm/drm_print.h >> +++ b/include/drm/drm_print.h >> @@ -186,6 +186,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 +358,42 @@ 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 >> + * @dp: the &struct drm_printer which actually generates 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. >> + * >> + * For example:: >> + * >> + * void crash_dump(struct drm_device *drm) >> + * { >> + * struct drm_printer dp = drm_err_printer(drm, "crash"); >> + * struct drm_printer lp = drm_line_printer(&dp); >> + * >> + * drm_printf(&lp, "foo"); >> + * drm_printf(&lp, "bar"); >> + * } >> + * >> + * Above code will print into the dmesg something like:: >> + * >> + * [ ] 0000:00:00.0: [drm] *ERROR* crash 1: foo >> + * [ ] 0000:00:00.0: [drm] *ERROR* crash 2: bar >> + * >> + * RETURNS: >> + * The &drm_printer object >> + */ >> +static inline struct drm_printer drm_line_printer(struct drm_printer *dp) > > Just p is customary for the drm_printer. "dp" gives me too much Display > Port vibes. ha, it was 'p' initially, but then it was still asymmetric compared to __drm_printfn_line where 'p' was actually referring to the line printer maybe best option would be to don't have local vars at all: drm_printf((struct drm_printer *)p->arg, "%u: %pV", p->line, vaf); > >> +{ >> + struct drm_printer lp = { >> + .printfn = __drm_printfn_line, >> + .arg = dp, >> + }; >> + return lp; >> +} >> + >> /* >> * struct device based logging >> * >