Quiz3 Study Guide

The focus of the quiz will be on the material since the second quiz, but you should be familiar with the material in the quiz1 study guide and the quiz2 study guide.

Logic Design

Digital Signals & Abstraction

Logic Gates and Combinational Circuits

Logic gates are the fundamental building blocks that perform Boolean functions. They respond to input changes continuously (with a small propagation delay).

Combinational Circuits are an acyclic (no loops) network of logic gates.

Standard Digital Components

These are common circuits built from logic gates.


Sequential Logic

1. Combinational vs. Sequential Logic

2. The Hierarchy of Storage Elements

The Bistable Element (The Physics)

SR Latch (Set-Reset)

D Latch (Level-Sensitive)

D Flip-Flop (Edge-Triggered)

Registers and Clocks

The RISC-V Register File


The Memory Subsystem

SRAM vs DRAM

Feature SRAM DRAM
Speed Faster Slower
Cost More expensive Cheaper
Structure Uses flip-flops (6 transistors) Uses capacitors (1 transistor + capacitor)
Volatility Volatile Volatile
Refreshing No need Requires periodic refreshing
Use Case Cache memory Main memory

Principle of Locality

Locality refers to the tendency of programs to access the same set of memory locations repetitively over a short period of time.

Temporal Locality

Spatial Locality


Role of Caches


Types of Cache Misses

Miss Type Description
Cold (Compulsory) The first time data is accessed; it’s not yet in the cache.
Conflict Multiple data mapped to the same cache location in set-associative/direct-mapped caches.
Capacity Cache cannot hold all the data being used; some data is evicted and reloaded.

LRU Replacement Algorithm


Performing a Cache Lookup

To perform a lookup:

  1. Extract the set index from the address.
  2. Search the set for a line where the valid bit is set and the tag matches.
  3. If found, it’s a hit. If not, it’s a miss.
  4. On a miss, fetch from lower memory and update the cache using the replacement policy.

Cache Terminology

Term Definition
Line Smallest unit of data storage in a cache.
Set A group of one or more cache lines.
Block A chunk of data transferred between memory and cache.
Tag Part of address used to identify memory blocks stored in cache lines.
Valid Bit Indicates whether the data in the cache line is valid.

Cache Mapping Techniques

Type Description
Direct-Mapped Each memory block maps to exactly one cache line. Fast but prone to conflict misses.
Fully Associative Any memory block can go into any line. Low conflict misses but slower and more hardware.
n-Way Set Associative Cache is divided into sets, each with E lines. A compromise between the two extremes.

Write Policies

Policy Description
Write-Through Updates are written to both the cache and main memory immediately. Easy to implement, slower writes.
Write-Back Updates are only written to cache initially. Written back to memory when line is evicted. Faster, but requires modified (dirty) bit tracking.

Summary

Concurrency

POSIX Threads (pthreads)

Creating Threads

pthread_t tid;
pthread_create(&tid, NULL, thread_func, (void*)arg);

Waiting for Threads to Finish

void* result;
pthread_join(tid, &result);

Passing Data to and from Threads

typedef struct {
    int id;
    char* msg;
} thread_data_t;

Locks

Basic Usage

pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;

pthread_mutex_lock(&lock);
// critical section
pthread_mutex_unlock(&lock);

Use Cases


Condition Variables

Usage Pattern

pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;

pthread_mutex_lock(&lock);
while (!condition_met) {
    pthread_cond_wait(&cond, &lock);
}
// do work
pthread_mutex_unlock(&lock);

// signal from another thread
pthread_cond_signal(&cond);

Use Case


Semaphores

Initialization

sem_t sem;
sem_init(&sem, 0, initial_value);

Wait and Signal

sem_wait(&sem);   // decrement semaphore
sem_post(&sem);   // increment semaphore

Use Cases


Producer-Consumer Problem

Key Conditions:


Readers-Writers Locks

Goals

Concurrent Data Structures

Examples:


Key Concepts to Know

Concept Know How To…
Race condition Explain what causes it and how to fix it
Deadlock Identify and prevent
Critical section Define and protect with locks
Bounded buffer Describe and implement
Signal vs broadcast Differentiate in condition variables
Mutex vs Semaphore Compare and choose correctly

Optimizing Program Performance

Why Optimize?

Measuring Performance

Optimization Blockers

How to maximize performance

Exploiting Modern Hardware (Microarchitecture)

Takeaways