Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp2142273rdb; Mon, 20 Nov 2023 03:19:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IG0qZ/hi/zUU3deU8dFS5GyAQ7R2nlp7iGSKSvGNFuKJvUvHM4PJVMQMj1oBz9JDgBf6qGE X-Received: by 2002:a05:6a20:8e2a:b0:187:41d6:3687 with SMTP id y42-20020a056a208e2a00b0018741d63687mr9669681pzj.11.1700479145524; Mon, 20 Nov 2023 03:19:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700479145; cv=none; d=google.com; s=arc-20160816; b=cecFX74dx1aAX0HcxOp25iiPeozgW+GaPAZI4Ahe4czniDMKRzSlnoKYwTnVlzpMfi tPwmAF38snpFF60j7VClUpgSL0XD1GU/Vp0kivCxSxEqkgQuUh+W8y5bnQhSF+IUFZH/ /kCg4AMO/wAd5aj7mXOyDuJMJUJ5kmX5W21J3XEwIZyTQAUV1+8lhplHMI1wHqyngxdM w1qbzA9vPlwnz+jsSxBm7kWIfFl9ZKXwgKjxPtGONnXJ8YX+XEQURL+Lvxn7xuQ2OdUK OouZqk2HYTDrfnF5DhAR+vE+f3VPzXQGiq+fOSwRDaLBQaRbLgPQTD7jqBmTAFh8YjkS aphg== 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=vYRQO3LiTTxSEYjQV8Guaai9LYcunVvJPerCBeFshLc=; fh=gPQ6jqLSfsDb5bE3yrtO+AlT5R4d75RXkjC5xckz7Dk=; b=FQhc0PCSnJqOpnCivHlHQODSjjKbnFiQwzlqJeWrW5XUlU52FpLYEyCITwOb0Wmd4i ngXhnSBoZ3oqTkzE1C8E5I/+cTIeGgCJ8+/NIVFIucln/hC1UMnAfOWzCjTj7HL7crZY hZpevHsA0EKEuPvXVcegLJB02kSh8hDtDnIwmeUm0sfZ1Knm3h4aYjBzHVNZdDIf5lIt YYh1K6BVKaWDxH/m2V2Lzh9dohl8032CJqp6Ye1K6zdg5Se2rQvPQoBnibkNWPPi2m2/ FPqIjzMm6xidfplkOeP19I4lnw7JqEErn9U+xU3lh4kpHR4vw6GqW8kDMEiTyqqbArVw G7Ug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=LBboshSc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id j8-20020a170902690800b001c9e890f42bsi7774497plk.78.2023.11.20.03.19.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 03:19:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=LBboshSc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (Postfix) with ESMTP id 820AF80A64DD; Mon, 20 Nov 2023 03:18:38 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233220AbjKTLRd (ORCPT + 99 others); Mon, 20 Nov 2023 06:17:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233454AbjKTLRB (ORCPT ); Mon, 20 Nov 2023 06:17:01 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C108170F; Mon, 20 Nov 2023 03:16:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700478984; x=1732014984; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=xPmGr7tpOJkUFCgjC5RUy87oirL30OKjxVb4BLpr69M=; b=LBboshScG0hI3ZXgHmNWeYpb+wGGc+koxiljQv8VYZ12o0mFVCW64BZE NFJC92xaYhFc2DQHjRXav5rqEafC8Rxyot1BXwqaxhj0EpiOclYdfmv0a rsAaDvIeRXVai+CMBfSB+qlSihkJA0wS+yfyJlciPaU9fb1OJuCVJCZa1 KfUY/fAozAXgylpmctLFh2KDyGtoyfqCkjfmKRQOoGYQNTI+5b6ShSRqh 3yNikpzZM6o4YVUYCOwQQmduqpou2ZzY49QBiBoAIHJsS5LHM7k5oVbs6 Y6ihuRNwF8yNAjiT28orDbz5/KOoW7z9FcFs8mJkHAW9dZ6ArATtFLt6k A==; X-IronPort-AV: E=McAfee;i="6600,9927,10899"; a="388737175" X-IronPort-AV: E=Sophos;i="6.04,213,1695711600"; d="scan'208";a="388737175" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Nov 2023 03:16:09 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10899"; a="759761378" X-IronPort-AV: E=Sophos;i="6.04,213,1695711600"; d="scan'208";a="759761378" Received: from sc9itsct4906.amr.corp.intel.com (HELO localhost) ([10.249.46.107]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Nov 2023 03:16:06 -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 16/26] selftests/resctrl: Open perf fd before start & add error handling Date: Mon, 20 Nov 2023 13:13:30 +0200 Message-Id: <20231120111340.7805-17-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=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email 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 (fry.vger.email [0.0.0.0]); Mon, 20 Nov 2023 03:18:38 -0800 (PST) Perf fd (pe_fd) is opened, reset, and enabled during every test the CAT selftest runs. Also, ioctl(pe_fd, ...) calls are not error checked even if ioctl() could return an error. Open perf fd only once before the tests and only reset and enable the counter within the test loop. Add error checking to pe_fd ioctl() calls. Signed-off-by: Ilpo Järvinen --- tools/testing/selftests/resctrl/cache.c | 19 +++++++++++++++---- tools/testing/selftests/resctrl/cat_test.c | 14 +++++++------- tools/testing/selftests/resctrl/resctrl.h | 1 + 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/tools/testing/selftests/resctrl/cache.c b/tools/testing/selftests/resctrl/cache.c index 29d70fc11f4e..012da5952cd6 100644 --- a/tools/testing/selftests/resctrl/cache.c +++ b/tools/testing/selftests/resctrl/cache.c @@ -22,10 +22,19 @@ void perf_event_attr_initialize(struct perf_event_attr *pea, __u64 config) } /* Start counters to log values */ -static void perf_event_reset_enable(int pe_fd) +int perf_event_reset_enable(int pe_fd) { - ioctl(pe_fd, PERF_EVENT_IOC_RESET, 0); - ioctl(pe_fd, PERF_EVENT_IOC_ENABLE, 0); + int ret; + + ret = ioctl(pe_fd, PERF_EVENT_IOC_RESET, 0); + if (ret < 0) + return ret; + + ret = ioctl(pe_fd, PERF_EVENT_IOC_ENABLE, 0); + if (ret < 0) + return ret; + + return 0; } void perf_event_initialize_read_format(struct perf_event_read *pe_read) @@ -129,7 +138,9 @@ int perf_event_measure(int pe_fd, struct perf_event_read *pe_read, int ret; /* Stop counters after one span to get miss rate */ - ioctl(pe_fd, PERF_EVENT_IOC_DISABLE, 0); + ret = ioctl(pe_fd, PERF_EVENT_IOC_DISABLE, 0); + if (ret < 0) + return ret; ret = read(pe_fd, pe_read, sizeof(*pe_read)); if (ret == -1) { diff --git a/tools/testing/selftests/resctrl/cat_test.c b/tools/testing/selftests/resctrl/cat_test.c index 7e1c383f9119..cfda87667b46 100644 --- a/tools/testing/selftests/resctrl/cat_test.c +++ b/tools/testing/selftests/resctrl/cat_test.c @@ -145,6 +145,9 @@ static int cat_test(struct resctrl_val_param *param, size_t span) perf_event_attr_initialize(&pea, PERF_COUNT_HW_CACHE_MISSES); perf_event_initialize_read_format(&pe_read); + pe_fd = perf_open(&pea, bm_pid, param->cpu_no); + if (pe_fd < 0) + return pe_fd; /* Test runs until the callback setup() tells the test to stop. */ while (1) { @@ -155,11 +158,10 @@ static int cat_test(struct resctrl_val_param *param, size_t span) } if (ret < 0) break; - pe_fd = perf_open(&pea, bm_pid, param->cpu_no); - if (pe_fd < 0) { - ret = -1; - break; - } + + ret = perf_event_reset_enable(pe_fd); + if (ret) + goto pe_close; if (run_fill_buf(span, memflush, operation, true)) { fprintf(stderr, "Error-running fill buffer\n"); @@ -171,8 +173,6 @@ static int cat_test(struct resctrl_val_param *param, size_t span) ret = perf_event_measure(pe_fd, &pe_read, param->filename, bm_pid); if (ret) goto pe_close; - - close(pe_fd); } return ret; diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h index 5626482b41cf..fe07b732cbd9 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -124,6 +124,7 @@ int get_core_sibling(int cpu_no); void perf_event_attr_initialize(struct perf_event_attr *pea, __u64 config); void perf_event_initialize_read_format(struct perf_event_read *pe_read); int perf_open(struct perf_event_attr *pea, pid_t pid, int cpu_no); +int perf_event_reset_enable(int pe_fd); int perf_event_measure(int pe_fd, struct perf_event_read *pe_read, const char *filename, int bm_pid); int measure_llc_resctrl(const char *filename, int bm_pid); -- 2.30.2