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 97C0BC54E90 for ; Thu, 22 May 2025 15:50:02 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3354B10E189; Thu, 22 May 2025 15:50:02 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="cb58iml0"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.21]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3EDC610E28E for ; Thu, 22 May 2025 15:50:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1747929001; x=1779465001; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8iAZIGwyMFjPvMRkzn4CKiG98AmrKqmAkfIdocQXTWY=; b=cb58iml0nkuo/chzwSjjEMpd9aD9e+rRQ7by2FQ7iytem9JqD3YDima+ iivCa0RXTxM/pnlNy00/uOGjb7MuRuapmQUSi/V+O505HmFak6euov18T XQdF9OZCtO0NTQnGO2uV3KfcGHaHYywQt2znRj7SzbVhQrR+LU9zxl1p9 rXZZHXu2ch7WE0IwjZMRBfeBhJ+1TCGXMUfF1YVyGSVzIGW6IbHAtPgh4 NzVXD4AB+TqnSRtqht7HlfOUlmJvXk4Aqf+CNf9keAQyHyTzJ8vNEk2KR SGf07wiqK4lEk6DE9pqDPOgdPW3QL/1VnDEzbcaoc+y6UVbp3W7rpIFcO Q==; X-CSE-ConnectionGUID: /UVJ0lj7S+a3QSWmfFxS5Q== X-CSE-MsgGUID: duJbetbRR7iM5a5GUatKAQ== X-IronPort-AV: E=McAfee;i="6700,10204,11441"; a="49862146" X-IronPort-AV: E=Sophos;i="6.15,306,1739865600"; d="scan'208";a="49862146" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa113.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 May 2025 08:50:01 -0700 X-CSE-ConnectionGUID: 09Zv07tQROW7H2Ze8syyMA== X-CSE-MsgGUID: kWd8eJCtQx6jjJOGiZaqhQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,306,1739865600"; d="scan'208";a="141594136" Received: from psoham-nuc7i7bnh.iind.intel.com ([10.190.216.151]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 May 2025 08:49:57 -0700 From: Soham Purkait To: igt-dev@lists.freedesktop.org, riana.tauro@intel.com, vinay.belgaumkar@intel.com, kamil.konieczny@intel.com, krzysztof.karas@intel.com, zbigniew.kempczynski@intel.com Cc: anshuman.gupta@intel.com, lucas.demarchi@intel.com, rodrigo.vivi@intel.com, soham.purkait@intel.com, ashutosh.dixit@intel.com Subject: [PATCH i-g-t v11 3/5] tools/gputop/utils: Add gputop utility functions common to all drivers Date: Thu, 22 May 2025 21:14:45 +0530 Message-Id: <20250522154447.496407-4-soham.purkait@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250522154447.496407-1-soham.purkait@intel.com> References: <20250522154447.496407-1-soham.purkait@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: igt-dev@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development mailing list for IGT GPU Tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: igt-dev-bounces@lists.freedesktop.org Sender: "igt-dev" Implement utility functions in gputop for common operations and data handling across different drivers. v2 : Fix for refactoring GPUTOP into a vendor-agnostic tool. (Lucas) v3 : Headers in alphabetical order. (Kamil, Riana) v4 : Fix source file naming and remove driver specific codes. (Riana) v7 : Fix per-client engine width value with a macro replacing magic number. (Krzysztof) Signed-off-by: Soham Purkait Reviewed-by: Krzysztof Karas --- tools/gputop/utils.c | 51 +++++++++++++++++++++++++++++++++++ tools/gputop/utils.h | 64 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 tools/gputop/utils.c create mode 100644 tools/gputop/utils.h diff --git a/tools/gputop/utils.c b/tools/gputop/utils.c new file mode 100644 index 000000000..7f260dc05 --- /dev/null +++ b/tools/gputop/utils.c @@ -0,0 +1,51 @@ +// SPDX-License-Identifier: MIT +/* + * Copyright © 2025 Intel Corporation + */ +#include + +#include "utils.h" + +static const char * const bars[] = { " ", "▏", "▎", "▍", "▌", "▋", "▊", "▉", "█" }; + +void n_spaces(const unsigned int n) +{ + unsigned int i; + + for (i = 0; i < n; i++) + putchar(' '); +} + +void print_percentage_bar(double percent, int max_len) +{ + int bar_len, i, len = max_len - 1; + const int w = PERCLIENT_ENGINE_WIDTH; + + len -= printf("|%5.1f%% ", percent); + + /* no space left for bars, do what we can */ + if (len < 0) + len = 0; + + bar_len = ceil(w * percent * len / 100.0); + if (bar_len > w * len) + bar_len = w * len; + + for (i = bar_len; i >= w; i -= w) + printf("%s", bars[w]); + if (i) + printf("%s", bars[i]); + + len -= (bar_len + (w - 1)) / w; + n_spaces(len); + + putchar('|'); +} + +int print_engines_footer(int lines, int con_w, int con_h) +{ + if (lines++ < con_h) + printf("\n"); + + return lines; +} diff --git a/tools/gputop/utils.h b/tools/gputop/utils.h new file mode 100644 index 000000000..3c62f1c47 --- /dev/null +++ b/tools/gputop/utils.h @@ -0,0 +1,64 @@ +/* SPDX-License-Identifier: MIT */ +/* + * Copyright © 2025 Intel Corporation + */ + +#ifndef COMMON_GPUTOP_H +#define COMMON_GPUTOP_H + +#include +#include +#include +#include +#include + +#include "igt_device_scan.h" + +#define ANSI_HEADER "\033[7m" +#define ANSI_RESET "\033[0m" + +#define PERCLIENT_ENGINE_WIDTH 8 + +/** + * struct gputop_device + * + * @driver_present: It is set if at least a + * single device of the respective driver is + * found + * @len: Number of total device discovered + * of the respective driver + * @instances: pointer to the array of + * discovered instances of the devices + * of the same driver + */ +struct gputop_device { + bool driver_present; + int len; + void *instances; +}; + +/** + * struct device_operations - Structure to hold function + * pointers for device specific operations for each individual driver. + * @gputop_init: Function to initialize GPUTOP object + * @init_engines: Function to initialize engines for the respective driver. + * @pmu_init: Function to initialize the PMU (Performance Monitoring Unit). + * @pmu_sample: Function to sample PMU data. + * @print_engines: Function to print engine business. + * @clean_up: Function to release resources. + */ +struct device_operations { + void (*gputop_init)(void *ptr, + struct igt_device_card *card); + void *(*init_engines)(const void *obj); + int (*pmu_init)(const void *obj); + void (*pmu_sample)(const void *obj); + int (*print_engines)(const void *obj, int lines, int w, int h); + void (*clean_up)(void *obj, int len); +}; + +void print_percentage_bar(double percent, int max_len); +int print_engines_footer(int lines, int con_w, int con_h); +void n_spaces(const unsigned int n); + +#endif /* COMMON_GPUTOP_H */ -- 2.34.1