pg.c revision b885580b43755ee4ea1e280b85428893d2ba9291
18c2aff776a775d34a4c9893a4c72e0434d68e36artem/*
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * CDDL HEADER START
18c2aff776a775d34a4c9893a4c72e0434d68e36artem *
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * The contents of this file are subject to the terms of the
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * Common Development and Distribution License (the "License").
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * You may not use this file except in compliance with the License.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem *
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * or http://www.opensolaris.org/os/licensing.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * See the License for the specific language governing permissions
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * and limitations under the License.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem *
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * When distributing Covered Code, include this CDDL HEADER in each
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * If applicable, add the following below this CDDL HEADER, with the
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * fields enclosed by brackets "[]" replaced with your own identifying
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * information: Portions Copyright [yyyy] [name of copyright owner]
18c2aff776a775d34a4c9893a4c72e0434d68e36artem *
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * CDDL HEADER END
18c2aff776a775d34a4c9893a4c72e0434d68e36artem */
18c2aff776a775d34a4c9893a4c72e0434d68e36artem/*
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * Use is subject to license terms.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem */
18c2aff776a775d34a4c9893a4c72e0434d68e36artem
18c2aff776a775d34a4c9893a4c72e0434d68e36artem#include <sys/systm.h>
18c2aff776a775d34a4c9893a4c72e0434d68e36artem#include <sys/types.h>
18c2aff776a775d34a4c9893a4c72e0434d68e36artem#include <sys/param.h>
18c2aff776a775d34a4c9893a4c72e0434d68e36artem#include <sys/thread.h>
18c2aff776a775d34a4c9893a4c72e0434d68e36artem#include <sys/cpuvar.h>
18c2aff776a775d34a4c9893a4c72e0434d68e36artem#include <sys/cpupart.h>
18c2aff776a775d34a4c9893a4c72e0434d68e36artem#include <sys/kmem.h>
18c2aff776a775d34a4c9893a4c72e0434d68e36artem#include <sys/cmn_err.h>
18c2aff776a775d34a4c9893a4c72e0434d68e36artem#include <sys/kstat.h>
18c2aff776a775d34a4c9893a4c72e0434d68e36artem#include <sys/processor.h>
18c2aff776a775d34a4c9893a4c72e0434d68e36artem#include <sys/disp.h>
18c2aff776a775d34a4c9893a4c72e0434d68e36artem#include <sys/group.h>
18c2aff776a775d34a4c9893a4c72e0434d68e36artem#include <sys/pg.h>
18c2aff776a775d34a4c9893a4c72e0434d68e36artem
18c2aff776a775d34a4c9893a4c72e0434d68e36artem/*
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * Processor groups
18c2aff776a775d34a4c9893a4c72e0434d68e36artem *
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * With the introduction of Chip Multi-Threaded (CMT) processor architectures,
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * it is no longer necessarily true that a given physical processor module
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * will present itself as a single schedulable entity (cpu_t). Rather, each
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * chip and/or processor core may present itself as one or more "logical" CPUs.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem *
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * The logical CPUs presented may share physical components such as caches,
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * data pipes, execution pipelines, FPUs, etc. It is advantageous to have the
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * kernel be aware of the relationships existing between logical CPUs so that
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * the appropriate optmizations may be employed.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem *
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * The processor group abstraction represents a set of logical CPUs that
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * generally share some sort of physical or characteristic relationship.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem *
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * In the case of a physical sharing relationship, the CPUs in the group may
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * share a pipeline, cache or floating point unit. In the case of a logical
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * relationship, a PG may represent the set of CPUs in a processor set, or the
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * set of CPUs running at a particular clock speed.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem *
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * The generic processor group structure, pg_t, contains the elements generic
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * to a group of CPUs. Depending on the nature of the CPU relationship
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * (LOGICAL or PHYSICAL), a pointer to a pg may be recast to a "view" of that
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * PG where more specific data is represented.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem *
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * As an example, a PG representing a PHYSICAL relationship, may be recast to
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * a pghw_t, where data further describing the hardware sharing relationship
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * is maintained. See pghw.c and pghw.h for details on physical PGs.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem *
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * At this time a more specialized casting of a PG representing a LOGICAL
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * relationship has not been implemented, but the architecture allows for this
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * in the future.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem *
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * Processor Group Classes
18c2aff776a775d34a4c9893a4c72e0434d68e36artem *
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * Processor group consumers may wish to maintain and associate specific
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * data with the PGs they create. For this reason, a mechanism for creating
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * class specific PGs exists. Classes may overload the default functions for
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * creating, destroying, and associating CPUs with PGs, and may also register
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * class specific callbacks to be invoked when the CPU related system
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * configuration changes. Class specific data is stored/associated with
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * PGs by incorporating the pg_t (or pghw_t, as appropriate), as the first
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * element of a class specific PG object. In memory, such a structure may look
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * like:
18c2aff776a775d34a4c9893a4c72e0434d68e36artem *
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * ----------------------- - - -
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * | common | | | | <--(pg_t *)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * ----------------------- | | -
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * | HW specific | | | <-----(pghw_t *)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * ----------------------- | -
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * | class specific | | <-------(pg_cmt_t *)
* ----------------------- -
*
* Access to the PG class specific data can be had by casting a pointer to
* it's class specific view.
*/
static pg_t *pg_alloc_default(pg_class_t);
static void pg_free_default(pg_t *);
static void pg_null_op();
/*
* Bootstrap CPU specific PG data
* See pg_cpu_bootstrap()
*/
static cpu_pg_t bootstrap_pg_data;
/*
* Bitset of allocated PG ids (they are sequential)
* and the next free id in the set.
*/
static bitset_t pg_id_set;
/*
* ID space starts from 1 to assume that root has ID 0;
*/
static pgid_t pg_id_next = 1;
/*
* Default and externed PG ops vectors
*/
static struct pg_ops pg_ops_default = {
pg_alloc_default, /* alloc */
pg_free_default, /* free */
NULL, /* cpu_init */
NULL, /* cpu_fini */
NULL, /* cpu_active */
NULL, /* cpu_inactive */
NULL, /* cpupart_in */
NULL, /* cpupart_out */
NULL, /* cpupart_move */
NULL, /* cpu_belongs */
NULL, /* policy_name */
};
static struct pg_cb_ops pg_cb_ops_default = {
pg_null_op, /* thread_swtch */
pg_null_op, /* thread_remain */
};
/*
* Class specific PG allocation callbacks
*/
#define PG_ALLOC(class) \
(pg_classes[class].pgc_ops->alloc ? \
pg_classes[class].pgc_ops->alloc() : \
pg_classes[pg_default_cid].pgc_ops->alloc())
#define PG_FREE(pg) \
((pg)->pg_class->pgc_ops->free ? \
(pg)->pg_class->pgc_ops->free(pg) : \
pg_classes[pg_default_cid].pgc_ops->free(pg)) \
/*
* Class specific PG policy name
*/
#define PG_POLICY_NAME(pg) \
((pg)->pg_class->pgc_ops->policy_name ? \
(pg)->pg_class->pgc_ops->policy_name(pg) : NULL) \
/*
* Class specific membership test callback
*/
#define PG_CPU_BELONGS(pg, cp) \
((pg)->pg_class->pgc_ops->cpu_belongs ? \
(pg)->pg_class->pgc_ops->cpu_belongs(pg, cp) : 0) \
/*
* CPU configuration callbacks
*/
#define PG_CPU_INIT(class, cp, cpu_pg) \
{ \
if (pg_classes[class].pgc_ops->cpu_init) \
pg_classes[class].pgc_ops->cpu_init(cp, cpu_pg); \
}
#define PG_CPU_FINI(class, cp, cpu_pg) \
{ \
if (pg_classes[class].pgc_ops->cpu_fini) \
pg_classes[class].pgc_ops->cpu_fini(cp, cpu_pg); \
}
#define PG_CPU_ACTIVE(class, cp) \
{ \
if (pg_classes[class].pgc_ops->cpu_active) \
pg_classes[class].pgc_ops->cpu_active(cp); \
}
#define PG_CPU_INACTIVE(class, cp) \
{ \
if (pg_classes[class].pgc_ops->cpu_inactive) \
pg_classes[class].pgc_ops->cpu_inactive(cp); \
}
/*
* CPU / cpupart configuration callbacks
*/
#define PG_CPUPART_IN(class, cp, pp) \
{ \
if (pg_classes[class].pgc_ops->cpupart_in) \
pg_classes[class].pgc_ops->cpupart_in(cp, pp); \
}
#define PG_CPUPART_OUT(class, cp, pp) \
{ \
if (pg_classes[class].pgc_ops->cpupart_out) \
pg_classes[class].pgc_ops->cpupart_out(cp, pp); \
}
#define PG_CPUPART_MOVE(class, cp, old, new) \
{ \
if (pg_classes[class].pgc_ops->cpupart_move) \
pg_classes[class].pgc_ops->cpupart_move(cp, old, new); \
}
static pg_class_t *pg_classes;
static int pg_nclasses;
static pg_cid_t pg_default_cid;
/*
* Initialze common PG subsystem.
*/
void
pg_init(void)
{
extern void pg_cmt_class_init();
extern void pg_cmt_cpu_startup();
pg_default_cid =
pg_class_register("default", &pg_ops_default, PGR_LOGICAL);
/*
* Initialize classes to allow them to register with the framework
*/
pg_cmt_class_init();
pg_cpu0_init();
pg_cmt_cpu_startup(CPU);
}
/*
* Perform CPU 0 initialization
*/
void
pg_cpu0_init(void)
{
extern void pghw_physid_create();
/*
* Create the physical ID cache for the boot CPU
*/
pghw_physid_create(CPU);
/*
* pg_cpu_* require that cpu_lock be held
*/
mutex_enter(&cpu_lock);
(void) pg_cpu_init(CPU, B_FALSE);
pg_cpupart_in(CPU, &cp_default);
pg_cpu_active(CPU);
mutex_exit(&cpu_lock);
}
/*
* Invoked when topology for CPU0 changes
* post pg_cpu0_init().
*
* Currently happens as a result of null_proc_lpa
* on Starcat.
*/
void
pg_cpu0_reinit(void)
{
mutex_enter(&cpu_lock);
pg_cpu_inactive(CPU);
pg_cpupart_out(CPU, &cp_default);
pg_cpu_fini(CPU, NULL);
(void) pg_cpu_init(CPU, B_FALSE);
pg_cpupart_in(CPU, &cp_default);
pg_cpu_active(CPU);
mutex_exit(&cpu_lock);
}
/*
* Register a new PG class
*/
pg_cid_t
pg_class_register(char *name, struct pg_ops *ops, pg_relation_t relation)
{
pg_class_t *newclass;
pg_class_t *classes_old;
id_t cid;
mutex_enter(&cpu_lock);
/*
* Allocate a new pg_class_t in the pg_classes array
*/
if (pg_nclasses == 0) {
pg_classes = kmem_zalloc(sizeof (pg_class_t), KM_SLEEP);
} else {
classes_old = pg_classes;
pg_classes =
kmem_zalloc(sizeof (pg_class_t) * (pg_nclasses + 1),
KM_SLEEP);
(void) kcopy(classes_old, pg_classes,
sizeof (pg_class_t) * pg_nclasses);
kmem_free(classes_old, sizeof (pg_class_t) * pg_nclasses);
}
cid = pg_nclasses++;
newclass = &pg_classes[cid];
(void) strncpy(newclass->pgc_name, name, PG_CLASS_NAME_MAX);
newclass->pgc_id = cid;
newclass->pgc_ops = ops;
newclass->pgc_relation = relation;
mutex_exit(&cpu_lock);
return (cid);
}
/*
* Try to find an existing pg in set in which to place cp.
* Returns the pg if found, and NULL otherwise.
* In the event that the CPU could belong to multiple
* PGs in the set, the first matching PG will be returned.
*/
pg_t *
pg_cpu_find_pg(cpu_t *cp, group_t *set)
{
pg_t *pg;
group_iter_t i;
group_iter_init(&i);
while ((pg = group_iterate(set, &i)) != NULL) {
/*
* Ask the class if the CPU belongs here
*/
if (PG_CPU_BELONGS(pg, cp))
return (pg);
}
return (NULL);
}
/*
* Iterate over the CPUs in a PG after initializing
* the iterator with PG_CPU_ITR_INIT()
*/
cpu_t *
pg_cpu_next(pg_cpu_itr_t *itr)
{
cpu_t *cpu;
pg_t *pg = itr->pg;
cpu = group_iterate(&pg->pg_cpus, &itr->position);
return (cpu);
}
/*
* Test if a given PG contains a given CPU
*/
boolean_t
pg_cpu_find(pg_t *pg, cpu_t *cp)
{
if (group_find(&pg->pg_cpus, cp) == (uint_t)-1)
return (B_FALSE);
return (B_TRUE);
}
/*
* Set the PGs callbacks to the default
*/
void
pg_callback_set_defaults(pg_t *pg)
{
bcopy(&pg_cb_ops_default, &pg->pg_cb, sizeof (struct pg_cb_ops));
}
/*
* Create a PG of a given class.
* This routine may block.
*/
pg_t *
pg_create(pg_cid_t cid)
{
pg_t *pg;
pgid_t id;
ASSERT(MUTEX_HELD(&cpu_lock));
/*
* Call the class specific PG allocation routine
*/
pg = PG_ALLOC(cid);
pg->pg_class = &pg_classes[cid];
pg->pg_relation = pg->pg_class->pgc_relation;
/*
* Find the next free sequential pg id
*/
do {
if (pg_id_next >= bitset_capacity(&pg_id_set))
bitset_resize(&pg_id_set, pg_id_next + 1);
id = pg_id_next++;
} while (bitset_in_set(&pg_id_set, id));
pg->pg_id = id;
bitset_add(&pg_id_set, pg->pg_id);
/*
* Create the PG's CPU group
*/
group_create(&pg->pg_cpus);
/*
* Initialize the events ops vector
*/
pg_callback_set_defaults(pg);
return (pg);
}
/*
* Destroy a PG.
* This routine may block.
*/
void
pg_destroy(pg_t *pg)
{
ASSERT(MUTEX_HELD(&cpu_lock));
group_destroy(&pg->pg_cpus);
/*
* Unassign the pg_id
*/
if (pg_id_next > pg->pg_id)
pg_id_next = pg->pg_id;
bitset_del(&pg_id_set, pg->pg_id);
/*
* Invoke the class specific de-allocation routine
*/
PG_FREE(pg);
}
/*
* Add the CPU "cp" to processor group "pg"
* This routine may block.
*/
void
pg_cpu_add(pg_t *pg, cpu_t *cp, cpu_pg_t *cpu_pg)
{
int err;
ASSERT(MUTEX_HELD(&cpu_lock));
/* This adds the CPU to the PG's CPU group */
err = group_add(&pg->pg_cpus, cp, GRP_RESIZE);
ASSERT(err == 0);
/*
* The CPU should be referencing the bootstrap PG data still
* at this point, since this routine may block causing us to
* enter the dispatcher.
*/
ASSERT(pg_cpu_is_bootstrapped(cp));
/* This adds the PG to the CPUs PG group */
err = group_add(&cpu_pg->pgs, pg, GRP_RESIZE);
ASSERT(err == 0);
}
/*
* Remove "cp" from "pg".
* This routine may block.
*/
void
pg_cpu_delete(pg_t *pg, cpu_t *cp, cpu_pg_t *cpu_pg)
{
int err;
ASSERT(MUTEX_HELD(&cpu_lock));
/* Remove the CPU from the PG */
err = group_remove(&pg->pg_cpus, cp, GRP_RESIZE);
ASSERT(err == 0);
/*
* The CPU should be referencing the bootstrap PG data still
* at this point, since this routine may block causing us to
* enter the dispatcher.
*/
ASSERT(pg_cpu_is_bootstrapped(cp));
/* Remove the PG from the CPU's PG group */
err = group_remove(&cpu_pg->pgs, pg, GRP_RESIZE);
ASSERT(err == 0);
}
/*
* Allocate a CPU's PG data. This hangs off struct cpu at cpu_pg
*/
static cpu_pg_t *
pg_cpu_data_alloc(void)
{
cpu_pg_t *pgd;
pgd = kmem_zalloc(sizeof (cpu_pg_t), KM_SLEEP);
group_create(&pgd->pgs);
group_create(&pgd->cmt_pgs);
return (pgd);
}
/*
* Free the CPU's PG data.
*/
static void
pg_cpu_data_free(cpu_pg_t *pgd)
{
group_destroy(&pgd->pgs);
group_destroy(&pgd->cmt_pgs);
kmem_free(pgd, sizeof (cpu_pg_t));
}
/*
* Called when either a new CPU is coming into the system (either
* via booting or DR) or when the CPU's PG data is being recalculated.
* Allocate its PG data, and notify all registered classes about
* the new CPU.
*
* If "deferred_init" is B_TRUE, the CPU's PG data will be allocated
* and returned, but the "bootstrap" structure will be left in place.
* The deferred_init option is used when all CPUs in the system are
* using the bootstrap structure as part of the process of recalculating
* all PG data. The caller must replace the bootstrap structure with the
* allocated PG data before pg_cpu_active is called.
*
* This routine may block.
*/
cpu_pg_t *
pg_cpu_init(cpu_t *cp, boolean_t deferred_init)
{
pg_cid_t i;
cpu_pg_t *cpu_pg;
ASSERT(MUTEX_HELD(&cpu_lock));
/*
* Allocate and size the per CPU pg data
*
* The CPU's PG data will be populated by the various
* PG classes during the invocation of the PG_CPU_INIT()
* callback below.
*
* Since the we could block and enter the dispatcher during
* this process, the CPU will continue to reference the bootstrap
* PG data until all the initialization completes.
*/
ASSERT(pg_cpu_is_bootstrapped(cp));
cpu_pg = pg_cpu_data_alloc();
/*
* Notify all registered classes about the new CPU
*/
for (i = 0; i < pg_nclasses; i++)
PG_CPU_INIT(i, cp, cpu_pg);
/*
* The CPU's PG data is now ready to use.
*/
if (deferred_init == B_FALSE)
cp->cpu_pg = cpu_pg;
return (cpu_pg);
}
/*
* Either this CPU is being deleted from the system or its PG data is
* being recalculated. Notify the classes and free up the CPU's PG data.
*
* If "cpu_pg_deferred" is non-NULL, it points to the CPU's PG data and
* serves to indicate that this CPU is already using the bootstrap
* stucture. Used as part of the process to recalculate the PG data for
* all CPUs in the system.
*/
void
pg_cpu_fini(cpu_t *cp, cpu_pg_t *cpu_pg_deferred)
{
pg_cid_t i;
cpu_pg_t *cpu_pg;
ASSERT(MUTEX_HELD(&cpu_lock));
if (cpu_pg_deferred == NULL) {
cpu_pg = cp->cpu_pg;
/*
* This can happen if the CPU coming into the system
* failed to power on.
*/
if (cpu_pg == NULL || pg_cpu_is_bootstrapped(cp))
return;
/*
* Have the CPU reference the bootstrap PG data to survive
* the dispatcher should it block from here on out.
*/
pg_cpu_bootstrap(cp);
} else {
ASSERT(pg_cpu_is_bootstrapped(cp));
cpu_pg = cpu_pg_deferred;
}
for (i = 0; i < pg_nclasses; i++)
PG_CPU_FINI(i, cp, cpu_pg);
pg_cpu_data_free(cpu_pg);
}
/*
* This CPU is becoming active (online)
* This routine may not block as it is called from paused CPUs
* context.
*/
void
pg_cpu_active(cpu_t *cp)
{
pg_cid_t i;
ASSERT(MUTEX_HELD(&cpu_lock));
/*
* Notify all registered classes about the new CPU
*/
for (i = 0; i < pg_nclasses; i++)
PG_CPU_ACTIVE(i, cp);
}
/*
* This CPU is going inactive (offline)
* This routine may not block, as it is called from paused
* CPUs context.
*/
void
pg_cpu_inactive(cpu_t *cp)
{
pg_cid_t i;
ASSERT(MUTEX_HELD(&cpu_lock));
/*
* Notify all registered classes about the new CPU
*/
for (i = 0; i < pg_nclasses; i++)
PG_CPU_INACTIVE(i, cp);
}
/*
* Invoked when the CPU is about to move into the partition
* This routine may block.
*/
void
pg_cpupart_in(cpu_t *cp, cpupart_t *pp)
{
int i;
ASSERT(MUTEX_HELD(&cpu_lock));
/*
* Notify all registered classes that the
* CPU is about to enter the CPU partition
*/
for (i = 0; i < pg_nclasses; i++)
PG_CPUPART_IN(i, cp, pp);
}
/*
* Invoked when the CPU is about to move out of the partition
* This routine may block.
*/
/*ARGSUSED*/
void
pg_cpupart_out(cpu_t *cp, cpupart_t *pp)
{
int i;
ASSERT(MUTEX_HELD(&cpu_lock));
/*
* Notify all registered classes that the
* CPU is about to leave the CPU partition
*/
for (i = 0; i < pg_nclasses; i++)
PG_CPUPART_OUT(i, cp, pp);
}
/*
* Invoked when the CPU is *moving* partitions.
*
* This routine may not block, as it is called from paused CPUs
* context.
*/
void
pg_cpupart_move(cpu_t *cp, cpupart_t *oldpp, cpupart_t *newpp)
{
int i;
ASSERT(MUTEX_HELD(&cpu_lock));
/*
* Notify all registered classes that the
* CPU is about to leave the CPU partition
*/
for (i = 0; i < pg_nclasses; i++)
PG_CPUPART_MOVE(i, cp, oldpp, newpp);
}
/*
* Return a class specific string describing a policy implemented
* across this PG
*/
char *
pg_policy_name(pg_t *pg)
{
char *str;
if ((str = PG_POLICY_NAME(pg)) != NULL)
return (str);
return ("N/A");
}
/*
* Provide the specified CPU a bootstrap pg
* This is needed to allow sane behaviour if any PG consuming
* code needs to deal with a partially initialized CPU
*/
void
pg_cpu_bootstrap(cpu_t *cp)
{
cp->cpu_pg = &bootstrap_pg_data;
}
/*
* Return non-zero if the specified CPU is bootstrapped,
* which means it's CPU specific PG data has not yet been
* fully constructed.
*/
int
pg_cpu_is_bootstrapped(cpu_t *cp)
{
return (cp->cpu_pg == &bootstrap_pg_data);
}
/*ARGSUSED*/
static pg_t *
pg_alloc_default(pg_class_t class)
{
return (kmem_zalloc(sizeof (pg_t), KM_SLEEP));
}
/*ARGSUSED*/
static void
pg_free_default(struct pg *pg)
{
kmem_free(pg, sizeof (pg_t));
}
static void
pg_null_op()
{
}
/*
* Invoke the "thread switch" callback for each of the CPU's PGs
* This is invoked from the dispatcher swtch() routine, which is called
* when a thread running an a CPU should switch to another thread.
* "cp" is the CPU on which the thread switch is happening
* "now" is an unscaled hrtime_t timestamp taken in swtch()
* "old" and "new" are the outgoing and incoming threads, respectively.
*/
void
pg_ev_thread_swtch(struct cpu *cp, hrtime_t now, kthread_t *old, kthread_t *new)
{
int i, sz;
group_t *grp;
pg_t *pg;
grp = &cp->cpu_pg->pgs;
sz = GROUP_SIZE(grp);
for (i = 0; i < sz; i++) {
pg = GROUP_ACCESS(grp, i);
pg->pg_cb.thread_swtch(pg, cp, now, old, new);
}
}
/*
* Invoke the "thread remain" callback for each of the CPU's PGs.
* This is called from the dispatcher's swtch() routine when a thread
* running on the CPU "cp" is switching to itself, which can happen as an
* artifact of the thread's timeslice expiring.
*/
void
pg_ev_thread_remain(struct cpu *cp, kthread_t *t)
{
int i, sz;
group_t *grp;
pg_t *pg;
grp = &cp->cpu_pg->pgs;
sz = GROUP_SIZE(grp);
for (i = 0; i < sz; i++) {
pg = GROUP_ACCESS(grp, i);
pg->pg_cb.thread_remain(pg, cp, t);
}
}