COMP 3000 Lab 2 2011

From Soma-notes

Please answer using text files. Do not use doc, docx, pdf etc.

Part A (in Tutorial)

  1. Copy the ISO images from the class DVD to your computer (or get them from the COMP 3000 support folder, from here, or just download them from the Internet). Boot at least two of the ISOs in Virtualbox or VMware Player by creating a new virtual machine and using the ISO for the virtual CD drive. Where possible, start the "live CD", e.g., "Try Ubuntu". Note that some of the distributions may not work in some VMs (e.g., minix may crash on both VirtualBox and VMware Player). For at least two distributions:
    1. Roughly how long did the VM take to boot completely? (2 points - 1 mark for each .iso tested)
    2. How similar is the environment to that available on the Lambda SCS hosts? (Say in a few sentences.) (2 points - 1 mark for each .iso tested)
  2. Create an account on the class wiki. What username did you choose? (1 point)
  3. Look at /proc/cpuinfo in a Linux virtual machine (any distribution). Is the "guest" CPU the same as that reported by the Windows "host"? (You can find out system information in Windows by running "msinfo32".) (1 point)
  4. Examine the PCI devices as reported by the command line program "lspci" and identify the video card. Is this "virtual" video card the same as the "real" one that Windows uses? (1 point)
  5. Compile the program hello.c (below) with gcc -O hello.c -o hello-dyn and then run it using the command ltrace ./hello-dyn . What dynamic functions does the program call? (1 point)
  6. Compile the same program with gcc -O -static hello.c -o hello-static . Run this second binary with ltrace as before. What dynamic functions does the program now call? (1 point)
  7. Run strace on the static and dynamically compiled versions of hello. How many system calls do they each produce? (2 marks - 1 for static list, 1 for dynamic list)
  8. How can you make the output of hello.c go to the file "hello-output" by changing how it is invoked at the command line? (1 point)
  9. How can you make the output of hello.c go to the file "hello-output" by changing its code? (1 point)
/* hello.c */
#include <stdio.h>
#include <unistd.h>

int main(int argc, char *argv[])
{
       printf("Hello, world!\n");
       return 0;
}

Part B (on your own)

  1. Typically, what does a guest OS's hard disk look like to the host OS? (1 point)
  2. Do guest OSs need the same device drivers as host OSs? Why? (1 point)
  3. Why do we "open" files? Specifically, to what extent is it possible to do file I/O without open and close operations - assuming you could change the UNIX API? (1 point)
  4. What is the relationship between dynamic library calls and system calls? (1 point)
  5. What type of programs should run at near-native efficiency within a virtual machine? Why? (1 point)
  6. What type of programs should be significantly slower within a virtual machine? Why? (1 point)
  7. What are two strategies for accelerating programs that are slow within VMs? (1 point)
  8. What are "guest additions" for VMs? What are they for? (1 point)
  9. Compile and run the code (below) to compare their run times on the host and on the virtual machines. Both Linux and Windows code is provided - use appropriately. Report in percentage how much slower is a VM compared to a host machine. What if you run them both simultaneously? (3 points)
  10. Bonus Question - Write code ( or modify the ones below ) to perform Disk I/O ( write to a file and read from it ) and report their performances on host and virtual machines. (5 points)
/* perf.c for linux */
#include <stdio.h>
#include <time.h>

#define TIMEVARS() clock_t start, stop; double sec
#define TIMESTART(msg) printf(msg "..."); fflush(stdout); start = clock()
#define TIMESTOP()   stop = clock(); \
sec = ((double)(stop-start))/CLOCKS_PER_SEC; \
printf("done (%.3f seconds)\n", sec)  

int main()
{
        int n1 = 12345,n2 = 188765;
        int i= 0 ,j=0,composite = 0;
        TIMEVARS();
        TIMESTART("Starting work");
        for(i = n1; i < n2; i++) {
                for(j = 2; j < i; j++) {
                        if (i%j == 0) {
                                composite++;
                                break;
                        }
                }
        }
        TIMESTOP();
        printf("%d primes found between %d and %d\n",n2-n1 - composite,n1,n2);
        return 0;

}
/* perf.c for windows - compile using Visual Studio C++ compiler 2010 */
#include "stdafx.h"
#include <cstdio>
#include <ctime>

#define TIMEVARS() clock_t start, stop; double sec
#define TIMESTART(msg) printf(msg "..."); fflush(stdout); start = clock()
#define TIMESTOP()   stop = clock(); \
sec = ((double)(stop-start))/CLOCKS_PER_SEC; \
printf("done (%.3f seconds)\n", sec)

int _tmain(int argc, _TCHAR* argv[])
{
        int n1 = 12345,n2 = 188765;
        int i= 0 ,j=0,composite = 0;
        TIMEVARS();
        TIMESTART("Starting work");
        for(i = n1; i < n2; i++) {
                for(j = 2; j < i; j++) {
                        if (i%j == 0) {
                                composite++;
                                break;
                        }
                }
        }
        TIMESTOP();
        printf("%d primes found between %d and %d\n",n2-n1 - composite,n1,n2);
        return 0;

}