From patchwork Wed Nov 14 22:49:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Busch X-Patchwork-Id: 10683281 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 C697513BF for ; Wed, 14 Nov 2018 22:53:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B91662BF63 for ; Wed, 14 Nov 2018 22:53:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ACB7E2BF72; Wed, 14 Nov 2018 22:53:06 +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=unavailable 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 4E84A2BF63 for ; Wed, 14 Nov 2018 22:53:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 856206B000D; Wed, 14 Nov 2018 17:53:05 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 82AB56B0010; Wed, 14 Nov 2018 17:53:05 -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 7682E6B0266; Wed, 14 Nov 2018 17:53:05 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) by kanga.kvack.org (Postfix) with ESMTP id 38A166B000D for ; Wed, 14 Nov 2018 17:53:05 -0500 (EST) Received: by mail-pg1-f198.google.com with SMTP id o17so11668045pgi.14 for ; Wed, 14 Nov 2018 14:53:05 -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; bh=Orzuppehbwr3wUGAz4EG7X6hYP4dXMeAD7PanJMphhU=; b=K5usA2DYN9ujMAaCsYzz78Lau3O2QzZJSASVSPrs7q267oBZBZnQiXgSIH5a3D4Lbq S2DJyJikeQKaiKQ6e8C13imUjL+QCwoRlG0zrAPyMxoXt0sVhf+VSCRngBWRSj31/3Bc hCrm6aBEV3XQDpcSACXOXrxVJtU3TAlIz49q2cfZ1NdX3SA8NIez2GZIIPkBZ7kge/d4 DDs0ivgfCypR/W5cjLmJ2BeeLoWQAHk14QHlnQU9+Lh0nMRI20BE9ilN9n7isxQ1QjiA SB2/a/bg+3oUsBpGnPSi565QsxHqFBV7/uTD0/LOl6ge/c7rdK2/79g+DLX3UKt2nmrm YOZA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of keith.busch@intel.com designates 134.134.136.100 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: AGRZ1gLKw+rxH2oWR2vragdmpyiseDLg+ZQB+nz/luksROnA0NqpHnz9 Ku3n0P0iCGYpeWyGGimA/DWlV8KcaNdweFj/1euCwQM/1PhdtN1bzube6DnzQuvA7tRfZbGnM4w ZNAVa5KWxGQHi34uvdFAnmZ4Aqme2fZ/ac4f//6dICi//eerw8dlNhPlObfj9df7FxQ== X-Received: by 2002:a62:cd89:: with SMTP id o131mr3854272pfg.222.1542235984889; Wed, 14 Nov 2018 14:53:04 -0800 (PST) X-Google-Smtp-Source: AJdET5dj01zDT9LxqHtuIoTg8rVXvMvU6If43f4751DiVAewDd5+GD/p0X0gbXMIS9VswzxSOJCT X-Received: by 2002:a62:cd89:: with SMTP id o131mr3854221pfg.222.1542235983764; Wed, 14 Nov 2018 14:53:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542235983; cv=none; d=google.com; s=arc-20160816; b=kFIryPlbqjEdo3mNq9B8PDMTDgtPOp7DZrLyq0NzzuyDvScYwu8qi8Pb4Kv5xfGHAD iw9WOzSdeUo3CD4TjPjtJbIK5yz/HRwhNQ1OY3KMJkX+z3owlmHuhAHPsr8w1whIWAA8 pen+QtS5MAim+rL2DXSzqKFM5cxMpMfXx15l69Q3oY9wrV4g2pnYWxqubyYfQTbXPxjy MARF5Anre/3SDMqq64Ja7t52D4z10Zu5P3M3lMKJv2Wy+JICgqKu+ic2XWrtM105IoQd KhfOO/e6isj9gZgq6Ll4l38zI60zjX+jgh7+2w+VhbwdUmtYbtYCkpWFZMsmoLS2F2Tb Nfzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from; bh=Orzuppehbwr3wUGAz4EG7X6hYP4dXMeAD7PanJMphhU=; b=zEXo+qFaKHfvu2lTSzWpCQaQjt/pGm7KlmJP6o9+W5nStktHyfbGXolMoLP9hSSWUY /XFCJurTdJSx+906NswGNm+rYr095O4kGrl71qIv5w3dra0EyGueC2MNHTmUqRRb8R1S VeOZqyEQl/eeOXVuOAJemXEQw4ycDAc8fp5cy7a1cvOHF27WzIGvCmNvqZ6e5TtsLjyz GXK66bFmo/dC798q+w5DJ8wpIftIdYsrH/v8lp4helWFQO7Mg23lx99WJY1+cmcJpnLu hJ5vHs5jZwoy+dTpO8d+fiMBBJfPs4vRQZ4G/B9k51Ik/eW2TzzBqREqcT11RwD4XUWj ARmA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of keith.busch@intel.com designates 134.134.136.100 as permitted sender) smtp.mailfrom=keith.busch@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga07.intel.com (mga07.intel.com. [134.134.136.100]) by mx.google.com with ESMTPS id l13-v6si29485562pls.222.2018.11.14.14.53.03 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 14:53:03 -0800 (PST) Received-SPF: pass (google.com: domain of keith.busch@intel.com designates 134.134.136.100 as permitted sender) client-ip=134.134.136.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of keith.busch@intel.com designates 134.134.136.100 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 fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Nov 2018 14:53:03 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,234,1539673200"; d="scan'208";a="106314877" Received: from unknown (HELO localhost.lm.intel.com) ([10.232.112.69]) by fmsmga004.fm.intel.com with ESMTP; 14 Nov 2018 14:53:02 -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: [PATCH 1/7] node: Link memory nodes to their compute nodes Date: Wed, 14 Nov 2018 15:49:14 -0700 Message-Id: <20181114224921.12123-2-keith.busch@intel.com> X-Mailer: git-send-email 2.13.6 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 Memory-only nodes will often have affinity to a compute node, and platforms have ways to express that locality relationship. A node containing CPUs or other DMA devices that can initiate memory access are referred to as "memory iniators". A "memory target" is a node that provides at least one phyiscal address range accessible to a memory initiator. In preparation for these systems, provide a new kernel API to link the target memory node to its initiator compute node with symlinks to each other. The following example shows the new sysfs hierarchy setup for memory node 'Y' local to commpute node 'X': # ls -l /sys/devices/system/node/nodeX/initiator* /sys/devices/system/node/nodeX/targetY -> ../nodeY # ls -l /sys/devices/system/node/nodeY/target* /sys/devices/system/node/nodeY/initiatorX -> ../nodeX Signed-off-by: Keith Busch --- drivers/base/node.c | 32 ++++++++++++++++++++++++++++++++ include/linux/node.h | 2 ++ 2 files changed, 34 insertions(+) diff --git a/drivers/base/node.c b/drivers/base/node.c index 86d6cd92ce3d..a9b7512a9502 100644 --- a/drivers/base/node.c +++ b/drivers/base/node.c @@ -372,6 +372,38 @@ int register_cpu_under_node(unsigned int cpu, unsigned int nid) kobject_name(&node_devices[nid]->dev.kobj)); } +int register_memory_node_under_compute_node(unsigned int m, unsigned int p) +{ + int ret; + char initiator[20], target[17]; + + if (!node_online(p) || !node_online(m)) + return -ENODEV; + if (m == p) + return 0; + + snprintf(initiator, sizeof(initiator), "initiator%d", p); + snprintf(target, sizeof(target), "target%d", m); + + ret = sysfs_create_link(&node_devices[p]->dev.kobj, + &node_devices[m]->dev.kobj, + target); + if (ret) + return ret; + + ret = sysfs_create_link(&node_devices[m]->dev.kobj, + &node_devices[p]->dev.kobj, + initiator); + if (ret) + goto err; + + return 0; + err: + sysfs_remove_link(&node_devices[p]->dev.kobj, + kobject_name(&node_devices[m]->dev.kobj)); + return ret; +} + int unregister_cpu_under_node(unsigned int cpu, unsigned int nid) { struct device *obj; diff --git a/include/linux/node.h b/include/linux/node.h index 257bb3d6d014..1fd734a3fb3f 100644 --- a/include/linux/node.h +++ b/include/linux/node.h @@ -75,6 +75,8 @@ extern int register_mem_sect_under_node(struct memory_block *mem_blk, extern int unregister_mem_sect_under_nodes(struct memory_block *mem_blk, unsigned long phys_index); +extern int register_memory_node_under_compute_node(unsigned int m, unsigned int p); + #ifdef CONFIG_HUGETLBFS extern void register_hugetlbfs_with_node(node_registration_func_t doregister, node_registration_func_t unregister); From patchwork Wed Nov 14 22:49:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Busch X-Patchwork-Id: 10683287 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 885E714DB for ; Wed, 14 Nov 2018 22:53:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7AC662BF63 for ; Wed, 14 Nov 2018 22:53:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6EB692BF72; Wed, 14 Nov 2018 22:53:14 +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 45DBF2BF6C for ; Wed, 14 Nov 2018 22:53:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BFE876B000E; Wed, 14 Nov 2018 17:53:05 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id BADCF6B0010; Wed, 14 Nov 2018 17:53:05 -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 AC3966B0269; Wed, 14 Nov 2018 17:53:05 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) by kanga.kvack.org (Postfix) with ESMTP id 686CB6B000E for ; Wed, 14 Nov 2018 17:53:05 -0500 (EST) Received: by mail-pl1-f197.google.com with SMTP id 3-v6so13032891plc.18 for ; Wed, 14 Nov 2018 14:53:05 -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=uomT9v05vZAaXeVUOnsSDwp76t0wXbO3YcrWMzwG5t0=; b=Pe7qR2wmMgXeY+J2RDazmxsO70ZNfOhrjbyiZWilX2VHI21jaGyJs7TdliSWoBmzlS x7XPFzx9R11j1Iv/UbQfZDvr5G5PZa1p8Jes5y0aVPDq0+WTHM2DjlfSdU9axykWTIOf ZWBWgRVexB2LC9RavjNUTZ4s4LJjd6de8lkKlGQq6OjS+oyy7x7WA9M1rLJIqQ44zzCX C1Ue02FgfhgOw4wixMvB7WwNMG0pCbLbv25fSJCm/F3qdtfwQ1exWMrj8RSYFn5RQIdF f75uM/slj416ki/HS0nk1zIv0XLrx78vlZ7OMc6N5wDqfiB2zVAzR2q3MgYtIazoMcMI 9ulA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of keith.busch@intel.com designates 134.134.136.100 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: AGRZ1gIfTGl3WTaIZG9jU15XjEAfM8zxfypJz5sjMuqTb5dVy9ll8GHF +ubR33uPt9L9koQlpOQvV+Ol5ByNf999v58kgNHXMvcOkubRCQ/1pEj7aEK9d3rZlEkn/EjbDpz lbY1I2kgQ4lOf7E8GWeG0rMkRHyaISaQNiA5+ThdMTORLpqAsdbbUgKPNhouZ6OaiKQ== X-Received: by 2002:a17:902:6801:: with SMTP id h1-v6mr3723065plk.177.1542235985065; Wed, 14 Nov 2018 14:53:05 -0800 (PST) X-Google-Smtp-Source: AJdET5eub5c468shlIQQ6jDgU3J0YVKK7ap7wWgZixYmNvZ32rhXsQYRtfu7edQbSkp/WuIyXRHW X-Received: by 2002:a17:902:6801:: with SMTP id h1-v6mr3723011plk.177.1542235984000; Wed, 14 Nov 2018 14:53:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542235983; cv=none; d=google.com; s=arc-20160816; b=R3tso+c2xBRHyg/R09MTPQNFkn73na2iSd0xZWoP59B4985LjGomUFSJrFH/hgJ2aw peHQ4ooeoUtkZmaoUV1S23Z4FzcauWhdj6viqzq24sxFoR37A/sQK9hSO138zgA+dD7P LQg4KpIY1n4ymGJKTorDJCXn9G2R0zcP8PENTsnLWU2eG0+APC6ZlfJHug8qkuVeuh4T ZDUYOm7h/HWJzztHTGWLT9wTDHca1jPQeALNkA45UUckD6qzwKsmeLQ2d3F115hjIt9E dETUBJPPqid9QuFCK8ZEUFb88Et6LG2rdu0le6InnR0XAHpmvFeDeaX/omXAS63NUiwv +R3w== 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=uomT9v05vZAaXeVUOnsSDwp76t0wXbO3YcrWMzwG5t0=; b=XYzuc6Gt8mHEzc61D8j/ib3eWAXFB/rFW6MVNhGFyHWAyESOpB2vLPtCAIsVlXK1Ur lFmtN75ah52lh+J6zmLdUqGEqyonwYuOLfzx4W6EhQQljs1mHL6xuxng5vgZb+4p8uYg zVeYxFvfDruuz6SUx8wuqJl5JTh/yXMh0WZGpCxwGrChcXwp4DZ1FyK1wgFKFYDsuZ44 3TW05gFLErq3ZlBr4EmYCPL56KJOuTDENcV1KjhWrDObDA5ETszyxJusA3ZHHYQeWTJw QofIUEocx0/V+aTHh3wyaUamSKGEeufvdLqcIhZ66srTCnA/I2BuYMjlFoYBb4BXo2oN P6Kg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of keith.busch@intel.com designates 134.134.136.100 as permitted sender) smtp.mailfrom=keith.busch@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga07.intel.com (mga07.intel.com. [134.134.136.100]) by mx.google.com with ESMTPS id l13-v6si29485562pls.222.2018.11.14.14.53.03 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 14:53:03 -0800 (PST) Received-SPF: pass (google.com: domain of keith.busch@intel.com designates 134.134.136.100 as permitted sender) client-ip=134.134.136.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of keith.busch@intel.com designates 134.134.136.100 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 fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Nov 2018 14:53:03 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,234,1539673200"; d="scan'208";a="106314880" Received: from unknown (HELO localhost.lm.intel.com) ([10.232.112.69]) by fmsmga004.fm.intel.com with ESMTP; 14 Nov 2018 14:53:02 -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: [PATCH 2/7] node: Add heterogenous memory performance Date: Wed, 14 Nov 2018 15:49:15 -0700 Message-Id: <20181114224921.12123-3-keith.busch@intel.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20181114224921.12123-2-keith.busch@intel.com> References: <20181114224921.12123-2-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 Heterogeneous memory systems provide memory nodes with latency and bandwidth performance attributes that are different from other nodes. Create an interface for the kernel to register these attributes under the node that provides the memory. If the system provides this information, applications can query the node attributes when deciding which node to request memory. When multiple memory initiators exist, accessing the same memory target from each may not perform the same as the other. The highest performing initiator to a given target is considered to be a local initiator for that target. The kernel provides performance attributes only for the local initiators. The memory's compute node should be symlinked in sysfs as one of the node's initiators. The following example shows the new sysfs hierarchy for a node exporting performance attributes: # tree /sys/devices/system/node/nodeY/initiator_access /sys/devices/system/node/nodeY/initiator_access |-- read_bandwidth |-- read_latency |-- write_bandwidth `-- write_latency The bandwidth is exported as MB/s and latency is reported in nanoseconds. Signed-off-by: Keith Busch --- drivers/base/Kconfig | 8 ++++++++ drivers/base/node.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/node.h | 22 ++++++++++++++++++++++ 3 files changed, 74 insertions(+) diff --git a/drivers/base/Kconfig b/drivers/base/Kconfig index ae213ed2a7c8..2cf67c80046d 100644 --- a/drivers/base/Kconfig +++ b/drivers/base/Kconfig @@ -149,6 +149,14 @@ config DEBUG_TEST_DRIVER_REMOVE unusable. You should say N here unless you are explicitly looking to test this functionality. +config HMEM + bool + default y + depends on NUMA + help + Enable reporting for heterogenous memory access attributes under + their non-uniform memory nodes. + source "drivers/base/test/Kconfig" config SYS_HYPERVISOR diff --git a/drivers/base/node.c b/drivers/base/node.c index a9b7512a9502..232535761998 100644 --- a/drivers/base/node.c +++ b/drivers/base/node.c @@ -59,6 +59,50 @@ static inline ssize_t node_read_cpulist(struct device *dev, static DEVICE_ATTR(cpumap, S_IRUGO, node_read_cpumask, NULL); static DEVICE_ATTR(cpulist, S_IRUGO, node_read_cpulist, NULL); +#ifdef CONFIG_HMEM +const struct attribute_group node_access_attrs_group; + +#define ACCESS_ATTR(name) \ +static ssize_t name##_show(struct device *dev, \ + struct device_attribute *attr, \ + char *buf) \ +{ \ + return sprintf(buf, "%d\n", to_node(dev)->hmem_attrs.name); \ +} \ +static DEVICE_ATTR_RO(name); + +ACCESS_ATTR(read_bandwidth) +ACCESS_ATTR(read_latency) +ACCESS_ATTR(write_bandwidth) +ACCESS_ATTR(write_latency) + +static struct attribute *access_attrs[] = { + &dev_attr_read_bandwidth.attr, + &dev_attr_read_latency.attr, + &dev_attr_write_bandwidth.attr, + &dev_attr_write_latency.attr, + NULL, +}; + +const struct attribute_group node_access_attrs_group = { + .name = "initiator_access", + .attrs = access_attrs, +}; + +void node_set_perf_attrs(unsigned int nid, struct node_hmem_attrs *hmem_attrs) +{ + struct node *node; + + if (WARN_ON_ONCE(!node_online(nid))) + return; + node = node_devices[nid]; + node->hmem_attrs = *hmem_attrs; + if (sysfs_create_group(&node->dev.kobj, &node_access_attrs_group)) + pr_info("failed to add performance attribute group to node %d\n", + nid); +} +#endif + #define K(x) ((x) << (PAGE_SHIFT - 10)) static ssize_t node_read_meminfo(struct device *dev, struct device_attribute *attr, char *buf) diff --git a/include/linux/node.h b/include/linux/node.h index 1fd734a3fb3f..6a1aa6a153f8 100644 --- a/include/linux/node.h +++ b/include/linux/node.h @@ -17,14 +17,36 @@ #include #include +#include #include +#ifdef CONFIG_HMEM +/** + * struct node_hmem_attrs - heterogeneous memory performance attributes + * + * read_bandwidth: Read bandwidth in MB/s + * write_bandwidth: Write bandwidth in MB/s + * read_latency: Read latency in nanoseconds + * write_latency: Write latency in nanoseconds + */ +struct node_hmem_attrs { + unsigned int read_bandwidth; + unsigned int write_bandwidth; + unsigned int read_latency; + unsigned int write_latency; +}; +void node_set_perf_attrs(unsigned int nid, struct node_hmem_attrs *hmem_attrs); +#endif + struct node { struct device dev; #if defined(CONFIG_MEMORY_HOTPLUG_SPARSE) && defined(CONFIG_HUGETLBFS) struct work_struct node_work; #endif +#ifdef CONFIG_HMEM + struct node_hmem_attrs hmem_attrs; +#endif }; struct memory_block; From patchwork Wed Nov 14 22:49:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Busch X-Patchwork-Id: 10683283 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 3A6B613BF for ; Wed, 14 Nov 2018 22:53:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2C66D2BF63 for ; Wed, 14 Nov 2018 22:53:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2083B2BF72; Wed, 14 Nov 2018 22:53:11 +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 9B3172BF63 for ; Wed, 14 Nov 2018 22:53:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2D73F6B0010; Wed, 14 Nov 2018 17:53:06 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2897B6B0269; Wed, 14 Nov 2018 17:53:05 -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 E01D06B026B; Wed, 14 Nov 2018 17:53:05 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) by kanga.kvack.org (Postfix) with ESMTP id 90C0E6B0266 for ; Wed, 14 Nov 2018 17:53:05 -0500 (EST) Received: by mail-pl1-f200.google.com with SMTP id o23so1838015pll.0 for ; Wed, 14 Nov 2018 14:53:05 -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=kZPMrQy2nfA6gzJ9Y/qbpquyF/ltUnixCoh32oReZj8=; b=m+Vk/V2c+QDSjWYF+401oP2ys7b8Zx4o+1Ml0ZPt4Rq8Mk/Pi3ehU8UaU0EjaaoMYe mzLabFqwm/V7GIBwkmmCPgtUbf93sPmCb+G92XPC6GbNQ79JCHi5lRdMCySJV1pSbhQr 5FgtSZC8OkrOC/pNFg4sHHJ+lnmEiw5FKGtOgcKhLD9xcOHccap/VrgdqDG2tqA1V4La 5NmmFSuJGC8qJ6VgUZjlsKJt6yiQp11x5et++AM87QPgbIsvU9jwRgQ3GzK9qeQ7s7lS kRzIiJc7rsDlOmdCE1Uaos7fwHD1zsF4/dRQ4aoaJrMn8JQi0jIt7X2dJ/tFkFKzIM+V hw3Q== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of keith.busch@intel.com designates 134.134.136.100 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: AGRZ1gKR9brnT6isWARlFwZqkoUS/s2th2Mn9YyAQIWEpMwP/Lmgw4q9 yn2dEnQH8mmaofSBG9bqTdf81PNqTldF6q/oO65sfXopzJh5bWU2d5IqBDYLZkTRXAXWGkpVJ5R SGrsAbiOUc8RG+W51LUq+zIiqkJskOO6CyTVAkMeXbQNj4yT6AXsIsIO4W5hh+wfEaA== X-Received: by 2002:a62:8d51:: with SMTP id z78-v6mr3835808pfd.234.1542235985218; Wed, 14 Nov 2018 14:53:05 -0800 (PST) X-Google-Smtp-Source: AJdET5e26F/stfR5fymaRQmE9nm7IzT95FvgCA0Yg7PrOM3ZEnHvrsuS+/+r7lh4F0IN2IL7F6O6 X-Received: by 2002:a62:8d51:: with SMTP id z78-v6mr3835757pfd.234.1542235984207; Wed, 14 Nov 2018 14:53:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542235984; cv=none; d=google.com; s=arc-20160816; b=VUm6AXDblhVN1Azy6OrJroH2xz2bqSt25GRdp8/yKQMqdE4fy0P9UbeSKHpDHrMenI CF0R+8MpC1rYWThe5GDOzUFf0F8wvG60fPCl0wwr3sMp5hU9HZoUemKr7D1yfq1r8c5H ismL263yfoq9f/lTpMdwJbWZMtyi++9Koi67B3QtX0BCBFRSCP73dIhQhBzlk9RJHPO+ QebsgsEa/F7Xbq+aBhAchteKRz/PsQaundlIDwJcnl4WL1znsjkTaKsSZoGlge9KA4KE ijyRxe4EbJxnc4aEBGno3bvLZNxs+O595Usr7q/6FPXZlUJBhK4/wvm1sK/d7Pz9BbSK P6Bw== 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=kZPMrQy2nfA6gzJ9Y/qbpquyF/ltUnixCoh32oReZj8=; b=b0E3elEQYOa/Gc4tjlMilJSokTLL/gQbDGfNh0o7nrvysQKmOW3aSqR/uLrhK0xJj1 wwY1+bQ7f+tlDfEnZCtgGhHpmcxD9durvPwwhMbXtpBTqD97ZDmDSfJuRFtCH8RvYzdO 1MPaiQiKIaEhb/hBLaPPohNaWXbYXu2LA/h0yFlLiP4ULrLy0rlgxm2cn+6DAdaW56gd hLQ8cUnX2Uxubdq5NS3R7RzHATmniNw4xPulMKuqCUhSjSAH/nX6OsNlzWabfKJ311U+ DGMK1bWAJFbP3+vDJGDh6cYNoU2JGXXjgcItn4h6kT4IiquJSAyUJLKo3pqMaKWFkGVO qgtw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of keith.busch@intel.com designates 134.134.136.100 as permitted sender) smtp.mailfrom=keith.busch@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga07.intel.com (mga07.intel.com. [134.134.136.100]) by mx.google.com with ESMTPS id l13-v6si29485562pls.222.2018.11.14.14.53.04 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 14:53:04 -0800 (PST) Received-SPF: pass (google.com: domain of keith.busch@intel.com designates 134.134.136.100 as permitted sender) client-ip=134.134.136.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of keith.busch@intel.com designates 134.134.136.100 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 fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Nov 2018 14:53:03 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,234,1539673200"; d="scan'208";a="106314883" Received: from unknown (HELO localhost.lm.intel.com) ([10.232.112.69]) by fmsmga004.fm.intel.com with ESMTP; 14 Nov 2018 14:53:03 -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: [PATCH 3/7] doc/vm: New documentation for memory performance Date: Wed, 14 Nov 2018 15:49:16 -0700 Message-Id: <20181114224921.12123-4-keith.busch@intel.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20181114224921.12123-2-keith.busch@intel.com> References: <20181114224921.12123-2-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 Platforms may provide system memory where some physical address ranges perform differently than others. These heterogeneous memory attributes are common to the node that provides the memory and exported by the kernel. Add new documentation providing a brief overview of such systems and the attributes the kernel makes available to aid applications wishing to query this information. Signed-off-by: Keith Busch --- Documentation/vm/numaperf.rst | 71 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 Documentation/vm/numaperf.rst diff --git a/Documentation/vm/numaperf.rst b/Documentation/vm/numaperf.rst new file mode 100644 index 000000000000..5a3ecaff5474 --- /dev/null +++ b/Documentation/vm/numaperf.rst @@ -0,0 +1,71 @@ +.. _numaperf: + +================ +NUMA Performance +================ + +Some platforms may have multiple types of memory attached to a single +CPU. These disparate memory ranges share some characteristics, such as +CPU cache coherence, but may have different performance. For example, +different media types and buses affect bandwidth and latency. + +A system supporting such heterogeneous memory groups each memory type +under different "nodes" based on similar CPU locality and performance +characteristics. Some memory may share the same node as a CPU, and +others are provided as memory-only nodes. While memory only nodes do not +provide CPUs, they may still be local to one or more compute nodes. The +following diagram shows one such example of two compute noes with local +memory and a memory only node for each of compute node: + + +------------------+ +------------------+ + | Compute Node 0 +-----+ Compute Node 1 | + | Local Node0 Mem | | Local Node1 Mem | + +--------+---------+ +--------+---------+ + | | + +--------+---------+ +--------+---------+ + | Slower Node2 Mem | | Slower Node3 Mem | + +------------------+ +--------+---------+ + +A "memory initiator" is a node containing one or more devices such as +CPUs or separate memory I/O devices that can initiate memory requests. A +"memory target" is a node containing one or more CPU-accessible physical +address ranges. + +When multiple memory initiators exist, accessing the same memory +target may not perform the same as each other. The highest performing +initiator to a given target is considered to be one of that target's +local initiators. + +To aid applications matching memory targets with their initiators, +the kernel provide symlinks to each other like the following example:: + + # ls -l /sys/devices/system/node/nodeX/initiator* + /sys/devices/system/node/nodeX/targetY -> ../nodeY + + # ls -l /sys/devices/system/node/nodeY/target* + /sys/devices/system/node/nodeY/initiatorX -> ../nodeX + +Applications may wish to consider which node they want their memory to +be allocated from based on the nodes performance characteristics. If +the system provides these attributes, the kernel exports them under the +node sysfs hierarchy by appending the initiator_access directory under +the node as follows:: + + /sys/devices/system/node/nodeY/initiator_access/ + +The kernel does not provide performance attributes for non-local memory +initiators. The performance characteristics the kernel provides for +the local initiators are exported are as follows:: + + # tree /sys/devices/system/node/nodeY/initiator_access + /sys/devices/system/node/nodeY/initiator_access + |-- read_bandwidth + |-- read_latency + |-- write_bandwidth + `-- write_latency + +The bandwidth attributes are provided in MiB/second. + +The latency attributes are provided in nanoseconds. + +See also: https://www.uefi.org/sites/default/files/resources/ACPI_6_2.pdf From patchwork Wed Nov 14 22:49:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Busch X-Patchwork-Id: 10683285 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 B570E14DB for ; Wed, 14 Nov 2018 22:53:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A81E92BF63 for ; Wed, 14 Nov 2018 22:53:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9CB862BF77; Wed, 14 Nov 2018 22:53:13 +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 DE7C22BF63 for ; Wed, 14 Nov 2018 22:53:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6D3526B026C; Wed, 14 Nov 2018 17:53:06 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 631D36B0269; Wed, 14 Nov 2018 17:53:06 -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 323096B026C; Wed, 14 Nov 2018 17:53:06 -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 D91586B026A for ; Wed, 14 Nov 2018 17:53:05 -0500 (EST) Received: by mail-pg1-f200.google.com with SMTP id r16-v6so11632526pgv.17 for ; Wed, 14 Nov 2018 14:53:05 -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=hih7AqRA4ilN9FXKggT4jquN+CIWJyp/whuuUm6DMQE=; b=sLvC3VCtLtMv6WctW2ZwmpnETpPmGLvrb5c6XYy5Rkz2mj67bxk+cDdkUl33esFr8z vyWw6DkgpySmOjQIw5kPLUVEeMnbb/tAD8BdqFjoCHm54czSGx3g8h42pepUxTasDDsA XEZrrygld0WVOIDCEXy1M4wqOPJNtTRI6LTytbIuqHdhe+oCnAYFrQ34A3kB9zMGwChV k4sNZq1s+GLL6zguTk7eW1sxRCQyd8850esw/dLZ+kavgcwyFIEKcATxbb2R3FFO/MJQ TaRid10iBgqDCENzSsF6PvGTET2HjrZx7qe2c8GlVOphufCdNzRQadYPukc4QrMcVd05 rogw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of keith.busch@intel.com designates 134.134.136.100 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: AGRZ1gIBS/lvw6jmxm2ImfCWJAT7AU1r4kx/ugtafZ4OGxJafDTKjbgq 33YvSbNQSDtYDqSSqeyug7EihAvQJI8L8fAUagEm/fHfHdUyzWCAuV8GO/u8h1KmtAne3cijnjP eG2fkbgQMRJ1Q8rzHlioDQ6ACUeM48UdnCTiEex9SrftQHPl8vAF9xRzDeP8QKouiLg== X-Received: by 2002:a62:2095:: with SMTP id m21-v6mr3877902pfj.32.1542235985523; Wed, 14 Nov 2018 14:53:05 -0800 (PST) X-Google-Smtp-Source: AJdET5eHAsb7wrwswAppEso8054swCf1ir+hcZkrXx8DWhMcOVqRsXrqguDQonJlyL5J8wKSQP6o X-Received: by 2002:a62:2095:: with SMTP id m21-v6mr3877857pfj.32.1542235984615; Wed, 14 Nov 2018 14:53:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542235984; cv=none; d=google.com; s=arc-20160816; b=mu+mXEdXFXOb3sKSMI1ByhfySioeT3LHlcwiKKWDII1nIw0jExLMWbAhmXkSxAScd4 m0J20IHWvCOzM0QB9fCFS61PTR09wvoq1O8yKH9NGjAxklslC3hNjN9rI4fHBndnWLmH iWjUvBQH887E1cAQOLQ1gHQsS2w5WW1y0OXqGuXlKgz7j+GvHD4NQhXSwp/VrGBz5Z93 MeFliGvoWGQtnDa3lSQl6FQOkdepKwIE0DNJgbxQ369UdWKe0yX5G4m7oFIiTIv2q5Mn 2LjHJ5AFHilqW7hT5KGQR/CmNZKGan2LPM1PyLwJx/MxlFZ5jfYmxcMskpI8QvjvSx2n 8Xlg== 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=hih7AqRA4ilN9FXKggT4jquN+CIWJyp/whuuUm6DMQE=; b=yftCaNzlkknfqs+EASVCWAsOsvjtkvzbgVkl/zucA/i02Fhu7vaXxW5MTmytLDeH0S jYuL+HGATm0G2tD9vL1nuPLCFghx6pnxPFNmg1zJSAFui8Ckk/ULruCRYQSEujmP8RX0 foFqhFzYHci0s8hzk5N79mSLa4jRIdAACLATzz/DiCU4cT+H4UoyoQXPsr1K37HJh6q+ FJonGWB/I0vHiPUsX1WhefMde670jXmn3OtgGzfCFnx//5XY/5mfsf3cfrMx9lORpcbh 26zEWvfqT00bfyGml31y8StfSaJry2dVDkCCwaPsPztLIB1w6SDiesNdDpHFIKg8kMP4 RibA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of keith.busch@intel.com designates 134.134.136.100 as permitted sender) smtp.mailfrom=keith.busch@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga07.intel.com (mga07.intel.com. [134.134.136.100]) by mx.google.com with ESMTPS id l13-v6si29485562pls.222.2018.11.14.14.53.04 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 14:53:04 -0800 (PST) Received-SPF: pass (google.com: domain of keith.busch@intel.com designates 134.134.136.100 as permitted sender) client-ip=134.134.136.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of keith.busch@intel.com designates 134.134.136.100 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 fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Nov 2018 14:53:03 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,234,1539673200"; d="scan'208";a="106314887" Received: from unknown (HELO localhost.lm.intel.com) ([10.232.112.69]) by fmsmga004.fm.intel.com with ESMTP; 14 Nov 2018 14:53:03 -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: [PATCH 4/7] node: Add memory caching attributes Date: Wed, 14 Nov 2018 15:49:17 -0700 Message-Id: <20181114224921.12123-5-keith.busch@intel.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20181114224921.12123-2-keith.busch@intel.com> References: <20181114224921.12123-2-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 System memory may have side caches to help improve access speed. While the system provided cache is transparent to the software accessing these memory ranges, applications can optimize their own access based on cache attributes. In preparation for such systems, provide a new API for the kernel to register these memory side caches under the memory node that provides it. The kernel's sysfs representation is modeled from the cpu cacheinfo attributes, as seen from /sys/devices/system/cpu/cpuX/cache/. Unlike CPU cacheinfo, though, a higher node's memory cache level is nearer to the CPU, while lower levels are closer to the backing memory. Also unlike CPU cache, the system handles flushing any dirty cached memory to the last level the memory on a power failure if the range is persistent. The exported attributes are the cache size, the line size, associativity, and write back policy. Signed-off-by: Keith Busch --- drivers/base/node.c | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/node.h | 23 ++++++++++ 2 files changed, 140 insertions(+) diff --git a/drivers/base/node.c b/drivers/base/node.c index 232535761998..bb94f1d18115 100644 --- a/drivers/base/node.c +++ b/drivers/base/node.c @@ -60,6 +60,12 @@ static DEVICE_ATTR(cpumap, S_IRUGO, node_read_cpumask, NULL); static DEVICE_ATTR(cpulist, S_IRUGO, node_read_cpulist, NULL); #ifdef CONFIG_HMEM +struct node_cache_obj { + struct kobject kobj; + struct list_head node; + struct node_cache_attrs cache_attrs; +}; + const struct attribute_group node_access_attrs_group; #define ACCESS_ATTR(name) \ @@ -101,6 +107,115 @@ void node_set_perf_attrs(unsigned int nid, struct node_hmem_attrs *hmem_attrs) pr_info("failed to add performance attribute group to node %d\n", nid); } + +struct cache_attribute_entry { + struct attribute attr; + ssize_t (*show)(struct node_cache_attrs *, char *); +}; + +#define CACHE_ATTR(name, fmt) \ +static ssize_t name##_show(struct node_cache_attrs *cache, \ + char *buf) \ +{ \ + return sprintf(buf, fmt "\n", cache->name); \ +} \ +static struct cache_attribute_entry cache_attr_##name = __ATTR_RO(name); + +CACHE_ATTR(size, "%lld") +CACHE_ATTR(level, "%d") +CACHE_ATTR(line_size, "%d") +CACHE_ATTR(associativity, "%d") +CACHE_ATTR(write_policy, "%d") + +static struct attribute *cache_attrs[] = { + &cache_attr_level.attr, + &cache_attr_associativity.attr, + &cache_attr_size.attr, + &cache_attr_line_size.attr, + &cache_attr_write_policy.attr, + NULL, +}; + +static ssize_t cache_attr_show(struct kobject *kobj, struct attribute *attr, + char *page) +{ + struct cache_attribute_entry *entry = + container_of(attr, struct cache_attribute_entry, attr); + struct node_cache_obj *cache_obj = + container_of(kobj, struct node_cache_obj, kobj); + return entry->show(&cache_obj->cache_attrs, page); +} + +static const struct sysfs_ops cache_ops = { + .show = &cache_attr_show, +}; + +static struct kobj_type cache_ktype = { + .default_attrs = cache_attrs, + .sysfs_ops = &cache_ops, +}; + +void node_add_cache(unsigned int nid, struct node_cache_attrs *cache_attrs) +{ + struct node_cache_obj *cache_obj; + struct node *node; + + if (!node_online(nid) || !node_devices[nid]) + return; + + node = node_devices[nid]; + list_for_each_entry(cache_obj, &node->cache_attrs, node) { + if (cache_obj->cache_attrs.level == cache_attrs->level) { + dev_warn(&node->dev, + "attempt to add duplicate cache level:%d\n", + cache_attrs->level); + return; + } + } + + if (!node->cache_kobj) + node->cache_kobj = kobject_create_and_add("cache", + &node->dev.kobj); + if (!node->cache_kobj) + return; + + cache_obj = kzalloc(sizeof(*cache_obj), GFP_KERNEL); + if (!cache_obj) + return; + + cache_obj->cache_attrs = *cache_attrs; + if (kobject_init_and_add(&cache_obj->kobj, &cache_ktype, node->cache_kobj, + "index%d", cache_attrs->level)) { + dev_warn(&node->dev, "failed to add cache level:%d\n", + cache_attrs->level); + kfree(cache_obj); + return; + } + list_add_tail(&cache_obj->node, &node->cache_attrs); +} + +static void node_remove_caches(struct node *node) +{ + struct node_cache_obj *obj, *next; + + if (!node->cache_kobj) + return; + + list_for_each_entry_safe(obj, next, &node->cache_attrs, node) { + list_del(&obj->node); + kobject_put(&obj->kobj); + kfree(obj); + } + kobject_put(node->cache_kobj); +} + +static void node_init_caches(unsigned int nid) +{ + INIT_LIST_HEAD(&node_devices[nid]->cache_attrs); +} +#else +static void node_init_caches(unsigned int nid) { } +static void node_remove_caches(struct node *node) { } #endif #define K(x) ((x) << (PAGE_SHIFT - 10)) @@ -345,6 +460,7 @@ static void node_device_release(struct device *dev) */ flush_work(&node->node_work); #endif + node_remove_caches(node); kfree(node); } @@ -658,6 +774,7 @@ int __register_one_node(int nid) /* initialize work queue for memory hot plug */ init_node_hugetlb_work(nid); + node_init_caches(nid); return error; } diff --git a/include/linux/node.h b/include/linux/node.h index 6a1aa6a153f8..f499a17f84bc 100644 --- a/include/linux/node.h +++ b/include/linux/node.h @@ -36,6 +36,27 @@ struct node_hmem_attrs { unsigned int write_latency; }; void node_set_perf_attrs(unsigned int nid, struct node_hmem_attrs *hmem_attrs); + +enum cache_associativity { + NODE_CACHE_DIRECT_MAP, + NODE_CACHE_INDEXED, + NODE_CACHE_OTHER, +}; + +enum cache_write_policy { + NODE_CACHE_WRITE_BACK, + NODE_CACHE_WRITE_THROUGH, + NODE_CACHE_WRITE_OTHER, +}; + +struct node_cache_attrs { + enum cache_associativity associativity; + enum cache_write_policy write_policy; + u64 size; + u16 line_size; + u8 level; +}; +void node_add_cache(unsigned int nid, struct node_cache_attrs *cache_attrs); #endif struct node { @@ -46,6 +67,8 @@ struct node { #endif #ifdef CONFIG_HMEM struct node_hmem_attrs hmem_attrs; + struct list_head cache_attrs; + struct kobject *cache_kobj; #endif }; From patchwork Wed Nov 14 22:49:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Busch X-Patchwork-Id: 10683291 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 1787D14DB for ; Wed, 14 Nov 2018 22:53:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0AB102BF63 for ; Wed, 14 Nov 2018 22:53:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F37792BF77; Wed, 14 Nov 2018 22:53:15 +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 704482BF6C for ; Wed, 14 Nov 2018 22:53:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8C0276B0266; Wed, 14 Nov 2018 17:53:06 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 859BD6B026D; Wed, 14 Nov 2018 17:53:06 -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 546B16B026A; Wed, 14 Nov 2018 17:53:06 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) by kanga.kvack.org (Postfix) with ESMTP id 099706B0266 for ; Wed, 14 Nov 2018 17:53:06 -0500 (EST) Received: by mail-pl1-f198.google.com with SMTP id t5-v6so13128425plo.2 for ; Wed, 14 Nov 2018 14:53:06 -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=+ITiI+DOKQv2M/zI2RuqPItw78++KPuAgzud/7mnErc=; b=ond62zCUAJRacdj2/01nKiXjT2uRyiCiSK3p5lFuubgShkDslAqgr5sv/NH7t3r1fs I3HWStzuZihM79ZU2I7o3YmYUwSNDGGqMfXJXRHaix86rRQyNLagsZriuZkgCJlHreCd DrtzYXmdHYMzaEhMOap81MId77Xvwxt2v4Y98vbdbEs1sGinHX3ob/E13eiNi69SQyXG WfwIf3aQcLvj+bffo8C2IfncyzlJjiKloH8XAUhEt4rrOKLw73AsqkjKKVr2xM/yfd8J cxxP0g4iZ7Eoc4An1Hlti4OPyNUTEq+kZuivQpYSSyMi8MowHNgpR8fRde2FXf4sK2cw Lw2A== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of keith.busch@intel.com designates 134.134.136.100 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: AGRZ1gIlOtbfi7Uj4NM0GuajhZtsZcnthHPmDfkLAJ+irZ6Vrr4pAaT1 mMYFdzx1W+aor0weJEN7Csi0wnvCLc9VrGBzbiGzzij+l1YAazlA2rlq5t/+Js9fDIacQlYwj5e L0xNnQqIHMLgPULWX6R3Naex9+tZWOSXIWr8Dr3MfmfN/LP0jM0L85deon7y64xvIrQ== X-Received: by 2002:a17:902:8507:: with SMTP id bj7-v6mr3695681plb.99.1542235985694; Wed, 14 Nov 2018 14:53:05 -0800 (PST) X-Google-Smtp-Source: AJdET5fbaRglYQuENMo19k4/Ib8INwe2M0c/BCLy9JRdSZeckMKk5WRRGgRMSLobdtL1I3X2Pha8 X-Received: by 2002:a17:902:8507:: with SMTP id bj7-v6mr3695640plb.99.1542235984789; Wed, 14 Nov 2018 14:53:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542235984; cv=none; d=google.com; s=arc-20160816; b=w4+pMl1oQZibI9Km+lFdXcRd/OeJFRVE2ZOVlo076AGKQT3B8O4NnEHbN9ZHb5pmWs 73nbj76lSuYKXOno1nBN2djDT+9s0Gz2R7VkKtXmFDELw6kmin5Rp9ebsZqMfOdUt+b5 VL93Jw2rzNOOsn5CeMNhLEZwBLgMfqDZun3Q7McUo7VPuV5mqR9ipzKFr6CxbNfimW0g nX6Lp2wQaqWRF5QK2JvbY1E3k8ZXQd+hcFzfmbwozEGe2RX2QD8VayVWdSuVop6ZgWWa A6Mh5iC72Ob7zBRJ7Zu5DQHYJ+Ob2vShOTstqPekXZIYRG3Vbp1CulR60FEjkSatDeAf nuHw== 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=+ITiI+DOKQv2M/zI2RuqPItw78++KPuAgzud/7mnErc=; b=gcn1KYASX4ROQuiRMB5avP66oXH1CSLMcHkcQGdjj5thDLe3Nyw77EFYfqxCJq0LB1 vtENGvGlcCIswIQFX+Q+xvJFbekzyaH9eaHn7iBDAURE6337QsXhJzeDhjw4iH+aygLv 9FDptfCmWPoo44EGucQvJqI0jP+v8VC7IZLLlzw0inXwvCRtvusOMo3TzYw1DlhMZ47l l/+latkYoepeTmWyXgfrza6DhBG8lxhl3pQpZEF1yYObDuFPuz/1yPJ9PZIdyIdyGMm4 vUgB3EYrIf5+3GKRCVU6+EOfaSyHm3C8lQ0Tb+AfG08V4LO9i7pZuyYomAzCfnlYBATe ZCUw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of keith.busch@intel.com designates 134.134.136.100 as permitted sender) smtp.mailfrom=keith.busch@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga07.intel.com (mga07.intel.com. [134.134.136.100]) by mx.google.com with ESMTPS id d10-v6si26779897pla.207.2018.11.14.14.53.04 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 14:53:04 -0800 (PST) Received-SPF: pass (google.com: domain of keith.busch@intel.com designates 134.134.136.100 as permitted sender) client-ip=134.134.136.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of keith.busch@intel.com designates 134.134.136.100 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 fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Nov 2018 14:53:04 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,234,1539673200"; d="scan'208";a="106314891" Received: from unknown (HELO localhost.lm.intel.com) ([10.232.112.69]) by fmsmga004.fm.intel.com with ESMTP; 14 Nov 2018 14:53:04 -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: [PATCH 5/7] doc/vm: New documentation for memory cache Date: Wed, 14 Nov 2018 15:49:18 -0700 Message-Id: <20181114224921.12123-6-keith.busch@intel.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20181114224921.12123-2-keith.busch@intel.com> References: <20181114224921.12123-2-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 Platforms may provide system memory that contains side caches to help spped up access. These memory caches are part of a memory node and the cache attributes are exported by the kernel. Add new documentation providing a brief overview of system memory side caches and the kernel provided attributes for application optimization. Signed-off-by: Keith Busch --- Documentation/vm/numacache.rst | 76 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 Documentation/vm/numacache.rst diff --git a/Documentation/vm/numacache.rst b/Documentation/vm/numacache.rst new file mode 100644 index 000000000000..e79c801b7e3b --- /dev/null +++ b/Documentation/vm/numacache.rst @@ -0,0 +1,76 @@ +.. _numacache: + +========== +NUMA Cache +========== + +System memory may be constructed in a hierarchy of various performing +characteristics in order to provide large address space of slower +performing memory cached by a smaller size of higher performing +memory. The system physical addresses that software is aware of see +is provided by the last memory level in the hierarchy, while higher +performing memory transparently provides caching to slower levels. + +The term "far memory" is used to denote the last level memory in the +hierarchy. Each increasing cache level provides higher performing CPU +access, and the term "near memory" represents the highest level cache +provided by the system. This number is different than CPU caches where +the cache level (ex: L1, L2, L3) uses a CPU centric view with each level +being lower performing and closer to system memory. The memory cache +level is centric to the last level memory, so the higher numbered cache +level denotes memory nearer to the CPU, and further from far memory. + +The memory side caches are not directly addressable by software. When +software accesses a system address, the system will return it from the +near memory cache if it is present. If it is not present, the system +accesses the next level of memory until there is either a hit in that +cache level, or it reaches far memory. + +In order to maximize the performance out of such a setup, software may +wish to query the memory cache attributes. If the system provides a way +to query this information, for example with ACPI HMAT (Heterogeneous +Memory Attribute Table)[1], the kernel will append these attributes to +the NUMA node that provides the memory. + +When the kernel first registers a memory cache with a node, the kernel +will create the following directory:: + + /sys/devices/system/node/nodeX/cache/ + +If that directory is not present, then either the memory does not have +a side cache, or that information is not provided to the kernel. + +The attributes for each level of cache is provided under its cache +level index:: + + /sys/devices/system/node/nodeX/cache/indexA/ + /sys/devices/system/node/nodeX/cache/indexB/ + /sys/devices/system/node/nodeX/cache/indexC/ + +Each cache level's directory provides its attributes. For example, +the following is a single cache level and the attributes available for +software to query:: + + # tree sys/devices/system/node/node0/cache/ + /sys/devices/system/node/node0/cache/ + |-- index1 + | |-- associativity + | |-- level + | |-- line_size + | |-- size + | `-- write_policy + +The cache "associativity" will be 0 if it is a direct-mapped cache, and +non-zero for any other indexed based, multi-way associativity. + +The "level" is the distance from the far memory, and matches the number +appended to its "index" directory. + +The "line_size" is the number of bytes accessed on a cache miss. + +The "size" is the number of bytes provided by this cache level. + +The "write_policy" will be 0 for write-back, and non-zero for +write-through caching. + +[1] https://www.uefi.org/sites/default/files/resources/ACPI_6_2.pdf From patchwork Wed Nov 14 22:49:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Busch X-Patchwork-Id: 10683295 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 BD04E13BF for ; Wed, 14 Nov 2018 22:53:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B04A42BF63 for ; Wed, 14 Nov 2018 22:53:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A48302BF72; Wed, 14 Nov 2018 22:53:18 +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=unavailable 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 2B0962BF63 for ; Wed, 14 Nov 2018 22:53:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C4D8D6B0269; Wed, 14 Nov 2018 17:53:06 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id BFD4A6B026B; Wed, 14 Nov 2018 17:53:06 -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 B15EB6B026A; Wed, 14 Nov 2018 17:53:06 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f200.google.com (mail-pf1-f200.google.com [209.85.210.200]) by kanga.kvack.org (Postfix) with ESMTP id 68CB06B026B for ; Wed, 14 Nov 2018 17:53:06 -0500 (EST) Received: by mail-pf1-f200.google.com with SMTP id a72-v6so14397793pfj.14 for ; Wed, 14 Nov 2018 14:53:06 -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=bLMs4Au7DiESCDOxLKd8+oMw9C/A5EHH/t0scKwgs+c=; b=mf31mAWSLPOw0uXUEAig0jY3fUnMiE+2qkVvrVlmhlyFRoqAiViKTWf8FIe86KFfAW KKZeYvf49Y1uNBr80k1ICcgofCqTfT32UEnt2hK+M9uTF/OaTL/6rNBcJqrEu6vaDPCE 1bkzdpyAdgalOIZyvj3q9qMHJEEkmAoINLfogFOTOg3PgmUPedCLs8y7CNcm6mxJeOXt k3u25DveTZTg6c+hZfBfQqHkNE+Mvt4T83n1TBZe/XAJaKkZs+/LuS92GotnYnFyQ6Iu Qg/9rh6s3BmODtWnE1B7W8zriQ3qX8PbYIx2wm7wp06s1Ugh5jAdVK/usAchZxfs90ac xKfg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of keith.busch@intel.com designates 134.134.136.100 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: AGRZ1gLg+9yhGcXxZ1NjX7FIdvh8QmLz2YzpEGjt3gi5yXZL8Z2TOC+l tIK1xP5nc8pdS5gRTLFGDFVaovHhq2MywFVtxk68vZui7IofD1ixglx5URTRVNQvExAfg9Encb+ 0dHiqPuWjwpG6h3Iq3HVzrUqw7hp5vGl8LcYGibQNcmb9/h+lwBR7k5w87aRkG3ubzA== X-Received: by 2002:a63:a612:: with SMTP id t18-v6mr3487409pge.338.1542235986074; Wed, 14 Nov 2018 14:53:06 -0800 (PST) X-Google-Smtp-Source: AJdET5eJRzmNTGiDF5DUxSHfHlB6k9EfEq3+lc9nonIw3GXicmo6/fZLx1qDOKRh3oaEbnsR5TkC X-Received: by 2002:a63:a612:: with SMTP id t18-v6mr3487361pge.338.1542235985201; Wed, 14 Nov 2018 14:53:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542235985; cv=none; d=google.com; s=arc-20160816; b=hKAHnk4uLR2YvrgA6+M/1RwTtHrOO0jbLSq2Ir8NVM+xk1iH6m1piKkNcHqk7Gxr5f SLJNyuVf/pol1Eo8q/neyBw6fQY7ijB3rTYB/GtboMenXkxPeADthc7VyPo07LZKoqXo 7gThx1vrEaEOSb2lcL09qv2OuCQxZLXP0geefvvV13a4J8h6j9EoOMdP9D4zS4IRd1Kh N7psyTzR83my+Oks1KVLc3G+cJxHSv4sLHVaaZOU1ssJN/HwK2mKd7mWuIcwiDf1ZDNY r25LkQ+6ZvZ/qETKY3vYyX+v2LaRaewymWWdKol3NwfaYRSYh9iBlMr8rH/RgvBAebTP Swxw== 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=bLMs4Au7DiESCDOxLKd8+oMw9C/A5EHH/t0scKwgs+c=; b=dv+cq44pxzYWRcWeKR0NuRsHk0JB5LE+zpvwlv9r2FLIHgfPLkOWL+FPU4QzafdU1Q 1TZbmh52PlsBdpZ0JwUJx5yis49d7vEW6Vp5b80BFKfAWeWIZpF8Jgb3MCMfZMxOpUhN ZXhnIb+BZx7S4VOoRYND8ijv78dgu56KgWzLLDr2iohdALdYtgR076j94DhHTZ7VZQ6k W8O3IkFKCjoMbwj2Wt+KxcXdHePVrXMAvANJfZIzGWaN6GppuSe6D93yl2+epzs5DHgz h5u3KpP1ZuH4YbUx5NBG0ro9p/sozu/oqxs4RO/yj1Tne7Oc3F60Q0c+9pnlQv4rBcNR NVCA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of keith.busch@intel.com designates 134.134.136.100 as permitted sender) smtp.mailfrom=keith.busch@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga07.intel.com (mga07.intel.com. [134.134.136.100]) by mx.google.com with ESMTPS id h18-v6si21592604pgv.47.2018.11.14.14.53.04 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 14:53:05 -0800 (PST) Received-SPF: pass (google.com: domain of keith.busch@intel.com designates 134.134.136.100 as permitted sender) client-ip=134.134.136.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of keith.busch@intel.com designates 134.134.136.100 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 fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Nov 2018 14:53:04 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,234,1539673200"; d="scan'208";a="106314894" Received: from unknown (HELO localhost.lm.intel.com) ([10.232.112.69]) by fmsmga004.fm.intel.com with ESMTP; 14 Nov 2018 14:53:04 -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: [PATCH 6/7] acpi: Create subtable parsing infrastructure Date: Wed, 14 Nov 2018 15:49:19 -0700 Message-Id: <20181114224921.12123-7-keith.busch@intel.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20181114224921.12123-2-keith.busch@intel.com> References: <20181114224921.12123-2-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 Parsing entries in an ACPI table had assumed a generic header structure that is most common. There is no standard ACPI header, though, so less common types would need custom parsers if they want go walk their subtable entry list. Create the infrastructure for adding different table types so parsing the entries array may be more reused for all ACPI system tables. Signed-off-by: Keith Busch --- drivers/acpi/tables.c | 75 ++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 65 insertions(+), 10 deletions(-) diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c index 61203eebf3a1..15ee77780f68 100644 --- a/drivers/acpi/tables.c +++ b/drivers/acpi/tables.c @@ -49,6 +49,19 @@ static struct acpi_table_desc initial_tables[ACPI_MAX_TABLES] __initdata; static int acpi_apic_instance __initdata; +enum acpi_subtable_type { + ACPI_SUBTABLE_COMMON, +}; + +union acpi_subtable_headers { + struct acpi_subtable_header common; +}; + +struct acpi_subtable_entry { + union acpi_subtable_headers *hdr; + enum acpi_subtable_type type; +}; + /* * Disable table checksum verification for the early stage due to the size * limitation of the current x86 early mapping implementation. @@ -217,6 +230,45 @@ void acpi_table_print_madt_entry(struct acpi_subtable_header *header) } } +static unsigned long __init +acpi_get_entry_type(struct acpi_subtable_entry *entry) +{ + switch (entry->type) { + case ACPI_SUBTABLE_COMMON: + return entry->hdr->common.type; + } + WARN_ONCE(1, "invalid acpi type\n"); + return 0; +} + +static unsigned long __init +acpi_get_entry_length(struct acpi_subtable_entry *entry) +{ + switch (entry->type) { + case ACPI_SUBTABLE_COMMON: + return entry->hdr->common.length; + } + WARN_ONCE(1, "invalid acpi type\n"); + return 0; +} + +static unsigned long __init +acpi_get_subtable_header_length(struct acpi_subtable_entry *entry) +{ + switch (entry->type) { + case ACPI_SUBTABLE_COMMON: + return sizeof(entry->hdr->common); + } + WARN_ONCE(1, "invalid acpi type\n"); + return 0; +} + +static enum acpi_subtable_type __init +acpi_get_subtable_type(char *id) +{ + return ACPI_SUBTABLE_COMMON; +} + /** * acpi_parse_entries_array - for each proc_num find a suitable subtable * @@ -246,8 +298,8 @@ acpi_parse_entries_array(char *id, unsigned long table_size, struct acpi_subtable_proc *proc, int proc_num, unsigned int max_entries) { - struct acpi_subtable_header *entry; - unsigned long table_end; + struct acpi_subtable_entry entry; + unsigned long table_end, subtable_len, entry_len; int count = 0; int errs = 0; int i; @@ -270,19 +322,21 @@ acpi_parse_entries_array(char *id, unsigned long table_size, /* Parse all entries looking for a match. */ - entry = (struct acpi_subtable_header *) + entry.type = acpi_get_subtable_type(id); + entry.hdr = (union acpi_subtable_headers *) ((unsigned long)table_header + table_size); + subtable_len = acpi_get_subtable_header_length(&entry); - while (((unsigned long)entry) + sizeof(struct acpi_subtable_header) < - table_end) { + while (((unsigned long)entry.hdr) + subtable_len < table_end) { if (max_entries && count >= max_entries) break; for (i = 0; i < proc_num; i++) { - if (entry->type != proc[i].id) + if (acpi_get_entry_type(&entry) != proc[i].id) continue; if (!proc[i].handler || - (!errs && proc[i].handler(entry, table_end))) { + (!errs && proc[i].handler(&entry.hdr->common, + table_end))) { errs++; continue; } @@ -297,13 +351,14 @@ acpi_parse_entries_array(char *id, unsigned long table_size, * If entry->length is 0, break from this loop to avoid * infinite loop. */ - if (entry->length == 0) { + entry_len = acpi_get_entry_length(&entry); + if (entry_len == 0) { pr_err("[%4.4s:0x%02x] Invalid zero length\n", id, proc->id); return -EINVAL; } - entry = (struct acpi_subtable_header *) - ((unsigned long)entry + entry->length); + entry.hdr = (union acpi_subtable_headers *) + ((unsigned long)entry.hdr + entry_len); } if (max_entries && count > max_entries) { From patchwork Wed Nov 14 22:49:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Busch X-Patchwork-Id: 10683297 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 E41BF14DB for ; Wed, 14 Nov 2018 22:53:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D6D6A2BF63 for ; Wed, 14 Nov 2018 22:53:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CB0972BF72; Wed, 14 Nov 2018 22:53:21 +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=unavailable 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 DB8FC2BF63 for ; Wed, 14 Nov 2018 22:53:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A9F096B026B; Wed, 14 Nov 2018 17:53:07 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A817D6B026D; Wed, 14 Nov 2018 17:53:07 -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 972836B026E; Wed, 14 Nov 2018 17:53:07 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) by kanga.kvack.org (Postfix) with ESMTP id 3AA266B026B for ; Wed, 14 Nov 2018 17:53:07 -0500 (EST) Received: by mail-pf1-f199.google.com with SMTP id p9so2598679pfj.3 for ; Wed, 14 Nov 2018 14:53:07 -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=fUqmpUBxkmone13ftrM/7NZoxLVMsh51FxOne5RJHpw=; b=cFtPgIXpgEs8tuQGEy1Wi2ZH1aT2ZYODxm/F5vw5pobAoPINNOVUsRgK6kZnZ9eOwU HKDMkINaAD+z108xBF9nfzO2Fc2304kTUb8aMrZ8tiSzScB+fTTs9sff5/h2OiH2uB8f oU9E39OJK0VjrpVUcSDDdQFjGfB2T6KlkimIhq20cot8C0qpWEtzRadLpO47biu5pMY5 2qsQ1sGx1x3Rog4YiN8I5UiEoCmf1ILxxxcuoRZdwnijSNkAPGf7ialsjjIm3fCPQCH4 sRp1zqQfhc4Jn8VmckKcBwtvTKsYwRyV9xJfIfHiOCe7GJ0CY73lI4ki0nRsPWb6UsjT yHtA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of keith.busch@intel.com designates 134.134.136.100 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: AGRZ1gJ/MREmRl+uRgHneRykQ/oZG8EAeY3h6hXRgbYl7v16Q8tSLrjO HXHC5++S0YM22YWoBOz6QMTVgloM6QL0bfkzFXed+WHeyTd8XlTKisgOPCHsqeSgDSV8r91qFhS OsPwqYVuWTNMJksuRGrDp9iwmdZOqDOa5zM8wvPTCtu3AQ39EE4p3V8ZtTrmFOfUlTw== X-Received: by 2002:a17:902:8507:: with SMTP id bj7-v6mr3695726plb.99.1542235986863; Wed, 14 Nov 2018 14:53:06 -0800 (PST) X-Google-Smtp-Source: AJdET5fxv7cqzvXdrLcRZ/Rm94623SrjOqPsv6abn2Tkl9Y8yu93n7oi+kccYmkbIjIpH9Ucouf0 X-Received: by 2002:a17:902:8507:: with SMTP id bj7-v6mr3695675plb.99.1542235985513; Wed, 14 Nov 2018 14:53:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542235985; cv=none; d=google.com; s=arc-20160816; b=v8eESBjbPrlZB7Xa8Hr0rb483NSZuQw5GMZHGqBWnFbf0WNz2gNbp0THTKGiXM2qSL o3oPj4kpivl1s4HcwJXtV8iy9741KtrDxFxdZ7gYW7JK9W/rXYBOfkbDE7E+4f4fdFw2 1PXxLEB3lXu1CYWiSny4rGvso8frFVOaeCMX9+6bQ5Dk76li7y45RcBHwsXkgf3Th6OD VC3Tl/LZSsuOwxkClPysHccX2iI9dcK0JbESrBV1La3hBgSAg0r2A1HHT6cQQS/hify+ 8rpMGgybzSK9yk6xkL5KRh73aJl4K0CvJ7p5pF/NGYnCBLmUfYF1a34HRikKJN89G3+m Co9Q== 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=fUqmpUBxkmone13ftrM/7NZoxLVMsh51FxOne5RJHpw=; b=ZeIhUGtzVuaxnQm0iDMaMOKokO5pUno7nefEvIMXCmA2KTy7XHFnFxwvFTZpVhV3uc fttjzjacTy09iJWEAG2w5mZNKwa7i9JA+NfB0H10HU4yCaJX7Ti4G+TTyAQi7Owkl4Gq 4Y0YnM4k4eoGHumDEMlIrL60KkkDbyGWC4bq1n2ncou0uyK/2ijhdBMklDiT29rs+i4+ o27e9C7h7drTx8orDDAxLIeSQWxv+MRagPXXVmTNuGWJNGjrT/gAVf8AbX9Hg3uSObaa 4Qt6t/VVFDX2gnwDF51XvFyDTzctLTxvnuSGXNDyA9r0S7J3aTy4qN0cBX8xpLGMbxqz y8MQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of keith.busch@intel.com designates 134.134.136.100 as permitted sender) smtp.mailfrom=keith.busch@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga07.intel.com (mga07.intel.com. [134.134.136.100]) by mx.google.com with ESMTPS id h18-v6si21592604pgv.47.2018.11.14.14.53.05 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 14:53:05 -0800 (PST) Received-SPF: pass (google.com: domain of keith.busch@intel.com designates 134.134.136.100 as permitted sender) client-ip=134.134.136.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of keith.busch@intel.com designates 134.134.136.100 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 fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Nov 2018 14:53:05 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,234,1539673200"; d="scan'208";a="106314898" Received: from unknown (HELO localhost.lm.intel.com) ([10.232.112.69]) by fmsmga004.fm.intel.com with ESMTP; 14 Nov 2018 14:53:04 -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: [PATCH 7/7] acpi/hmat: Parse and report heterogeneous memory Date: Wed, 14 Nov 2018 15:49:20 -0700 Message-Id: <20181114224921.12123-8-keith.busch@intel.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20181114224921.12123-2-keith.busch@intel.com> References: <20181114224921.12123-2-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 The ACPI Heterogeneous Memory Attribute Table (HMAT) table added in ACPI 6.2 provides a way for platforms to express different memory address range characteristics. Parse these tables provided by the platform and register the local initiator performance access and caching attributes with the memory numa nodes so they can be observed through sysfs. Signed-off-by: Keith Busch --- drivers/acpi/Kconfig | 9 ++ drivers/acpi/Makefile | 1 + drivers/acpi/hmat.c | 384 ++++++++++++++++++++++++++++++++++++++++++++++++++ drivers/acpi/tables.c | 10 ++ 4 files changed, 404 insertions(+) create mode 100644 drivers/acpi/hmat.c diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig index 7cea769c37df..9e6b767dd366 100644 --- a/drivers/acpi/Kconfig +++ b/drivers/acpi/Kconfig @@ -327,6 +327,15 @@ config ACPI_NUMA depends on (X86 || IA64 || ARM64) default y if IA64_GENERIC || IA64_SGI_SN2 || ARM64 +config ACPI_HMAT + bool "ACPI Heterogeneous Memory Attribute Table Support" + depends on ACPI_NUMA + select HMEM + help + Parses representation of the ACPI Heterogeneous Memory Attributes + Table (HMAT) and set the memory node relationships and access + attributes. + config ACPI_CUSTOM_DSDT_FILE string "Custom DSDT Table file to include" default "" diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile index edc039313cd6..b5e13499f88b 100644 --- a/drivers/acpi/Makefile +++ b/drivers/acpi/Makefile @@ -55,6 +55,7 @@ acpi-$(CONFIG_X86) += x86/apple.o acpi-$(CONFIG_X86) += x86/utils.o acpi-$(CONFIG_DEBUG_FS) += debugfs.o acpi-$(CONFIG_ACPI_NUMA) += numa.o +acpi-$(CONFIG_ACPI_HMAT) += hmat.o acpi-$(CONFIG_ACPI_PROCFS_POWER) += cm_sbs.o acpi-y += acpi_lpat.o acpi-$(CONFIG_ACPI_LPIT) += acpi_lpit.o diff --git a/drivers/acpi/hmat.c b/drivers/acpi/hmat.c new file mode 100644 index 000000000000..9070e84fd30e --- /dev/null +++ b/drivers/acpi/hmat.c @@ -0,0 +1,384 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Heterogeneous Memory Attributes Table (HMAT) representation + * + * Copyright (c) 2018, Intel Corporation. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static LIST_HEAD(targets); + +struct memory_target { + struct list_head node; + unsigned int memory_pxm; + unsigned long processor_nodes[BITS_TO_LONGS(MAX_NUMNODES)]; + struct node_hmem_attrs hmem; +}; + +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) { + case ACPI_HMAT_ACCESS_LATENCY: + return "Access Latency"; + case ACPI_HMAT_READ_LATENCY: + return "Read Latency"; + case ACPI_HMAT_WRITE_LATENCY: + return "Write Latency"; + case ACPI_HMAT_ACCESS_BANDWIDTH: + return "Access Bandwidth"; + case ACPI_HMAT_READ_BANDWIDTH: + return "Read Bandwidth"; + case ACPI_HMAT_WRITE_BANDWIDTH: + return "Write Bandwidth"; + default: + return "Reserved"; + }; +} + +static __init const char *hmat_data_type_suffix(u8 type) +{ + switch (type) { + case ACPI_HMAT_ACCESS_LATENCY: + case ACPI_HMAT_READ_LATENCY: + case ACPI_HMAT_WRITE_LATENCY: + return " nsec"; + case ACPI_HMAT_ACCESS_BANDWIDTH: + case ACPI_HMAT_READ_BANDWIDTH: + case ACPI_HMAT_WRITE_BANDWIDTH: + return " MB/s"; + default: + return ""; + }; +} + +static __init void hmat_update_value(u32 *dest, u32 value, bool gt, + bool *update, bool *tie) +{ + if (!(*dest)) { + *update = true; + *dest = value; + } else if (gt && value > *dest) { + *update = true; + *dest = value; + } else if (!gt && value < *dest) { + *update = true; + *dest = value; + } else if (*dest == value) { + *tie = true; + } +} + +static __init void hmat_update_target_access(unsigned int p, unsigned int m, u8 type, + unsigned int value) +{ + struct memory_target *t = find_mem_target(m); + int p_node = pxm_to_node(p); + bool update = false, tie = false; + + if (!t || p_node == NUMA_NO_NODE || !value) + return; + + switch (type) { + case ACPI_HMAT_ACCESS_LATENCY: + hmat_update_value(&t->hmem.read_latency, value, false, + &update, &tie); + hmat_update_value(&t->hmem.write_latency, value, false, + &update, &tie); + break; + case ACPI_HMAT_READ_LATENCY: + hmat_update_value(&t->hmem.read_latency, value, false, + &update, &tie); + break; + case ACPI_HMAT_WRITE_LATENCY: + hmat_update_value(&t->hmem.write_latency, value, false, + &update, &tie); + break; + case ACPI_HMAT_ACCESS_BANDWIDTH: + hmat_update_value(&t->hmem.read_bandwidth, value, true, + &update, &tie); + hmat_update_value(&t->hmem.write_bandwidth, value, true, + &update, &tie); + break; + case ACPI_HMAT_READ_BANDWIDTH: + hmat_update_value(&t->hmem.read_bandwidth, value, true, + &update, &tie); + break; + case ACPI_HMAT_WRITE_BANDWIDTH: + hmat_update_value(&t->hmem.write_bandwidth, value, true, + &update, &tie); + break; + } + + if (update) { + bitmap_zero(t->processor_nodes, MAX_NUMNODES); + set_bit(p_node, t->processor_nodes); + } else if (tie) + set_bit(p_node, t->processor_nodes); +} + +static __init int hmat_parse_locality(struct acpi_subtable_header *header, + const unsigned long end) +{ + struct acpi_hmat_locality *loc = (void *)header; + unsigned int i, j, total_size, ipds, tpds; + u32 *inits, *targs, value; + u16 *entries; + u8 type; + + if (loc->header.length < sizeof(*loc)) { + pr_err("HMAT: Unexpected locality header length: %d\n", + loc->header.length); + return -EINVAL; + } + + type = loc->data_type; + ipds = loc->number_of_initiator_Pds; + tpds = loc->number_of_target_Pds; + total_size = sizeof(*loc) + sizeof(*entries) * ipds * tpds + + sizeof(*inits) * ipds + sizeof(*targs) * tpds; + if (loc->header.length < total_size) { + pr_err("HMAT: Unexpected locality header length:%d, minimum required:%d\n", + loc->header.length, total_size); + return -EINVAL; + } + + pr_info("HMAT: Locality: Flags:%02x Type:%s Initiator Domains:%d Target Domains:%d Base:%lld\n", + loc->flags, hmat_data_type(type), ipds, tpds, + loc->entry_base_unit); + + inits = (u32 *)(loc + 1); + targs = &inits[ipds]; + entries = (u16 *)(&targs[tpds]); + for (i = 0; i < ipds; i++) { + for (j = 0; j < loc->number_of_target_Pds; j++) { + value = (*entries * loc->entry_base_unit) / 10; + pr_info(" Initiator-Target[%d-%d]:%d%s\n", inits[i], + targs[j], value, hmat_data_type_suffix(type)); + + if ((loc->flags & ACPI_HMAT_MEMORY_HIERARCHY) == + ACPI_HMAT_MEMORY) + hmat_update_target_access(inits[i], targs[j], + type, value); + entries++; + } + } + return 0; +} + +static __init int hmat_parse_cache(struct acpi_subtable_header *header, + const unsigned long end) +{ + struct acpi_hmat_cache *cache = (void *)header; + struct node_cache_attrs cache_attrs; + u32 attrs; + + if (cache->header.length < sizeof(*cache)) { + pr_err("HMAT: Unexpected cache header length: %d\n", + cache->header.length); + return -EINVAL; + } + + attrs = cache->cache_attributes; + pr_info("HMAT: Cache: Domain:%d Size:%llu Attrs:%08x SMBIOS Handles:%d\n", + 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; + + switch ((attrs & ACPI_HMAT_CACHE_ASSOCIATIVITY) >> 8) { + case ACPI_HMAT_CA_DIRECT_MAPPED: + cache_attrs.associativity = NODE_CACHE_DIRECT_MAP; + break; + case ACPI_HMAT_CA_COMPLEX_CACHE_INDEXING: + cache_attrs.associativity = NODE_CACHE_INDEXED; + break; + case ACPI_HMAT_CA_NONE: + default: + cache_attrs.associativity = NODE_CACHE_OTHER; + break; + } + switch ((attrs & ACPI_HMAT_WRITE_POLICY) >> 12) { + case ACPI_HMAT_CP_WB: + cache_attrs.write_policy = NODE_CACHE_WRITE_BACK; + break; + case ACPI_HMAT_CP_WT: + cache_attrs.write_policy = NODE_CACHE_WRITE_THROUGH; + break; + case ACPI_HMAT_CP_NONE: + default: + cache_attrs.write_policy = NODE_CACHE_WRITE_OTHER; + break; + } + + node_add_cache(pxm_to_node(cache->memory_PD), &cache_attrs); + return 0; +} + +static int __init hmat_parse_address_range(struct acpi_subtable_header *header, + const unsigned long end) +{ + struct acpi_hmat_address_range *spa = (void *)header; + + if (spa->header.length != sizeof(*spa)) { + pr_err("HMAT: Unexpected address range header length: %d\n", + spa->header.length); + return -EINVAL; + } + 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); + return 0; +} + +static int __init hmat_parse_subtable(struct acpi_subtable_header *header, + const unsigned long end) +{ + struct acpi_hmat_structure *hdr = (void *)header; + + if (!hdr) + return -EINVAL; + + switch (hdr->type) { + case ACPI_HMAT_TYPE_ADDRESS_RANGE: + return hmat_parse_address_range(header, end); + case ACPI_HMAT_TYPE_LOCALITY: + return hmat_parse_locality(header, end); + case ACPI_HMAT_TYPE_CACHE: + return hmat_parse_cache(header, end); + default: + return -EINVAL; + } +} + +static __init int srat_parse_mem_affinity(struct acpi_subtable_header *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) { + bool hmem_valid = false; + + list_del(&t->node); + m = pxm_to_node(t->memory_pxm); + + for_each_set_bit(p, t->processor_nodes, MAX_NUMNODES) { + if (register_memory_node_under_compute_node(m, p)) + goto free_target; + hmem_valid = true; + } + if (hmem_valid) + node_set_perf_attrs(m, &t->hmem); +free_target: + kfree(t); + } +} + +static __init int parse_noop(struct acpi_table_header *table) +{ + return 0; +} + +static __init int hmat_init(void) +{ + struct acpi_subtable_proc subtable_proc; + struct acpi_table_header *tbl; + enum acpi_hmat_type i; + acpi_status status; + + if (srat_disabled()) + return 0; + + status = acpi_get_table(ACPI_SIG_SRAT, 0, &tbl); + if (ACPI_FAILURE(status)) + return 0; + + if (acpi_table_parse(ACPI_SIG_SRAT, parse_noop)) + goto out_put; + + memset(&subtable_proc, 0, sizeof(subtable_proc)); + subtable_proc.id = ACPI_SRAT_TYPE_MEMORY_AFFINITY; + subtable_proc.handler = srat_parse_mem_affinity; + + if (acpi_table_parse_entries_array(ACPI_SIG_SRAT, + sizeof(struct acpi_table_srat), + &subtable_proc, 1, 0) < 0) + goto out_put; + acpi_put_table(tbl); + + status = acpi_get_table(ACPI_SIG_HMAT, 0, &tbl); + if (ACPI_FAILURE(status)) + return 0; + + if (acpi_table_parse(ACPI_SIG_HMAT, parse_noop)) + goto out_put; + + memset(&subtable_proc, 0, sizeof(subtable_proc)); + subtable_proc.handler = hmat_parse_subtable; + for (i = ACPI_HMAT_TYPE_ADDRESS_RANGE; i < ACPI_HMAT_TYPE_RESERVED; i++) { + subtable_proc.id = i; + if (acpi_table_parse_entries_array(ACPI_SIG_HMAT, + sizeof(struct acpi_table_hmat), + &subtable_proc, 1, 0) < 0) + goto out_put; + } + hmat_register_targets(); + out_put: + acpi_put_table(tbl); + return 0; +} +device_initcall(hmat_init); diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c index 15ee77780f68..a34669a1d47a 100644 --- a/drivers/acpi/tables.c +++ b/drivers/acpi/tables.c @@ -51,10 +51,12 @@ static int acpi_apic_instance __initdata; enum acpi_subtable_type { ACPI_SUBTABLE_COMMON, + ACPI_SUBTABLE_HMAT, }; union acpi_subtable_headers { struct acpi_subtable_header common; + struct acpi_hmat_structure hmat; }; struct acpi_subtable_entry { @@ -236,6 +238,8 @@ acpi_get_entry_type(struct acpi_subtable_entry *entry) switch (entry->type) { case ACPI_SUBTABLE_COMMON: return entry->hdr->common.type; + case ACPI_SUBTABLE_HMAT: + return entry->hdr->hmat.type; } WARN_ONCE(1, "invalid acpi type\n"); return 0; @@ -247,6 +251,8 @@ acpi_get_entry_length(struct acpi_subtable_entry *entry) switch (entry->type) { case ACPI_SUBTABLE_COMMON: return entry->hdr->common.length; + case ACPI_SUBTABLE_HMAT: + return entry->hdr->hmat.length; } WARN_ONCE(1, "invalid acpi type\n"); return 0; @@ -258,6 +264,8 @@ acpi_get_subtable_header_length(struct acpi_subtable_entry *entry) switch (entry->type) { case ACPI_SUBTABLE_COMMON: return sizeof(entry->hdr->common); + case ACPI_SUBTABLE_HMAT: + return sizeof(entry->hdr->hmat); } WARN_ONCE(1, "invalid acpi type\n"); return 0; @@ -266,6 +274,8 @@ acpi_get_subtable_header_length(struct acpi_subtable_entry *entry) static enum acpi_subtable_type __init acpi_get_subtable_type(char *id) { + if (strncmp(id, ACPI_SIG_HMAT, 4) == 0) + return ACPI_SUBTABLE_HMAT; return ACPI_SUBTABLE_COMMON; }