From patchwork Wed Jan 16 17:57:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Busch X-Patchwork-Id: 10766605 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E397713B4 for ; Wed, 16 Jan 2019 17:59:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D2AFB2F0EF for ; Wed, 16 Jan 2019 17:59:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C6A9F2F102; Wed, 16 Jan 2019 17:59:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2653D2F0EF for ; Wed, 16 Jan 2019 17:59:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EB5A58E0008; Wed, 16 Jan 2019 12:59:42 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E705A8E0006; Wed, 16 Jan 2019 12:59:42 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C1E538E0008; Wed, 16 Jan 2019 12:59:42 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) by kanga.kvack.org (Postfix) with ESMTP id 750828E0006 for ; Wed, 16 Jan 2019 12:59:42 -0500 (EST) Received: by mail-pg1-f200.google.com with SMTP id 202so4339470pgb.6 for ; Wed, 16 Jan 2019 09:59:42 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=Yca6fCvrHPEOciR9bJUbC7nCn8ZyQaAC2wLtcb2Lx6c=; b=dT3Hp+e5IHO5eryVh7JwPqlF7fVfgMoYK4n6hYH+wGyFP3pfyrd7YB/vwNd5ozp2s5 xr2MfYe0w+TUAAzkbycef/d4nkbOhGOQOyP+8oy4xHYve8B/kYsgqbmaa8aQ0Yj84ntb vr1TPepmMBOGqP70JxesNwUpZOu6qXWqtdiG1fDnZb18rB4qWizlCmTAIVSVGSBKqG8P MKSHn8x8RMd1NjGhO3rghpYHrXfIARFNaBI11v3GfQmnZFbL7TMflx9iqaParGwNSgVd Pb57iqq28SGDed4zBpL/PflzGcPoH6yLBPLpxqlDFEBH2EW0BNcDQnmv1btTrgkIgNeA XFGg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of keith.busch@intel.com designates 192.55.52.88 as permitted sender) smtp.mailfrom=keith.busch@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Gm-Message-State: AJcUukcHv3Id44zZ4yUOZmJsV3tAjT1v2PWEqSlQiVA554nk0LUKBB3R M0TtOUXleFV5DjIDvXh27XHWxUSNEhjxS9UUhqlGHgfVXFGxXDl9YJYNEEcXvOcY2ZAkii5TAoI IAvhyRoiB+LAJdngc5pubkieI5hkAixuSxS2qgTaEZbkoQuKVMozaMQj1c7m1/PP6ow== X-Received: by 2002:a17:902:bd92:: with SMTP id q18mr11110632pls.167.1547661582107; Wed, 16 Jan 2019 09:59:42 -0800 (PST) X-Google-Smtp-Source: ALg8bN6sXtLxsTcrlFm/j0ZcNlbofxhbeS+GBvlJaS/OmzlGCWhl9NE/s0o32xkLTwWg8oThJf43 X-Received: by 2002:a17:902:bd92:: with SMTP id q18mr11110574pls.167.1547661581229; Wed, 16 Jan 2019 09:59:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547661581; cv=none; d=google.com; s=arc-20160816; b=Ur6W64wP8U//POBY1KQObCIXclst3y0DrScfZqivh8mQZSSXbob1V90GKPKRZvJ2J1 M2RsAGRnJa5edOUb69bNcxnhRvl0slHI8usqRY3K3mDTYYkeBluYw/qRDfSMXnUMB9ju Y2josRnASM1biflTtxCJP8zG9WxhYgwUqX0xPMBwEzoDizEVFHsaxzboso/DQ0gHqR8f 8VujEJ6RbraBxYlOyZOcP5OhMad8k7R8SgIiFD56Y3s+rksSCzzDHQqKpnbtapSM7Bpm QOV9eCF6kBwg1jp0V5WCXldCSKs1tVMG73Uo34wPblKhW58JftlQysg7EMM53TwsKFG6 Ofjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=Yca6fCvrHPEOciR9bJUbC7nCn8ZyQaAC2wLtcb2Lx6c=; b=vHTZoimE3juIPj/RcdorNidBaTGugyVf9Z2KW4Yj2ORgBqHcYPDTqUV7BSv27SMH/6 IzI+upuuTFpaTJZ0zPapa3IEerZnZvDyKvLscgqSIIOaTegt6Itmixd9B0aPKMqdtOQo Zc7E2FCE5F6a2V06a8n+gxYNJ2oJGdZniJoL/v8NpWRBHv3wD+aSBkS0K8AoWf5jxRs2 CG1xB/w4/l4YX41C1J1uzHnCeE1JuPafgZLmTF8Jik7MvBD2riYyC75HC04pved6NaBa UJTXoYKsKzWS9qPR4Yow+/qF9sQSXWvybVudL+jLpjkcGFEg4E7yx3Za61LTvpwOHm31 q0lA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of keith.busch@intel.com designates 192.55.52.88 as permitted sender) smtp.mailfrom=keith.busch@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga01.intel.com (mga01.intel.com. [192.55.52.88]) by mx.google.com with ESMTPS id d18si6701527pgm.212.2019.01.16.09.59.41 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 16 Jan 2019 09:59:41 -0800 (PST) Received-SPF: pass (google.com: domain of keith.busch@intel.com designates 192.55.52.88 as permitted sender) client-ip=192.55.52.88; Authentication-Results: mx.google.com; spf=pass (google.com: domain of keith.busch@intel.com designates 192.55.52.88 as permitted sender) smtp.mailfrom=keith.busch@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Jan 2019 09:59:39 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,487,1539673200"; d="scan'208";a="117227786" Received: from unknown (HELO localhost.lm.intel.com) ([10.232.112.69]) by fmsmga008.fm.intel.com with ESMTP; 16 Jan 2019 09:59:38 -0800 From: Keith Busch To: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-mm@kvack.org Cc: Greg Kroah-Hartman , Rafael Wysocki , Dave Hansen , Dan Williams , Keith Busch Subject: [PATCHv4 06/13] acpi/hmat: Register processor domain to its memory Date: Wed, 16 Jan 2019 10:57:57 -0700 Message-Id: <20190116175804.30196-7-keith.busch@intel.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20190116175804.30196-1-keith.busch@intel.com> References: <20190116175804.30196-1-keith.busch@intel.com> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP If the HMAT Subsystem Address Range provides a valid processor proximity domain for a memory domain, or a processor domain with the highest performing access exists, register the memory target with that initiator so this relationship will be visible under the node's sysfs directory. Since HMAT requires valid address ranges have an equivalent SRAT entry, verify each memory target satisfies this requirement. Signed-off-by: Keith Busch --- drivers/acpi/hmat/hmat.c | 143 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 136 insertions(+), 7 deletions(-) diff --git a/drivers/acpi/hmat/hmat.c b/drivers/acpi/hmat/hmat.c index 833a783868d5..efb33c74d1a3 100644 --- a/drivers/acpi/hmat/hmat.c +++ b/drivers/acpi/hmat/hmat.c @@ -17,6 +17,43 @@ #include #include +static LIST_HEAD(targets); + +struct memory_target { + struct list_head node; + unsigned int memory_pxm; + unsigned long p_nodes[BITS_TO_LONGS(MAX_NUMNODES)]; +}; + +static __init struct memory_target *find_mem_target(unsigned int m) +{ + struct memory_target *t; + + list_for_each_entry(t, &targets, node) + if (t->memory_pxm == m) + return t; + return NULL; +} + +static __init void alloc_memory_target(unsigned int mem_pxm) +{ + struct memory_target *t; + + if (pxm_to_node(mem_pxm) == NUMA_NO_NODE) + return; + + t = find_mem_target(mem_pxm); + if (t) + return; + + t = kzalloc(sizeof(*t), GFP_KERNEL); + if (!t) + return; + + t->memory_pxm = mem_pxm; + list_add_tail(&t->node, &targets); +} + static __init const char *hmat_data_type(u8 type) { switch (type) { @@ -53,11 +90,30 @@ static __init const char *hmat_data_type_suffix(u8 type) }; } +static __init void hmat_update_access(u8 type, u32 value, u32 *best) +{ + switch (type) { + case ACPI_HMAT_ACCESS_LATENCY: + case ACPI_HMAT_READ_LATENCY: + case ACPI_HMAT_WRITE_LATENCY: + if (!*best || *best > value) + *best = value; + break; + case ACPI_HMAT_ACCESS_BANDWIDTH: + case ACPI_HMAT_READ_BANDWIDTH: + case ACPI_HMAT_WRITE_BANDWIDTH: + if (!*best || *best < value) + *best = value; + break; + } +} + static __init int hmat_parse_locality(union acpi_subtable_headers *header, const unsigned long end) { + struct memory_target *t; struct acpi_hmat_locality *loc = (void *)header; - unsigned int init, targ, total_size, ipds, tpds; + unsigned int init, targ, pass, p_node, total_size, ipds, tpds; u32 *inits, *targs, value; u16 *entries; u8 type; @@ -87,12 +143,28 @@ static __init int hmat_parse_locality(union acpi_subtable_headers *header, targs = &inits[ipds]; entries = (u16 *)(&targs[tpds]); for (targ = 0; targ < tpds; targ++) { - for (init = 0; init < ipds; init++) { - value = entries[init * tpds + targ]; - value = (value * loc->entry_base_unit) / 10; - pr_info(" Initiator-Target[%d-%d]:%d%s\n", - inits[init], targs[targ], value, - hmat_data_type_suffix(type)); + u32 best = 0; + + t = find_mem_target(targs[targ]); + for (pass = 0; pass < 2; pass++) { + for (init = 0; init < ipds; init++) { + value = entries[init * tpds + targ]; + value = (value * loc->entry_base_unit) / 10; + + if (!pass) { + hmat_update_access(type, value, &best); + pr_info(" Initiator-Target[%d-%d]:%d%s\n", + inits[init], targs[targ], value, + hmat_data_type_suffix(type)); + continue; + } + + if (!t) + continue; + p_node = pxm_to_node(inits[init]); + if (p_node != NUMA_NO_NODE && value == best) + set_bit(p_node, t->p_nodes); + } } } return 0; @@ -122,6 +194,7 @@ static int __init hmat_parse_address_range(union acpi_subtable_headers *header, const unsigned long end) { struct acpi_hmat_address_range *spa = (void *)header; + struct memory_target *t = NULL; if (spa->header.length != sizeof(*spa)) { pr_err("HMAT: Unexpected address range header length: %d\n", @@ -131,6 +204,23 @@ static int __init hmat_parse_address_range(union acpi_subtable_headers *header, pr_info("HMAT: Memory (%#llx length %#llx) Flags:%04x Processor Domain:%d Memory Domain:%d\n", spa->physical_address_base, spa->physical_address_length, spa->flags, spa->processor_PD, spa->memory_PD); + + if (spa->flags & ACPI_HMAT_MEMORY_PD_VALID) { + t = find_mem_target(spa->memory_PD); + if (!t) { + pr_warn("HMAT: Memory Domain missing from SRAT\n"); + return -EINVAL; + } + } + if (t && spa->flags & ACPI_HMAT_PROCESSOR_PD_VALID) { + int p_node = pxm_to_node(spa->processor_PD); + + if (p_node == NUMA_NO_NODE) { + pr_warn("HMAT: Invalid Processor Domain\n"); + return -EINVAL; + } + set_bit(p_node, t->p_nodes); + } return 0; } @@ -154,6 +244,33 @@ static int __init hmat_parse_subtable(union acpi_subtable_headers *header, } } +static __init int srat_parse_mem_affinity(union acpi_subtable_headers *header, + const unsigned long end) +{ + struct acpi_srat_mem_affinity *ma = (void *)header; + + if (!ma) + return -EINVAL; + if (!(ma->flags & ACPI_SRAT_MEM_ENABLED)) + return 0; + alloc_memory_target(ma->proximity_domain); + return 0; +} + +static __init void hmat_register_targets(void) +{ + struct memory_target *t, *next; + unsigned m, p; + + list_for_each_entry_safe(t, next, &targets, node) { + list_del(&t->node); + m = pxm_to_node(t->memory_pxm); + for_each_set_bit(p, t->p_nodes, MAX_NUMNODES) + register_memory_node_under_compute_node(m, p, 0); + kfree(t); + } +} + static __init int hmat_init(void) { struct acpi_table_header *tbl; @@ -163,6 +280,17 @@ static __init int hmat_init(void) if (srat_disabled()) return 0; + status = acpi_get_table(ACPI_SIG_SRAT, 0, &tbl); + if (ACPI_FAILURE(status)) + return 0; + + if (acpi_table_parse_entries(ACPI_SIG_SRAT, + sizeof(struct acpi_table_srat), + ACPI_SRAT_TYPE_MEMORY_AFFINITY, + srat_parse_mem_affinity, 0) < 0) + goto out_put; + acpi_put_table(tbl); + status = acpi_get_table(ACPI_SIG_HMAT, 0, &tbl); if (ACPI_FAILURE(status)) return 0; @@ -173,6 +301,7 @@ static __init int hmat_init(void) hmat_parse_subtable, 0) < 0) goto out_put; } + hmat_register_targets(); out_put: acpi_put_table(tbl); return 0;