From patchwork Tue May 14 14:56:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Wajdeczko X-Patchwork-Id: 13664219 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 5BC0AC04FFE for ; Tue, 14 May 2024 14:56:58 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 99FEF10E188; Tue, 14 May 2024 14:56:57 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="kKqPd+ev"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9DB4810EA2D for ; Tue, 14 May 2024 14:56:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715698617; x=1747234617; h=from:to:subject:date:message-id:mime-version: content-transfer-encoding; bh=pkwc/6ov6/WLDAENkBPu2A1v4hPmdP1ccMJ1qjgjDGs=; b=kKqPd+evnvx2PZcibQkq7KGcAqzKhQbgPK5SlC5A6ewjT9DsfJPMZ87e x3esgGfLllspY4oeWu0UgKNuAus+lP8/fwTJrcWCv3QIS+2PZtq/pQpKY vWWPjwoPDHuYHbGCsVT2ivtxORnVIDTf1NIZxX5SPuFtC/PFKdL3nqOPt DzfVWfSy31lQIaxsrIfyR9bqxBKhpRGIG5wElWNYMrTxb4u9DNOZDXSfw akhJGcyX3wbQwMmjjmhD9Ud0QoKiEw39mldjEiido6oLy5g76GBn5CgL6 9OXuq7u7HaaxPbWSc7psw/RfJHtQdDFuJBORi+abgtA8db5D+xJfG02L0 A==; X-CSE-ConnectionGUID: OVXy6F1qQNutaMhTdZzvDQ== X-CSE-MsgGUID: 4Q1zN8NOS72vMBijYe3rnA== X-IronPort-AV: E=McAfee;i="6600,9927,11073"; a="15522587" X-IronPort-AV: E=Sophos;i="6.08,159,1712646000"; d="scan'208";a="15522587" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 May 2024 07:56:57 -0700 X-CSE-ConnectionGUID: eotxBPJ1QBGKNRyEbbm+Yg== X-CSE-MsgGUID: uvbQaT9xSiqZh3lI8BGlVw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,159,1712646000"; d="scan'208";a="35595030" Received: from mwajdecz-mobl.ger.corp.intel.com ([10.246.1.253]) by orviesa004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 May 2024 07:56:55 -0700 From: Michal Wajdeczko To: dri-devel@lists.freedesktop.org Subject: [RFC] drm/print: Introduce drm_line_printer Date: Tue, 14 May 2024 16:56:31 +0200 Message-Id: <20240514145631.2128-1-michal.wajdeczko@intel.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 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" 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 --- 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); + 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) +{ + struct drm_printer lp = { + .printfn = __drm_printfn_line, + .arg = dp, + }; + return lp; +} + /* * struct device based logging *