1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 2003 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate * 26*7c478bd9Sstevel@tonic-gate * ident "%Z%%M% %I% %E% SMI" 27*7c478bd9Sstevel@tonic-gate * 28*7c478bd9Sstevel@tonic-gate */ 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate package com.sun.solaris.service.locality; 31*7c478bd9Sstevel@tonic-gate 32*7c478bd9Sstevel@tonic-gate import java.util.*; 33*7c478bd9Sstevel@tonic-gate 34*7c478bd9Sstevel@tonic-gate import com.sun.solaris.service.pools.*; 35*7c478bd9Sstevel@tonic-gate 36*7c478bd9Sstevel@tonic-gate /** 37*7c478bd9Sstevel@tonic-gate * A representation of an individual Locality Group. A Locality Group 38*7c478bd9Sstevel@tonic-gate * resides within a Locality Domain. 39*7c478bd9Sstevel@tonic-gate */ 40*7c478bd9Sstevel@tonic-gate public class LocalityGroup 41*7c478bd9Sstevel@tonic-gate { 42*7c478bd9Sstevel@tonic-gate /** 43*7c478bd9Sstevel@tonic-gate * The locality domain which contains this group. 44*7c478bd9Sstevel@tonic-gate */ 45*7c478bd9Sstevel@tonic-gate private LocalityDomain domain; 46*7c478bd9Sstevel@tonic-gate 47*7c478bd9Sstevel@tonic-gate /** 48*7c478bd9Sstevel@tonic-gate * The C proxy id for this instance. 49*7c478bd9Sstevel@tonic-gate */ 50*7c478bd9Sstevel@tonic-gate private long id; 51*7c478bd9Sstevel@tonic-gate 52*7c478bd9Sstevel@tonic-gate /** 53*7c478bd9Sstevel@tonic-gate * The parent group of this instance. 54*7c478bd9Sstevel@tonic-gate */ 55*7c478bd9Sstevel@tonic-gate private LocalityGroup parent; 56*7c478bd9Sstevel@tonic-gate 57*7c478bd9Sstevel@tonic-gate /** 58*7c478bd9Sstevel@tonic-gate * The array of CPU IDs which are assigned to this instance. 59*7c478bd9Sstevel@tonic-gate */ 60*7c478bd9Sstevel@tonic-gate private int cpu_ids[]; 61*7c478bd9Sstevel@tonic-gate 62*7c478bd9Sstevel@tonic-gate /** 63*7c478bd9Sstevel@tonic-gate * The child groups of this instance. 64*7c478bd9Sstevel@tonic-gate */ 65*7c478bd9Sstevel@tonic-gate private Set children; 66*7c478bd9Sstevel@tonic-gate 67*7c478bd9Sstevel@tonic-gate /** 68*7c478bd9Sstevel@tonic-gate * Constructor. 69*7c478bd9Sstevel@tonic-gate * 70*7c478bd9Sstevel@tonic-gate * @param domain is the domain to which this instance belongs. 71*7c478bd9Sstevel@tonic-gate * @param id is the id of this instance. 72*7c478bd9Sstevel@tonic-gate * @param parent is the parent of this instance. 73*7c478bd9Sstevel@tonic-gate */ LocalityGroup(LocalityDomain domain, long id, LocalityGroup parent)74*7c478bd9Sstevel@tonic-gate public LocalityGroup(LocalityDomain domain, long id, 75*7c478bd9Sstevel@tonic-gate LocalityGroup parent) 76*7c478bd9Sstevel@tonic-gate { 77*7c478bd9Sstevel@tonic-gate this.domain = domain; 78*7c478bd9Sstevel@tonic-gate this.id = id; 79*7c478bd9Sstevel@tonic-gate this.parent = parent; 80*7c478bd9Sstevel@tonic-gate this.cpu_ids = jl_cpus(); 81*7c478bd9Sstevel@tonic-gate long nativeChildren[] = jl_children(); 82*7c478bd9Sstevel@tonic-gate children = new HashSet(); 83*7c478bd9Sstevel@tonic-gate for (int i = 0; i < nativeChildren.length; i++) 84*7c478bd9Sstevel@tonic-gate children.add(new LocalityGroup(domain, 85*7c478bd9Sstevel@tonic-gate nativeChildren[i], this)); 86*7c478bd9Sstevel@tonic-gate } 87*7c478bd9Sstevel@tonic-gate 88*7c478bd9Sstevel@tonic-gate /** 89*7c478bd9Sstevel@tonic-gate * Return a string representation of this instance. 90*7c478bd9Sstevel@tonic-gate */ toString()91*7c478bd9Sstevel@tonic-gate public String toString() 92*7c478bd9Sstevel@tonic-gate { 93*7c478bd9Sstevel@tonic-gate StringBuffer sb = new StringBuffer().append("locality group ") 94*7c478bd9Sstevel@tonic-gate .append(id) 95*7c478bd9Sstevel@tonic-gate .append(" with cpus ["); 96*7c478bd9Sstevel@tonic-gate 97*7c478bd9Sstevel@tonic-gate String sep = ""; 98*7c478bd9Sstevel@tonic-gate for (int i = 0; i < cpu_ids.length; i++) { 99*7c478bd9Sstevel@tonic-gate sb.append(sep); 100*7c478bd9Sstevel@tonic-gate sb.append(cpu_ids[i]); 101*7c478bd9Sstevel@tonic-gate sep = " "; 102*7c478bd9Sstevel@tonic-gate } 103*7c478bd9Sstevel@tonic-gate sb.append("]"); 104*7c478bd9Sstevel@tonic-gate 105*7c478bd9Sstevel@tonic-gate return (sb.toString()); 106*7c478bd9Sstevel@tonic-gate } 107*7c478bd9Sstevel@tonic-gate 108*7c478bd9Sstevel@tonic-gate /** 109*7c478bd9Sstevel@tonic-gate * Return the set of child locality groups for this instance. 110*7c478bd9Sstevel@tonic-gate */ getChildren()111*7c478bd9Sstevel@tonic-gate public Set getChildren() 112*7c478bd9Sstevel@tonic-gate { 113*7c478bd9Sstevel@tonic-gate return (children); 114*7c478bd9Sstevel@tonic-gate } 115*7c478bd9Sstevel@tonic-gate 116*7c478bd9Sstevel@tonic-gate /** 117*7c478bd9Sstevel@tonic-gate * Return the array of CPU IDs which belong to this locality 118*7c478bd9Sstevel@tonic-gate * group. 119*7c478bd9Sstevel@tonic-gate */ getCPUIDs()120*7c478bd9Sstevel@tonic-gate public int[] getCPUIDs() 121*7c478bd9Sstevel@tonic-gate { 122*7c478bd9Sstevel@tonic-gate return (cpu_ids); 123*7c478bd9Sstevel@tonic-gate } 124*7c478bd9Sstevel@tonic-gate 125*7c478bd9Sstevel@tonic-gate /** 126*7c478bd9Sstevel@tonic-gate * Return the locality group ID. 127*7c478bd9Sstevel@tonic-gate */ getID()128*7c478bd9Sstevel@tonic-gate long getID() 129*7c478bd9Sstevel@tonic-gate { 130*7c478bd9Sstevel@tonic-gate return (id); 131*7c478bd9Sstevel@tonic-gate } 132*7c478bd9Sstevel@tonic-gate 133*7c478bd9Sstevel@tonic-gate /** 134*7c478bd9Sstevel@tonic-gate * Return the latency of the supplied group with respect to 135*7c478bd9Sstevel@tonic-gate * this group. 136*7c478bd9Sstevel@tonic-gate * 137*7c478bd9Sstevel@tonic-gate * @param other is another locality group belonging to the 138*7c478bd9Sstevel@tonic-gate * same LocalityDomain. 139*7c478bd9Sstevel@tonic-gate */ getLatency(LocalityGroup other)140*7c478bd9Sstevel@tonic-gate public int getLatency(LocalityGroup other) 141*7c478bd9Sstevel@tonic-gate { 142*7c478bd9Sstevel@tonic-gate return (jl_latency(id, other.getID())); 143*7c478bd9Sstevel@tonic-gate } 144*7c478bd9Sstevel@tonic-gate 145*7c478bd9Sstevel@tonic-gate /** 146*7c478bd9Sstevel@tonic-gate * Return the number of Latency Groups to which these cpus 147*7c478bd9Sstevel@tonic-gate * belong which are not part of this group. 148*7c478bd9Sstevel@tonic-gate * 149*7c478bd9Sstevel@tonic-gate * @param cpus List of cpus to be examined. 150*7c478bd9Sstevel@tonic-gate * 151*7c478bd9Sstevel@tonic-gate * @throws PoolsException if there is an error accessing the 152*7c478bd9Sstevel@tonic-gate * cpu details. 153*7c478bd9Sstevel@tonic-gate */ countForeignGroups(List cpus)154*7c478bd9Sstevel@tonic-gate public int countForeignGroups(List cpus) throws PoolsException 155*7c478bd9Sstevel@tonic-gate { 156*7c478bd9Sstevel@tonic-gate Set groups = new HashSet(); 157*7c478bd9Sstevel@tonic-gate Iterator cpuIt = cpus.iterator(); 158*7c478bd9Sstevel@tonic-gate 159*7c478bd9Sstevel@tonic-gate while (cpuIt.hasNext()) { 160*7c478bd9Sstevel@tonic-gate Component comp = (Component) cpuIt.next(); 161*7c478bd9Sstevel@tonic-gate int id = (int) comp.getLongProperty("cpu.sys_id"); 162*7c478bd9Sstevel@tonic-gate for (int i = 0; i < cpu_ids.length; i++) { 163*7c478bd9Sstevel@tonic-gate if (cpu_ids[i] == id) { 164*7c478bd9Sstevel@tonic-gate LocalityGroup other = domain. 165*7c478bd9Sstevel@tonic-gate getGroup(id); 166*7c478bd9Sstevel@tonic-gate if (other != this && 167*7c478bd9Sstevel@tonic-gate groups.contains(other) == false) 168*7c478bd9Sstevel@tonic-gate groups.add(other); 169*7c478bd9Sstevel@tonic-gate } 170*7c478bd9Sstevel@tonic-gate } 171*7c478bd9Sstevel@tonic-gate } 172*7c478bd9Sstevel@tonic-gate return (groups.size()); 173*7c478bd9Sstevel@tonic-gate } 174*7c478bd9Sstevel@tonic-gate contains(List cpus)175*7c478bd9Sstevel@tonic-gate public Set contains(List cpus) throws PoolsException 176*7c478bd9Sstevel@tonic-gate { 177*7c478bd9Sstevel@tonic-gate Set contained = new HashSet(); 178*7c478bd9Sstevel@tonic-gate Iterator cpuIt = cpus.iterator(); 179*7c478bd9Sstevel@tonic-gate int set_cpus[] = getCPUIDs(); 180*7c478bd9Sstevel@tonic-gate 181*7c478bd9Sstevel@tonic-gate while (cpuIt.hasNext()) { 182*7c478bd9Sstevel@tonic-gate Component comp = (Component) cpuIt.next(); 183*7c478bd9Sstevel@tonic-gate for (int i = 0; i < set_cpus.length; i++) { 184*7c478bd9Sstevel@tonic-gate if (set_cpus[i] == (int)comp.getLongProperty( 185*7c478bd9Sstevel@tonic-gate "cpu.sys_id")) { 186*7c478bd9Sstevel@tonic-gate contained.add(comp); 187*7c478bd9Sstevel@tonic-gate break; 188*7c478bd9Sstevel@tonic-gate } 189*7c478bd9Sstevel@tonic-gate } 190*7c478bd9Sstevel@tonic-gate } 191*7c478bd9Sstevel@tonic-gate return (contained); 192*7c478bd9Sstevel@tonic-gate } 193*7c478bd9Sstevel@tonic-gate 194*7c478bd9Sstevel@tonic-gate /** 195*7c478bd9Sstevel@tonic-gate * Return an array containing the child locality group IDs. 196*7c478bd9Sstevel@tonic-gate */ jl_children()197*7c478bd9Sstevel@tonic-gate private native long[] jl_children(); 198*7c478bd9Sstevel@tonic-gate 199*7c478bd9Sstevel@tonic-gate /** 200*7c478bd9Sstevel@tonic-gate * Return an array of CPU IDs within this locality group. 201*7c478bd9Sstevel@tonic-gate */ jl_cpus()202*7c478bd9Sstevel@tonic-gate private native int[] jl_cpus(); 203*7c478bd9Sstevel@tonic-gate 204*7c478bd9Sstevel@tonic-gate /** 205*7c478bd9Sstevel@tonic-gate * Return the latency between the two supplied lgrp IDs. 206*7c478bd9Sstevel@tonic-gate * 207*7c478bd9Sstevel@tonic-gate * @param id1 is the first id. 208*7c478bd9Sstevel@tonic-gate * @param id2 is the second id. 209*7c478bd9Sstevel@tonic-gate */ jl_latency(long id1, long id2)210*7c478bd9Sstevel@tonic-gate private native int jl_latency(long id1, long id2); 211*7c478bd9Sstevel@tonic-gate } 212