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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 33184E99063 for ; Fri, 10 Apr 2026 09:34:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date :Subject:CC:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Un6/5hQDB4O/MEu6q894jg317PijwDr803+Azh9z1Jg=; b=iSqMuDfJgBMa/yoGT8P/R8P8oN cNF62dC///m5V4U6DMzI3ZNty56Elc1BeSUBfKkQcRZoqKbqZl2rkB7LAQ9cSCeJWDacWP4AnYdiR 4y8mDdUyuz6XHrGnEjgMptjNprfF4XYqdh7fT4pRt0npAnZlAjswP/oPZkeU6fUVaX1X0KqAVcLsK PefDTROIeOUilQayEqAibtHcdY27f8au3f8uluUk/PemUsK6h82gk4qD5vHbG4gm/zBe1ctUAcMnq YR/K5eBv9OUncZ6pbEu+hFy9yFyEifZSOpvirtzcKHDyQUaDfB+tHm0LuhWR3w7BFZl5iwUNzvKdU l2obcTvg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1wB8Fe-0000000Bv5W-0fFx; Fri, 10 Apr 2026 09:34:10 +0000 Received: from canpmsgout02.his.huawei.com ([113.46.200.217]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1wB8FY-0000000Bv2x-1Mtw for linux-arm-kernel@lists.infradead.org; Fri, 10 Apr 2026 09:34:07 +0000 dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=Un6/5hQDB4O/MEu6q894jg317PijwDr803+Azh9z1Jg=; b=i55Kip2zCvSkxi/dx8mmEUh3mlwyX/Z9rqtPkjLLA+cHvkcvtVguhivXOMcR5QNy9eaYBR6HU bBEzuj6Mi9DYEnw+ol+ckj7uYIEX4BKlqm1+SdmEIzFsYGyILcEHzZ8ZwrRpq3LDZhIjof2/qIN zO/WKxNMtcmialiVAmfX5tA= Received: from mail.maildlp.com (unknown [172.19.163.104]) by canpmsgout02.his.huawei.com (SkyGuard) with ESMTPS id 4fsWfw3JNczcb16; Fri, 10 Apr 2026 17:27:36 +0800 (CST) Received: from kwepemk500005.china.huawei.com (unknown [7.202.194.90]) by mail.maildlp.com (Postfix) with ESMTPS id 6DA0C4048F; Fri, 10 Apr 2026 17:33:57 +0800 (CST) Received: from huawei.com (10.50.163.32) by kwepemk500005.china.huawei.com (7.202.194.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 10 Apr 2026 17:33:56 +0800 From: Yifan Wu To: , , , , , , , , , , , , , , , CC: , , , , , Subject: [PATCH v2 5/6] selftests/resctrl: Refactor reading from IMC using linked list Date: Fri, 10 Apr 2026 17:33:51 +0800 Message-ID: <20260410093352.3988125-6-wuyifan50@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20260410093352.3988125-1-wuyifan50@huawei.com> References: <20260410093352.3988125-1-wuyifan50@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.50.163.32] X-ClientProxiedBy: kwepems500001.china.huawei.com (7.221.188.70) To kwepemk500005.china.huawei.com (7.202.194.90) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260410_023404_733260_8B747495 X-CRM114-Status: GOOD ( 10.85 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Read the memory bandwidth from the IMC using linked list. Signed-off-by: Yifan Wu --- tools/testing/selftests/resctrl/resctrl_val.c | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/tools/testing/selftests/resctrl/resctrl_val.c b/tools/testing/selftests/resctrl/resctrl_val.c index ce5f96d5457c..65ae93205b38 100644 --- a/tools/testing/selftests/resctrl/resctrl_val.c +++ b/tools/testing/selftests/resctrl/resctrl_val.c @@ -57,15 +57,15 @@ static void read_mem_bw_initialize_perf_event_attr(struct imc_counter_config *im PERF_FORMAT_TOTAL_TIME_ENABLED | PERF_FORMAT_TOTAL_TIME_RUNNING; } -static void read_mem_bw_ioctl_perf_event_ioc_reset_enable(int i) +static void read_mem_bw_ioctl_perf_event_ioc_reset_enable(struct imc_counter_config *imc_counter) { - ioctl(imc_counters_config[i].fd, PERF_EVENT_IOC_RESET, 0); - ioctl(imc_counters_config[i].fd, PERF_EVENT_IOC_ENABLE, 0); + ioctl(imc_counter->fd, PERF_EVENT_IOC_RESET, 0); + ioctl(imc_counter->fd, PERF_EVENT_IOC_ENABLE, 0); } -static void read_mem_bw_ioctl_perf_event_ioc_disable(int i) +static void read_mem_bw_ioctl_perf_event_ioc_disable(struct imc_counter_config *imc_counter) { - ioctl(imc_counters_config[i].fd, PERF_EVENT_IOC_DISABLE, 0); + ioctl(imc_counter->fd, PERF_EVENT_IOC_DISABLE, 0); } /* @@ -361,16 +361,16 @@ static int perf_open_imc_read_mem_bw(int cpu_no) */ static void do_imc_read_mem_bw_test(void) { - int imc; + struct imc_counter_config *imc_counter; - for (imc = 0; imc < imcs; imc++) - read_mem_bw_ioctl_perf_event_ioc_reset_enable(imc); + list_for_each_entry(imc_counter, &imc_counters_list, entry) + read_mem_bw_ioctl_perf_event_ioc_reset_enable(imc_counter); sleep(1); /* Stop counters after a second to get results. */ - for (imc = 0; imc < imcs; imc++) - read_mem_bw_ioctl_perf_event_ioc_disable(imc); + list_for_each_entry(imc_counter, &imc_counters_list, entry) + read_mem_bw_ioctl_perf_event_ioc_disable(imc_counter); } /* @@ -385,17 +385,15 @@ static void do_imc_read_mem_bw_test(void) static int get_read_mem_bw_imc(float *bw_imc) { float reads = 0, of_mul_read = 1; - int imc; + struct imc_counter_config *r; /* * Log read event values from all iMC counters into * struct imc_counter_config. * Take overflow into consideration before calculating total bandwidth. */ - for (imc = 0; imc < imcs; imc++) { + list_for_each_entry(r, &imc_counters_list, entry) { struct membw_read_format measurement; - struct imc_counter_config *r = - &imc_counters_config[imc]; if (read(r->fd, &measurement, sizeof(measurement)) == -1) { ksft_perror("Couldn't get read bandwidth through iMC"); -- 2.43.0