view probes.c @ 55:3bac84e4e56e

Works with correct matrix mult Nov 4 -- switch animators macros, many updates Changed all queues back to VMSQ variants #defines correct, protected, work-stealing, with compiler switch in and out
author Me
date Thu, 04 Nov 2010 18:13:18 -0700
parents f8508572f3de
children 7b799a46cc87
line source
1 /*
2 * Copyright 2010 OpenSourceStewardshipFoundation
3 *
4 * Licensed under BSD
5 */
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <malloc.h>
10 #include <sys/time.h>
11 #include <string.h>
13 #include "VMS.h"
14 #include "Queue_impl/BlockingQueue.h"
15 #include "Histogram/Histogram.h"
18 //================================ STATS ====================================
20 inline TSCount getTSCount()
21 { unsigned int low, high;
22 TSCount out;
24 saveTimeStampCountInto( low, high );
25 out = high;
26 out = (out << 32) + low;
27 return out;
28 }
32 //==================== Probes =================
33 #ifdef STATS__USE_TSC_PROBES
35 int32
36 VMS__create_histogram_probe( int32 numBins, float32 startValue,
37 float32 binWidth, char *nameStr )
38 { IntervalProbe *newProbe;
39 int32 idx;
40 FloatHist *hist;
42 idx = VMS__create_single_interval_probe( nameStr );
43 newProbe = _VMSMasterEnv->intervalProbes[ idx ];
45 hist = makeFloatHistogram( numBins, startValue, binWidth );
46 newProbe->hist = hist;
47 return idx;
48 }
50 void
51 VMS_impl__record_interval_start_in_probe( int32 probeID )
52 { IntervalProbe *probe;
54 probe = _VMSMasterEnv->intervalProbes[ probeID ];
55 probe->startStamp = getTSCount();
56 }
58 void
59 VMS_impl__record_interval_end_in_probe( int32 probeID )
60 { IntervalProbe *probe;
61 TSCount endStamp;
63 endStamp = getTSCount();
65 probe = _VMSMasterEnv->intervalProbes[ probeID ];
66 probe->endStamp = endStamp;
68 if( probe->hist != NULL )
69 { TSCount interval = probe->endStamp - probe->startStamp;
70 //if the interval is sane, then add to histogram
71 if( interval < probe->hist->endOfRange * 10 )
72 addToFloatHist( interval, probe->hist );
73 }
74 }
76 void
77 VMS_impl__print_stats_of_probe( int32 probeID )
78 { IntervalProbe *probe;
80 probe = _VMSMasterEnv->intervalProbes[ probeID ];
82 if( probe->hist == NULL )
83 {
84 printf("probe: %s, interval: %.6lf\n", probe->nameStr,probe->interval);
85 }
87 else
88 {
89 printf( "probe: %s\n", probe->nameStr );
90 printFloatHist( probe->hist );
91 }
92 }
93 #else
94 #ifdef STATS__USE_DBL_PROBES
96 /*
97 * In practice, probe operations are called from the app, from inside slaves
98 * -- so have to be sure each probe is single-VP owned, and be sure that
99 * any place common structures are modified it's done inside the master.
100 * So -- the only place common structures are modified is during creation.
101 * after that, all mods are to individual instances.
102 *
103 * Thniking perhaps should change the semantics to be that probes are
104 * attached to the virtual processor -- and then everything is guaranteed
105 * to be isolated -- except then can't take any intervals that span VPs,
106 * and would have to transfer the probes to Master env when VP dissipates..
107 * gets messy..
108 *
109 * For now, just making so that probe creation causes a suspend, so that
110 * the dynamic array in the master env is only modified from the master
111 *
112 */
113 IntervalProbe *
114 create_generic_probe( char *nameStr, VirtProcr *animPr )
115 { IntervalProbe *newProbe;
116 VMSSemReq reqData;
118 reqData.reqType = createProbe;
119 reqData.nameStr = nameStr;
121 VMS__send_VMSSem_request( &reqData, animPr );
123 return animPr->dataRetFromReq;
124 }
126 /*Use this version from outside VMS -- it uses external malloc, and modifies
127 * dynamic array, so can't be animated in a slave VP
128 */
129 IntervalProbe *
130 ext__create_generic_probe( char *nameStr )
131 { IntervalProbe *newProbe;
132 int32 nameLen;
134 newProbe = malloc( sizeof(IntervalProbe) );
135 nameLen = strlen( nameStr );
136 newProbe->nameStr = malloc( nameLen );
137 memcpy( newProbe->nameStr, nameStr, nameLen );
138 newProbe->hist = NULL;
139 newProbe->schedChoiceWasRecorded = FALSE;
140 newProbe->probeID =
141 addToDynArray( newProbe, _VMSMasterEnv->dynIntervalProbesInfo );
143 return newProbe;
144 }
147 /*Only call from inside master or main startup/shutdown thread
148 */
149 void
150 VMS_impl__free_probe( IntervalProbe *probe )
151 { if( probe->hist != NULL ) freeDblHist( probe->hist );
152 if( probe->nameStr != NULL) VMS__free( probe->nameStr );
153 VMS__free( probe );
154 }
157 int32
158 VMS_impl__record_time_point_into_new_probe( char *nameStr, VirtProcr *animPr)
159 { IntervalProbe *newProbe;
160 struct timeval *startStamp;
161 float64 startSecs;
163 newProbe = create_generic_probe( nameStr, animPr );
164 newProbe->endSecs = 0;
166 gettimeofday( &(newProbe->startStamp), NULL);
168 //turn into a double
169 startStamp = &(newProbe->startStamp);
170 startSecs = startStamp->tv_sec + ( startStamp->tv_usec / 1000000.0 );
171 newProbe->startSecs = startSecs;
173 return newProbe->probeID;
174 }
176 int32
177 VMS_ext_impl__record_time_point_into_new_probe( char *nameStr )
178 { IntervalProbe *newProbe;
179 struct timeval *startStamp;
180 float64 startSecs;
182 newProbe = ext__create_generic_probe( nameStr );
183 newProbe->endSecs = 0;
185 gettimeofday( &(newProbe->startStamp), NULL);
187 //turn into a double
188 startStamp = &(newProbe->startStamp);
189 startSecs = startStamp->tv_sec + ( startStamp->tv_usec / 1000000.0 );
190 newProbe->startSecs = startSecs;
192 return newProbe->probeID;
193 }
195 int32
196 VMS_impl__create_single_interval_probe( char *nameStr, VirtProcr *animPr )
197 { IntervalProbe *newProbe;
199 newProbe = create_generic_probe( nameStr, animPr );
201 return newProbe->probeID;
202 }
204 int32
205 VMS_impl__create_histogram_probe( int32 numBins, float64 startValue,
206 float64 binWidth, char *nameStr, VirtProcr *animPr )
207 { IntervalProbe *newProbe;
208 DblHist *hist;
210 newProbe = create_generic_probe( nameStr, animPr );
212 hist = makeDblHistogram( numBins, startValue, binWidth );
213 newProbe->hist = hist;
214 return newProbe->probeID;
215 }
217 void
218 VMS_impl__index_probe_by_its_name( int32 probeID, VirtProcr *animPr )
219 { IntervalProbe *probe;
221 //TODO: fix this To be in Master -- race condition
222 probe = _VMSMasterEnv->intervalProbes[ probeID ];
224 addValueIntoTable(probe->nameStr, probe, _VMSMasterEnv->probeNameHashTbl);
225 }
227 IntervalProbe *
228 VMS_impl__get_probe_by_name( char *probeName, VirtProcr *animPr )
229 {
230 //TODO: fix this To be in Master -- race condition
231 return getValueFromTable( probeName, _VMSMasterEnv->probeNameHashTbl );
232 }
235 /*Everything is local to the animating procr, so no need for request, do
236 * work locally, in the anim Pr
237 */
238 void
239 VMS_impl__record_sched_choice_into_probe( int32 probeID, VirtProcr *animatingPr )
240 { IntervalProbe *probe;
242 probe = _VMSMasterEnv->intervalProbes[ probeID ];
243 probe->schedChoiceWasRecorded = TRUE;
244 probe->coreNum = animatingPr->coreAnimatedBy;
245 probe->procrID = animatingPr->procrID;
246 probe->procrCreateSecs = animatingPr->createPtInSecs;
247 }
249 /*Everything is local to the animating procr, so no need for request, do
250 * work locally, in the anim Pr
251 */
252 void
253 VMS_impl__record_interval_start_in_probe( int32 probeID )
254 { IntervalProbe *probe;
256 DEBUG( dbgProbes, "record start of interval\n" )
257 probe = _VMSMasterEnv->intervalProbes[ probeID ];
258 gettimeofday( &(probe->startStamp), NULL );
259 }
262 /*Everything is local to the animating procr, so no need for request, do
263 * work locally, in the anim Pr
264 */
265 void
266 VMS_impl__record_interval_end_in_probe( int32 probeID )
267 { IntervalProbe *probe;
268 struct timeval *endStamp, *startStamp;
269 float64 startSecs, endSecs;
271 DEBUG( dbgProbes, "record end of interval\n" )
272 //possible seg-fault if array resized by diff core right after this
273 // one gets probe..? Something like that? Might be safe.. don't care
274 probe = _VMSMasterEnv->intervalProbes[ probeID ];
275 gettimeofday( &(probe->endStamp), NULL);
277 //now turn into an interval held in a double
278 startStamp = &(probe->startStamp);
279 endStamp = &(probe->endStamp);
281 startSecs = startStamp->tv_sec + ( startStamp->tv_usec / 1000000.0 );
282 endSecs = endStamp->tv_sec + ( endStamp->tv_usec / 1000000.0 );
284 probe->interval = endSecs - startSecs;
285 probe->startSecs = startSecs;
286 probe->endSecs = endSecs;
288 if( probe->hist != NULL )
289 {
290 //if the interval is sane, then add to histogram
291 if( probe->interval < probe->hist->endOfRange * 10 )
292 addToDblHist( probe->interval, probe->hist );
293 }
294 }
296 void
297 print_probe_helper( IntervalProbe *probe )
298 {
299 printf( "\nprobe: %s, ", probe->nameStr );
301 if( probe->schedChoiceWasRecorded )
302 { printf( "coreNum: %d, procrID: %d, procrCreated: %.6lf | ",
303 probe->coreNum, probe->procrID, probe->procrCreateSecs );
304 }
306 if( probe->endSecs == 0 ) //just a single point in time
307 {
308 printf( " time point: %.6lf\n",
309 probe->startSecs - _VMSMasterEnv->createPtInSecs );
310 }
311 else if( probe->hist == NULL ) //just an interval
312 {
313 printf( " startSecs: %.6lf, interval: %.6lf\n",
314 probe->startSecs - _VMSMasterEnv->createPtInSecs, probe->interval);
315 }
316 else //a full histogram of intervals
317 {
318 printDblHist( probe->hist );
319 }
320 }
322 //TODO: change so pass around pointer to probe instead of its array-index..
323 // will eliminate chance for timing of resize to cause problems with the
324 // lookup -- even though don't think it actually can cause problems..
325 // there's no need to pass index around -- have hash table for names, and
326 // only need it once, then have ptr to probe.. the thing about enum the
327 // index and use that as name is clunky in practice -- just hash.
328 void
329 VMS_impl__print_stats_of_probe( int32 probeID )
330 { IntervalProbe *probe;
332 probe = _VMSMasterEnv->intervalProbes[ probeID ];
334 print_probe_helper( probe );
335 }
339 void
340 generic_print_probe( void *_probe )
341 { IntervalProbe *probe;
343 probe = (IntervalProbe *)_probe;
344 print_probe_helper( probe );
345 }
347 void
348 VMS_impl__print_stats_of_all_probes()
349 { IntervalProbe *probe;
351 forAllInDynArrayDo( _VMSMasterEnv->dynIntervalProbesInfo,
352 &generic_print_probe );
353 fflush( stdout );
354 }
355 #endif
356 #endif
358 /* Junk left over from when trying the different ways to get time stamps..
359 struct timeval tim;
360 gettimeofday(&tim, NULL);
361 double t1=tim.tv_sec+(tim.tv_usec/1000000.0);
363 clock_t startClockStamp = clock();
365 TSCount startMultStamp = getTSCount();
366 */
368 /*
369 TSCount endMultStamp = getTSCount();
371 dividerParams->numTSCsToExe = endMultStamp - startMultStamp;
372 printf("\ntime to execute: %d\n", endMultStamp - startMultStamp);
374 //==================================================================
375 clock_t endClockStamp = clock();
376 printf("%.4lf seconds of processing\n",
377 (endClockStamp - startClockStamp)/(double)CLOCKS_PER_SEC);
379 //==================================================================
380 gettimeofday(&tim, NULL);
381 double t2=tim.tv_sec+(tim.tv_usec/1000000.0);
382 printf("%.6lf seconds elapsed\n", t2-t1);
383 */