11 __thread int cp_threadnum;
12 __thread struct coreprofmonitor* cp_monitor = NULL;
13 struct coreprofmonitor* cp_monitorList = NULL;
14 static volatile int cp_threadCount = 0;
17 static inline int atomicinc(volatile int *lock) {
19 __asm__ __volatile__("lock; xadd %0,%1"
21 : "m"(*lock), "0"(retval)
27 // Need to have global lock before calling this method
29 if( cp_monitor != NULL )
32 struct coreprofmonitor* monitor =
33 calloc( 1, sizeof( struct coreprofmonitor ) );
35 if( monitor == NULL ) {
36 printf( "ERROR: calloc returned NULL\n" );
40 struct coreprofmonitor* tmp;
42 // add ourself to the list
46 } while( CAS( &cp_monitorList,
52 int ourcount = atomicinc( &cp_threadCount );
53 cp_threadnum = ourcount;
55 // point thread lock variable to event monitor
57 #ifdef CP_EVENTID_MAIN
58 CP_LOGEVENT( CP_EVENTID_MAIN, CP_EVENTTYPE_BEGIN );
62 // Place to do shutdown stuff
64 #ifdef CP_EVENTID_MAIN
65 CP_LOGEVENT( CP_EVENTID_MAIN, CP_EVENTTYPE_END );
69 void cp_writedata( int fd, char* buffer, int count ) {
72 int size = write( fd, &buffer[offset], count );
81 int fd = open( "coreprof.dat", O_RDWR | O_CREAT, S_IRWXU );
85 struct coreprofmonitor* monitor;
89 // Write version number
95 // Write the number of threads
96 monitor = cp_monitorList;
97 while( monitor != NULL ) {
99 monitor = monitor->next;
105 // Write the number of words used to log
106 // events for each thread
107 monitor = cp_monitorList;
108 while( monitor != NULL ) {
110 (char*)&monitor->numWords,
112 monitor = monitor->next;
115 // END HEADER, BEGIN DATA
116 monitor = cp_monitorList;
117 while( monitor != NULL ) {
119 (char*)monitor->data,
120 sizeof( unsigned int )*monitor->numWords );
121 monitor = monitor->next;
128 void cp_reportOverflow() {
129 printf( "ERROR: coreprof event overflow\n" );