




























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
A lab guide for cs140 students to gain understanding of processors and their behavior. The lab focuses on calculating the cpi (cycles per instruction) for a given program using both c and java, and comparing their performance. Students are required to determine the number of instructions executed per loop in each mode and measure the influence of the operating system on the performance.
Typology: Slides
1 / 36
This page cannot be seen from the preview
Don't miss anything!
CS140 - Lab06 (^) 1
CS140 - Lab06 (^) 2
The purpose of this lab is to gain understanding of processors and their behavior. You will do this by writing code that “tickles” the processor, making it interact in a particular way; and from this you learn characteristics about that processor. You’re doing experiments on the hardware!
In this lab, you have five very specific tasks.
CS140 - Lab06 (^) 4
A note on compiler efficiency. I often compile code with the ability to debug. The “-g” switch does this. So if I say “gcc –g Prog06.c –o Prog06” I get an executable where I can use gdb – and a debugger is the greatest timesaver known to the programming world.
But this doesn’t produce efficient code – to get efficiency you need to compile with optimization “-O4”. While we’re on the topic of switches, the “-S” switch tells the compiler to produce assembler output and NOT to produce an executable.
The cycle speed of your computer can be determined as follows: On LINUX the file /proc/cpuinfo contains the rated processor speed, as well as lots of other goodies. On Windows Start Control Panel System tells you processor speed.
Appendix A.2 shows how to find the number of instructions in a cycle.
CS140 - Lab06 (^) 5
The code for my C and java programs is available to you – no need to type in lots of instructions. They can be found at Prog06.c and Prog06.java. Here you can also find Prog06.s and Prog06.exe The source code for these programs is also listed in Appendices A and B of this document.
The Task asked of you here is to determine the processor/compiler CPI. I’m showing you how I did this task so you can see a concrete example
Look at my Prog06.c and resulting .s file. My code accomplishes a very simple task
CS140 - Lab06 (^) 7
1. This is a repeat of the warmup on the last few slides: Look at my sample C and java programs. My code accomplishes a very simple task – just finding the sum of the numbers between 1 and 1,000,000. - Try calculating the CPI of my code: - Figure out how many instructions are required to accomplish the 1 million sum. - Time the number of seconds to accomplish that task. - What is the speed of the processors – the number of cycles/second. - Calculate the CPI - ALL THIS IS JUST WARMUP, because you should
CS140 - Lab06 (^) 8
Here’s how I filled in the sheet when I ran a part of a Task 1 experiment.
Task 1: CPI Calculation Program Run Compiler Used
Operating System
Original Prog06.exe
gcc Windows XP
Processor Name
Processor Cycle Speed
Instructions per loop
Loops per reporting period
Seconds in reporting period
Instructions executed per sec.
CPI
AMD Athlon XP 3000+
2,160,000, / sec or 2.16 GHz
4 1,000,000,000 0.937seconds 4,268,943,436 0.
CS140 - Lab06 (^) 10
Now you know that in any experimental design, when you have a whole list of things you can change, it’s important to change only one variable at a time.
What are the variables you have in this experiment? a) The processor and therefore the processor cycles/second b) The program to be run – we’ve discussed three options for this so far –
The POINT IS – when you design your experiment to compare three processors, you need to keep other variables the same.
CS140 - Lab06 (^) 11
Reporting: In the Show and Tell section, you will find a table like this to be filled out for your three different machines.
Task 1: CPI Calculation Program Run
Compiler Used
Operating System
Processor Name
Processor Cycle Speed
Instructions per loop
Loops per reporting period
Seconds in reporting period
Instructions executed per sec.
CPI
CS140 - Lab06 (^) 13
We want to compare the performance of C and Java. Keeping in mind our need to change only one variable, this experiment needs to be done on the same machine – you want to change ONLY language. Completion time means how long it takes to accomplish equal work. Timing should be for several iterations and should last for about 30 seconds each to ameliorate initial effects.
The steps are simple here:
Processor Cycle Speed
Program run Compiler Used
Operating System
Completion Time (secs) Intel Pentium 4 Core Duo
2.6 GHz MyCode.c Linux / Windows MyCode.java
CS140 - Lab06 (^) 14
The machines we have in the lab are dual core processors. You should read more about this, but the essence is that the processors can run two programs simultaneously. I would like to know what happens when you run two copies of your program at the same time – what is the execution time for each of the programs when running in this mode? How do the 2 executions interfere? Why?
To facilitate running multiple copies of a program, you should learn about “&” and running in the background. By the way, DO NOT RUN ON CSGATEWAY (younger) since this will clog up the machine. You should also learn some Useful LINUX commands including “&”, “ps aux”, “kill
Processor Cycle Speed
Program run Compiler Operating System
Completion Time (secs) C – 1 copy C – 2 copies Java – 1 copy Java – 2 copies
CS140 - Lab06 (^) 16
So here’s the question. Should the Operating System make any difference when running your code? There is of course only one way to find out the real answer – measure it. To do this, run your C or Java program on the same machine, but change only the OS that’s running. It’s possible to do this with our dual-booted lab machines.
4: Measure the influence of the Operating System
Processor Name
Processor Cycle Speed
Program run Operating System
Compiler Completion Time
Intel Pentium 4 Core Duo
2.6 GHz MyCode.c OR MyCode.java
Linux etc.
Linux etc.
CS140 - Lab06 (^) 17
Determine the number of processor cycles that are lost when a branch is mispredicted. You want one number – BUT there are a number of steps and lots of required documentation to get this number.
Here you work only with the program I’m providing. Branch.c can be downloaded and the source is also available in Appendix C of this document. You are also given one (1) brain.
This program provides a way to outsmart the processor – to ensure that the processor can not predict whether a branch will be taken or not. This is difficult to do – the processor is VERY smart and only by going to random branching can we fool it. Look at the code in Appendix C to understand how this is done.
CS140 - Lab06 (^) 19
Fill in the table on the next page. Bring it to lab.
Determine the number of cycles in an instruction loop in branch.s when the code is correctly predicted and when it is miss-predicted. How many cycles does the Pentium 4 lose on that one instruction as a result of miss-prediction?
When all else fails, and you don’t understand these instructions, don’t blindly follow your misunderstanding. Go back to the previous pages and understand the goal. Then do it the best you can. This is difficult stuff!
CS140 - Lab06 (^) 20
Branch Misprediction Work Sheet Mode Hz Execution Time
Instr / Loops (using stepi)
Instr loop
Instr / second
Machine Cycles / Loop
CPI
This table can help you with the calculation
Mode – Which mode (0,1,2) we’re running in. Hz -- What is the cycle speed of the processor (normally in GHz) Execution Time – How long does it take to execute the program Instr / Loops - From the Appendix C2, how many instructions are there in a loop? Instr loop - How many instruction loops were executed in the reported time. Instr / second – Calculate the number of instructions executed in one second. Machine Cycles/Loop – How many machine cycles were required to execute the number of instructions in one loop? CPI – what is the CPI for the program running in this mode?