From patchwork Thu Oct 6 09:38:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tadhg Kearney X-Patchwork-Id: 117446 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id DAFDFA00C2; Thu, 6 Oct 2022 11:39:03 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6065642BED; Thu, 6 Oct 2022 11:38:52 +0200 (CEST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by mails.dpdk.org (Postfix) with ESMTP id A597C42BDC for ; Thu, 6 Oct 2022 11:38:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1665049129; x=1696585129; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ptT72pqqBMrLVEDxn0kJCYbSXizRw+bM6W/MxZoQb0g=; b=CCQDyFK6YSDLY+R0DBksmHq1ZO3fkYP5nFeybD79ZIp0JuIQiLfdeo36 RF5r7fTCk4JAKskQoAbSklnZHg2xt6HSfRKi6pHyyn0eXi0AjjHhl31Oa 2/u0rM3HHFcIlsQ+es1WAwMJcZ+T3gh4C15xG9dh+bqtcQLyUGumDuOk8 Ub1GXus0B3BlJvlNxgLy7186u8TxNTWB9Zzn10f894cBDjqsvez0qDUrY +9HFMeafwssRG63+jwDowciTyp5roiCWYfw579Blk59bPHdmIKxnlm24R piUfLt4Mdnl+0Q6K5TUHz2/cpPbzC1nJRFgEMayVcWaU1Y86Ah1U1W70F Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10491"; a="329821572" X-IronPort-AV: E=Sophos;i="5.95,163,1661842800"; d="scan'208";a="329821572" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Oct 2022 02:38:49 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10491"; a="729072528" X-IronPort-AV: E=Sophos;i="5.95,163,1661842800"; d="scan'208";a="729072528" Received: from silpixa00401183.ir.intel.com ([10.55.129.143]) by fmsmga002.fm.intel.com with ESMTP; 06 Oct 2022 02:38:47 -0700 From: Tadhg Kearney To: dev@dpdk.org Cc: david.hunt@intel.com, anatoly.burakov@intel.com, reshma.pattan@intel.com, thomas@monjalon.net, Tadhg Kearney Subject: [PATCH v9 3/3] test/power: add unit tests for uncore API Date: Thu, 6 Oct 2022 09:38:03 +0000 Message-Id: <20221006093803.2076768-4-tadhg.kearney@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221006093803.2076768-1-tadhg.kearney@intel.com> References: <20221005162023.1923558-1-tadhg.kearney@intel.com> <20221006093803.2076768-1-tadhg.kearney@intel.com> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Add basic unit tests covering all nine uncore API's. Signed-off-by: Tadhg Kearney Reviewed-by: David Hunt Acked-by: David Hunt --- app/test/meson.build | 2 + app/test/test_power_intel_uncore.c | 301 +++++++++++++++++++++++++++++ 2 files changed, 303 insertions(+) create mode 100644 app/test/test_power_intel_uncore.c diff --git a/app/test/meson.build b/app/test/meson.build index d5cad72116..396b133959 100644 --- a/app/test/meson.build +++ b/app/test/meson.build @@ -101,6 +101,7 @@ test_sources = files( 'test_power.c', 'test_power_cpufreq.c', 'test_power_kvm_vm.c', + 'test_power_intel_uncore.c', 'test_prefetch.c', 'test_rand_perf.c', 'test_rawdev.c', @@ -241,6 +242,7 @@ fast_tests = [ ['power_cpufreq_autotest', false, true], ['power_autotest', true, true], ['power_kvm_vm_autotest', false, true], + ['power_intel_uncore_autotest', true, true], ['reorder_autotest', true, true], ['service_autotest', true, true], ['thash_autotest', true, true], diff --git a/app/test/test_power_intel_uncore.c b/app/test/test_power_intel_uncore.c new file mode 100644 index 0000000000..31163af84e --- /dev/null +++ b/app/test/test_power_intel_uncore.c @@ -0,0 +1,301 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2010-2022 Intel Corporation + */ + +#include "test.h" + +#ifndef RTE_LIB_POWER + +static int +test_power_intel_uncore(void) +{ + printf("Power management library not supported, skipping test\n"); + return TEST_SKIPPED; +} + +#else +#include +#include + +#define MAX_UNCORE_FREQS 32 + +#define VALID_PKG 0 +#define VALID_DIE 0 +#define INVALID_PKG (rte_power_uncore_get_num_pkgs() + 1) +#define INVALID_DIE (rte_power_uncore_get_num_dies(VALID_PKG) + 1) +#define VALID_INDEX 1 +#define INVALID_INDEX (MAX_UNCORE_FREQS + 1) + +static int check_power_uncore_init(void) +{ + int ret; + + /* Test initialisation of uncore configuration*/ + ret = rte_power_uncore_init(VALID_PKG, VALID_DIE); + if (ret < 0) { + printf("Cannot initialise uncore power management for pkg %u die %u, this " + "may occur if environment is not configured " + "correctly(APCI cpufreq) or operating in another valid " + "Power management environment\n", VALID_PKG, VALID_DIE); + return -1; + } + + /* Unsuccessful Test */ + ret = rte_power_uncore_init(INVALID_PKG, INVALID_DIE); + if (ret == 0) { + printf("Unexpectedly was able to initialise uncore power management " + "for pkg %u die %u\n", INVALID_PKG, INVALID_DIE); + return -1; + } + + return 0; +} + +static int +check_power_get_uncore_freq(void) +{ + int ret; + + /* Successfully get uncore freq */ + ret = rte_power_get_uncore_freq(VALID_PKG, VALID_DIE); + if (ret < 0) { + printf("Failed to get uncore frequency for pkg %u die %u\n", + VALID_PKG, VALID_DIE); + return -1; + } + + /* Unsuccessful Test */ + ret = rte_power_get_uncore_freq(INVALID_PKG, INVALID_DIE); + if (ret >= 0) { + printf("Unexpectedly got invalid uncore frequency for pkg %u die %u\n", + INVALID_PKG, INVALID_DIE); + return -1; + } + + return 0; +} + +static int +check_power_set_uncore_freq(void) +{ + int ret; + + /* Successfully set uncore freq */ + ret = rte_power_set_uncore_freq(VALID_PKG, VALID_DIE, VALID_INDEX); + if (ret < 0) { + printf("Failed to set uncore frequency for pkg %u die %u index %u\n", + VALID_PKG, VALID_DIE, VALID_INDEX); + return -1; + } + + /* Try to unsuccessfully set invalid uncore freq index */ + ret = rte_power_set_uncore_freq(VALID_PKG, VALID_DIE, INVALID_INDEX); + if (ret == 0) { + printf("Unexpectedly set invalid uncore index for pkg %u die %u index %u\n", + VALID_PKG, VALID_DIE, INVALID_INDEX); + return -1; + } + + /* Unsuccessful Test */ + ret = rte_power_set_uncore_freq(INVALID_PKG, INVALID_DIE, VALID_INDEX); + if (ret == 0) { + printf("Unexpectedly set invalid uncore frequency for pkg %u die %u index %u\n", + INVALID_PKG, INVALID_DIE, VALID_INDEX); + return -1; + } + + return 0; +} + +static int +check_power_uncore_freq_max(void) +{ + int ret; + + /* Successfully get max uncore freq */ + ret = rte_power_uncore_freq_max(VALID_PKG, VALID_DIE); + if (ret < 0) { + printf("Failed to set max uncore frequency for pkg %u die %u\n", + VALID_PKG, VALID_DIE); + return -1; + } + + /* Unsuccessful Test */ + ret = rte_power_uncore_freq_max(INVALID_PKG, INVALID_DIE); + if (ret == 0) { + printf("Unexpectedly set invalid max uncore frequency for pkg %u die %u\n", + INVALID_PKG, INVALID_DIE); + return -1; + } + + return 0; +} + +static int +check_power_uncore_freq_min(void) +{ + int ret; + + /* Successfully get min uncore freq */ + ret = rte_power_uncore_freq_min(VALID_PKG, VALID_DIE); + if (ret < 0) { + printf("Failed to set min uncore frequency for pkg %u die %u\n", + VALID_PKG, VALID_DIE); + return -1; + } + + /* Unsuccessful Test */ + ret = rte_power_uncore_freq_min(INVALID_PKG, INVALID_DIE); + if (ret == 0) { + printf("Unexpectedly set invalid min uncore frequency for pkg %u die %u\n", + INVALID_PKG, INVALID_DIE); + return -1; + } + + return 0; +} + +static int +check_power_uncore_get_num_freqs(void) +{ + int ret; + + /* Successfully get number of uncore freq */ + ret = rte_power_uncore_get_num_freqs(VALID_PKG, VALID_DIE); + if (ret < 0) { + printf("Failed to get number of uncore frequencies for pkg %u die %u\n", + VALID_PKG, VALID_DIE); + return -1; + } + + /* Unsuccessful Test */ + ret = rte_power_uncore_get_num_freqs(INVALID_PKG, INVALID_DIE); + if (ret >= 0) { + printf("Unexpectedly got number of invalid frequencies for pkg %u die %u\n", + INVALID_PKG, INVALID_DIE); + return -1; + } + + return 0; +} + +static int +check_power_uncore_get_num_pkgs(void) +{ + int ret; + + /* Successfully get number of uncore pkgs */ + ret = rte_power_uncore_get_num_pkgs(); + if (ret == 0) { + printf("Failed to get number of uncore pkgs\n"); + return -1; + } + + return 0; +} + +static int +check_power_uncore_get_num_dies(void) +{ + int ret; + + /* Successfully get number of uncore dies */ + ret = rte_power_uncore_get_num_dies(VALID_PKG); + if (ret == 0) { + printf("Failed to get number of uncore dies for pkg %u\n", + VALID_PKG); + return -1; + } + + /* Unsuccessful test */ + ret = rte_power_uncore_get_num_dies(INVALID_PKG); + if (ret > 0) { + printf("Unexpectedly got number of invalid dies for pkg %u\n", + INVALID_PKG); + return -1; + } + + return 0; +} + +static int +check_power_uncore_exit(void) +{ + int ret; + + /* Successfully exit uncore power management */ + ret = rte_power_uncore_exit(VALID_PKG, VALID_DIE); + if (ret < 0) { + printf("Failed to exit uncore power management for pkg %u die %u\n", + VALID_PKG, VALID_DIE); + } + + /* Unsuccessful Test */ + ret = rte_power_uncore_exit(INVALID_PKG, INVALID_DIE); + if (ret == 0) { + printf("Unexpectedly was able to exit uncore power management for pkg %u die %u\n", + INVALID_PKG, INVALID_DIE); + return -1; + } + + return 0; +} + +static int +test_power_intel_uncore(void) +{ + int ret; + + ret = rte_power_uncore_get_num_pkgs(); + if (ret == 0) { + printf("Uncore frequency management not supported/enabled on this kernel. " + "Please enable CONFIG_INTEL_UNCORE_FREQ_CONTROL if on x86 with linux kernel" + " >= 5.6\n"); + return TEST_SKIPPED; + } + + ret = check_power_uncore_init(); + if (ret < 0) + goto fail_all; + + ret = check_power_get_uncore_freq(); + if (ret < 0) + goto fail_all; + + ret = check_power_set_uncore_freq(); + if (ret < 0) + goto fail_all; + + ret = check_power_uncore_freq_max(); + if (ret < 0) + goto fail_all; + + ret = check_power_uncore_freq_min(); + if (ret < 0) + goto fail_all; + + ret = check_power_uncore_get_num_freqs(); + if (ret < 0) + goto fail_all; + + ret = check_power_uncore_get_num_pkgs(); + if (ret < 0) + goto fail_all; + + ret = check_power_uncore_get_num_dies(); + if (ret < 0) + goto fail_all; + + ret = check_power_uncore_exit(); + if (ret < 0) + return -1; + + return 0; + +fail_all: + rte_power_uncore_exit(VALID_PKG, VALID_DIE); + return -1; +} +#endif + +REGISTER_TEST_COMMAND(power_intel_uncore_autotest, test_power_intel_uncore);