+ All Categories
Home > Documents > Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output...

Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output...

Date post: 19-Jan-2016
Category:
Upload: luke-butler
View: 220 times
Download: 0 times
Share this document with a friend
65
Mid2 Revision & VM Prof. Sin-Min Lee
Transcript
Page 1: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

Mid2 Revision & VM

Prof. Sin-Min Lee

Page 2: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

Classification of Digital Circuits

• Combinational.– Output depends only on current input values.

• Sequential.– Output depends on current input values and

present state of the circuit, where the present state of the circuit is the current value of the devices’ memory.

– Also called finite state machines.

Page 3: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

Edge Triggered D Flip-Flop

• This flip-flop is made out of two D latches. The first latch is the master, and the second the slave.

• When CLK_L = 1 the master is open (on) and the slave is closed (off). Qm and Ds follow Dm .

Page 4: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

Edge Triggered D Flip-Flop

• When CLK_L = 0 the master is closed, the slave is open and Qm is transferred to Qs . Note that Qs does not change if Dm changes because the master latch is closed leaving Qm fixed.

Page 5: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

Master/Slave J-K Flip-Flop

• Q* = JQ’+K’Q

Page 6: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

Edge Triggered J-K Flip-Flop

• Q* = JQ’+K’Q

Page 7: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

Edge Triggered J-K Flip-Flop

• 74LS109

Page 8: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

T Flip-Flop

• Flip-flop changes state every tick of the clock.

• Q* = Q’

Page 9: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

T Flip-Flop With Enable

• Flip-flop changes state every tick of the clock when enable is asserted.

• Q* = ENQ’+EN’Q

Page 10: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

Analysis

• Determine the next-state and output functions F and G.

• Use F and G to construct a state/output table that completely specifies the next state and output of the circuit for every possible combination of current state and input.

• Draw a state diagram.

Page 11: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

State Machines With D Flip-Flops

• D0 = Q0 · EN’ + Q0’ · EN• D1 = Q1 · EN’ + Q1’ · Q0 · EN + Q1 · Q0’ · EN

Page 12: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

State Machines With D Flip-Flops

• Q0* = D0• Q1* = D1

• Q0* = Q0 · EN’ + Q0’ · EN• Q1* = Q1 · EN’ + Q1’ · Q0 · EN + Q1 · Q0’ · EN

Page 13: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

State Machines With D Flip-Flops

• MAX = Q1 · Q0 · EN

Page 14: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

State Machines With D Flip-Flops

• Q0* = Q0 · EN’ + Q0’ · EN• Q1* = Q1 · EN’ + Q1’ · Q0 · EN + Q1 · Q0’ · EN• MAX = Q1 · Q0 · EN

Present State Input Next State OutputS EN S* MAXA 0 A 0A 1 B 0B 0 B 0B 1 C 0C 0 C 0C 1 D 0D 0 D 0D 1 A 1

Input OutputQ1 Q0 EN Q1* Q0* MAX0 0 0 0 0 00 0 1 0 1 00 1 0 0 1 00 1 1 1 0 01 0 0 1 0 01 0 1 1 1 01 1 0 1 1 01 1 1 0 0 1

Present State Next State

Page 15: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

State Machines With D Flip-Flops

Page 16: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

State Machines With D Flip-Flops

Page 17: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

State Machines With D Flip-Flops

Page 18: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

State Machines With J-K Flip-Flops

Page 19: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

Characteristic tables

• The tables that we’ve made so far are called characteristic tables.– They show the next state

Q(t+1) in terms of the current state Q(t) and the inputs.

– For simplicity, the control input C is not usually listed.

– Again, these tables don’t indicate the positive edge-triggered behavior of the flip-flops that we’ll be using.

D Q(t+1) Operation

0 0 Reset1 1 Set

T Q(t+1) Operation

0 Q(t) No change1 Q’(t) Complement

J K Q(t+1) Operation

0 0 Q(t) No change0 1 0 Reset1 0 1 Set1 1 Q’(t) Complement

Page 20: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

Characteristic equations• We can also write characteristic equations, where the next state Q(t+1) is defined in terms of the current state Q(t) and inputs.

D Q(t+1) Operation

0 0 Reset1 1 Set

T Q(t+1) Operation

0 Q(t) No change1 Q’(t) Complement

J K Q(t+1) Operation

0 0 Q(t) No change0 1 0 Reset1 0 1 Set1 1 Q’(t) Complement

Q(t+1) = D

Q(t+1)= K’Q(t) + JQ’(t)

Q(t+1)= T’Q(t) + TQ’(t)= T Q(t)

Page 21: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

Memory Allocation

• Compile for overlays• Compile for fixed Partitions

– Separate queue per partition– Single queue

• Relocation and variable partitions– Dynamic contiguous allocation (bit maps versus linked

lists)• Fragmentation issues• Swapping• Paging

Page 22: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

Overlays

Overlay Manager

Overlay Area

Main Program

Overlay 1

Overlay 2

Overlay 3

Secondary Storage

Overlay 1Overlay 2Overlay 3Overlay 1

0K

5k

7k

12k

Page 23: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

Multiprogramming with Fixed Partitions

• Divide memory into n (possible unequal) partitions.

• Problem:– Fragmentation

Free Space

0k

4k

16k

64k

128k

Page 24: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

Fixed PartitionsLegend

Free Space0k

4k

16k

64k

128k

Internalfragmentation

(cannot be reallocated)

Page 25: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

Fixed Partition Allocation Implementation Issues

• Separate input queue for each partition– Requires sorting the incoming jobs and putting them into separate

queues– Inefficient utilization of memory

• when the queue for a large partition is empty but the queue for a small partition is full. Small jobs have to wait to get into memory even though plenty of memory is free.

• One single input queue for all partitions. – Allocate a partition where the job fits in.

• Best Fit

• Worst Fit

• First Fit

Page 26: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

Relocation

• Correct starting address when a program starts in memory • Different jobs will run at different addresses

– When a program is linked, the linker must know at what address the program will begin in memory.

• Logical addresses, Virtual addresses– Logical address space , range (0 to max)

• Physical addresses, Physical address space– range (R+0 to R+max) for base value R.

• User program never sees the real physical addresses • Memory-management unit (MMU)

– map virtual to physical addresses.

• Relocation register – Mapping requires hardware (MMU) with the base register

Page 27: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

Relocation Register

Memory

Base Register

CPU Instruction

Address

+

BA

MA MA+BA

PhysicalAddress

LogicalAddress

Page 28: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

Storage Placement Strategies

• Best fit– Use the hole whose size is equal to the need, or if none is equal,

the whole that is larger but closest in size. – Rationale?

• First fit– Use the first available hole whose size is sufficient to meet the need– Rationale?

• Worst fit– Use the largest available hole– Rationale?

Page 29: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

Storage Placement Strategies

• Every placement strategy has its own problem– Best fit

• Creates small holes that cant be used

– Worst Fit• Gets rid of large holes making it difficult to run large

programs

– First Fit• Creates average size holes

Page 30: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

Locality of Reference

• Most memory references confined to small region

• Well-written program in small loop, procedure or function

• Data likely in array and variables stored together

• Working set– Number of pages sufficient to run program normally,

i.e., satisfy locality of a particular program

Page 31: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

Page Replacement Algorithms

• Page fault - page is not in memory and must be loaded from disk

• Algorithms to manage swapping– First-In, First-Out FIFO – Belady’s Anomaly– Least Recently Used LRU– Least Frequently Used LFU– Not Used Recently NUR

• Referenced bit, Modified (dirty) bit

– Second Chance Replacement algorithms

• Thrashing– too many page faults affect system performance

Page 32: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

Virtual Memory Tradeoffs

Disadvantages• SWAP file takes up space on disk• Paging takes up resources of the CPU

Advantages• Programs share memory space• More programs run at the same time• Programs run even if they cannot fit into memory

all at once• Process separation

Page 33: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

Virtual Memory vs. Caching

• Cache speeds up memory access

• Virtual memory increases amount of perceived storage – Independence from the configuration and

capacity of the memory system– Low cost per bit compared to main memory

Page 34: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

How Bad Is Fragmentation?

• Statistical arguments - Random sizes• First-fit• Given N allocated blocks• 0.5N blocks will be lost because of

fragmentation

• Known as 50% RULE

Page 35: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

Solve Fragmentation w. Compaction

Monitor Job 3 FreeJob 5 Job 6Job 7 Job 85

Monitor Job 3 FreeJob 5 Job 6Job 7 Job 86

Monitor Job 3 FreeJob 5 Job 6Job 7 Job 87

Monitor Job 3 FreeJob 5 Job 6Job 7 Job 88

Monitor Job 3 FreeJob 5 Job 6Job 7 Job 89

Page 36: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

Storage Management Problems

• Fixed partitions suffer from– internal fragmentation

• Variable partitions suffer from– external fragmentation

• Compaction suffers from – overhead

Page 37: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

Placement Policy

• Determines where in real memory a process piece is to reside

• Important in a segmentation system

• Paging or combined paging with segmentation hardware performs address translation

Page 38: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

Replacement Policy

• Placement Policy– Which page is replaced?– Page removed should be the page least likely

to be referenced in the near future– Most policies predict the future behavior on

the basis of past behavior

Page 39: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

Replacement Policy

• Frame Locking– If frame is locked, it may not be replaced– Kernel of the operating system– Control structures– I/O buffers– Associate a lock bit with each frame

Page 40: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

Basic Replacement Algorithms

• Optimal policy– Selects for replacement that page for which

the time to the next reference is the longest– Impossible to have perfect knowledge of

future events

Page 41: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

Basic Replacement Algorithms

• Least Recently Used (LRU)– Replaces the page that has not been

referenced for the longest time– By the principle of locality, this should be the

page least likely to be referenced in the near future

– Each page could be tagged with the time of last reference. This would require a great deal of overhead.

Page 42: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

Basic Replacement Algorithms

• First-in, first-out (FIFO)– Treats page frames allocated to a process as

a circular buffer– Pages are removed in round-robin style– Simplest replacement policy to implement– Page that has been in memory the longest is

replaced– These pages may be needed again very soon

Page 43: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

Basic Replacement Algorithms

• Clock Policy– Additional bit called a use bit– When a page is first loaded in memory, the use bit is

set to 1– When the page is referenced, the use bit is set to 1– When it is time to replace a page, the first frame

encountered with the use bit set to 0 is replaced.– During the search for replacement, each use bit set to

1 is changed to 0

Page 44: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.
Page 45: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

Early memory management schemes

• Originally used to devote computer to single user:

User has all of memory

0 65535

Page 46: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

Limitations of single-user contiguous scheme

• Only one person using the machine--lots of computer time going to waste (why?)

• Largest job based on size of machine memory

Page 47: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

Next: fixed partitions

• Created chunks of memory for each job:

Job 1 Job 2 Job 3

0 65535

Page 48: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

Limitations of fixed partitions

• Operator had to correctly guess size of programs

• Programs limited to partitions they were given

• Memory fragmentation resulted

• The kind illustrated here is called internal memory fragmentation

Page 49: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

Dynamic Partitions

1

3

4

2

1

6

5

7

Page 50: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

Internal versus external memory fragmentation:

Job 8

Space previously allocated by Job 1

Space currently allocated by Job 8

Page 51: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

Dynamic Partitions

• Contiguous memory is still required for processes

• How do we decide size of the partitions?

• Once the machine is going, how do old jobs get replaced by new ones?

Page 52: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

Dyanmic Partitions: First Fit

• In this scheme, we search forward in the “free list” for a partition large enough to accommodate the next job

• Fast, but the gaps left can be large

Page 53: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

Dynamic Partitions: Best Fit

• In this scheme, we try to find the smallest partition large enough to hold the next job

• This tends to minimize the size of the gaps

• But it also requires that we keep list of free spaces

Page 54: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

Deallocating memory

• If the block we are deallocating is adjacent to one or two free blocks, then it needs to be merged with them.

• So either we are returning a pointer to the free block, or we are changing the size of a block, or both

Page 55: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

Relocatable Dynamic Partitions

• We can see that in some cases, a job can “fit” into the combined spaces within or between partitions of the early schemes

• So how do we take advantage of that space?

• One way is to move programs while they are in the machine--compacting them down into the lower end of memory above the operating system

Page 56: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

Several names for this

• Garbage collection

• Defragmentation

• Compaction

• All share a problem: relative addressing!

Page 57: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

Page Replacement Algorithms

• Optimal page replacement simply not possible

• Keep referenced (R) and Modify (M) bits to allow us to keep track of past usage instead– Page is referenced by any read or write in it– Page is modified by any change (write) made

to it

Page 58: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

Page Replacement Algorithms, Continued

• FIFO = First in, first out• LRU = Least recently used• LFU = Least frequently used• both of the latter rely on a page request

call to the operating system• a failure to find a page = page interrupt• we might measure quality by

failure rate = page interrupts / page requests

Page 59: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

Page Replacement Algorithms, Continued

• Clock page replacement– Hand of the clock points to the oldest page– If a page fault occurs, check R bits in

“clockwise” order

• A variant called the “two-handed clock” is used in some UNIX systems

Page 60: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

FIFO solution is not more memory

• Called Belady’s anomaly

• the page request order is an important factor, not just the size of memory

Page 61: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

LRU

• Doesn’t suffer from Belady’s anomaly

• Presumes locality of reference

• But while it works well, it is a little more complex to implement in software– Consequently, aging and various clock

algorithms are the most common in practice– Aging can yield a good approximation

Page 62: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

Segmented Memory Allocation

• Instead of equal divisions, try to break code into its natural modules

• Compiler now asked to help operating system

• No page frames--different sizes required (meaning we get external fragmentation again)

Page 63: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

Segmented/Demand Paging

• Subdivide the natural program segments into equal sized parts to load into page frames

• eliminates external fragmentation

• allows for large virtual memory, so it is often used in more modern OS’s

Page 64: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

Tradeoffs

• Note that there is a tradeoff between external fragmentation and page faults in paging systems

• Note also that we probably want slightly smaller page frames in a Segmented-Demand Paging framework

Page 65: Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.

And Onward!

• Coming Thursday we’ll do our Mid2 exam

• Study guide already posted

• Don’t miss the exam!


Recommended