annotate SSR.c @ 82:724b5fbcdd57

Starting new branch for developing the data tracking assigner
author Sean Halle <seanhalle@yahoo.com>
date Fri, 28 Dec 2012 09:31:44 -0800
parents 494703aecda2
children ce07f1a42ddf
rev   line source
seanhalle@64 1 /*
seanhalle@64 2 * Copyright 2010 OpenSourceCodeStewardshipFoundation
seanhalle@64 3 *
seanhalle@64 4 * Licensed under BSD
seanhalle@64 5 */
seanhalle@64 6
seanhalle@64 7 #include <stdio.h>
seanhalle@64 8 #include <stdlib.h>
seanhalle@64 9 #include <malloc.h>
seanhalle@64 10
seanhalle@64 11 #include "Queue_impl/PrivateQueue.h"
seanhalle@64 12 #include "Hash_impl/PrivateHash.h"
seanhalle@64 13
seanhalle@64 14 #include "SSR.h"
seanhalle@64 15 #include "SSR_Counter_Recording.h"
seanhalle@64 16
seanhalle@64 17 //==========================================================================
seanhalle@64 18
seanhalle@64 19 void
seanhalle@64 20 SSR__init();
seanhalle@64 21
seanhalle@64 22 void
seanhalle@64 23 SSR__init_Helper();
seanhalle@64 24 //==========================================================================
seanhalle@64 25
seanhalle@64 26
seanhalle@64 27 /*TODO: Q: dealing with library f()s and DKU vs WT vs FoR
seanhalle@64 28 * (still want to do FoR, with time-lines as syntax, could be super cool)
seanhalle@64 29 * A: thinking pin the coreCtlrs for all of BLIS -- let Master arbitrate
seanhalle@64 30 * among library, DKU, WT, FoR -- all the patterns in terms of virtual
seanhalle@64 31 * processors (or equivalently work-units), so Master picks which virt procr
seanhalle@67 32 * from which portions of app (DKU, WT, FoR) onto which anim slots
seanhalle@67 33 *Might even do hierarchy of masters -- group of anim slots for each core
seanhalle@64 34 * has its own master, that keeps generated work local
seanhalle@64 35 * single-reader-single-writer sync everywhere -- no atomic primitives
seanhalle@64 36 * Might have the different assigners talk to each other, to negotiate
seanhalle@64 37 * larger-grain sharing of resources, according to predicted critical
seanhalle@64 38 * path, and expansion of work
seanhalle@64 39 */
seanhalle@64 40
seanhalle@64 41
seanhalle@64 42
seanhalle@64 43 //===========================================================================
seanhalle@64 44
seanhalle@64 45
seanhalle@64 46 /*These are the library functions *called in the application*
seanhalle@64 47 *
seanhalle@64 48 *There's a pattern for the outside sequential code to interact with the
seanhalle@64 49 * VMS_HW code.
seanhalle@64 50 *The VMS_HW system is inside a boundary.. every SSR system is in its
seanhalle@64 51 * own directory that contains the functions for each of the processor types.
seanhalle@64 52 * One of the processor types is the "seed" processor that starts the
seanhalle@64 53 * cascade of creating all the processors that do the work.
seanhalle@64 54 *So, in the directory is a file called "EntryPoint.c" that contains the
seanhalle@64 55 * function, named appropriately to the work performed, that the outside
seanhalle@64 56 * sequential code calls. This function follows a pattern:
seanhalle@64 57 *1) it calls SSR__init()
seanhalle@64 58 *2) it creates the initial data for the seed processor, which is passed
seanhalle@64 59 * in to the function
seanhalle@64 60 *3) it creates the seed SSR processor, with the data to start it with.
seanhalle@64 61 *4) it calls startSSRThenWaitUntilWorkDone
seanhalle@64 62 *5) it gets the returnValue from the transfer struc and returns that
seanhalle@64 63 * from the function
seanhalle@64 64 *
seanhalle@64 65 *For now, a new SSR system has to be created via SSR__init every
seanhalle@64 66 * time an entry point function is called -- later, might add letting the
seanhalle@64 67 * SSR system be created once, and let all the entry points just reuse
seanhalle@64 68 * it -- want to be as simple as possible now, and see by using what makes
seanhalle@64 69 * sense for later..
seanhalle@64 70 */
seanhalle@64 71
seanhalle@64 72
seanhalle@64 73
seanhalle@64 74 //===========================================================================
seanhalle@64 75
seanhalle@64 76 /*This is the "border crossing" function -- the thing that crosses from the
seanhalle@64 77 * outside world, into the VMS_HW world. It initializes and starts up the
seanhalle@64 78 * VMS system, then creates one processor from the specified function and
seanhalle@64 79 * puts it into the readyQ. From that point, that one function is resp.
seanhalle@64 80 * for creating all the other processors, that then create others, and so
seanhalle@64 81 * forth.
seanhalle@64 82 *When all the processors, including the seed, have dissipated, then this
seanhalle@64 83 * function returns. The results will have been written by side-effect via
seanhalle@64 84 * pointers read from, or written into initData.
seanhalle@64 85 *
seanhalle@64 86 *NOTE: no Threads should exist in the outside program that might touch
seanhalle@64 87 * any of the data reachable from initData passed in to here
seanhalle@64 88 */
seanhalle@64 89 void
seanhalle@64 90 SSR__create_seed_procr_and_do_work( TopLevelFnPtr fnPtr, void *initData )
seanhalle@64 91 { SSRSemEnv *semEnv;
seanhalle@64 92 SlaveVP *seedPr;
seanhalle@64 93
seanhalle@64 94 SSR__init(); //normal multi-thd
seanhalle@64 95
seanhalle@64 96 semEnv = _VMSMasterEnv->semanticEnv;
seanhalle@64 97
seanhalle@64 98 //SSR starts with one processor, which is put into initial environ,
seanhalle@64 99 // and which then calls create() to create more, thereby expanding work
seanhalle@64 100 seedPr = SSR__create_procr_helper( fnPtr, initData,
seanhalle@64 101 semEnv, semEnv->nextCoreToGetNewPr++ );
seanhalle@64 102
seanhalle@64 103 resume_slaveVP( seedPr, semEnv );
seanhalle@64 104
seanhalle@64 105 VMS_SS__start_the_work_then_wait_until_done(); //normal multi-thd
seanhalle@64 106
seanhalle@64 107 SSR__cleanup_after_shutdown();
seanhalle@64 108 }
seanhalle@64 109
seanhalle@64 110
seanhalle@64 111 int32
seanhalle@64 112 SSR__giveMinWorkUnitCycles( float32 percentOverhead )
seanhalle@64 113 {
seanhalle@64 114 return MIN_WORK_UNIT_CYCLES;
seanhalle@64 115 }
seanhalle@64 116
seanhalle@64 117 int32
seanhalle@64 118 SSR__giveIdealNumWorkUnits()
seanhalle@64 119 {
seanhalle@69 120 return NUM_ANIM_SLOTS * NUM_CORES;
seanhalle@64 121 }
seanhalle@64 122
seanhalle@64 123 int32
seanhalle@64 124 SSR__give_number_of_cores_to_schedule_onto()
seanhalle@64 125 {
seanhalle@64 126 return NUM_CORES;
seanhalle@64 127 }
seanhalle@64 128
seanhalle@64 129 /*For now, use TSC -- later, make these two macros with assembly that first
seanhalle@64 130 * saves jump point, and second jumps back several times to get reliable time
seanhalle@64 131 */
seanhalle@64 132 void
seanhalle@64 133 SSR__start_primitive()
seanhalle@64 134 { saveLowTimeStampCountInto( ((SSRSemEnv *)(_VMSMasterEnv->semanticEnv))->
seanhalle@64 135 primitiveStartTime );
seanhalle@64 136 }
seanhalle@64 137
seanhalle@64 138 /*Just quick and dirty for now -- make reliable later
seanhalle@64 139 * will want this to jump back several times -- to be sure cache is warm
seanhalle@64 140 * because don't want comm time included in calc-time measurement -- and
seanhalle@64 141 * also to throw out any "weird" values due to OS interrupt or TSC rollover
seanhalle@64 142 */
seanhalle@64 143 int32
seanhalle@64 144 SSR__end_primitive_and_give_cycles()
seanhalle@64 145 { int32 endTime, startTime;
seanhalle@64 146 //TODO: fix by repeating time-measurement
seanhalle@64 147 saveLowTimeStampCountInto( endTime );
seanhalle@64 148 startTime =((SSRSemEnv*)(_VMSMasterEnv->semanticEnv))->primitiveStartTime;
seanhalle@64 149 return (endTime - startTime);
seanhalle@64 150 }
seanhalle@64 151
seanhalle@64 152 //===========================================================================
seanhalle@64 153
seanhalle@64 154 /*Initializes all the data-structures for a SSR system -- but doesn't
seanhalle@64 155 * start it running yet!
seanhalle@64 156 *
seanhalle@64 157 *This runs in the main thread -- before VMS starts up
seanhalle@64 158 *
seanhalle@64 159 *This sets up the semantic layer over the VMS system
seanhalle@64 160 *
seanhalle@64 161 *First, calls VMS_Setup, then creates own environment, making it ready
seanhalle@64 162 * for creating the seed processor and then starting the work.
seanhalle@64 163 */
seanhalle@64 164 void
seanhalle@64 165 SSR__init()
seanhalle@64 166 {
seanhalle@64 167 VMS_SS__init();
seanhalle@64 168 //masterEnv, a global var, now is partially set up by init_VMS
seanhalle@64 169 // after this, have VMS_int__malloc and VMS_int__free available
seanhalle@64 170
seanhalle@64 171 SSR__init_Helper();
seanhalle@64 172 }
seanhalle@64 173
seanhalle@64 174
seanhalle@64 175 void idle_fn(void* data, SlaveVP *animatingSlv){
seanhalle@64 176 while(1){
seanhalle@64 177 VMS_int__suspend_slaveVP_and_send_req(animatingSlv);
seanhalle@64 178 }
seanhalle@64 179 }
seanhalle@64 180
seanhalle@64 181 void
seanhalle@64 182 SSR__init_Helper()
seanhalle@64 183 { SSRSemEnv *semanticEnv;
seanhalle@64 184 PrivQueueStruc **readyVPQs;
seanhalle@64 185 int coreIdx, i, j;
seanhalle@64 186
seanhalle@64 187 //Hook up the semantic layer's plug-ins to the Master virt procr
seanhalle@64 188 _VMSMasterEnv->requestHandler = &SSR__Request_Handler;
seanhalle@67 189 _VMSMasterEnv->slaveAssigner = &SSR__assign_slaveVP_to_slot;
seanhalle@64 190 #ifdef HOLISTIC__TURN_ON_PERF_COUNTERS
seanhalle@64 191 _VMSMasterEnv->counterHandler = &SSR__counter_handler;
seanhalle@64 192 #endif
seanhalle@64 193
seanhalle@64 194 //create the semantic layer's environment (all its data) and add to
seanhalle@64 195 // the master environment
seanhalle@64 196 semanticEnv = VMS_int__malloc( sizeof( SSRSemEnv ) );
seanhalle@64 197 _VMSMasterEnv->semanticEnv = semanticEnv;
seanhalle@64 198
seanhalle@64 199 #ifdef HOLISTIC__TURN_ON_PERF_COUNTERS
seanhalle@64 200 SSR__init_counter_data_structs();
seanhalle@64 201 #endif
nengel@72 202 #ifdef IDLE_SLAVES
nengel@66 203 semanticEnv->shutdownInitiated = FALSE;
seanhalle@64 204 for(i=0;i<NUM_CORES;++i){
seanhalle@69 205 for(j=0;j<NUM_ANIM_SLOTS;++j){
seanhalle@64 206 semanticEnv->idlePr[i][j] = VMS_int__create_slaveVP(&idle_fn,NULL);
seanhalle@64 207 semanticEnv->idlePr[i][j]->coreAnimatedBy = i;
nengel@72 208 semanticEnv->idlePr[i][j]->typeOfVP = Idle;
seanhalle@64 209 }
seanhalle@64 210 }
nengel@72 211 #endif
seanhalle@64 212 #ifdef HOLISTIC__TURN_ON_OBSERVE_UCC
seanhalle@64 213 semanticEnv->unitList = makeListOfArrays(sizeof(Unit),128);
seanhalle@64 214 semanticEnv->ctlDependenciesList = makeListOfArrays(sizeof(Dependency),128);
seanhalle@64 215 semanticEnv->commDependenciesList = makeListOfArrays(sizeof(Dependency),128);
seanhalle@64 216 semanticEnv->dynDependenciesList = makeListOfArrays(sizeof(Dependency),128);
nengel@74 217 semanticEnv->singletonDependenciesList = makeListOfArrays(sizeof(Dependency),128);
seanhalle@64 218 semanticEnv->ntonGroupsInfo = makePrivDynArrayOfSize((void***)&(semanticEnv->ntonGroups),8);
seanhalle@64 219
seanhalle@64 220 semanticEnv->hwArcs = makeListOfArrays(sizeof(Dependency),128);
seanhalle@69 221 memset(semanticEnv->last_in_slot,0,sizeof(NUM_CORES * NUM_ANIM_SLOTS * sizeof(Unit)));
seanhalle@64 222 #endif
seanhalle@64 223
seanhalle@64 224 //create the ready queue, hash tables used for pairing send to receive
seanhalle@64 225 // and so forth
seanhalle@64 226 //TODO: add hash tables for pairing sends with receives, and
seanhalle@64 227 // initialize the data ownership system
seanhalle@64 228 readyVPQs = VMS_int__malloc( NUM_CORES * sizeof(PrivQueueStruc *) );
seanhalle@64 229
seanhalle@64 230 for( coreIdx = 0; coreIdx < NUM_CORES; coreIdx++ )
seanhalle@64 231 {
seanhalle@64 232 readyVPQs[ coreIdx ] = makeVMSQ();
seanhalle@64 233 }
seanhalle@64 234
seanhalle@64 235 semanticEnv->readyVPQs = readyVPQs;
seanhalle@64 236
seanhalle@64 237 semanticEnv->nextCoreToGetNewPr = 0;
seanhalle@64 238 semanticEnv->numSlaveVP = 0;
seanhalle@64 239
seanhalle@64 240 semanticEnv->commHashTbl = makeHashTable( 1<<16, &VMS_int__free );//start big
seanhalle@64 241
seanhalle@64 242 //TODO: bug -- turn these arrays into dyn arrays to eliminate limit
seanhalle@64 243 //semanticEnv->singletonHasBeenExecutedFlags = makeDynArrayInfo( );
seanhalle@64 244 //semanticEnv->transactionStrucs = makeDynArrayInfo( );
seanhalle@64 245 for( i = 0; i < NUM_STRUCS_IN_SEM_ENV; i++ )
seanhalle@64 246 {
seanhalle@64 247 semanticEnv->fnSingletons[i].endInstrAddr = NULL;
seanhalle@64 248 semanticEnv->fnSingletons[i].hasBeenStarted = FALSE;
seanhalle@64 249 semanticEnv->fnSingletons[i].hasFinished = FALSE;
seanhalle@64 250 semanticEnv->fnSingletons[i].waitQ = makeVMSQ();
seanhalle@64 251 semanticEnv->transactionStrucs[i].waitingVPQ = makeVMSQ();
seanhalle@64 252 }
seanhalle@82 253
seanhalle@82 254 VMSCommNode *
seanhalle@82 255 systemNode = VMS_SS__give_comm_hierarchy(); //this is read only!!
seanhalle@82 256
seanhalle@82 257 //Do something with the comm system here.. make own, faster, data
seanhalle@82 258 // structure that is used by assigner -- it can include info about
seanhalle@82 259 // measured miss rates, and structures that track the data..
seanhalle@82 260 //Next step would be to take a shot at a function call to put into the
seanhalle@82 261 // application that gives a "name" to collection of data consumed by
seanhalle@82 262 // a work-unit, and a name to the data produced.. along with the size
seanhalle@82 263 // each of those named collections.
seanhalle@82 264 //Then, can come up with a way to represent how much of each
seanhalle@82 265 // named data collection that resides in each of the caches. Keep that
seanhalle@82 266 // representation in the data structure that build from parsing the
seanhalle@82 267 // comm system returned from VMS.
seanhalle@64 268 }
seanhalle@64 269
seanhalle@64 270
seanhalle@64 271 /*Frees any memory allocated by SSR__init() then calls VMS_int__shutdown
seanhalle@64 272 */
seanhalle@64 273 void
seanhalle@64 274 SSR__cleanup_after_shutdown()
seanhalle@64 275 { SSRSemEnv *semanticEnv;
seanhalle@64 276
seanhalle@64 277 semanticEnv = _VMSMasterEnv->semanticEnv;
seanhalle@64 278
seanhalle@64 279 #ifdef HOLISTIC__TURN_ON_OBSERVE_UCC
seanhalle@64 280 //UCC
seanhalle@64 281 FILE* output;
seanhalle@64 282 int n;
seanhalle@64 283 char filename[255];
seanhalle@64 284 for(n=0;n<255;n++)
seanhalle@64 285 {
seanhalle@64 286 sprintf(filename, "./counters/UCC.%d",n);
seanhalle@64 287 output = fopen(filename,"r");
seanhalle@64 288 if(output)
seanhalle@64 289 {
seanhalle@64 290 fclose(output);
seanhalle@64 291 }else{
seanhalle@64 292 break;
seanhalle@64 293 }
seanhalle@64 294 }
seanhalle@64 295 if(n<255){
seanhalle@64 296 printf("Saving UCC to File: %s ...\n", filename);
seanhalle@64 297 output = fopen(filename,"w+");
seanhalle@64 298 if(output!=NULL){
seanhalle@64 299 set_dependency_file(output);
seanhalle@64 300 //fprintf(output,"digraph Dependencies {\n");
seanhalle@64 301 //set_dot_file(output);
seanhalle@64 302 //FIXME: first line still depends on counters being enabled, replace w/ unit struct!
seanhalle@64 303 //forAllInDynArrayDo(_VMSMasterEnv->counter_history_array_info, &print_dot_node_info );
seanhalle@64 304 forAllInListOfArraysDo(semanticEnv->unitList, &print_unit_to_file);
seanhalle@64 305 forAllInListOfArraysDo( semanticEnv->commDependenciesList, &print_comm_dependency_to_file );
seanhalle@64 306 forAllInListOfArraysDo( semanticEnv->ctlDependenciesList, &print_ctl_dependency_to_file );
seanhalle@64 307 forAllInDynArrayDo(semanticEnv->ntonGroupsInfo,&print_nton_to_file);
seanhalle@64 308 //fprintf(output,"}\n");
seanhalle@64 309 fflush(output);
seanhalle@64 310
seanhalle@64 311 } else
seanhalle@64 312 printf("Opening UCC file failed. Please check that folder \"counters\" exists in run directory and has write permission.\n");
seanhalle@64 313 } else {
seanhalle@64 314 printf("Could not open UCC file, please clean \"counters\" folder. (Must contain less than 255 files.)\n");
seanhalle@64 315 }
seanhalle@64 316 //Loop Graph
seanhalle@64 317 for(n=0;n<255;n++)
seanhalle@64 318 {
seanhalle@64 319 sprintf(filename, "./counters/LoopGraph.%d",n);
seanhalle@64 320 output = fopen(filename,"r");
seanhalle@64 321 if(output)
seanhalle@64 322 {
seanhalle@64 323 fclose(output);
seanhalle@64 324 }else{
seanhalle@64 325 break;
seanhalle@64 326 }
seanhalle@64 327 }
seanhalle@64 328 if(n<255){
seanhalle@64 329 printf("Saving LoopGraph to File: %s ...\n", filename);
seanhalle@64 330 output = fopen(filename,"w+");
seanhalle@64 331 if(output!=NULL){
seanhalle@64 332 set_dependency_file(output);
seanhalle@64 333 //fprintf(output,"digraph Dependencies {\n");
seanhalle@64 334 //set_dot_file(output);
seanhalle@64 335 //FIXME: first line still depends on counters being enabled, replace w/ unit struct!
seanhalle@64 336 //forAllInDynArrayDo(_VMSMasterEnv->counter_history_array_info, &print_dot_node_info );
seanhalle@64 337 forAllInListOfArraysDo( semanticEnv->unitList, &print_unit_to_file );
seanhalle@64 338 forAllInListOfArraysDo( semanticEnv->commDependenciesList, &print_comm_dependency_to_file );
seanhalle@64 339 forAllInListOfArraysDo( semanticEnv->ctlDependenciesList, &print_ctl_dependency_to_file );
seanhalle@64 340 forAllInListOfArraysDo( semanticEnv->dynDependenciesList, &print_dyn_dependency_to_file );
nengel@74 341 forAllInListOfArraysDo( semanticEnv->singletonDependenciesList, &print_singleton_dependency_to_file );
seanhalle@64 342 forAllInListOfArraysDo( semanticEnv->hwArcs, &print_hw_dependency_to_file );
seanhalle@64 343 //fprintf(output,"}\n");
seanhalle@64 344 fflush(output);
seanhalle@64 345
seanhalle@64 346 } else
seanhalle@64 347 printf("Opening LoopGraph file failed. Please check that folder \"counters\" exists in run directory and has write permission.\n");
seanhalle@64 348 } else {
seanhalle@64 349 printf("Could not open LoopGraph file, please clean \"counters\" folder. (Must contain less than 255 files.)\n");
seanhalle@64 350 }
seanhalle@64 351
seanhalle@64 352
seanhalle@64 353 freeListOfArrays(semanticEnv->unitList);
seanhalle@64 354 freeListOfArrays(semanticEnv->commDependenciesList);
seanhalle@64 355 freeListOfArrays(semanticEnv->ctlDependenciesList);
seanhalle@64 356 freeListOfArrays(semanticEnv->dynDependenciesList);
nengel@74 357 freeListOfArrays(semanticEnv->singletonDependenciesList);
seanhalle@64 358 #endif
seanhalle@64 359 #ifdef HOLISTIC__TURN_ON_PERF_COUNTERS
seanhalle@64 360 for(n=0;n<255;n++)
seanhalle@64 361 {
seanhalle@64 362 sprintf(filename, "./counters/Counters.%d.csv",n);
seanhalle@64 363 output = fopen(filename,"r");
seanhalle@64 364 if(output)
seanhalle@64 365 {
seanhalle@64 366 fclose(output);
seanhalle@64 367 }else{
seanhalle@64 368 break;
seanhalle@64 369 }
seanhalle@64 370 }
seanhalle@64 371 if(n<255){
seanhalle@64 372 printf("Saving Counter measurements to File: %s ...\n", filename);
seanhalle@64 373 output = fopen(filename,"w+");
seanhalle@64 374 if(output!=NULL){
seanhalle@64 375 set_counter_file(output);
seanhalle@64 376 int i;
seanhalle@64 377 for(i=0;i<NUM_CORES;i++){
seanhalle@64 378 forAllInListOfArraysDo( semanticEnv->counterList[i], &print_counter_events_to_file );
seanhalle@64 379 fflush(output);
seanhalle@64 380 }
seanhalle@64 381
seanhalle@64 382 } else
seanhalle@64 383 printf("Opening UCC file failed. Please check that folder \"counters\" exists in run directory and has write permission.\n");
seanhalle@64 384 } else {
seanhalle@64 385 printf("Could not open UCC file, please clean \"counters\" folder. (Must contain less than 255 files.)\n");
seanhalle@64 386 }
seanhalle@64 387
seanhalle@64 388 #endif
seanhalle@64 389 /* It's all allocated inside VMS's big chunk -- that's about to be freed, so
seanhalle@64 390 * nothing to do here
seanhalle@64 391
seanhalle@64 392
seanhalle@64 393 for( coreIdx = 0; coreIdx < NUM_CORES; coreIdx++ )
seanhalle@64 394 {
seanhalle@64 395 VMS_int__free( semanticEnv->readyVPQs[coreIdx]->startOfData );
seanhalle@64 396 VMS_int__free( semanticEnv->readyVPQs[coreIdx] );
seanhalle@64 397 }
seanhalle@64 398 VMS_int__free( semanticEnv->readyVPQs );
seanhalle@64 399
seanhalle@64 400 freeHashTable( semanticEnv->commHashTbl );
seanhalle@64 401 VMS_int__free( _VMSMasterEnv->semanticEnv );
seanhalle@64 402 */
seanhalle@64 403 VMS_SS__cleanup_at_end_of_shutdown();
seanhalle@64 404 }
seanhalle@64 405
seanhalle@64 406
seanhalle@64 407 //===========================================================================
seanhalle@64 408
seanhalle@64 409 /*
seanhalle@64 410 */
seanhalle@64 411 SlaveVP *
seanhalle@64 412 SSR__create_procr_with( TopLevelFnPtr fnPtr, void *initData,
seanhalle@64 413 SlaveVP *creatingPr )
seanhalle@64 414 { SSRSemReq reqData;
seanhalle@64 415
seanhalle@64 416 //the semantic request data is on the stack and disappears when this
seanhalle@64 417 // call returns -- it's guaranteed to remain in the VP's stack for as
seanhalle@64 418 // long as the VP is suspended.
seanhalle@64 419 reqData.reqType = 0; //know type because in a VMS create req
seanhalle@64 420 reqData.coreToAssignOnto = -1; //means round-robin assign
seanhalle@64 421 reqData.fnPtr = fnPtr;
seanhalle@64 422 reqData.initData = initData;
seanhalle@64 423 reqData.sendPr = creatingPr;
seanhalle@64 424
seanhalle@64 425 VMS_WL__send_create_slaveVP_req( &reqData, creatingPr );
seanhalle@64 426
seanhalle@64 427 return creatingPr->dataRetFromReq;
seanhalle@64 428 }
seanhalle@64 429
seanhalle@64 430 SlaveVP *
seanhalle@64 431 SSR__create_procr_with_affinity( TopLevelFnPtr fnPtr, void *initData,
seanhalle@64 432 SlaveVP *creatingPr, int32 coreToAssignOnto )
seanhalle@64 433 { SSRSemReq reqData;
seanhalle@64 434
seanhalle@64 435 //the semantic request data is on the stack and disappears when this
seanhalle@64 436 // call returns -- it's guaranteed to remain in the VP's stack for as
seanhalle@64 437 // long as the VP is suspended.
seanhalle@64 438 reqData.reqType = 0; //know type because in a VMS create req
seanhalle@64 439 reqData.coreToAssignOnto = coreToAssignOnto;
seanhalle@64 440 reqData.fnPtr = fnPtr;
seanhalle@64 441 reqData.initData = initData;
seanhalle@64 442 reqData.sendPr = creatingPr;
seanhalle@64 443
seanhalle@64 444 VMS_WL__send_create_slaveVP_req( &reqData, creatingPr );
seanhalle@64 445
seanhalle@64 446 return creatingPr->dataRetFromReq;
seanhalle@64 447 }
seanhalle@64 448
seanhalle@64 449
seanhalle@64 450 void
seanhalle@64 451 SSR__dissipate_procr( SlaveVP *procrToDissipate )
seanhalle@64 452 {
seanhalle@64 453 VMS_WL__send_dissipate_req( procrToDissipate );
seanhalle@64 454 }
seanhalle@64 455
seanhalle@64 456
seanhalle@64 457 //===========================================================================
seanhalle@64 458
seanhalle@64 459 void *
seanhalle@64 460 SSR__malloc_to( int32 sizeToMalloc, SlaveVP *owningPr )
seanhalle@64 461 { SSRSemReq reqData;
seanhalle@64 462
seanhalle@64 463 reqData.reqType = malloc_req;
seanhalle@64 464 reqData.sendPr = owningPr;
seanhalle@64 465 reqData.sizeToMalloc = sizeToMalloc;
seanhalle@64 466
seanhalle@64 467 VMS_WL__send_sem_request( &reqData, owningPr );
seanhalle@64 468
seanhalle@64 469 return owningPr->dataRetFromReq;
seanhalle@64 470 }
seanhalle@64 471
seanhalle@64 472
seanhalle@64 473 /*Sends request to Master, which does the work of freeing
seanhalle@64 474 */
seanhalle@64 475 void
seanhalle@64 476 SSR__free( void *ptrToFree, SlaveVP *owningPr )
seanhalle@64 477 { SSRSemReq reqData;
seanhalle@64 478
seanhalle@64 479 reqData.reqType = free_req;
seanhalle@64 480 reqData.sendPr = owningPr;
seanhalle@64 481 reqData.ptrToFree = ptrToFree;
seanhalle@64 482
seanhalle@64 483 VMS_WL__send_sem_request( &reqData, owningPr );
seanhalle@64 484 }
seanhalle@64 485
seanhalle@64 486
seanhalle@64 487 void
seanhalle@64 488 SSR__transfer_ownership_of_from_to( void *data, SlaveVP *oldOwnerSlv,
seanhalle@64 489 SlaveVP *newOwnerPr )
seanhalle@64 490 {
seanhalle@64 491 //TODO: put in the ownership system that automatically frees when no
seanhalle@64 492 // owners of data left -- will need keeper for keeping data around when
seanhalle@64 493 // future created processors might need it but don't exist yet
seanhalle@64 494 }
seanhalle@64 495
seanhalle@64 496
seanhalle@64 497 void
seanhalle@64 498 SSR__add_ownership_by_to( SlaveVP *newOwnerSlv, void *data )
seanhalle@64 499 {
seanhalle@64 500
seanhalle@64 501 }
seanhalle@64 502
seanhalle@64 503
seanhalle@64 504 void
seanhalle@64 505 SSR__remove_ownership_by_from( SlaveVP *loserSlv, void *dataLosing )
seanhalle@64 506 {
seanhalle@64 507
seanhalle@64 508 }
seanhalle@64 509
seanhalle@64 510
seanhalle@64 511 /*Causes the SSR system to remove internal ownership, so data won't be
seanhalle@64 512 * freed when SSR shuts down, and will persist in the external program.
seanhalle@64 513 *
seanhalle@64 514 *Must be called from the processor that currently owns the data.
seanhalle@64 515 *
seanhalle@64 516 *IMPL: Transferring ownership touches two different virtual processor's
seanhalle@64 517 * state -- which means it has to be done carefully -- the VMS rules for
seanhalle@64 518 * semantic layers say that a work-unit is only allowed to touch the
seanhalle@64 519 * virtual processor it is part of, and that only a single work-unit per
seanhalle@64 520 * virtual processor be assigned to a slave at a time. So, this has to
seanhalle@64 521 * modify the virtual processor that owns the work-unit that called this
seanhalle@64 522 * function, then create a request to have the other processor modified.
seanhalle@64 523 *However, in this case, the TO processor is the outside, and transfers
seanhalle@64 524 * are only allowed to be called by the giver-upper, so can mark caller of
seanhalle@64 525 * this function as no longer owner, and return -- done.
seanhalle@64 526 */
seanhalle@64 527 void
seanhalle@64 528 SSR__transfer_ownership_to_outside( void *data )
seanhalle@64 529 {
seanhalle@64 530 //TODO: removeAllOwnersFrom( data );
seanhalle@64 531 }
seanhalle@64 532
seanhalle@64 533
seanhalle@64 534 //===========================================================================
seanhalle@64 535
seanhalle@64 536 void
seanhalle@64 537 SSR__send_of_type_to( SlaveVP *sendPr, void *msg, const int type,
seanhalle@64 538 SlaveVP *receivePr)
seanhalle@64 539 { SSRSemReq reqData;
seanhalle@64 540
seanhalle@64 541 reqData.receivePr = receivePr;
seanhalle@64 542 reqData.sendPr = sendPr;
seanhalle@64 543 reqData.reqType = send_type;
seanhalle@64 544 reqData.msgType = type;
seanhalle@64 545 reqData.msg = msg;
seanhalle@64 546 reqData.nextReqInHashEntry = NULL;
seanhalle@64 547
seanhalle@64 548 //On ownership -- remove inside the send and let ownership sit in limbo
seanhalle@64 549 // as a potential in an entry in the hash table, when this receive msg
seanhalle@64 550 // gets paired to a send, the ownership gets added to the receivePr --
seanhalle@64 551 // the next work-unit in the receivePr's trace will have ownership.
seanhalle@64 552 VMS_WL__send_sem_request( &reqData, sendPr );
seanhalle@64 553
seanhalle@64 554 //When come back from suspend, no longer own data reachable from msg
seanhalle@64 555 //TODO: release ownership here
seanhalle@64 556 }
seanhalle@64 557
seanhalle@64 558 void
seanhalle@64 559 SSR__send_from_to( void *msg, SlaveVP *sendPr, SlaveVP *receivePr )
seanhalle@64 560 { SSRSemReq reqData;
seanhalle@64 561
seanhalle@64 562 //hash on the receiver, 'cause always know it, but sometimes want to
seanhalle@64 563 // receive from anonymous sender
seanhalle@64 564
seanhalle@64 565 reqData.receivePr = receivePr;
seanhalle@64 566 reqData.sendPr = sendPr;
seanhalle@64 567 reqData.reqType = send_from_to;
seanhalle@64 568 reqData.msg = msg;
seanhalle@64 569 reqData.nextReqInHashEntry = NULL;
seanhalle@64 570
seanhalle@64 571 VMS_WL__send_sem_request( &reqData, sendPr );
seanhalle@64 572 }
seanhalle@64 573
seanhalle@64 574
seanhalle@64 575 //===========================================================================
seanhalle@64 576
seanhalle@64 577 void *
seanhalle@64 578 SSR__receive_any_to( SlaveVP *receivePr )
seanhalle@64 579 {
seanhalle@64 580
seanhalle@64 581 }
seanhalle@64 582
seanhalle@64 583 void *
seanhalle@64 584 SSR__receive_type_to( const int type, SlaveVP *receivePr )
seanhalle@67 585 { DEBUG__printf1(dbgRqstHdlr,"WL: receive type to: %d", receivePr->slaveID);
seanhalle@64 586 SSRSemReq reqData;
seanhalle@64 587
seanhalle@64 588 reqData.receivePr = receivePr;
seanhalle@64 589 reqData.reqType = receive_type;
seanhalle@64 590 reqData.msgType = type;
seanhalle@64 591 reqData.nextReqInHashEntry = NULL;
seanhalle@64 592
seanhalle@64 593 VMS_WL__send_sem_request( &reqData, receivePr );
seanhalle@64 594
seanhalle@64 595 return receivePr->dataRetFromReq;
seanhalle@64 596 }
seanhalle@64 597
seanhalle@64 598
seanhalle@64 599
seanhalle@64 600 /*Call this at point receiving virt pr wants in-coming data.
seanhalle@64 601 *
seanhalle@64 602 *The reason receivePr must call this is that it modifies the receivPr
seanhalle@64 603 * loc structure directly -- and the VMS rules state a virtual processor
seanhalle@64 604 * loc structure can only be modified by itself.
seanhalle@64 605 */
seanhalle@64 606 void *
seanhalle@64 607 SSR__receive_from_to( SlaveVP *sendPr, SlaveVP *receivePr )
seanhalle@67 608 { DEBUG__printf2(dbgRqstHdlr,"WL: receive from %d to: %d", sendPr->slaveID, receivePr->slaveID);
seanhalle@67 609 SSRSemReq reqData;
seanhalle@64 610
seanhalle@64 611 //hash on the receiver, 'cause always know it, but sometimes want to
seanhalle@64 612 // receive from anonymous sender
seanhalle@64 613
seanhalle@64 614 reqData.receivePr = receivePr;
seanhalle@64 615 reqData.sendPr = sendPr;
seanhalle@64 616 reqData.reqType = receive_from_to;
seanhalle@64 617 reqData.nextReqInHashEntry = NULL;
seanhalle@64 618
seanhalle@64 619 VMS_WL__send_sem_request( &reqData, receivePr );
seanhalle@64 620
seanhalle@64 621 return receivePr->dataRetFromReq;
seanhalle@64 622 }
seanhalle@64 623
seanhalle@64 624
seanhalle@64 625 //===========================================================================
seanhalle@64 626 //
seanhalle@64 627 /*A function singleton is a function whose body executes exactly once, on a
seanhalle@64 628 * single core, no matter how many times the fuction is called and no
seanhalle@64 629 * matter how many cores or the timing of cores calling it.
seanhalle@64 630 *
seanhalle@64 631 *A data singleton is a ticket attached to data. That ticket can be used
seanhalle@64 632 * to get the data through the function exactly once, no matter how many
seanhalle@64 633 * times the data is given to the function, and no matter the timing of
seanhalle@64 634 * trying to get the data through from different cores.
seanhalle@64 635 */
seanhalle@64 636
seanhalle@64 637 /*asm function declarations*/
seanhalle@64 638 void asm_save_ret_to_singleton(SSRSingleton *singletonPtrAddr);
seanhalle@64 639 void asm_write_ret_from_singleton(SSRSingleton *singletonPtrAddr);
seanhalle@64 640
seanhalle@64 641 /*Fn singleton uses ID as index into array of singleton structs held in the
seanhalle@64 642 * semantic environment.
seanhalle@64 643 */
seanhalle@64 644 void
seanhalle@64 645 SSR__start_fn_singleton( int32 singletonID, SlaveVP *animPr )
seanhalle@64 646 {
seanhalle@64 647 SSRSemReq reqData;
seanhalle@64 648
seanhalle@64 649 //
seanhalle@64 650 reqData.reqType = singleton_fn_start;
seanhalle@64 651 reqData.singletonID = singletonID;
seanhalle@64 652
seanhalle@64 653 VMS_WL__send_sem_request( &reqData, animPr );
seanhalle@64 654 if( animPr->dataRetFromReq ) //will be 0 or addr of label in end singleton
seanhalle@64 655 {
seanhalle@64 656 SSRSemEnv *semEnv = VMS_int__give_sem_env_for( animPr );
seanhalle@64 657 asm_write_ret_from_singleton(&(semEnv->fnSingletons[ singletonID]));
seanhalle@64 658 }
seanhalle@64 659 }
seanhalle@64 660
seanhalle@64 661 /*Data singleton hands addr of loc holding a pointer to a singleton struct.
seanhalle@64 662 * The start_data_singleton makes the structure and puts its addr into the
seanhalle@64 663 * location.
seanhalle@64 664 */
seanhalle@64 665 void
seanhalle@64 666 SSR__start_data_singleton( SSRSingleton **singletonAddr, SlaveVP *animPr )
seanhalle@64 667 {
seanhalle@64 668 SSRSemReq reqData;
seanhalle@64 669
seanhalle@64 670 if( *singletonAddr && (*singletonAddr)->hasFinished )
seanhalle@64 671 goto JmpToEndSingleton;
seanhalle@64 672
seanhalle@64 673 reqData.reqType = singleton_data_start;
seanhalle@64 674 reqData.singletonPtrAddr = singletonAddr;
seanhalle@64 675
seanhalle@64 676 VMS_WL__send_sem_request( &reqData, animPr );
seanhalle@64 677 if( animPr->dataRetFromReq ) //either 0 or end singleton's return addr
seanhalle@64 678 { //Assembly code changes the return addr on the stack to the one
seanhalle@64 679 // saved into the singleton by the end-singleton-fn
seanhalle@64 680 //The return addr is at 0x4(%%ebp)
seanhalle@64 681 JmpToEndSingleton:
seanhalle@64 682 asm_write_ret_from_singleton(*singletonAddr);
seanhalle@64 683 }
seanhalle@64 684 //now, simply return
seanhalle@64 685 //will exit either from the start singleton call or the end-singleton call
seanhalle@64 686 }
seanhalle@64 687
seanhalle@64 688 /*Uses ID as index into array of flags. If flag already set, resumes from
seanhalle@64 689 * end-label. Else, sets flag and resumes normally.
seanhalle@64 690 *
seanhalle@64 691 *Note, this call cannot be inlined because the instr addr at the label
seanhalle@64 692 * inside is shared by all invocations of a given singleton ID.
seanhalle@64 693 */
seanhalle@64 694 void
seanhalle@64 695 SSR__end_fn_singleton( int32 singletonID, SlaveVP *animPr )
seanhalle@64 696 {
seanhalle@64 697 SSRSemReq reqData;
seanhalle@64 698
seanhalle@64 699 //don't need this addr until after at least one singleton has reached
seanhalle@64 700 // this function
seanhalle@64 701 SSRSemEnv *semEnv = VMS_int__give_sem_env_for( animPr );
seanhalle@64 702 asm_write_ret_from_singleton(&(semEnv->fnSingletons[ singletonID]));
seanhalle@64 703
seanhalle@64 704 reqData.reqType = singleton_fn_end;
seanhalle@64 705 reqData.singletonID = singletonID;
seanhalle@64 706
seanhalle@64 707 VMS_WL__send_sem_request( &reqData, animPr );
seanhalle@64 708
seanhalle@64 709 EndSingletonInstrAddr:
seanhalle@64 710 return;
seanhalle@64 711 }
seanhalle@64 712
seanhalle@64 713 void
seanhalle@64 714 SSR__end_data_singleton( SSRSingleton **singletonPtrAddr, SlaveVP *animPr )
seanhalle@64 715 {
seanhalle@64 716 SSRSemReq reqData;
seanhalle@64 717
seanhalle@64 718 //don't need this addr until after singleton struct has reached
seanhalle@64 719 // this function for first time
seanhalle@64 720 //do assembly that saves the return addr of this fn call into the
seanhalle@64 721 // data singleton -- that data-singleton can only be given to exactly
seanhalle@64 722 // one instance in the code of this function. However, can use this
seanhalle@64 723 // function in different places for different data-singletons.
seanhalle@64 724 // (*(singletonAddr))->endInstrAddr = &&EndDataSingletonInstrAddr;
seanhalle@64 725
seanhalle@64 726
seanhalle@64 727 asm_save_ret_to_singleton(*singletonPtrAddr);
seanhalle@64 728
seanhalle@64 729 reqData.reqType = singleton_data_end;
seanhalle@64 730 reqData.singletonPtrAddr = singletonPtrAddr;
seanhalle@64 731
seanhalle@64 732 VMS_WL__send_sem_request( &reqData, animPr );
seanhalle@64 733 }
seanhalle@64 734
seanhalle@64 735 /*This executes the function in the masterVP, so it executes in isolation
seanhalle@64 736 * from any other copies -- only one copy of the function can ever execute
seanhalle@64 737 * at a time.
seanhalle@64 738 *
seanhalle@64 739 *It suspends to the master, and the request handler takes the function
seanhalle@64 740 * pointer out of the request and calls it, then resumes the VP.
seanhalle@64 741 *Only very short functions should be called this way -- for longer-running
seanhalle@64 742 * isolation, use transaction-start and transaction-end, which run the code
seanhalle@64 743 * between as work-code.
seanhalle@64 744 */
seanhalle@64 745 void
seanhalle@64 746 SSR__animate_short_fn_in_isolation( PtrToAtomicFn ptrToFnToExecInMaster,
seanhalle@64 747 void *data, SlaveVP *animPr )
seanhalle@64 748 {
seanhalle@64 749 SSRSemReq reqData;
seanhalle@64 750
seanhalle@64 751 //
seanhalle@64 752 reqData.reqType = atomic;
seanhalle@64 753 reqData.fnToExecInMaster = ptrToFnToExecInMaster;
seanhalle@64 754 reqData.dataForFn = data;
seanhalle@64 755
seanhalle@64 756 VMS_WL__send_sem_request( &reqData, animPr );
seanhalle@64 757 }
seanhalle@64 758
seanhalle@64 759
seanhalle@64 760 /*This suspends to the master.
seanhalle@64 761 *First, it looks at the VP's data, to see the highest transactionID that VP
seanhalle@64 762 * already has entered. If the current ID is not larger, it throws an
seanhalle@64 763 * exception stating a bug in the code. Otherwise it puts the current ID
seanhalle@64 764 * there, and adds the ID to a linked list of IDs entered -- the list is
seanhalle@64 765 * used to check that exits are properly ordered.
seanhalle@64 766 *Next it is uses transactionID as index into an array of transaction
seanhalle@64 767 * structures.
seanhalle@64 768 *If the "VP_currently_executing" field is non-null, then put requesting VP
seanhalle@64 769 * into queue in the struct. (At some point a holder will request
seanhalle@64 770 * end-transaction, which will take this VP from the queue and resume it.)
seanhalle@64 771 *If NULL, then write requesting into the field and resume.
seanhalle@64 772 */
seanhalle@64 773 void
seanhalle@64 774 SSR__start_transaction( int32 transactionID, SlaveVP *animPr )
seanhalle@64 775 {
seanhalle@64 776 SSRSemReq reqData;
seanhalle@64 777
seanhalle@64 778 //
seanhalle@64 779 reqData.sendPr = animPr;
seanhalle@64 780 reqData.reqType = trans_start;
seanhalle@64 781 reqData.transID = transactionID;
seanhalle@64 782
seanhalle@64 783 VMS_WL__send_sem_request( &reqData, animPr );
seanhalle@64 784 }
seanhalle@64 785
seanhalle@64 786 /*This suspends to the master, then uses transactionID as index into an
seanhalle@64 787 * array of transaction structures.
seanhalle@64 788 *It looks at VP_currently_executing to be sure it's same as requesting VP.
seanhalle@64 789 * If different, throws an exception, stating there's a bug in the code.
seanhalle@64 790 *Next it looks at the queue in the structure.
seanhalle@64 791 *If it's empty, it sets VP_currently_executing field to NULL and resumes.
seanhalle@64 792 *If something in, gets it, sets VP_currently_executing to that VP, then
seanhalle@64 793 * resumes both.
seanhalle@64 794 */
seanhalle@64 795 void
seanhalle@64 796 SSR__end_transaction( int32 transactionID, SlaveVP *animPr )
seanhalle@64 797 {
seanhalle@64 798 SSRSemReq reqData;
seanhalle@64 799
seanhalle@64 800 //
seanhalle@64 801 reqData.sendPr = animPr;
seanhalle@64 802 reqData.reqType = trans_end;
seanhalle@64 803 reqData.transID = transactionID;
seanhalle@64 804
seanhalle@64 805 VMS_WL__send_sem_request( &reqData, animPr );
seanhalle@64 806 }