Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp2504802lqo; Mon, 20 May 2024 07:55:34 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWHazSkpFBTDtmOhSqyXhp1yAw5tWmki0tH6oboYg63LzSL/NIxRK53EcOU7OlphIvNHz0fku984S9uVUBONRBQx18+oDWcN8twcfdXFA== X-Google-Smtp-Source: AGHT+IGfsRNlQnPE1JzVYq1rwpHl/Kp4P8aNRe/MigEZIU1nmaxeMXTmfA+b6hoTBxnPPvFkbwoi X-Received: by 2002:a05:6a21:c98:b0:1a7:5e8f:8707 with SMTP id adf61e73a8af0-1afde10af9emr30706884637.26.1716216933860; Mon, 20 May 2024 07:55:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716216933; cv=pass; d=google.com; s=arc-20160816; b=BlD2YQYUKGaphNn3QbqYjXodWYv6EXrSQZTVLpltXJnk/EDLPCd0La1AvwelVZ05JA mh1j19+xQOkP+YUwduTK4G2h/RMotIgy4Qz1M+PPvEgeoxd6+JitR1GGAbRAvD8n8wdJ w2bUiSEm+jJAMkiNcGNi0qv8BcKxQ53JXIQ+7kML3fsLUDkBCEre+HaqYXKfGw4JMv9y z0TJbc6QrvL55t01oC2gDDctrpX29olZuo+tWYxTi3tpr0tPQNJug2ZPQYmbGro6mxFf QKiGXIbYTRZ7YTWJSasskHRB7h4z47yHgZ6fHV3vw3hazPpfXER6uuyPi6EB1hWZOKm8 XmmA== 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=E1FYPpALfO8je6plxzfaeWZjKJuK5fpOsuJW/vaR6nM=; fh=3qdKZaZnWy2Zq4/Kg/IJyvunFN5PAGmH2zs2MHj5FgQ=; b=nZNNTXYCagzeh9yt+s8qXJ87TrB8jNZExQOj48nfoTwP794KwnU7eLiKzaUZPatHax ENhbnjTC3tzDEarjRFRrob8QDFAyvyZCYSH0Lscsdf61x0P800msjeO1y5t3yLn8IxCu 1OVq2rNreyspTYFPwYxhE4aMK1PtYNRDlYTKBHivkbOq5zUe5By8il/uzTzfgHX84QbK onXVWeTT7TLoP90TqJrejXrjbEUsgRvR/yK5wPqoOB2j4wbexjsHT0Tp7z6wRZHSTuKC UU6WtxQ6Aizs522P2cm7OEF2Go2VHrAfJo9e/wKNaTlFfbjsALiQDWNAiIPvWgrwggzK HhDw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=frfTSl87; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-183740-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-183740-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-66af062b077si2373439a12.80.2024.05.20.07.55.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 May 2024 07:55:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-183740-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=frfTSl87; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-183740-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-183740-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 44D02284A10 for ; Mon, 20 May 2024 12:33:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 47A1C56766; Mon, 20 May 2024 12:31:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="frfTSl87" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (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 C414755E53; Mon, 20 May 2024 12:31:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716208315; cv=none; b=Yk1b94K/z8AIJRtqY8KoJnUCSOdNwt3ag43FuPkdJpYaeMWm+qhit0YbDsZGW1l9LJ0VbbK6zTSdPjw68rGm9rvMcsTKFUkyYiOj8ESegynGuUnyEbiP3Yz+Zr1S85WiJSIf83+sqJsb1Avm4KBdvBBIGNPpAtxXVcqVGGmMAes= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716208315; c=relaxed/simple; bh=GA4pv39MR635BUgP8l+N/zN9DfloTiIsJX023Tz0sW0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=cXhTVPb1IL/tg24RQb/3vF6h566siAqxKbAEwMwdtrNEimduF1YOEXiBaizNkzxjAjqr1Hjcy9BgYQ0ziGyXd4dJtAXUM/8oWQY1x5qxOGGkBzEgkU6KwqNBPHv1ZpFaJ5/CdVLvNmcaeDpJA5riRaCdJpMOEXJ9QupUbOiNEUA= 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=frfTSl87; arc=none smtp.client-ip=198.175.65.19 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=1716208314; x=1747744314; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=GA4pv39MR635BUgP8l+N/zN9DfloTiIsJX023Tz0sW0=; b=frfTSl87/SpkGfTu2Bkhlva1gFnMus7KQPhJFgZDc/maNOXSdXJ4Upwg jQk8S3nMq0GMYGKHTBThIbCJK/J6PZShzR95mxgB9i4dF9kKVPmlGDBpd fHEiMP7PiaeJoJQo0ktxrta36kgKLajBB/B1uELaXgsGHUGZQm+x1pIPs R6JyM1EYP41aZfoXuwSQyQdrWud0jlP8M/c20Q7/WUF1YALjmVf9qnRz2 Z8sJvGJAZa0erPNSWhq4uV+f5kApjX34Px2EakL8+/KN1S9DZsBu28uib UfO7+5PrhZrgKzfgpsmottyh0rNysJaZU8r1lDLMJzPsaYliCSxSinbeV Q==; X-CSE-ConnectionGUID: Iy0saNWjTj2xn3C1bnHHbA== X-CSE-MsgGUID: AFevvtBuT0ylKH/4UNK2hA== X-IronPort-AV: E=McAfee;i="6600,9927,11078"; a="12180458" X-IronPort-AV: E=Sophos;i="6.08,175,1712646000"; d="scan'208";a="12180458" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 May 2024 05:31:53 -0700 X-CSE-ConnectionGUID: iOOxxlL5ThCDI6lTEnBTWQ== X-CSE-MsgGUID: ceTDA6/NRmW1zT61V0jYTw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,175,1712646000"; d="scan'208";a="37474623" Received: from unknown (HELO localhost) ([10.245.247.114]) by orviesa004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 May 2024 05:31:50 -0700 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= To: linux-kselftest@vger.kernel.org, Reinette Chatre , Shuah Khan , Babu Moger , =?UTF-8?q?Maciej=20Wiecz=C3=B3r-Retman?= Cc: linux-kernel@vger.kernel.org, Fenghua Yu , Shuah Khan , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Subject: [PATCH v4 09/16] selftests/resctrl: Add ->measure() callback to resctrl_val_param Date: Mon, 20 May 2024 15:30:13 +0300 Message-Id: <20240520123020.18938-10-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240520123020.18938-1-ilpo.jarvinen@linux.intel.com> References: <20240520123020.18938-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 --- 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 a3cf3c5ed17f..76ae89e1aea3 100644 --- a/tools/testing/selftests/resctrl/resctrl_val.c +++ b/tools/testing/selftests/resctrl/resctrl_val.c @@ -607,8 +607,8 @@ static void initialize_llc_occu_resctrl(const char *ctrlgrp, const char *mongrp, * @param: parameters passed to resctrl_val() * @bm_pid: PID that runs the benchmark */ -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, *mem_bw_fp2; @@ -879,17 +879,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