From lego-robotics-return-5165-nelson=crynwr.com@crynwr.com Fri Feb 12 13:05:04 1999 X-VM-v5-Data: ([nil nil nil nil nil nil nil nil nil] [nil nil nil nil nil nil nil nil nil nil nil nil "^From:" nil nil nil nil nil nil nil nil] nil) Return-Path: Delivered-To: nelson@desk.crynwr.com Received: (qmail 6708 invoked from network); 12 Feb 1999 13:05:03 -0000 Received: from ns.crynwr.com (192.203.178.14) by desk.crynwr.com with SMTP; 12 Feb 1999 13:05:03 -0000 Received: (qmail 18767 invoked by uid 500); 12 Feb 1999 13:01:36 -0000 Delivered-To: nelson@crynwr.com Received: (qmail 18756 invoked by alias); 12 Feb 1999 13:01:35 -0000 Mailing-List: contact lego-robotics-help@crynwr.com; run by ezmlm Delivered-To: mailing list lego-robotics@crynwr.com Received: (qmail 18728 invoked by uid 0); 12 Feb 1999 13:01:34 -0000 Received: from lugnet.com (209.68.63.236) by pdam.crynwr.com with SMTP; 12 Feb 1999 13:01:34 -0000 Received: by lugnet.com (8.9.0/8.6.12) id IAA23057; Fri, 12 Feb 1999 08:01:02 -0500 (EST) X-Envelope-To: lego-robotics@crynwr.com X-Loop: lugnet.robotics@lugnet.com X-Message-Archive: http://www.lugnet.com/news/display.cgi?lugnet.robotics:3619 X-Real-Life-Name: Dick Swan Errors-To: news-errors@lugnet.com Posted-Date: Wed, 10 Feb 1999 03:29:03 GMT Organization: None Message-ID: Precedence: list From: "Dick Swan" Sender: news-gateway@lugnet.com To: lego-robotics@crynwr.com Subject: CPU Time Required for RCX Instructions Date: Wed, 10 Feb 1999 03:29:03 GMT Someone recently asked how long it took to execute an RCX instruction. My measurements show there is there is 1.75 msec of processing involved between calls to the "RCX instruction loop" which then spends about 0.20 msec per active task executing one opcode. More details follow. Knowledge from pervious posts is that the RCX periodically executes the "RCX instruction loop". The "RCX instruction loop" then checks each of the ten possible tasks in turn and if ready to run executes one instruction. [I may not have this quite right -- someone correct me if I'm wrong]. Hence one to 10 instructions can be executed dependent on the number of active tasks. I measured the following: 1.75 msec (milli-seconds) of "outside" CPU work time required between finish and start time of "RCX instruction loop" calls. 0.17 msec CPU time used to execute a assignment statement ("j = 0") 0.35 msec CPU time to execute a motor off command. 0.26 msec CPU time to execute a cleartimer() command. I ran each instruction type in three configurations to measure the impact of multiple tasks operating. The configurations were with one, two and five tasks operating simultaneously. The measured time (in msec) was: # of Tasks 001 002 005 assignment 1.92 2.10 2.67 motor off 2.09 2.44 3.50 clearTimer 2.03 2.29 3.07 Solving the simple linear equation yielded the approximately 1.75 msec overhead time plus the time for each opcode. ---------------------------------------------------------- For those interested, the actual program code used to perform the timing is given below. It uses a (hopefully) about to be released for beta-testing "C++ like" compiler. This code shows off a few of the capabilities of this development system including: - class declarations for 'timer' and 'motor' types. The actual definition and method statements are in an "#include" file. that is not shown. Base and derived classes are supported. ['new' and 'delete' operators are not supported!] - scope rules on variables with memory overlays / re-use where appropriate to maximize reuse the critical 32 memory variables of the RCX. - "for" loops. - inline procedures and functions. Use of inline procedure allows separate instance of the "measureIt" procedure to be executing in each of the five tasks and each instance has its own allocated local variables. timer time(T1); timer time2(T2); motor left(A); inline measureIt() { int i, elapsed, loopOverheadTime; elapsed = time; // // Perform empty loop to calculate overhead of looping // for (i = 0; i < 500; ++i) {} loopOverheadTime = time - elapsed; // // Now perform the loop with instructions this time // elapsed = time; for (i = 0; i < 500; ++i) { left.off(); left.off(); left.off(); left.off(); left.off(); left.off(); left.off(); left.off(); left.off(); left.off(); left.off(); left.off(); left.off(); left.off(); left.off(); left.off(); left.off(); left.off(); left.off(); left.off(); } // // Subtract out the loop overhead processing time and we have // the time required to execute 10,000 instances of "left.off()" // elapsed = time - elapsed - loopOverheadTime; return; } task secondTask() {measureIt();} task thirdTask() {measureIt();} task fourthTask() {measureIt();} task fifthTask() {measureIt();} { time.clear(); setDisplay(1); startTask(secondTask); startTask(thirdTask); startTask(fourthTask); startTask(fifthTask); measureIt(); setDisplay(3); // so we know when it is done playSound(1); return; } -- Did you check the web site first?: http://www.crynwr.com/lego-robotics