Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00014 #define DURING_MODE env
00015 #include <systemc>
00016 #include "during.h"
00017 #include <boost/bind.hpp>
00018 #include "utils/io-lock.h"
00019
00020 using namespace std;
00021 using namespace sc_core;
00022
00023 #define BIL 1000000000
00024 int N = 100;
00025 #define M 100
00026
00027 void eat_cpu() {
00028 int dummy_counter;
00029 for (int i = 0; i < N; i++) {
00030 for (int j = 0; j < 42000; j++) {
00031 dummy_counter++;
00032 __asm("");
00033 }
00034 }
00035 }
00036
00037 SC_MODULE(A), sc_during
00038 {
00039 void compute() {
00040 cout << "this = " << this << endl;
00041 wait(500, SC_MS);
00042 cout << "N = " << N << endl;
00043 for (int i = 0;
00044 i < N;
00045 i++)
00046 during(BIL/N, SC_NS, boost::bind(&A::f, this));
00047 assert(m_counter == N);
00048 L_COUT << "simple OK: " << sc_core::sc_time_stamp() << endl;
00049 wait(1, SC_SEC);
00050 for (int i = 0; i < N; i++)
00051 during((BIL/N)/M, SC_NS, boost::bind(&A::g, this));
00052 L_COUT << "extra_time OK: " << sc_core::sc_time_stamp() << endl;
00053 wait(1, SC_SEC);
00054 during(1, SC_SEC, boost::bind(&A::h, this));
00055 L_COUT << "eat_cpu OK: " << sc_core::sc_time_stamp() << endl;
00056 wait(1, SC_SEC);
00057 during(500, SC_MS, boost::bind(&A::many_extra_time, this));
00058 L_COUT << "many_extra_time OK: " << sc_core::sc_time_stamp() << endl;
00059 }
00060
00061 SC_CTOR(A) {
00062 SC_THREAD(compute);
00063 m_counter = 0;
00064 }
00065
00066 void f() {
00067 m_counter++;
00068 };
00069 void g() {
00070 m_counter++;
00071 for (int j = 0; j < (M - 1); j++) {
00072 extra_time((BIL/N)/M, SC_NS);
00073 m_counter++;
00074 }
00075 };
00076 void many_extra_time() {
00077 int duration = BIL/(N*M)/2;
00078 L_COUT << N*M << " extra_time()s" << endl;
00079 measure_time t(name());
00080 for (int j = 0; j < N*M; j++) {
00081 extra_time(duration, SC_NS);
00082 }
00083 }
00084 void h() {
00085 L_COUT << "start h()" << endl;
00086 eat_cpu();
00087 L_COUT << "finish h()" << endl;
00088 }
00089 int m_counter;
00090 };
00091
00092 int sc_main(int argc, char *argv[])
00093 {
00094 if (argc > 1)
00095 N = atoi(argv[1]);
00096 cout << "N = " << N << endl;
00097 #ifdef NDEBUG
00098 cout << "release build" << endl;
00099 #else
00100 cout << "debug build" << endl;
00101 #endif
00102 A a("a");
00103 A b("b"), c("c");
00104 cout << "sc_main: " << sc_time_stamp() << endl;
00105 {
00106 measure_time t("Simple during tasks");
00107 sc_start(2, SC_SEC);
00108 }
00109 cout << "sc_main: " << sc_time_stamp() << endl;
00110 {
00111 measure_time t("During tasks with extra-time");
00112 sc_start(2, SC_SEC);
00113 }
00114 cout << "sc_main: " << sc_time_stamp() << endl;
00115 {
00116 measure_time t("eat_cpu, sequential");
00117 eat_cpu();
00118 }
00119 cout << "sc_main: " << sc_time_stamp() << endl;
00120 {
00121 measure_time t("eat_cpu in during tasks");
00122 sc_start(2, SC_SEC);
00123 }
00124 cout << "sc_main: " << sc_time_stamp() << endl;
00125 {
00126 measure_time t("many extra_time() in one task");
00127 sc_start(2, SC_SEC);
00128 }
00129 cout << "sc_main: " << sc_time_stamp() << endl;
00130 return 0;
00131 }