// for backward compatibility with 1.0 sc_clock::sc_clock( const char* name_, double period_, // in default time units double duty_cycle_, double start_time_, // in default time units bool posedge_first_ ) : sc_signal<bool>( name_ ) { static bool warn_sc_clock=true; if ( warn_sc_clock ) { warn_sc_clock = false; SC_REPORT_INFO(SC_ID_IEEE_1666_DEPRECATION_, "\n sc_clock(const char*, double, double, double, bool)\n" " is deprecated use a form that includes sc_time or\n" " sc_time_unit"); } init( sc_time( period_, true ), duty_cycle_, sc_time( start_time_, true ), posedge_first_ ); if( posedge_first_ ) { // posedge first m_next_posedge_event.notify_internal( m_start_time ); } else { // negedge first m_next_negedge_event.notify_internal( m_start_time ); } }
int main(int argc, char *argv[]) { session *s; session_init(&argc, &argv, &s, "Pingpong_A.spr"); if (argc < 3) return EXIT_FAILURE; int M = atoi(argv[1]); int N = atoi(argv[2]); printf("M: %d, N: %d\n", M, N); role *B = s->r(s, "B"); int val[M]; size_t sz = M; long long start_time = sc_time(); int i; for (i=0; i<N; i++) { memset(val, i, M * sizeof(int)); send_int_array(val, (size_t)M, B); sz = M; recv_int_array(val, &sz, B); } long long end_time = sc_time(); printf("%s: Time elapsed: %f sec\n", s->name, sc_time_diff(start_time, end_time)); session_end(s); return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { if (argc < 2) return EXIT_FAILURE; int N = atoi(argv[1]); printf("N: %d\n", N); void *ctx = zmq_init(1); void *pub = zmq_socket(ctx, ZMQ_PUB); // Output channel of 0 assert(pub); void *sub = zmq_socket(ctx, ZMQ_SUB); // Input channel of 0 assert(sub); int rc; rc = zmq_bind(sub, "tcp://*:8887"); // Waits for publishers assert(rc == 0); rc = zmq_connect(pub, "tcp://localhost:8888"); // Actively connect to subscribers assert(rc == 0); zmq_setsockopt(sub, ZMQ_SUBSCRIBE, "", 0); int *val = (int *)calloc(N, sizeof(int)); zmq_msg_t msg; long long start_time = sc_time(); // Send int *buf = (int *)calloc(N, sizeof(int)); memcpy(buf, val, N * sizeof(int)); zmq_msg_init_data(&msg, buf, N * sizeof(int), _dealloc, NULL); zmq_send(pub, &msg, 0); zmq_msg_close(&msg); // Receive zmq_msg_init(&msg); zmq_recv(sub, &msg, 0); memcpy(val, (int *)zmq_msg_data(&msg), zmq_msg_size(&msg)); zmq_msg_close(&msg); long long end_time = sc_time(); printf("%s: Time elapsed: %f sec\n", argv[0], sc_time_diff(start_time, end_time)); #ifdef __DEBUG__ int i; printf("%s [ ", argv[0]); for (i=0; i<N; ++i) { printf("%d ", val[i]); } printf("]\n"); #endif free(val); zmq_close(sub); zmq_close(pub); zmq_term(ctx); return EXIT_SUCCESS; }
void target_sync_reset_4() { switch (reset_4_count) { case 0: sc_assert( sc_time_stamp() == sc_time(10, SC_NS) ); break; case 1: sc_assert( false ); break; case 2: sc_assert( false ); break; } ++reset_4_count; while (true) { wait(); switch (reset_4_count) { case 0: sc_assert( false ); break; case 1: sc_assert( sc_time_stamp() == sc_time(40, SC_NS) ); break; case 2: sc_assert( sc_time_stamp() == sc_time(50, SC_NS) ); target_sync_reset_4_called = true; break; } ++reset_4_count; } }
void target_disable_2() { sc_assert( sc_time_stamp() == sc_time(40, SC_NS) ); target_disable_2_called = true; wait(); // on ev sc_assert( sc_time_stamp() == sc_time(50, SC_NS) ); target_disable_2_called_again = true; }
void session_end(session *s) { unsigned int role_idx; unsigned int role_count = s->nrole; #ifdef __DEBUG__ DEBUG_sess_end_time = sc_time(); #endif sleep(1); for (role_idx=0; role_idx<role_count; role_idx++) { switch (s->roles[role_idx]->type) { case SESSION_ROLE_P2P: assert(s->roles[role_idx]->p2p != NULL); if (zmq_close(s->roles[role_idx]->p2p->ptr)) { perror("zmq_close"); } break; case SESSION_ROLE_GRP: if (zmq_close(s->roles[role_idx]->grp->in->ptr) != 0) { perror("zmq_close"); } if (zmq_close(s->roles[role_idx]->grp->out->ptr) != 0) { perror("zmq_close"); } free(s->roles[role_idx]->grp->in); free(s->roles[role_idx]->grp->out); break; case SESSION_ROLE_INDEXED: assert(0); // TODO handle indexed endpoint break; default: fprintf(stderr, "Unable to terminate endpoint#%u: unknown type\n", role_idx); } // Switch } for (role_idx=0; role_idx<role_count; role_idx++) { free(s->roles[role_idx]); } free(s->roles); zmq_term(s->ctx); s->r = NULL; free(s); #ifdef __DEBUG__ DEBUG_prog_end_time = sc_time(); printf("----- Statistics -----\n"); printf("Total execution time (including session init and cleanup): %f sec\n", sc_time_diff(DEBUG_prog_start_time, DEBUG_prog_end_time)); printf("Total time in session: %f sec\n", sc_time_diff(DEBUG_sess_start_time, DEBUG_sess_end_time)); printf("----------------------\n"); #endif }
void f() { while(true) { e2.notify(sc_time(1,sc_ns)); wait(e2); e3.notify(sc_time(10,sc_ns)); wait(e3); } }
ProcessingElement::ProcessingElement(sc_module_name name, int peID, int maxOutstandingRequests, int cacheWordsTotal, CacheMode cacheMode, SpMVOCMSimulation *parentSim, QList<MemRequestTag> bypass) : sc_module(name) { m_parentSim = parentSim; m_peID = peID; m_maxOutstandingRequests = maxOutstandingRequests; m_streamBufferHeadPos = 0; m_maxAlive = 0; m_requestBypassEnable = bypass; setupCache(cacheMode, cacheWordsTotal); m_cyclesWithRequest = 0; m_cyclesWithResponse = 0; m_memLatencySamples = 0; m_memLatencySum = sc_time(0, SC_NS); m_cacheHits = m_cacheMisses = 0; m_peNZCount = 0; m_peRowCount = 0; // declare SystemC threads SC_THREAD(rowPtrAddrGen); SC_THREAD(matrixValueAddrGen); SC_THREAD(colIndAddrGen); SC_THREAD(progress); }
int main(int argc, char *argv[]) { session *s; session_init(&argc, &argv, &s, "Protocol_R2.spr"); session_dump(s); long long barrier_start = sc_time(); barrier(s->r(s, "_Others"), "R0"); long long barrier_end = sc_time(); sc_print_version(); printf("%s: Barrier time: %f sec\n", s->name, sc_time_diff(barrier_start, barrier_end)); session_end(s); return EXIT_SUCCESS; }
void task2() { while(true) { #ifdef _INTRODUCE_DELTA_DELAY_IN_TASK_2_OF_SYSTEM_LEVEL_MODEL wait(sc_time(101,SC_MS)); #endif cout << "Task 2 waits for event1 at time " << sc_time_stamp() << endl; wait(flag1); #ifdef _USE_FLAG_WITH_SEPARATE_UNSET flag1.unset(); #endif // KisTA model cout << "task 2 " << " resumed at t=" << sc_time_stamp() << endl; consume(sc_time(200,SC_MS)); flag2.set(); } }
int sc_main(int argc, char* argv[]) { sc_clock clk("clk", sc_time(10, SC_NS)); Processor p("p"); ProcessorTester t("t"); sc_signal<uint32_t> command; sc_signal<uint32_t> p_grp[32]; sc_signal<uint32_t> p_srp[32]; sc_signal<uint32_t> t_grp[32]; sc_signal<uint32_t> t_srp[32]; sc_signal<bool> rst; p.clk(clk); //connect modules p.rst(rst); t.rst(rst); p.command(command); t.command(command); for (int i = 0; i < 32; i++) { p.GPR[i](p_grp[i]); p.SPR[i](p_srp[i]); t.GPR[i](t_grp[i]); t.SPR[i](t_srp[i]); } sc_start(); uint32_t reg2Proc = p.GPR[2].read(); uint32_t reg2Test = t.GPR[2].read(); uint32_t reg5Proc = p.GPR[5].read(); uint32_t reg5Test = t.GPR[5].read(); uint32_t reg8Proc = p.GPR[8].read(); uint32_t reg8Test = t.GPR[8].read(); /*uint32_t reg2Proc = p.generalRegisters[2]; uint32_t reg2Test = t.GPR[2].read(); uint32_t reg5Proc = p.generalRegisters[5]; uint32_t reg5Test = t.GPR[5].read(); uint32_t reg8Proc = p.generalRegisters[8]; uint32_t reg8Test = t.GPR[8].read();*/ bool res = reg2Proc == reg2Test && reg5Proc == reg5Test && reg8Proc == reg8Test; #ifdef TRACING_ENABLED printf("\nREGISTERS:\n"); printf("processor register %i = %i\ntestbench register %i = %i\n", 2, reg2Proc, 2, reg2Test); printf("processor register %i =", 5); PrintBinary32(reg5Proc); printf("testbench register %i =", 5); PrintBinary32(reg5Test); printf("processor register %i = %#08x\ntestbench register %i = %#08x\n", 8, reg8Proc, 8, reg8Test); printf("Is test passed? %s\n", res ? "Yes" : "No"); #endif cout << "Sc_Main_finished" << endl; return 0; }
void Simulator::Start() { Simulator::Log() << "Starting Simulation." << std:: endl; sc_start(sc_time(m_duration.GetMilliseconds(), SC_MS)); GetTraceRecorder()->Save(); Simulator::Log() << "Simulation finished." << std:: endl; }
/// Named constructor. ac_module::ac_module(sc_module_name nm) : sc_module(nm), mod_id(next_mod_id++), ac_exit_status(0){ ac_qk.set_global_quantum( sc_time(100, SC_NS) ); ac_qk.reset(); module_period_ns=5; //200 MHz = 5ns this_mod = mods_list.insert(mods_list.end(), this); return; }
sc_clock::sc_clock( const char* name_ ) : sc_signal<bool>( name_ ) { init( sc_time( 1.0, true ), 0.5, SC_ZERO_TIME, true ); m_next_posedge_event.notify_internal( m_start_time ); }
sc_clock::sc_clock() : sc_signal<bool>( sc_gen_unique_name( "clock" ) ) { init( sc_time( 1.0, true ), 0.5, SC_ZERO_TIME, true ); m_next_posedge_event.notify_internal( m_start_time ); }
void f() { while(true) { e1.notify(sc_time(5,sc_ns)); wait(e1); wait(2,sc_ns); } }
Host::Host(sc_module_name p_ModuleName, Connection *p_ConnectionConfig):sc_module(p_ModuleName), m_Encoder("Encoder"), m_Decoder("Decoder"), m_MsgBuffer(START) { ///StringTools instance for reporting StringTools *l_Report = new StringTools(name()); l_Report->resetReportString(); //DEBUGGING SC_REPORT_INFO(g_DebugID, l_Report->newReportString("elaborates")); /// \li define clock period for Router m_ClkPeriod = new const sc_time(1, SC_SEC); /// \li Allocate clock for the Routers using the previously allocated period m_ClkRouter = new sc_clock("CLK", *m_ClkPeriod); SC_REPORT_INFO(g_DebugID, l_Report->newReportString("Building the network interfaces")); //allocate reference array for network interface modules m_NetworkInterface = new Interface*[1]; //allocate reference array for receiving exports export_ReceivingInterface = new sc_export<Interface_If>*[1]; //allocate reference array for fowarding ports port_ForwardingInterface = new sc_port<Interface_If, 1, SC_ZERO_OR_MORE_BOUND>*[1]; m_NetworkInterface[0] = new Interface(m_Name.getNextName(), p_ConnectionConfig); //instantiate hierarchial forwarding port port_ForwardingInterface[0] = new sc_port<Interface_If, 1, SC_ZERO_OR_MORE_BOUND>; //bind network interface port to host's hierarchial port m_NetworkInterface[0]->port_Output.bind(*port_ForwardingInterface[0]); //make the hierarchial binding for receiving exports export_ReceivingInterface[0] = new sc_export<Interface_If>; export_ReceivingInterface[0]->bind(*m_NetworkInterface[0]); //bind the clock to the network interface m_NetworkInterface[0]->port_Clk(*m_ClkRouter); //delete the StringTools object delete l_Report; SC_THREAD(hostMain); sensitive << *m_ClkRouter; }
// for backward compatibility with 1.0 void sc_start( double duration ) // in default time units { static bool warn_sc_start=true; if ( warn_sc_start ) { warn_sc_start = false; SC_REPORT_INFO(SC_ID_IEEE_1666_DEPRECATION_, "sc_start(double) deprecated, use sc_start(sc_time) or sc_start()"); } if ( duration == -1 ) // simulate forever { sc_start( sc_time(~sc_dt::UINT64_ZERO, false) - sc_time_stamp() ); } else { sc_start( sc_time( duration, true ) ); } }
sc_clock::sc_clock( const char* name_, double period_v_, sc_time_unit period_tu_, double duty_cycle_, double start_time_v_, sc_time_unit start_time_tu_, bool posedge_first_ ) : sc_signal<bool>( name_ ) { init( sc_time( period_v_, period_tu_, simcontext() ), duty_cycle_, sc_time( start_time_v_, start_time_tu_, simcontext() ), posedge_first_ ); if( posedge_first_ ) { // posedge first m_next_posedge_event.notify_internal( m_start_time ); } else { // negedge first m_next_negedge_event.notify_internal( m_start_time ); } }
int sc_main(int argc, char* argv[]) { cout << sc_time_stamp() << ": Issuing sc_start(10, SC_NS)" << endl; sc_start(10, SC_NS); cout << sc_time_stamp() << ": Issuing sc_start()" << endl; sc_start(sc_max_time() - sc_time(10,SC_NS) ); cout << sc_time_stamp() << ": Issuing sc_start()" << endl; sc_start(); cout << sc_time_stamp() << ": Issuing sc_start(10, SC_NS)" << endl; sc_start(10, SC_NS); cout << sc_time_stamp() << ": Program completed" << endl; return 0; }
int main(int argc, char *argv[]) { if (argc < 3) return EXIT_FAILURE; int M = atoi(argv[1]); int N = atoi(argv[2]); printf("M: %d, N: %d\n", M, N); void *ctx = zmq_init(1); void *b = zmq_socket(ctx, ZMQ_PAIR); zmq_connect(b, "tcp://localhost:4444"); zmq_msg_t msg; int val[M]; long long start_time = sc_time(); int i; for (i=0; i<N; i++) { int *buf = (int *)malloc(M * sizeof(int)); memset(val, i, M * sizeof(int)); memcpy(buf, val, M * sizeof(int)); zmq_msg_init_data(&msg, buf, M * sizeof(int), _dealloc, NULL); zmq_send(b, &msg, 0); zmq_msg_close(&msg); zmq_msg_init(&msg); zmq_recv(b, &msg, 0); memcpy(val, (int *)zmq_msg_data(&msg), zmq_msg_size(&msg)); zmq_msg_close(&msg); } long long end_time = sc_time(); printf("zmq_a: Time elapsed: %f sec\n", sc_time_diff(start_time, end_time)); zmq_close(b); zmq_term(ctx); return EXIT_SUCCESS; }
sc_clock::sc_clock( const char* name_, double period_v_, sc_time_unit period_tu_, double duty_cycle_ ) : sc_signal<bool>( name_ ) { init( sc_time( period_v_, period_tu_, simcontext() ), duty_cycle_, SC_ZERO_TIME, true ); // posedge first m_next_posedge_event.notify_internal( m_start_time ); }
void task1() { #ifndef _FINITE_TASKS while(true) { #endif cout << "task 1 " << " t_begin=" << sc_time_stamp() << endl; consume(sc_time(100,SC_MS)); #ifdef _USE_YIELDS yield(); #endif #ifndef _FINITE_TASKS } #endif }
void task1() { while(true) { cout << "task 1 " << " begins or resumes at t=" << sc_time_stamp() << endl; consume(sc_time(100,SC_MS)); cout << "task 1 " << " notifies and wait at t=" << sc_time_stamp() << endl; flag1.set(); #ifdef _USE_FLAG_WITH_SEPARATE_UNSET flag2.unset(); #endif wait(flag2); } }
void svf_thread_cond_sc::notify_all() { // Iterate through the list and notify all while (m_waiters) { // Remove the waiter from the list wait_ev *waiter = m_waiters; m_waiters = m_waiters->m_next; waiter->m_ev.notify(sc_time(0, SC_NS)); // Move the waiter to the freelist waiter->m_next = m_freelist; m_freelist = waiter; } }
void svf_thread_cond_sc::notify() { // Select a target to notify if (m_waiters) { // Remove the waiter from the list wait_ev *waiter = m_waiters; m_waiters = m_waiters->m_next; waiter->m_ev.notify(sc_time(0, SC_NS)); // Move the waiter to the freelist waiter->m_next = m_freelist; m_freelist = waiter; } }
void ProcessingElement::progress() { // increment progress if both matrixValue and denseVectorValue are nonempty // and if we have some rowlen data available quint64 nzCount = m_peNZCount; // keep track of nonzeroes left in row VectorIndex nzLeftInRow = 0; sc_time last = sc_time(0,SC_NS); while(1) { // keep track of current row if(m_rowPtrValue->num_available() > 0 && nzLeftInRow == 0) { VectorIndex row = m_rowPtrValue->read(); nzLeftInRow = m_rowLenList[row]; } // TODO enable multiple NZs per cycle? if(m_matrixValue->num_available() > 0 && m_denseVectorValue->num_available() > 0 && nzLeftInRow > 0) { m_matrixValue->read(); m_memLatencySum += sc_time_stamp() - last; m_memLatencySamples++; last = sc_time_stamp(); m_denseVectorValue->read(); nzCount--; nzLeftInRow--; } // break when have issued enough ops if(!nzCount) { break; } wait(PE_CLOCK_CYCLE); } m_parentSim->signalFinishedPE(m_peID); }
void sc_trace_file_base::set_time_unit( double v, sc_time_unit tu ) { if( initialized_ ) { std::stringstream ss; ss << filename_ << "\n" "\tTimescale unit cannot be changed once tracing has begun.\n" "\tTo change the scale, create a new trace file."; SC_REPORT_ERROR( SC_ID_TRACING_ALREADY_INITIALIZED_ , ss.str().c_str() ); return; } switch ( tu ) { case SC_FS: v = v * 1e-15; break; case SC_PS: v = v * 1e-12; break; case SC_NS: v = v * 1e-9; break; case SC_US: v = v * 1e-6; break; case SC_MS: v = v * 1e-3; break; case SC_SEC: break; default: { std::stringstream ss; ss << "unknown time unit:" << tu << " (" << filename_ << ")"; SC_REPORT_WARNING( SC_ID_TRACING_TIMESCALE_UNIT_ , ss.str().c_str() ); } } timescale_set_by_user = true; timescale_unit = v; // EMIT ADVISORY MESSAGE ABOUT CHANGE IN TIME SCALE: { std::stringstream ss; ss << sc_time( timescale_unit, SC_SEC ) << " (" << filename_ << ")"; SC_REPORT_INFO( SC_ID_TRACING_TIMESCALE_UNIT_, ss.str().c_str() ); } }
void SCBus::batch_thread() { cout << "SCBus: batch_thread() started @ " << sc_time_stamp() << endl; SCBusPacket packet; set_wall_time_us(0); double target_time_us = 0; double last_time_us = 0; while (true) { //cout << "SCBus: batch_thread() loop executed @ " << sc_time_stamp() << endl; if (batch_fifo.empty()) { cout << "SCBus: batch_thread() input FIFO empty @ " << sc_time_stamp() << endl; wait(1, SC_MS); sc_stop(); return; } packet = batch_fifo.front(); batch_fifo.pop(); target_time_us = packet.header.timestamp; // SystemC timing wait(sc_time(target_time_us, SC_US) - sc_time_stamp()); cout << "SCBus: batch_thread() SystemC wait ended @ " << sc_time_stamp() << " [" << get_wall_time_us()/1e6 << " s]" << endl; // Wall clock timing while (get_wall_time_us() < target_time_us) {} last_time_us = get_wall_time_us(); cout << "SCBus: batch_thread() wall clock wait ended @ " << sc_time_stamp() << " [" << get_wall_time_us()/1e6 << " s]" << endl; for (int i = 0; i < packet.header.length; i++) { rx_fifo.push(packet.data[i]); } } }
// Send 10 transactions through initiator socket void top::thread_process() { tlm_phase phase = tlm::BEGIN_REQ; sc_time time((sc_dt::uint64)5050,true); tlm_sync_enum status; unsigned int ind; tlm_generic_payload * tgp; tgp = mem_manager.allocate(); tgp->acquire(); ind = 0; cout<<"[SC "<<sc_time_stamp()<<"] staring SC thread process."<<endl; for (int j = 0; j < 10; j++) { create_trans(ind, tgp, tlm::TLM_WRITE_COMMAND); wait(sc_time(1, SC_NS)); cout<<"[SC "<<sc_time_stamp()<<"] Calling nb_transport_fw with data size "<< tgp->get_data_length() << endl; status = i.isocket->nb_transport_fw(*tgp, phase, time); cout<<"[SC "<<sc_time_stamp()<<"] After nb_transport_fw status = "<<status<<endl; ind++; }; sc_assert(i.trans_count==ind); tgp->release(); cout<<"[SC "<<sc_time_stamp()<<"] End of SC thread process"<<endl; }