void sender(void) { int receiver_tid = 2; char byte4[4] = {'A', 'B', 'C', 'D'}; int byte64[16] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}; char byte4_reply[4]; int byte64_reply[16]; int ret1, ret2; ret1 = Send(receiver_tid, (void*)byte64, 64, (void*)byte64_reply, 64); unsigned int start = TC4_start(); Send(receiver_tid, (void*)byte4, 4, (void*)byte4_reply, 4); unsigned int end = TC4_stop(); unsigned int time1 = microsecs(start, end); ret2 = Send(receiver_tid, (void*)byte64, 64, (void*)byte64_reply, 64); start = TC4_start(); Send(receiver_tid, (void*)byte64, 64, (void*)byte64_reply, 64); end = TC4_stop(); unsigned int time2 = microsecs(start, end); kprintf("Data: %c %c %c %c\n\r", byte4_reply[0], byte4_reply[1], byte4_reply[2], byte4_reply[3]); kprintf("Data: "); int i; for(i=0;i<16;i++) { kprintf("%d ", byte64_reply[i]); } kprintf("\n\rSender first, 4 byte data transaction: %u micro secs\n\r", time1); kprintf("Sender first, 64 byte data transaction: %u micro secs\n\r", time2); Exit(); }
double getdiff(void(*func)(void)){ for(i = 0, diff = 0.0; i < RANGE; i++){ t1 = microsecs(); func(); t2 = microsecs(); diff = diff + (t2 - t1); } return diff /= (double)RANGE; }
int main(void) { double t0, t1; srand(time(NULL)); // seed the rand number generator mat4x4 *bigMatA = create4x4Array(ARRAY_SIZE); mat4x4 *bigMatB = create4x4Array(ARRAY_SIZE); mat4x4 *bigMatRes = create4x4ClearArray(ARRAY_SIZE); t0 = microsecs(); multBigMat(bigMatRes, ARRAY_SIZE, bigMatA, bigMatB); t1 = microsecs(); printf("Execution time: %f\n", (t1 - t0)); return 0; }
void syscall(TD *td_caller, Request *req) { #ifdef TASK_RUNTIME td_caller->runtime += microsecs (0, TC4_stop()); #endif int retval = -5;// int err = 0; switch(req->call_number) { case SYS_Create: retval = sys_Create(td_caller, req); break; case SYS_MyTid: retval = sys_MyTid(td_caller, req); break; case SYS_MyParentTid: retval = sys_MyParentTid(td_caller, req); break; case SYS_Pass: sys_Pass(td_caller, req); break; case SYS_Exit: sys_Exit(td_caller, req); break; case SYS_Send: retval = sys_Send(td_caller, req); break; case SYS_Receive: retval = sys_Receive(td_caller, req); break; case SYS_Reply: retval = sys_Reply(td_caller, req); break; case SYS_AwaitEvent: retval = sys_AwaitEvent(td_caller, req); break; case SYS_SHUTDOWN: sys_SHUTDOWN(td_caller, req); break; case SYS_RunTime: retval = sys_RunTime(td_caller, req); break; case SYS_Output: retval = sys_Output(td_caller, req); break; case SYS_CreateSmall: retval = sys_CreateSmall(td_caller, req); break; case SYS_Destroy: retval = sys_Destroy(td_caller, req); break; case SYS_Receive_nonbl: retval = sys_Receive_nonbl(td_caller, req); break; default: kprintf("Unknown system call\n\r"); break; } *((int *)(td_caller->sp)) = retval; }
void handle_io_sampling(uint64_t io_clock) { uint64_t now = microsecs(); if (now - last_sample < 10000) return; last_sample = now; std::set <IOComponent*>::iterator iter = regular_polls.begin(); while (iter != regular_polls.end() ) { IOComponent *ioc = *iter++; ioc->read_time = io_clock; ioc->filter(ioc->address.value); } }
bool RateLimiter::ready() { uint64_t now = microsecs(); if (now >= last + delay) { last = now; if (back_off == boaStep) delay += step; else if (back_off == boaGeometric) delay *= scale; if (delay> max_delay) delay = max_delay; return true; } return false; }
Action::Status Action::operator()() { reset(); start_time = microsecs(); status = Running; // important because run() checks the current state status = run(); if (status == Failed) { if (error_msg) { AbortActionTemplate aat(true, error_msg->get()); AbortAction *aa = (AbortAction*)aat.factory(owner); owner->enqueueAction(aa); } else if (timeout_msg) { AbortActionTemplate aat(true, timeout_msg->get()); AbortAction *aa = (AbortAction*)aat.factory(owner); owner->enqueueAction(aa); } } return status; }
MessageHeader::MessageHeader(uint32_t dst, uint32_t src, bool need_reply) : msgid(++last_id), dest(dst), source(src), start_time(microsecs()), arrival_time(0), options(0) { if (need_reply) options |= NEED_REPLY; }
MessageHeader::MessageHeader() : msgid(++last_id), dest(0), source(0), start_time(microsecs()), arrival_time(0), options(0){}
AutoStat::~AutoStat() { uint64_t now = microsecs(); storage_.update(now, now-start_time); }
AutoStat::AutoStat(AutoStatStorage &storage) : storage_(storage) { start_time = microsecs(); }
void AutoStatStorage::update() { uint64_t now = microsecs(); if (start_time) {update(now, now-start_time); } start_time = now; }
void AutoStatStorage::stop() { if (start_time) { uint64_t now = microsecs(); update(now, now-start_time); start_time = 0; } }
void AutoStatStorage::start() { start_time = microsecs(); }
CounterRate::CounterRate(IOAddress addr) : IOComponent(addr), times(16), positions(0) { start_t = microsecs(); }
void IOComponent::processAll(uint64_t clock, size_t data_size, uint8_t *mask, uint8_t *data, std::set<IOComponent *> &updated_machines) { io_clock = clock; // receive process data updates and mask to yield updated components current_time = microsecs(); assert(data != io_process_data); #if VERBOSE_DEBUG for (size_t ii=0; ii<data_size; ++ii) if (mask[ii]) { std::cout << "IOComponent::processAll()\n"; std::cout << "size: " << data_size << "\n"; std::cout << "pdta: "; display( io_process_data, data_size); std::cout << "\n"; std::cout << "pmsk: "; display( io_process_mask, data_size); std::cout << "\n"; std::cout << "data: "; display( data, data_size); std::cout << "\n"; std::cout << "mask: "; display( mask, data_size); std::cout << "\n"; break; } #endif assert(data_size == process_data_size); if (hardware_state == s_hardware_preinit) { // the initial process data has arrived from EtherCAT. keep the previous data as the defaults // so they can be applied asap memcpy(io_process_data, data, process_data_size); //setHardwareState(s_hardware_init); return; } // step through the incoming mask and update bits in process data uint8_t *p = data; uint8_t *m = mask; uint8_t *q = io_process_data; IOComponent *just_added = 0; for (unsigned int i=0; i<process_data_size; ++i) { if (!last_process_data) { if (*m) notifyComponentsAt(i); } // if (*m && *p==*q) { // std::cout<<"warning: incoming_data == process_data but mask indicates a change at byte " // << (int)(m-mask) << std::setw(2) << std::hex << " value: 0x" << (int)(*m) << std::dec << "\n"; // } if (*p != *q && *m) { // copy masked bits if any uint8_t bitmask = 0x01; int j = 0; // check each bit against the mask and if the mask if // set, check if the bit has changed. If the bit has // changed, notify components that use this bit and // update the bit while (bitmask) { if ( *m & bitmask) { //std::cout << "looking up " << i << ":" << j << "\n"; IOComponent *ioc = (*indexed_components)[ i*8+j ]; if (ioc && ioc != just_added) { just_added = ioc; //if (!ioc) std::cout << "no component at " << i << ":" << j << " found\n"; //else std::cout << "found " << ioc->io_name << "\n"; #if 0 if (ioc && ioc->last_event != e_none) { // pending locally sourced change on this io std::cout << " adding " << ioc->io_name << " due to event " << ioc->last_event << "\n"; updatedComponentsIn.insert(ioc); } #endif if ( (*p & bitmask) != (*q & bitmask) ) { // remotely source change on this io if (ioc) { //std::cout << " adding " << ioc->io_name << " due to bit change\n"; boost::recursive_mutex::scoped_lock lock(processing_queue_mutex); updatedComponentsIn.insert(ioc); } if (*p & bitmask) *q |= bitmask; else *q &= (uint8_t)(0xff - bitmask); } //else { // std::cout << "no change " << (unsigned int)*p << " vs " << // (unsigned int)*q << "\n";} } else { if (!ioc) std::cout << "IOComponent::processAll(): no io component at " << i <<":" <<j <<" but mask bit is set\n"; if ( (*p & bitmask) != (*q & bitmask) ) { if (*p & bitmask) *q |= bitmask; else *q &= (uint8_t)(0xff - bitmask); } } } bitmask = bitmask << 1; ++j; } } ++p; ++q; ++m; } if (hardware_state == s_operational) { // save the domain data for the next check if (!last_process_data) { last_process_data = new uint8_t[process_data_size]; } memcpy(last_process_data, io_process_data, process_data_size); } { boost::recursive_mutex::scoped_lock lock(processing_queue_mutex); if (!updatedComponentsIn.size()) return; // std::cout << updatedComponentsIn.size() << " component updates from hardware\n"; #ifdef USE_EXPERIMENTAL_IDLE_LOOP // look at the components that changed and remove them from the outgoing queue as long as the // outputs have been sent to the hardware std::set<IOComponent*>::iterator iter = updatedComponentsIn.begin(); while (iter != updatedComponentsIn.end()) { IOComponent *ioc = *iter++; ioc->read_time = io_clock; //std::cerr << "processing " << ioc->io_name << " time: " << ioc->read_time << "\n"; updatedComponentsIn.erase(ioc); if (updates_sent && updatedComponentsOut.count(ioc)) { //std::cout << "output request for " << ioc->io_name << " resolved\n"; updatedComponentsOut.erase(ioc); } //else std::cout << "still waiting for " << ioc->io_name << " event: " << ioc->last_event << "\n"; updated_machines.insert(ioc); } // for machines with updates to send, if these machines already have the same value // as the hardware (and updates have been sent) we also remove them from the // outgoing queue if (updates_sent) { iter = updatedComponentsOut.begin(); while (iter != updatedComponentsOut.end()) { IOComponent *ioc = *iter++; if (ioc->pending_value == (uint32_t)ioc->address.value) { //std::cout << "output request for " << ioc->io_name << " cleared as hardware value matches\n"; updatedComponentsOut.erase(ioc); } } } #else std::list<IOComponent *>::iterator iter = processing_queue.begin(); while (iter != processing_queue.end()) { IOComponent *ioc = *iter++; ioc->read_time = io_clock; ioc->idle(); } #endif } outputs_waiting = updatedComponentsOut.size(); }