annotate VSs.c @ 3:468b8638ff92

Works -- first working version, includes slave pruning and shutdown detection
author Sean Halle <seanhalle@yahoo.com>
date Wed, 06 Jun 2012 17:55:36 -0700
parents f2ed1c379fe7
children 13af59ed7ea5
rev   line source
seanhalle@0 1 /*
seanhalle@0 2 * Copyright 2010 OpenSourceCodeStewardshipFoundation
seanhalle@0 3 *
seanhalle@0 4 * Licensed under BSD
seanhalle@0 5 */
seanhalle@0 6
seanhalle@0 7 #include <stdio.h>
seanhalle@0 8 #include <stdlib.h>
seanhalle@0 9 #include <malloc.h>
seanhalle@0 10
seanhalle@0 11 #include "Queue_impl/PrivateQueue.h"
seanhalle@0 12 #include "Hash_impl/PrivateHash.h"
seanhalle@0 13
seanhalle@2 14 #include "VSs.h"
seanhalle@3 15 #include "Measurement/VSs_Counter_Recording.h"
seanhalle@0 16
seanhalle@0 17 //==========================================================================
seanhalle@0 18
seanhalle@0 19 void
seanhalle@2 20 VSs__init();
seanhalle@0 21
seanhalle@0 22 void
seanhalle@2 23 VSs__init_Helper();
seanhalle@0 24 //==========================================================================
seanhalle@0 25
seanhalle@0 26
seanhalle@0 27
seanhalle@0 28 //===========================================================================
seanhalle@0 29
seanhalle@0 30
seanhalle@0 31 /*These are the library functions *called in the application*
seanhalle@0 32 *
seanhalle@0 33 *There's a pattern for the outside sequential code to interact with the
seanhalle@0 34 * VMS_HW code.
seanhalle@2 35 *The VMS_HW system is inside a boundary.. every VSs system is in its
seanhalle@0 36 * own directory that contains the functions for each of the processor types.
seanhalle@0 37 * One of the processor types is the "seed" processor that starts the
seanhalle@0 38 * cascade of creating all the processors that do the work.
seanhalle@0 39 *So, in the directory is a file called "EntryPoint.c" that contains the
seanhalle@0 40 * function, named appropriately to the work performed, that the outside
seanhalle@0 41 * sequential code calls. This function follows a pattern:
seanhalle@2 42 *1) it calls VSs__init()
seanhalle@0 43 *2) it creates the initial data for the seed processor, which is passed
seanhalle@0 44 * in to the function
seanhalle@2 45 *3) it creates the seed VSs processor, with the data to start it with.
seanhalle@2 46 *4) it calls startVSsThenWaitUntilWorkDone
seanhalle@0 47 *5) it gets the returnValue from the transfer struc and returns that
seanhalle@0 48 * from the function
seanhalle@0 49 *
seanhalle@2 50 *For now, a new VSs system has to be created via VSs__init every
seanhalle@0 51 * time an entry point function is called -- later, might add letting the
seanhalle@2 52 * VSs system be created once, and let all the entry points just reuse
seanhalle@0 53 * it -- want to be as simple as possible now, and see by using what makes
seanhalle@0 54 * sense for later..
seanhalle@0 55 */
seanhalle@0 56
seanhalle@0 57
seanhalle@0 58
seanhalle@0 59 //===========================================================================
seanhalle@0 60
seanhalle@0 61 /*This is the "border crossing" function -- the thing that crosses from the
seanhalle@0 62 * outside world, into the VMS_HW world. It initializes and starts up the
seanhalle@0 63 * VMS system, then creates one processor from the specified function and
seanhalle@0 64 * puts it into the readyQ. From that point, that one function is resp.
seanhalle@0 65 * for creating all the other processors, that then create others, and so
seanhalle@0 66 * forth.
seanhalle@0 67 *When all the processors, including the seed, have dissipated, then this
seanhalle@0 68 * function returns. The results will have been written by side-effect via
seanhalle@0 69 * pointers read from, or written into initData.
seanhalle@0 70 *
seanhalle@0 71 *NOTE: no Threads should exist in the outside program that might touch
seanhalle@0 72 * any of the data reachable from initData passed in to here
seanhalle@0 73 */
seanhalle@0 74 void
seanhalle@2 75 VSs__create_seed_slave_and_do_work( TopLevelFnPtr fnPtr, void *initData )
seanhalle@2 76 { VSsSemEnv *semEnv;
seanhalle@3 77 SlaveVP *seedSlv;
seanhalle@0 78
seanhalle@2 79 VSs__init(); //normal multi-thd
seanhalle@0 80
seanhalle@0 81 semEnv = _VMSMasterEnv->semanticEnv;
seanhalle@0 82
seanhalle@2 83 //VSs starts with one processor, which is put into initial environ,
seanhalle@0 84 // and which then calls create() to create more, thereby expanding work
seanhalle@3 85 seedSlv = VSs__create_slave_helper( fnPtr, initData,
seanhalle@3 86 semEnv, semEnv->nextCoreToGetNewSlv++ );
seanhalle@3 87
seanhalle@3 88 //seedVP doesn't do tasks
seanhalle@3 89 ((VSsSemData *)seedSlv->semanticData)->needsTaskAssigned = FALSE;
seanhalle@0 90
seanhalle@3 91 resume_slaveVP( seedSlv, semEnv );
seanhalle@0 92
seanhalle@0 93 VMS_SS__start_the_work_then_wait_until_done(); //normal multi-thd
seanhalle@0 94
seanhalle@2 95 VSs__cleanup_after_shutdown();
seanhalle@0 96 }
seanhalle@0 97
seanhalle@0 98
seanhalle@0 99 int32
seanhalle@2 100 VSs__giveMinWorkUnitCycles( float32 percentOverhead )
seanhalle@0 101 {
seanhalle@0 102 return MIN_WORK_UNIT_CYCLES;
seanhalle@0 103 }
seanhalle@0 104
seanhalle@0 105 int32
seanhalle@2 106 VSs__giveIdealNumWorkUnits()
seanhalle@0 107 {
seanhalle@0 108 return NUM_ANIM_SLOTS * NUM_CORES;
seanhalle@0 109 }
seanhalle@0 110
seanhalle@0 111 int32
seanhalle@2 112 VSs__give_number_of_cores_to_schedule_onto()
seanhalle@0 113 {
seanhalle@0 114 return NUM_CORES;
seanhalle@0 115 }
seanhalle@0 116
seanhalle@0 117 /*For now, use TSC -- later, make these two macros with assembly that first
seanhalle@0 118 * saves jump point, and second jumps back several times to get reliable time
seanhalle@0 119 */
seanhalle@0 120 void
seanhalle@2 121 VSs__start_primitive()
seanhalle@2 122 { saveLowTimeStampCountInto( ((VSsSemEnv *)(_VMSMasterEnv->semanticEnv))->
seanhalle@0 123 primitiveStartTime );
seanhalle@0 124 }
seanhalle@0 125
seanhalle@0 126 /*Just quick and dirty for now -- make reliable later
seanhalle@0 127 * will want this to jump back several times -- to be sure cache is warm
seanhalle@0 128 * because don't want comm time included in calc-time measurement -- and
seanhalle@0 129 * also to throw out any "weird" values due to OS interrupt or TSC rollover
seanhalle@0 130 */
seanhalle@0 131 int32
seanhalle@2 132 VSs__end_primitive_and_give_cycles()
seanhalle@0 133 { int32 endTime, startTime;
seanhalle@0 134 //TODO: fix by repeating time-measurement
seanhalle@0 135 saveLowTimeStampCountInto( endTime );
seanhalle@2 136 startTime =((VSsSemEnv*)(_VMSMasterEnv->semanticEnv))->primitiveStartTime;
seanhalle@0 137 return (endTime - startTime);
seanhalle@0 138 }
seanhalle@0 139
seanhalle@0 140 //===========================================================================
seanhalle@0 141
seanhalle@2 142 /*Initializes all the data-structures for a VSs system -- but doesn't
seanhalle@0 143 * start it running yet!
seanhalle@0 144 *
seanhalle@0 145 *This runs in the main thread -- before VMS starts up
seanhalle@0 146 *
seanhalle@0 147 *This sets up the semantic layer over the VMS system
seanhalle@0 148 *
seanhalle@0 149 *First, calls VMS_Setup, then creates own environment, making it ready
seanhalle@0 150 * for creating the seed processor and then starting the work.
seanhalle@0 151 */
seanhalle@0 152 void
seanhalle@2 153 VSs__init()
seanhalle@0 154 {
seanhalle@0 155 VMS_SS__init();
seanhalle@0 156 //masterEnv, a global var, now is partially set up by init_VMS
seanhalle@0 157 // after this, have VMS_int__malloc and VMS_int__free available
seanhalle@0 158
seanhalle@2 159 VSs__init_Helper();
seanhalle@0 160 }
seanhalle@0 161
seanhalle@0 162
seanhalle@0 163 void idle_fn(void* data, SlaveVP *animatingSlv){
seanhalle@0 164 while(1){
seanhalle@0 165 VMS_int__suspend_slaveVP_and_send_req(animatingSlv);
seanhalle@0 166 }
seanhalle@0 167 }
seanhalle@0 168
seanhalle@0 169 void
seanhalle@2 170 VSs__init_Helper()
seanhalle@2 171 { VSsSemEnv *semanticEnv;
seanhalle@0 172 PrivQueueStruc **readyVPQs;
seanhalle@0 173 int coreIdx, i, j;
seanhalle@0 174
seanhalle@0 175 //Hook up the semantic layer's plug-ins to the Master virt procr
seanhalle@2 176 _VMSMasterEnv->requestHandler = &VSs__Request_Handler;
seanhalle@2 177 _VMSMasterEnv->slaveAssigner = &VSs__assign_slaveVP_to_slot;
seanhalle@0 178 #ifdef HOLISTIC__TURN_ON_PERF_COUNTERS
seanhalle@2 179 _VMSMasterEnv->counterHandler = &VSs__counter_handler;
seanhalle@0 180 #endif
seanhalle@0 181
seanhalle@0 182 //create the semantic layer's environment (all its data) and add to
seanhalle@0 183 // the master environment
seanhalle@2 184 semanticEnv = VMS_int__malloc( sizeof( VSsSemEnv ) );
seanhalle@0 185 _VMSMasterEnv->semanticEnv = semanticEnv;
seanhalle@0 186
seanhalle@0 187 #ifdef HOLISTIC__TURN_ON_PERF_COUNTERS
seanhalle@2 188 VSs__init_counter_data_structs();
seanhalle@0 189 #endif
seanhalle@3 190
seanhalle@0 191 semanticEnv->shutdownInitiated = FALSE;
seanhalle@3 192 semanticEnv->coreIsDone = VMS_int__malloc( NUM_CORES * sizeof( bool32 ) );
seanhalle@3 193 for( i = 0; i < NUM_CORES; ++i )
seanhalle@3 194 { semanticEnv->coreIsDone[i] = FALSE;
seanhalle@3 195 for( j = 0; j < NUM_ANIM_SLOTS; ++j )
seanhalle@3 196 {
seanhalle@3 197 semanticEnv->idleSlv[i][j] = VMS_int__create_slaveVP(&idle_fn,NULL);
seanhalle@3 198 semanticEnv->idleSlv[i][j]->coreAnimatedBy = i;
seanhalle@0 199 }
seanhalle@3 200 }
seanhalle@0 201
seanhalle@0 202 #ifdef HOLISTIC__TURN_ON_OBSERVE_UCC
seanhalle@0 203 semanticEnv->unitList = makeListOfArrays(sizeof(Unit),128);
seanhalle@0 204 semanticEnv->ctlDependenciesList = makeListOfArrays(sizeof(Dependency),128);
seanhalle@0 205 semanticEnv->commDependenciesList = makeListOfArrays(sizeof(Dependency),128);
seanhalle@0 206 semanticEnv->dynDependenciesList = makeListOfArrays(sizeof(Dependency),128);
seanhalle@0 207 semanticEnv->ntonGroupsInfo = makePrivDynArrayOfSize((void***)&(semanticEnv->ntonGroups),8);
seanhalle@0 208
seanhalle@0 209 semanticEnv->hwArcs = makeListOfArrays(sizeof(Dependency),128);
seanhalle@0 210 memset(semanticEnv->last_in_slot,0,sizeof(NUM_CORES * NUM_ANIM_SLOTS * sizeof(Unit)));
seanhalle@0 211 #endif
seanhalle@0 212
seanhalle@3 213 //create the ready queue, hash tables used for matching and so forth
seanhalle@0 214 readyVPQs = VMS_int__malloc( NUM_CORES * sizeof(PrivQueueStruc *) );
seanhalle@0 215
seanhalle@0 216 for( coreIdx = 0; coreIdx < NUM_CORES; coreIdx++ )
seanhalle@0 217 {
seanhalle@0 218 readyVPQs[ coreIdx ] = makeVMSQ();
seanhalle@0 219 }
seanhalle@0 220
seanhalle@0 221 semanticEnv->readyVPQs = readyVPQs;
seanhalle@0 222
seanhalle@3 223 semanticEnv->taskReadyQ = makeVMSQ();
seanhalle@3 224
seanhalle@3 225 semanticEnv->nextCoreToGetNewSlv = 0;
seanhalle@0 226 semanticEnv->numSlaveVP = 0;
seanhalle@0 227
seanhalle@3 228 semanticEnv->argPtrHashTbl = makeHashTable32( 16, &VMS_int__free );
seanhalle@0 229
seanhalle@0 230 //TODO: bug -- turn these arrays into dyn arrays to eliminate limit
seanhalle@0 231 //semanticEnv->singletonHasBeenExecutedFlags = makeDynArrayInfo( );
seanhalle@0 232 //semanticEnv->transactionStrucs = makeDynArrayInfo( );
seanhalle@0 233 for( i = 0; i < NUM_STRUCS_IN_SEM_ENV; i++ )
seanhalle@0 234 {
seanhalle@0 235 semanticEnv->fnSingletons[i].endInstrAddr = NULL;
seanhalle@0 236 semanticEnv->fnSingletons[i].hasBeenStarted = FALSE;
seanhalle@0 237 semanticEnv->fnSingletons[i].hasFinished = FALSE;
seanhalle@0 238 semanticEnv->fnSingletons[i].waitQ = makeVMSQ();
seanhalle@0 239 semanticEnv->transactionStrucs[i].waitingVPQ = makeVMSQ();
seanhalle@0 240 }
seanhalle@0 241 }
seanhalle@0 242
seanhalle@0 243
seanhalle@2 244 /*Frees any memory allocated by VSs__init() then calls VMS_int__shutdown
seanhalle@0 245 */
seanhalle@0 246 void
seanhalle@2 247 VSs__cleanup_after_shutdown()
seanhalle@2 248 { VSsSemEnv *semanticEnv;
seanhalle@0 249
seanhalle@0 250 semanticEnv = _VMSMasterEnv->semanticEnv;
seanhalle@0 251
seanhalle@0 252 #ifdef HOLISTIC__TURN_ON_OBSERVE_UCC
seanhalle@0 253 //UCC
seanhalle@0 254 FILE* output;
seanhalle@0 255 int n;
seanhalle@0 256 char filename[255];
seanhalle@0 257 for(n=0;n<255;n++)
seanhalle@0 258 {
seanhalle@0 259 sprintf(filename, "./counters/UCC.%d",n);
seanhalle@0 260 output = fopen(filename,"r");
seanhalle@0 261 if(output)
seanhalle@0 262 {
seanhalle@0 263 fclose(output);
seanhalle@0 264 }else{
seanhalle@0 265 break;
seanhalle@0 266 }
seanhalle@0 267 }
seanhalle@0 268 if(n<255){
seanhalle@0 269 printf("Saving UCC to File: %s ...\n", filename);
seanhalle@0 270 output = fopen(filename,"w+");
seanhalle@0 271 if(output!=NULL){
seanhalle@0 272 set_dependency_file(output);
seanhalle@0 273 //fprintf(output,"digraph Dependencies {\n");
seanhalle@0 274 //set_dot_file(output);
seanhalle@0 275 //FIXME: first line still depends on counters being enabled, replace w/ unit struct!
seanhalle@0 276 //forAllInDynArrayDo(_VMSMasterEnv->counter_history_array_info, &print_dot_node_info );
seanhalle@0 277 forAllInListOfArraysDo(semanticEnv->unitList, &print_unit_to_file);
seanhalle@0 278 forAllInListOfArraysDo( semanticEnv->commDependenciesList, &print_comm_dependency_to_file );
seanhalle@0 279 forAllInListOfArraysDo( semanticEnv->ctlDependenciesList, &print_ctl_dependency_to_file );
seanhalle@0 280 forAllInDynArrayDo(semanticEnv->ntonGroupsInfo,&print_nton_to_file);
seanhalle@0 281 //fprintf(output,"}\n");
seanhalle@0 282 fflush(output);
seanhalle@0 283
seanhalle@0 284 } else
seanhalle@0 285 printf("Opening UCC file failed. Please check that folder \"counters\" exists in run directory and has write permission.\n");
seanhalle@0 286 } else {
seanhalle@0 287 printf("Could not open UCC file, please clean \"counters\" folder. (Must contain less than 255 files.)\n");
seanhalle@0 288 }
seanhalle@0 289 //Loop Graph
seanhalle@0 290 for(n=0;n<255;n++)
seanhalle@0 291 {
seanhalle@0 292 sprintf(filename, "./counters/LoopGraph.%d",n);
seanhalle@0 293 output = fopen(filename,"r");
seanhalle@0 294 if(output)
seanhalle@0 295 {
seanhalle@0 296 fclose(output);
seanhalle@0 297 }else{
seanhalle@0 298 break;
seanhalle@0 299 }
seanhalle@0 300 }
seanhalle@0 301 if(n<255){
seanhalle@0 302 printf("Saving LoopGraph to File: %s ...\n", filename);
seanhalle@0 303 output = fopen(filename,"w+");
seanhalle@0 304 if(output!=NULL){
seanhalle@0 305 set_dependency_file(output);
seanhalle@0 306 //fprintf(output,"digraph Dependencies {\n");
seanhalle@0 307 //set_dot_file(output);
seanhalle@0 308 //FIXME: first line still depends on counters being enabled, replace w/ unit struct!
seanhalle@0 309 //forAllInDynArrayDo(_VMSMasterEnv->counter_history_array_info, &print_dot_node_info );
seanhalle@0 310 forAllInListOfArraysDo( semanticEnv->unitList, &print_unit_to_file );
seanhalle@0 311 forAllInListOfArraysDo( semanticEnv->commDependenciesList, &print_comm_dependency_to_file );
seanhalle@0 312 forAllInListOfArraysDo( semanticEnv->ctlDependenciesList, &print_ctl_dependency_to_file );
seanhalle@0 313 forAllInListOfArraysDo( semanticEnv->dynDependenciesList, &print_dyn_dependency_to_file );
seanhalle@0 314 forAllInListOfArraysDo( semanticEnv->hwArcs, &print_hw_dependency_to_file );
seanhalle@0 315 //fprintf(output,"}\n");
seanhalle@0 316 fflush(output);
seanhalle@0 317
seanhalle@0 318 } else
seanhalle@0 319 printf("Opening LoopGraph file failed. Please check that folder \"counters\" exists in run directory and has write permission.\n");
seanhalle@0 320 } else {
seanhalle@0 321 printf("Could not open LoopGraph file, please clean \"counters\" folder. (Must contain less than 255 files.)\n");
seanhalle@0 322 }
seanhalle@0 323
seanhalle@0 324
seanhalle@0 325 freeListOfArrays(semanticEnv->unitList);
seanhalle@0 326 freeListOfArrays(semanticEnv->commDependenciesList);
seanhalle@0 327 freeListOfArrays(semanticEnv->ctlDependenciesList);
seanhalle@0 328 freeListOfArrays(semanticEnv->dynDependenciesList);
seanhalle@0 329
seanhalle@0 330 #endif
seanhalle@0 331 #ifdef HOLISTIC__TURN_ON_PERF_COUNTERS
seanhalle@0 332 for(n=0;n<255;n++)
seanhalle@0 333 {
seanhalle@0 334 sprintf(filename, "./counters/Counters.%d.csv",n);
seanhalle@0 335 output = fopen(filename,"r");
seanhalle@0 336 if(output)
seanhalle@0 337 {
seanhalle@0 338 fclose(output);
seanhalle@0 339 }else{
seanhalle@0 340 break;
seanhalle@0 341 }
seanhalle@0 342 }
seanhalle@0 343 if(n<255){
seanhalle@0 344 printf("Saving Counter measurements to File: %s ...\n", filename);
seanhalle@0 345 output = fopen(filename,"w+");
seanhalle@0 346 if(output!=NULL){
seanhalle@0 347 set_counter_file(output);
seanhalle@0 348 int i;
seanhalle@0 349 for(i=0;i<NUM_CORES;i++){
seanhalle@0 350 forAllInListOfArraysDo( semanticEnv->counterList[i], &print_counter_events_to_file );
seanhalle@0 351 fflush(output);
seanhalle@0 352 }
seanhalle@0 353
seanhalle@0 354 } else
seanhalle@0 355 printf("Opening UCC file failed. Please check that folder \"counters\" exists in run directory and has write permission.\n");
seanhalle@0 356 } else {
seanhalle@0 357 printf("Could not open UCC file, please clean \"counters\" folder. (Must contain less than 255 files.)\n");
seanhalle@0 358 }
seanhalle@0 359
seanhalle@0 360 #endif
seanhalle@0 361 /* It's all allocated inside VMS's big chunk -- that's about to be freed, so
seanhalle@0 362 * nothing to do here
seanhalle@0 363
seanhalle@0 364
seanhalle@0 365 for( coreIdx = 0; coreIdx < NUM_CORES; coreIdx++ )
seanhalle@0 366 {
seanhalle@0 367 VMS_int__free( semanticEnv->readyVPQs[coreIdx]->startOfData );
seanhalle@0 368 VMS_int__free( semanticEnv->readyVPQs[coreIdx] );
seanhalle@0 369 }
seanhalle@0 370 VMS_int__free( semanticEnv->readyVPQs );
seanhalle@0 371
seanhalle@0 372 freeHashTable( semanticEnv->commHashTbl );
seanhalle@0 373 VMS_int__free( _VMSMasterEnv->semanticEnv );
seanhalle@0 374 */
seanhalle@0 375 VMS_SS__cleanup_at_end_of_shutdown();
seanhalle@0 376 }
seanhalle@0 377
seanhalle@0 378
seanhalle@0 379 //===========================================================================
seanhalle@0 380
seanhalle@0 381 /*
seanhalle@0 382 */
seanhalle@2 383 SlaveVP *
seanhalle@2 384 VSs__create_slave_with( TopLevelFnPtr fnPtr, void *initData,
seanhalle@3 385 SlaveVP *creatingSlv )
seanhalle@2 386 { VSsSemReq reqData;
seanhalle@0 387
seanhalle@0 388 //the semantic request data is on the stack and disappears when this
seanhalle@0 389 // call returns -- it's guaranteed to remain in the VP's stack for as
seanhalle@0 390 // long as the VP is suspended.
seanhalle@0 391 reqData.reqType = 0; //know type because in a VMS create req
seanhalle@0 392 reqData.coreToAssignOnto = -1; //means round-robin assign
seanhalle@0 393 reqData.fnPtr = fnPtr;
seanhalle@0 394 reqData.initData = initData;
seanhalle@3 395 reqData.callingSlv = creatingSlv;
seanhalle@0 396
seanhalle@3 397 VMS_WL__send_create_slaveVP_req( &reqData, creatingSlv );
seanhalle@0 398
seanhalle@3 399 return creatingSlv->dataRetFromReq;
seanhalle@0 400 }
seanhalle@0 401
seanhalle@2 402 SlaveVP *
seanhalle@2 403 VSs__create_slave_with_affinity( TopLevelFnPtr fnPtr, void *initData,
seanhalle@3 404 SlaveVP *creatingSlv, int32 coreToAssignOnto )
seanhalle@2 405 { VSsSemReq reqData;
seanhalle@0 406
seanhalle@0 407 //the semantic request data is on the stack and disappears when this
seanhalle@0 408 // call returns -- it's guaranteed to remain in the VP's stack for as
seanhalle@0 409 // long as the VP is suspended.
seanhalle@3 410 reqData.reqType = create_slave_w_aff; //not used, May 2012
seanhalle@2 411 reqData.coreToAssignOnto = coreToAssignOnto;
seanhalle@0 412 reqData.fnPtr = fnPtr;
seanhalle@0 413 reqData.initData = initData;
seanhalle@3 414 reqData.callingSlv = creatingSlv;
seanhalle@0 415
seanhalle@3 416 VMS_WL__send_create_slaveVP_req( &reqData, creatingSlv );
seanhalle@0 417
seanhalle@3 418 return creatingSlv->dataRetFromReq;
seanhalle@0 419 }
seanhalle@0 420
seanhalle@0 421
seanhalle@2 422 void
seanhalle@2 423 VSs__dissipate_slave( SlaveVP *slaveToDissipate )
seanhalle@0 424 {
seanhalle@2 425 VMS_WL__send_dissipate_req( slaveToDissipate );
seanhalle@0 426 }
seanhalle@0 427
seanhalle@0 428
seanhalle@0 429 //===========================================================================
seanhalle@0 430
seanhalle@0 431
seanhalle@2 432 //===========================================================================
seanhalle@2 433 /*Returns a taskID, which can be used to communicate between tasks with
seanhalle@2 434 * send-receive, or to use other kinds of constructs with tasks.
seanhalle@2 435 */
seanhalle@2 436 int32
seanhalle@2 437 VSs__submit_task( VSsTaskType *taskType, void *args, SlaveVP *animSlv)
seanhalle@2 438 { VSsSemReq reqData;
seanhalle@0 439
seanhalle@2 440 reqData.reqType = submit_task;
seanhalle@2 441 reqData.callingSlv = animSlv;
seanhalle@2 442 reqData.taskType = taskType;
seanhalle@2 443 reqData.args = args;
seanhalle@2 444
seanhalle@2 445
seanhalle@2 446 VMS_WL__send_sem_request( &reqData, animSlv );
seanhalle@3 447 return (int32)animSlv->dataRetFromReq;
seanhalle@0 448 }
seanhalle@0 449
seanhalle@2 450 /*NOTE: if want, don't need to send the animating SlaveVP around..
seanhalle@2 451 * instead, can make a single slave per core, and coreCtrlr looks up the
seanhalle@2 452 * slave from having the core number.
seanhalle@2 453 *
seanhalle@2 454 *But, to stay compatible with all the other VMS languages, leave it in..
seanhalle@2 455 *
seanhalle@2 456 *This call is the last to happen in every task. It causes the slave to
seanhalle@2 457 * suspend and get the next task out of the task-queue. Notice there is no
seanhalle@2 458 * assigner here.. only one slave, no slave ReadyQ, and so on..
seanhalle@2 459 *Can either make the assigner take the next task out of the taskQ, or can
seanhalle@2 460 * leave all as it is, and make task-end take the next task.
seanhalle@2 461 *Note: this fits the case in the new VMS for no-context tasks, so will use
seanhalle@2 462 * the built-in taskQ of new VMS, and should be local and much faster.
seanhalle@2 463 *
seanhalle@2 464 *The task-stub is saved in the animSlv, so the request handler will get it
seanhalle@2 465 * from there, along with the task-type which has arg types, and so on..
seanhalle@0 466 */
seanhalle@0 467 void
seanhalle@2 468 VSs__end_task( SlaveVP *animSlv )
seanhalle@2 469 { VSsSemReq reqData;
seanhalle@0 470
seanhalle@2 471 reqData.reqType = end_task;
seanhalle@2 472 reqData.callingSlv = animSlv;
seanhalle@2 473
seanhalle@2 474 VMS_WL__send_sem_request( &reqData, animSlv );
seanhalle@0 475 }
seanhalle@0 476
seanhalle@2 477 //==========================================================================
seanhalle@0 478 //
seanhalle@0 479 /*A function singleton is a function whose body executes exactly once, on a
seanhalle@0 480 * single core, no matter how many times the fuction is called and no
seanhalle@0 481 * matter how many cores or the timing of cores calling it.
seanhalle@0 482 *
seanhalle@0 483 *A data singleton is a ticket attached to data. That ticket can be used
seanhalle@0 484 * to get the data through the function exactly once, no matter how many
seanhalle@0 485 * times the data is given to the function, and no matter the timing of
seanhalle@0 486 * trying to get the data through from different cores.
seanhalle@0 487 */
seanhalle@0 488
seanhalle@0 489 /*asm function declarations*/
seanhalle@2 490 void asm_save_ret_to_singleton(VSsSingleton *singletonPtrAddr);
seanhalle@2 491 void asm_write_ret_from_singleton(VSsSingleton *singletonPtrAddr);
seanhalle@0 492
seanhalle@0 493 /*Fn singleton uses ID as index into array of singleton structs held in the
seanhalle@0 494 * semantic environment.
seanhalle@0 495 */
seanhalle@0 496 void
seanhalle@3 497 VSs__start_fn_singleton( int32 singletonID, SlaveVP *animSlv )
seanhalle@0 498 {
seanhalle@2 499 VSsSemReq reqData;
seanhalle@0 500
seanhalle@0 501 //
seanhalle@0 502 reqData.reqType = singleton_fn_start;
seanhalle@0 503 reqData.singletonID = singletonID;
seanhalle@0 504
seanhalle@3 505 VMS_WL__send_sem_request( &reqData, animSlv );
seanhalle@3 506 if( animSlv->dataRetFromReq ) //will be 0 or addr of label in end singleton
seanhalle@0 507 {
seanhalle@3 508 VSsSemEnv *semEnv = VMS_int__give_sem_env_for( animSlv );
seanhalle@0 509 asm_write_ret_from_singleton(&(semEnv->fnSingletons[ singletonID]));
seanhalle@0 510 }
seanhalle@0 511 }
seanhalle@0 512
seanhalle@0 513 /*Data singleton hands addr of loc holding a pointer to a singleton struct.
seanhalle@0 514 * The start_data_singleton makes the structure and puts its addr into the
seanhalle@0 515 * location.
seanhalle@0 516 */
seanhalle@0 517 void
seanhalle@3 518 VSs__start_data_singleton( VSsSingleton **singletonAddr, SlaveVP *animSlv )
seanhalle@0 519 {
seanhalle@2 520 VSsSemReq reqData;
seanhalle@0 521
seanhalle@0 522 if( *singletonAddr && (*singletonAddr)->hasFinished )
seanhalle@0 523 goto JmpToEndSingleton;
seanhalle@0 524
seanhalle@0 525 reqData.reqType = singleton_data_start;
seanhalle@0 526 reqData.singletonPtrAddr = singletonAddr;
seanhalle@0 527
seanhalle@3 528 VMS_WL__send_sem_request( &reqData, animSlv );
seanhalle@3 529 if( animSlv->dataRetFromReq ) //either 0 or end singleton's return addr
seanhalle@0 530 { //Assembly code changes the return addr on the stack to the one
seanhalle@0 531 // saved into the singleton by the end-singleton-fn
seanhalle@0 532 //The return addr is at 0x4(%%ebp)
seanhalle@0 533 JmpToEndSingleton:
seanhalle@0 534 asm_write_ret_from_singleton(*singletonAddr);
seanhalle@0 535 }
seanhalle@0 536 //now, simply return
seanhalle@0 537 //will exit either from the start singleton call or the end-singleton call
seanhalle@0 538 }
seanhalle@0 539
seanhalle@0 540 /*Uses ID as index into array of flags. If flag already set, resumes from
seanhalle@0 541 * end-label. Else, sets flag and resumes normally.
seanhalle@0 542 *
seanhalle@0 543 *Note, this call cannot be inlined because the instr addr at the label
seanhalle@0 544 * inside is shared by all invocations of a given singleton ID.
seanhalle@0 545 */
seanhalle@0 546 void
seanhalle@3 547 VSs__end_fn_singleton( int32 singletonID, SlaveVP *animSlv )
seanhalle@0 548 {
seanhalle@2 549 VSsSemReq reqData;
seanhalle@0 550
seanhalle@0 551 //don't need this addr until after at least one singleton has reached
seanhalle@0 552 // this function
seanhalle@3 553 VSsSemEnv *semEnv = VMS_int__give_sem_env_for( animSlv );
seanhalle@0 554 asm_write_ret_from_singleton(&(semEnv->fnSingletons[ singletonID]));
seanhalle@0 555
seanhalle@0 556 reqData.reqType = singleton_fn_end;
seanhalle@0 557 reqData.singletonID = singletonID;
seanhalle@0 558
seanhalle@3 559 VMS_WL__send_sem_request( &reqData, animSlv );
seanhalle@0 560
seanhalle@0 561 EndSingletonInstrAddr:
seanhalle@0 562 return;
seanhalle@0 563 }
seanhalle@0 564
seanhalle@0 565 void
seanhalle@3 566 VSs__end_data_singleton( VSsSingleton **singletonPtrAddr, SlaveVP *animSlv )
seanhalle@0 567 {
seanhalle@2 568 VSsSemReq reqData;
seanhalle@0 569
seanhalle@0 570 //don't need this addr until after singleton struct has reached
seanhalle@0 571 // this function for first time
seanhalle@0 572 //do assembly that saves the return addr of this fn call into the
seanhalle@0 573 // data singleton -- that data-singleton can only be given to exactly
seanhalle@0 574 // one instance in the code of this function. However, can use this
seanhalle@0 575 // function in different places for different data-singletons.
seanhalle@0 576 // (*(singletonAddr))->endInstrAddr = &&EndDataSingletonInstrAddr;
seanhalle@0 577
seanhalle@0 578
seanhalle@0 579 asm_save_ret_to_singleton(*singletonPtrAddr);
seanhalle@0 580
seanhalle@0 581 reqData.reqType = singleton_data_end;
seanhalle@0 582 reqData.singletonPtrAddr = singletonPtrAddr;
seanhalle@0 583
seanhalle@3 584 VMS_WL__send_sem_request( &reqData, animSlv );
seanhalle@0 585 }
seanhalle@0 586
seanhalle@0 587 /*This executes the function in the masterVP, so it executes in isolation
seanhalle@0 588 * from any other copies -- only one copy of the function can ever execute
seanhalle@0 589 * at a time.
seanhalle@0 590 *
seanhalle@0 591 *It suspends to the master, and the request handler takes the function
seanhalle@0 592 * pointer out of the request and calls it, then resumes the VP.
seanhalle@0 593 *Only very short functions should be called this way -- for longer-running
seanhalle@0 594 * isolation, use transaction-start and transaction-end, which run the code
seanhalle@0 595 * between as work-code.
seanhalle@0 596 */
seanhalle@0 597 void
seanhalle@2 598 VSs__animate_short_fn_in_isolation( PtrToAtomicFn ptrToFnToExecInMaster,
seanhalle@3 599 void *data, SlaveVP *animSlv )
seanhalle@0 600 {
seanhalle@2 601 VSsSemReq reqData;
seanhalle@0 602
seanhalle@0 603 //
seanhalle@0 604 reqData.reqType = atomic;
seanhalle@0 605 reqData.fnToExecInMaster = ptrToFnToExecInMaster;
seanhalle@0 606 reqData.dataForFn = data;
seanhalle@0 607
seanhalle@3 608 VMS_WL__send_sem_request( &reqData, animSlv );
seanhalle@0 609 }
seanhalle@0 610
seanhalle@0 611
seanhalle@0 612 /*This suspends to the master.
seanhalle@0 613 *First, it looks at the VP's data, to see the highest transactionID that VP
seanhalle@0 614 * already has entered. If the current ID is not larger, it throws an
seanhalle@0 615 * exception stating a bug in the code. Otherwise it puts the current ID
seanhalle@0 616 * there, and adds the ID to a linked list of IDs entered -- the list is
seanhalle@0 617 * used to check that exits are properly ordered.
seanhalle@0 618 *Next it is uses transactionID as index into an array of transaction
seanhalle@0 619 * structures.
seanhalle@0 620 *If the "VP_currently_executing" field is non-null, then put requesting VP
seanhalle@0 621 * into queue in the struct. (At some point a holder will request
seanhalle@0 622 * end-transaction, which will take this VP from the queue and resume it.)
seanhalle@0 623 *If NULL, then write requesting into the field and resume.
seanhalle@0 624 */
seanhalle@0 625 void
seanhalle@3 626 VSs__start_transaction( int32 transactionID, SlaveVP *animSlv )
seanhalle@0 627 {
seanhalle@2 628 VSsSemReq reqData;
seanhalle@0 629
seanhalle@0 630 //
seanhalle@3 631 reqData.callingSlv = animSlv;
seanhalle@0 632 reqData.reqType = trans_start;
seanhalle@0 633 reqData.transID = transactionID;
seanhalle@0 634
seanhalle@3 635 VMS_WL__send_sem_request( &reqData, animSlv );
seanhalle@0 636 }
seanhalle@0 637
seanhalle@0 638 /*This suspends to the master, then uses transactionID as index into an
seanhalle@0 639 * array of transaction structures.
seanhalle@0 640 *It looks at VP_currently_executing to be sure it's same as requesting VP.
seanhalle@0 641 * If different, throws an exception, stating there's a bug in the code.
seanhalle@0 642 *Next it looks at the queue in the structure.
seanhalle@0 643 *If it's empty, it sets VP_currently_executing field to NULL and resumes.
seanhalle@0 644 *If something in, gets it, sets VP_currently_executing to that VP, then
seanhalle@0 645 * resumes both.
seanhalle@0 646 */
seanhalle@0 647 void
seanhalle@3 648 VSs__end_transaction( int32 transactionID, SlaveVP *animSlv )
seanhalle@0 649 {
seanhalle@2 650 VSsSemReq reqData;
seanhalle@0 651
seanhalle@0 652 //
seanhalle@3 653 reqData.callingSlv = animSlv;
seanhalle@0 654 reqData.reqType = trans_end;
seanhalle@0 655 reqData.transID = transactionID;
seanhalle@0 656
seanhalle@3 657 VMS_WL__send_sem_request( &reqData, animSlv );
seanhalle@0 658 }