Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp2830609ybh; Mon, 5 Aug 2019 07:30:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqyS8/3U5215qFGS+aBWChzW0tmx0XHQP5xUnmM8XbCmEDr+CP5Kc8gXLu2aoq1zN0I3Ysag X-Received: by 2002:a63:a302:: with SMTP id s2mr31488946pge.125.1565015455411; Mon, 05 Aug 2019 07:30:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565015455; cv=none; d=google.com; s=arc-20160816; b=GWbqxmRw9y2ej+J4i+au/NewqrUxM73LKP5+IlKn7WnJ5rff/n/LVgOLEORMmoeLZX 1KSzGKB5+MHHncunDKVrLqSNNmFZuxrwfXu4SZh3x8kf2KQTXmXC1nIf/OphJVMufJKu TZe+0tkiLxm3GAeBCd9Dmq375tXQjFFqvFvNxJozGsQQu4vBQFERK9R6efBO/BYIwlc0 l8Hcqfw9XM25w21La5rJSLhFzEO3osfHuR/Ug+Tac9ka1kDmQvV+E4RinwvvJw5YNt5Z QWGlqkD3iE8A+3xNfMMAx21dmWPVI2ZuzKwsh5kgUAGgyVfMnDvO/Tu8b+KpMCwy733a aplg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=x7xqH8yvGPBQILjy9GkOsMgPZResgkMlKumcWpOKRGY=; b=Gfo5m3C3r8+gjxiP9ZHML4j4BdsOORHgrJYQaJfPSOrbGXhiDs0zxfkr3wof+jI2/O OB18fRk7FPlQLa7q6GlI983VIl5obvfmn2mjtIhJcOaxwNhgjgLlr+ocKRPfU2qnSMtl /b47dr82CQlXP3BgJ7M9vM8TYJJkSoIASW+MClYBJL9Xn/sEf95KUAGk3p2+ygG40R3c PJG9hbZ7vvbTOCaL6kBNP2O0Wd1SKo5dMNxm39EUkhZIHpvW00bIt3LehWBkahqIe0BT kGT6H7DfgmSfqjES1vHJ5p1LU1H8y3XqZJ/82pUGiTVxtjOifzittV22fWb4bFua6OI1 6ObA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p23si14784215pgi.76.2019.08.05.07.30.39; Mon, 05 Aug 2019 07:30:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729533AbfHEOaC (ORCPT + 99 others); Mon, 5 Aug 2019 10:30:02 -0400 Received: from mga06.intel.com ([134.134.136.31]:21116 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727830AbfHEOaB (ORCPT ); Mon, 5 Aug 2019 10:30:01 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Aug 2019 07:30:00 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,350,1559545200"; d="scan'208";a="185333619" Received: from unknown (HELO localhost.lm.intel.com) ([10.232.112.69]) by orsmga002.jf.intel.com with ESMTP; 05 Aug 2019 07:29:59 -0700 From: Keith Busch To: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Rafael Wysocki Cc: Dave Hansen , Dan Williams , Keith Busch Subject: [PATCH 1/3] hmat: Register memory-side cache after parsing Date: Mon, 5 Aug 2019 08:27:04 -0600 Message-Id: <20190805142706.22520-2-keith.busch@intel.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20190805142706.22520-1-keith.busch@intel.com> References: <20190805142706.22520-1-keith.busch@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Instead of registering the hmat cache attributes in line with parsing the table, save the attributes in the memory target and register them after parsing completes. This will make it easier to register the attributes later when hot add is supported. Tested-by: Brice Goglin Signed-off-by: Keith Busch --- drivers/acpi/hmat/hmat.c | 70 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 55 insertions(+), 15 deletions(-) diff --git a/drivers/acpi/hmat/hmat.c b/drivers/acpi/hmat/hmat.c index 96b7d39a97c6..bf23c9a27958 100644 --- a/drivers/acpi/hmat/hmat.c +++ b/drivers/acpi/hmat/hmat.c @@ -36,11 +36,17 @@ enum locality_types { static struct memory_locality *localities_types[4]; +struct target_cache { + struct list_head node; + struct node_cache_attrs cache_attrs; +}; + struct memory_target { struct list_head node; unsigned int memory_pxm; unsigned int processor_pxm; struct node_hmem_attrs hmem_attrs; + struct list_head caches; }; struct memory_initiator { @@ -110,6 +116,7 @@ static __init void alloc_memory_target(unsigned int mem_pxm) target->memory_pxm = mem_pxm; target->processor_pxm = PXM_INVAL; list_add_tail(&target->node, &targets); + INIT_LIST_HEAD(&target->caches); } static __init const char *hmat_data_type(u8 type) @@ -314,7 +321,8 @@ static __init int hmat_parse_cache(union acpi_subtable_headers *header, const unsigned long end) { struct acpi_hmat_cache *cache = (void *)header; - struct node_cache_attrs cache_attrs; + struct memory_target *target; + struct target_cache *tcache; u32 attrs; if (cache->header.length < sizeof(*cache)) { @@ -328,37 +336,47 @@ static __init int hmat_parse_cache(union acpi_subtable_headers *header, cache->memory_PD, cache->cache_size, attrs, cache->number_of_SMBIOShandles); - cache_attrs.size = cache->cache_size; - cache_attrs.level = (attrs & ACPI_HMAT_CACHE_LEVEL) >> 4; - cache_attrs.line_size = (attrs & ACPI_HMAT_CACHE_LINE_SIZE) >> 16; + target = find_mem_target(cache->memory_PD); + if (!target) + return 0; + + tcache = kzalloc(sizeof(*tcache), GFP_KERNEL); + if (!tcache) { + pr_notice_once("Failed to allocate HMAT cache info\n"); + return 0; + } + + tcache->cache_attrs.size = cache->cache_size; + tcache->cache_attrs.level = (attrs & ACPI_HMAT_CACHE_LEVEL) >> 4; + tcache->cache_attrs.line_size = (attrs & ACPI_HMAT_CACHE_LINE_SIZE) >> 16; switch ((attrs & ACPI_HMAT_CACHE_ASSOCIATIVITY) >> 8) { case ACPI_HMAT_CA_DIRECT_MAPPED: - cache_attrs.indexing = NODE_CACHE_DIRECT_MAP; + tcache->cache_attrs.indexing = NODE_CACHE_DIRECT_MAP; break; case ACPI_HMAT_CA_COMPLEX_CACHE_INDEXING: - cache_attrs.indexing = NODE_CACHE_INDEXED; + tcache->cache_attrs.indexing = NODE_CACHE_INDEXED; break; case ACPI_HMAT_CA_NONE: default: - cache_attrs.indexing = NODE_CACHE_OTHER; + tcache->cache_attrs.indexing = NODE_CACHE_OTHER; break; } switch ((attrs & ACPI_HMAT_WRITE_POLICY) >> 12) { case ACPI_HMAT_CP_WB: - cache_attrs.write_policy = NODE_CACHE_WRITE_BACK; + tcache->cache_attrs.write_policy = NODE_CACHE_WRITE_BACK; break; case ACPI_HMAT_CP_WT: - cache_attrs.write_policy = NODE_CACHE_WRITE_THROUGH; + tcache->cache_attrs.write_policy = NODE_CACHE_WRITE_THROUGH; break; case ACPI_HMAT_CP_NONE: default: - cache_attrs.write_policy = NODE_CACHE_WRITE_OTHER; + tcache->cache_attrs.write_policy = NODE_CACHE_WRITE_OTHER; break; } + list_add_tail(&tcache->node, &target->caches); - node_add_cache(pxm_to_node(cache->memory_PD), &cache_attrs); return 0; } @@ -577,20 +595,37 @@ static __init void hmat_register_target_initiators(struct memory_target *target) } } +static __init void hmat_register_target_cache(struct memory_target *target) +{ + unsigned mem_nid = pxm_to_node(target->memory_pxm); + struct target_cache *tcache; + + list_for_each_entry(tcache, &target->caches, node) + node_add_cache(mem_nid, &tcache->cache_attrs); +} + static __init void hmat_register_target_perf(struct memory_target *target) { unsigned mem_nid = pxm_to_node(target->memory_pxm); node_set_perf_attrs(mem_nid, &target->hmem_attrs, 0); } +static __init void hmat_register_target(struct memory_target *target) +{ + if (!node_online(pxm_to_node(target->memory_pxm))) + return; + + hmat_register_target_initiators(target); + hmat_register_target_cache(target); + hmat_register_target_perf(target); +} + static __init void hmat_register_targets(void) { struct memory_target *target; - list_for_each_entry(target, &targets, node) { - hmat_register_target_initiators(target); - hmat_register_target_perf(target); - } + list_for_each_entry(target, &targets, node) + hmat_register_target(target); } static __init void hmat_free_structures(void) @@ -598,8 +633,13 @@ static __init void hmat_free_structures(void) struct memory_target *target, *tnext; struct memory_locality *loc, *lnext; struct memory_initiator *initiator, *inext; + struct target_cache *tcache, *cnext; list_for_each_entry_safe(target, tnext, &targets, node) { + list_for_each_entry_safe(tcache, cnext, &target->caches, node) { + list_del(&tcache->node); + kfree(tcache); + } list_del(&target->node); kfree(target); } -- 2.14.4