From patchwork Fri Dec 15 15:05:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ilpo_J=C3=A4rvinen?= X-Patchwork-Id: 179369 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp9347543dys; Fri, 15 Dec 2023 07:13:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IFXla6GauoXOIlGEl4nBMLavM5XL5GXXTsrDhIJvwotQWYOqCDt0a1WMWPMngnawNapRGrL X-Received: by 2002:a05:620a:488d:b0:77f:31f5:ae52 with SMTP id ea13-20020a05620a488d00b0077f31f5ae52mr14399027qkb.123.1702653224484; Fri, 15 Dec 2023 07:13:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702653224; cv=none; d=google.com; s=arc-20160816; b=Q8I8dVvC3azdDPvMLdQ7zt1hrtMenBHqYwyUab5P/nUUXjVpBUXn/e9rCx3HVtNuTQ +3Tgsu5ib0rt0knm4RdFtsUl5TofptfECnQIAPJGZblGSqWIbpL5VD70S7QsLOt4hys4 AKiuC7MMDbyYqzh7qdtT0aEznzQtNM9Ajc9uPQuu/mLN1eYuwryOuaMTqmTFeak1ViWA pnFtkJ7Y7XrHizTZo8z8jZsEqdcnpDmKA0tVeAY8noO16SIdgtJ4oDLaKnR1G1nzhxgH JDHVBrgxio0P86AyrIG14mh2qy/wi2WYVLlwmPGiZWglc5ffeQHlDnTXZfKS49myQF9v v04w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=+Ms/d/3LqR6ZZj7P9oORtBPUXxnaqi2vPApG78lb2wA=; fh=gPQ6jqLSfsDb5bE3yrtO+AlT5R4d75RXkjC5xckz7Dk=; b=JGonaJKeVDkUqujw9j/Iob07HvNmPDm7qFiuasBftV81tjf9R+Itwnl92ld+rhyHZp sR/1fO4onc0jlo1SF4ZbppG9mZHP1U5MUgM5P/6dQZcaWgbYm39m5JbMtMksdGP4hXeZ zqxdgiIfj/TkrKjHo855gwZBCfCx0E4PKkrXuiG37WAGw3mMT0kJX9+kr6unOcw+QFv9 6EASUP960NO6zA1tTGWScHpCy0PwFiHImtj2gSC6FrJB36DoePZpfofvani8I85KpDjQ +FLqbb5yZoM/VJtrhlQ29h1mi1LQTfCbc0zpmreUmIpjYcQ9mBuhvi2q4vx5Pd5ZEIEJ xZXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=n6EHBiWt; spf=pass (google.com: domain of linux-kernel+bounces-1180-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1180-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id dv23-20020a05620a1b9700b0077d859f0db8si18266799qkb.763.2023.12.15.07.13.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 07:13:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-1180-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=n6EHBiWt; spf=pass (google.com: domain of linux-kernel+bounces-1180-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1180-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 4282E1C234F3 for ; Fri, 15 Dec 2023 15:13:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DB99F45C07; Fri, 15 Dec 2023 15:09:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="n6EHBiWt" X-Original-To: linux-kernel@vger.kernel.org Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.93]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BDF454596B; Fri, 15 Dec 2023 15:09:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1702652980; x=1734188980; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VB0+uopmzLBdFoQyH1tNp0ZoBbzjE/BpX5BNhSMP/b4=; b=n6EHBiWttpnLTeGKHOK8p4vEwWfNgEmErycUnkQwPRhCVFdINQLeBHcf adEM9ZyKZEkHPtCrjPAsUlbXViOv2VYN00QFKNWaugTCVl7osd1jOamua VKMSL8vIZJMrRVR3sQipM20+aRXnTaYOR1zXh6ON1dNGV2MgeVKPcfGs3 4JDoM9YlTMfq7RQYAVxsQmNL+IXrcm/vLDFy1UH9xByjyk1z6GYoof1XK AZOnmYXDHc65tnz2QqvB6bYm0mgxtdWAqMRixpikJfvaD+dvooeLLlBrX cE3GzzcEP7odaBOXlFDwqMCArv23SFzjZ0Gvr+OTpce9DK3m1PBAAsoOl Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10924"; a="392461795" X-IronPort-AV: E=Sophos;i="6.04,279,1695711600"; d="scan'208";a="392461795" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Dec 2023 07:09:40 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10924"; a="1106151106" X-IronPort-AV: E=Sophos;i="6.04,279,1695711600"; d="scan'208";a="1106151106" Received: from ijarvine-desk1.ger.corp.intel.com (HELO localhost) ([10.246.49.116]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Dec 2023 07:09:36 -0800 From: =?utf-8?q?Ilpo_J=C3=A4rvinen?= To: linux-kselftest@vger.kernel.org, Reinette Chatre , Shuah Khan , Shaopeng Tan , =?utf-8?q?Maciej_Wiecz=C3=B3r-R?= =?utf-8?q?etman?= , Fenghua Yu Cc: linux-kernel@vger.kernel.org, =?utf-8?q?Ilpo_J=C3=A4rvinen?= Subject: [PATCH v4 27/29] selftests/resctrl: Add helper to convert L2/3 to integer Date: Fri, 15 Dec 2023 17:05:13 +0200 Message-Id: <20231215150515.36983-28-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20231215150515.36983-1-ilpo.jarvinen@linux.intel.com> References: <20231215150515.36983-1-ilpo.jarvinen@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785361308000722653 X-GMAIL-MSGID: 1785361308000722653 "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 Reviewed-by: Reinette Chatre --- 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 fed6741edc5f..eab928c46f98 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; + + ksft_print_msg("Invalid cache level\n"); + 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 { - ksft_print_msg("Invalid cache level\n"); - 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);