double start_synchronization(void) { switch( current_synchronization ) { case SYNC_BARRIER: MPI_Barrier(get_measurement_comm()); start_sync = wtime(); break; case SYNC_REAL: logging(DBG_SYNC, "start = %9.1f ", normalize_time(wtime())); logging(DBG_SYNC, " -> %9.1f ", (counter+1)*interval*1.0e6 ); if( !wait_till(should_wait_till(counter, interval, -tds[get_global_rank(0)]), &start_sync) ) invalid[counter] = INVALID_STARTED_LATE; else invalid[counter] = False; logging(DBG_SYNC, "start_sync = %9.1f ", normalize_time(start_sync)); break; case SYNC_NOSYNC: start_sync = wtime(); break; default: error_without_abort("out of cases in measurement.c__start_synchronization() current_synchronization = %d\n", current_synchronization); } return start_sync; }
/* p_val and p_to are normalized */ int add_time (timeout_t *p_to, timeout_t *p_val) { /* normalize the values */ (void) normalize_time (p_val); (void) normalize_time (p_to); /* Addition */ (p_to->tv_sec) += p_val->tv_sec; (p_to->tv_usec) += p_val->tv_usec; /* normalize the result */ return (normalize_time (p_to)); }
INT_TIME decode_time_sdr (SDR_TIME st, /* SDR_TIME structure to decode. */ int wordorder) /* wordorder of time contents. */ { SDR_TIME ct = st; EXT_TIME et; if (my_wordorder < 0) get_my_wordorder(); if (my_wordorder != wordorder) { swab2 ((short int *)&ct.year); swab2 ((short int *)&ct.day); swab2 ((short int *)&ct.ticks); } #ifdef QLIB_DEBUG if (debug_option & 128) fprintf (info, "time = %02d.%02d %02d:%02d:%02d:%04d\n", ct.year, ct.day, ct.hour, ct.minute, ct.second, ct.ticks); #endif et.year = ct.year; et.doy = ct.day; et.hour = ct.hour; et.minute = ct.minute; et.second = ct.second; et.usec = ct.ticks * USECS_PER_TICK; dy_to_mdy (et.doy, et.year, &et.month, &et.day); return (normalize_time(ext_to_int(et))); }
/* ****************************************************************************** * Function : double_to_time * * Abstract : Convert a double (seconds dot microseconds) to time * * Decisions : Normalize the result * * Input : from The double value to convert * * Output : p_to address of the converted time structure * * Return : The double value of conversion * * Errors : None * * History : * ******************************************************************************* */ extern void double_to_time (double from, timeout_t *p_to) { double s, u; /* Try to round usecs */ if (from < HUGE / DMILLION) { /* Cannot round usecs: trunc them */ s = trunc (from); u = trunc ((from - s) * MILLION); } else { /* Round usecs */ u = from * DMILLION; u = (rint (u)) / DMILLION; /* Split */ s = trunc (u); u = (u - s) * DMILLION; } /* Convert to ints, checking overflow */ p_to->tv_sec = (sizeof(p_to->tv_sec) == sizeof(long) ? LONG_MAX : INT_MAX); if (s <= (double) p_to->tv_sec) { p_to->tv_sec = (time_t)s; } p_to->tv_usec = (long)u; normalize_time (p_to); }
/* Compares 2 times (-1 if t1 < t2, 0 if t1 = t2, 1 if t1 > t2) */ int comp_time (timeout_t *p_time_1, timeout_t *p_time_2) { normalize_time (p_time_1); normalize_time (p_time_2); if (p_time_1->tv_sec > p_time_2->tv_sec) { return (1); } else if (p_time_1->tv_sec < p_time_2->tv_sec) { return (-1); } else if (p_time_1->tv_usec > p_time_2->tv_usec) { return (1); } else if (p_time_1->tv_usec < p_time_2->tv_usec) { return (-1); } else { return (0); } }
static void sec_gpu_utilization_handler(void *arg) { u64 time_now = get_time_ns(); struct timeval working_time; struct timeval period_time; mutex_lock(&time_data_lock); if (total_work_time == 0) { if (!hw_start_time) { mutex_unlock(&time_data_lock); sec_gpu_dvfs_handler(0); return; } } if (hw_start_time != 0) { total_work_time += (time_now - hw_start_time); hw_start_time = time_now; } /* changed way to compute the utilization */ working_time = (struct timeval)ns_to_timeval(total_work_time); period_time = (struct timeval)ns_to_timeval(time_now - period_start_time); sgx_gpu_utilization = (normalize_time(working_time) * 256) / normalize_time(period_time); total_work_time = 0; period_start_time = time_now; mutex_unlock(&time_data_lock); sec_gpu_dvfs_handler(sgx_gpu_utilization); }
ha_time_t * parse_time(char **time_str, ha_time_t * a_time, gboolean with_offset) { ha_time_t *new_time = a_time; tzset(); if (a_time == NULL) { new_time = new_ha_date(FALSE); } CRM_CHECK(new_time != NULL, return NULL); CRM_CHECK(new_time->has != NULL, free_ha_date(new_time); return NULL); /* reset the time fields */ new_time->hours = 0; new_time->minutes = 0; new_time->seconds = 0; crm_trace("Get hours..."); new_time->has->hours = FALSE; if (parse_int(time_str, 2, 24, &new_time->hours)) { new_time->has->hours = TRUE; } crm_trace("Get minutes..."); new_time->has->minutes = FALSE; if (parse_int(time_str, 2, 60, &new_time->minutes)) { new_time->has->minutes = TRUE; } crm_trace("Get seconds..."); new_time->has->seconds = FALSE; if (parse_int(time_str, 2, 60, &new_time->seconds)) { new_time->has->seconds = TRUE; } if (with_offset) { crm_trace("Get offset..."); while (isspace((int)(*time_str)[0])) { (*time_str)++; } new_time->offset = parse_time_offset(time_str); normalize_time(new_time); } return new_time; }
double stop_synchronization(void) { stop_batch = stop_sync = wtime(); if( current_synchronization == SYNC_REAL ) { if( stop_sync - start_sync > interval ) invalid[counter] = INVALID_TOOK_TOO_LONG; logging(DBG_SYNC, "stop_sync = %9.1f ", normalize_time(stop_sync)); switch( invalid[counter] ) { case INVALID_TOOK_TOO_LONG: logging(DBG_SYNC, "invalid_too_long\n"); break; case INVALID_STARTED_LATE: logging(DBG_SYNC, "invalid_started_late\n"); break; default: logging(DBG_SYNC, "\n"); } } return stop_sync; }
static void exec_action(int op,int arg1,int arg2) { int i, j; char *tmpstr; switch(op) { case 1000:goto_room(arg1-first_room);break; case 1001:goto_room(agt_rand(arg1,arg2)-first_room);break; case 1002:agt_var[arg1]=loc+first_room;break; case 1003:agt_var[arg1]=dobj;break; case 1004:agt_var[arg1]=iobj;break; case 1005:goto_room(agt_var[arg1]-first_room);break; case 1006:it_move(arg1,agt_var[arg2]);break; case 1007:get_obj(agt_var[arg1]);break; case 1008:msgout(agt_var[arg1],1);break; case 1009:get_obj(arg1);break; case 1010:get_obj(arg1);it_move(arg1,1000);break; case 1011:drop_obj(arg1);break; case 1012: if (it_loc(arg1)==1000) { if (PURE_WEAR) drop_obj(arg1); else it_move(arg1,1); } break; case 1013:fontcmd(0,arg1-1);break; /* Load font */ case 1014:pictcmd(1,pictable[arg1-1]);break; /* Show picture */ case 1015:changepict(arg1,arg2);break; /* ChangePicture */ case 1016: if (PICT_SUPPORT && yesno("Would you like to see the picture?")) pictcmd(1,pictable[arg1-1]);break; case 1017:pictcmd(2,arg1);break; /* Show room pix */ case 1018: if (PICT_SUPPORT && yesno("Would you like to see the picture?")) pictcmd(2,arg1-1);break; case 1019:musiccmd(1,arg1-1);break; case 1020:musiccmd(1,agt_rand(arg1,arg2)-1);break; case 1021:musiccmd(2,arg1-1);break; case 1022:musiccmd(3,-1); break; /* Stop Repeat */ case 1023:musiccmd(4,-1); break; /* Stop song */ case 1024:musiccmd(5,-1); break; /* Suspend song */ case 1025:musiccmd(6,-1);break; /* Resume song */ case 1026: if (tnoun(dobj)) noun[dobj-first_noun].movable=!noun[dobj-first_noun].movable; break; case 1027: it_newdesc(arg1,&msg_ptr[arg2-1]); break; case 1028: if (tnoun(arg1)) noun[arg1-first_noun].points=arg2; else if (tcreat(arg1)) creature[arg1-first_creat].points=arg2; else if (troom(arg1)) room[arg1-first_room].points=arg2; break; case 1029:it_destroy(iobj);break; case 1030: tmpstr=agt_readline(3); i=strlen(tmpstr)-1; if (i>0 && tmpstr[i]=='\n') tmpstr[i]=0; strncpy(userstr[arg1-1],tmpstr,80); rfree(tmpstr); break; case 1031:agt_var[arg1]=read_number();break; case 1032:agt_var[arg1]=curr_time;break; case 1033:curr_time=normalize_time(agt_var[arg1]);break; case 1034:curr_time=normalize_time(arg1); break; case 1035:add_time(arg1);break; case 1036:delta_time=arg1;break; /* 1037 and 1038 are subroutine commands */ case 1039:get_obj(dobj);break; case 1040:it_move(dobj,1000);break; case 1041:drop_obj(dobj);break; case 1042: if (it_loc(dobj)==1000) { if (PURE_WEAR) it_move(dobj,1); else drop_obj(dobj); } break; case 1043: /* drop all */ safecontloop(i,j,1) drop_obj(i); break; case 1044: /* remove all */ safecontloop(i,j,1000) drop_obj(i); break; case 1045:deadflag=1;break; case 1046:it_move(arg1,loc+first_room);break; case 1047:it_move(arg1,arg2);break; case 1048:it_reposition(arg1,arg2,1);break; /* RePosition */ case 1049:it_move(dobj,loc+first_room);break; case 1050:it_move(dobj,arg1);break; case 1051: safecontloop(i,j,1) it_move(i,arg1); safecontloop(i,j,1000) it_move(i,arg1); break; case 1052: nounloop(i) if (player_has(i+first_noun) && noun[i].points>arg2) it_move(i+first_noun,arg1); break; case 1053: safecontloop(i,j,arg1) if (tnoun(i)) it_move(i,arg2); break; case 1054:it_destroy(arg1);break; case 1055:it_destroy(dobj);break; case 1056:i=it_loc(arg1); it_move(arg1,it_loc(arg2)); it_move(arg2,i); break; case 1057:it_move(arg1,it_loc(arg2));break; case 1058:it_move(dobj,it_loc(arg2));break; case 1059: case 1060: /* Add to/remove from group */ if (tcreat(arg1)) creature[arg1-first_creat].groupmemb=(op==1059); break; case 1061: /* Move group */ safecontloop(i,j,loc+first_room) if (it_group(i)) it_move(i,arg1); break; /* 1062 is RedirectTo */ case 1063:msgout(agt_rand(arg1,arg2),1);break; case 1064:print_contents(arg1,1);break; case 1065: case 1066: case 1067: case 1068: obj_act(op-1065,arg1);break; case 1069: case 1070: case 1071: case 1072: obj_act(op-1069,dobj);break; case 1073:print_score();break; case 1074: tscore+=arg1;break; case 1075: tscore-=arg1;break; case 1076:v_inventory();break; case 1077:wait_return();break; case 1078:writeln("Time passes...");break; case 1079:agt_delay(arg1);break; case 1080:agt_clrscr();break; case 1081:it_describe(arg1);break; case 1082:look_room();break; /* LOOK */ case 1083:msgout(arg1,1);break; case 1084:writeln("");break; case 1085:if (PURE_TONE && sound_on) agt_tone(arg1,arg2);break; /* Tone */ case 1086:agt_number=ask_for_number(arg1,arg2);break; case 1087:agt_answer=ask_question(arg1);break; case 1088:change_passage(loc,arg1,arg2);break; case 1089:flag[arg1]=1;break; case 1090:flag[arg1]=0;break; case 1091:flag[arg1]=!flag[arg1];break; case 1092:room[loc].flag_noun_bits|=(1 << (arg1-1) ); break; /* Roomflag on */ case 1093:room[loc].flag_noun_bits&=~(1 << (arg1-1) );break; /* Off */ case 1094:room[loc].flag_noun_bits^=(1 << (arg1-1) );break; /* Toggle */ case 1095: /* if (agt_counter[arg1]==-1)*/ agt_counter[arg1]=1;break; case 1096:agt_counter[arg1]=-1;break; case 1097:agt_var[arg1]=arg2;break; case 1098:agt_var[arg1]+=arg2;break; case 1099:agt_var[arg1]-=arg2;break; case 1100:agt_var[arg1]+=agt_var[arg2];break; case 1101:agt_var[arg1]-=agt_var[arg2];break; case 1102:agt_var[arg1]=agt_rand(0,arg2);break; case 1103:agt_var[arg1]=dobj_rec->num;break; case 1104:agt_var[arg1]=iobj_rec->num;break; /* The following are v1.8x specific */ case 1105:quote(arg1);break; case 1106:add_time(arg1);break; case 1107:add_time(-arg1);break; case 1108:curr_time=(curr_time%100)+100*arg1;break; case 1109:curr_time=(curr_time/100)*100+arg1;break; case 1110:add_time(agt_var[arg1]);break; case 1111:add_time(-agt_var[arg1]);break; case 1112:curr_time=(curr_time%100)+100*agt_var[arg1];break; case 1113:curr_time=(curr_time/100)*100+agt_var[arg1];break; /* Now for the AGX additions */ case 1114:add_time(-arg1);break; /* ME-style SubtractFromTime */ case 1115: disambig_score=arg1; break; /* SetDisambigPriority */ case 1116:agt_var[arg1]=delta_time;break; case 1117: /* ChangeStatus */ statusmode=arg1; break; case 1118: if (!mult_rangecheck(agt_var[arg1],arg2)) break; agt_var[arg1]*=arg2;break; case 1119: if (arg2==0) { if (!PURE_ERROR) writeln("GAME ERROR: Division by zero."); } else agt_var[arg1]/=arg2; break; case 1120: if (arg2==0) { if (!PURE_ERROR) writeln("GAME ERROR: Attempt to divide by zero."); } else agt_var[arg1]%=arg2; break; case 1121:agt_waitkey();break; case 1122:last_he=arg1;break; /* SetHE */ case 1123:last_she=arg1;break; case 1124:last_it=arg1;break; case 1125:last_they=arg1;break; case 1126:msgout(arg1,0);break; case 1127: if (!PURE_ERROR) sysmsg(arg1,"GAME ERROR: Standard message not defined."); break; case 1128: msgout(arg1,1);break; /* FailMessage */ case 1129: /* StdMessage */ sysmsg(arg1,"GAME ERROR: Standard message not defined."); break; case 1130: msgout(arg2,1);break; /* ErrMessage */ case 1131: /* StdErrMessage */ sysmsg(arg1,"GAME ERROR: Standard message not defined."); break; case 1132: /* AND */ break; /* These don't do anything under normal circumstances */ case 1133: /* SetClass */ if (troom(arg1)) room[arg1-first_room].oclass=arg2; else if (tnoun(arg1)) noun[arg1-first_noun].oclass=arg2; else if (tcreat(arg1)) noun[arg1-first_creat].oclass=arg2; break; case 1134: agt_var[arg1]=it_class(arg2); break; /* SetVariableToClass */ /* Stack commands */ case 1135: push_stack(arg1); break; case 1136: agt_var[arg1]=pop_stack(); break; case 1137: case 1138: case 1139: case 1140: case 1141: op_stack(op-1137); /* +,-,*, /,% * */ break; case 1142: { /* DupStack */ long n; n=pop_stack(); push_stack(n); push_stack(n); break; } case 1143: pop_stack();break; /* Discard TOS */ case 1144: agt_var[arg1]=agt_number;break; /* SetVariableToInput */ case 1145: setattr(arg1,arg2,1); break; /* Set */ case 1146: setattr(arg1,arg2,0); break; /* Clear */ case 1147: push_stack(getprop(arg1,arg2));break; /* PushProp */ case 1148: setprop(arg1,arg2,pop_stack());break; /* PopProp */ /* 1149, 1150 handled by run_metacommand */ /* 1151 is EndDisambig */ /* 1152 is XRedirect */ case 1153: rstrncpy(userstr[arg1-1],userstr[arg2-1],81);break; case 1154: setcase(userstr[arg1-1],1); break; case 1155: setcase(userstr[arg1-1],0);break; case 1156: op_objflag(1,arg1,arg2);break; case 1157: op_objflag(0,arg1,arg2);break; case 1158: op_objflag(3,arg1,arg2);break; case 1159: push_stack(op_objprop(2,arg1,arg2,0)); break; case 1160: op_objprop(1,arg1,arg2,pop_stack()); break; case 1161: move_in_dir(arg1,arg2); break; default: writeln("INTERNAL ERROR: Action token not supported."); rprintf("Action #%d",op); writeln(""); } }
/* ****************************************************************************** * Function : time_to_double * * Abstract : Convert time to double (seconds dot microseconds) * * Decisions : None * * Input : p_time The time to convert * * Output : None * * Return : The double value of conversion * * Errors : None * * History : * ******************************************************************************* */ extern double time_to_double (timeout_t *p_time ) { normalize_time (p_time); return (double) p_time->tv_sec + ((double) p_time->tv_usec) / DMILLION; }
int main(int argc, char **argv) { int fn,argnum,retval; size_t tsdata_size; char *iotrace_data_dir, *current_work_dir; /* tsdumps for the source and destination sides */ xdd_ts_header_t *src = NULL; xdd_ts_header_t *dst = NULL; xdd_ts_header_t *tsdata = NULL; /* timestamp entries sorted by ending time */ xdd_ts_tte_t **read_op = NULL; xdd_ts_tte_t **send_op = NULL; xdd_ts_tte_t **recv_op = NULL; xdd_ts_tte_t **write_op = NULL; /* get command line options */ argnum = getoptions(argc, argv); fn = MAX(argnum,1); /* get the src or dst data structs */ retval = xdd_readfile(argv[fn],&tsdata,&tsdata_size); if (retval == 0) { fprintf(stderr,"xdd_readfile() failed...reading 1st xdd timestamp file: %s ...exiting.\n",argv[fn]); exit(1); } /* determine whether this is the source or destination file */ /* if only 1 file given, then source==read, destination==write */ if (READ_OP(tsdata->tsh_tte[0].tte_op_type)) { src = tsdata; srcfilename = argv[fn]; } else if (WRITE_OP(tsdata->tsh_tte[0].tte_op_type)){ dst = tsdata; dstfilename = argv[fn]; } else { fprintf(stderr,"Timestamp dump had invalid operation in tte[0]: %s\n",argv[fn]); exit(1); } /* if 2nd file specified, this must be an e2e pair (src,dst) */ if ( argv[fn+1] != NULL ) { /* get the src or dst data structs */ retval = xdd_readfile(argv[fn+1],&tsdata,&tsdata_size); if (retval == 0) { fprintf(stderr,"xdd_readfile() failed...reading 2nd xdd timestamp file: %s ...exiting.\n",argv[fn+1]); exit(1); } /* determine whether this is the source or destination file */ if (READ_OP(tsdata->tsh_tte[0].tte_op_type)) { if (src != NULL) { fprintf(stderr,"You passed 2 source dump files.\n"); fprintf(stderr,"Please pass matching source and destination dumps or a single dump .\n"); exit(1); } src = tsdata; srcfilename = argv[fn+1]; } else if (WRITE_OP(tsdata->tsh_tte[0].tte_op_type)) { if (dst != NULL) { fprintf(stderr,"You passed 2 destination dump files.\n"); fprintf(stderr,"Please pass matching source and destination dumps or a single dump .\n"); exit(1); } dst = tsdata; dstfilename = argv[fn+1]; } else { fprintf(stderr,"Timestamp dump had invalid operation in tte[0]: %s\n",argv[fn+1]); exit(1); } /* If these files are from the same transfer, they should be the same size. */ if (src->tsh_tt_bytes != dst->tsh_tt_bytes) { fprintf(stderr,"Source and destination files are not the same size.\n"); fprintf(stderr,"Please pass matching source and destination dumps.\n"); exit(1); } } /* get total threads */ if (src != NULL) xdd_getthreads(src,&total_threads_src, thread_id_src, &op_mix); if (dst != NULL) xdd_getthreads(dst,&total_threads_dst, thread_id_dst, &op_mix); /* If e2e, better have same number of threads. */ if (total_threads_src > 0 && total_threads_dst > 0 && total_threads_src != total_threads_dst) { fprintf(stderr,"Warning: source (%d) and destination (%d) files don't have the same number of I/O threads.\n", total_threads_src, total_threads_dst); } /* match-add kernel events with xdd events if specfied */ /* at this point, src & dst contain all xdd events */ /* note that iotrace_data_dir is independent of $PWD */ if (kernel_trace) { if ((iotrace_data_dir=getenv("TRACE_LOG_LOC")) == NULL) iotrace_data_dir=getenv("HOME"); current_work_dir=getenv("PWD"); if (src != NULL) { sprintf(kernfilename,"decode %s/dictionary* %s/iotrace_data.%d.out", iotrace_data_dir, iotrace_data_dir, src->tsh_target_thread_id); if ( system(kernfilename) == -1 ) { fprintf(stderr,"in main: shell command failed: %s\n",kernfilename); exit(1); } if (strcmp(iotrace_data_dir,current_work_dir) != 0) { sprintf(kernfilename,"mv %s/iotrace_data.%d.out.ascii %s", iotrace_data_dir, src->tsh_target_thread_id,getenv("PWD")); if ( system(kernfilename) == -1 ) { fprintf(stderr,"in main: shell command failed: %s\n",kernfilename); exit(1); } } sprintf(kernfilename,"%s/iotrace_data.%d.out.ascii", current_work_dir, src->tsh_target_thread_id); matchadd_kernel_events(1,total_threads_src,thread_id_src,kernfilename,src); if (op_mix > 0.0) matchadd_kernel_events(0,total_threads_src,thread_id_src,kernfilename,src); /* write out the src and dst data structs that now contain kernel data */ sprintf(kernfilename,"%s/%sk", current_work_dir, srcfilename); retval = xdd_writefile(kernfilename,src,tsdata_size); if (retval == 0) { fprintf(stderr,"xdd_writefile() failed to write %s ...exiting.\n",kernfilename); exit(1); } } if (dst != NULL) { sprintf(kernfilename,"decode %s/dictionary* %s/iotrace_data.%d.out", iotrace_data_dir, iotrace_data_dir, dst->tsh_target_thread_id); if ( system(kernfilename) == -1 ) { fprintf(stderr,"in main: shell command failed: %s\n",kernfilename); exit(1); } if (strcmp(iotrace_data_dir,current_work_dir) != 0) { sprintf(kernfilename,"mv %s/iotrace_data.%d.out.ascii %s", iotrace_data_dir, dst->tsh_target_thread_id,getenv("PWD")); if ( system(kernfilename) == -1 ) { fprintf(stderr,"in main: shell command failed: %s\n",kernfilename); exit(1); } } sprintf(kernfilename,"%s/iotrace_data.%d.out.ascii", current_work_dir, dst->tsh_target_thread_id); matchadd_kernel_events(0,total_threads_dst,thread_id_dst,kernfilename,dst); if (op_mix > 0.0) matchadd_kernel_events(1,total_threads_dst,thread_id_dst,kernfilename,dst); sprintf(kernfilename,"%s/%sk", current_work_dir, dstfilename); retval = xdd_writefile(kernfilename,dst,tsdata_size); if (retval == 0) { fprintf(stderr,"xdd_writefile() failed to write %s ...exiting.\n",kernfilename); exit(1); } } } /* get the MIN timestamp normalize the times */ if (src!=NULL) normalize_time(src,&src_start_norm); if (dst!=NULL) normalize_time(dst,&dst_start_norm); /* sort timestamp entries for each operation (read/send/recv/write) */ /* kernel events are co-located with matching xdd op */ if (src!=NULL) { sort_by_time(src, DISK_END, &read_op); if (dst!=NULL) { sort_by_time(src, NET_END, &send_op); } } if (dst!=NULL) { sort_by_time(dst, DISK_END, &write_op); if (src!=NULL) { sort_by_time(dst, NET_END, &recv_op); } } /* write the outfile(s) */ write_outfile (src,dst,read_op,send_op,recv_op,write_op); /* free memory */ free(read_op); free(send_op); free(recv_op); free(write_op); free(src); free(dst); return 0; }