Received: by 2002:ab2:784b:0:b0:1fd:adc2:8405 with SMTP id m11csp430201lqp; Mon, 10 Jun 2024 08:19:10 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVeW4/CeOqXz3wqlAhYSEuAicnerVW4/0ossAgL51/ELBrS7Ls6ojzUve5vmtoVAE7A1J66WlyaMPIg+zEtjWICYL6ZeRrXZxG3UkPq/Q== X-Google-Smtp-Source: AGHT+IESUQwzNJhNHFzG3lBwOv55gccEUWaT4tHUJ0zf1tDyRR2czFUmEslzUOYamd2xsuKqUkwv X-Received: by 2002:a50:d7ca:0:b0:578:638e:3683 with SMTP id 4fb4d7f45d1cf-57c50861ae8mr7836818a12.5.1718032750327; Mon, 10 Jun 2024 08:19:10 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718032750; cv=pass; d=google.com; s=arc-20160816; b=wizNk8jBA7p8G1LCGtt8kQx++WBuFvhcc/lQoyaKCzcKWaWnb4nY/jQCQtuK+utj02 BNVD4X6cs+N/I0uHy9YBZB2Q/XiG45+wikDjfJVl6PZkwcKcobGv7IMvzIRDqKmGgFza 6tOxlGSPK2LEFJ9v7oinBNqUCAOs4H6gIl3uNmXKpVpp7+fBJRrDmTnRjG3Jnyg9nJUr m3uMfKaqX0lMXmUApPwxqz8eRsKLrIbfOkn/HxjJLmUvz9ec4X8cixtafGkl4ZQYjMH8 2rV5/E8s+F/OG+T69G8yOvgK4/7E4syEb3cGYwSBIOU6LIBPnyKY2cnazQAqzgUiHLxc 73zQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=XQpaVNRev/QmEbh82BVbBFy8/vzuwyQ1ybw8ScIIk1s=; fh=NBWFQeoQJCxKalVKeIRTZaO55uIqw1uKTUtRX+uowOE=; b=xvmIZ4zG3Gv01nM5kLot4gDeO0Rw01KJIKoZ29Ex5SmO6QHhYD1UUzlrtKPHHxFqib LLoqyx9f9UD33rY+9ra329Ky7HJMM0WMnmkiYRxXs5xRurXGQyBYqRb6wRsVU1QN9e3m fAGywxtUDqg4Epx9+gECcpUITiozn2G7W+Es9Eo/ICyrpf3rqCKeGHwmhyh+m7XjovpB VeTql55wVglhDxn+Vx/tt50GqktIeDnT0iBV0yZ6TyDhQtJaBJAbdQ4IEeyWofujsmdA FyW6s/Uk+3bRpu8EeT1xZQEjdzpsZHRxdZAIeGKat90r9GawcZCpZ2ZqgcWd8itn4EY6 jNLg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Ucs0IFwO; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-208451-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208451-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-57c732aaca7si2192250a12.454.2024.06.10.08.19.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 08:19:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-208451-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Ucs0IFwO; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-208451-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208451-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id D56991F24976 for ; Mon, 10 Jun 2024 15:19:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7FD27762D0; Mon, 10 Jun 2024 15:16:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Ucs0IFwO" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.13]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 06AEE13FD96; Mon, 10 Jun 2024 15:16:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.13 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718032591; cv=none; b=N96OgAQrkJdBu7LMaa1pHl70hQkqpfDYS0H//S/FVKuyjVrZj7sXNRk2oDuWyTjRoxA8KKdUSOu8uI480ClCb7KhuIjkRAdaI9RPmoMbzbaKEPh7DxkVqrLs9x5JPSBlWcJbbUFQFb0EHua+N0aP/Gw7Z6V215EGmuk5Ikw6CM4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718032591; c=relaxed/simple; bh=m5t8MxJ+I7n35w2ToGl4YgrZ29fG4mtxJkBP0WBT/wQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=AbPGqVxJKMVwG5AFR+XyQMOqJtM+jurm3ug5yANTlh2UtO3cnh3mSHSjd7wBGoKo5IpW0QLBlvoLI8Y6MCkEN//9GeZImkFxLqPWeoNQMVqiF7OtTD8jvJfItOIxztiRQ1LW7WzNAH6ctrbu/rskc7dtYhnyOE3B5Z6q3iigZNs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Ucs0IFwO; arc=none smtp.client-ip=198.175.65.13 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1718032590; x=1749568590; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=m5t8MxJ+I7n35w2ToGl4YgrZ29fG4mtxJkBP0WBT/wQ=; b=Ucs0IFwOr2XIbEXywym9NNf32AWxsVA5np+dfxKt+o9gpTkCvNgnXJLa ro4OSxrCpe3lDgviZOJ4+wIy0gop9YF839ejyN80f91knj5eI0icXM/1x BbQWRqxk3VF80nkUxgq8QkrZHRsAzvSaalY8QAXSrtmhUsIf1lnNWkxp+ zC3VTdA+d0FefbOIfxNbuK0X76nXjeUytF8pG0KECXnmeHPJSqQJC6siJ N83/352BeYba/JP9N+Xb7hvkRnhJLKH81mYMSF0+HLD47GmvzKRFlFxLm vcbHRa6hh3A7WdVhO4wsZwnqqqGPggfgugOKPhwNPveg3DBgdZ169PKGd A==; X-CSE-ConnectionGUID: tJQIcZ1ZTzSXj0Acg1VNNg== X-CSE-MsgGUID: t2ByfhZ6Rkyib1ZIQmnyoA== X-IronPort-AV: E=McAfee;i="6600,9927,11099"; a="25807797" X-IronPort-AV: E=Sophos;i="6.08,227,1712646000"; d="scan'208";a="25807797" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2024 08:16:30 -0700 X-CSE-ConnectionGUID: sCqeE4L0ScWRx1Layv2qwg== X-CSE-MsgGUID: FbioOfdQTNyTgXty8FV1Nw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,227,1712646000"; d="scan'208";a="39016959" Received: from ijarvine-desk1.ger.corp.intel.com (HELO localhost) ([10.245.247.194]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2024 08:16:26 -0700 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= To: linux-kselftest@vger.kernel.org, Shuah Khan , Reinette Chatre , Babu Moger , =?UTF-8?q?Maciej=20Wiecz=C3=B3r-Retman?= Cc: Fenghua Yu , linux-kernel@vger.kernel.org, Shuah Khan , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Subject: [PATCH v7 09/16] selftests/resctrl: Add ->measure() callback to resctrl_val_param Date: Mon, 10 Jun 2024 18:14:50 +0300 Message-Id: <20240610151457.7305-10-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240610151457.7305-1-ilpo.jarvinen@linux.intel.com> References: <20240610151457.7305-1-ilpo.jarvinen@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The measurement done in resctrl_val() varies depending on test type. The decision for how to measure is decided based on the string compare to test name which is quite inflexible. Add ->measure() callback into the struct resctrl_val_param to allow each test to provide necessary code as a function which simplifies what resctrl_val() has to do. Signed-off-by: Ilpo Järvinen Tested-by: Babu Moger Reviewed-by: Reinette Chatre --- v2: - spaces -> tabs --- tools/testing/selftests/resctrl/cmt_test.c | 8 ++++++++ tools/testing/selftests/resctrl/mba_test.c | 9 ++++++++- tools/testing/selftests/resctrl/mbm_test.c | 9 ++++++++- tools/testing/selftests/resctrl/resctrl.h | 6 ++++++ tools/testing/selftests/resctrl/resctrl_val.c | 18 +++++------------- 5 files changed, 35 insertions(+), 15 deletions(-) diff --git a/tools/testing/selftests/resctrl/cmt_test.c b/tools/testing/selftests/resctrl/cmt_test.c index a44e6fcd37b7..d8521386cd18 100644 --- a/tools/testing/selftests/resctrl/cmt_test.c +++ b/tools/testing/selftests/resctrl/cmt_test.c @@ -29,6 +29,13 @@ static int cmt_setup(const struct resctrl_test *test, return 0; } +static int cmt_measure(const struct user_params *uparams, + struct resctrl_val_param *param, pid_t bm_pid) +{ + sleep(1); + return measure_llc_resctrl(param->filename, bm_pid); +} + static int show_results_info(unsigned long sum_llc_val, int no_of_bits, unsigned long cache_span, unsigned long max_diff, unsigned long max_diff_percent, unsigned long num_of_runs, @@ -133,6 +140,7 @@ static int cmt_run_test(const struct resctrl_test *test, const struct user_param .mask = ~(long_mask << n) & long_mask, .num_of_runs = 0, .setup = cmt_setup, + .measure = cmt_measure, }; span = cache_portion_size(cache_total_size, param.mask, long_mask); diff --git a/tools/testing/selftests/resctrl/mba_test.c b/tools/testing/selftests/resctrl/mba_test.c index 5d6af9e8afed..de6e29faf214 100644 --- a/tools/testing/selftests/resctrl/mba_test.c +++ b/tools/testing/selftests/resctrl/mba_test.c @@ -51,6 +51,12 @@ static int mba_setup(const struct resctrl_test *test, return 0; } +static int mba_measure(const struct user_params *uparams, + struct resctrl_val_param *param, pid_t bm_pid) +{ + return measure_mem_bw(uparams, param, bm_pid); +} + static bool show_mba_info(unsigned long *bw_imc, unsigned long *bw_resc) { int allocation, runs; @@ -150,7 +156,8 @@ static int mba_run_test(const struct resctrl_test *test, const struct user_param .mongrp = "m1", .filename = RESULT_FILE_NAME, .bw_report = "reads", - .setup = mba_setup + .setup = mba_setup, + .measure = mba_measure, }; int ret; diff --git a/tools/testing/selftests/resctrl/mbm_test.c b/tools/testing/selftests/resctrl/mbm_test.c index 96d279b06377..59e26adf60bb 100644 --- a/tools/testing/selftests/resctrl/mbm_test.c +++ b/tools/testing/selftests/resctrl/mbm_test.c @@ -105,6 +105,12 @@ static int mbm_setup(const struct resctrl_test *test, return ret; } +static int mbm_measure(const struct user_params *uparams, + struct resctrl_val_param *param, pid_t bm_pid) +{ + return measure_mem_bw(uparams, param, bm_pid); +} + static void mbm_test_cleanup(void) { remove(RESULT_FILE_NAME); @@ -117,7 +123,8 @@ static int mbm_run_test(const struct resctrl_test *test, const struct user_param .ctrlgrp = "c1", .filename = RESULT_FILE_NAME, .bw_report = "reads", - .setup = mbm_setup + .setup = mbm_setup, + .measure = mbm_measure, }; int ret; diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h index e4b6dc672ecc..5dc3def70669 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -87,6 +87,7 @@ struct resctrl_test { * @filename: Name of file to which the o/p should be written * @bw_report: Bandwidth report type (reads vs writes) * @setup: Call back function to setup test environment + * @measure: Callback that performs the measurement (a single test) */ struct resctrl_val_param { char *resctrl_val; @@ -99,6 +100,9 @@ struct resctrl_val_param { int (*setup)(const struct resctrl_test *test, const struct user_params *uparams, struct resctrl_val_param *param); + int (*measure)(const struct user_params *uparams, + struct resctrl_val_param *param, + pid_t bm_pid); }; struct perf_event_read { @@ -145,6 +149,8 @@ unsigned char *alloc_buffer(size_t buf_size, int memflush); void mem_flush(unsigned char *buf, size_t buf_size); void fill_cache_read(unsigned char *buf, size_t buf_size, bool once); int run_fill_buf(size_t buf_size, int memflush, int op, bool once); +int measure_mem_bw(const struct user_params *uparams, + struct resctrl_val_param *param, pid_t bm_pid); int resctrl_val(const struct resctrl_test *test, const struct user_params *uparams, const char * const *benchmark_cmd, diff --git a/tools/testing/selftests/resctrl/resctrl_val.c b/tools/testing/selftests/resctrl/resctrl_val.c index 277c13b7a4c5..590fc74cb88f 100644 --- a/tools/testing/selftests/resctrl/resctrl_val.c +++ b/tools/testing/selftests/resctrl/resctrl_val.c @@ -606,8 +606,8 @@ static void initialize_llc_occu_resctrl(const char *ctrlgrp, const char *mongrp, * available. Compare the two values to validate resctrl value. It takes * 1 sec to measure the data. */ -static int measure_mem_bw(const struct user_params *uparams, - struct resctrl_val_param *param, pid_t bm_pid) +int measure_mem_bw(const struct user_params *uparams, + struct resctrl_val_param *param, pid_t bm_pid) { unsigned long bw_resc, bw_resc_start, bw_resc_end; FILE *mem_bw_fp; @@ -868,17 +868,9 @@ int resctrl_val(const struct resctrl_test *test, if (ret < 0) break; - if (!strncmp(resctrl_val, MBM_STR, sizeof(MBM_STR)) || - !strncmp(resctrl_val, MBA_STR, sizeof(MBA_STR))) { - ret = measure_mem_bw(uparams, param, bm_pid); - if (ret) - break; - } else if (!strncmp(resctrl_val, CMT_STR, sizeof(CMT_STR))) { - sleep(1); - ret = measure_llc_resctrl(param->filename, bm_pid); - if (ret) - break; - } + ret = param->measure(uparams, param, bm_pid); + if (ret) + break; } out: -- 2.39.2