params.c 48.2 KB
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 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375
/*
 * Copyright (C) 1996-1998 by the Board of Trustees
 *    of Leland Stanford Junior University.
 * 
 * This file is part of the SimOS distribution. 
 * See LICENSE file for terms of the license. 
 *
 */

/*****************************************************************
 * params.c
 * 
 * All parameters are available through the PARAM array in Tcl. 
 * 
 *****************************************************************/
#include <string.h>
#include <sys/time.h>
#include "params.h"
#include "syslimits.h"
#include "sim_error.h"
#include "simutil.h"
#include "machine_params.h"
#include "../../cpus/simos/machine_defs.h" /* for DEV_DISK_MAX_UNIT */
#include "checkpoint.h"


extern int restoringCpt;
extern char *checkpointName;
extern CPUType simosCPUType;

/* 
 * This is the storage for all of the parameters that describe some
 * aspect of the machine under simulation. 
 */
MachinesStruct machines;

/*
 * This is a vector that specifies which of the machines the current
 * read or write is referring to
 */
int machineParamVec[MAX_MACHINES];
MachineScopeType machineScope;

/*
 * Stores the CPU to Machine mapping vector
 */
int *MachineFromCPU;

/* 
 * To ensure that all registered values are given a default value, I
 * keep a table of pointers to these parameters and set each of them
 * to a known "bad" value at registration. If any of these variables
 * is still set to this bad value after initialization, it is an
 * error. One way around this is to set the underlying C-value AFTER
 * the parameter is registered. 
 */
#define MAX_PARAMS           300
#define PARAM_BAD_INT      51071
#define PARAM_BAD_STRING    NULL
#define MAX_PARAM_NAME        64


/*
 * Access function -- called when accessing a per-machine parameter.
 * Arguments: machine number, name of accessed parameter.
 */
typedef char* (*AccessFunc)(int machine, char* varname);

/*
 * Descriptor for per-machine parameter.
 */
typedef struct paramStruct {

   long       initialized; /* Boolean OR bitfield, 1 b / machine */
   long       readOnly;    /* Boolean OR bitfield, 1 b / machine */
   int        type;
   char*      name;
   int        bitField;    /* are above params bitfields or Booleans? */
   AccessFunc accessFunc;  /* pointer to access function */
   int        modifiedPerMachine; /* have we modified this for
				     separate machines */
} ParamStruct;

/* The initialized and read_only values for all the machines are stored as bit
   vectors within the ParamStruct for each per-machine parameter. The maximum number
   of machines can not be set to greater than the width of the type for these two
   variables */

#define IS_INITIALIZED(p, machine) (((p).initialized) & (1 << (machine))) 
#define SET_INITIALIZED(p, machine) (((p).initialized) |= (1 << (machine))) 
#define IS_READONLY(p, machine) (((p).readOnly) & (1 << (machine))) 
#define SET_READONLY(p, machine) (((p).readOnly) |= (1 << (machine))) 
#define BITFIELD_TRUE 0xFFFFFFFF

ParamStruct param[MAX_PARAMS];
int paramCount = 0;

/*
 * Dummy structure that the TCL variables are linked to. Values are copied to
 * and from here in the link callbacks.
 */
MachineSpecificStruct dummyMachine;

/* 
 * A few values are set before being registered (the parameters
 * grabbed by Simcpt_GrabMachineParams very early during startup if
 * we are restoring from a checkpoint).  Need to record these
 * to avoid giving errors that they are uninitialized.
 */

#define MAXGRABBED 16
static char* grabbedParams[MAXGRABBED];
static int numgrabbed = 0;

/*
 *   A place for random params
 */

char *MemFileDir;
char *DevFileDir;

extern int ConsolePort;
extern int SlaveConsoleTimeOut;
extern char *EthersimHostname;
extern char *EtherAddress;
extern int EtherSendPort;
extern int RestoreEthernet;
extern char *FPromFile;
extern int FPromUseFL;
extern int DebugPort;
extern int VisualPort;
extern int VisualSamplePeriod;
extern int FalseSharing;
extern int SimErrorKeepLogs;
extern int inCellMode;
extern int loopOnError;

#ifdef VCS_FAKE
extern int VcsFakeType;             /* 0 */
extern char *VcsFakeFilename;       /* vcsdump */
#endif

extern int migRepTriggerThreshold;
extern int migRepResetInterval;
extern int migRepEnableCounting;
extern int migRepMaxKern;
extern int migRepSampleCount;
extern int migRepPendIntr;
extern int migRepIntrHot;
extern int migRepZeroOnWrite;
extern int migRep4BitCounters;

static void ParamRegisterPerMachine(char *varName, char *addr,
				    AccessFunc accessFunc, int type);
char *ParamAccess(ClientData clientData, Tcl_Interp *interp,
                         char *name1, char *name2, int flags);
static void DumpMachineParams(void);
static int  ParamGrabbed(char* varName);

static char *AccessCPUModel(Tcl_Interp *interp);

Tcl_HashTable entries;

/**********************************************************************
 * Pointers to these functions are used as callbacks to access these
 * parameter values from the TCL C code
 **********************************************************************/

static char*
MachineNumCPUs(int _m, char* name)
{
   ASSERT (_m >= 0 && _m < MAX_MACHINES);
   return (char*)&(machines.machine[_m].NumCPUs);
}
 
static char*
MachineMemSizeSpecified(int _m, char* name)
{
   ASSERT (_m >= 0 && _m < MAX_MACHINES);
   return (char*)&(machines.machine[_m].MemSizeSpecified);
}
 
static char*
MachineNumMemories(int _m, char* name)
{
   ASSERT (_m >= 0 && _m < MAX_MACHINES);
   return (char*)&(machines.machine[_m].NumMemories);
}
 
static char*
MachineDiskModel(int _m, char* name)
{
   ASSERT (_m >= 0 && _m < MAX_MACHINES);
   return (char*)&(machines.machine[_m].DiskModel);
}
 
static char*
MachineHPDiskScaling(int _m, char* name)
{
   ASSERT (_m >= 0 && _m < MAX_MACHINES);
   return (char*)&(machines.machine[_m].HPDiskScaling);
}
 
static char*
MachineFixedDiskDelay(int _m, char* name)
{
   ASSERT (_m >= 0 && _m < MAX_MACHINES);
   return (char*)&(machines.machine[_m].FixedDiskDelay);
}
 
static char*
MachineNumConsoles(int _m, char* name)
{
   ASSERT (_m >= 0 && _m < MAX_MACHINES);
   return (char*)&(machines.machine[_m].NumConsoles);
}
 
static char*
MachineNumEtherControllers(int _m, char* name)
{
   ASSERT (_m >= 0 && _m < MAX_MACHINES);
   return (char*)&(machines.machine[_m].NumEtherControllers);
}

/*
 * Note: the following is special, since the parameter's name
 * contains the node number. Must decode.
 */
static char*
MachineNumDiskCtrls(int _m, char* name)
{
   int node;
   
   ASSERT (_m >= 0 && _m < MAX_MACHINES);
   sscanf(name, "PARAM(DISK.NumControllers.%d)", &node);
   ASSERT(0 <= node && node < DISK_NODES);
   return (char*)&(machines.machine[_m].NumDiskCtrls[node]);
}

static char*
MachineNumUnitsPerController(int _m, char* name)
{
   ASSERT (_m >= 0 && _m < MAX_MACHINES);
   return (char*)&(machines.machine[_m].NumUnitsPerController);
}

static char*
MachineNumClocks(int _m, char* name)
{
   ASSERT (_m >= 0 && _m < MAX_MACHINES);
   return (char*)&(machines.machine[_m].NumClocks);
}

static char*
MachineNumCells(int _m, char* name)
{
   ASSERT (_m >= 0 && _m < MAX_MACHINES);
   return (char*)&(machines.machine[_m].NumCells);
}

static char*
tcl_itoa(int val)
{
   char buf[32];  /* Big enough for a 64 bit int */
   sprintf(buf, "%d", val);
   return SaveString(buf);
}

/*****************************************************************
 * ParamInit
 * 
 *****************************************************************/
void 
ParamInit(Tcl_Interp *interp)
{
   int i;
   int machNo;
 
   for (i=0; i< MAX_PARAMS; i++) {
      param[i].initialized = FALSE; /* Clears all machines */
      param[i].readOnly = FALSE;    /* Clears all machines */
      param[i].type = PARAM_INT;
      param[i].name = NULL;
   }
   for (i=0; i < MAX_MACHINES; i++) {
      machineParamVec[i] = TRUE;
      machineScope = MACHINE_TOP;
   }

   ASSERT(MAX_MACHINES <= 32); /* Bit vector length of param struct */
   
   Tcl_InitHashTable(&entries, TCL_STRING_KEYS);

   /*--------------------------
    * Per-machine parameters
    *--------------------------*/

   /*
    * CPU parameters 
    */
   ParamRegisterPerMachine("PARAM(CPU.Count)",
                           (char *)&dummyMachine.NumCPUs,
                           MachineNumCPUs, PARAM_INT);

   /* 
    * MEMSYS parameters 
    */
   ParamRegisterPerMachine("PARAM(MEMSYS.MemSize)",
                           (char *)&dummyMachine.MemSizeSpecified,
                           MachineMemSizeSpecified, PARAM_INT);
   ParamRegisterPerMachine("PARAM(MEMSYS.BusUma.NumMemories)", 
                           (char *)&dummyMachine.NumMemories,
                           MachineNumMemories, PARAM_INT);
   ParamRegisterPerMachine("PARAM(MEMSYS.Numa.NumMemories)", 
                           (char *)&dummyMachine.NumMemories,
                           MachineNumMemories, PARAM_INT);

#ifndef SOLO
   /* 
    * DISK parameters
    */
   {
     /* NOTES:
      *
      * DISK.NumControllers.<n> is a per-node parameter. However,
      * at this point we do not yet know how many nodes there are
      * in the system. Hence we'll register enough parameters for
      * the max number of nodes, and do the checks dynamically
      * when accessing the parameter.
      *
      * An additional problem is that these parameters cannot be
      * cleanly initialized in defaults.tcl, since when we source
      * that file, we don't yet know how many CPUs there are.
      * We thus provide reasonable init values here.
      */
     int n;
     for (n = 0; n < SIM_MAXCPUS; n++) {
       char name[32];
       sprintf(name, "PARAM(DISK.NumControllers.%d)", n);
       ParamRegisterPerMachine(name,
			       (char *)&dummyMachine.NumDiskCtrls[n],
			       MachineNumDiskCtrls, PARAM_INT);
       for (machNo = 0; machNo < MAX_MACHINES; machNo++) {
	 SET_INITIALIZED(param[paramCount-1], machNo);
	 machines.machine[machNo].NumDiskCtrls[n] = 1; /* default */
       }
     }
   }

   ParamRegisterPerMachine("PARAM(DISK.NumUnitsPerController)",
                           (char *)&dummyMachine.NumUnitsPerController,
                           MachineNumUnitsPerController, PARAM_INT);
   for (machNo = 0; machNo < MAX_MACHINES; machNo++) {
     /* default */
     SET_INITIALIZED(param[paramCount-1], machNo);
     machines.machine[machNo].NumUnitsPerController = DEV_DISK_MAX_UNIT;
   }

   ParamRegisterPerMachine("PARAM(DISK.Model)",
                           (char *)&dummyMachine.DiskModel,
                           MachineDiskModel, PARAM_STRING);
   ParamRegisterPerMachine("PARAM(DISK.HP.Scaling)",
                           (char *)&dummyMachine.HPDiskScaling,
                           MachineHPDiskScaling, PARAM_INT);
   ParamRegisterPerMachine("PARAM(DISK.Fixed.Latency)",
                           (char *)&dummyMachine.FixedDiskDelay,
                           MachineFixedDiskDelay, PARAM_INT);

   /*
    * CONSOLE parameters
    */
   ParamRegisterPerMachine("PARAM(CONSOLE.Count)",
                           (char *)&dummyMachine.NumConsoles,
                           MachineNumConsoles, PARAM_INT);

   /* 
    * ETHERNET parameters
    */
   ParamRegisterPerMachine("PARAM(ETHERNET.Count)",
                           (char *)&dummyMachine.NumEtherControllers,
                           MachineNumEtherControllers, PARAM_INT);

   /* 
    * CLOCK parameters
    */
   ParamRegisterPerMachine("PARAM(CLOCK.Count)",
                           (char *)&dummyMachine.NumClocks,
                           MachineNumClocks, PARAM_INT);

   /* 
    * remaining paramters 
    */
   ParamRegisterPerMachine("PARAM(HIVE.NumCells)",
                           (char *)&dummyMachine.NumCells,
                           MachineNumCells, PARAM_INT);
#endif

   /*--------------------------
    * All-machine parameters
    *--------------------------*/

   /*
    * Machine parameters 
    */
   ParamRegister("PARAM(MACHINE.Count)", (char *)&machines.NumMachines, PARAM_INT);

   /*
    * CPU parameters 
    */
   ParamRegister("PARAM(CPU.Clock)", (char *)&machines.CpuClock, PARAM_INT);
   ParamRegister("PARAM(CPU.ISA)",   (char *)&machines.CpuISA,    PARAM_STRING);
   ParamRegister("PARAM(CPU.Model)", (char *)&machines.CpuModel,  PARAM_STRING);

   ParamRegister("PARAM(TLB.Org)", (char *)&machines.TlbOrg, PARAM_STRING);

   ParamRegister("PARAM(CPU.IntrClockFrequency)", (char*)&machines.IntrClockFrequency,PARAM_INT);

   /*
    * CACHE parameters 
    */
   ParamRegister("PARAM(CACHE.Model)", (char *)&machines.CacheModel, PARAM_STRING);
   ParamRegister("PARAM(CACHE.2Level.ISize)",   (char *)&machines.ICacheSizeSpecified, 
                 PARAM_INT);
   ParamRegister("PARAM(CACHE.2Level.ILine)",   (char *)&machines.ICacheLineSize,
                 PARAM_INT);
   ParamRegister("PARAM(CACHE.2Level.IAssoc)",  (char *)&machines.ICacheAssoc,
                 PARAM_INT);
   ParamRegister("PARAM(CACHE.2Level.IInclusion)",  (char *)&machines.ICacheInclusion,
                 PARAM_BOOLEAN);
   ParamRegister("PARAM(CACHE.2Level.DSize)",   (char *)&machines.DCacheSizeSpecified,
                 PARAM_INT);
   ParamRegister("PARAM(CACHE.2Level.DLine)",   (char *)&machines.DCacheLineSize,
                 PARAM_INT);
   ParamRegister("PARAM(CACHE.2Level.DAssoc)",  (char *)&machines.DCacheAssoc,
                 PARAM_INT);
   ParamRegister("PARAM(CACHE.2Level.L2Size)",  (char *)&machines.SCacheSizeSpecified,
                 PARAM_INT);
   ParamRegister("PARAM(CACHE.2Level.L2Line)",  (char *)&machines.SCacheLineSize,
                 PARAM_INT);
   ParamRegister("PARAM(CACHE.2Level.L2Assoc)", (char *)&machines.SCacheAssoc,
                 PARAM_INT);
   ParamRegister("PARAM(CACHE.2Level.L2HitTime)", 
                 (char *)&machines.SCacheHitTimeSpecified, PARAM_INT);
   ParamRegister("PARAM(CACHE.2Level.WriteBufferSize)", (char *)&machines.WriteBufferSize,
                 PARAM_INT);
   ParamRegister("PARAM(CACHE.2Level.UpgradesOnUP)", (char *)&machines.UpgradesOnUP,
                 PARAM_BOOLEAN);
   ParamRegister("PARAM(CACHE.2Level.NAKRetryTime)", 
                 (char *)&machines.NAKRetryTime, PARAM_INT);

   /* 
    * MEMSYS parameters 
    */
   ParamRegister("PARAM(MEMSYS.Model)", (char *)&machines.MemSysModel,
                 PARAM_STRING);
   ParamRegister("PARAM(MEMSYS.Perfect.Latency)", 
                 (char *)&machines.PerfectMemLatencySpecified, PARAM_INT);
   ParamRegister("PARAM(MEMSYS.BusUma.BusBW)", (char *)&machines.BusBW, 
                 PARAM_INT);
   ParamRegister("PARAM(MEMSYS.BusUma.MemCycleTime)", 
                 (char *)&machines.MemCycleTimeSpecified, PARAM_INT);
   ParamRegister("PARAM(MEMSYS.BusUma.DirtyPenalty)", 
                 (char *)&machines.DirtyPenaltySpecified, PARAM_INT);
   ParamRegister("PARAM(MEMSYS.BusUma.UpgradeTime)",  
                 (char *)&machines.UpgradeTimeSpecified, PARAM_INT);
   ParamRegister("PARAM(MEMSYS.Numa.BusTime)", 
                 (char *)&machines.NumaBusTimeSpecified, PARAM_INT);
   ParamRegister("PARAM(MEMSYS.Numa.PILocalDCTime)", 
                 (char *)&machines.NumaPILocalDCTimeSpecified, PARAM_INT);
   ParamRegister("PARAM(MEMSYS.Numa.PIRemoteDCTime)", 
                 (char *)&machines.NumaPIRemoteDCTimeSpecified, PARAM_INT);
   ParamRegister("PARAM(MEMSYS.Numa.NILocalDCTime)", 
                 (char *)&machines.NumaNILocalDCTimeSpecified, PARAM_INT);
   ParamRegister("PARAM(MEMSYS.Numa.NIRemoteDCTime)", 
                 (char *)&machines.NumaNIRemoteDCTimeSpecified, PARAM_INT);
   ParamRegister("PARAM(MEMSYS.Numa.MemTime)", 
                 (char *)&machines.NumaMemTimeSpecified, PARAM_INT);
   ParamRegister("PARAM(MEMSYS.Numa.NetTime)", 
                 (char *)&machines.NumaNetTimeSpecified, PARAM_INT);
   ParamRegister("PARAM(MEMSYS.Numa.StripeSize)", 
                 (char *)&machines.NumaStripeSize, PARAM_INT);


#ifdef USE_FLASHLITE
#ifndef SOLO
   ParamRegister("PARAM(MEMSYS.FLASH.FlashAddrMap)", 
                 (char *)NULL, PARAM_STRING);
   ParamRegister("PARAM(MEMSYS.FLASH.RoundRobinStripe)", 
                 (char *)NULL, PARAM_INT);
#endif
#endif

   ParamRegister("PARAM(VISUAL.Port)", (char *)&VisualPort, PARAM_INT);
   ParamRegister("PARAM(VISUAL.SamplePeriod)", 
                 (char *)&VisualSamplePeriod, PARAM_INT);

   /* With the exception of PARAM(FILES.SaveOldCPULogs), none of the 
    * FILES, DISK, CONSOLE, ETHERNET, or other miscellaneous parameters
    * are used in solo */

   /* 
    * FILES parameters
    */
   ParamRegister("PARAM(FILES.SaveOldCPULogs)", (char *)&SimErrorKeepLogs, 
                 PARAM_BOOLEAN);
#ifndef SOLO
   ParamRegister("PARAM(FILES.CptDir)", (char *)&cptSaveDir, PARAM_STRING);
   ParamRegister("PARAM(FILES.CptTag)", (char *)&CheckpointID, PARAM_STRING);
   ParamRegister("PARAM(FILES.CptCompress)", (char *)&CheckpointCompress, 
                 PARAM_BOOLEAN);
   ParamRegister("PARAM(FILES.FPROMFile)", (char *)&FPromFile, PARAM_STRING);   
   ParamRegister("PARAM(FILES.MemFileDir)", (char*)&MemFileDir, PARAM_STRING);
   ParamRegister("PARAM(FILES.DevFileDir)", (char*)&DevFileDir, PARAM_STRING);

   /*
    * CONSOLE parameters
    */
   ParamRegister("PARAM(CONSOLE.Port)",  (char *)&ConsolePort, PARAM_INT);
   ParamRegister("PARAM(CONSOLE.SlaveTimeOut)", (char *)&SlaveConsoleTimeOut, PARAM_INT);

   /* 
    * ETHERNET parameters
    */
   ParamRegister("PARAM(ETHERNET.Model)", (char *)&machines.EthernetModel, PARAM_STRING);
   ParamRegister("PARAM(ETHERNET.EtherSim.Active)", (char *)&RestoreEthernet, 
                 PARAM_BOOLEAN);
   ParamRegister("PARAM(ETHERNET.EtherSim.Address)", (char*)&EtherAddress, 
                 PARAM_STRING);
   ParamRegister("PARAM(ETHERNET.EtherSim.Hostname)", (char*)&EthersimHostname, 
                 PARAM_STRING);
   ParamRegister("PARAM(ETHERNET.EtherSim.Port)", (char *)&EtherSendPort, PARAM_INT);

   ParamRegister("PARAM(DEBUG.Port)", (char *)&DebugPort, PARAM_INT);
   ParamRegister("PARAM(DEBUG.LoopOnError)",(char*)&loopOnError,PARAM_BOOLEAN);

   ParamRegister("PARAM(STATS.FalseSharing)", (char *)&FalseSharing, PARAM_BOOLEAN);

   /* 
    * remaining paramters (MIPS-only)
    */
#if defined(SIM_MIPS32) || defined(SIM_MIPS64)
   ParamRegister("PARAM(MAGIC.SIPSLatency)", (char *)&machines.SIPSLatencySpecified,
                 PARAM_INT);
   ParamRegister("PARAM(MAGIC.IPILatency)", (char *)&machines.IPILatencySpecified,
                 PARAM_INT);
   ParamRegister("PARAM(MAGIC.InitialTime)", (char *)&machines.InitialTimeSpecified,
                 PARAM_INT);


   ParamRegister("PARAM(FPROM.PROMSize)", (char *)&machines.FPROMSize, PARAM_INT);
   ParamRegister("PARAM(FPROM.RAMSize)", (char *)&machines.FRAMSize, PARAM_INT);
   ParamRegister("PARAM(FPROM.UseFL)", (char *)&FPromUseFL, PARAM_BOOLEAN);

   ParamRegister("PARAM(MIGREP.Trigger)", (char *)&migRepTriggerThreshold, PARAM_INT);
   ParamRegister("PARAM(MIGREP.Reset)", (char *)&migRepResetInterval, PARAM_INT);
   ParamRegister("PARAM(MIGREP.Enable)", (char *)&migRepEnableCounting, PARAM_BOOLEAN);
   ParamRegister("PARAM(MIGREP.MaxKern)", (char *)&migRepMaxKern, PARAM_INT);
   ParamRegister("PARAM(MIGREP.SampleCount)", (char *)&migRepSampleCount, PARAM_INT);
   ParamRegister("PARAM(MIGREP.IntrCount)", (char *)&migRepPendIntr, PARAM_INT);
   ParamRegister("PARAM(MIGREP.IntrHot)", (char *)&migRepIntrHot, PARAM_BOOLEAN);
   ParamRegister("PARAM(MIGREP.ZeroOnWrite)", (char *)&migRepZeroOnWrite, PARAM_BOOLEAN);
   ParamRegister("PARAM(MIGREP.4BitCounters)", (char *)&migRep4BitCounters, PARAM_BOOLEAN);
#endif 

#ifdef VCS_FAKE
   ParamRegister("PARAM(MISC.VCSFake)", (char *)&VcsFakeType, PARAM_INT);
   ParamRegister("PARAM(MISC.VCSFake.FileName)", (char *)&VcsFakeFilename, PARAM_STRING);
#endif

#endif /* !SOLO */
   Tcl_TraceVar(TCLInterp, "PARAM",
                TCL_TRACE_READS | TCL_TRACE_WRITES | TCL_GLOBAL_ONLY, 
                ParamAccess, NULL); 
}

/*****************************************************************
 * Param Register (all-machine params)
 *****************************************************************/
void 
ParamRegister(char *varName, char *addr, int type)
{
   int newEntry;
   Tcl_HashEntry *entryPtr;
   char *stringMem;

   entryPtr = Tcl_CreateHashEntry(&entries, varName, &newEntry);
   
   ASSERT(newEntry);
   ASSERT(entryPtr);

   if ((type == PARAM_STRING) && (addr) && (*addr)) {
      char **temp = (char**)addr;
      *temp = SaveString(*temp);
   }

   /* Hack: since LL isn't supported in this version of Tcl, we don't
      allow direct linking -- we can only register and lookup LL values */
   if (type == PARAM_LL) {
     ASSERT(addr == NULL);
   }

   param[paramCount].initialized = ParamGrabbed(varName);
   /* Don't make CPU.Model read-only, since it is ok to specify and have
      the command line overide */
   if (!strcmp(varName, "PARAM(CPU.Model)")) {
      param[paramCount].readOnly = FALSE;
   } else {
      param[paramCount].readOnly = ParamGrabbed(varName);
   }
   param[paramCount].type = type;
   param[paramCount].bitField = FALSE;
   param[paramCount].accessFunc = (AccessFunc)NULL;
   param[paramCount].modifiedPerMachine = 0;
   stringMem = param[paramCount].name = SaveString(varName);

   /* Create a hash from variable name to its structure */
   Tcl_SetHashValue(entryPtr, &param[paramCount++]);

   /*
    * Warning: Tcl_LinkVar modifies and then restores the variable
    * name, we use the malloced copy of the name in case varName
    * was a read-only const passed to ParamRegister().
    */
   if (addr != NULL) {
      if (Tcl_LinkVar(TCLInterp, stringMem, addr, type) != TCL_OK) {
         CPUWarning("ParamRegister: Tcl_LinkVar call failed\n");
         ASSERT(0);
      }
   }
}

/*****************************************************************
 * Param Register (per-machine params)
 *****************************************************************/
static void 
ParamRegisterPerMachine(char *varName, char *addr,
                        AccessFunc accessFunc, int type)
{
   int newEntry;
   Tcl_HashEntry *entryPtr;
   char *stringMem;

   entryPtr = Tcl_CreateHashEntry(&entries, varName, &newEntry);
   
   ASSERT(newEntry);
   ASSERT(entryPtr);
   ASSERT(accessFunc);

   if ((type == PARAM_STRING) && (addr) && (*addr)) {
      char **temp = (char**)addr;
      *temp = SaveString(*temp);
   }

   /* Hack: since LL isn't supported in this version of Tcl, we don't
      allow direct linking -- we can only register and lookup LL values */
   if (type == PARAM_LL) {
     ASSERT(addr == NULL);
   }

   if (ParamGrabbed(varName)) {
      param[paramCount].initialized = BITFIELD_TRUE;
      param[paramCount].readOnly = BITFIELD_TRUE;
   } else {
      param[paramCount].initialized = FALSE;
      param[paramCount].readOnly = FALSE;
   }
   param[paramCount].type = type;
   param[paramCount].bitField = TRUE;
   param[paramCount].accessFunc = accessFunc;
   param[paramCount].modifiedPerMachine = 0;
   stringMem = param[paramCount].name = SaveString(varName);

   /* Create a hash from variable name to its structure */
   Tcl_SetHashValue(entryPtr, &param[paramCount++]);

   /*
    * Warning: Tcl_LinkVar modifies and then restores the variable
    * name, we use the malloced copy of the name in case varName
    * was a read-only const passed to ParamRegister().
    */
   if (addr != NULL) {
      if (Tcl_LinkVar(TCLInterp, stringMem, addr, type) != TCL_OK) {
         CPUWarning("ParamRegister: Tcl_LinkVar call failed\n");
         ASSERT(0);
      }
   }
}

/*****************************************************************
 * ParamAccess
 * -----------
 * When reading a per-machine param, this function is called just
 * before reading from the dummy param. We copy the correct value
 * int the dummy and let the copy proceed.
 * When writing to a per-machine param, this function is called
 * just after the dummy param is written to. We copy this value
 * out to all the machines that are currently active.
 *****************************************************************/
char *
ParamAccess(ClientData clientData, Tcl_Interp *interp,
            char *name1, char *name2, int flags)
{
   char buf[64];
   Tcl_HashEntry *entryPtr;
   ParamStruct   *oneParam;
   int count;

   sprintf(buf, "%s(%s)", name1, name2);

   if (!(entryPtr = Tcl_FindHashEntry(&entries, buf))) {
      return "unknown parameter accessed";
   }
  
   oneParam = (ParamStruct *)Tcl_GetHashValue(entryPtr);

   /* If we are reading the values */
   if (flags & TCL_TRACE_READS) {
      /* We don't want anyone changing variables after they have been
          read, so we make them read-only after the first read. Note
          that this only protects you in Tcl, not when referencing and
          changing the linked variables in C. */

      /* A per-machine parameter */
      if (oneParam->bitField) {
         int totalActive = 0, firstActive = MAX_MACHINES+1;
         char *paramPtr;

         for (count = 0; count < MAX_MACHINES; count++) {
            if (machineParamVec[count]) {
               totalActive++;
               if (firstActive > count)
                  firstActive = count;
            }
         }
         /* If more than one machine is the read source, only allow if we've never modified
             this param inside a machine block */
         if (totalActive != 1) {
            if (oneParam->modifiedPerMachine) {
               CPUWarning("PARAM: Must specify machine num when reading %s (since previously set per-machine).\nPARAM: Use '[machine_val machine_num param_name]' to specify.\n",
                          oneParam->name);
               return "PARAM: ambiguous variable read";
            } else
               firstActive = 0;
         } 

         if (!IS_INITIALIZED(*oneParam, firstActive)) {
            CPUWarning("PARAM: Trying to read uninitialized variable %s (machine %d).\n",
                       oneParam->name, firstActive);
            return "PARAM: uninitialized variable";
         }
         
         /* Set the value of the dummy */
         if (oneParam->type == PARAM_INT) {
	   paramPtr = tcl_itoa(*(int*)oneParam->accessFunc(firstActive, buf));
         } else if (oneParam->type == PARAM_STRING) {
	   paramPtr = SaveString(*((char **)oneParam->accessFunc(firstActive,
								 buf)));
         } else {
          /* Type not currently handled here */
            ASSERT (0);
	    paramPtr = 0; /* compiler happy */
         }
         Tcl_SetVar2(interp, name1, name2, paramPtr, TCL_GLOBAL_ONLY); 

         SET_READONLY(*oneParam, firstActive);

      } else {

         if (machineScope == MACHINE_VAL) {
            CPUWarning("PARAM: Can't use machine_val to read an all-machines param\n");
            return "PARAM: incorrect variable read";
         }
         if (!oneParam->initialized) {
            CPUWarning("PARAM: Trying to read uninitialized variable %s.\n",
                       oneParam->name);
            return "PARAM: uninitialized variable";
         }
         oneParam->readOnly = TRUE;
      }
      
   } else {

#ifndef SIM_ALPHA
      ASSERT(TclIniting);
#endif
      /* A per-machine parameter */
      if (oneParam->bitField) {
         char *paramVal = Tcl_GetVar2(interp, name1, name2, TCL_GLOBAL_ONLY); 
         for (count = 0; count < MAX_MACHINES; count++) {
            if (machineParamVec[count]) {

               if (IS_READONLY(*oneParam, count)) {
                  CPUWarning("PARAM: Trying to write to %s (machine %d) after it has been read... ABORTING\n",
                        oneParam->name, count);
                  return "PARAM: writing to accessed var";
               } else {
                  SET_INITIALIZED(*oneParam, count);
               }

               /* Copy the value to this machine's param */
               if (oneParam->type == PARAM_INT) {
                  Tcl_GetInt(interp, paramVal,
			     (int*)oneParam->accessFunc(count, buf));
               } else if (oneParam->type == PARAM_STRING) {
                  *((char **)oneParam->accessFunc(count, buf)) =
		                                   SaveString(paramVal);
               } else {
                  /* Type not currently handled here */
                  ASSERT (0);
               }
            }
         }
         /* If we modified this in a machine block, set modifiedPerMachine */
         if (machineScope != MACHINE_TOP) {
            oneParam->modifiedPerMachine = TRUE;
         }
      } else {
         if (machineScope != MACHINE_TOP) {
             CPUWarning("PARAM: Trying to modify an all-machines param %s per machine... ABORTING\n",
                 oneParam->name);
             return "PARAM: illegal modification"; 
         }

         if (oneParam->readOnly) {
            CPUWarning("PARAM: Trying to write to %s after it has been read... ABORTING\n",
                oneParam->name);
            return "PARAM: illegal modification";
         } else {
            oneParam->initialized = TRUE;

            if (!strcmp(name2, "CPU.Model")) {
               return AccessCPUModel(interp);
            }
         }
      }
   }

   return NULL;
}

/*
 * Calling this function for per-machine params would be a bad idea, 
 * since only the last accessed value would be returned. However, it
 * is never used on these params, so there is no problem.
 */
int
ParamLookup(void *valptr, char *name, int type) 
{
  char *ptr;
  char *val = Tcl_GetVar2(TCLInterp, "PARAM", name, TCL_GLOBAL_ONLY);
  if (val == NULL) {
    return FALSE;
  }
  switch (type) {
  case PARAM_STRING:
    *((char **)valptr) = val;
    return TRUE;
  case PARAM_INT:
    return (Tcl_GetInt(TCLInterp, val, (int *)valptr) == TCL_OK);
  case PARAM_BOOLEAN:
    return (Tcl_GetBoolean(TCLInterp, val, (int *)valptr) == TCL_OK);
  case PARAM_DOUBLE:
    return (Tcl_GetDouble(TCLInterp, val, (double *)valptr) == TCL_OK);
  case PARAM_LL:
#if defined(__alpha) || defined(i386)
    *((int64 *)valptr) = strtol(val, &ptr, 0);
#else
    *((int64 *)valptr) = strtoll(val, &ptr, 0);
#endif
    return (ptr != val);
  default:
    break;
  }    
  return FALSE;
}

/*****************************************************************
 * ParamGrabbed
 *
 * Almost all parameters return FALSE for this, so will require
 * initialization by the init.simos and follow-on scripts.
 *
 *****************************************************************/
static int
ParamGrabbed(char* varName)
{
   int i;
   for (i=0; i<numgrabbed; i++) {
      if (!strcmp(varName, grabbedParams[i])) 
         return TRUE;
   }
   return FALSE;
}


/*****************************************************************
 * ParamGrabbedAtStartup
 *
 * Called by simcpt.c to record its dirty deed.  Note that
 * this is called *before* tclinit so we can't rely on anything
 * from the tcl library.
 * NOTE: This specifies that the param has been grabbed for _all_
 * machines, since when restoring from checkpoint, values must
 * have been set for all machines.
 *****************************************************************/

void
ParamGrabbedAtStartup(char* varName)
{
   ASSERT(numgrabbed < MAXGRABBED);
   grabbedParams[numgrabbed++] = varName;
}

/*****************************************************************
 * MachineSettingsComplete
 *
 * This procedure has two purposes:
 *   Ensure that all variables have had a default value assigned 
 *      to them 
 *   Compute the derived fields from the "specified" values
 *****************************************************************/
void
MachineSettingsComplete(void)
{
   int i, machNo, cpuCount, memoryCount;
   int consoleCount, etherCount, clockCount;
   bool badParamExists = FALSE;
   Tcl_HashEntry *entryPtr;
   ParamStruct *oneParam;

   /*
    * Find the value of PARAM(MACHINE.Count) so that we know how many machines
    * to check for completion on.
    */
   if (!(entryPtr = Tcl_FindHashEntry(&entries, "PARAM(MACHINE.Count)"))) {
      /* It should exist, so if not we will assert fail */
      ASSERT(0);
   }
   oneParam = (ParamStruct *)Tcl_GetHashValue(entryPtr);
   ASSERT(oneParam);
   if (!oneParam->initialized) {
      CPUWarning("PARAM: PARAM(MACHINE.Count) has not been initialized. Assuming 1 machine.\n");
      oneParam->initialized = TRUE;
      NUM_MACHINES = 1;
   }
   if (NUM_MACHINES < 1 || NUM_MACHINES > MAX_MACHINES) {
      CPUWarning("Number of machines (%d) is out of legal range of %d to %d.\n",
                 NUM_MACHINES, 1, MAX_MACHINES);
      ASSERT(0);
   }

#ifndef SOLO
   /*
    * Ensure that if we have more than one machine, that each machine is just
    * one cell. i.e If we have multiple machines, then each is just one cell,
    * and if we have multiple cells, then we only have one machine.
    */
   inCellMode = 0;
   if (NUM_MACHINES > 1) {
      for (machNo = 0; machNo < NUM_MACHINES; machNo++) {
         if (machines.machine[machNo].NumCells > 1) {
            CPUWarning("Can't have a machine with more than one cell when using multiple machines");
            ASSERT(0);
         }
      }
   } else {
      if (machines.machine[0].NumCells > 1) {
         inCellMode = 1;
         ASSERT(NUM_CONSOLES(0) == NUM_CELLS(0));
         ASSERT(NUM_ETHER_CONTROLLERS(0) == NUM_CELLS(0));
         ASSERT(NUM_CLOCKS(0) == NUM_CELLS(0));
      }
   }
#endif

   /* 
    * Check for any uninitialized parameters. I could also do this
    * within the Tcl access functions, but then I would miss the case 
    * where C was accessing an uninitialized variable.
    */
   for (i=0; i< paramCount; i++) {
      if (param[i].bitField) {
         for (machNo = 0; machNo < NUM_MACHINES; machNo++) { 
             if (!IS_INITIALIZED(param[i], machNo)) {
                 CPUWarning("PARAM: %s (machine %d) has not been initialized\n",
                            param[i].name, machNo);
                 badParamExists = TRUE;
             }
         }
      } else {
         if (!param[i].initialized) {
            CPUWarning("PARAM %s has not been initialized\n",
                       param[i].name);
            badParamExists = TRUE;
         }
      }
   }

   if (badParamExists) {
       ASSERT(0);
   }

   /* 
    * Compute all of the derived parameter fields 
    */
   MAX_CPUS_PER_MACHINE = 0;
   MAX_CONSOLES_PER_MACHINE = 0;
   MAX_ETHER_CONTROLLERS_PER_MACHINE = 0;
   MAX_CLOCKS_PER_MACHINE = 0;

   /* Find the total number of CPUS for allocating mapping vector */
   for (machNo = 0, cpuCount = 0; machNo < NUM_MACHINES; machNo++) {
       cpuCount += NUM_CPUS(machNo);
   }
   /* Allocate memory for cpu to machine mapping array */
   MachineFromCPU = (int*) calloc(SIM_MAXCPUS /* XXX cpuCount XXX */,
				  sizeof(int));

   for (machNo = 0, cpuCount = 0, memoryCount = 0, consoleCount = 0,
            etherCount = 0, clockCount = 0 ;
        machNo < NUM_MACHINES; machNo++) {
       machines.machine[machNo].MemSize =
           machines.machine[machNo].MemSizeSpecified*1024*1024;

      FIRST_CPU(machNo) = cpuCount;
      for (i = 0; i < NUM_CPUS(machNo); cpuCount++, i++) {
          MachineFromCPU[cpuCount] = machNo;
      }
      LAST_CPU(machNo) = cpuCount-1;
      if (NUM_CPUS(machNo) > MAX_CPUS_PER_MACHINE)
         MAX_CPUS_PER_MACHINE = NUM_CPUS(machNo);

      FIRST_MEMORY(machNo) = memoryCount;
      memoryCount += NUM_MEMORIES(machNo);
      LAST_MEMORY(machNo) = memoryCount-1;

      FIRST_CONSOLE(machNo) = consoleCount;
      consoleCount += NUM_CONSOLES(machNo);
      LAST_CONSOLE(machNo) = consoleCount-1;
      if (NUM_CONSOLES(machNo) > MAX_CONSOLES_PER_MACHINE)
         MAX_CONSOLES_PER_MACHINE = NUM_CONSOLES(machNo);

      FIRST_ETHER_CONTROLLER(machNo) = etherCount;
      etherCount += NUM_ETHER_CONTROLLERS(machNo);
      LAST_ETHER_CONTROLLER(machNo) = etherCount-1;
      if (NUM_ETHER_CONTROLLERS(machNo) > MAX_ETHER_CONTROLLERS_PER_MACHINE)
         MAX_ETHER_CONTROLLERS_PER_MACHINE = NUM_ETHER_CONTROLLERS(machNo);

      FIRST_CLOCK(machNo) = clockCount;
      clockCount += NUM_CLOCKS(machNo);
      LAST_CLOCK(machNo) = clockCount-1;
      if (NUM_CLOCKS(machNo) > MAX_CLOCKS_PER_MACHINE)
         MAX_CLOCKS_PER_MACHINE = NUM_CLOCKS(machNo);

#if !defined(SOLO) && (defined(SIM_MIPS32) || defined(SIM_MIPS64))
      machines.machine[machNo].CPUsPerCell = machines.machine[machNo].NumCPUs /
                                             machines.machine[machNo].NumCells;
      machines.machine[machNo].log2CPUsPerCell =
                                 GetLog2(machines.machine[machNo].NumCPUs /
                                         machines.machine[machNo].NumCells);
#else
#ifdef SIM_ALPHA
      machines.machine[machNo].CPUsPerCell = -12345678;   /* unused */
      machines.machine[machNo].log2CPUsPerCell = -12345678; /* unused */
#else
      machines.machine[machNo].CPUsPerCell = machines.machine[machNo].NumCPUs;
      machines.machine[machNo].log2CPUsPerCell =
                                 GetLog2(machines.machine[machNo].CPUsPerCell);
#endif
#endif

   }
   machines.TotalCPUs = cpuCount;
   machines.TotalMemories = memoryCount;
   machines.TotalConsoles = consoleCount;
   machines.TotalEtherControllers = etherCount;
   machines.TotalClocks = clockCount;

   machines.SCacheSize = machines.SCacheSizeSpecified*1024;
   machines.ICacheSize = machines.ICacheSizeSpecified*1024;
   machines.DCacheSize = machines.DCacheSizeSpecified*1024;

   machines.PerfectMemLatency = 
                          NanoSecsToCycles(machines.PerfectMemLatencySpecified);
   machines.MemCycleTime = NanoSecsToCycles(machines.MemCycleTimeSpecified);
   machines.UpgradeTime  = NanoSecsToCycles(machines.UpgradeTimeSpecified);
   machines.DirtyPenalty = NanoSecsToCycles(machines.DirtyPenaltySpecified);
#ifndef SOLO
   machines.SIPSLatency  = NanoSecsToCycles(machines.SIPSLatencySpecified);
   machines.IPILatency   = NanoSecsToCycles(machines.IPILatencySpecified);
   if (machines.InitialTimeSpecified == 0) {
      int ret; struct timeval tv;
      /* An InitialTime of zero means use current time. */
      ret = gettimeofday(&tv, NULL);
      ASSERT(ret == 0);
      machines.InitialTime  = tv.tv_sec;
   } else {
      machines.InitialTime = machines.InitialTimeSpecified;
   }
#endif
   machines.log2ICacheLineSize = GetLog2(machines.ICacheLineSize);
   machines.log2ICacheSize     = GetLog2(machines.ICacheSize);
   machines.log2ICacheAssoc    = GetLog2(machines.ICacheAssoc);

   machines.iCacheIndex = machines.ICacheSize 
      / machines.ICacheLineSize 
      / machines.ICacheAssoc;

   machines.log2DCacheLineSize = GetLog2(machines.DCacheLineSize);
   machines.log2DCacheSize     = GetLog2(machines.DCacheSize);
   machines.log2DCacheAssoc    = GetLog2(machines.DCacheAssoc);

   machines.dCacheIndex = machines.DCacheSize 
      / machines.DCacheLineSize 
      / machines.DCacheAssoc;

   machines.SCacheHitTime      = (machines.SCacheHitTimeSpecified 
                                * machines.CpuClock ) / 1000;  
   machines.log2SCacheSize     = GetLog2(machines.SCacheSize);
   machines.log2SCacheLineSize = GetLog2(machines.SCacheLineSize);
   machines.log2SCacheAssoc    = GetLog2(machines.SCacheAssoc);

   machines.sCacheIndex = machines.SCacheSize 
      / machines.SCacheLineSize 
      / machines.SCacheAssoc;

   machines.NumaBusTime   = NanoSecsToCycles(machines.NumaBusTimeSpecified);
   machines.NumaPILocalDCTime  = NanoSecsToCycles(machines.NumaPILocalDCTimeSpecified);
   machines.NumaPIRemoteDCTime = NanoSecsToCycles(machines.NumaPIRemoteDCTimeSpecified);
   machines.NumaNILocalDCTime  = NanoSecsToCycles(machines.NumaNILocalDCTimeSpecified);
   machines.NumaNIRemoteDCTime = NanoSecsToCycles(machines.NumaNIRemoteDCTimeSpecified);
   machines.NumaMemTime   = NanoSecsToCycles(machines.NumaMemTimeSpecified);
   machines.NumaNetTime   = NanoSecsToCycles(machines.NumaNetTimeSpecified);

   DumpMachineParams();
}

/*****************************************************************
 * SetAdditionalParams
 *****************************************************************/
void
SetAdditionalParams(Tcl_Interp *interp)
{
   int machineCount, totalCpuCount, cpuCount;
   
   Tcl_SetVar2(interp, "PARAM", "MACHINE.TotalCPUs",
               tcl_itoa(machines.TotalCPUs), TCL_GLOBAL_ONLY);
   
   for (machineCount = 0, totalCpuCount = 0;
        machineCount < machines.NumMachines; machineCount++) {
      for (cpuCount = 0; cpuCount < machines.machine[machineCount].NumCPUs;
           cpuCount++) {
         Tcl_SetVar2(interp, "M", tcl_itoa(totalCpuCount),
                    tcl_itoa(machineCount), TCL_GLOBAL_ONLY);
         Tcl_SetVar2(interp, "MCPU", tcl_itoa(totalCpuCount),
                    tcl_itoa(cpuCount), TCL_GLOBAL_ONLY);
         totalCpuCount++;
      }
   }
}

/*****************************************************************
 *
 * CPU Model is handled specially because it can be overriden
 * on the command line.
 *
 *****************************************************************/

static int CPUTypeSpecified = 0;

void InitCPUModel(CPUType cmdLineCPU)
{
   if (cmdLineCPU != NO_CPU) {
      CPUTypeSpecified = 1;
      ParamGrabbedAtStartup("PARAM(CPU.Model)");
   }
   
   simosCPUType = cmdLineCPU;

   if (simosCPUType == EMBRA_PAGE) {
      machines.CpuModel = SaveString("EMBRA_PAGE");
   } else if (simosCPUType == EMBRA_CACHE) {
      machines.CpuModel = SaveString("EMBRA_CACHE");
   } else if (simosCPUType == MIPSY) {
      machines.CpuModel = SaveString("MIPSY");
#if defined(SIM_ALPHA)
   } else if (simosCPUType == GAMMA) {
      machines.CpuModel = SaveString("GAMMA");
   } else if (simosCPUType == DELTA) { 
      machines.CpuModel = SaveString("DELTA");
   } else if (simosCPUType == EPSILON) { 
      machines.CpuModel = SaveString("EPSILON");
   } else if (simosCPUType == KAPPA) { 
      machines.CpuModel = SaveString("KAPPA");
#endif
   } else if (simosCPUType == NO_CPU) {
      machines.CpuModel = SaveString("NONE");
   } else {
      ASSERT(0);
   }   
}

char *AccessCPUModel(Tcl_Interp *interp)
{
   if (CPUTypeSpecified) {
      free(machines.CpuModel);
      
#if defined(SIM_MIPS32) || defined(SIM_MIPS64)
      if (simosCPUType == EMBRA_PAGE) {
         Tcl_SetVar2(interp, "PARAM", "CPU.Model", "EMBRA_PAGE", TCL_GLOBAL_ONLY);
         machines.CpuModel = SaveString("EMBRA_PAGE");
      } else if (simosCPUType == EMBRA_CACHE) {
         Tcl_SetVar2(interp, "PARAM", "CPU.Model", "EMBRA_CACHE", TCL_GLOBAL_ONLY);
         machines.CpuModel = SaveString("EMBRA_CACHE");
      } else if (simosCPUType == MIPSY) {
         Tcl_SetVar2(interp, "PARAM", "CPU.Model", "MIPSY", TCL_GLOBAL_ONLY);
         machines.CpuModel = SaveString("MIPSY");
      } else
#endif /* def SIM_MIPS32 || def SIM_MIPS64 */
#ifdef SIM_ALPHA
      if (simosCPUType == GAMMA) {
         Tcl_SetVar2(interp, "PARAM", "CPU.Model", "GAMMA", TCL_GLOBAL_ONLY);
         machines.CpuModel = SaveString("GAMMA");
      } else if (simosCPUType==DELTA) { 
         Tcl_SetVar2(interp, "PARAM", "CPU.Model", "DELTA", TCL_GLOBAL_ONLY);
         machines.CpuModel = SaveString("DELTA");	 
      } else if (simosCPUType==EPSILON) { 
         Tcl_SetVar2(interp, "PARAM", "CPU.Model", "EPSILON", TCL_GLOBAL_ONLY);
         machines.CpuModel = SaveString("EPSILON");	 
      } else if (simosCPUType==KAPPA) { 
         Tcl_SetVar2(interp, "PARAM", "CPU.Model", "KAPPA", TCL_GLOBAL_ONLY);
         machines.CpuModel = SaveString("KAPPA");	 
      } else
#endif /* def SIM_ALPHA */
#ifdef SIM_X86
      if (simosCPUType == X86SIM) { 
         Tcl_SetVar2(interp, "PARAM", "CPU.Model", "X86SIM", TCL_GLOBAL_ONLY);
         machines.CpuModel = SaveString("X86SIM");
      } else
#endif /* def SIM_X86 */
         ASSERT(0);
      
   } else {
      char *model = Tcl_GetVar2(interp, "PARAM", "CPU.Model", TCL_GLOBAL_ONLY);

#if defined(SIM_MIPS32) || defined(SIM_MIPS64)
      if (strcmp("EMBRA_PAGE", model) == 0) { 
         simosCPUType = EMBRA_PAGE;
      } else if (strcmp("EMBRA_CACHE", model) == 0) { 
         simosCPUType = EMBRA_CACHE;
      } else if (strcmp("MIPSY", model) == 0) { 
         simosCPUType = MIPSY;
      } else if (strcmp("MXS", model) == 0) { 
         simosCPUType = MIPSY;
      } else
#endif /* def SIM_MIPS32 || def SIM_MIPS64 */
#ifdef SIM_ALPHA
      if (strcmp("GAMMA", model) == 0) { 
         simosCPUType = GAMMA;
      } else if (strcmp("DELTA",model)==0) {
	 simosCPUType = DELTA;
      } else if (strcmp("EPSILON",model)==0) {
	 simosCPUType = EPSILON;
      } else if (strcmp("KAPPA",model)==0) {
	 simosCPUType = KAPPA;
      } else
#endif /* def SIM_ALPHA */
#ifdef SIM_X86
      if (strcmp("X86SIM", model) == 0) { 
         simosCPUType = X86SIM;
      } else
#endif /* def SIM_X86 */
         return "unknown cpu model";
   }

   return NULL;
} /* AccessCPUModel () */


/*****************************************************************
 * DumpMachineParams
 *****************************************************************/
static void
DumpMachineParams(void)
{
   int machNo;
   int node;
   
   CPUPrint("=============================================================\n");
   CPUPrint("=                   MACHINE PARAMETERS                      =\n");
   CPUPrint("=============================================================\n");

   CPUPrint("\nNumber of machines = %d\n", machines.NumMachines);

   for (machNo = 0; machNo < NUM_MACHINES; machNo++) { 
      CPUPrint("\n===== Machine %d =====\n\n", machNo);
      CPUPrint("MACHINE NumCPUs\t\t\t%d\n", machines.machine[machNo].NumCPUs);
      CPUPrint("MACHINE NumCells\t\t%d\n", machines.machine[machNo].NumCells);
      CPUPrint("MACHINE MemSize\t\t\t%d  Meg\n", machines.machine[machNo].MemSizeSpecified);
      CPUPrint("MACHINE NumMemories\t\t%d\n", machines.machine[machNo].NumMemories);

#if !defined(SOLO) && (defined(SIM_MIPS32) || defined(SIM_MIPS64))
      if (!strcmp(machines.machine[machNo].DiskModel, "HP")) {
         CPUPrint("MACHINE DiskModel\t\tHP\n");
         CPUPrint("MACHINE DiskScaling\t\t%d %%\n",  machines.machine[machNo].HPDiskScaling);
      } else {
         CPUPrint("MACHINE DiskModel\t\tFixed\n");
         CPUPrint("MACHINE FixedDiskDelay\t\t%d ns\n",  machines.machine[machNo].FixedDiskDelay);
      }
#endif

      CPUPrint("MACHINE NumConsoles\t\t%d\n",  machines.machine[machNo].NumConsoles);
      CPUPrint("MACHINE NumEtherInterfaces\t%d\n",  machines.machine[machNo].NumEtherControllers);

#if !defined(SOLO)
      CPUPrint("MACHINE NumUnitsPerController\t\t%d ns\n",
	       machines.machine[machNo].NumUnitsPerController);
      /* DT: disk controllers are now per node */
      for (node = 0; node < NUM_CPUS(machNo); node++) {
	CPUPrint("MACHINE NumDiskControllers.%d\t%d\n",
		 node, machines.machine[machNo].NumDiskCtrls[node]);
      }
#endif

      CPUPrint("MACHINE NumClocks\t\t%d\n",  machines.machine[machNo].NumClocks);
   }

   CPUPrint("\n===== Additional params for all machines =====\n\n");

   CPUPrint("MACHINE BusBW\t\t%d MB/s\n", machines.BusBW);
   CPUPrint("MACHINE Clock\t\t%d Mhz\n", machines.CpuClock);

   CPUPrint("MACHINE DCacheSize\t%d kB\n",  machines.DCacheSizeSpecified);
   CPUPrint("MACHINE DCacheAssoc\t%d way\n",  machines.DCacheAssoc);
   CPUPrint("MACHINE DCacheLineSize\t%d bytes\n",  machines.DCacheLineSize);

   CPUPrint("MACHINE DirtyPenalty\t%d ns\n", machines.DirtyPenaltySpecified);

   CPUPrint("MACHINE ICacheAssoc\t%d way\n",  machines.ICacheAssoc);
   CPUPrint("MACHINE ICacheLineSize\t%d bytes\n",  machines.ICacheLineSize);
   CPUPrint("MACHINE ICacheSize\t%d kB\n",  machines.ICacheSizeSpecified);

   CPUPrint("MACHINE PerfectMemLatency\t%d ns\n", 
            machines.PerfectMemLatencySpecified);

   CPUPrint("MACHINE MemCycleTime\t%d ns\n", machines.MemCycleTimeSpecified);

   CPUPrint("MACHINE SCacheAssoc\t%d way\n",  machines.SCacheAssoc);
   CPUPrint("MACHINE SCacheHitTime\t%d ns\n",  machines.SCacheHitTimeSpecified);
   CPUPrint("MACHINE SCacheLineSize\t%d bytes\n",  machines.SCacheLineSize);
   CPUPrint("MACHINE SCacheSize\t%d kB\n",  machines.SCacheSizeSpecified);
   CPUPrint("MACHINE NAKRetryTime\t%d cycles\n", machines.NAKRetryTime);

#ifndef SOLO
   CPUPrint("MACHINE SIPSLatency\t%d ns\n", machines.SIPSLatencySpecified);
   CPUPrint("MACHINE IPILatency\t%d ns\n", machines.IPILatencySpecified);
   CPUPrint("MACHINE InitialTime\t%d ns\n", machines.InitialTimeSpecified);
#endif

   CPUPrint("MACHINE UpgradeTime\t%d ns\n", machines.UpgradeTimeSpecified);

   CPUPrint("MACHINE WriteBufferSize\t%d entries\n",  machines.WriteBufferSize);

   CPUPrint("MACHINE NumaBusTime\t%d entries\n",  machines.NumaBusTimeSpecified);
   CPUPrint("MACHINE NumaPILocalDCTime\t%d entries\n",  machines.NumaPILocalDCTimeSpecified);
   CPUPrint("MACHINE NumaPIRemoteDCTime\t%d entries\n", machines.NumaPIRemoteDCTimeSpecified);
   CPUPrint("MACHINE NumaNILocalDCTime\t%d entries\n",  machines.NumaNILocalDCTimeSpecified);
   CPUPrint("MACHINE NumaNIRemoteDCTime\t%d entries\n", machines.NumaNIRemoteDCTimeSpecified);
   CPUPrint("MACHINE NumaMemTime\t%d entries\n",  machines.NumaMemTimeSpecified);
   CPUPrint("MACHINE NumaNetTime\t%d entries\n",  machines.NumaNetTimeSpecified);
   CPUPrint("MACHINE NumaStripeSize\t%d entries\n",  machines.NumaStripeSize);

   CPUPrint("\n=============================================================\n\n");
}