cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

numa.c (1998B)


      1/*
      2 * This file is subject to the terms and conditions of the GNU General Public
      3 * License.  See the file "COPYING" in the main directory of this archive
      4 * for more details.
      5 *
      6 * This file contains NUMA specific variables and functions which are used on
      7 * NUMA machines with contiguous memory.
      8 * 
      9 *                         2002/08/07 Erich Focht <efocht@ess.nec.de>
     10 */
     11
     12#include <linux/cpu.h>
     13#include <linux/kernel.h>
     14#include <linux/mm.h>
     15#include <linux/node.h>
     16#include <linux/init.h>
     17#include <linux/memblock.h>
     18#include <linux/module.h>
     19#include <asm/mmzone.h>
     20#include <asm/numa.h>
     21
     22
     23/*
     24 * The following structures are usually initialized by ACPI or
     25 * similar mechanisms and describe the NUMA characteristics of the machine.
     26 */
     27int num_node_memblks;
     28struct node_memblk_s node_memblk[NR_NODE_MEMBLKS];
     29struct node_cpuid_s node_cpuid[NR_CPUS] =
     30	{ [0 ... NR_CPUS-1] = { .phys_id = 0, .nid = NUMA_NO_NODE } };
     31
     32/*
     33 * This is a matrix with "distances" between nodes, they should be
     34 * proportional to the memory access latency ratios.
     35 */
     36u8 numa_slit[MAX_NUMNODES * MAX_NUMNODES];
     37
     38int __node_distance(int from, int to)
     39{
     40	return slit_distance(from, to);
     41}
     42EXPORT_SYMBOL(__node_distance);
     43
     44/* Identify which cnode a physical address resides on */
     45int
     46paddr_to_nid(unsigned long paddr)
     47{
     48	int	i;
     49
     50	for (i = 0; i < num_node_memblks; i++)
     51		if (paddr >= node_memblk[i].start_paddr &&
     52		    paddr < node_memblk[i].start_paddr + node_memblk[i].size)
     53			break;
     54
     55	return (i < num_node_memblks) ? node_memblk[i].nid : (num_node_memblks ? -1 : 0);
     56}
     57EXPORT_SYMBOL(paddr_to_nid);
     58
     59#if defined(CONFIG_SPARSEMEM) && defined(CONFIG_NUMA)
     60void numa_clear_node(int cpu)
     61{
     62	unmap_cpu_from_node(cpu, NUMA_NO_NODE);
     63}
     64
     65#ifdef CONFIG_MEMORY_HOTPLUG
     66/*
     67 *  SRAT information is stored in node_memblk[], then we can use SRAT
     68 *  information at memory-hot-add if necessary.
     69 */
     70
     71int memory_add_physaddr_to_nid(u64 addr)
     72{
     73	int nid = paddr_to_nid(addr);
     74	if (nid < 0)
     75		return 0;
     76	return nid;
     77}
     78#endif
     79#endif