xref: /illumos-gate/usr/src/uts/common/sys/lgrp.h (revision f06dce2c)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5c6402783Sakolb  * Common Development and Distribution License (the "License").
6c6402783Sakolb  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
21c6402783Sakolb 
227c478bd9Sstevel@tonic-gate /*
23d5d7cf4eSJonathan Chew  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*f06dce2cSAndrew Stormont  *
26*f06dce2cSAndrew Stormont  * Copyright 2017 RackTop Systems.
277c478bd9Sstevel@tonic-gate  */
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #ifndef	_LGRP_H
307c478bd9Sstevel@tonic-gate #define	_LGRP_H
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate /*
337c478bd9Sstevel@tonic-gate  * locality group definitions for kernel
347c478bd9Sstevel@tonic-gate  */
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #include <sys/types.h>
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
397c478bd9Sstevel@tonic-gate extern "C" {
407c478bd9Sstevel@tonic-gate #endif
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate #define	LGRP_NONE	(-1)		/* non-existent lgroup ID */
437c478bd9Sstevel@tonic-gate 
44*f06dce2cSAndrew Stormont #if !defined(_KERNEL) && !defined(_FAKE_KERNEL) && !defined(_KMEMUSER)
457c478bd9Sstevel@tonic-gate typedef struct lgrp_mem_policy_info { int opaque[2]; }	lgrp_mem_policy_info_t;
46*f06dce2cSAndrew Stormont #endif	/* !_KERNEL && !_FAKE_KERNEL && !_KMEMUSER */
477c478bd9Sstevel@tonic-gate 
48*f06dce2cSAndrew Stormont #if defined(_KERNEL) || defined(_FAKE_KERNEL) || defined(_KMEMUSER)
497c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h>
507c478bd9Sstevel@tonic-gate #include <sys/bitmap.h>
517c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
527c478bd9Sstevel@tonic-gate #include <vm/anon.h>
537c478bd9Sstevel@tonic-gate #include <vm/seg.h>
547c478bd9Sstevel@tonic-gate #include <sys/lgrp_user.h>
557c478bd9Sstevel@tonic-gate #include <sys/param.h>
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate typedef	uint32_t	lgrp_load_t;	/* lgrp_loadavg type */
587c478bd9Sstevel@tonic-gate typedef uintptr_t	lgrp_handle_t;	/* lgrp handle */
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate #define	LGRP_NONE_SUCH		LGRP_NONE	/* non-existent lgroup ID */
617c478bd9Sstevel@tonic-gate /* null platform handle */
627c478bd9Sstevel@tonic-gate #define	LGRP_NULL_HANDLE	((lgrp_handle_t)0xbadbad)
637c478bd9Sstevel@tonic-gate #define	LGRP_DEFAULT_HANDLE	((lgrp_handle_t)0xbabecafe) /* uma handle */
647c478bd9Sstevel@tonic-gate #define	LGRP_ROOTID		(0)		/* root lgroup ID */
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate /*
677c478bd9Sstevel@tonic-gate  * Maximum number of lgrps a platform may define.
687c478bd9Sstevel@tonic-gate  */
697c478bd9Sstevel@tonic-gate #define	NLGRPS_MAX		64
707c478bd9Sstevel@tonic-gate #define	LGRP_LOADAVG_MAX	UINT32_MAX
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate /*
737c478bd9Sstevel@tonic-gate  * The load-average we expect for one cpu-bound thread's worth of load
747c478bd9Sstevel@tonic-gate  */
757c478bd9Sstevel@tonic-gate #define	LGRP_LOADAVG_THREAD_MAX		65516
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate /*
787c478bd9Sstevel@tonic-gate  * The input to the load-average generating function for one cpu-bound thread's
797c478bd9Sstevel@tonic-gate  * worth of load
807c478bd9Sstevel@tonic-gate  */
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate #define	LGRP_LOADAVG_IN_THREAD_MAX	128
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate /*
857c478bd9Sstevel@tonic-gate  * LPL actions
867c478bd9Sstevel@tonic-gate  */
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate typedef enum {
897c478bd9Sstevel@tonic-gate 	LPL_INCREMENT,
907c478bd9Sstevel@tonic-gate 	LPL_DECREMENT
917c478bd9Sstevel@tonic-gate } lpl_act_t;
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate /*
947c478bd9Sstevel@tonic-gate  * lgroup statistics.  Most of these are counters that are updated
957c478bd9Sstevel@tonic-gate  * dynamically so they are hashed to CPU buckets to reduce cache
967c478bd9Sstevel@tonic-gate  * interference.  The remaining statistics are snapshots of kernel
977c478bd9Sstevel@tonic-gate  * data, so they aren't stored in the array of counter stats.
987c478bd9Sstevel@tonic-gate  *
997c478bd9Sstevel@tonic-gate  * For the hashed stats to make sense, you have to sum all the buckets for
1007c478bd9Sstevel@tonic-gate  * that stat, hence macros are provided to read the stats.
1017c478bd9Sstevel@tonic-gate  */
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate #define	LGRP_NUM_CPU_BUCKETS	8	/* must be power of 2 */
1047c478bd9Sstevel@tonic-gate #define	LGRP_CPU_BUCKET_MASK	(LGRP_NUM_CPU_BUCKETS - 1)
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate /*
1077c478bd9Sstevel@tonic-gate  * Flags for what to do with lgroup memory policy
1087c478bd9Sstevel@tonic-gate  * Used for heap and stack where policy is extended to new segments added to
1097c478bd9Sstevel@tonic-gate  * the end
1107c478bd9Sstevel@tonic-gate  */
1117c478bd9Sstevel@tonic-gate #define	LGRP_MP_FLAG_EXTEND_UP		0x1	/* policy should extend up */
1127c478bd9Sstevel@tonic-gate #define	LGRP_MP_FLAG_EXTEND_DOWN	0x2	/* policy should extend down */
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate #define	LGRP_STAT(stats, bucket, whichstat) \
1157c478bd9Sstevel@tonic-gate 	((stats)->ls_data[bucket][whichstat])
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate /* Return a pointer suitable for an atomic 64-bit op on the bucket */
1187c478bd9Sstevel@tonic-gate #define	LGRP_STAT_WRITE_PTR(stats, whichstat) \
1197c478bd9Sstevel@tonic-gate 	(&LGRP_STAT(stats, (CPU->cpu_id) & LGRP_CPU_BUCKET_MASK, \
1207c478bd9Sstevel@tonic-gate 	    whichstat))
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate /* Sum up all the buckets and return the value in 'val' */
1237c478bd9Sstevel@tonic-gate #define	LGRP_STAT_READ(stats, whichstat, val) {				\
1247c478bd9Sstevel@tonic-gate 	int bkt;							\
1257c478bd9Sstevel@tonic-gate 	for (val = 0, bkt = 0; bkt < LGRP_NUM_CPU_BUCKETS; bkt++)	\
1267c478bd9Sstevel@tonic-gate 		val += LGRP_STAT(stats, bkt, whichstat);		\
1277c478bd9Sstevel@tonic-gate }
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate /* Reset all buckets for the stat to 0 */
1307c478bd9Sstevel@tonic-gate #define	LGRP_STAT_RESET(stats, stat) {					\
1317c478bd9Sstevel@tonic-gate 	int i;								\
1327c478bd9Sstevel@tonic-gate 	for (i = 0; i < LGRP_NUM_CPU_BUCKETS; i++)			\
1337c478bd9Sstevel@tonic-gate 		LGRP_STAT(stats, i, stat) = 0;				\
1347c478bd9Sstevel@tonic-gate }
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate /*
1377c478bd9Sstevel@tonic-gate  * Define all of the statistics that are kept for lgrp kstats,
1387c478bd9Sstevel@tonic-gate  * and their corresponding text names.
1397c478bd9Sstevel@tonic-gate  */
1407c478bd9Sstevel@tonic-gate 
1417c478bd9Sstevel@tonic-gate typedef enum lgrp_stat_types {
1427c478bd9Sstevel@tonic-gate 	LGRP_NUM_MIGR,		/* # migrations away from this lgrp */
1437c478bd9Sstevel@tonic-gate 	LGRP_NUM_ALLOC_FAIL,	/* # times alloc fails for chosen lgrp */
1447c478bd9Sstevel@tonic-gate 	LGRP_PM_SRC_PGS,	/* # pages migrated from this lgrp */
1457c478bd9Sstevel@tonic-gate 	LGRP_PM_DEST_PGS,	/* # pages migrated to this lgrp */
1467c478bd9Sstevel@tonic-gate 	LGRP_PM_FAIL_ALLOC_PGS,	/* # pages failed to migrate to this lgrp */
1477c478bd9Sstevel@tonic-gate 	LGRP_PM_FAIL_LOCK_PGS,	/* # pages failed to migrate from this lgrp */
1487c478bd9Sstevel@tonic-gate 	LGRP_PMM_PGS,		/* # pages marked to migrate from this lgrp */
1497c478bd9Sstevel@tonic-gate 	LGRP_PMM_FAIL_PGS,	/* # pages marked to migrate from this lgrp */
1507c478bd9Sstevel@tonic-gate 	LGRP_NUM_DEFAULT,	/* # of times default policy applied */
1517c478bd9Sstevel@tonic-gate 	LGRP_NUM_NEXT,		/* # of times next touch policy applied */
1527c478bd9Sstevel@tonic-gate 	LGRP_NUM_RANDOM,	/* # of times random policy applied */
1537c478bd9Sstevel@tonic-gate 	LGRP_NUM_RANDOM_PROC,	/* # of times random proc policy applied */
1547c478bd9Sstevel@tonic-gate 	LGRP_NUM_RANDOM_PSET,	/* # of times random pset policy applied */
1557c478bd9Sstevel@tonic-gate 	LGRP_NUM_ROUNDROBIN,	/* # of times round robin policy applied */
1562cb27123Saguzovsk 	LGRP_NUM_NEXT_SEG,	/* # of times next to seg policy applied */
1577c478bd9Sstevel@tonic-gate 	LGRP_NUM_COUNTER_STATS,	/* always last */
1587c478bd9Sstevel@tonic-gate 	LGRP_CTR_STATS_ALLOC = 16	/* cache-align pad - multiple of 8 */
1597c478bd9Sstevel@tonic-gate 				/* always keep >= LGRP_NUM_COUNTER_STATS */
1607c478bd9Sstevel@tonic-gate } lgrp_stat_t;
1617c478bd9Sstevel@tonic-gate 
1627c478bd9Sstevel@tonic-gate typedef enum lgrp_snap_stat_types {
1637c478bd9Sstevel@tonic-gate 	LGRP_NUM_CPUS,		/* number of CPUs */
1647c478bd9Sstevel@tonic-gate 	LGRP_NUM_PG_FREE,	/* # of free pages */
1657c478bd9Sstevel@tonic-gate 	LGRP_NUM_PG_AVAIL,	/* # of allocatable physical pages */
1667c478bd9Sstevel@tonic-gate 	LGRP_NUM_PG_INSTALL,	/* # of installed physical pages */
167c6402783Sakolb 	LGRP_LOADAVG,		/* unscaled load average of this lgrp */
168c6402783Sakolb 	LGRP_LOADAVG_SCALE,	/* load unit of one CPU bound thread */
1697c478bd9Sstevel@tonic-gate 	LGRP_NUM_SNAPSHOT_STATS	/* always last */
1707c478bd9Sstevel@tonic-gate } lgrp_snap_stat_t;
1717c478bd9Sstevel@tonic-gate 
1727c478bd9Sstevel@tonic-gate #define	LGRP_KSTAT_NAMES		\
1737c478bd9Sstevel@tonic-gate static char *lgrp_kstat_names[] = {	\
1747c478bd9Sstevel@tonic-gate 					\
1757c478bd9Sstevel@tonic-gate 	/* Counter stats */		\
1767c478bd9Sstevel@tonic-gate 	"lwp migrations",		\
1777c478bd9Sstevel@tonic-gate 	"alloc fail",			\
1787c478bd9Sstevel@tonic-gate 	"pages migrated from",		\
1797c478bd9Sstevel@tonic-gate 	"pages migrated to",		\
1807c478bd9Sstevel@tonic-gate 	"pages failed to migrate to",	\
1817c478bd9Sstevel@tonic-gate 	"pages failed to migrate from",	\
1827c478bd9Sstevel@tonic-gate 	"pages marked for migration",	\
1837c478bd9Sstevel@tonic-gate 	"pages failed to mark",		\
1847c478bd9Sstevel@tonic-gate 	"default policy",		\
1857c478bd9Sstevel@tonic-gate 	"next-touch policy",		\
1867c478bd9Sstevel@tonic-gate 	"random policy",		\
1877c478bd9Sstevel@tonic-gate 	"span process policy",		\
1887c478bd9Sstevel@tonic-gate 	"span psrset policy",		\
1897c478bd9Sstevel@tonic-gate 	"round robin policy",		\
1902cb27123Saguzovsk 	"next-seg policy",		\
1917c478bd9Sstevel@tonic-gate 					\
1927c478bd9Sstevel@tonic-gate 	/* Snapshot stats */		\
1937c478bd9Sstevel@tonic-gate 	"cpus",				\
1947c478bd9Sstevel@tonic-gate 	"pages free",			\
1957c478bd9Sstevel@tonic-gate 	"pages avail",			\
1967c478bd9Sstevel@tonic-gate 	"pages installed",		\
197c6402783Sakolb 	"load average",			\
198c6402783Sakolb 	"loadscale"			\
1997c478bd9Sstevel@tonic-gate }
2007c478bd9Sstevel@tonic-gate 
2017c478bd9Sstevel@tonic-gate #define	LGRP_NUM_STATS	((int)LGRP_NUM_COUNTER_STATS +			\
2027c478bd9Sstevel@tonic-gate 	(int)LGRP_NUM_SNAPSHOT_STATS)
2037c478bd9Sstevel@tonic-gate 
2047c478bd9Sstevel@tonic-gate /*
2057c478bd9Sstevel@tonic-gate  * The contents of this structure are opaque and should only be
2067c478bd9Sstevel@tonic-gate  * accessed through the LGRP_STAT macro.
2077c478bd9Sstevel@tonic-gate  */
2087c478bd9Sstevel@tonic-gate struct lgrp_stats {
2097c478bd9Sstevel@tonic-gate 	int64_t ls_data[LGRP_NUM_CPU_BUCKETS][LGRP_CTR_STATS_ALLOC];
2107c478bd9Sstevel@tonic-gate };
2117c478bd9Sstevel@tonic-gate 
2127c478bd9Sstevel@tonic-gate /* The kernel's version of a bitmap of lgroups */
2137c478bd9Sstevel@tonic-gate typedef uint64_t klgrpset_t;
2147c478bd9Sstevel@tonic-gate 
2157c478bd9Sstevel@tonic-gate /*
2167c478bd9Sstevel@tonic-gate  * This really belongs in memnode.h, but it must be defined here to avoid
2177c478bd9Sstevel@tonic-gate  * recursive inclusion problems. Note that memnode.h includes this header.
2187c478bd9Sstevel@tonic-gate  */
2197c478bd9Sstevel@tonic-gate typedef	uint64_t	mnodeset_t;
2207c478bd9Sstevel@tonic-gate 
2217c478bd9Sstevel@tonic-gate /*
2227c478bd9Sstevel@tonic-gate  * lgroup structure
2237c478bd9Sstevel@tonic-gate  *
2247c478bd9Sstevel@tonic-gate  * Visible to generic code and contains the lgroup ID, CPUs in this lgroup,
2257c478bd9Sstevel@tonic-gate  * and a platform handle used to identify this lgroup to the lgroup platform
2267c478bd9Sstevel@tonic-gate  * support code
2277c478bd9Sstevel@tonic-gate  */
2287c478bd9Sstevel@tonic-gate typedef struct lgrp {
2297c478bd9Sstevel@tonic-gate 
2307c478bd9Sstevel@tonic-gate 	lgrp_id_t 	lgrp_id;	/* which lgroup	*/
2317c478bd9Sstevel@tonic-gate 	int		lgrp_latency;
2327c478bd9Sstevel@tonic-gate 	lgrp_handle_t  	lgrp_plathand;	/* handle for platform calls */
2337c478bd9Sstevel@tonic-gate 	struct lgrp	*lgrp_parent;	/* parent lgroup */
2347c478bd9Sstevel@tonic-gate 	uint_t		lgrp_reserved1;	/* filler */
2357c478bd9Sstevel@tonic-gate 	uint_t		lgrp_childcnt;	/* number of children lgroups */
2367c478bd9Sstevel@tonic-gate 	klgrpset_t	lgrp_children;	/* children lgroups */
2377c478bd9Sstevel@tonic-gate 	klgrpset_t	lgrp_leaves;	/* (direct decendant) leaf lgroups */
2387c478bd9Sstevel@tonic-gate 
2397c478bd9Sstevel@tonic-gate 	/*
2407c478bd9Sstevel@tonic-gate 	 * set of lgroups containing a given type of resource
2417c478bd9Sstevel@tonic-gate 	 * at this level of locality
2427c478bd9Sstevel@tonic-gate 	 */
2437c478bd9Sstevel@tonic-gate 	klgrpset_t	lgrp_set[LGRP_RSRC_COUNT];
2447c478bd9Sstevel@tonic-gate 
2457c478bd9Sstevel@tonic-gate 	mnodeset_t	lgrp_mnodes;	/* set of memory nodes in this lgroup */
2467c478bd9Sstevel@tonic-gate 	uint_t		lgrp_nmnodes;	/* number of memnodes */
2477c478bd9Sstevel@tonic-gate 	uint_t		lgrp_reserved2;	/* filler */
2487c478bd9Sstevel@tonic-gate 
2497c478bd9Sstevel@tonic-gate 	struct cpu	*lgrp_cpu;	/* pointer to a cpu may be null */
2507c478bd9Sstevel@tonic-gate 	uint_t		lgrp_cpucnt;	/* number of cpus in this lgrp	*/
2517c478bd9Sstevel@tonic-gate 	kstat_t		*lgrp_kstat;	/* per-lgrp kstats */
2527c478bd9Sstevel@tonic-gate } lgrp_t;
2537c478bd9Sstevel@tonic-gate 
2547c478bd9Sstevel@tonic-gate /*
2557c478bd9Sstevel@tonic-gate  * lgroup load average structure
2567c478bd9Sstevel@tonic-gate  */
2577c478bd9Sstevel@tonic-gate 
2587c478bd9Sstevel@tonic-gate typedef struct lgrp_ld {
2597c478bd9Sstevel@tonic-gate 	lgrp_load_t	lpl_loadavg;	/* load average		*/
2607c478bd9Sstevel@tonic-gate 	uint_t		lpl_ncpu;	/* how many cpus	*/
2617c478bd9Sstevel@tonic-gate 	lgrp_id_t	lpl_lgrpid;	/* which group this lpl part of */
2627c478bd9Sstevel@tonic-gate 	lgrp_t		*lpl_lgrp;	/* ptr to lpl's lgrp */
2637c478bd9Sstevel@tonic-gate 	struct lgrp_ld	*lpl_parent;	/* lpl of parent lgrp */
2647c478bd9Sstevel@tonic-gate 	struct cpu	*lpl_cpus;	/* list of cpus in lpl */
2657c478bd9Sstevel@tonic-gate 					/* NULL for non-leaf lgrps */
2667c478bd9Sstevel@tonic-gate 	uint_t		lpl_nrset;	/* no. of leaf lpls for lgrp */
2677c478bd9Sstevel@tonic-gate 	hrtime_t	lpl_homed_time;	/* time of last homing to this lpl */
2686890d023SEric Saxe 	uint_t		lpl_rset_sz;	/* Resource set capacity */
2696890d023SEric Saxe 	struct lgrp_ld	**lpl_rset;	/* leaf lpls for lgrp */
2707c478bd9Sstevel@tonic-gate 					/* contains ptr to self for leaf lgrp */
2716890d023SEric Saxe 	int		*lpl_id2rset;	/* mapping of lgrpid to rset index */
2727c478bd9Sstevel@tonic-gate } lpl_t;
2737c478bd9Sstevel@tonic-gate 
2747c478bd9Sstevel@tonic-gate /*
2757c478bd9Sstevel@tonic-gate  * 1 << LGRP_MAX_EFFECT_SHFT ==  lgrp_loadavg_max_effect
2767c478bd9Sstevel@tonic-gate  */
2777c478bd9Sstevel@tonic-gate #define	LGRP_MAX_EFFECT_SHFT 16
2787c478bd9Sstevel@tonic-gate 
2797c478bd9Sstevel@tonic-gate /*
2807c478bd9Sstevel@tonic-gate  * Operations handled by lgrp_config()
2817c478bd9Sstevel@tonic-gate  */
2827c478bd9Sstevel@tonic-gate typedef enum lgrp_config_flag {
2837c478bd9Sstevel@tonic-gate 	LGRP_CONFIG_NOP,
2847c478bd9Sstevel@tonic-gate 	LGRP_CONFIG_CPU_ADD,
2857c478bd9Sstevel@tonic-gate 	LGRP_CONFIG_CPU_DEL,
2867c478bd9Sstevel@tonic-gate 	LGRP_CONFIG_CPU_ONLINE,
2877c478bd9Sstevel@tonic-gate 	LGRP_CONFIG_CPU_OFFLINE,
2887c478bd9Sstevel@tonic-gate 	LGRP_CONFIG_CPUPART_ADD,
2897c478bd9Sstevel@tonic-gate 	LGRP_CONFIG_CPUPART_DEL,
2907c478bd9Sstevel@tonic-gate 	LGRP_CONFIG_MEM_ADD,
2917c478bd9Sstevel@tonic-gate 	LGRP_CONFIG_MEM_DEL,
2927c478bd9Sstevel@tonic-gate 	LGRP_CONFIG_MEM_RENAME,
2937c478bd9Sstevel@tonic-gate 	LGRP_CONFIG_GEN_UPDATE,
2947c478bd9Sstevel@tonic-gate 	LGRP_CONFIG_FLATTEN,
29503400a71Sjjc 	LGRP_CONFIG_LAT_CHANGE_ALL,
29603400a71Sjjc 	LGRP_CONFIG_LAT_CHANGE
2977c478bd9Sstevel@tonic-gate } lgrp_config_flag_t;
2987c478bd9Sstevel@tonic-gate 
299d5d7cf4eSJonathan Chew /*
300d5d7cf4eSJonathan Chew  * Stages of lgroup framework initialization (done through lgrp_init()):
301d5d7cf4eSJonathan Chew  *
302d5d7cf4eSJonathan Chew  * 1) Initialize common and platform specific code (called in mlsetup())
303d5d7cf4eSJonathan Chew  *
304d5d7cf4eSJonathan Chew  * 2) Setup root lgroup and add CPU 0 to lgroup(s) (called near beginning of
305d5d7cf4eSJonathan Chew  *    main() before startup())
306d5d7cf4eSJonathan Chew  *
307d5d7cf4eSJonathan Chew  * 3) Probe from CPU 0 and copy and release any BOP_ALLOC-ed memory temporarily
308d5d7cf4eSJonathan Chew  *    allocated before kernel memory allocator is setup (called in main()
309d5d7cf4eSJonathan Chew  *    after startup(), gethrtime() is setup, and before interrupts enabled)
310d5d7cf4eSJonathan Chew  *
311d5d7cf4eSJonathan Chew  * 4) Check for null proc LPA on Starcat, collapse lgroup topology (if
312d5d7cf4eSJonathan Chew  *    necessary), setup lgroup kstats, etc. (called before start_other_cpus())
313d5d7cf4eSJonathan Chew  *
314d5d7cf4eSJonathan Chew  * 5) Finish any lgroup initialization needed including updating lgroup
315d5d7cf4eSJonathan Chew  *    topology after all CPUs started (called after start_other_cpus())
316d5d7cf4eSJonathan Chew  */
317d5d7cf4eSJonathan Chew typedef enum lgrp_init_stages {
318d5d7cf4eSJonathan Chew 	LGRP_INIT_STAGE1,
319d5d7cf4eSJonathan Chew 	LGRP_INIT_STAGE2,
320d5d7cf4eSJonathan Chew 	LGRP_INIT_STAGE3,
321d5d7cf4eSJonathan Chew 	LGRP_INIT_STAGE4,
322d5d7cf4eSJonathan Chew 	LGRP_INIT_STAGE5
323d5d7cf4eSJonathan Chew } lgrp_init_stages_t;
324d5d7cf4eSJonathan Chew 
3257c478bd9Sstevel@tonic-gate /*
3267c478bd9Sstevel@tonic-gate  * Memory allocation policies
3277c478bd9Sstevel@tonic-gate  */
3287c478bd9Sstevel@tonic-gate typedef enum lgrp_mem_policy {
3297c478bd9Sstevel@tonic-gate 	LGRP_MEM_POLICY_DEFAULT,
3307c478bd9Sstevel@tonic-gate 	LGRP_MEM_POLICY_NEXT,		/* near LWP to next touch */
3317c478bd9Sstevel@tonic-gate 	LGRP_MEM_POLICY_RANDOM_PROC,	/* randomly across process */
3327c478bd9Sstevel@tonic-gate 	LGRP_MEM_POLICY_RANDOM_PSET,	/* randomly across processor set */
3337c478bd9Sstevel@tonic-gate 	LGRP_MEM_POLICY_RANDOM,		/* randomly across all lgroups */
3347c478bd9Sstevel@tonic-gate 	LGRP_MEM_POLICY_ROUNDROBIN,	/* round robin across all lgroups */
3357c478bd9Sstevel@tonic-gate 	LGRP_MEM_POLICY_NEXT_CPU,	/* Near next CPU to touch memory */
3362cb27123Saguzovsk 	LGRP_MEM_POLICY_NEXT_SEG,	/* lgrp specified directly by seg */
3377c478bd9Sstevel@tonic-gate 	LGRP_NUM_MEM_POLICIES
3387c478bd9Sstevel@tonic-gate } lgrp_mem_policy_t;
3397c478bd9Sstevel@tonic-gate 
3407c478bd9Sstevel@tonic-gate /*
3417c478bd9Sstevel@tonic-gate  * Search scopes for finding resouces
3427c478bd9Sstevel@tonic-gate  */
3437c478bd9Sstevel@tonic-gate typedef	enum lgrp_res_ss {
3447c478bd9Sstevel@tonic-gate 	LGRP_SRCH_LOCAL,		/* Search local lgroup only */
3457c478bd9Sstevel@tonic-gate 	LGRP_SRCH_HIER			/* Search entire hierarchy */
3467c478bd9Sstevel@tonic-gate } lgrp_res_ss_t;
3477c478bd9Sstevel@tonic-gate 
3487c478bd9Sstevel@tonic-gate /*
3497c478bd9Sstevel@tonic-gate  * Cookie used for lgrp mnode selection
3507c478bd9Sstevel@tonic-gate  */
3517c478bd9Sstevel@tonic-gate typedef struct lgrp_mnode_cookie {
3527c478bd9Sstevel@tonic-gate 	lgrp_t		*lmc_lgrp;	/* lgrp under consideration */
3537c478bd9Sstevel@tonic-gate 	mnodeset_t	lmc_nodes;	/* nodes not yet tried in lgrp */
3547c478bd9Sstevel@tonic-gate 	int		lmc_cnt;	/* how many nodes in untried set */
3557c478bd9Sstevel@tonic-gate 	mnodeset_t	lmc_tried;	/* nodes already tried */
3567c478bd9Sstevel@tonic-gate 	int		lmc_ntried;	/* how many nodes in tried set */
3577c478bd9Sstevel@tonic-gate 	lgrp_res_ss_t	lmc_scope;	/* consider non-local nodes? */
3587c478bd9Sstevel@tonic-gate 	ushort_t	lmc_rand;	/* a "random" number */
3597c478bd9Sstevel@tonic-gate } lgrp_mnode_cookie_t;
3607c478bd9Sstevel@tonic-gate 
3617c478bd9Sstevel@tonic-gate /*
3627c478bd9Sstevel@tonic-gate  * Information needed to implement memory allocation policy
3637c478bd9Sstevel@tonic-gate  */
3647c478bd9Sstevel@tonic-gate typedef struct lgrp_mem_policy_info {
3652cb27123Saguzovsk 	int		mem_policy;		/* memory allocation policy */
3662cb27123Saguzovsk 	lgrp_id_t	mem_lgrpid;		/* lgroup id */
3677c478bd9Sstevel@tonic-gate } lgrp_mem_policy_info_t;
3687c478bd9Sstevel@tonic-gate 
3697c478bd9Sstevel@tonic-gate /*
3707c478bd9Sstevel@tonic-gate  * Shared memory policy segment
3717c478bd9Sstevel@tonic-gate  */
3727c478bd9Sstevel@tonic-gate typedef struct lgrp_shm_policy_seg {
3737c478bd9Sstevel@tonic-gate 	u_offset_t		shm_off;	/* offset into shared object */
3747c478bd9Sstevel@tonic-gate 	size_t			shm_size;	/* size of segment */
3757c478bd9Sstevel@tonic-gate 	lgrp_mem_policy_info_t	shm_policy;	/* memory allocation policy */
3767c478bd9Sstevel@tonic-gate 	avl_node_t		shm_tree;	/* AVL tree */
3777c478bd9Sstevel@tonic-gate } lgrp_shm_policy_seg_t;
3787c478bd9Sstevel@tonic-gate 
3797c478bd9Sstevel@tonic-gate /*
3807c478bd9Sstevel@tonic-gate  * Shared memory locality info
3817c478bd9Sstevel@tonic-gate  */
3827c478bd9Sstevel@tonic-gate typedef struct lgrp_shm_locality {
3837c478bd9Sstevel@tonic-gate 	size_t		loc_count;		/* reference count */
3847c478bd9Sstevel@tonic-gate 	avl_tree_t	*loc_tree;		/* policy segment tree */
3857c478bd9Sstevel@tonic-gate 	krwlock_t	loc_lock;		/* protects tree */
3867c478bd9Sstevel@tonic-gate } lgrp_shm_locality_t;
3877c478bd9Sstevel@tonic-gate 
3887c478bd9Sstevel@tonic-gate /*
3897c478bd9Sstevel@tonic-gate  * Queries that may be made to determine lgroup memory size
3907c478bd9Sstevel@tonic-gate  */
3917c478bd9Sstevel@tonic-gate typedef enum {
3927c478bd9Sstevel@tonic-gate 	LGRP_MEM_SIZE_FREE,		/* number of free pages */
3937c478bd9Sstevel@tonic-gate 	LGRP_MEM_SIZE_AVAIL,		/* number of pages in phys_avail */
3947c478bd9Sstevel@tonic-gate 	LGRP_MEM_SIZE_INSTALL		/* number of pages in phys_install */
3957c478bd9Sstevel@tonic-gate } lgrp_mem_query_t;
3967c478bd9Sstevel@tonic-gate 
3977c478bd9Sstevel@tonic-gate /*
3987c478bd9Sstevel@tonic-gate  * Argument for the memory copy-rename operation, contains the source and the
3997c478bd9Sstevel@tonic-gate  * destination platform handles.
4007c478bd9Sstevel@tonic-gate  */
4017c478bd9Sstevel@tonic-gate typedef struct lgrp_config_mem_rename {
4027c478bd9Sstevel@tonic-gate 	lgrp_handle_t lmem_rename_from;
4037c478bd9Sstevel@tonic-gate 	lgrp_handle_t lmem_rename_to;
4047c478bd9Sstevel@tonic-gate } lgrp_config_mem_rename_t;
4057c478bd9Sstevel@tonic-gate 
4067c478bd9Sstevel@tonic-gate /* Macro to clear an lgroup bitmap */
4077c478bd9Sstevel@tonic-gate #define	klgrpset_clear(klgrpset) \
4087c478bd9Sstevel@tonic-gate 	(klgrpset) = (klgrpset_t)0
4097c478bd9Sstevel@tonic-gate 
4107c478bd9Sstevel@tonic-gate /* Macro to fill an lgroup bitmap */
4117c478bd9Sstevel@tonic-gate #define	klgrpset_fill(klgrpset) \
4127c478bd9Sstevel@tonic-gate 	(klgrpset) = (klgrpset_t)(-1)
4137c478bd9Sstevel@tonic-gate 
4147c478bd9Sstevel@tonic-gate /* Macro to add an lgroup to an lgroup bitmap */
4157c478bd9Sstevel@tonic-gate #define	klgrpset_add(klgrpset, lgrpid) \
4167c478bd9Sstevel@tonic-gate 	(klgrpset) |= ((klgrpset_t)1 << (lgrpid))
4177c478bd9Sstevel@tonic-gate 
4187c478bd9Sstevel@tonic-gate /* Macro to delete an lgroup from an lgroup bitmap */
4197c478bd9Sstevel@tonic-gate #define	klgrpset_del(klgrpset, lgrpid) \
4207c478bd9Sstevel@tonic-gate 	(klgrpset) &= ~((klgrpset_t)1 << (lgrpid))
4217c478bd9Sstevel@tonic-gate 
4227c478bd9Sstevel@tonic-gate /* Macro to copy a klgrpset into another klgrpset */
4237c478bd9Sstevel@tonic-gate #define	klgrpset_copy(klgrpset_to, klgrpset_from) \
4247c478bd9Sstevel@tonic-gate 	(klgrpset_to) = (klgrpset_from)
4257c478bd9Sstevel@tonic-gate 
4267c478bd9Sstevel@tonic-gate /* Macro to perform an 'and' operation on a pair of lgroup bitmaps */
4277c478bd9Sstevel@tonic-gate #define	klgrpset_and(klgrpset_rslt, klgrpset_arg) \
4287c478bd9Sstevel@tonic-gate 	(klgrpset_rslt) &= (klgrpset_arg)
4297c478bd9Sstevel@tonic-gate 
4307c478bd9Sstevel@tonic-gate /* Macro to perform an 'or' operation on a pair of lgroup bitmaps */
4317c478bd9Sstevel@tonic-gate #define	klgrpset_or(klgrpset_rslt, klgrpset_arg) \
4327c478bd9Sstevel@tonic-gate 	(klgrpset_rslt) |= (klgrpset_arg)
4337c478bd9Sstevel@tonic-gate 
4347c478bd9Sstevel@tonic-gate /* Macro to perform a 'diff' operation on a pair of lgroup bitmaps */
4357c478bd9Sstevel@tonic-gate #define	klgrpset_diff(klgrpset_rslt, klgrpset_arg) \
4367c478bd9Sstevel@tonic-gate 	(klgrpset_rslt) &= ~(klgrpset_arg)
4377c478bd9Sstevel@tonic-gate 
4387c478bd9Sstevel@tonic-gate /* Macro to check if an lgroup is a member of an lgrpset */
4397c478bd9Sstevel@tonic-gate #define	klgrpset_ismember(klgrpset, lgrpid) \
4407c478bd9Sstevel@tonic-gate 	((klgrpset) & ((klgrpset_t)1 << (lgrpid)))
4417c478bd9Sstevel@tonic-gate 
4427c478bd9Sstevel@tonic-gate /* Macro to check if an lgroup bitmap is empty */
4437c478bd9Sstevel@tonic-gate #define	klgrpset_isempty(klgrpset) \
4447c478bd9Sstevel@tonic-gate 	((klgrpset) == (klgrpset_t)0)
4457c478bd9Sstevel@tonic-gate 
4467c478bd9Sstevel@tonic-gate /* Macro to check if two lgrpsets intersect */
4477c478bd9Sstevel@tonic-gate #define	klgrpset_intersects(klgrpset1, klgrpset2) \
4487c478bd9Sstevel@tonic-gate 	((klgrpset1) & (klgrpset2))
4497c478bd9Sstevel@tonic-gate 
4507c478bd9Sstevel@tonic-gate /* Macro to count the number of members in an lgrpset */
4517c478bd9Sstevel@tonic-gate #define	klgrpset_nlgrps(klgrpset, count)				\
4527c478bd9Sstevel@tonic-gate {									\
4537c478bd9Sstevel@tonic-gate 	lgrp_id_t	lgrpid;						\
4547c478bd9Sstevel@tonic-gate 	for (lgrpid = 0, count = 0; lgrpid <= lgrp_alloc_max; lgrpid++) {\
4557c478bd9Sstevel@tonic-gate 		if (klgrpset_ismember(klgrpset, lgrpid))		\
4567c478bd9Sstevel@tonic-gate 			count++;					\
4577c478bd9Sstevel@tonic-gate 	}								\
4587c478bd9Sstevel@tonic-gate }
4597c478bd9Sstevel@tonic-gate 
4607c478bd9Sstevel@tonic-gate /* Macro to get total memory size (in bytes) of a given set of lgroups */
4617c478bd9Sstevel@tonic-gate #define	klgrpset_totalsize(klgrpset, size)				\
4627c478bd9Sstevel@tonic-gate {									\
4637c478bd9Sstevel@tonic-gate 	lgrp_handle_t	hand;						\
4647c478bd9Sstevel@tonic-gate 	lgrp_id_t	lgrpid;						\
4657c478bd9Sstevel@tonic-gate 									\
4667c478bd9Sstevel@tonic-gate 	for (lgrpid = 0, size = 0; lgrpid <= lgrp_alloc_max; lgrpid++) {\
4677c478bd9Sstevel@tonic-gate 		if (klgrpset_ismember(klgrpset, lgrpid) &&		\
4687c478bd9Sstevel@tonic-gate 		    lgrp_table[lgrpid])	{				\
4697c478bd9Sstevel@tonic-gate 			hand = lgrp_table[lgrpid]->lgrp_plathand;	\
4707c478bd9Sstevel@tonic-gate 			size += lgrp_plat_mem_size(hand,		\
4717c478bd9Sstevel@tonic-gate 			    LGRP_MEM_SIZE_AVAIL) * PAGESIZE;		\
4727c478bd9Sstevel@tonic-gate 		}							\
4737c478bd9Sstevel@tonic-gate 	}								\
4747c478bd9Sstevel@tonic-gate }
4757c478bd9Sstevel@tonic-gate 
4767c478bd9Sstevel@tonic-gate /*
4777c478bd9Sstevel@tonic-gate  * Does this lgroup exist?
4787c478bd9Sstevel@tonic-gate  */
4797c478bd9Sstevel@tonic-gate #define	LGRP_EXISTS(lgrp)	\
4807c478bd9Sstevel@tonic-gate 	(lgrp != NULL && lgrp->lgrp_id != LGRP_NONE)
4817c478bd9Sstevel@tonic-gate 
4826890d023SEric Saxe /*
4836890d023SEric Saxe  * Macro for testing if a CPU is contained in an lgrp.
4846890d023SEric Saxe  */
4856890d023SEric Saxe #define	LGRP_CONTAINS_CPU(lgrp, cpu)	\
4866890d023SEric Saxe 	(klgrpset_ismember(lgrp->lgrp_set[LGRP_RSRC_CPU],	\
4876890d023SEric Saxe 	    cpu->cpu_lpl->lpl_lgrpid))
4886890d023SEric Saxe 
4897c478bd9Sstevel@tonic-gate /*
4907c478bd9Sstevel@tonic-gate  * Initialize an lgrp_mnode_cookie
4917c478bd9Sstevel@tonic-gate  */
4927c478bd9Sstevel@tonic-gate #define	LGRP_MNODE_COOKIE_INIT(c, lgrp, scope)	\
4937c478bd9Sstevel@tonic-gate {							\
4947c478bd9Sstevel@tonic-gate 	bzero(&(c), sizeof (lgrp_mnode_cookie_t));	\
4957c478bd9Sstevel@tonic-gate 	(&(c))->lmc_lgrp = lgrp;			\
4967c478bd9Sstevel@tonic-gate 	(&(c))->lmc_nodes = lgrp->lgrp_mnodes;		\
4977c478bd9Sstevel@tonic-gate 	(&(c))->lmc_cnt = lgrp->lgrp_nmnodes;		\
4987c478bd9Sstevel@tonic-gate 	(&(c))->lmc_scope = scope;			\
4997c478bd9Sstevel@tonic-gate 	(&(c))->lmc_rand = (ushort_t)gethrtime_unscaled() >> 4;	\
5007c478bd9Sstevel@tonic-gate }
5017c478bd9Sstevel@tonic-gate 
5027c478bd9Sstevel@tonic-gate /*
5037c478bd9Sstevel@tonic-gate  * Upgrade cookie scope from LGRP_SRCH_LOCAL to LGRP_SRCH_HIER.
5047c478bd9Sstevel@tonic-gate  */
5057c478bd9Sstevel@tonic-gate #define	LGRP_MNODE_COOKIE_UPGRADE(c)	\
5067c478bd9Sstevel@tonic-gate {							\
5077c478bd9Sstevel@tonic-gate 	ASSERT((&(c))->lmc_scope == LGRP_SRCH_LOCAL);	\
5087c478bd9Sstevel@tonic-gate 	(&(c))->lmc_scope = LGRP_SRCH_HIER;		\
5097c478bd9Sstevel@tonic-gate }
5107c478bd9Sstevel@tonic-gate 
5117c478bd9Sstevel@tonic-gate /*
5127c478bd9Sstevel@tonic-gate  * Macro to see whether memory allocation policy can be reapplied
5137c478bd9Sstevel@tonic-gate  */
5147c478bd9Sstevel@tonic-gate #define	LGRP_MEM_POLICY_REAPPLICABLE(p) \
5157c478bd9Sstevel@tonic-gate 	(p == LGRP_MEM_POLICY_NEXT)
5167c478bd9Sstevel@tonic-gate 
5177c478bd9Sstevel@tonic-gate /*
5187c478bd9Sstevel@tonic-gate  * Return true if lgrp has CPU resources in the cpupart
5197c478bd9Sstevel@tonic-gate  */
5207c478bd9Sstevel@tonic-gate #define	LGRP_CPUS_IN_PART(lgrpid, cpupart) \
5217c478bd9Sstevel@tonic-gate 	(cpupart->cp_lgrploads[lgrpid].lpl_ncpu > 0)
5227c478bd9Sstevel@tonic-gate 
5237c478bd9Sstevel@tonic-gate extern int	lgrp_alloc_max;
5247c478bd9Sstevel@tonic-gate extern lgrp_t	*lgrp_table[NLGRPS_MAX];	/* indexed by lgrp_id */
5257c478bd9Sstevel@tonic-gate extern int		nlgrps;		/* number of lgroups in machine */
5267c478bd9Sstevel@tonic-gate extern int		nlgrpsmax;	/* max number of lgroups on platform */
5277c478bd9Sstevel@tonic-gate extern lgrp_gen_t	lgrp_gen;	/* generation of lgroup hierarchy */
5287c478bd9Sstevel@tonic-gate extern int		lgrp_initialized; /* single-CPU initialization done */
5297c478bd9Sstevel@tonic-gate extern int		lgrp_topo_initialized; /* lgrp topology constructed */
5307c478bd9Sstevel@tonic-gate extern lgrp_t		*lgrp_root;	/* root lgroup */
5317c478bd9Sstevel@tonic-gate extern unsigned int	lgrp_topo_levels;
5327c478bd9Sstevel@tonic-gate extern lpl_t		*lpl_bootstrap;	/* bootstrap lpl for non-active CPUs */
5337c478bd9Sstevel@tonic-gate 
5347c478bd9Sstevel@tonic-gate 
5357c478bd9Sstevel@tonic-gate /* generic interfaces */
5367c478bd9Sstevel@tonic-gate 
5377c478bd9Sstevel@tonic-gate /*
5387c478bd9Sstevel@tonic-gate  * lgroup management
5397c478bd9Sstevel@tonic-gate  */
5407c478bd9Sstevel@tonic-gate int	lgrp_optimizations(void);
541d5d7cf4eSJonathan Chew void	lgrp_init(lgrp_init_stages_t);
5427c478bd9Sstevel@tonic-gate lgrp_t	*lgrp_create(void);
5437c478bd9Sstevel@tonic-gate void	lgrp_destroy(lgrp_t *);
5447c478bd9Sstevel@tonic-gate void	lgrp_config(lgrp_config_flag_t, uintptr_t, uintptr_t);
5457c478bd9Sstevel@tonic-gate lgrp_t	*lgrp_hand_to_lgrp(lgrp_handle_t);
5467c478bd9Sstevel@tonic-gate 
5477c478bd9Sstevel@tonic-gate /*
5487c478bd9Sstevel@tonic-gate  * lgroup stats
5497c478bd9Sstevel@tonic-gate  */
5507c478bd9Sstevel@tonic-gate void	lgrp_kstat_create(struct cpu *);
5517c478bd9Sstevel@tonic-gate void	lgrp_kstat_destroy(struct cpu *);
5527c478bd9Sstevel@tonic-gate void	lgrp_stat_add(lgrp_id_t, lgrp_stat_t, int64_t);
5537c478bd9Sstevel@tonic-gate int64_t lgrp_stat_read(lgrp_id_t, lgrp_stat_t);
5547c478bd9Sstevel@tonic-gate 
5557c478bd9Sstevel@tonic-gate /*
5567c478bd9Sstevel@tonic-gate  * lgroup memory
5577c478bd9Sstevel@tonic-gate  */
5587c478bd9Sstevel@tonic-gate lgrp_mem_policy_t	lgrp_madv_to_policy(uchar_t, size_t, int);
5597c478bd9Sstevel@tonic-gate pgcnt_t	lgrp_mem_size(lgrp_id_t, lgrp_mem_query_t);
5607c478bd9Sstevel@tonic-gate lgrp_t	*lgrp_mem_choose(struct seg *, caddr_t, size_t);
5617c478bd9Sstevel@tonic-gate int	lgrp_memnode_choose(lgrp_mnode_cookie_t *);
5627c478bd9Sstevel@tonic-gate lgrp_mem_policy_t	lgrp_mem_policy_default(size_t, int);
5637c478bd9Sstevel@tonic-gate int	lgrp_mnode_update(klgrpset_t, klgrpset_t *);
5647c478bd9Sstevel@tonic-gate lgrp_t	*lgrp_pfn_to_lgrp(pfn_t);
5657c478bd9Sstevel@tonic-gate lgrp_t	*lgrp_phys_to_lgrp(u_longlong_t);	/* used by numat driver */
5667c478bd9Sstevel@tonic-gate int	lgrp_privm_policy_set(lgrp_mem_policy_t, lgrp_mem_policy_info_t *,
5677c478bd9Sstevel@tonic-gate     size_t);
5687c478bd9Sstevel@tonic-gate void	lgrp_shm_policy_init(struct anon_map *, vnode_t *);
5697c478bd9Sstevel@tonic-gate void	lgrp_shm_policy_fini(struct anon_map *, vnode_t *);
5707c478bd9Sstevel@tonic-gate lgrp_mem_policy_info_t	*lgrp_shm_policy_get(struct anon_map *, ulong_t,
5717c478bd9Sstevel@tonic-gate     vnode_t *, u_offset_t);
5727c478bd9Sstevel@tonic-gate int	lgrp_shm_policy_set(lgrp_mem_policy_t, struct anon_map *, ulong_t,
5737c478bd9Sstevel@tonic-gate     vnode_t *, u_offset_t, size_t);
5747c478bd9Sstevel@tonic-gate 
5757c478bd9Sstevel@tonic-gate /*
5767c478bd9Sstevel@tonic-gate  * Used by numat driver
5777c478bd9Sstevel@tonic-gate  */
5787c478bd9Sstevel@tonic-gate int	lgrp_query_cpu(processorid_t, lgrp_id_t *);
5797c478bd9Sstevel@tonic-gate int	lgrp_query_load(processorid_t, lgrp_load_t *);
5807c478bd9Sstevel@tonic-gate 
5817c478bd9Sstevel@tonic-gate /*
5827c478bd9Sstevel@tonic-gate  * lgroup thread placement
5837c478bd9Sstevel@tonic-gate  */
58403400a71Sjjc lpl_t	*lgrp_affinity_best(kthread_t *, struct cpupart *, lgrp_id_t,
58503400a71Sjjc     boolean_t);
5867c478bd9Sstevel@tonic-gate void	lgrp_affinity_init(lgrp_affinity_t **);
5877c478bd9Sstevel@tonic-gate void	lgrp_affinity_free(lgrp_affinity_t **);
5887c478bd9Sstevel@tonic-gate lpl_t	*lgrp_choose(kthread_t *t, struct cpupart *);
5897c478bd9Sstevel@tonic-gate lgrp_t	*lgrp_home_lgrp(void);
5907c478bd9Sstevel@tonic-gate lgrp_id_t	lgrp_home_id(kthread_t *);
5917c478bd9Sstevel@tonic-gate void	lgrp_loadavg(lpl_t *, uint_t, int);
5927c478bd9Sstevel@tonic-gate void	lgrp_move_thread(kthread_t *, lpl_t *, int);
5932cb27123Saguzovsk uint64_t lgrp_get_trthr_migrations(void);
5942cb27123Saguzovsk void 	lgrp_update_trthr_migrations(uint64_t);
5957c478bd9Sstevel@tonic-gate 
5967c478bd9Sstevel@tonic-gate /*
5977c478bd9Sstevel@tonic-gate  * lgroup topology
5987c478bd9Sstevel@tonic-gate  */
5997c478bd9Sstevel@tonic-gate int	lgrp_leaf_add(lgrp_t *, lgrp_t **, int, klgrpset_t *);
6007c478bd9Sstevel@tonic-gate int	lgrp_leaf_delete(lgrp_t *, lgrp_t **, int, klgrpset_t *);
6017c478bd9Sstevel@tonic-gate int	lgrp_rsets_empty(klgrpset_t *);
6027c478bd9Sstevel@tonic-gate int	lgrp_rsets_member(klgrpset_t *, lgrp_id_t);
6037c478bd9Sstevel@tonic-gate int	lgrp_topo_flatten(int, lgrp_t **, int, klgrpset_t *);
6047c478bd9Sstevel@tonic-gate int	lgrp_topo_ht_limit(void);
6057c478bd9Sstevel@tonic-gate int	lgrp_topo_ht_limit_default(void);
6067c478bd9Sstevel@tonic-gate int	lgrp_topo_ht_limit_set(int);
6077c478bd9Sstevel@tonic-gate int	lgrp_topo_update(lgrp_t **, int, klgrpset_t *);
6087c478bd9Sstevel@tonic-gate 
6097c478bd9Sstevel@tonic-gate /*
6107c478bd9Sstevel@tonic-gate  * lpl topology
6117c478bd9Sstevel@tonic-gate  */
6127c478bd9Sstevel@tonic-gate void	lpl_topo_bootstrap(lpl_t *, int);
6137c478bd9Sstevel@tonic-gate int	lpl_topo_flatten(int);
6147c478bd9Sstevel@tonic-gate int	lpl_topo_verify(struct cpupart *);
6157c478bd9Sstevel@tonic-gate 
6167c478bd9Sstevel@tonic-gate 
6177c478bd9Sstevel@tonic-gate /* platform interfaces */
618d5d7cf4eSJonathan Chew void	lgrp_plat_init(lgrp_init_stages_t);
6197c478bd9Sstevel@tonic-gate lgrp_t	*lgrp_plat_alloc(lgrp_id_t lgrpid);
6207c478bd9Sstevel@tonic-gate void	lgrp_plat_config(lgrp_config_flag_t, uintptr_t);
6217c478bd9Sstevel@tonic-gate lgrp_handle_t	lgrp_plat_cpu_to_hand(processorid_t);
6227c478bd9Sstevel@tonic-gate lgrp_handle_t	lgrp_plat_pfn_to_hand(pfn_t);
6237c478bd9Sstevel@tonic-gate int	lgrp_plat_max_lgrps(void);
6247c478bd9Sstevel@tonic-gate pgcnt_t	lgrp_plat_mem_size(lgrp_handle_t, lgrp_mem_query_t);
6257c478bd9Sstevel@tonic-gate int	lgrp_plat_latency(lgrp_handle_t, lgrp_handle_t);
6267c478bd9Sstevel@tonic-gate lgrp_handle_t	lgrp_plat_root_hand(void);
6277c478bd9Sstevel@tonic-gate 
628ce8eb11aSdp extern uint32_t		lgrp_expand_proc_thresh;
629ce8eb11aSdp extern uint32_t		lgrp_expand_proc_diff;
630ce8eb11aSdp extern pgcnt_t		lgrp_mem_free_thresh;
631ce8eb11aSdp extern uint32_t		lgrp_loadavg_tolerance;
632ce8eb11aSdp extern uint32_t		lgrp_loadavg_max_effect;
633ce8eb11aSdp extern uint32_t		lgrp_load_thresh;
634ce8eb11aSdp extern lgrp_mem_policy_t lgrp_mem_policy_root;
635ce8eb11aSdp 
636*f06dce2cSAndrew Stormont #endif	/* _KERNEL || _FAKE_KERNEL || _KMEMUSER */
6377c478bd9Sstevel@tonic-gate 
6387c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
6397c478bd9Sstevel@tonic-gate }
6407c478bd9Sstevel@tonic-gate #endif
6417c478bd9Sstevel@tonic-gate 
6427c478bd9Sstevel@tonic-gate #endif /* _LGRP_H */
643