Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp2142284rdb; Mon, 20 Nov 2023 03:19:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IEl+GRgQw8ilB+Pk947rIy+hIfceSZvystTOGKLeht1JrVsmK6X8n6z74eXqdL0mMFlqbwj X-Received: by 2002:a05:6870:71d3:b0:1ea:cdcb:5a2b with SMTP id p19-20020a05687071d300b001eacdcb5a2bmr9554851oag.54.1700479146867; Mon, 20 Nov 2023 03:19:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700479146; cv=none; d=google.com; s=arc-20160816; b=Pk+MYF5GVt3pHomPixd7aC4JO1MpFX9ohRM+axmxzyKGjGGn8MiUclkUBs9IcK6EqZ 8+YZXfQLZcijIYq4etnHbayno3Md1FEtB5h8O1CCVaoM5d4hYo0v2TyV+sX2WzMBHFFx PbnZPeifuMXN6pGp7cZ0nw9YWZ0YAF05qCI3tNKSfB5ygVwH1A/KI9zhqsMGPHkkGFtW KAiwbcClka5CA4o98C9sQFL4w2Xrgps44MhdveQnIp4fUCcsoWqKSxBlL28rdV1OKiE1 0S31Ot+n6k1tJpGaqwT9JUJhdM2k0MJuq7PbOXvIcpQCD5yKyiGXTiTvLQFnh0BW2xi/ jn7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=iAuAELjLrZG8m7iomDqGXGUCnPiWhsAjb5IlpXlCgh4=; fh=gPQ6jqLSfsDb5bE3yrtO+AlT5R4d75RXkjC5xckz7Dk=; b=TfbpMZCI8EVc9FPcHV03Kq2Gw+GH8qlMVPdw/vV8kt98tQjLMwZh0xRJBlH/AIqo8j GQ6joBfduZKS5KmagzCHMs1F+OSVDx4rf8WfIEuihd438mxXWY0+57fhx2B1xkQVKapb g+65INcnXQT/a/nFbg92s0eorKekWa31nGylSI1txwIQuaKPjSQqOWYap52avn5FLfAk PVJqgDVxL+hwonfhSjmpnIdo5tEEZJwLKc4btuX3yXgDxJfbqsQDc2MOmmtAi7CwORyE 3zFZ7tiq8LSIomyRWk/+VfpaBp0nimKdpO4stw6BY+wxcHQe4RvzgoVgbbeyH//DJojJ G+0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=kmeEtYJI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id d29-20020a631d5d000000b0056952b496efsi7870233pgm.366.2023.11.20.03.19.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 03:19:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=kmeEtYJI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 8D9A58098487; Mon, 20 Nov 2023 03:16:07 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232775AbjKTLP5 (ORCPT + 99 others); Mon, 20 Nov 2023 06:15:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233013AbjKTLPd (ORCPT ); Mon, 20 Nov 2023 06:15:33 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE4CB10E2; Mon, 20 Nov 2023 03:15:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700478928; x=1732014928; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=nsN9ZlaOmiphawewtImMFNwBEk6HXc44WNYdCCMUuoQ=; b=kmeEtYJIylD2hEbDiNKxEF5ikHWtT9KPKHE+jyM/OlH0VvgXlFKhDFce noOAou83/NeFodJZeZBArEfAYQpKPEBdCgCnKDV3Kcew1Y3XvOSnXxsho OBV6jSmJxT+u7JBRMj2j0fuBNBrW9uQWF0FOCzkL+pR/t03jNVIQWitwx FXtsvWH87twqv2opVWgChud3FY4cGLlJB1SfoykVLzvJXFHkDBCCaiSXp dDhre/HU2Iklt28IvjXR0mXJ2JKt8ueGZW8G8We8cRvOp5rP8hsXKddI6 DmNZd0h/Lr9amx5TLhqlbqL4pXOqlJR9rvjq7iQAAzNTCc4qgS7gx7JOq Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10899"; a="13151915" X-IronPort-AV: E=Sophos;i="6.04,213,1695711600"; d="scan'208";a="13151915" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Nov 2023 03:15:27 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10899"; a="832238220" X-IronPort-AV: E=Sophos;i="6.04,213,1695711600"; d="scan'208";a="832238220" Received: from sc9itsct4906.amr.corp.intel.com (HELO localhost) ([10.249.46.107]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Nov 2023 03:15:21 -0800 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= To: linux-kselftest@vger.kernel.org, Reinette Chatre , Shuah Khan , Shaopeng Tan , =?UTF-8?q?Maciej=20Wiecz=C3=B3r-Retman?= , Fenghua Yu Cc: linux-kernel@vger.kernel.org, =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Subject: [PATCH v2 11/26] selftests/resctrl: Remove nested calls in perf event handling Date: Mon, 20 Nov 2023 13:13:25 +0200 Message-Id: <20231120111340.7805-12-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20231120111340.7805-1-ilpo.jarvinen@linux.intel.com> References: <20231120111340.7805-1-ilpo.jarvinen@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 20 Nov 2023 03:16:07 -0800 (PST) Perf event handling has functions that are the sole caller of another perf event handling related function: - reset_enable_llc_perf() calls perf_event_open_llc_miss() - perf_event_measure() calls get_llc_perf() Remove the extra layer of calls to make the code easier to follow by moving the code into the calling function. Signed-off-by: Ilpo Järvinen --- tools/testing/selftests/resctrl/cache.c | 65 ++++++------------------- 1 file changed, 14 insertions(+), 51 deletions(-) diff --git a/tools/testing/selftests/resctrl/cache.c b/tools/testing/selftests/resctrl/cache.c index 6a754ea376c9..aea4f54d32bd 100644 --- a/tools/testing/selftests/resctrl/cache.c +++ b/tools/testing/selftests/resctrl/cache.c @@ -29,24 +29,13 @@ static void initialize_perf_event_attr(void) pea_llc_miss.disabled = 1; } +/* Start counters to log values */ static void ioctl_perf_event_ioc_reset_enable(void) { ioctl(fd_lm, PERF_EVENT_IOC_RESET, 0); ioctl(fd_lm, PERF_EVENT_IOC_ENABLE, 0); } -static int perf_event_open_llc_miss(pid_t pid, int cpu_no) -{ - fd_lm = perf_event_open(&pea_llc_miss, pid, cpu_no, -1, - PERF_FLAG_FD_CLOEXEC); - if (fd_lm == -1) { - perror("Error opening leader"); - return -1; - } - - return 0; -} - static void initialize_llc_perf(void) { memset(&pea_llc_miss, 0, sizeof(struct perf_event_attr)); @@ -62,42 +51,13 @@ static void initialize_llc_perf(void) static int reset_enable_llc_perf(pid_t pid, int cpu_no) { - int ret = 0; - - ret = perf_event_open_llc_miss(pid, cpu_no); - if (ret < 0) - return ret; - - /* Start counters to log values */ - ioctl_perf_event_ioc_reset_enable(); - - return 0; -} - -/* - * get_llc_perf: llc cache miss through perf events - * @llc_perf_miss: LLC miss counter that is filled on success - * - * Perf events like HW_CACHE_MISSES could be used to validate number of - * cache lines allocated. - * - * Return: =0 on success. <0 on failure. - */ -static int get_llc_perf(__u64 *llc_perf_miss) -{ - int ret; - - /* Stop counters after one span to get miss rate */ - - ioctl(fd_lm, PERF_EVENT_IOC_DISABLE, 0); - - ret = read(fd_lm, &rf_cqm, sizeof(struct read_format)); - if (ret == -1) { - perror("Could not get llc misses through perf"); + fd_lm = perf_event_open(&pea_llc_miss, pid, cpu_no, -1, PERF_FLAG_FD_CLOEXEC); + if (fd_lm == -1) { + perror("Error opening leader"); return -1; } - *llc_perf_miss = rf_cqm.values[0].value; + ioctl_perf_event_ioc_reset_enable(); return 0; } @@ -178,15 +138,18 @@ static int print_results_cache(const char *filename, int bm_pid, __u64 llc_value */ static int perf_event_measure(const char *filename, int bm_pid) { - __u64 llc_perf_miss = 0; int ret; - ret = get_llc_perf(&llc_perf_miss); - if (ret < 0) - return ret; + /* Stop counters after one span to get miss rate */ + ioctl(fd_lm, PERF_EVENT_IOC_DISABLE, 0); - ret = print_results_cache(filename, bm_pid, llc_perf_miss); - return ret; + ret = read(fd_lm, &rf_cqm, sizeof(struct read_format)); + if (ret == -1) { + perror("Could not get perf value"); + return -1; + } + + return print_results_cache(filename, bm_pid, rf_cqm.values[0].value); } /* -- 2.30.2