lgrp.h revision 6890d023cce317bfcb74d7e43a813d060ebd2e47
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef _LGRP_H
#define _LGRP_H
/*
* locality group definitions for kernel
*/
#ifdef __cplusplus
extern "C" {
#endif
#endif /* !_KERNEL && !_KMEMUSER */
#include <sys/lgrp_user.h>
/* null platform handle */
#define LGRP_ROOTID (0) /* root lgroup ID */
/*
* Maximum number of lgrps a platform may define.
*/
#define NLGRPS_MAX 64
#define LGRP_LOADAVG_MAX UINT32_MAX
/*
* The load-average we expect for one cpu-bound thread's worth of load
*/
#define LGRP_LOADAVG_THREAD_MAX 65516
/*
* The input to the load-average generating function for one cpu-bound thread's
* worth of load
*/
#define LGRP_LOADAVG_IN_THREAD_MAX 128
/*
* LPL actions
*/
typedef enum {
} lpl_act_t;
/*
* lgroup statistics. Most of these are counters that are updated
* dynamically so they are hashed to CPU buckets to reduce cache
* interference. The remaining statistics are snapshots of kernel
* data, so they aren't stored in the array of counter stats.
*
* For the hashed stats to make sense, you have to sum all the buckets for
* that stat, hence macros are provided to read the stats.
*/
/*
* Flags for what to do with lgroup memory policy
* Used for heap and stack where policy is extended to new segments added to
* the end
*/
/* Return a pointer suitable for an atomic 64-bit op on the bucket */
/* Sum up all the buckets and return the value in 'val' */
int bkt; \
}
/* Reset all buckets for the stat to 0 */
int i; \
for (i = 0; i < LGRP_NUM_CPU_BUCKETS; i++) \
}
/*
* Define all of the statistics that are kept for lgrp kstats,
* and their corresponding text names.
*/
typedef enum lgrp_stat_types {
LGRP_NUM_MIGR, /* # migrations away from this lgrp */
LGRP_NUM_ALLOC_FAIL, /* # times alloc fails for chosen lgrp */
LGRP_PM_SRC_PGS, /* # pages migrated from this lgrp */
LGRP_PM_DEST_PGS, /* # pages migrated to this lgrp */
LGRP_PM_FAIL_ALLOC_PGS, /* # pages failed to migrate to this lgrp */
LGRP_PM_FAIL_LOCK_PGS, /* # pages failed to migrate from this lgrp */
LGRP_PMM_PGS, /* # pages marked to migrate from this lgrp */
LGRP_PMM_FAIL_PGS, /* # pages marked to migrate from this lgrp */
LGRP_NUM_DEFAULT, /* # of times default policy applied */
LGRP_NUM_NEXT, /* # of times next touch policy applied */
LGRP_NUM_RANDOM, /* # of times random policy applied */
LGRP_NUM_RANDOM_PROC, /* # of times random proc policy applied */
LGRP_NUM_RANDOM_PSET, /* # of times random pset policy applied */
LGRP_NUM_ROUNDROBIN, /* # of times round robin policy applied */
LGRP_NUM_NEXT_SEG, /* # of times next to seg policy applied */
LGRP_NUM_COUNTER_STATS, /* always last */
/* always keep >= LGRP_NUM_COUNTER_STATS */
} lgrp_stat_t;
typedef enum lgrp_snap_stat_types {
LGRP_NUM_CPUS, /* number of CPUs */
LGRP_NUM_PG_FREE, /* # of free pages */
LGRP_NUM_PG_AVAIL, /* # of allocatable physical pages */
LGRP_NUM_PG_INSTALL, /* # of installed physical pages */
LGRP_LOADAVG, /* unscaled load average of this lgrp */
LGRP_LOADAVG_SCALE, /* load unit of one CPU bound thread */
LGRP_NUM_SNAPSHOT_STATS /* always last */
#define LGRP_KSTAT_NAMES \
static char *lgrp_kstat_names[] = { \
\
/* Counter stats */ \
"lwp migrations", \
"alloc fail", \
"pages migrated from", \
"pages migrated to", \
"pages failed to migrate to", \
"pages failed to migrate from", \
"pages marked for migration", \
"pages failed to mark", \
"default policy", \
"next-touch policy", \
"random policy", \
"span process policy", \
"span psrset policy", \
"round robin policy", \
"next-seg policy", \
\
/* Snapshot stats */ \
"cpus", \
"pages free", \
"pages avail", \
"pages installed", \
"load average", \
"loadscale" \
}
#define LGRP_NUM_STATS ((int)LGRP_NUM_COUNTER_STATS + \
(int)LGRP_NUM_SNAPSHOT_STATS)
/*
* The contents of this structure are opaque and should only be
* accessed through the LGRP_STAT macro.
*/
struct lgrp_stats {
};
/* The kernel's version of a bitmap of lgroups */
typedef uint64_t klgrpset_t;
/*
* This really belongs in memnode.h, but it must be defined here to avoid
* recursive inclusion problems. Note that memnode.h includes this header.
*/
typedef uint64_t mnodeset_t;
/*
* lgroup structure
*
* Visible to generic code and contains the lgroup ID, CPUs in this lgroup,
* and a platform handle used to identify this lgroup to the lgroup platform
* support code
*/
typedef struct lgrp {
int lgrp_latency;
/*
* set of lgroups containing a given type of resource
* at this level of locality
*/
} lgrp_t;
/*
* lgroup load average structure
*/
typedef struct lgrp_ld {
/* NULL for non-leaf lgrps */
/* contains ptr to self for leaf lgrp */
int *lpl_id2rset; /* mapping of lgrpid to rset index */
} lpl_t;
/*
* 1 << LGRP_MAX_EFFECT_SHFT == lgrp_loadavg_max_effect
*/
#define LGRP_MAX_EFFECT_SHFT 16
/*
* Operations handled by lgrp_config()
*/
typedef enum lgrp_config_flag {
/*
* Memory allocation policies
*/
typedef enum lgrp_mem_policy {
LGRP_MEM_POLICY_NEXT, /* near LWP to next touch */
LGRP_MEM_POLICY_RANDOM_PROC, /* randomly across process */
LGRP_MEM_POLICY_RANDOM_PSET, /* randomly across processor set */
LGRP_MEM_POLICY_RANDOM, /* randomly across all lgroups */
LGRP_MEM_POLICY_ROUNDROBIN, /* round robin across all lgroups */
LGRP_MEM_POLICY_NEXT_CPU, /* Near next CPU to touch memory */
LGRP_MEM_POLICY_NEXT_SEG, /* lgrp specified directly by seg */
/*
* Search scopes for finding resouces
*/
typedef enum lgrp_res_ss {
LGRP_SRCH_LOCAL, /* Search local lgroup only */
LGRP_SRCH_HIER /* Search entire hierarchy */
/*
* Cookie used for lgrp mnode selection
*/
typedef struct lgrp_mnode_cookie {
int lmc_cnt; /* how many nodes in untried set */
int lmc_ntried; /* how many nodes in tried set */
/*
* Information needed to implement memory allocation policy
*/
typedef struct lgrp_mem_policy_info {
int mem_policy; /* memory allocation policy */
/*
* Shared memory policy segment
*/
typedef struct lgrp_shm_policy_seg {
/*
* Shared memory locality info
*/
typedef struct lgrp_shm_locality {
/*
* Queries that may be made to determine lgroup memory size
*/
typedef enum {
LGRP_MEM_SIZE_FREE, /* number of free pages */
LGRP_MEM_SIZE_AVAIL, /* number of pages in phys_avail */
LGRP_MEM_SIZE_INSTALL /* number of pages in phys_install */
/*
* Argument for the memory copy-rename operation, contains the source and the
* destination platform handles.
*/
typedef struct lgrp_config_mem_rename {
/* Macro to clear an lgroup bitmap */
#define klgrpset_clear(klgrpset) \
(klgrpset) = (klgrpset_t)0
/* Macro to fill an lgroup bitmap */
#define klgrpset_fill(klgrpset) \
/* Macro to add an lgroup to an lgroup bitmap */
/* Macro to delete an lgroup from an lgroup bitmap */
/* Macro to copy a klgrpset into another klgrpset */
(klgrpset_to) = (klgrpset_from)
/* Macro to perform an 'and' operation on a pair of lgroup bitmaps */
(klgrpset_rslt) &= (klgrpset_arg)
/* Macro to perform an 'or' operation on a pair of lgroup bitmaps */
(klgrpset_rslt) |= (klgrpset_arg)
/* Macro to perform a 'diff' operation on a pair of lgroup bitmaps */
(klgrpset_rslt) &= ~(klgrpset_arg)
/* Macro to check if an lgroup is a member of an lgrpset */
/* Macro to check if an lgroup bitmap is empty */
#define klgrpset_isempty(klgrpset) \
((klgrpset) == (klgrpset_t)0)
/* Macro to check if two lgrpsets intersect */
/* Macro to count the number of members in an lgrpset */
{ \
count++; \
} \
}
/* Macro to get total memory size (in bytes) of a given set of lgroups */
{ \
\
lgrp_table[lgrpid]) { \
LGRP_MEM_SIZE_AVAIL) * PAGESIZE; \
} \
} \
}
/*
* Does this lgroup exist?
*/
#define LGRP_EXISTS(lgrp) \
/*
* Macro for testing if a CPU is contained in an lgrp.
*/
/*
* Initialize an lgrp_mnode_cookie
*/
{ \
bzero(&(c), sizeof (lgrp_mnode_cookie_t)); \
}
/*
* Upgrade cookie scope from LGRP_SRCH_LOCAL to LGRP_SRCH_HIER.
*/
#define LGRP_MNODE_COOKIE_UPGRADE(c) \
{ \
(&(c))->lmc_scope = LGRP_SRCH_HIER; \
}
/*
* Macro to see whether memory allocation policy can be reapplied
*/
#define LGRP_MEM_POLICY_REAPPLICABLE(p) \
(p == LGRP_MEM_POLICY_NEXT)
/*
* Return true if lgrp has CPU resources in the cpupart
*/
extern int lgrp_alloc_max;
extern int nlgrps; /* number of lgroups in machine */
extern int nlgrpsmax; /* max number of lgroups on platform */
extern int lgrp_initialized; /* single-CPU initialization done */
extern int lgrp_topo_initialized; /* lgrp topology constructed */
extern unsigned int lgrp_topo_levels;
/* generic interfaces */
/*
* lgroup management
*/
int lgrp_optimizations(void);
void lgrp_init(void);
void lgrp_setup(void);
lgrp_t *lgrp_create(void);
void lgrp_destroy(lgrp_t *);
/*
* lgroup stats
*/
void lgrp_kstat_create(struct cpu *);
void lgrp_kstat_destroy(struct cpu *);
/*
* lgroup memory
*/
size_t);
vnode_t *, u_offset_t);
/*
* Used by numat driver
*/
/*
* lgroup thread placement
*/
void lgrp_affinity_init(lgrp_affinity_t **);
void lgrp_affinity_free(lgrp_affinity_t **);
lgrp_t *lgrp_home_lgrp(void);
/*
* lgroup topology
*/
int lgrp_rsets_empty(klgrpset_t *);
int lgrp_topo_ht_limit(void);
int lgrp_topo_ht_limit_default(void);
int lgrp_topo_ht_limit_set(int);
/*
* lpl topology
*/
void lpl_topo_bootstrap(lpl_t *, int);
int lpl_topo_flatten(int);
int lpl_topo_verify(struct cpupart *);
/* platform interfaces */
void lgrp_plat_init(void);
void lgrp_plat_main_init(void);
int lgrp_plat_max_lgrps(void);
lgrp_handle_t lgrp_plat_root_hand(void);
void lgrp_plat_probe(void);
extern uint32_t lgrp_expand_proc_thresh;
extern uint32_t lgrp_expand_proc_diff;
extern pgcnt_t lgrp_mem_free_thresh;
extern uint32_t lgrp_loadavg_tolerance;
extern uint32_t lgrp_loadavg_max_effect;
extern uint32_t lgrp_load_thresh;
#endif /* _KERNEL && _KMEMUSER */
#ifdef __cplusplus
}
#endif
#endif /* _LGRP_H */