/*
* 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 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* CMT dispatcher policies
*
* This file implements CMT dispatching policies using Processor Groups.
*
* The scheduler/dispatcher leverages knowledge of the performance
* relevant CMT sharing relationships existing between CPUs to implement
* load balancing, and coalescence thread placement policies.
*
* Load balancing policy seeks to improve performance by minimizing
* contention over shared processor resources / facilities. Coalescence
* policies improve resource utilization and ultimately power efficiency.
*
* On NUMA systems, the dispatcher will generally perform load balancing and
* coalescence within (and not across) lgroups. This is because there isn't
* much sense in trying to correct an imbalance by sending a thread outside
* of its home, if it would attempt to return home a short while later.
* The dispatcher will implement CMT policy across lgroups however, if
* it can do so with a thread homed to the root lgroup, since root homed
* threads have no lgroup affinity.
*/
/*
* Return non-zero if, given the policy, we should migrate from running
* somewhere "here" to somewhere "there".
*/
static int
int self)
{
/*
* This assumes that curthread's utilization is "1"
*/
here_util--; /* Ignore curthread's effect */
/*
* Load balancing and coalescence are conflicting policies
*/
if (policy & CMT_BALANCE) {
/*
* Balance utilization
*
* If the target is comparatively underutilized
* (either in an absolute sense, or scaled by capacity),
* then choose to balance.
*/
if ((here_util > there_util) ||
(here_util == there_util &&
return (1);
}
} else if (policy & CMT_COALESCE) {
/*
* Attempt to drive group utilization up to capacity
*/
if (there_util > here_util &&
return (1);
}
return (0);
}
/*
* Perform multi-level CMT load balancing of running threads.
*
* tp is the thread being enqueued.
* cp is a hint CPU, against which CMT load balancing will be performed.
*
* Returns cp, or a CPU better than cp with respect to balancing
* running thread load.
*/
cpu_t *
{
int self = 0;
int level = 0;
extern cmt_lgrp_t *cmt_root;
if (GROUP_SIZE(cmt_pgs) == 0)
return (cp); /* nothing to do */
self = 1;
/*
* Balance across siblings in the CPUs CMT lineage
* If the thread is homed to the root lgroup, perform
* top level balancing against other top level PGs
* in the system. Otherwise, start with the default
* top level siblings group, which is within the leaf lgroup
*/
else
/*
* Traverse down the lineage until we find a level that needs
* balancing, or we get to the end.
*/
for (;;) {
if (nsiblings == 1)
goto next_level;
/*
* Find a balancing candidate from among our siblings
* "hint" is a hint for where to start looking
*/
i = hint;
do {
/*
* The candidate must not be us, and must
* have some CPU resources in the thread's
* partition
*/
break;
}
if (++i >= nsiblings)
i = 0;
} while (i != hint);
if (!tpg)
goto next_level; /* no candidates at this level */
/*
* Decide if we should migrate from the current PG to a
* target PG given a policy
*/
break;
break;
}
if (tpg) {
/*
* Select an idle CPU from the target
*/
do {
break;
}
cpu = 0;
}
return (cp);
}