Starting from:
$30

$24

Assignment 01 Solution

Tasks



The objective of this assignment is to figure out exactly how fast the new system call instructions are compared to the old method. Make sure you have a 64-bit POSIX-compliant operating system installed on your machine.




Write an assembly program with the following code and name it hello.asm. This program simply uses the int instruction 500,000 times to write the dot character on the console.


























































































2. Compile the program using the command:




nasm -f elf64 hello.asm




Note: If you don’t have nasm installed, you can issue the following command to install it.




sudo apt install nasm




Also issue the following if you get an error on the ld command below:




sudo apt install build-essential




3. Link the object file using the following command:




ld -s -o hello hello.o







CS220 Operating Systems (Spring 2020 - Assignment 01) Page 1 of 3
4. Run the new executable:




./hello




As you will see, this will keep going for a while since 500,000 dots are going to take a while. We’re only interested in seeing how long it takes to actually issue all the interrupts. So, modify the execution command above to the following:



time ./hello /dev/null




You don’t have to understand how this command works but the summary is: it uses the time utility to provide precise statistics of how long the command takes and the final part ensures that any output produced by the command is essentially ignored. (You may cover this in detail in the lab or course later).




6. Now create another assembly file and name it hello2.asm. Put the following content in it:
























































































As you can see, this is the same logic but instead of the int instruction, we are using the syscall instruction which is the 64-bit equivalent of the 32-bit sysenter command you have studied. Rest of the logic should be self-evident.




Compile both of the files and link them using the following commands:






















You can go ahead and compile and run this code as before. However, for the sake of our original problem of finding out which one of these two is the faster one, you are provided with a runner file. This is runner.sh. You may look at the contents of the file.



The purpose of the runner is to run hello and hello2 one by one. This pair is executed 50 times and the results of execution times of each are saved in hello.txt and hello2.txt respectively.




Make sure you have runner.sh saved in the same directory as your assembly files and you are in the same working directory. First, you need to make runner executable:




chmod +x runner.sh













CS220 Operating Systems (Spring 2020 - Assignment 01) Page 2 of 3
After that, execute it:




./runner.sh




This should take a while but after it is done, you should have the two text files in the current working directory.




The contents of these directories are times for each individual run. A sample looks like this:




real 0m0.553s

user 0m0.242s

sys 0m0.335s




We are interested in the user times. For each of the files, you need to calculate the average of the user time taken across the 50 experiments.




Submission



Provide screenshots of everything you have done in one PDF file. Other formats will not be accepted and you will get no credit if you provide another format.




At the top of the PDF, clearly provide the following statistics:




Number of experiments run:
N =
Average
‘user time’ for
hello (int-based calls):
I =
Average
‘user time’ for
hello2 (syscall-based calls):
S =
Percentage speedup: (I-S)*100/I
=



You may use any method/tool/software you chose to calculate the averages.































Note: Some points to consider about this assignment are: why did we issue 500k syscalls? Why not less or more? Also, why did we run the experiment 50 times? Finally, why did we have to interleave hello and hello2. Why not run hello 50 times first and then hello2 the same number of times?




Answers to these are not a part of the assignment but you should consider them nonetheless.















































































CS220 Operating Systems (Spring 2020 - Assignment 01) Page 3 of 3

More products