Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp2313926rwp; Fri, 14 Jul 2023 04:25:53 -0700 (PDT) X-Google-Smtp-Source: APBJJlFd1e8CVdJBMfJJ5VOisTLksB0ODMvDrf8qy11OyuPYN16rzd5KiXPrbQo1mnxGBUIAs4M8 X-Received: by 2002:a2e:3315:0:b0:2b6:fa8d:ff91 with SMTP id d21-20020a2e3315000000b002b6fa8dff91mr3895550ljc.3.1689333952736; Fri, 14 Jul 2023 04:25:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689333952; cv=none; d=google.com; s=arc-20160816; b=vD/FEPf7mAUqEfYWWzDc7oh9nm41PG9YLdac/QTmgzjtXuDH5QLJdQ1DFSZFlxPBem /7OT2FR3qX70MC7AVXeYe/040GafyK8ifdxYjWjtrYyEykP5VDsVHFpJO5cUiv82nZpz q7+ZcZPgz/1fApQnci9e1Qb3OeWA5Rg+t1S+jvbfBjP3jyINmrfrTyDWlrTHTGmCTmwD ojZQ06IXad/CjprGrxhoclSdei+gJY0wV6t/aROCoU+8jZm7W6h6WAJPRdImwXQAyX68 TcIDTZl//54lZKaXyQTERQ6OmCOmG/+iwoalIvaW2a7xoQ2hTlTurWC080ylgpz3LxRR A9xA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-id:mime-version:references:message-id :in-reply-to:subject:cc:to:from:date:dkim-signature; bh=+gjEaUP0mci/eOqaZ7pxNWC+F59pJ6aHgjBjoIDqT6s=; fh=SgVVoH7D7YufymY5t2iJibY7D9GO4A1MH8d0xQ+8N7g=; b=vK+ObvkbKcj4/ni/t766dj4FCg77j6sS3pO92UsZPoqjWx6/t76CyadLllxMzzJOSz nVgh53oqLV4Wy1FVIMl573aj+4chXlVoILCqtDK7L/yxRRdmbKvrwbvEuUy4RmLyERgH NDyXmDwGSgB0D1la7z3C/ry9MYhDNJj85mmNY/qfATGSYZCq4DkF5hF3vZTjG/eEHXtU wscI1KGZbPPOICC7xcxvaZxSOfStQ68F4+vanwK6Or/vCY7XnkaYXU3lHeL200JNzbNR G2UFOvturWfSkRd2O55hB7kIkZbOy2Qg97+azmoyvLdkktM2UD7/QyiCSTt/fy/8hc0l 1s2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=h+IjKrcD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gt23-20020a170906f21700b00993a68a3afcsi8933079ejb.489.2023.07.14.04.25.29; Fri, 14 Jul 2023 04:25:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=h+IjKrcD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235723AbjGNKfa (ORCPT + 99 others); Fri, 14 Jul 2023 06:35:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232239AbjGNKf3 (ORCPT ); Fri, 14 Jul 2023 06:35:29 -0400 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 727F7A2; Fri, 14 Jul 2023 03:35:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689330928; x=1720866928; h=date:from:to:cc:subject:in-reply-to:message-id: references:mime-version:content-id; bh=ii4cvoqnoqZ+3sJH7xharBOhi935BhebVSR23hdE2OM=; b=h+IjKrcDFlwsLVaHyH626qdBADnjTdArmbaXG8fE1kXsZyznUcV1veu5 MmrTmMzhHnBEyhwFN+KoYYFf3tCty8D0dnHE/ZnBz3pdRplRaOhF7gkr7 YXBUV2dSmT8Hai0sJ/w5aYtuW53ZmhHI9f7kll0N2kqr+NhECyCWXnzKQ F2Gm9s5e4KeATUhsqBIyan8Z8my94TRItqNyWOeqFRjIwMdnc4EXBfL9N nlAcoZNvtKKdeFMV2xAWszwdnGsH7LDJPHYz3STyiRueGrFkKJCsBYDCM eKH1WnfDNKvdjKKCTsyKpYkHAeXJW8tSacTp6xCjVuEWbBx+NnG8kCTDD A==; X-IronPort-AV: E=McAfee;i="6600,9927,10770"; a="431615806" X-IronPort-AV: E=Sophos;i="6.01,205,1684825200"; d="scan'208";a="431615806" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Jul 2023 03:35:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10770"; a="812381155" X-IronPort-AV: E=Sophos;i="6.01,205,1684825200"; d="scan'208";a="812381155" Received: from rchauhax-mobl1.gar.corp.intel.com ([10.249.35.123]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Jul 2023 03:35:25 -0700 Date: Fri, 14 Jul 2023 13:35:22 +0300 (EEST) From: =?ISO-8859-15?Q?Ilpo_J=E4rvinen?= To: Reinette Chatre cc: linux-kselftest@vger.kernel.org, Shuah Khan , Shaopeng Tan , Fenghua Yu , Sai Praneeth Prakhya , Babu Moger , LKML Subject: Re: [PATCH v4 04/19] selftests/resctrl: Close perf value read fd on errors In-Reply-To: Message-ID: References: <20230713131932.133258-1-ilpo.jarvinen@linux.intel.com> <20230713131932.133258-5-ilpo.jarvinen@linux.intel.com> MIME-Version: 1.0 Content-Type: multipart/mixed; BOUNDARY="8323329-782494842-1689327854=:1695" Content-ID: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --8323329-782494842-1689327854=:1695 Content-Type: text/plain; CHARSET=ISO-8859-15 Content-Transfer-Encoding: 8BIT Content-ID: <42226133-5e22-b1fa-fb3-7cc2ac9b62@linux.intel.com> On Thu, 13 Jul 2023, Reinette Chatre wrote: > Hi Ilpo, > > On 7/13/2023 6:19 AM, Ilpo J?rvinen wrote: > > Perf event fd (fd_lm) is not closed on some error paths. > > > > Always close fd_lm in get_llc_perf() and add close into an error > > handling block in cat_val(). > > > > Fixes: 790bf585b0ee ("selftests/resctrl: Add Cache Allocation Technology (CAT) selftest") > > Signed-off-by: Ilpo J?rvinen > > --- > > tools/testing/selftests/resctrl/cache.c | 10 +++++----- > > 1 file changed, 5 insertions(+), 5 deletions(-) > > > > diff --git a/tools/testing/selftests/resctrl/cache.c b/tools/testing/selftests/resctrl/cache.c > > index 8a4fe8693be6..ced47b445d1e 100644 > > --- a/tools/testing/selftests/resctrl/cache.c > > +++ b/tools/testing/selftests/resctrl/cache.c > > @@ -87,21 +87,20 @@ static int reset_enable_llc_perf(pid_t pid, int cpu_no) > > static int get_llc_perf(unsigned long *llc_perf_miss) > > { > > __u64 total_misses; > > + int ret; > > > > /* Stop counters after one span to get miss rate */ > > > > ioctl(fd_lm, PERF_EVENT_IOC_DISABLE, 0); > > > > - if (read(fd_lm, &rf_cqm, sizeof(struct read_format)) == -1) { > > + ret = read(fd_lm, &rf_cqm, sizeof(struct read_format)); > > + close(fd_lm); > > + if (ret == -1) { > > perror("Could not get llc misses through perf"); > > - > > return -1; > > } > > > > total_misses = rf_cqm.values[0].value; > > - > > - close(fd_lm); > > - > > *llc_perf_miss = total_misses; > > > > return 0; > > @@ -253,6 +252,7 @@ int cat_val(struct resctrl_val_param *param) > > memflush, operation, resctrl_val)) { > > fprintf(stderr, "Error-running fill buffer\n"); > > ret = -1; > > + close(fd_lm); > > break; > > } > > > > Instead of fixing these existing patterns I think it would make the code > easier to understand and maintain if it is made symmetrical. > Having the perf event fd opened in one place but its close() > scattered elsewhere has the potential for confusion and making later > mistakes easy to miss. > > What if perf event fd is closed in a new "disable_llc_perf()" that > is matched with "reset_enable_llc_perf()" and called > from cat_val()? > > I think this raises another issue with the test trickery where > measure_cache_vals() has some assumptions about state based on the > test name. I very much agree on the principle here, and thus I already have created patches which will do a major cleanup on this area. The cleaned-up code has pe_fd local var to cat_val() and handles closing it in cat_val() with the usual patterns. However, the patch is currently resides post L3 CAT test rewrite. Backporting the cleanups/refactors into this series would require considerable effort due to how convoluted all those n-step cleanup patches and L3 CAT test rewrite are in this area. There's just very much to cleanup here and L3 rewrite will touch the same areas so its a net full of conflicts. Do you want me to spend the effort to backport them into this series (I expect will take some time)? I currently have these items pending besides this series (in order): - L3 CAT test rewrite and its preparatory patches - More cleanups (including the pe_fd cleanup) - New generalized test framework - L2 CAT test -- i. --8323329-782494842-1689327854=:1695--