CS 111 Spring 2010: Lecture 3 Scribe Notes

Lecture Topic: Modularity and virtualization

Scribed by: Kyungtae Kwon, Spencer Sutterlin, Nim Nahum, James Galvan

 


Problems with last week's stand-alone application:

  1. The read_sector() function has multiple copies: in the MBR, VBR, application, and BIOS. In order to avoid multiple copies of read_sector(), we keep only one in the BIOS and publish it so it is available in the other areas. In fact, BIOS stands for Basic Input Output System. One advantage to doing it this way is that it needs only one person to maintain it. Another advantage is that it is standardized. It also has disadvantages, two examples being that it is neither flexible nor portable.
    + 1 copy/maintainer, standardized
    - very inflexible

  2. Performance is an issue. By using DMA (Direct Memory Access), we can make I/O faster. The old method: The bus is used twice. Once for data to move from the disk controller to the CPU, and once for it to move between the CPU and the RAM.

    We have:                                                                             We want Direct Memory Access:
    cpuramdisk
    DMA: The controller talks to the RAM directly to send data, and notifies the CPU when it is done. This means that our previously defined read_sector() function has to be redefined to accomodate these operations.

  3. Double Buffering (Overlapping reading and counting) Instead of the traditional method of running operations one at a time, we can run two operations concurrently in parallel, by the use of an extra buffer. The following picture may illustrate this better.

    read    ----  ----  ----  ----  ----
    count       --    --    --    --    --

            A    B    A    B    A             Need 2 buffers
    read    ---------------------------       Read into a new buffer
                 A    B    A    B    A        Count first buffer
    count       --   --   --   --   --

    Double buffering can thus speed up the performance of our O/S. The biggest performance increase is if counting and reading take the same amount of time, We can consider the use of triple buffering to run 3 different processes at one time to solve overhead problems, but there may be the problem of the HDD being able to read only one sector at a time. Again, to do this many of our previously defined functions have to be rewritten.

  4. The application is too much of a pain to maintain. Difficulty to make changes to the application or reuse pieces of the application's code may be due to a large number of components or a large number of interconnections between components, or may be due to irregularity in the code or the code may be lacking a methodical description. These problems are symptoms of complexity.

How to cope with complexity:


Redefining the API

readsectorTOread

-> Because the ability to read a sector has been taken away, and all that remains to seek to a spot is the offset, there is also a function lseek to move the pointer to the desired spot

off_t lseek (int fd, off_t b, int flag)

x86 Review in 10 minutes

	1 int fact (int n) {
	2 	if (n == 0) 
	3 		return 1;
	4 	return n*fact(n-1);
	5 }
		
	fact:
		pushl %ebp		//save fp
		movl $1, %eax		//ax=1
		movl %esp, %ebp		//fp=sp
		subl $8, %esp		//sp-=8
		movl %ebx, -4(%ebp)	//save bx
		movl 8(%ebp), %ebx	//bx=n
		testl %ebx, %ebx	//is n==0?
		jne .L5			//if nonzero go to L5
  	.L1	movl -4(%ebp), %ebx	//restore bx
		movl %ebp, %esp		//restore sp
		popl %ebp		//restore fp
		ret			//pop stack, go there
  	.L5	leal -1(%ebx), %eax	//ax=bx-1
		movl %eax, (%esp)	//*sp=ax
		call fact		//pushes return address on stack/jumps to fact
		imull %ebx, %eax	//result*=n
		jmp .L1
		

              stack


Review: How to enforce modularity - function calls