From patchwork Wed Jul 12 14:50:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Kocialkowki X-Patchwork-Id: 9836921 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7379260363 for ; Wed, 12 Jul 2017 14:51:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 66C4D27D0E for ; Wed, 12 Jul 2017 14:51:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5BA4B28592; Wed, 12 Jul 2017 14:51:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id DC70727D0E for ; Wed, 12 Jul 2017 14:51:34 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 84B546E43F; Wed, 12 Jul 2017 14:51:34 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by gabe.freedesktop.org (Postfix) with ESMTPS id 30CBA6E43F for ; Wed, 12 Jul 2017 14:51:33 +0000 (UTC) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Jul 2017 07:51:15 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.40,350,1496127600"; d="scan'208"; a="1171628518" Received: from linux.intel.com ([10.54.29.200]) by fmsmga001.fm.intel.com with ESMTP; 12 Jul 2017 07:51:15 -0700 Received: from workstation.fi.intel.com (workstation.fi.intel.com [10.237.68.144]) by linux.intel.com (Postfix) with ESMTP id 3F34A5804B7; Wed, 12 Jul 2017 07:51:13 -0700 (PDT) From: Paul Kocialkowski To: intel-gfx@lists.freedesktop.org Date: Wed, 12 Jul 2017 17:50:29 +0300 Message-Id: <20170712145031.3531-6-paul.kocialkowski@linux.intel.com> X-Mailer: git-send-email 2.13.2 In-Reply-To: <20170712145031.3531-1-paul.kocialkowski@linux.intel.com> References: <20170705080435.26789-1-paul.kocialkowski@linux.intel.com> <20170712145031.3531-1-paul.kocialkowski@linux.intel.com> Cc: Lyude Subject: [Intel-gfx] [PATCH i-g-t v4 5/7] lib/igt_debugfs: Add extended helper to format crc to string X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP This introduces a igt_crc_to_string_extended helper that allows formatting a crc to a string with a given delimiter and size to print per crc word. Signed-off-by: Paul Kocialkowski --- lib/igt_debugfs.c | 28 ++++++++++++++++++++++++---- lib/igt_debugfs.h | 1 + 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/lib/igt_debugfs.c b/lib/igt_debugfs.c index 78c22e67..005f99b1 100644 --- a/lib/igt_debugfs.c +++ b/lib/igt_debugfs.c @@ -348,26 +348,46 @@ bool igt_check_crc_equal(const igt_crc_t *a, const igt_crc_t *b) } /** - * igt_crc_to_string: + * igt_crc_to_string_extended: * @crc: pipe CRC value to print + * @delimiter: The delimiter to use between crc words + * @crc_size: the number of bytes to print per crc word (either 4 or 2) * - * This formats @crc into a string buffer which is owned by igt_crc_to_string(). + * This formats @crc into a string buffer, depending on @delimiter and @crc_size + * which is owned by igt_crc_to_string_extended(). * The next call will override the buffer again, which makes this multithreading * unsafe. * * This should only ever be used for diagnostic debug output. */ -char *igt_crc_to_string(igt_crc_t *crc) +char *igt_crc_to_string_extended(igt_crc_t *crc, char delimiter, int crc_size) { int i; char buf[128] = { 0 }; + const char *format[2] = { "%08x%c", "%04x%c" }; for (i = 0; i < crc->n_words; i++) - sprintf(buf + strlen(buf), "%08x ", crc->crc[i]); + sprintf(buf + strlen(buf), format[crc_size == 2], crc->crc[i], + i == (crc->n_words - 1) ? '\0' : delimiter); return strdup(buf); } +/** + * igt_crc_to_string: + * @crc: pipe CRC value to print + * + * This formats @crc into a string buffer which is owned by igt_crc_to_string(). + * The next call will override the buffer again, which makes this multithreading + * unsafe. + * + * This should only ever be used for diagnostic debug output. + */ +char *igt_crc_to_string(igt_crc_t *crc) +{ + return igt_crc_to_string_extended(crc, ' ', 4); +} + #define MAX_CRC_ENTRIES 10 #define MAX_LINE_LEN (10 + 11 * MAX_CRC_ENTRIES + 1) diff --git a/lib/igt_debugfs.h b/lib/igt_debugfs.h index fe355919..f1a76406 100644 --- a/lib/igt_debugfs.h +++ b/lib/igt_debugfs.h @@ -115,6 +115,7 @@ enum intel_pipe_crc_source { void igt_assert_crc_equal(const igt_crc_t *a, const igt_crc_t *b); bool igt_check_crc_equal(const igt_crc_t *a, const igt_crc_t *b); +char *igt_crc_to_string_extended(igt_crc_t *crc, char delimiter, int crc_size); char *igt_crc_to_string(igt_crc_t *crc); void igt_require_pipe_crc(int fd);