/[cmucl]/src/benchmarks/richards/richards.c
ViewVC logotype

Contents of /src/benchmarks/richards/richards.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations)
Wed Feb 19 18:00:46 1992 UTC (22 years, 2 months ago) by ram
Branch: MAIN
CVS Tags: sparc-tramp-assem-base, double-double-array-base, post-merge-intl-branch, release-19b-pre1, release-19b-pre2, merged-unicode-utf16-extfmt-2009-06-11, double-double-init-sparc-2, unicode-utf16-extfmt-2009-03-27, double-double-base, snapshot-2007-09, snapshot-2007-08, snapshot-2008-08, snapshot-2008-09, ppc_gencgc_snap_2006-01-06, sse2-packed-2008-11-12, snapshot-2008-05, snapshot-2008-06, snapshot-2008-07, snapshot-2007-05, snapshot-2008-01, snapshot-2008-02, snapshot-2008-03, intl-branch-working-2010-02-19-1000, snapshot-2006-11, snapshot-2006-10, double-double-init-sparc, snapshot-2006-12, unicode-string-buffer-impl-base, sse2-base, release-20b-pre1, release-20b-pre2, unicode-string-buffer-base, sse2-packed-base, sparc-tramp-assem-2010-07-19, amd64-dd-start, snapshot-2003-10, snapshot-2004-10, release-18e-base, release-19f-pre1, snapshot-2008-12, snapshot-2008-11, intl-2-branch-base, snapshot-2004-08, snapshot-2004-09, remove_negative_zero_not_zero, snapshot-2007-01, snapshot-2007-02, snapshot-2004-05, snapshot-2004-06, snapshot-2004-07, release-19e, release-19d, GIT-CONVERSION, double-double-init-ppc, release-19c, dynamic-extent-base, unicode-utf16-sync-2008-12, LINKAGE_TABLE, release-19c-base, cross-sol-x86-merged, label-2009-03-16, release-19f-base, PRE_LINKAGE_TABLE, merge-sse2-packed, mod-arith-base, sparc_gencgc_merge, merge-with-19f, snapshot-2004-12, snapshot-2004-11, intl-branch-working-2010-02-11-1000, unicode-snapshot-2009-05, unicode-snapshot-2009-06, amd64-merge-start, ppc_gencgc_snap_2005-12-17, double-double-init-%make-sparc, unicode-utf16-sync-2008-07, release-18e-pre2, unicode-utf16-sync-2008-09, unicode-utf16-extfmts-sync-2008-12, prm-before-macosx-merge-tag, cold-pcl-base, RELEASE_20b, snapshot-2008-04, snapshot-2003-11, snapshot-2005-07, unicode-utf16-sync-label-2009-03-16, RELEASE_19f, snapshot-2007-03, release-20a-base, cross-sol-x86-base, unicode-utf16-char-support-2009-03-26, unicode-utf16-char-support-2009-03-25, release-19a-base, unicode-utf16-extfmts-pre-sync-2008-11, snapshot-2008-10, sparc_gencgc, snapshot-2007-04, snapshot-2010-12, snapshot-2010-11, unicode-utf16-sync-2008-11, snapshot-2007-07, snapshot-2011-09, snapshot-2011-06, snapshot-2011-07, snapshot-2011-04, snapshot-2007-06, snapshot-2011-02, snapshot-2011-03, snapshot-2011-01, snapshot-2003-12, release-19a-pre1, release-19a-pre3, release-19a-pre2, pre-merge-intl-branch, release-19a, UNICODE-BASE, double-double-array-checkpoint, double-double-reader-checkpoint-1, release-19d-base, release-19e-pre1, double-double-irrat-end, release-19e-pre2, snapshot-2010-05, snapshot-2010-04, snapshot-2010-07, snapshot-2010-06, snapshot-2010-01, snapshot-2010-03, snapshot-2010-02, release-19d-pre2, release-19d-pre1, snapshot-2010-08, release-18e, double-double-init-checkpoint-1, double-double-reader-base, label-2009-03-25, snapshot-2005-03, release-19b-base, cross-sol-x86-2010-12-20, double-double-init-x86, sse2-checkpoint-2008-10-01, intl-branch-2010-03-18-1300, snapshot-2005-11, double-double-sparc-checkpoint-1, snapshot-2004-04, sse2-merge-with-2008-11, sse2-merge-with-2008-10, snapshot-2005-10, RELEASE_20a, snapshot-2005-12, release-20a-pre1, snapshot-2005-01, snapshot-2009-11, snapshot-2009-12, unicode-utf16-extfmt-2009-06-11, portable-clx-import-2009-06-16, unicode-utf16-string-support, release-19c-pre1, cross-sparc-branch-base, release-19e-base, intl-branch-base, double-double-irrat-start, snapshot-2005-06, snapshot-2005-05, snapshot-2005-04, ppc_gencgc_snap_2005-05-14, snapshot-2005-02, unicode-utf16-base, portable-clx-base, snapshot-2005-09, snapshot-2005-08, lisp-executable-base, snapshot-2009-08, snapshot-2007-12, snapshot-2007-10, snapshot-2007-11, snapshot-2009-02, snapshot-2009-01, snapshot-2009-07, snapshot-2009-05, snapshot-2009-04, snapshot-2006-02, snapshot-2006-03, release-18e-pre1, snapshot-2006-01, snapshot-2006-06, snapshot-2006-07, snapshot-2006-04, snapshot-2006-05, pre-telent-clx, snapshot-2006-08, snapshot-2006-09, HEAD
Branch point for: release-19b-branch, double-double-reader-branch, double-double-array-branch, mod-arith-branch, RELEASE-19F-BRANCH, portable-clx-branch, sparc_gencgc_branch, cross-sparc-branch, RELEASE-20B-BRANCH, unicode-string-buffer-branch, sparc-tramp-assem-branch, dynamic-extent, UNICODE-BRANCH, release-19d-branch, ppc_gencgc_branch, sse2-packed-branch, lisp-executable, RELEASE-20A-BRANCH, amd64-dd-branch, double-double-branch, unicode-string-buffer-impl-branch, intl-branch, release-18e-branch, cold-pcl, unicode-utf16-branch, cross-sol-x86-branch, release-19e-branch, sse2-branch, release-19a-branch, release-19c-branch, intl-2-branch, unicode-utf16-extfmt-branch
File MIME type: text/plain
Initial revision
1 /* richards.c - Richards Benchmark in C++ */
2 /* uh 2/2/89 */
3
4 #include <time.h>
5 #define clock_t long /* because Sun library isn't ANSI */
6 #define CLK_TCK 1000000
7 #include "richards.h"
8
9
10 /*
11 // creation
12 */
13
14 void RBench::CreateDevice (Identity id, int prio, Packet *work,
15 TaskState *state)
16 { DeviceTaskRec *data;
17 TaskControlBlock *t;
18
19 data = new DeviceTaskRec;
20 t = new DeviceTCB(taskList, id, prio, work, state, data);
21 EnterTask(id, t);
22 }
23
24
25 void RBench::CreateHandler(Identity id, int prio, Packet *work,
26 TaskState *state)
27 { HandlerTaskRec *data;
28 TaskControlBlock *t;
29
30 data = new HandlerTaskRec;
31 t = new HandlerTCB(taskList, id, prio, work, state, data);
32 EnterTask(id, t);
33 }
34
35
36 void RBench::CreateIdler (Identity id, int prio, Packet *work,
37 TaskState *state)
38 { IdleTaskRec *data;
39 TaskControlBlock *t;
40
41 data = new IdleTaskRec;
42 t = new IdlerTCB(taskList, id, prio, work, state, data);
43 EnterTask(id, t);
44 }
45
46
47 void RBench::CreateWorker (Identity id, int prio, Packet *work,
48 TaskState *state)
49 { WorkerTaskRec *data;
50 TaskControlBlock *t;
51
52 data = new WorkerTaskRec;
53 t = new WorkerTCB(taskList, id, prio, work, state, data);
54 EnterTask(id, t);
55 }
56
57
58 void RBench::EnterTask(Identity id, TaskControlBlock *t)
59 {
60 taskList = t;
61 taskTable[id] = t;
62 }
63
64
65 /*
66 //private
67 */
68
69 TaskControlBlock *RBench::FindTask(Identity id)
70 { TaskControlBlock *t;
71
72 t = taskTable[id];
73 if (t == NULL) printf("***error: FindTask failed! ");
74 return t;
75 }
76
77
78 TaskControlBlock *RBench::HoldSelf()
79 {
80 holdCount++;
81 currentTask->SetTaskHolding(TRUE);
82 return currentTask->Link();
83 }
84
85
86 TaskControlBlock *RBench::QueuePacket(Packet *p)
87 { TaskControlBlock *t;
88
89 t = FindTask(p->Ident());
90 queuePacketCount++;
91 p->SetLink(NoWork);
92 p->SetIdent(currentTaskIdent);
93 return t->AddPacket(p, currentTask);
94 }
95
96
97 TaskControlBlock *RBench::Release(Identity id)
98 { TaskControlBlock *t;
99
100 t = FindTask(id);
101 t->SetTaskHolding(FALSE);
102 return (t->Priority() > currentTask->Priority()) ? t : currentTask;
103 }
104
105
106 void RBench::Trace(Identity id)
107 {
108 if(! --layout) {printf("\n"); layout = 50;}
109 printf("%d", id + 1);
110 }
111
112
113 TaskControlBlock *RBench::Wait()
114 {
115 currentTask->SetTaskWaiting(TRUE);
116 return currentTask;
117 }
118
119
120 /*
121 //scheduling
122 */
123
124 void RBench::Schedule()
125 {
126 currentTask = taskList;
127 while (currentTask != NoTask) {
128 if (currentTask->IsTaskHoldingOrWaiting())
129 currentTask = currentTask->Link();
130 else {
131 currentTaskIdent = currentTask->Ident();
132 if (tracing) Trace(currentTaskIdent);
133 currentTask = currentTask->RunTask();
134 }
135 }
136 }
137
138 /*
139 //initializing
140 */
141
142 void RBench::InitScheduler()
143 {
144 queuePacketCount = 0;
145 holdCount = 0;
146 for (int i = 0; i < NTASKS; i++) {taskTable[i] = NoTask;}
147 taskList = NoTask;
148 }
149
150
151 void RBench::InitTrace()
152 { char c;
153
154 printf("Trace (y/n)? ");
155 c = getchar();
156 tracing = (_toupper(c) == 'Y');
157 }
158
159
160 void RBench::Start(BOOLEAN trace) {
161 // clock_t t1, t2, t3, t4;
162 TaskState *t;
163 Packet *workQ;
164
165 if (trace) InitTrace(); else tracing = FALSE;
166 InitScheduler();
167 // t1 = clock();
168 // printf("\nRichards benchmark: initializing...\n");
169 t = new TaskState; t->Running(); // Idler
170 CreateIdler(Idler, 0, NoWork, t);
171
172 workQ = new Packet(NoWork, Worker, WorkPacket); // Worker
173 workQ = new Packet(workQ , Worker, WorkPacket);
174 t = new TaskState; t->WaitingWithPacket();
175 CreateWorker(Worker, 1000, workQ, t);
176
177 workQ = new Packet(NoWork, DeviceA, DevicePacket); // HandlerA
178 workQ = new Packet(workQ , DeviceA, DevicePacket);
179 workQ = new Packet(workQ , DeviceA, DevicePacket);
180 t = new TaskState; t->WaitingWithPacket();
181 CreateHandler(HandlerA, 2000, workQ, t);
182
183 workQ = new Packet(NoWork, DeviceB, DevicePacket); // HandlerB
184 workQ = new Packet(workQ , DeviceB, DevicePacket);
185 workQ = new Packet(workQ , DeviceB, DevicePacket);
186 t = new TaskState; t->WaitingWithPacket();
187 CreateHandler(HandlerB, 3000, workQ, t);
188
189 t = new TaskState; t->Waiting(); // DeviceA
190 CreateDevice(DeviceA, 4000, NoWork, t);
191 t = new TaskState; t->Waiting(); // DeviceB
192 CreateDevice(DeviceB, 5000, NoWork, t);
193
194 // printf("starting...\n");
195 // t2 = clock();
196 Schedule();
197 // t3 = clock();
198 // printf("done.\n");
199
200 // printf("QueuePacketCount = %d, HoldCount = %d.\nThese results are %s",
201 // queuePacketCount, holdCount,
202 // (queuePacketCount == 23246 && holdCount == 9297) ?
203 // "correct." : "wrong!"
204 // );
205 if (! (queuePacketCount == 23246 && holdCount == 9297)) {
206 printf("error: richards results are incorrect\n");
207 }
208
209 // t4 = clock();
210 // printf("\nScheduler time = %g seconds, total time = %g\n",
211 // (double)(t3 - t2) / CLK_TCK,
212 // (double)(t4 - t1) / CLK_TCK);
213 }
214
215
216 #define ITER 10 /* # of iterations in main loop */
217
218 int main()
219 { clock_t t_start, t_stop;
220
221 t_start = clock();
222 for (int i = 0; i < ITER; i++)
223 bm.Start(ITER == 1);
224 t_stop = clock();
225
226 clock_t diff = (t_stop - t_start)/ITER;
227
228 printf("richards: %d ms\n", diff/(CLK_TCK/1000));
229
230 // if (ITER > 1)
231 // printf("\n*** %d iterations, average of %g secs / iteration.\n",
232 // ITER,
233 // (double)(t_stop - t_start) / (ITER * CLK_TCK));
234 }
235

  ViewVC Help
Powered by ViewVC 1.1.5