From patchwork Wed Feb 5 02:10:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Vinay Belgaumkar X-Patchwork-Id: 13960425 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 2A791C02193 for ; Wed, 5 Feb 2025 02:16:59 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BF7B310E130; Wed, 5 Feb 2025 02:16:58 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="UOUmfCj8"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0C0A110E717; Wed, 5 Feb 2025 02:14:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1738721688; x=1770257688; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=CGashF46PTX2+1+VaJnYpwZd5GCa+5UjRi+3oh3H0Wc=; b=UOUmfCj8sut6dJ+thge5CPcGe1rNE/xyV76tu0gvK9jAzDKgluihuwRX hNMEYc5rFdr3Let0OZVFH0IvhtWquGFiJqTpfp8XKysiVTTlCmqxQN7L2 IzI3v+bZFBd3J0myjcatQInMEmJJSVTg68ftzkB0st2GKlE1n/Kg5sV0m tqZe4+97TTNLZ6qzJBdGt2i7KXSQHxY7hU6/1BHamaejd6m+1tP3vmtW6 sUlue0yVPIjJxNX/fOpzgLkhi7aTzDYbaeWacPB2YpapBTW6Jyyyjn2dU P/jUKpVHJ5huQK5gyDqvoC+FCCCVOhcC0HacbF+L7lQki1An0DRpEgTd9 w==; X-CSE-ConnectionGUID: reXSkrpsTu2sOKTxFKzWWQ== X-CSE-MsgGUID: +p1uxKLmRJijRwHEn5XByg== X-IronPort-AV: E=McAfee;i="6700,10204,11336"; a="39160214" X-IronPort-AV: E=Sophos;i="6.13,260,1732608000"; d="scan'208";a="39160214" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Feb 2025 18:14:48 -0800 X-CSE-ConnectionGUID: RJZQU+P2QaWjJ5upUWFNXw== X-CSE-MsgGUID: /RvKPqseSh+5x85tkoFwFQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,224,1728975600"; d="scan'208";a="111643381" Received: from vbelgaum-ubuntu.fm.intel.com ([10.1.39.141]) by orviesa008.jf.intel.com with ESMTP; 04 Feb 2025 18:14:47 -0800 From: Vinay Belgaumkar To: intel-gfx@lists.freedesktop.org, igt-dev@lists.freedesktop.org Cc: Vinay Belgaumkar , Lucas De Marchi , Riana Tauro , Rodrigo Vivi , Kamil Konieczny Subject: [PATCH i-g-t v8 3/3] tests/xe/pmu: Add pmu tests for gt-c6 Date: Tue, 4 Feb 2025 18:10:56 -0800 Message-Id: <20250205021056.1539902-4-vinay.belgaumkar@intel.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20250205021056.1539902-1-vinay.belgaumkar@intel.com> References: <20250205021056.1539902-1-vinay.belgaumkar@intel.com> MIME-Version: 1.0 X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Simple tests for validating the PMU implementation for GT C6 residencies. v2: Rename rc6-residency-* to gt-c6-residency and remove freq tests. v3: Keep just gt-c6 tests, add frequency tests later. v4: Review comments (Riana) v5: Review comments (Lucas) v6: Comments (Riana, Kamil) Cc: Lucas De Marchi Cc: Riana Tauro Cc: Rodrigo Vivi Cc: Kamil Konieczny Reviewed-by: Riana Tauro Signed-off-by: Vinay Belgaumkar --- tests/intel/xe_pmu.c | 142 +++++++++++++++++++++++++++++++++++++++++++ tests/meson.build | 1 + 2 files changed, 143 insertions(+) create mode 100644 tests/intel/xe_pmu.c diff --git a/tests/intel/xe_pmu.c b/tests/intel/xe_pmu.c new file mode 100644 index 000000000..62ed3a977 --- /dev/null +++ b/tests/intel/xe_pmu.c @@ -0,0 +1,142 @@ +// SPDX-License-Identifier: MIT +/* + * Copyright © 2025 Intel Corporation + */ + +/** + * TEST: Test Xe PMU(Performance Monitoring Unit) functionality + * Category: Metrics + * Functionality: Power/Perf + * Mega feature: Performance Monitoring Unit + * Sub-category: Telemetry + * Test category: Functional tests + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "igt.h" +#include "igt_device.h" +#include "igt_perf.h" +#include "igt_sysfs.h" + +#include "xe/xe_gt.h" + +#define SLEEP_DURATION 2 /* in seconds */ +const double tolerance = 0.1; + +static int open_pmu(int xe, uint64_t config) +{ + int fd; + + fd = perf_xe_open(xe, config); + igt_skip_on(fd < 0 && errno == ENODEV); + igt_assert(fd >= 0); + + return fd; +} + +static uint64_t __pmu_read_single(int fd, uint64_t *ts) +{ + uint64_t data[2]; + + igt_assert_eq(read(fd, data, sizeof(data)), sizeof(data)); + if (ts) + *ts = data[1]; + + return data[0]; +} + +static unsigned long read_idle_residency(int fd, int gt) +{ + unsigned long residency = 0; + int gt_fd; + + gt_fd = xe_sysfs_gt_open(fd, gt); + igt_assert(gt_fd >= 0); + igt_assert(igt_sysfs_scanf(gt_fd, "gtidle/idle_residency_ms", "%lu", &residency) == 1); + close(gt_fd); + + return residency; +} + +static uint64_t get_event_config(int xe, unsigned int gt, char *event) +{ + int ret; + char xe_device[100]; + uint64_t pmu_config; + u32 start, end; + + xe_perf_device(xe, xe_device, sizeof(xe_device)); + ret = perf_event_config(xe_device, event, &pmu_config); + igt_assert(ret >= 0); + ret = perf_event_format(xe_device, "gt", &start, &end); + igt_assert(ret >= 0); + pmu_config |= (uint64_t) gt << start; + + return pmu_config; +} + +/** + * SUBTEST: gt-c6-idle + * Description: Basic residency test to validate idle residency + * measured over a time interval is within the tolerance + */ +static void test_gt_c6_idle(int xe, unsigned int gt) +{ + int pmu_fd; + uint64_t pmu_config; + char event[100]; + uint64_t ts[2]; + unsigned long slept, start, end; + uint64_t val; + + /* Get the PMU config for the gt-c6 event */ + sprintf(event, "gt-c6-residency"); + pmu_config = get_event_config(xe, gt, event); + + pmu_fd = open_pmu(xe, pmu_config); + + igt_require_f(igt_wait(xe_gt_is_in_c6(xe, gt), 1000, 10), "GT %d should be in C6\n", gt); + + /* While idle check full RC6. */ + start = read_idle_residency(xe, gt); + val = __pmu_read_single(pmu_fd, &ts[0]); + slept = igt_measured_usleep(SLEEP_DURATION * USEC_PER_SEC) / 1000; + end = read_idle_residency(xe, gt); + val = __pmu_read_single(pmu_fd, &ts[1]) - val; + + igt_debug("gt%u: slept=%lu, perf=%"PRIu64"\n", + gt, slept, val); + + igt_debug("Start res: %lu, end_res: %lu", start, end); + + assert_within_epsilon(val, + (ts[1] - ts[0])/USEC_PER_SEC, + tolerance); + close(pmu_fd); +} + +igt_main +{ + int fd, gt; + + igt_fixture { + fd = drm_open_driver(DRIVER_XE); + igt_require(!IS_PONTEVECCHIO(xe_dev_id(fd))); + } + + igt_describe("Validate PMU gt-c6 residency counters when idle"); + igt_subtest("gt-c6-idle") + xe_for_each_gt(fd, gt) + test_gt_c6_idle(fd, gt); + + igt_fixture { + close(fd); + } +} diff --git a/tests/meson.build b/tests/meson.build index 33dffad31..95ddcae2a 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -310,6 +310,7 @@ intel_xe_progs = [ 'xe_peer2peer', 'xe_pm', 'xe_pm_residency', + 'xe_pmu', 'xe_prime_self_import', 'xe_query', 'xe_render_copy',