Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp2142506rdb; Mon, 20 Nov 2023 03:19:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IEtsIQz3iazqCCQvFCsa5iKL6d6mjo1WBVPOvaCtb88sEGx8bo0NELT1Xtj0AcSPHJaMFqx X-Received: by 2002:a05:6a20:3d23:b0:187:b35b:81b with SMTP id y35-20020a056a203d2300b00187b35b081bmr5361340pzi.52.1700479175700; Mon, 20 Nov 2023 03:19:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700479175; cv=none; d=google.com; s=arc-20160816; b=B5a7kJ76PEjR1PC+e5UqqwemcIKJlVbo1qkbuzjvv2939RYhqMsZ4NMHDidPZRLUuJ nEYjsdlzTvEswbrkf6MUfyK7knoKj4NUA48kS7+IC5+8aq23j+Po7qtzIatgl6/G0JEo ECiEwN735HGpsD+shoLljjc2cCeq1eFFnIi/VCQiINRMV+TSn/hRQp+KLGDKVCZvkD2G l/3EnaJ+24mu9/dIc0LtfNKjMrKSwN2waSa/jC+kQ+7Vz22YMHYB8skFyrIJsu82uAcI psT8l6ow333TWGBOGIanLSOmfnjZ/wk0aF6wkJZWv4cD9wudKU1Z8oADuspeE243aASU Thcg== 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=LDAQoyfSF1e4kZGIoRkbaoHGYXCfyIOrs2gpdOwmAsA=; fh=gPQ6jqLSfsDb5bE3yrtO+AlT5R4d75RXkjC5xckz7Dk=; b=MQDwWpaN44y811pKWiI115vVPhI6CmrMIkfWsItRC+zoTOwrHzclUt3/mTH+Qfhnf+ uZobCfZt03N4Fh1sVMWoK5E+FfiKYumg5qkIQQqLPBPyzokuOIHcQSBd7GmKaVwpNLig /Ljfofl+/RBmnlNbbn87viW+uT5T+vE/f5zGhH8lJ/bdaTRvRzrTMww63oR6epJy6cEN EioLMI4tJytPA2WaILCX9WDrUeKdm4j7dRzAFVUgsPBd00v1ezBs2FAAQW6rmaNdqBSd EKcWectNi9giebk1AleNKzWIwSXTVH/8Jn6ZfzniB0wet7o2f2M1XnssaeJVLhJSMkqo MQvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Q8YPG+vT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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. [23.128.96.37]) by mx.google.com with ESMTPS id lc3-20020a17090b158300b002773d013d02si10559754pjb.140.2023.11.20.03.19.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 03:19:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Q8YPG+vT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 B9D10805F945; Mon, 20 Nov 2023 03:19:06 -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 S233395AbjKTLS6 (ORCPT + 99 others); Mon, 20 Nov 2023 06:18:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233441AbjKTLSg (ORCPT ); Mon, 20 Nov 2023 06:18:36 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E6F12691; Mon, 20 Nov 2023 03:17:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700479045; x=1732015045; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=22cBx10DhRppnsCIlGXNuC/WP0NGzPH27j7vhPlKXIE=; b=Q8YPG+vT++sd3+/xfjVuBRrUoIJOFlTvmrI2tr8RSKCRuZCYu7o/+kpd JJsbNVZYLQ6vXWQF8eq4WDGDY4aXoE0Wb4quG2Lg1czWiRq5/rjFbLTop iYsRU4aBe8/Y0sYPebT2+oo8kA2jGkPH04h4H2hm7OCzSKF990g8RPtR1 m97FBA8MzfTeuvoEmzknyrXeprCpSOT3iQWvL0gd2IvQHfSDmJChpfhhc rLDOnW7G7vz+QZq2vEfWsoZopEbLHMcUj70lCjqr3JDHrvZPm1jlQIDe8 nWo3BeAw6UmLQqO3u9dV3bNtNxrygb+qXXV/Eb/J982vkp5V3E+BUFp55 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10899"; a="13152215" X-IronPort-AV: E=Sophos;i="6.04,213,1695711600"; d="scan'208";a="13152215" 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:17:08 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10899"; a="832238714" X-IronPort-AV: E=Sophos;i="6.04,213,1695711600"; d="scan'208";a="832238714" 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:17:04 -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 23/26] selftests/resctrl: Add helper to convert L2/3 to integer Date: Mon, 20 Nov 2023 13:13:37 +0200 Message-Id: <20231120111340.7805-24-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:19:06 -0800 (PST) "L2"/"L3" conversion to integer is embedded into get_cache_size() which prevents reuse. Create a helper for the cache string to integer conversion to make it reusable. Signed-off-by: Ilpo Järvinen --- tools/testing/selftests/resctrl/resctrlfs.c | 28 +++++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/tools/testing/selftests/resctrl/resctrlfs.c b/tools/testing/selftests/resctrl/resctrlfs.c index fda5ad812faa..38ca3ae562e9 100644 --- a/tools/testing/selftests/resctrl/resctrlfs.c +++ b/tools/testing/selftests/resctrl/resctrlfs.c @@ -94,6 +94,23 @@ int umount_resctrlfs(void) return 0; } +/* + * get_cache_level - Convert cache level from string to integer + * @cache_type: Cache level as string + * + * Return: cache level as integer or -1 if @cache_type is invalid. + */ +static int get_cache_level(const char *cache_type) +{ + if (!strcmp(cache_type, "L3")) + return 3; + if (!strcmp(cache_type, "L2")) + return 2; + + perror("Invalid cache level"); + return -1; +} + /* * get_resource_id - Get socket number/l3 id for a specified CPU * @cpu_no: CPU number @@ -144,14 +161,9 @@ int get_cache_size(int cpu_no, const char *cache_type, unsigned long *cache_size int length, i, cache_num; FILE *fp; - if (!strcmp(cache_type, "L3")) { - cache_num = 3; - } else if (!strcmp(cache_type, "L2")) { - cache_num = 2; - } else { - perror("Invalid cache level"); - return -1; - } + cache_num = get_cache_level(cache_type); + if (cache_num < 0) + return cache_num; sprintf(cache_path, "/sys/bus/cpu/devices/cpu%d/cache/index%d/size", cpu_no, cache_num); -- 2.30.2