00001
00002
00003
00004
00005
00006
00014 #include <systemc>
00015 #include "utils/measure-time.h"
00016 #include <unistd.h>
00017
00018 using namespace std;
00019 using namespace sc_core;
00020
00021 #define BIL 1000000000
00022 int N = 10000;
00023 #define M 100
00024
00025 void eat_cpu() {
00026 int dummy_counter;
00027 for (int i = 0; i < N; i++) {
00028 for (int j = 0; j < 42000; j++) {
00029 dummy_counter++;
00030 __asm("");
00031 }
00032 }
00033 }
00034
00035 SC_MODULE(A)
00036 {
00037 void compute() {
00038 wait(2, SC_SEC);
00039 cout << name() << ": done first wait @" << sc_time_stamp() << endl;
00040 wait(1, SC_SEC);
00041 {
00042 measure_time t("wait (time)");
00043
00044 for (int i = 0; i < 500000; i++) {
00045 wait(2, SC_US);
00046
00047 }
00048 }
00049 wait(1, SC_SEC);
00050 cout << name() << ": done 500000 waits @" << sc_time_stamp() << endl;
00051 wait(1, SC_SEC);
00052 for (int i = 0; i < 500000; i++)
00053 wait(SC_ZERO_TIME);
00054 cout << name() << ": done 500000 waits(0) @" << sc_time_stamp() << endl;
00055 wait(1, SC_SEC);
00056 }
00057
00058 SC_CTOR(A) {
00059 SC_THREAD(compute);
00060 m_counter = 0;
00061 }
00062
00063 void f() {
00064 m_counter++;
00065 };
00066 void h() {
00067 cout << "start h()" << endl;
00068 eat_cpu();
00069 cout << "finish h()" << endl;
00070 }
00071 int m_counter;
00072 };
00073
00074 int sc_main(int argc, char *argv[])
00075 {
00076 A a1("a1"), a2("a2");
00077 if (argc > 1)
00078 N = atoi(argv[1]);
00079 cout << "N = " << N << endl;
00080 #ifdef NDEBUG
00081 cout << "release build" << endl;
00082 #else
00083 cout << "debug build" << endl;
00084 #endif
00085 {
00086 measure_time t("nothing");
00087 }
00088 {
00089 measure_time t("first sc_start()");
00090 sc_start(250, SC_MS);
00091 }
00092 {
00093 measure_time t("second sc_start()");
00094 sc_start(250, SC_MS);
00095 }
00096 {
00097 measure_time t("1000 sc_start() (nothing in simulation)");
00098 for (int i = 0; i < 1000; i++)
00099 sc_start(1, SC_MS);
00100 }
00101 cout << "main(): t1 = " << sc_time_stamp() << endl;
00102 sc_start(1, SC_SEC);
00103 {
00104 measure_time t("1,000,000 waits(time)");
00105 sc_start(2, SC_SEC);
00106 }
00107 cout << "main(): t2 = " << sc_time_stamp() << endl;
00108 sc_start(1, SC_SEC);
00109 {
00110 measure_time t("1,000,000 waits(0)");
00111 sc_start(1, SC_SEC);
00112 }
00113 cout << "main(): t3 = " << sc_time_stamp() << endl;
00114
00115 return 0;
00116 }