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 wait(500, SC_MS);
00041 during(0, SC_MS, boost::bind(&A::many_extra_time, this));
00042 L_COUT << "many_extra_time OK: " << sc_core::sc_time_stamp() << endl;
00043 during(1, SC_SEC, boost::bind(&A::many_extra_time, this));
00044 L_COUT << "many_extra_time OK: " << sc_core::sc_time_stamp() << endl;
00045 }
00046
00047 void slow_down() {
00048 wait(2, SC_SEC);
00049 L_COUT << "start sleeping" << endl;
00050 sleep(2);
00051 L_COUT << "end sleeping" << endl;
00052 wait(2, SC_SEC);
00053 }
00054
00055 SC_CTOR(A) {
00056 SC_THREAD(compute);
00057 SC_THREAD(slow_down);
00058 }
00059
00060 void many_extra_time() {
00061 int duration = BIL/(N*M);
00062 usleep(1000);
00063 L_COUT << N*M << " extra_time()s" << endl;
00064 measure_time t(name());
00065 for (int j = 0; j < N*M; j++) {
00066 extra_time(duration, SC_NS);
00067 }
00068 }
00069 };
00070
00071 int sc_main(int argc, char *argv[])
00072 {
00073 if (argc > 1)
00074 N = atoi(argv[1]);
00075 cout << "N = " << N << endl;
00076 #ifdef NDEBUG
00077 cout << "release build" << endl;
00078 #else
00079 cout << "debug build" << endl;
00080 #endif
00081 A a("a");
00082 cout << "sc_main: " << sc_time_stamp() << endl;
00083 {
00084 measure_time t("many extra_time() in one task");
00085 sc_start(2, SC_SEC);
00086 }
00087 cout << "sc_main: " << sc_time_stamp() << endl;
00088 sc_start();
00089 return 0;
00090 }