License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 21:07:57 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2014-03-07 00:47:21 +07:00
|
|
|
/*
|
|
|
|
* NUMA support for s390
|
|
|
|
*
|
|
|
|
* NUMA emulation (aka fake NUMA) distributes the available memory to nodes
|
|
|
|
* without using real topology information about the physical memory of the
|
|
|
|
* machine.
|
|
|
|
*
|
|
|
|
* It distributes the available CPUs to nodes while respecting the original
|
|
|
|
* machine topology information. This is done by trying to avoid to separate
|
|
|
|
* CPUs which reside on the same book or even on the same MC.
|
|
|
|
*
|
|
|
|
* Because the current Linux scheduler code requires a stable cpu to node
|
|
|
|
* mapping, cores are pinned to nodes when the first CPU thread is set online.
|
|
|
|
*
|
|
|
|
* Copyright IBM Corp. 2015
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define KMSG_COMPONENT "numa_emu"
|
|
|
|
#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/cpumask.h>
|
|
|
|
#include <linux/memblock.h>
|
2016-12-03 15:50:21 +07:00
|
|
|
#include <linux/bootmem.h>
|
2014-03-07 00:47:21 +07:00
|
|
|
#include <linux/node.h>
|
|
|
|
#include <linux/memory.h>
|
2015-08-05 16:23:53 +07:00
|
|
|
#include <linux/slab.h>
|
2014-03-07 00:47:21 +07:00
|
|
|
#include <asm/smp.h>
|
|
|
|
#include <asm/topology.h>
|
|
|
|
#include "numa_mode.h"
|
|
|
|
#include "toptree.h"
|
|
|
|
|
|
|
|
/* Distances between the different system components */
|
|
|
|
#define DIST_EMPTY 0
|
|
|
|
#define DIST_CORE 1
|
|
|
|
#define DIST_MC 2
|
|
|
|
#define DIST_BOOK 3
|
2016-05-25 15:25:50 +07:00
|
|
|
#define DIST_DRAWER 4
|
|
|
|
#define DIST_MAX 5
|
2014-03-07 00:47:21 +07:00
|
|
|
|
|
|
|
/* Node distance reported to common code */
|
|
|
|
#define EMU_NODE_DIST 10
|
|
|
|
|
|
|
|
/* Node ID for free (not yet pinned) cores */
|
|
|
|
#define NODE_ID_FREE -1
|
|
|
|
|
|
|
|
/* Different levels of toptree */
|
2016-05-25 15:25:50 +07:00
|
|
|
enum toptree_level {CORE, MC, BOOK, DRAWER, NODE, TOPOLOGY};
|
2014-03-07 00:47:21 +07:00
|
|
|
|
|
|
|
/* The two toptree IDs */
|
|
|
|
enum {TOPTREE_ID_PHYS, TOPTREE_ID_NUMA};
|
|
|
|
|
|
|
|
/* Number of NUMA nodes */
|
|
|
|
static int emu_nodes = 1;
|
|
|
|
/* NUMA stripe size */
|
|
|
|
static unsigned long emu_size;
|
2015-08-01 23:12:41 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Node to core pinning information updates are protected by
|
|
|
|
* "sched_domains_mutex".
|
|
|
|
*/
|
2015-08-05 16:23:53 +07:00
|
|
|
static struct {
|
|
|
|
s32 to_node_id[CONFIG_NR_CPUS]; /* Pinned core to node mapping */
|
|
|
|
int total; /* Total number of pinned cores */
|
|
|
|
int per_node_target; /* Cores per node without extra cores */
|
|
|
|
int per_node[MAX_NUMNODES]; /* Number of cores pinned to node */
|
|
|
|
} *emu_cores;
|
2014-03-07 00:47:21 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Pin a core to a node
|
|
|
|
*/
|
|
|
|
static void pin_core_to_node(int core_id, int node_id)
|
|
|
|
{
|
2015-08-05 16:23:53 +07:00
|
|
|
if (emu_cores->to_node_id[core_id] == NODE_ID_FREE) {
|
|
|
|
emu_cores->per_node[node_id]++;
|
|
|
|
emu_cores->to_node_id[core_id] = node_id;
|
|
|
|
emu_cores->total++;
|
2014-03-07 00:47:21 +07:00
|
|
|
} else {
|
2015-08-05 16:23:53 +07:00
|
|
|
WARN_ON(emu_cores->to_node_id[core_id] != node_id);
|
2014-03-07 00:47:21 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Number of pinned cores of a node
|
|
|
|
*/
|
|
|
|
static int cores_pinned(struct toptree *node)
|
|
|
|
{
|
2015-08-05 16:23:53 +07:00
|
|
|
return emu_cores->per_node[node->id];
|
2014-03-07 00:47:21 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ID of the node where the core is pinned (or NODE_ID_FREE)
|
|
|
|
*/
|
|
|
|
static int core_pinned_to_node_id(struct toptree *core)
|
|
|
|
{
|
2015-08-05 16:23:53 +07:00
|
|
|
return emu_cores->to_node_id[core->id];
|
2014-03-07 00:47:21 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Number of cores in the tree that are not yet pinned
|
|
|
|
*/
|
|
|
|
static int cores_free(struct toptree *tree)
|
|
|
|
{
|
|
|
|
struct toptree *core;
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
toptree_for_each(core, tree, CORE) {
|
|
|
|
if (core_pinned_to_node_id(core) == NODE_ID_FREE)
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return node of core
|
|
|
|
*/
|
|
|
|
static struct toptree *core_node(struct toptree *core)
|
2016-05-25 15:25:50 +07:00
|
|
|
{
|
|
|
|
return core->parent->parent->parent->parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return drawer of core
|
|
|
|
*/
|
|
|
|
static struct toptree *core_drawer(struct toptree *core)
|
2014-03-07 00:47:21 +07:00
|
|
|
{
|
|
|
|
return core->parent->parent->parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return book of core
|
|
|
|
*/
|
|
|
|
static struct toptree *core_book(struct toptree *core)
|
|
|
|
{
|
|
|
|
return core->parent->parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return mc of core
|
|
|
|
*/
|
|
|
|
static struct toptree *core_mc(struct toptree *core)
|
|
|
|
{
|
|
|
|
return core->parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Distance between two cores
|
|
|
|
*/
|
|
|
|
static int dist_core_to_core(struct toptree *core1, struct toptree *core2)
|
|
|
|
{
|
2016-05-25 15:25:50 +07:00
|
|
|
if (core_drawer(core1)->id != core_drawer(core2)->id)
|
|
|
|
return DIST_DRAWER;
|
2014-03-07 00:47:21 +07:00
|
|
|
if (core_book(core1)->id != core_book(core2)->id)
|
|
|
|
return DIST_BOOK;
|
|
|
|
if (core_mc(core1)->id != core_mc(core2)->id)
|
|
|
|
return DIST_MC;
|
|
|
|
/* Same core or sibling on same MC */
|
|
|
|
return DIST_CORE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Distance of a node to a core
|
|
|
|
*/
|
|
|
|
static int dist_node_to_core(struct toptree *node, struct toptree *core)
|
|
|
|
{
|
|
|
|
struct toptree *core_node;
|
|
|
|
int dist_min = DIST_MAX;
|
|
|
|
|
|
|
|
toptree_for_each(core_node, node, CORE)
|
|
|
|
dist_min = min(dist_min, dist_core_to_core(core_node, core));
|
|
|
|
return dist_min == DIST_MAX ? DIST_EMPTY : dist_min;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unify will delete empty nodes, therefore recreate nodes.
|
|
|
|
*/
|
|
|
|
static void toptree_unify_tree(struct toptree *tree)
|
|
|
|
{
|
|
|
|
int nid;
|
|
|
|
|
|
|
|
toptree_unify(tree);
|
|
|
|
for (nid = 0; nid < emu_nodes; nid++)
|
|
|
|
toptree_get_child(tree, nid);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the best/nearest node for a given core and ensure that no node
|
2015-08-05 16:23:53 +07:00
|
|
|
* gets more than "emu_cores->per_node_target + extra" cores.
|
2014-03-07 00:47:21 +07:00
|
|
|
*/
|
|
|
|
static struct toptree *node_for_core(struct toptree *numa, struct toptree *core,
|
|
|
|
int extra)
|
|
|
|
{
|
|
|
|
struct toptree *node, *node_best = NULL;
|
2015-08-05 16:23:53 +07:00
|
|
|
int dist_cur, dist_best, cores_target;
|
2014-03-07 00:47:21 +07:00
|
|
|
|
2015-08-05 16:23:53 +07:00
|
|
|
cores_target = emu_cores->per_node_target + extra;
|
2014-03-07 00:47:21 +07:00
|
|
|
dist_best = DIST_MAX;
|
|
|
|
node_best = NULL;
|
|
|
|
toptree_for_each(node, numa, NODE) {
|
|
|
|
/* Already pinned cores must use their nodes */
|
|
|
|
if (core_pinned_to_node_id(core) == node->id) {
|
|
|
|
node_best = node;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* Skip nodes that already have enough cores */
|
2015-08-05 16:23:53 +07:00
|
|
|
if (cores_pinned(node) >= cores_target)
|
2014-03-07 00:47:21 +07:00
|
|
|
continue;
|
|
|
|
dist_cur = dist_node_to_core(node, core);
|
|
|
|
if (dist_cur < dist_best) {
|
|
|
|
dist_best = dist_cur;
|
|
|
|
node_best = node;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return node_best;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the best node for each core with respect to "extra" core count
|
|
|
|
*/
|
|
|
|
static void toptree_to_numa_single(struct toptree *numa, struct toptree *phys,
|
|
|
|
int extra)
|
|
|
|
{
|
|
|
|
struct toptree *node, *core, *tmp;
|
|
|
|
|
|
|
|
toptree_for_each_safe(core, tmp, phys, CORE) {
|
|
|
|
node = node_for_core(numa, core, extra);
|
|
|
|
if (!node)
|
|
|
|
return;
|
|
|
|
toptree_move(core, node);
|
|
|
|
pin_core_to_node(core->id, node->id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Move structures of given level to specified NUMA node
|
|
|
|
*/
|
|
|
|
static void move_level_to_numa_node(struct toptree *node, struct toptree *phys,
|
|
|
|
enum toptree_level level, bool perfect)
|
|
|
|
{
|
2015-08-05 16:23:53 +07:00
|
|
|
int cores_free, cores_target = emu_cores->per_node_target;
|
2014-03-07 00:47:21 +07:00
|
|
|
struct toptree *cur, *tmp;
|
|
|
|
|
|
|
|
toptree_for_each_safe(cur, tmp, phys, level) {
|
2015-08-05 16:23:53 +07:00
|
|
|
cores_free = cores_target - toptree_count(node, CORE);
|
2014-03-07 00:47:21 +07:00
|
|
|
if (perfect) {
|
|
|
|
if (cores_free == toptree_count(cur, CORE))
|
|
|
|
toptree_move(cur, node);
|
|
|
|
} else {
|
|
|
|
if (cores_free >= toptree_count(cur, CORE))
|
|
|
|
toptree_move(cur, node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Move structures of a given level to NUMA nodes. If "perfect" is specified
|
|
|
|
* move only perfectly fitting structures. Otherwise move also smaller
|
|
|
|
* than needed structures.
|
|
|
|
*/
|
|
|
|
static void move_level_to_numa(struct toptree *numa, struct toptree *phys,
|
|
|
|
enum toptree_level level, bool perfect)
|
|
|
|
{
|
|
|
|
struct toptree *node;
|
|
|
|
|
|
|
|
toptree_for_each(node, numa, NODE)
|
|
|
|
move_level_to_numa_node(node, phys, level, perfect);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For the first run try to move the big structures
|
|
|
|
*/
|
|
|
|
static void toptree_to_numa_first(struct toptree *numa, struct toptree *phys)
|
|
|
|
{
|
|
|
|
struct toptree *core;
|
|
|
|
|
|
|
|
/* Always try to move perfectly fitting structures first */
|
2016-05-25 15:25:50 +07:00
|
|
|
move_level_to_numa(numa, phys, DRAWER, true);
|
|
|
|
move_level_to_numa(numa, phys, DRAWER, false);
|
2014-03-07 00:47:21 +07:00
|
|
|
move_level_to_numa(numa, phys, BOOK, true);
|
|
|
|
move_level_to_numa(numa, phys, BOOK, false);
|
|
|
|
move_level_to_numa(numa, phys, MC, true);
|
|
|
|
move_level_to_numa(numa, phys, MC, false);
|
|
|
|
/* Now pin all the moved cores */
|
|
|
|
toptree_for_each(core, numa, CORE)
|
|
|
|
pin_core_to_node(core->id, core_node(core)->id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate new topology and create required nodes
|
|
|
|
*/
|
|
|
|
static struct toptree *toptree_new(int id, int nodes)
|
|
|
|
{
|
|
|
|
struct toptree *tree;
|
|
|
|
int nid;
|
|
|
|
|
|
|
|
tree = toptree_alloc(TOPOLOGY, id);
|
|
|
|
if (!tree)
|
|
|
|
goto fail;
|
|
|
|
for (nid = 0; nid < nodes; nid++) {
|
|
|
|
if (!toptree_get_child(tree, nid))
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
return tree;
|
|
|
|
fail:
|
|
|
|
panic("NUMA emulation could not allocate topology");
|
|
|
|
}
|
|
|
|
|
2015-08-05 16:23:53 +07:00
|
|
|
/*
|
|
|
|
* Allocate and initialize core to node mapping
|
|
|
|
*/
|
2016-12-03 15:50:21 +07:00
|
|
|
static void __ref create_core_to_node_map(void)
|
2015-08-05 16:23:53 +07:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2016-12-03 15:50:21 +07:00
|
|
|
emu_cores = memblock_virt_alloc(sizeof(*emu_cores), 8);
|
2015-08-05 16:23:53 +07:00
|
|
|
for (i = 0; i < ARRAY_SIZE(emu_cores->to_node_id); i++)
|
|
|
|
emu_cores->to_node_id[i] = NODE_ID_FREE;
|
|
|
|
}
|
|
|
|
|
2014-03-07 00:47:21 +07:00
|
|
|
/*
|
|
|
|
* Move cores from physical topology into NUMA target topology
|
|
|
|
* and try to keep as much of the physical topology as possible.
|
|
|
|
*/
|
|
|
|
static struct toptree *toptree_to_numa(struct toptree *phys)
|
|
|
|
{
|
|
|
|
static int first = 1;
|
|
|
|
struct toptree *numa;
|
2015-08-05 16:23:53 +07:00
|
|
|
int cores_total;
|
2014-03-07 00:47:21 +07:00
|
|
|
|
2015-08-05 16:23:53 +07:00
|
|
|
cores_total = emu_cores->total + cores_free(phys);
|
|
|
|
emu_cores->per_node_target = cores_total / emu_nodes;
|
2014-03-07 00:47:21 +07:00
|
|
|
numa = toptree_new(TOPTREE_ID_NUMA, emu_nodes);
|
|
|
|
if (first) {
|
|
|
|
toptree_to_numa_first(numa, phys);
|
|
|
|
first = 0;
|
|
|
|
}
|
|
|
|
toptree_to_numa_single(numa, phys, 0);
|
|
|
|
toptree_to_numa_single(numa, phys, 1);
|
|
|
|
toptree_unify_tree(numa);
|
|
|
|
|
|
|
|
WARN_ON(cpumask_weight(&phys->mask));
|
|
|
|
return numa;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a toptree out of the physical topology that we got from the hypervisor
|
|
|
|
*/
|
|
|
|
static struct toptree *toptree_from_topology(void)
|
|
|
|
{
|
2016-05-25 15:25:50 +07:00
|
|
|
struct toptree *phys, *node, *drawer, *book, *mc, *core;
|
2014-03-07 00:47:21 +07:00
|
|
|
struct cpu_topology_s390 *top;
|
|
|
|
int cpu;
|
|
|
|
|
|
|
|
phys = toptree_new(TOPTREE_ID_PHYS, 1);
|
|
|
|
|
2016-12-03 15:50:21 +07:00
|
|
|
for_each_cpu(cpu, &cpus_with_topology) {
|
2016-12-02 16:38:37 +07:00
|
|
|
top = &cpu_topology[cpu];
|
2014-03-07 00:47:21 +07:00
|
|
|
node = toptree_get_child(phys, 0);
|
2016-05-25 15:25:50 +07:00
|
|
|
drawer = toptree_get_child(node, top->drawer_id);
|
|
|
|
book = toptree_get_child(drawer, top->book_id);
|
2014-03-07 00:47:21 +07:00
|
|
|
mc = toptree_get_child(book, top->socket_id);
|
2016-12-02 19:16:02 +07:00
|
|
|
core = toptree_get_child(mc, smp_get_base_cpu(cpu));
|
2016-05-25 15:25:50 +07:00
|
|
|
if (!drawer || !book || !mc || !core)
|
2014-03-07 00:47:21 +07:00
|
|
|
panic("NUMA emulation could not allocate memory");
|
|
|
|
cpumask_set_cpu(cpu, &core->mask);
|
|
|
|
toptree_update_mask(mc);
|
|
|
|
}
|
|
|
|
return phys;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add toptree core to topology and create correct CPU masks
|
|
|
|
*/
|
|
|
|
static void topology_add_core(struct toptree *core)
|
|
|
|
{
|
|
|
|
struct cpu_topology_s390 *top;
|
|
|
|
int cpu;
|
|
|
|
|
|
|
|
for_each_cpu(cpu, &core->mask) {
|
2016-12-02 16:38:37 +07:00
|
|
|
top = &cpu_topology[cpu];
|
2014-03-07 00:47:21 +07:00
|
|
|
cpumask_copy(&top->thread_mask, &core->mask);
|
|
|
|
cpumask_copy(&top->core_mask, &core_mc(core)->mask);
|
|
|
|
cpumask_copy(&top->book_mask, &core_book(core)->mask);
|
2016-05-25 15:25:50 +07:00
|
|
|
cpumask_copy(&top->drawer_mask, &core_drawer(core)->mask);
|
2015-09-22 19:21:16 +07:00
|
|
|
cpumask_set_cpu(cpu, &node_to_cpumask_map[core_node(core)->id]);
|
2014-03-07 00:47:21 +07:00
|
|
|
top->node_id = core_node(core)->id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Apply toptree to topology and create CPU masks
|
|
|
|
*/
|
|
|
|
static void toptree_to_topology(struct toptree *numa)
|
|
|
|
{
|
|
|
|
struct toptree *core;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Clear all node masks */
|
|
|
|
for (i = 0; i < MAX_NUMNODES; i++)
|
2015-09-22 19:21:16 +07:00
|
|
|
cpumask_clear(&node_to_cpumask_map[i]);
|
2014-03-07 00:47:21 +07:00
|
|
|
|
|
|
|
/* Rebuild all masks */
|
|
|
|
toptree_for_each(core, numa, CORE)
|
|
|
|
topology_add_core(core);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Show the node to core mapping
|
|
|
|
*/
|
|
|
|
static void print_node_to_core_map(void)
|
|
|
|
{
|
|
|
|
int nid, cid;
|
|
|
|
|
|
|
|
if (!numa_debug_enabled)
|
|
|
|
return;
|
|
|
|
printk(KERN_DEBUG "NUMA node to core mapping\n");
|
|
|
|
for (nid = 0; nid < emu_nodes; nid++) {
|
|
|
|
printk(KERN_DEBUG " node %3d: ", nid);
|
2015-08-05 16:23:53 +07:00
|
|
|
for (cid = 0; cid < ARRAY_SIZE(emu_cores->to_node_id); cid++) {
|
|
|
|
if (emu_cores->to_node_id[cid] == nid)
|
2014-03-07 00:47:21 +07:00
|
|
|
printk(KERN_CONT "%d ", cid);
|
|
|
|
}
|
|
|
|
printk(KERN_CONT "\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-02 17:12:01 +07:00
|
|
|
static void pin_all_possible_cpus(void)
|
|
|
|
{
|
|
|
|
int core_id, node_id, cpu;
|
|
|
|
static int initialized;
|
|
|
|
|
|
|
|
if (initialized)
|
|
|
|
return;
|
|
|
|
print_node_to_core_map();
|
|
|
|
node_id = 0;
|
|
|
|
for_each_possible_cpu(cpu) {
|
|
|
|
core_id = smp_get_base_cpu(cpu);
|
|
|
|
if (emu_cores->to_node_id[core_id] != NODE_ID_FREE)
|
|
|
|
continue;
|
|
|
|
pin_core_to_node(core_id, node_id);
|
|
|
|
cpu_topology[cpu].node_id = node_id;
|
|
|
|
node_id = (node_id + 1) % emu_nodes;
|
|
|
|
}
|
|
|
|
print_node_to_core_map();
|
|
|
|
initialized = 1;
|
|
|
|
}
|
|
|
|
|
2014-03-07 00:47:21 +07:00
|
|
|
/*
|
|
|
|
* Transfer physical topology into a NUMA topology and modify CPU masks
|
|
|
|
* according to the NUMA topology.
|
|
|
|
*
|
2015-08-01 23:12:41 +07:00
|
|
|
* Must be called with "sched_domains_mutex" lock held.
|
2014-03-07 00:47:21 +07:00
|
|
|
*/
|
|
|
|
static void emu_update_cpu_topology(void)
|
|
|
|
{
|
|
|
|
struct toptree *phys, *numa;
|
|
|
|
|
2015-08-05 16:23:53 +07:00
|
|
|
if (emu_cores == NULL)
|
|
|
|
create_core_to_node_map();
|
2014-03-07 00:47:21 +07:00
|
|
|
phys = toptree_from_topology();
|
|
|
|
numa = toptree_to_numa(phys);
|
|
|
|
toptree_free(phys);
|
|
|
|
toptree_to_topology(numa);
|
|
|
|
toptree_free(numa);
|
2016-12-02 17:12:01 +07:00
|
|
|
pin_all_possible_cpus();
|
2014-03-07 00:47:21 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If emu_size is not set, use CONFIG_EMU_SIZE. Then round to minimum
|
|
|
|
* alignment (needed for memory hotplug).
|
|
|
|
*/
|
|
|
|
static unsigned long emu_setup_size_adjust(unsigned long size)
|
|
|
|
{
|
2015-09-03 16:57:56 +07:00
|
|
|
unsigned long size_new;
|
|
|
|
|
2014-03-07 00:47:21 +07:00
|
|
|
size = size ? : CONFIG_EMU_SIZE;
|
2015-09-03 16:57:56 +07:00
|
|
|
size_new = roundup(size, memory_block_size_bytes());
|
|
|
|
if (size_new == size)
|
|
|
|
return size;
|
|
|
|
pr_warn("Increasing memory stripe size from %ld MB to %ld MB\n",
|
|
|
|
size >> 20, size_new >> 20);
|
|
|
|
return size_new;
|
2014-03-07 00:47:21 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we have not enough memory for the specified nodes, reduce the node count.
|
|
|
|
*/
|
|
|
|
static int emu_setup_nodes_adjust(int nodes)
|
|
|
|
{
|
|
|
|
int nodes_max;
|
|
|
|
|
|
|
|
nodes_max = memblock.memory.total_size / emu_size;
|
|
|
|
nodes_max = max(nodes_max, 1);
|
|
|
|
if (nodes_max >= nodes)
|
|
|
|
return nodes;
|
|
|
|
pr_warn("Not enough memory for %d nodes, reducing node count\n", nodes);
|
|
|
|
return nodes_max;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Early emu setup
|
|
|
|
*/
|
|
|
|
static void emu_setup(void)
|
|
|
|
{
|
2016-07-28 23:14:29 +07:00
|
|
|
int nid;
|
|
|
|
|
2014-03-07 00:47:21 +07:00
|
|
|
emu_size = emu_setup_size_adjust(emu_size);
|
|
|
|
emu_nodes = emu_setup_nodes_adjust(emu_nodes);
|
2016-07-28 23:14:29 +07:00
|
|
|
for (nid = 0; nid < emu_nodes; nid++)
|
|
|
|
node_set(nid, node_possible_map);
|
2014-03-07 00:47:21 +07:00
|
|
|
pr_info("Creating %d nodes with memory stripe size %ld MB\n",
|
|
|
|
emu_nodes, emu_size >> 20);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return node id for given page number
|
|
|
|
*/
|
|
|
|
static int emu_pfn_to_nid(unsigned long pfn)
|
|
|
|
{
|
|
|
|
return (pfn / (emu_size >> PAGE_SHIFT)) % emu_nodes;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return stripe size
|
|
|
|
*/
|
|
|
|
static unsigned long emu_align(void)
|
|
|
|
{
|
|
|
|
return emu_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return distance between two nodes
|
|
|
|
*/
|
|
|
|
static int emu_distance(int node1, int node2)
|
|
|
|
{
|
|
|
|
return (node1 != node2) * EMU_NODE_DIST;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Define callbacks for generic s390 NUMA infrastructure
|
|
|
|
*/
|
|
|
|
const struct numa_mode numa_mode_emu = {
|
|
|
|
.name = "emu",
|
|
|
|
.setup = emu_setup,
|
|
|
|
.update_cpu_topology = emu_update_cpu_topology,
|
|
|
|
.__pfn_to_nid = emu_pfn_to_nid,
|
|
|
|
.align = emu_align,
|
|
|
|
.distance = emu_distance,
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Kernel parameter: emu_nodes=<n>
|
|
|
|
*/
|
|
|
|
static int __init early_parse_emu_nodes(char *p)
|
|
|
|
{
|
|
|
|
int count;
|
|
|
|
|
|
|
|
if (kstrtoint(p, 0, &count) != 0 || count <= 0)
|
|
|
|
return 0;
|
|
|
|
if (count <= 0)
|
|
|
|
return 0;
|
|
|
|
emu_nodes = min(count, MAX_NUMNODES);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
early_param("emu_nodes", early_parse_emu_nodes);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Kernel parameter: emu_size=[<n>[k|M|G|T]]
|
|
|
|
*/
|
|
|
|
static int __init early_parse_emu_size(char *p)
|
|
|
|
{
|
|
|
|
emu_size = memparse(p, NULL);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
early_param("emu_size", early_parse_emu_size);
|