Computer Architecture What is it, and how is it related to ...

Computer Architecture What is it, and how is it related to ...

CSE506: Operating Systems CSE 506: Operating Systems What Hardware Provides to the OS CSE506: Operating Systems What Hardware Provides to the OS Memory Instructions

Interrupts Video & Keyboard DMA PCI Disk Network CSE506: Operating Systems (Physical) Memory Machine includes some amount of physical memory Provides blocks of sequential addresses Sometimes has holes in it BIOS can provide a list of available physical addresses On x86, called e820 Can be determined by boot loader and passed as arg. to kernel Non-Uniform Memory Access (NUMA) Some memory can be slower than others Example: 2 CPUs (nodes), each with its own 32GB of RAM

Can be leveraged to avoid performance loss OS can allocate local memory to avoid remote access Or BIOS can interleave memory across nodes All accesses are penalized roughly equally CSE506: Operating Systems (Virtual) Memory Hardware can manage virtual address spaces Dictated by the OS through page tables Page tables map from virtual to physical addresses On x86, 4KB is common, 2MB is sometimes used, 1GB is possible Page tables dictate translation Stored in memory Indexed by virtual page index Includes physical page index and permission bits Uses hierarchical structure to reduce storage

CSE506: Operating Systems Translation Overview From Intel 80386 Reference Programmers Manual x86-64 is similar, but with 4 levels CSE506: Operating Systems Example 0xf1084150 0x3b4 Page Dir Offset (Top 10 addr bits: 0xf10 >> 2) 0x84 Page Table Offset (Next 10 addr bits)

0x150 Physical Page Offset (Low 12 addr bits) cr3 Entry at cr3+0x3b4 * sizeof(PTE) Entry at 0x84 * sizeof(PTE) Data we want at offset 0x150 CSE506: Operating Systems Page Table Entries cr3

Upper Physical Address Bits (36 bits) Flags (12 bits) 0x00384 PTE_W|PTE_P|PTE_U 0 0 0x28370 PTE_W|PTE_P 0

0 0 0 0 0 0 0 0 0 12 bits not needed (4K pages have 12 bit offset) Convenient place for flags

CSE506: Operating Systems x86 Page Table Flags 3 for OS to use however it likes 4 reserved by Intel, just in case 3 for OS to CPU metadata User or Kernel page Write permission Present bit (so we can swap out pages) 2 for CPU to OS metadata Dirty (page was written), Accessed (page was read) CSE506: Operating Systems TLB Entries The CPU caches address translations in the TLB Translation Look-aside Buffer

Not coherent with memory If you change a PTE, you need to invalidate TLB entry Flush whole table (overwrite CR3) or invlpg one entry Virt cr3 Page Traversal is Slow Phys 0xf0231000 0x1000 0x00b31000 0x1f000 0xb0002000

0xc1000 - - Table Lookup is Fast CSE506: Operating Systems No execute (NX) bit Many security holes arise from bad input Tricks program to jump to unintended address That happens to be on heap or stack And contains bits that form malware Idea: execute protection can catch these Bit 63 in 64-bit page tables

CSE506: Operating Systems What Hardware Provides to the OS Memory Instructions Interrupts Video & Keyboard DMA PCI Disk Network

CSE506: Operating Systems Instructions Bytes encoding an operation Basic instructions manipulate registers and/or memory Can execute at any time (e.g., in ring 3 on x86) Trigger system calls Special instructions manipulate other hardware Usually only execute in privileged (kernel) mode (ring 0) Output and input to ports (special I/O space, going away slowly) Model-Specific Registers (rdmsr, wrmsr) for hardware config CRx registers CR2 provides address of faulting instruction

CR3 sets base address of top-level page table LIDT sets location of Interrupt Descriptor Table (IDT) CSE506: Operating Systems What Hardware Provides to the OS Memory Instructions Interrupts Video & Keyboard

DMA PCI Disk Network CSE506: Operating Systems Interrupts Umbrella term (used to mean many things) Interrupts: spontaneous hardware events (e.g., keypress) Exceptions: events in response to insn (e.g., div/0, gpf) Traps: events explicitly requested by insn (swi, syscall) Handling new interrupts can be suspended (cli) Hardware jumps to handler routine Event number selects index into vector Index contains pointer and some flags Flags may signal automatic cli on handler entry If event occurs in ring 3, also switches stack (%rsp)

Stack pointer taken from TSS via GDT CSE506: Operating Systems Hardware Interrupts PIC: old style (slightly easier) 8 wires, each wire goes to different device Can be programmed to mask interrupts Needs to receive ack before triggering new interrupt Cascaded for more interrupts Two 8-input PICs chained together, one master one slave If interrupt from slave, must ack both master and slave Programmable with offset to add to IRQ number Must be programmed before use

Usually map master to 32, slave to 40 APIC: new style (more complex) One LAPIC (Local APIC) per core, one IOAPIC per chip Supports Inter-Processor Interrupts (IPI), needed for MP CSE506: Operating Systems What Hardware Provides to the OS Memory Instructions

Interrupts Video & Keyboard DMA PCI Disk Network CSE506: Operating Systems Video and Keyboard x86 text console Memory mapped at 0xB8000 80*50 bytes (80 cols, 25 rows, 2 bytes per location) One byte for color, one byte for glyph PS/2 keyboard Wired to IRQ#1 Needs read of port 0x60 to ack interrupt Read byte is a scan code, not a letter Letters on key caps are just a convention

Always get two interrupts per keypress One for press (high bit clear) one for release (high bit set) CSE506: Operating Systems Keyboard via SSH and Curses We are working in an emulated environment Which isnt even on our local machines Must keep in mind keys such as Shift, Ctrl, and Alt On a local keyboard, these behave like all other keys In an ssh session, scan codes are not sent to destination Local OS interprets scan codes, characters are sent via ssh Qemu in curses mode fakes keyboard scan codes User presses Shift+a on local machine Character A is transmitted over the ssh session Qemu fakes shift down, a down, a up, shift up sequence

CSE506: Operating Systems What Hardware Provides to the OS Memory Instructions Interrupts Video & Keyboard DMA PCI Disk Network

CSE506: Operating Systems Direct Memory Access (DMA) I/O devices need to xfer data to/from memory CPU looping for every word (read/write) is expensive CPU can delegate xfer and get IRQ when xfer is done Originally, done with special DMA controller CPU programmed controller Controller performed xfer device memory Legacy setup, dont accidentally try to implement it ISA Industry Standard Architecture PCI / PCIe are dominant today Each device has its own DMA controller Called bus mastering CSE506: Operating Systems

Typical DMA Operation CPU creates a ring buffer of descriptors Device has head and tail pointers To receive data Descriptors contain physical addresses waiting for data When device has data (e.g., received network packet) Device copies data directly into address from head descriptor Raises hardware IRQ CPU clears/replaces used buffer with empty one in ring To send data CPU puts physical address of data into tail descriptor Informs device that tail has changed When xfer done, device raises IRQ (CPU reclaims buffer) CSE506: Operating Systems What Hardware Provides to the OS

Memory Instructions Interrupts Video & Keyboard DMA PCI Disk Network CSE506: Operating Systems

Peripheral Component Interconnect Slowly getting replaced by PCIe (PCI Express) Same general idea, higher performance Replaces previous buses (e.g., ISA) PCI is software-configurable Opposite of ISA, which was hard-wired (e.g., with jumpers) OS should walk PCI configuration space Enumerates all PCI devices on all PCI buses Each device reports at least Vendor ID and Device ID Used to select driver to load Driver can configure up to 6 BARs (Base Address Registers) BARs dictate the devices memory-mapped I/O addresses CSE506: Operating Systems What Hardware Provides to the OS

Memory Instructions Interrupts Video & Keyboard DMA PCI Disk Network CSE506: Operating Systems Disks

Organized into sectors C/H/S (cylinder, head, sector) - mostly outdated notion Modern disks addressed by logical block address (LBA) Typically sectors were 512 bytes, newer disks use 4KB A sector is the minimum unit to read/write Most OSes typically read/write entire memory page (4K) Can be grouped together into logical units Redundant Array of Independent Disks (RAID) RAID 1 (disk mirror): tolerate N-1 disk failures, improve read perf. RAID 5 (striped w/parity): tolerate 1 failure Hot spare: provides unused disk until failure (tolerate +1 failure) CSE506: Operating Systems Disk Controllers Disks connected via controller IDE: just a bridge from ISA bus to on-disk controller Evolved into ATA-x, renamed Parallel ATA (PATA), Serial ATA (SATA)

SCSI: actual smart disk controller Many revisions, most recently to Serial Attached SCSI (SAS) SATA uses IDE protocol, SAS uses SCSI protocol Provides commands such as Read/Write, Start/Stop, Inquiry Modern controllers provide tagged commands Each read/write request has a tag Allows for multiple operations to be outstanding CSE506: Operating Systems What Hardware Provides to the OS

Memory Instructions Interrupts Video & Keyboard DMA PCI Disk Network CSE506: Operating Systems Network Cards Physically connects machine to network Typically support only low-level operations Receive data from wire, put data into ring buffer Take buffer out of ring buffer, send contents on the wire

Raise interrupt when ready Modern NICs have many add-on features Interrupt coalescing: dont raise interrupt for each packet TCP Offload Engine (TOE): do some TCP work on the NIC Checksum Offload: compute checksum in hardware TCP Segmentation Offload (TOS): split large buffers into packets

Recently Viewed Presentations

  • The Northern Renaissance - Mount Saint Joseph High School

    The Northern Renaissance - Mount Saint Joseph High School

    The Northern Renaissance The Spread of Humanism Printing Press (c. 1456) Johann Gutenberg - spread of humanistic literature to rest of Europe. By 1480, 380 printing presses in Europe (1000 by 1500) Christian Humanism Attempted to find a balance between...
  • STANDARD A High quality clinical care High quality, safe and ...

    STANDARD A High quality clinical care High quality, safe and ...

    Title STANDARD A High quality clinical care High quality, safe and integrated clinical care for IBD patients based on multi- disciplinary team working and effective collaboration across NHS organisational structures and boundaries.
  • Background Soil Guidance

    Background Soil Guidance

    Outliers in background should be excluded from the background dataset since that point is suspect and will skew background statistics. Outliers in the dataset are real outliers but may still be part of the background population (for example, a 99th...
  • Molecular Systematics - Western New Mexico University

    Molecular Systematics - Western New Mexico University

    1977 Allan Maxam and Walter Gilbert publish "DNA sequencing by chemical degradation". Frederick Sanger, ... the model ABI 370. 1990 The U.S. National Institutes of Health ... Many more molecular characters available for analysis than morphological ones.
  • Synovial Joints

    Synovial Joints

    Modified ball and socket joints in which the head of a bone is similar in shape to a football. Moves in two axes, but restricts rotational motion ... A modified hinge joint. Allows flexion, extension, and limited rotation. Knee dislocation...
  • GCSE Mathematics - Walton High School

    GCSE Mathematics - Walton High School

    To the new. 22 The Venn diagram shows information about a coin collection.. S= 120 coins in the collection. T = coins from the 20th century. B = British coins. A coin is chosen at random. It is British. Work...
  • Cubism Pablo Picasso Georges Braque Cubism Cubism was

    Cubism Pablo Picasso Georges Braque Cubism Cubism was

    Cubism. Cubism was a truly revolutionary style of modern art developed by Pablo Picasso and Georges Braque. It was the first style of abstract art which evolved at the beginning of the 20th century in response to a world that...
  • The Last days of Jesus - Bathwick

    The Last days of Jesus - Bathwick

    Cymerwyd yr Iesu i lawr o'r groes a'i gario i ogof o fedd dinesydd cyfoethog a gredai yn Iesu, mab Duw. At yr Ogof Cafodd yr Iesu ei rwymo mewn dillad-claddu a'i eneinio รข pheraroglau fel 'sandalwood'. Gosodwyd ei gorff...