Received: by 2002:ab2:6d45:0:b0:1fb:d597:ff75 with SMTP id d5csp404259lqr; Wed, 5 Jun 2024 09:15:07 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWMNF0X9wbAueW49YFz378TA0twC4udQdM++cX0FPrtDe/5YvxNH0/RMH2Nfkl1Bg9q/aZXYxX75WpXINAskoy9Qeg4BQ9NqwYLn04gGA== X-Google-Smtp-Source: AGHT+IEP2uZ3zb+l+QgOtPmriu4zhVvezNdlyucw5inaqxR+EV4+XnhG3Tsik3QPJfPffxMGH7Mp X-Received: by 2002:a05:6214:5884:b0:6ae:9c0:d180 with SMTP id 6a1803df08f44-6b030a8ab95mr26849506d6.60.1717604106859; Wed, 05 Jun 2024 09:15:06 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717604106; cv=pass; d=google.com; s=arc-20160816; b=lzWkvcgxczCU9kFeUdNKAXyYwUH79aNHXCSKXW3tt9uo8I6NzICj8ICkAjYOgwQj3W 8EFTKAkTouDS3/h583m1ZrH5Sgd0Mwx1wtSzHAmUqLCben8wrEuo6/9eQ3GrAop36IsR AOid+I/RD14C2OBeebiormum6upVn1slZxfhTnT0uZsFB/4IWfiH1x3O6ZtXmB0t1LOq qHOr2oiXErujornxRAVW3RXRGR4qXiToRMaU7ZPPbrPFqNLtUSCWs35ovqv/R52ocmwS K5tXFVBRInQbVBiruE4QNfq7tqvn+RrYVVPImnuCMyv4ZpNUoMNK87ef4ucXU6khviCX gMMQ== ARC-Message-Signature: i=2; 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=KjvalibAuUdGptQZL2Bj8UcDvgEi1aTozTM0WSMiEAQ=; fh=zrVDlrC06DAIec5BvDl2IM9WrZzuc2uxw+nPFYRCHpQ=; b=TdANZcHXrRFI1z5wNQIAH6G0xhCh/wpJlfLR5uGfZuH6WdZllEMwYtGSflum6IEJAo 40Lqb+BkBFHTiCqP+lT80SQ8YF8WDzJpAn7d6gnyWy9/UtLkgyJO0BMEwsMQNIFbBai5 l/c384E3pfbl5JQJzbBsTg+ieKvsto3jLGtWKTBHkpenmfB1UlwFoR3oi8kTj3OrmSzH CHUnkfJx0eZJdIMfJ5mozFp4z/MQHuAWxgLmT4pZfD7yOME+qDbGh+KsGuHbHcMUUMF1 6Jd+2Xuhdu55XNweTmFuA9G9JDIg9nMoMVP1DQ2AGnMTvjLWvi7a8iMBZWfnpt6fng0i ufKg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=cmFtgbHt; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-202895-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-202895-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 6a1803df08f44-6ae4b4019f7si137745666d6.306.2024.06.05.09.15.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 09:15:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-202895-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=cmFtgbHt; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-202895-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-202895-linux.lists.archive=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 94D3A1C23D98 for ; Wed, 5 Jun 2024 16:15:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E64CD188CDC; Wed, 5 Jun 2024 16:14:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="cmFtgbHt" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) (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 4C1961553B3 for ; Wed, 5 Jun 2024 16:14:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.8 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717604081; cv=none; b=aW8nAGe9zbg26Vw0Esq7FtEuXb5ZPT86PR57l0+naPUmLU5rfGGs5uWYcpOZIPIxQbNIipfry9NOJrkcAtgG362ulUhkCuJy71cWQ+eGTIIgeHdQZ935l6JEiyPY/VVPWYbkJcLOkTin5qQFGgPknpHUmspCPd5NQTPMM/pZBwQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717604081; c=relaxed/simple; bh=yanHfd6jlJmGT0zmUR9ubQ+HVlgEg5ygOb5UbWWoM5o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Dy0pJOf9RgndyZ0vtwTrhjAfSh+nuXMRcbEYEhGzECYvvDah3DwqIh2KZ5zWEQ3S6jNEEGQA2j1DrFhBOumIGUEXZsrSMgqm+u220QYoamHaRSMWlPn4ZZgvDtOX70wrAi5SQul9udVOGQiSFBrNP8SN9mPdlqBxcSW4cgwQ77o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=cmFtgbHt; arc=none smtp.client-ip=192.198.163.8 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1717604079; x=1749140079; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yanHfd6jlJmGT0zmUR9ubQ+HVlgEg5ygOb5UbWWoM5o=; b=cmFtgbHt6hfcggoHIqGOyKzpnlG5suMufYExESWAxYU+OcSO8lQqJ4Kq LMOX+n10u3sy9Z/EFGcHOedpGeDRM74pIscniGmzuvMkWbn3XIbAH8Cz2 SKP2wa/51ZFPTSaGPbIVFZ36PZBr99lR7I+AP2injn+yOe52SazSaKDPR i721aGLnJ8nyyi/nHmcnaMM451dDsYSy8vQYP58oxUN1uX/GGCRMeGTlM K21L9BWfndbMspZTi9CHMzE3A+MeiQlBIGOLwrBXQ/MSBWUIFajFTdrw2 CjDa2XAmrrGo2HqSLOcks2Jp0AUZ55aaG684yn29wk/VyorpQ7ZiKQldJ w==; X-CSE-ConnectionGUID: p4X7r8y3RCSn9o2VdHqHNQ== X-CSE-MsgGUID: GNi/YDXITiWV+R8uvCX3aQ== X-IronPort-AV: E=McAfee;i="6600,9927,11094"; a="31772289" X-IronPort-AV: E=Sophos;i="6.08,217,1712646000"; d="scan'208";a="31772289" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jun 2024 09:14:37 -0700 X-CSE-ConnectionGUID: AQuyBpvDQACNsZSEi0KIFw== X-CSE-MsgGUID: YmYw7eXRSMuVIMIaAiQw7g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,217,1712646000"; d="scan'208";a="42581898" Received: from agluck-desk3.sc.intel.com ([172.25.222.70]) by orviesa005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jun 2024 09:14:36 -0700 From: Tony Luck To: Borislav Petkov Cc: x86@kernel.org, Fenghua Yu , Reinette Chatre , Maciej Wieczor-Retman , Peter Newman , James Morse , Babu Moger , Drew Fustini , Dave Martin , linux-kernel@vger.kernel.org, patches@lists.linux.dev, Tony Luck Subject: [PATCH v2 1/3] cacheinfo: Add function to get cacheinfo for a given (cpu, cachelevel) Date: Wed, 5 Jun 2024 09:14:25 -0700 Message-ID: <20240605161427.312994-2-tony.luck@intel.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240605161427.312994-1-tony.luck@intel.com> References: <20240605161427.312994-1-tony.luck@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Resctrl code open codes a search for information about a given cache level in a couple of places (and more are on the way). Provide a new inline function get_cpu_cacheinfo_level() in to do the search and return a pointer to the cacheinfo structure. Simplify the existing get_cpu_cacheinfo_id() by using this new function to do the search. Signed-off-by: Tony Luck Reviewed-by: Reinette Chatre --- include/linux/cacheinfo.h | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/include/linux/cacheinfo.h b/include/linux/cacheinfo.h index 2cb15fe4fe12..b4d99052d186 100644 --- a/include/linux/cacheinfo.h +++ b/include/linux/cacheinfo.h @@ -113,10 +113,11 @@ int acpi_get_cache_info(unsigned int cpu, const struct attribute_group *cache_get_priv_group(struct cacheinfo *this_leaf); /* - * Get the id of the cache associated with @cpu at level @level. + * Get the cacheinfo structure for the cache associated with @cpu at + * level @level. * cpuhp lock must be held. */ -static inline int get_cpu_cacheinfo_id(int cpu, int level) +static inline struct cacheinfo *get_cpu_cacheinfo_level(int cpu, int level) { struct cpu_cacheinfo *ci = get_cpu_cacheinfo(cpu); int i; @@ -124,12 +125,23 @@ static inline int get_cpu_cacheinfo_id(int cpu, int level) for (i = 0; i < ci->num_leaves; i++) { if (ci->info_list[i].level == level) { if (ci->info_list[i].attributes & CACHE_ID) - return ci->info_list[i].id; - return -1; + return &ci->info_list[i]; + return NULL; } } - return -1; + return NULL; +} + +/* + * Get the id of the cache associated with @cpu at level @level. + * cpuhp lock must be held. + */ +static inline int get_cpu_cacheinfo_id(int cpu, int level) +{ + struct cacheinfo *ci = get_cpu_cacheinfo_level(cpu, level); + + return ci ? ci->id : -1; } #ifdef CONFIG_ARM64 -- 2.45.0