From patchwork Wed Jan 9 17:43:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Busch X-Patchwork-Id: 10754637 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 5F5D16C5 for ; Wed, 9 Jan 2019 17:48:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4F8AD28A2E for ; Wed, 9 Jan 2019 17:48:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4241928DC6; Wed, 9 Jan 2019 17:48:04 +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 801BC28A2E for ; Wed, 9 Jan 2019 17:48:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 366FA8E00A1; Wed, 9 Jan 2019 12:48:00 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2EB5D8E0038; Wed, 9 Jan 2019 12:48:00 -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 144E68E00A3; Wed, 9 Jan 2019 12:48:00 -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 AB4118E00A1 for ; Wed, 9 Jan 2019 12:47:59 -0500 (EST) Received: by mail-pl1-f198.google.com with SMTP id o23so4583458pll.0 for ; Wed, 09 Jan 2019 09:47:59 -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=WkxRbXsyJx+8YU8EFkbpOgmcfouDZAhdnb/RTxBK8HA=; b=lhdNrGl6auwoyowN0zVo9XnU995b/KA1QeJ5Jaw6hxvyM04zAaXQ4bOj+hxM+cWDIl 00EMCBy0UGPNGVbyvRsZRQPpHUce2Yu1ATCwDv0m761N469ZBAyvVJt8ckXUw6DetIWc H9tudgmZfARSleJqA76u4bFYBDtbGnhneGI3S2SMVBFn0zcNCi6dJy5s32zu/wVro+G0 9CrwOu1ixj/aVP/TJHPki7IizsZMyDFPaiJavaz62dpsES2vVVUZfsnw0yHKq6IfxLVh SZPCQ2dWPuMcafUj5ZiQ0jTPp05upHz2zsTp5tfkUDk/vAErbCjxo9GW3f+uYKajI5ir SwCA== 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: AJcUukd157escfTcVYtqRIqBi8WnRy0TrnhQwP3FXQ9lAAvw5VG9xKXA 2+c+x1I/22+FqACt86toE/nsiZkMxNIufXeobfOYnT6NQBqpB2+rgTU8NMZAHD2C67VCw6woYkJ 2bm8Nqx6bcQ7BIbEbmYwyqDmu8aqyledUmr0UidH3iJj13f5qg5e77ANRw4jIlgASvQ== X-Received: by 2002:a63:eb0e:: with SMTP id t14mr6347119pgh.445.1547056079268; Wed, 09 Jan 2019 09:47:59 -0800 (PST) X-Google-Smtp-Source: ALg8bN64CjBexLU6CW72jJJqg5rfdZNLO5R0yucMUo7FDSUJRvUvi3Vs4CHu73/G5ZDjRaDbahg0 X-Received: by 2002:a63:eb0e:: with SMTP id t14mr6347078pgh.445.1547056078228; Wed, 09 Jan 2019 09:47:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547056078; cv=none; d=google.com; s=arc-20160816; b=uZeUji1exPQXCrhy9aT1y2pg3l8k26Cxhex7gM1zT4M8eX9pKgCy63Mt7pf22AmWhh 9LNO/a5g4HvTwyRuz2BdGpNNIn9SQq+0IWsNuYVvvvD23/LEhijN/R052mRUGCiGgbmq yfJDVkyht4H/fySTghziDuIDWkGe/H+RDEmI2ti25D+mzrUYfdQdFnrUT9btIGs3DIy3 oeudyQM9Nf+F1Rltp/DYbz0gUgdfGInSNU1dog8CmJCMA72Sa6D8xFlX5FbKiF02vE/Y ncOD+zfcYICnXxxGj9eH1DTeP1sN+XhDhVw71amFoUOW+H3OdH1Q84dQQbzVTMnDffgQ +tzA== 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=WkxRbXsyJx+8YU8EFkbpOgmcfouDZAhdnb/RTxBK8HA=; b=fK2iSIkMEDo3cfhsJ4CXQf2x3AjvqxsrdFfKSVDyvfL65CI6DypnDb+Ku1NWKK6knk Ty2FoQeZocW3BFSwM5jgyfNzzXjiNPWhqUO7aZTAMgB100HDxTrlbrr7tUxTbMEVNZDd MFsqUkputJtoNJHZTuoRoQ273FqdKr7tRTsyDJvSB38svDmXNDnqvbMj5xlVHxjUi4WZ 1emI6KeNJQXChZn5G8uVtjH8m9XdZyMuwiMScIMjxKJchMX1+5dGhnpG7h+wO+n0/UUi VyJWHVBb3J/cLDQAol6ZlM5z/7QYwKw2HX5jB+bSd80mK+04V5KHA5uGa4sAzpWUXPK+ frkg== 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 c10si25675731pla.173.2019.01.09.09.47.58 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 Jan 2019 09:47:58 -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 fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Jan 2019 09:47:57 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,458,1539673200"; d="scan'208";a="115485615" Received: from unknown (HELO localhost.lm.intel.com) ([10.232.112.69]) by fmsmga008.fm.intel.com with ESMTP; 09 Jan 2019 09:47:57 -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: [PATCHv3 04/13] node: Link memory nodes to their compute nodes Date: Wed, 9 Jan 2019 10:43:32 -0700 Message-Id: <20190109174341.19818-5-keith.busch@intel.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20190109174341.19818-1-keith.busch@intel.com> References: <20190109174341.19818-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 Systems may be constructed with various specialized nodes. Some nodes may provide memory, some provide compute devices that access and use that memory, and others may provide both. Nodes that provide memory are referred to as memory targets, and nodes that can initiate memory access are referred to as memory initiators. Memory targets will often have varying access characteristics from different initiators, and platforms may have ways to express those relationships. In preparation for these systems, provide interfaces for the kernel to export the memory relationship among different node's memory targets and their initiators with symlinks to each other's nodes, and export node lists showing the same relationship. If a system provides access locality for each initiator-target pair, nodes may be grouped into ranked access classes relative to other nodes. The new interface allows a subsystem to register relationships of varying classes if available and desired to be exported. A lower class number indicates a higher performing tier, with 0 being the best performing class. A memory initiator may have multiple memory targets in the same access class. The initiator's memory targets in given class indicate the node's access characteristics perform better relative to other initiator nodes either unreported or in lower class numbers. The targets within an initiator's class, though, do not necessarily perform the same as each other. A memory target node may have multiple memory initiators. All linked initiators in a target's class have the same access characteristics as each other to that target. The following example show the nodes' new sysfs hierarchy for a memory target node 'Y' with class 0 access from initiator node 'X': # symlinks -v /sys/devices/system/node/nodeX/class0/ relative: /sys/devices/system/node/nodeX/class0/targetY -> ../../nodeY # symlinks -v /sys/devices/system/node/nodeY/class0/ relative: /sys/devices/system/node/nodeY/class0/initiatorX -> ../../nodeX And the same information is reflected in the nodelist: # cat /sys/devices/system/node/nodeX/class0/target_nodelist Y # cat /sys/devices/system/node/nodeY/class0/initiator_nodelist X Signed-off-by: Keith Busch --- drivers/base/node.c | 127 ++++++++++++++++++++++++++++++++++++++++++++++++++- include/linux/node.h | 6 ++- 2 files changed, 131 insertions(+), 2 deletions(-) diff --git a/drivers/base/node.c b/drivers/base/node.c index 86d6cd92ce3d..1da5072116ab 100644 --- a/drivers/base/node.c +++ b/drivers/base/node.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -59,6 +60,91 @@ 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); +struct node_class_nodes { + struct device dev; + struct list_head list_node; + unsigned class; + nodemask_t initiator_nodes; + nodemask_t target_nodes; +}; +#define to_class_nodes(dev) container_of(dev, struct node_class_nodes, dev) + +static ssize_t initiator_nodelist_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct node_class_nodes *c = to_class_nodes(dev); + return scnprintf(buf, PAGE_SIZE - 1, "%*pbl\n", + nodemask_pr_args(&c->initiator_nodes)); +} +static DEVICE_ATTR_RO(initiator_nodelist); + +static ssize_t target_nodelist_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct node_class_nodes *c = to_class_nodes(dev); + return scnprintf(buf, PAGE_SIZE - 1, "%*pbl\n", + nodemask_pr_args(&c->target_nodes)); +} +static DEVICE_ATTR_RO(target_nodelist); + +static struct attribute *node_class_node_attrs[] = { + &dev_attr_initiator_nodelist.attr, + &dev_attr_target_nodelist.attr, + NULL, +}; +ATTRIBUTE_GROUPS(node_class_node); + +static void node_remove_classes(struct node *node) +{ + struct node_class_nodes *c, *cnext; + + list_for_each_entry_safe(c, cnext, &node->class_list, list_node) { + list_del(&c->list_node); + device_unregister(&c->dev); + } +} + +static void node_class_release(struct device *dev) +{ + kfree(to_class_nodes(dev)); +} + +static struct node_class_nodes *node_init_node_class(struct device *parent, + struct list_head *list, + unsigned class) +{ + struct node_class_nodes *class_node; + struct device *dev; + + list_for_each_entry(class_node, list, list_node) + if (class_node->class == class) + return class_node; + + class_node = kzalloc(sizeof(*class_node), GFP_KERNEL); + if (!class_node) + return NULL; + + class_node->class = class; + dev = &class_node->dev; + dev->parent = parent; + dev->release = node_class_release; + dev->groups = node_class_node_groups; + if (dev_set_name(dev, "class%u", class)) + goto free; + + if (device_register(dev)) + goto free_name; + + pm_runtime_no_callbacks(dev); + list_add_tail(&class_node->list_node, list); + return class_node; +free_name: + kfree_const(dev->kobj.name); +free: + kfree(class_node); + return NULL; +} + #define K(x) ((x) << (PAGE_SHIFT - 10)) static ssize_t node_read_meminfo(struct device *dev, struct device_attribute *attr, char *buf) @@ -340,7 +426,7 @@ static int register_node(struct node *node, int num) void unregister_node(struct node *node) { hugetlb_unregister_node(node); /* no-op, if memoryless node */ - + node_remove_classes(node); device_unregister(&node->dev); } @@ -372,6 +458,44 @@ 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, + unsigned class) +{ + struct node *init, *targ; + struct node_class_nodes *i, *t; + char initiator[20]; /* "initiator4294967295\0" */ + char target[17]; /* "target4294967295\0" */ + int ret; + + if (!node_online(p) || !node_online(m)) + return -ENODEV; + + init = node_devices[p]; + targ = node_devices[m]; + i = node_init_node_class(&init->dev, &init->class_list, class); + t = node_init_node_class(&targ->dev, &targ->class_list, class); + if (!i || !t) + return -ENOMEM; + + snprintf(initiator, sizeof(initiator), "initiator%u", p); + snprintf(target, sizeof(target), "target%u", m); + ret = sysfs_create_link(&i->dev.kobj, &targ->dev.kobj, target); + if (ret) + return ret; + + ret = sysfs_create_link(&t->dev.kobj, &init->dev.kobj, initiator); + if (ret) + goto err; + + node_set(m, i->target_nodes); + node_set(p, t->initiator_nodes); + 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; @@ -580,6 +704,7 @@ int __register_one_node(int nid) register_cpu_under_node(cpu, nid); } + INIT_LIST_HEAD(&node_devices[nid]->class_list); /* initialize work queue for memory hot plug */ init_node_hugetlb_work(nid); diff --git a/include/linux/node.h b/include/linux/node.h index 257bb3d6d014..8e3666c12ef2 100644 --- a/include/linux/node.h +++ b/include/linux/node.h @@ -17,11 +17,12 @@ #include #include +#include #include struct node { struct device dev; - + struct list_head class_list; #if defined(CONFIG_MEMORY_HOTPLUG_SPARSE) && defined(CONFIG_HUGETLBFS) struct work_struct node_work; #endif @@ -75,6 +76,9 @@ 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, + unsigned class); + #ifdef CONFIG_HUGETLBFS extern void register_hugetlbfs_with_node(node_registration_func_t doregister, node_registration_func_t unregister);