Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1764838rda; Tue, 24 Oct 2023 02:32:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHnd8joFpuBp5cTX/leFf1cLDQLJ3y/AwLKl8OW1o9f1j0mhy4s3oBveL5uVDNG4rRpRHDs X-Received: by 2002:a17:902:c215:b0:1c7:3558:721a with SMTP id 21-20020a170902c21500b001c73558721amr8489840pll.58.1698139932877; Tue, 24 Oct 2023 02:32:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698139932; cv=none; d=google.com; s=arc-20160816; b=OzbaDWJ8bWh1uHyuAJYcyJwvYTTBTDxJsaWbCLs6O5lf+jEF+QG8ZPLU3wopeaYZtn XKL778qV0wQ7isUgKVkfwEIRlyuCcfy2YlVNwBZfmR7XrOIfeSvLwXI8vf6OUTWOZAvr VB5pSKGm0iZ6D7BV2goD5gTYJ+FXuyvlHwlEuLeDE14VzMoGRDhwMOfIqmy5DVsPjb4t 4C0PkoZ++/mpKSdTU2CTJkzpfedBzVL8Np5eHXw9bjoZ9xM64Xku/JCvpY8Opo1Sp3bx OrR8uTzEjE6HwENEn3pnqVk6d/yeMYL3aDdr8M8i13iR5L1X3bl38okzl36NYM1UuJup JNzg== 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=T15KGgFfJzBK/PeAvviq25UxeKBNz9dIM9srLo0F8CQ=; fh=gPQ6jqLSfsDb5bE3yrtO+AlT5R4d75RXkjC5xckz7Dk=; b=BVFq2/KTYB9+rLL0bDbvrXHbIAjzXR9HOiImXbcA8YDKI8AIUpC0ZshKbxaxRcxFOi +qe6i4QtaNvvrD01+bTgtYw//rpJHVL0GraLqs4PBJLMojkh5U9GoLPO998pu1BfPXUB 8RVbqTw8kYJA7H4tatRMRFLuDuhihj/nzdxInDvoR3Jo5Mdj78YyQ2Pr3hog7UCFUQ66 kDaBKiffiIk2Cxf6boOmoiHfr7FvMPN8yBLBGQwCYfUGigMdhSC/S0mBDS71jaIcEL6K q+i6Koc+J6e0bArXZdLN3MmSnMHvZmio4WqFVry+9q76yZ8luicSmpIF1NprtD7h4q0q l59g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=DewtULf3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id q14-20020a170902a3ce00b001c60de17b5esi8035012plb.118.2023.10.24.02.32.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 02:32:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=DewtULf3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (Postfix) with ESMTP id 966F18073298; Tue, 24 Oct 2023 02:32:09 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234252AbjJXJbZ (ORCPT + 99 others); Tue, 24 Oct 2023 05:31:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234308AbjJXJaz (ORCPT ); Tue, 24 Oct 2023 05:30:55 -0400 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5AB12171E; Tue, 24 Oct 2023 02:29:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698139777; x=1729675777; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3vy9fAeuuxL3PMPYGchCQGLED1dgGOCzucRm1jFBvV8=; b=DewtULf3PDupkB1w4Ti8UBZOcYO8gIWvF3Atv3MCzQpJYPceQN4Y3e+7 jByE4taRbnB5JQ068flvqeO+cxWtQN1jQnDQF8jFC2pzcTXbyOs4IG5Ub BZtFEYBWrVNVvm6XY7AJilKqR+I4wxrV2D+dJ5qndJf+jM9Cc4Yo7WQq6 KYacQmJqtEjh+ZxruGvJ971QLzIkw9FWNeGxM63kjKARHR365EouNeH41 k/YAC9DkWEghKYMmt0DfrjnibltCxXhbnKxlnRN3eGbJ1uD+FQQMd6HIC 6/xdfNv/AI1qfgl1XKoXlYEpfwLjlWJ5MJLC+dEXihBunBIc4nDBn/OXm w==; X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="5644362" X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="5644362" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2023 02:29:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="758410117" X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="758410117" Received: from hprosing-mobl.ger.corp.intel.com (HELO localhost) ([10.249.40.219]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2023 02:29:33 -0700 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 20/24] selftests/resctrl: Add helper to convert L2/3 to integer Date: Tue, 24 Oct 2023 12:26:30 +0300 Message-Id: <20231024092634.7122-21-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20231024092634.7122-1-ilpo.jarvinen@linux.intel.com> References: <20231024092634.7122-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 autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.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 (groat.vger.email [0.0.0.0]); Tue, 24 Oct 2023 02:32:09 -0700 (PDT) "L2"/"L3" conversion to integer in 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 7d72bea3ed58..b98d88f7cbc4 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