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