1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*0Sstevel@tonic-gate 29*0Sstevel@tonic-gate 30*0Sstevel@tonic-gate #include <sys/cpuvar.h> 31*0Sstevel@tonic-gate #include <sys/lgrp.h> 32*0Sstevel@tonic-gate #include <sys/memnode.h> 33*0Sstevel@tonic-gate #include <sys/mman.h> 34*0Sstevel@tonic-gate #include <sys/param.h> 35*0Sstevel@tonic-gate #include <sys/systm.h> 36*0Sstevel@tonic-gate #include <sys/types.h> 37*0Sstevel@tonic-gate #include <vm/seg_spt.h> 38*0Sstevel@tonic-gate #include <vm/seg_vn.h> 39*0Sstevel@tonic-gate 40*0Sstevel@tonic-gate #include <sys/errno.h> 41*0Sstevel@tonic-gate #include <sys/kstat.h> 42*0Sstevel@tonic-gate #include <sys/cmn_err.h> 43*0Sstevel@tonic-gate #include <sys/memlist.h> 44*0Sstevel@tonic-gate #include <sys/sysmacros.h> 45*0Sstevel@tonic-gate 46*0Sstevel@tonic-gate /* 47*0Sstevel@tonic-gate * Platform-specific support for lgroups common to sun4 based platforms. 48*0Sstevel@tonic-gate * 49*0Sstevel@tonic-gate * Those sun4 platforms wanting default lgroup behavior build with 50*0Sstevel@tonic-gate * MAX_MEM_NODES = 1. Those sun4 platforms wanting other than default 51*0Sstevel@tonic-gate * lgroup behavior build with MAX_MEM_NODES > 1 and provide unique 52*0Sstevel@tonic-gate * definitions to replace the #pragma weak interfaces. 53*0Sstevel@tonic-gate */ 54*0Sstevel@tonic-gate 55*0Sstevel@tonic-gate /* 56*0Sstevel@tonic-gate * For now, there are 0 or 1 memnodes per lgroup on sun4 based platforms, 57*0Sstevel@tonic-gate * plus the root lgroup. 58*0Sstevel@tonic-gate */ 59*0Sstevel@tonic-gate #define NLGRP (MAX_MEM_NODES + 1) 60*0Sstevel@tonic-gate 61*0Sstevel@tonic-gate /* 62*0Sstevel@tonic-gate * Allocate lgrp and lgrp stat arrays statically. 63*0Sstevel@tonic-gate */ 64*0Sstevel@tonic-gate struct lgrp_stats lgrp_stats[NLGRP]; 65*0Sstevel@tonic-gate 66*0Sstevel@tonic-gate static int nlgrps_alloc; 67*0Sstevel@tonic-gate static lgrp_t lgrp_space[NLGRP]; 68*0Sstevel@tonic-gate 69*0Sstevel@tonic-gate /* 70*0Sstevel@tonic-gate * Arrays mapping lgroup handles to memnodes and vice versa. This helps 71*0Sstevel@tonic-gate * manage a copy-rename operation during DR, which moves memory from one 72*0Sstevel@tonic-gate * board to another without changing addresses/pfns or memnodes. 73*0Sstevel@tonic-gate */ 74*0Sstevel@tonic-gate int lgrphand_to_memnode[MAX_MEM_NODES]; 75*0Sstevel@tonic-gate int memnode_to_lgrphand[MAX_MEM_NODES]; 76*0Sstevel@tonic-gate 77*0Sstevel@tonic-gate static pgcnt_t lgrp_plat_mem_size_default(lgrp_handle_t, lgrp_mem_query_t); 78*0Sstevel@tonic-gate int plat_lgrphand_to_mem_node(lgrp_handle_t); 79*0Sstevel@tonic-gate lgrp_handle_t plat_mem_node_to_lgrphand(int); 80*0Sstevel@tonic-gate void plat_assign_lgrphand_to_mem_node(lgrp_handle_t, int); 81*0Sstevel@tonic-gate 82*0Sstevel@tonic-gate /* 83*0Sstevel@tonic-gate * Default sun4 lgroup interfaces which should be overriden 84*0Sstevel@tonic-gate * by platform module. 85*0Sstevel@tonic-gate */ 86*0Sstevel@tonic-gate extern void plat_lgrp_init(void); 87*0Sstevel@tonic-gate extern void plat_lgrp_config(lgrp_config_flag_t, uintptr_t); 88*0Sstevel@tonic-gate extern lgrp_handle_t plat_lgrp_cpu_to_hand(processorid_t); 89*0Sstevel@tonic-gate extern int plat_lgrp_latency(lgrp_handle_t, lgrp_handle_t); 90*0Sstevel@tonic-gate extern lgrp_handle_t plat_lgrp_root_hand(void); 91*0Sstevel@tonic-gate 92*0Sstevel@tonic-gate #pragma weak plat_lgrp_init 93*0Sstevel@tonic-gate #pragma weak plat_lgrp_config 94*0Sstevel@tonic-gate #pragma weak plat_lgrp_cpu_to_hand 95*0Sstevel@tonic-gate #pragma weak plat_lgrp_latency 96*0Sstevel@tonic-gate #pragma weak plat_lgrp_root_hand 97*0Sstevel@tonic-gate 98*0Sstevel@tonic-gate int mpo_disabled = 0; 99*0Sstevel@tonic-gate lgrp_handle_t lgrp_default_handle = LGRP_DEFAULT_HANDLE; 100*0Sstevel@tonic-gate 101*0Sstevel@tonic-gate void 102*0Sstevel@tonic-gate lgrp_plat_init(void) 103*0Sstevel@tonic-gate { 104*0Sstevel@tonic-gate int i; 105*0Sstevel@tonic-gate 106*0Sstevel@tonic-gate /* 107*0Sstevel@tonic-gate * Initialize lookup tables to invalid values so we catch 108*0Sstevel@tonic-gate * any illegal use of them. 109*0Sstevel@tonic-gate */ 110*0Sstevel@tonic-gate for (i = 0; i < MAX_MEM_NODES; i++) { 111*0Sstevel@tonic-gate memnode_to_lgrphand[i] = -1; 112*0Sstevel@tonic-gate lgrphand_to_memnode[i] = -1; 113*0Sstevel@tonic-gate } 114*0Sstevel@tonic-gate 115*0Sstevel@tonic-gate if (lgrp_topo_ht_limit() == 1) { 116*0Sstevel@tonic-gate max_mem_nodes = 1; 117*0Sstevel@tonic-gate return; 118*0Sstevel@tonic-gate } 119*0Sstevel@tonic-gate 120*0Sstevel@tonic-gate if (&plat_lgrp_cpu_to_hand) 121*0Sstevel@tonic-gate max_mem_nodes = MAX_MEM_NODES; 122*0Sstevel@tonic-gate 123*0Sstevel@tonic-gate if (&plat_lgrp_init) 124*0Sstevel@tonic-gate plat_lgrp_init(); 125*0Sstevel@tonic-gate } 126*0Sstevel@tonic-gate 127*0Sstevel@tonic-gate void 128*0Sstevel@tonic-gate lgrp_plat_main_init(void) 129*0Sstevel@tonic-gate { 130*0Sstevel@tonic-gate } 131*0Sstevel@tonic-gate 132*0Sstevel@tonic-gate /* ARGSUSED */ 133*0Sstevel@tonic-gate void 134*0Sstevel@tonic-gate lgrp_plat_config(lgrp_config_flag_t flag, uintptr_t arg) 135*0Sstevel@tonic-gate { 136*0Sstevel@tonic-gate if (max_mem_nodes == 1) 137*0Sstevel@tonic-gate return; 138*0Sstevel@tonic-gate 139*0Sstevel@tonic-gate if (&plat_lgrp_config) { 140*0Sstevel@tonic-gate plat_lgrp_config(flag, arg); 141*0Sstevel@tonic-gate } 142*0Sstevel@tonic-gate } 143*0Sstevel@tonic-gate 144*0Sstevel@tonic-gate lgrp_handle_t 145*0Sstevel@tonic-gate lgrp_plat_cpu_to_hand(processorid_t id) 146*0Sstevel@tonic-gate { 147*0Sstevel@tonic-gate if (lgrp_topo_ht_limit() > 1 && &plat_lgrp_cpu_to_hand) 148*0Sstevel@tonic-gate return (plat_lgrp_cpu_to_hand(id)); 149*0Sstevel@tonic-gate else 150*0Sstevel@tonic-gate return (LGRP_DEFAULT_HANDLE); 151*0Sstevel@tonic-gate } 152*0Sstevel@tonic-gate 153*0Sstevel@tonic-gate /* 154*0Sstevel@tonic-gate * Lgroup interfaces common to all sun4 platforms. 155*0Sstevel@tonic-gate */ 156*0Sstevel@tonic-gate 157*0Sstevel@tonic-gate /* 158*0Sstevel@tonic-gate * Return the platform handle of the lgroup that contains the physical memory 159*0Sstevel@tonic-gate * corresponding to the given page frame number 160*0Sstevel@tonic-gate */ 161*0Sstevel@tonic-gate lgrp_handle_t 162*0Sstevel@tonic-gate lgrp_plat_pfn_to_hand(pfn_t pfn) 163*0Sstevel@tonic-gate { 164*0Sstevel@tonic-gate int mnode; 165*0Sstevel@tonic-gate 166*0Sstevel@tonic-gate if (lgrp_topo_ht_limit() == 1 || max_mem_nodes == 1) 167*0Sstevel@tonic-gate return (LGRP_DEFAULT_HANDLE); 168*0Sstevel@tonic-gate 169*0Sstevel@tonic-gate if (pfn > physmax) 170*0Sstevel@tonic-gate return (LGRP_NULL_HANDLE); 171*0Sstevel@tonic-gate 172*0Sstevel@tonic-gate mnode = PFN_2_MEM_NODE(pfn); 173*0Sstevel@tonic-gate return (MEM_NODE_2_LGRPHAND(mnode)); 174*0Sstevel@tonic-gate } 175*0Sstevel@tonic-gate 176*0Sstevel@tonic-gate /* 177*0Sstevel@tonic-gate * Return the maximum number of supported lgroups 178*0Sstevel@tonic-gate */ 179*0Sstevel@tonic-gate int 180*0Sstevel@tonic-gate lgrp_plat_max_lgrps(void) 181*0Sstevel@tonic-gate { 182*0Sstevel@tonic-gate return (NLGRP); 183*0Sstevel@tonic-gate } 184*0Sstevel@tonic-gate 185*0Sstevel@tonic-gate /* 186*0Sstevel@tonic-gate * Return the number of free pages in an lgroup. 187*0Sstevel@tonic-gate * 188*0Sstevel@tonic-gate * For query of LGRP_MEM_SIZE_FREE, return the number of base pagesize 189*0Sstevel@tonic-gate * pages on freelists. For query of LGRP_MEM_SIZE_AVAIL, return the 190*0Sstevel@tonic-gate * number of allocatable base pagesize pages corresponding to the 191*0Sstevel@tonic-gate * lgroup (e.g. do not include page_t's, BOP_ALLOC()'ed memory, ..) 192*0Sstevel@tonic-gate * For query of LGRP_MEM_SIZE_INSTALL, return the amount of physical 193*0Sstevel@tonic-gate * memory installed, regardless of whether or not it's usable. 194*0Sstevel@tonic-gate */ 195*0Sstevel@tonic-gate pgcnt_t 196*0Sstevel@tonic-gate lgrp_plat_mem_size(lgrp_handle_t plathand, lgrp_mem_query_t query) 197*0Sstevel@tonic-gate { 198*0Sstevel@tonic-gate int mnode; 199*0Sstevel@tonic-gate pgcnt_t npgs = (pgcnt_t)0; 200*0Sstevel@tonic-gate extern struct memlist *phys_avail; 201*0Sstevel@tonic-gate extern struct memlist *phys_install; 202*0Sstevel@tonic-gate 203*0Sstevel@tonic-gate 204*0Sstevel@tonic-gate if (lgrp_topo_ht_limit() == 1 || max_mem_nodes == 1 || mpo_disabled || 205*0Sstevel@tonic-gate plathand == LGRP_DEFAULT_HANDLE) 206*0Sstevel@tonic-gate return (lgrp_plat_mem_size_default(plathand, query)); 207*0Sstevel@tonic-gate 208*0Sstevel@tonic-gate if (plathand != LGRP_NULL_HANDLE) { 209*0Sstevel@tonic-gate mnode = plat_lgrphand_to_mem_node(plathand); 210*0Sstevel@tonic-gate if (mnode >= 0 && mem_node_config[mnode].exists) { 211*0Sstevel@tonic-gate switch (query) { 212*0Sstevel@tonic-gate case LGRP_MEM_SIZE_FREE: 213*0Sstevel@tonic-gate npgs = mem_node_config[mnode].cursize; 214*0Sstevel@tonic-gate break; 215*0Sstevel@tonic-gate case LGRP_MEM_SIZE_AVAIL: 216*0Sstevel@tonic-gate npgs = mem_node_memlist_pages(mnode, 217*0Sstevel@tonic-gate phys_avail); 218*0Sstevel@tonic-gate break; 219*0Sstevel@tonic-gate case LGRP_MEM_SIZE_INSTALL: 220*0Sstevel@tonic-gate npgs = mem_node_memlist_pages(mnode, 221*0Sstevel@tonic-gate phys_install); 222*0Sstevel@tonic-gate break; 223*0Sstevel@tonic-gate default: 224*0Sstevel@tonic-gate break; 225*0Sstevel@tonic-gate } 226*0Sstevel@tonic-gate } 227*0Sstevel@tonic-gate } 228*0Sstevel@tonic-gate return (npgs); 229*0Sstevel@tonic-gate } 230*0Sstevel@tonic-gate 231*0Sstevel@tonic-gate /* 232*0Sstevel@tonic-gate * Return latency between "from" and "to" lgroups 233*0Sstevel@tonic-gate * If "from" or "to" is LGRP_NONE, then just return latency within other 234*0Sstevel@tonic-gate * lgroup. This latency number can only be used for relative comparison 235*0Sstevel@tonic-gate * between lgroups on the running system, cannot be used across platforms, 236*0Sstevel@tonic-gate * and may not reflect the actual latency. It is platform and implementation 237*0Sstevel@tonic-gate * specific, so platform gets to decide its value. 238*0Sstevel@tonic-gate */ 239*0Sstevel@tonic-gate int 240*0Sstevel@tonic-gate lgrp_plat_latency(lgrp_handle_t from, lgrp_handle_t to) 241*0Sstevel@tonic-gate { 242*0Sstevel@tonic-gate if (lgrp_topo_ht_limit() > 1 && &plat_lgrp_latency) 243*0Sstevel@tonic-gate return (plat_lgrp_latency(from, to)); 244*0Sstevel@tonic-gate else 245*0Sstevel@tonic-gate return (0); 246*0Sstevel@tonic-gate } 247*0Sstevel@tonic-gate 248*0Sstevel@tonic-gate /* 249*0Sstevel@tonic-gate * Return platform handle for root lgroup 250*0Sstevel@tonic-gate */ 251*0Sstevel@tonic-gate lgrp_handle_t 252*0Sstevel@tonic-gate lgrp_plat_root_hand(void) 253*0Sstevel@tonic-gate { 254*0Sstevel@tonic-gate if (&plat_lgrp_root_hand) 255*0Sstevel@tonic-gate return (plat_lgrp_root_hand()); 256*0Sstevel@tonic-gate else 257*0Sstevel@tonic-gate return (LGRP_DEFAULT_HANDLE); 258*0Sstevel@tonic-gate } 259*0Sstevel@tonic-gate 260*0Sstevel@tonic-gate /* Internal interfaces */ 261*0Sstevel@tonic-gate /* 262*0Sstevel@tonic-gate * Return the number of free, allocatable, or installed 263*0Sstevel@tonic-gate * pages in an lgroup 264*0Sstevel@tonic-gate * This is a copy of the MAX_MEM_NODES == 1 version of the routine 265*0Sstevel@tonic-gate * used when MPO is disabled (i.e. single lgroup) 266*0Sstevel@tonic-gate */ 267*0Sstevel@tonic-gate /* ARGSUSED */ 268*0Sstevel@tonic-gate static pgcnt_t 269*0Sstevel@tonic-gate lgrp_plat_mem_size_default(lgrp_handle_t lgrphand, lgrp_mem_query_t query) 270*0Sstevel@tonic-gate { 271*0Sstevel@tonic-gate extern struct memlist *phys_install; 272*0Sstevel@tonic-gate extern struct memlist *phys_avail; 273*0Sstevel@tonic-gate struct memlist *mlist; 274*0Sstevel@tonic-gate pgcnt_t npgs = 0; 275*0Sstevel@tonic-gate 276*0Sstevel@tonic-gate switch (query) { 277*0Sstevel@tonic-gate case LGRP_MEM_SIZE_FREE: 278*0Sstevel@tonic-gate return ((pgcnt_t)freemem); 279*0Sstevel@tonic-gate case LGRP_MEM_SIZE_AVAIL: 280*0Sstevel@tonic-gate memlist_read_lock(); 281*0Sstevel@tonic-gate for (mlist = phys_avail; mlist; mlist = mlist->next) 282*0Sstevel@tonic-gate npgs += btop(mlist->size); 283*0Sstevel@tonic-gate memlist_read_unlock(); 284*0Sstevel@tonic-gate return (npgs); 285*0Sstevel@tonic-gate case LGRP_MEM_SIZE_INSTALL: 286*0Sstevel@tonic-gate memlist_read_lock(); 287*0Sstevel@tonic-gate for (mlist = phys_install; mlist; mlist = mlist->next) 288*0Sstevel@tonic-gate npgs += btop(mlist->size); 289*0Sstevel@tonic-gate memlist_read_unlock(); 290*0Sstevel@tonic-gate return (npgs); 291*0Sstevel@tonic-gate default: 292*0Sstevel@tonic-gate return ((pgcnt_t)0); 293*0Sstevel@tonic-gate } 294*0Sstevel@tonic-gate } 295*0Sstevel@tonic-gate 296*0Sstevel@tonic-gate /* 297*0Sstevel@tonic-gate * Return the memnode associated with the specified lgroup handle 298*0Sstevel@tonic-gate */ 299*0Sstevel@tonic-gate int 300*0Sstevel@tonic-gate plat_lgrphand_to_mem_node(lgrp_handle_t plathand) 301*0Sstevel@tonic-gate { 302*0Sstevel@tonic-gate int mnode; 303*0Sstevel@tonic-gate 304*0Sstevel@tonic-gate if (lgrp_topo_ht_limit() == 1 || mpo_disabled || max_mem_nodes == 1) 305*0Sstevel@tonic-gate return (-1); 306*0Sstevel@tonic-gate 307*0Sstevel@tonic-gate /* 308*0Sstevel@tonic-gate * We should always receive a valid pointer to a platform 309*0Sstevel@tonic-gate * handle, as we can not choose the allocation policy in 310*0Sstevel@tonic-gate * this layer. 311*0Sstevel@tonic-gate */ 312*0Sstevel@tonic-gate ASSERT((int)plathand >= 0 && (int)plathand < max_mem_nodes); 313*0Sstevel@tonic-gate 314*0Sstevel@tonic-gate mnode = lgrphand_to_memnode[(int)plathand]; 315*0Sstevel@tonic-gate return (mnode); 316*0Sstevel@tonic-gate } 317*0Sstevel@tonic-gate 318*0Sstevel@tonic-gate lgrp_handle_t 319*0Sstevel@tonic-gate plat_mem_node_to_lgrphand(int mnode) 320*0Sstevel@tonic-gate { 321*0Sstevel@tonic-gate if (lgrp_topo_ht_limit() == 1 || mpo_disabled || max_mem_nodes == 1) 322*0Sstevel@tonic-gate return (lgrp_default_handle); 323*0Sstevel@tonic-gate 324*0Sstevel@tonic-gate ASSERT(mnode >= 0 && mnode < max_mem_nodes); 325*0Sstevel@tonic-gate return (memnode_to_lgrphand[mnode]); 326*0Sstevel@tonic-gate } 327*0Sstevel@tonic-gate 328*0Sstevel@tonic-gate void 329*0Sstevel@tonic-gate plat_assign_lgrphand_to_mem_node(lgrp_handle_t plathand, int mnode) 330*0Sstevel@tonic-gate { 331*0Sstevel@tonic-gate if (lgrp_topo_ht_limit() == 1 || mpo_disabled || max_mem_nodes == 1) 332*0Sstevel@tonic-gate return; 333*0Sstevel@tonic-gate 334*0Sstevel@tonic-gate ASSERT(plathand < max_mem_nodes); 335*0Sstevel@tonic-gate ASSERT(mnode >= 0 && mnode < max_mem_nodes); 336*0Sstevel@tonic-gate 337*0Sstevel@tonic-gate lgrphand_to_memnode[plathand] = mnode; 338*0Sstevel@tonic-gate memnode_to_lgrphand[mnode] = plathand; 339*0Sstevel@tonic-gate } 340*0Sstevel@tonic-gate 341*0Sstevel@tonic-gate lgrp_t * 342*0Sstevel@tonic-gate lgrp_plat_alloc(lgrp_id_t lgrpid) 343*0Sstevel@tonic-gate { 344*0Sstevel@tonic-gate lgrp_t *lgrp; 345*0Sstevel@tonic-gate 346*0Sstevel@tonic-gate lgrp = &lgrp_space[nlgrps_alloc++]; 347*0Sstevel@tonic-gate if (lgrpid >= NLGRP || nlgrps_alloc > NLGRP) 348*0Sstevel@tonic-gate return (NULL); 349*0Sstevel@tonic-gate return (lgrp); 350*0Sstevel@tonic-gate } 351*0Sstevel@tonic-gate 352*0Sstevel@tonic-gate /* 353*0Sstevel@tonic-gate * Do any platform specific preparation and/or building of full lgroup topology 354*0Sstevel@tonic-gate */ 355*0Sstevel@tonic-gate void 356*0Sstevel@tonic-gate lgrp_plat_build_topo(void) 357*0Sstevel@tonic-gate { 358*0Sstevel@tonic-gate } 359*0Sstevel@tonic-gate 360*0Sstevel@tonic-gate /* 361*0Sstevel@tonic-gate * Probe memory in each node from current CPU to determine latency topology 362*0Sstevel@tonic-gate */ 363*0Sstevel@tonic-gate void 364*0Sstevel@tonic-gate lgrp_plat_probe(void) 365*0Sstevel@tonic-gate { 366*0Sstevel@tonic-gate } 367