1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466
|
/*___INFO__MARK_BEGIN__*/
/*************************************************************************
*
* The Contents of this file are made available subject to the terms of
* the Sun Industry Standards Source License Version 1.2
*
* Sun Microsystems Inc., March, 2001
*
*
* Sun Industry Standards Source License Version 1.2
* =================================================
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.2 (the "License"); You may not use this file
* except in compliance with the License. You may obtain a copy of the
* License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
*
* Software provided under this License is provided on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
* See the License for the specific provisions governing your rights and
* obligations concerning the Software.
*
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
*
* Copyright: 2009 by Sun Microsystems, Inc.
*
* All Rights Reserved.
*
************************************************************************/
/*___INFO__MARK_END__*/
package com.sun.grid.jsv;
import java.io.Serializable;
import java.util.List;
/**
* The BindingSpecifier object represents the core binding settings
* for a job. It contains the binding type, strategy, and strategy
* parameters.
* @see JobDescription#getBindingSpecifier()
<!-- * @see JobDescription#setBindingSpecifier() --> <!-- javadoc complains -->
* @since 6.2u5
*/
public final class BindingSpecifier implements Cloneable, Serializable {
public final class CoreSpecifier {
public int socket;
public int core;
public CoreSpecifier(int socket, int core) {
this.socket = socket;
this.core = core;
}
public CoreSpecifier() {
this(0, 0);
}
@Override
public boolean equals(Object obj) {
boolean ret = false;
if (obj instanceof CoreSpecifier) {
CoreSpecifier sc = (CoreSpecifier)obj;
if (sc.socket == socket &&
sc.core == core) {
ret = true;
}
}
return ret;
}
@Override
public int hashCode() {
int hash = 7;
hash = 79 * hash + this.socket;
hash = 79 * hash + this.core;
return hash;
}
}
public enum Strategy {
LINEAR,
STRIDING,
EXPLICIT;
@Override
public String toString() {
String ret = super.toString();
if (this == Strategy.LINEAR) {
ret = "linear";
} else if (this == Strategy.STRIDING) {
ret = "striding";
} else if (this == Strategy.EXPLICIT) {
ret = "explicit";
} else {
ret = "unknown";
}
return ret;
}
}
public enum Type {
SET,
PE,
ENV;
@Override
public String toString() {
String ret = super.toString();
if (this == Type.SET) {
ret = "set";
} else if (this == Type.PE) {
ret = "pe";
} else if (this == Type.ENV) {
ret = "env";
} else {
ret = "unknown";
}
return ret;
}
}
private Strategy strategy = null;
private Type type = Type.SET; /* if not other specified set is used */
private int amount = -1;
private int step = -1;
private int socket = -1;
private int core = -1;
private List<CoreSpecifier> socketCore = null;
private void setStrategy(Strategy strategy, int amount, int socket, int core, List<CoreSpecifier> socketCore) {
this.strategy = strategy;
this.amount = amount;
this.socket = socket;
this.core = core;
this.socketCore = socketCore;
}
/**
* Set binding strategy string
* @param strategy new strategy
*/
public void setStrategy(Strategy strategy) {
this.strategy = strategy;
}
/**
* Set linear binding strategy
* @param amount number of cores
* @param socket first socket
* @param core first core on socket
*/
public void setLinearStrategy(int amount, int socket, int core) {
if (amount < 0 || socket < 0 || core < 0) {
throw new IllegalArgumentException("amount, socket and core must be geater that zero");
} else {
setStrategy(Strategy.LINEAR, amount, socket, core, null);
}
}
/**
* Set linear-automatic binding strategy
* @param amount number of sockets
*/
public void setLinearStrategy(int amount) {
if (amount < 0) {
throw new IllegalArgumentException("amount must be geater that zero");
} else {
setStrategy(Strategy.LINEAR, amount, 0, 0, null);
}
}
/**
* Set striding binding strategy
* @param amount number of cores
* @param socket first socket
* @param core first core on socket
*/
public void setStridingStrategy(int amount, int socket, int core) {
if (amount < 0 || socket < 0 || core < 0) {
throw new IllegalArgumentException("amount, socket and core must be geater that zero");
} else {
setStrategy(Strategy.STRIDING, amount, socket, core, null);
}
}
/**
* Set striding-automatic binding strategy
* @param amount number of cores
*/
public void setStridingStrategy(int amount) {
if (amount < 0) {
throw new IllegalArgumentException("amount must be geater that zero");
} else {
setStrategy(Strategy.STRIDING, amount, 0, 0, null);
}
}
/**
* Set explicit binding strategy specifying socket/core map
* @param socketCore list of cores
*/
public void setExplicitStrategy(List<CoreSpecifier> socketCore) {
if (socketCore.size() == 0) {
throw new IllegalArgumentException("map has to contain at least one entry");
} else {
setStrategy(Strategy.EXPLICIT, -1, -1, -1, socketCore);
}
}
/**
* Returns true if binding strategy is linear
* @return true in case of linear binding
*/
public Boolean isLinear() {
return strategy == Strategy.LINEAR;
}
/**
* Returns true if binding strategy is striding
* @return true in case of striding binding
*/
public Boolean isStriding() {
return strategy == Strategy.STRIDING;
}
/**
* Returns true if binding strategy is explicit
* @return true in case of explicit binding
*/
public Boolean isExplicit() {
return strategy == Strategy.EXPLICIT;
}
/**
* Returns the binding strategy string
* @return binding strategy
*/
public Strategy getStrategy() {
return strategy;
}
/**
* Set binding type
*/
public void setType(Type type) {
this.type = type;
}
/**
* Set binding type to type 'set'
*/
public void setSetType() {
setType(Type.SET);
}
/**
* Set binding type to type pe
*/
public void setPeType() {
setType(Type.PE);
}
/**
* Set binding type to type env
*/
private void setEnvType() {
setType(Type.ENV);
}
/**
* Returns true if type is set
* @return true in case of set type
*/
public Boolean isSetType() {
return type.equals(Type.SET);
}
/**
* Returns true if type is pe
* @return true in case of pe type
*/
public Boolean isPeType() {
return type.equals(Type.PE);
}
/**
* Returns true if type is env
* @return true in case of env type
*/
public Boolean isEnvType() {
return type.equals(Type.ENV);
}
/**
* Returns the binding type
* @return binding type
*/
public Type getType() {
return type;
}
/**
* Returns the number of cores
* @return core amount
*/
public int getAmount() {
return amount;
}
/**
* Sets the binding amount
* @param amount binding amount
*/
public void setAmount(int amount) {
this.amount = amount;
}
/**
* Returns the start socket
* @return start socket
*/
public int getSocket() {
return socket;
}
/**
* Sets the binding socket
* @param socket binding socket
*/
public void setSocket(int socket) {
this.socket = socket;
}
/**
* Returns the core on the start socket
* @return start core
*/
public int getCore() {
return core;
}
/**
* Sets the binding core
* @param core binding core
*/
public void setCore(int core) {
this.core = core;
}
/**
* Returns the step size
* @return step size
*/
public int getStep() {
return step;
}
/**
* Sets the binding step size
* @param step binding step size
*/
public void setStep(int step) {
this.step = step;
}
/**
* Returns the core specifier list (only explicit binding)
* @return list of core specifiers
*/
public List<CoreSpecifier> getCoreSpecifiers() {
return socketCore;
}
@Override
public boolean equals(Object obj) {
boolean ret = false;
if (obj instanceof BindingSpecifier) {
BindingSpecifier bs = (BindingSpecifier)obj;
if (((strategy == null && bs.strategy == null)
|| (strategy != null && bs.strategy != null && strategy.equals(bs.strategy))) &&
((type == null && bs.type == null)
|| (type != null && bs.type != null && type.equals(bs.type))) &&
((socketCore == null && bs.socketCore == null)
|| (socketCore != null && bs.socketCore != null && socketCore.equals(bs.socketCore))) &&
amount == bs.amount &&
socket == bs.socket &&
core == bs.core &&
step == bs.step) {
ret = true;
}
}
return ret;
}
@Override
public int hashCode() {
return strategy.hashCode();
}
@Override
public BindingSpecifier clone() {
BindingSpecifier clone = null;
try {
clone = (BindingSpecifier) super.clone();
} catch (CloneNotSupportedException e) {
assert false : "BindingSpecifier is not cloneable";
}
return clone;
}
@Override
public String toString() {
StringBuffer ret = new StringBuffer();
if (type != null) {
ret.append(type + " ");
}
if (strategy != null) {
ret.append(strategy);
}
if (strategy == Strategy.LINEAR) {
ret.append(":" + amount);
if (socket != -1 && core != -1) {
ret.append(":" + socket + "," + core);
}
} else if (strategy == Strategy.STRIDING) {
ret.append(":" + amount);
ret.append(":" + step);
if (socket != -1 && core != -1) {
ret.append(":" + socket + "," + core);
}
} else {
Boolean isFirst = true;
ret.append(strategy);
ret.append(":");
for (CoreSpecifier sc : socketCore) {
if (isFirst) {
isFirst = false;
} else {
ret.append(':');
}
ret.append(sc.socket + "," + sc.core);
}
}
return ret.toString();
}
}
|