COMP 3000 Lab 2 2011

From Soma-notes
Revision as of 14:36, 26 September 2011 by Saran (talk | contribs) (performance on vm Code)

Part B (on your own)

  1. Typically, what does a guest OS's hard disk look like to the host OS?
  2. Do guest OSs need the same device drivers as host OSs? Why?
  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?
  4. What is the relationship between dynamic library calls and system calls?
  5. What type of programs should run at near-native efficiency within a virtual machine? Why?
  6. What type of programs should be significantly slower within a virtual machine? Why?
  7. What are two strategies for accelerating programs that are slow within VMs?
  8. What are "guest additions" for VMs? What are they for?
/* 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;

}