Computer Architecture: Core Components

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson
Download our mobile app to listen on the go
Get App

Questions and Answers

Which of the following is NOT a tool available at the hardware architecture level?

  • Interrupts and Interrupt Vector
  • Memory Management Unit
  • System Call Interface (correct)
  • Kernel/User Mode

What is the primary purpose of the interrupt vector?

  • To store the current state of the CPU
  • To provide direct access to I/O ports for user applications
  • To manage memory allocation for processes
  • To link hardware interrupts with the appropriate interrupt service routines (correct)

In the basic instruction cycle of the CPU, which step immediately follows fetching an instruction?

  • Executing the instruction
  • Checking for interrupts
  • Saving the instruction to memory
  • Incrementing the program counter (correct)

What distinguishes kernel mode from user mode?

<p>Kernel mode can execute all instructions, plus access special instructions and registers that control I/O and memory. (D)</p>
Signup and view all the answers

During a context switch, which of the following actions is essential for resuming the program later?

<p>Saving the 'program state', including the program counter, registers, status register and stack pointer. (A)</p>
Signup and view all the answers

What happens to the Program Counter (PC) during an interrupt?

<p>It is saved on the stack. (B)</p>
Signup and view all the answers

What is the purpose of 'masking off' interrupts?

<p>To delay or disable interrupts temporarily. (C)</p>
Signup and view all the answers

In the context of interrupt handling, what is the primary function of the 'Return from Interrupt' (RTI) instruction?

<p>To restore registers and return control to the interrupted process. (C)</p>
Signup and view all the answers

What characterizes a 'critical section' in concurrent programming?

<p>A section of code that references data shared by two or more threads of control. (C)</p>
Signup and view all the answers

What is a potential risk if a critical section is not properly managed?

<p>Data may be corrupted, leading to incorrect behavior. (D)</p>
Signup and view all the answers

Which of the following is NOT a type of device driver in modern UNIX-type systems?

<p>Graphical (C)</p>
Signup and view all the answers

Which action is typically performed by the open function in a device driver?

<p>Initializes variables and generates a file descriptor. (A)</p>
Signup and view all the answers

What is the role of the 'interrupt service routine' within device drivers?

<p>To handle events when a device generates an interrupt. (C)</p>
Signup and view all the answers

What does the term 'process context' refer to?

<p>All the information needed to resume a process after it has been interrupted. (A)</p>
Signup and view all the answers

Which of the following is a primary function of the process table?

<p>To hold information about each current process, like context and state. (D)</p>
Signup and view all the answers

What is the key purpose of synchronization primitives?

<p>To manage critical sections. (A)</p>
Signup and view all the answers

Which outcome does a 'mutex' intend to achieve when applied to a critical section?

<p>Ensuring only one process can access the section at a time. (B)</p>
Signup and view all the answers

What is the fundamental operation of the signal operation on a semaphore?

<p>To increment the semaphore's internal counter, potentially releasing a waiting process. (B)</p>
Signup and view all the answers

Which condition defines 'deadlock'?

<p>When processes hold resources and require resources that other processes already hold, creating a circular dependency. (A)</p>
Signup and view all the answers

In the context of inter-process communication (IPC), what are 'signals' primarily used for?

<p>Indicating that an important event has occurred. (B)</p>
Signup and view all the answers

Which type of scheduling algorithm is generally considered 'fair' because jobs cannot be stuck waiting forever?

<p>First-In-First-Out (FIFO) (D)</p>
Signup and view all the answers

For interactive systems, what type of schedulers are generally required to achieve smoother response times?

<p>Preemptive schedulers (C)</p>
Signup and view all the answers

What is the primary characteristic of 'real-time' tasks in scheduling?

<p>They demand a fixed fraction of CPU/unit time. (A)</p>
Signup and view all the answers

How do pipes facilitate inter-process communication?

<p>By creating a file descriptor pair attached to a common buffer in memory. (B)</p>
Signup and view all the answers

Which step, related to process state, is part of the basic process scheduler loop?

<p>Marking a process as RUNNABLE or BLOCKED. (B)</p>
Signup and view all the answers

When is a device driver's probe function typically called?

<p>During the operating system's boot sequence. (B)</p>
Signup and view all the answers

What is the purpose of the splx function in the context of device drivers?

<p>To restore the interrupt mask to its previous state. (A)</p>
Signup and view all the answers

What is the purpose of the tsleep function in the context of device drivers?

<p>To mark a thread as blocked until a condition is met. (A)</p>
Signup and view all the answers

What is the purpose of the Java synchronized keyword

<p>To provide a critical section (C)</p>
Signup and view all the answers

What is a software 'interrupt'?

<p>Signals (D)</p>
Signup and view all the answers

What is the normal pairing of signal and wait in semaphores?

<p>Always, there will be a wait_sem with a corresponding signal_sem on the same semaphore (D)</p>
Signup and view all the answers

To avoid deadlock, what has to be avoided?

<p>Cycle in the request allocation graph (A)</p>
Signup and view all the answers

What is the signal used for in IPC?

<p>A software interrupt (A)</p>
Signup and view all the answers

What defines FIFO?

<p>If jobs/process-es/...repeatedly join the queue this is typically called 'round robin.' (A)</p>
Signup and view all the answers

What describes SJF?

<p>Both A &amp; B (A)</p>
Signup and view all the answers

What describes batch processing?

<p>Is insensitive to gaps in runtime; get overall task done. (C)</p>
Signup and view all the answers

What describes interactive processing?

<p>Sensitive to gaps in runtime; typically lots of I/O (D)</p>
Signup and view all the answers

What describes real time processing?

<p>Both C &amp; D (D)</p>
Signup and view all the answers

Flashcards

CPU (Central Processing Unit)

The core processing unit that executes instructions.

RAM (Random Access Memory)

A type of computer memory that can be accessed randomly.

I/O Devices

The connection points for external devices to a computer.

Interrupt vector

The memory location reserved for interrupt handlers.

Signup and view all the flashcards

Processor status register

A register in the CPU that indicates the current execution mode.

Signup and view all the flashcards

Instruction Cycle

A basic step in the central processing unit (CPU).

Signup and view all the flashcards

User mode

A mode where the CPU can execute most instructions, but not certain privileged ones.

Signup and view all the flashcards

Kernel mode

A mode where a CPU can execute all instructions and privileged instructions.

Signup and view all the flashcards

Context Switch

Switching from one running program to another.

Signup and view all the flashcards

Interrupt

A hardware-generated jump to a subroutine requested by an external hardware device.

Signup and view all the flashcards

Masking off

To temporarily disable interrupts.

Signup and view all the flashcards

Return from interrupt

Specialized CPU mode to execute instructions after an interrupt.

Signup and view all the flashcards

Critical section

Section of code that accesses shared data.

Signup and view all the flashcards

Block Device Drivers

A type of device driver to read/write blocks, tapes, SD-cards, CD-ROM/DVDs etc.

Signup and view all the flashcards

Network Device Drivers

A type of device driver for local and remote network interface

Signup and view all the flashcards

Character Device Driver

A type of device driver that manages serial ports, keyboard, mouse an joysticks among other

Signup and view all the flashcards

Top Half

Device driver function to communicate with user, kernel

Signup and view all the flashcards

Bottom Half

Device driver function for event handling

Signup and view all the flashcards

Get Keyb

A jump to get a character from keyboard.

Signup and view all the flashcards

Circular Queue

A queue that operates as if the ends are joined, useful in buffering.

Signup and view all the flashcards

Spltty

Marks interrupts or returns the mask.

Signup and view all the flashcards

Tsleep

Causes current thread to be blocked.

Signup and view all the flashcards

Wakeup

Un-blocks all threads, allows to have a certain identifier.

Signup and view all the flashcards

Get char from device

Returns characters from the device.

Signup and view all the flashcards

Process

Instance of a program being executed.

Signup and view all the flashcards

Process table

Contains info about a process, current process.

Signup and view all the flashcards

Deadlock

Resource is taken by another resource and vice versa.

Signup and view all the flashcards

Java synchronized keyword

Can be used on methods to provide a critical section.

Signup and view all the flashcards

Semaphores/Mutexes

Values for flow control.

Signup and view all the flashcards

Signals

Sending interrupt with software.

Signup and view all the flashcards

Signal Values

Integer valued action, similar to interupts.

Signup and view all the flashcards

Pipes

File descriptor pair shared between processes, attached to buffer.

Signup and view all the flashcards

Preemptive Discipline

Routine that is followed when scheduling.

Signup and view all the flashcards

Round robin FIFO

A scheduling algorithm of repeatedly joining tasks.

Signup and view all the flashcards

Shortest job

A scheduling algorithm which goes to the first job.

Signup and view all the flashcards

fair

Getting the highest bandwith for the right cost

Signup and view all the flashcards

optimal

Algo to get most thoughput for lowest cost

Signup and view all the flashcards

Int time system.

Non int time runtime for system.

Signup and view all the flashcards

Study Notes

Computer Components

  • Central Processing Unit (CPU)
  • Random Access Memory (RAM)
  • Input/Output (I/O) Devices

Actual Physical Memory Organization

  • "Zero Page" contains the interrupt vector, I/O, and BIOS/ROMs if present
  • Has an address range from 0x00...00
  • RAM has an address range Ox??...??

Hardware Architecture Tools

  • Program Counter (PC) tracks current instruction
  • Stack Pointer/Frame Pointer
  • Processor Status Register
  • General Purpose Registers
  • Memory Management Unit (MMU), for mapping and protection
  • Kernel/User Mode
  • Interrupts and interrupt vector

Interrupt Vector Function

  • Links devices with service routines using function addresses
  • Example devices: disk, CD, mouse, keyboard

Basic Instruction Cycle

  • Fetch instruction pointed to by the PC
  • Increment the PC
  • Execute the instruction
  • Process repeats

Processor Status

  • User mode can execute most instructions, excluding I/O operations
  • Kernel mode can execute all user instructions, as well as special instructions and registers for I/O and memory access
  • Kernel mode called supervisor mode

Interrupt Vector

  • Allocates a special range of locations in RAM
  • Links hardware interrupts with interrupt service routines

Processes in Memory

  • Consists of a process table entry, hardware kernel space and user space
  • Shared memory is accessible from the user space and kernel space
  • Requires interrupt signal

Program Execution

  • Assembler translates code to machine code and designates a memory address
  • Assembler, Machine Code and virtual memory addresses are used
  • Registers include R0, R1, R2, R3, SP, and PC
  • Op Codes dictate Load, Store, Increment, Decrement, Jump, Jump to Subroutine, Reserve Storage Bytes, and Zero

Context Switch Definition

  • Process of changing from one running program to another "on the fly"
  • Involves saving the "program state," mainly the program counter, general purpose registers, status register, and stack pointer
  • Each program must reside indifferent parts of the memory

Time Chart

  • Can be used to visualize context switching
  • Program represented by a line
  • Interrupts (disk or mouse) represented by vertical bars during the interrupt
  • Context switches occur at points where programs switch due to interrupts

Interrupts Explained

  • Trigger a hardware-generated jump to a subroutine (JSR)
  • Initiated by an external hardware device, not the CPU
  • Defined by an interrupt vector, which resides in physical memory as an array of function pointers
  • Can be delayed via masking off

Interrupt Steps

  • Saves Program Counter (PC) on the stack
  • Switches the CPU to kernel (supervisor) mode
  • Loads PC from a vector utilizing a hardware ID
  • Vector contains the start address of the interrupt service routine
  • Saves all registers and continues execution

Return from Interrupt (RTI) Steps

  • Restore registers
  • Restore saved PC value
  • Set CPU to the previous mode

Critical Section Definition

  • A code segment that references data shared among multiple "threads of control"
  • Threads may include interrupts, processes, or multiple conventional threads
  • Data must be managed so all parties can rely on its value
  • Failure to manage could lead to incorrect or corrupted data

Critical Section Example

  • i++ gets compiled to load R1, #i; incr R1; store R1, #i
  • Interrupts must be managed

Device Drivers

  • Enable communication between hardware and the operating system
  • Divided into three primary types in modern UNIX-like systems: BLOCK, NETWORK, and CHARACTER

Types of Device Drivers

  • BLOCK: manage devices that read/write blocks, like disks and tapes
  • NETWORK: handle local and remote network communications, such as Ethernet and PPP
  • CHARACTER: manage devices that don't fit into the BLOCK or NETWORK categories (serial ports)

Device Driver Top Half Functions

  • Interface with user and kernel level processes
  • Primary operations include:
  • Probe: Checks for hardware during boot time
  • Open: Initialized when a process opens a device file
  • Generates a file descriptor in user space.
  • Close: Called when a process closes a device file to deallocate
  • Read function copies data from device to process
  • Write function queues the data for the device to output.

Device Driver Bottom Half Functions

  • Focuses on event handling
  • Manages interrupt service routines triggered when a device generates an interrupt, handling I/O on the hardware

Mutual Exclusion

  • Must block interrupt signal to prevent conflicts in updating
  • Uses spltty() to prevent the second interrupt from overwriting the first.
  • splx(int prev State) returns to a previous interrupt mask
  • Processes can be put to sleep if a buffer is full using tsleep() and awoken using wakeup()

Device Driver Skeleton - read

  • Character variable Q is declared with a variable size QSIZE
  • Sets starting variables for number in queue, start and end position in the queue
  • Enters the spltty() critical section to check that a device can be read
  • Enters a while loop conditioned upon the list being empty
  • Enters an sleept() critical section and then loop back to a new spltty() to check the device again
  • Copies the first character from the read queue into a variable and iterates the pointer
  • Exits the sleept() critical section

Device Driver Skeleton - intr

  • Enters the spltty() critical section to ensure nothing else reads at the same time
  • Conditional statement checks that the queue is not full
  • Exits the spltty() critical section and exits
  • If the queue isn't full it adds the first available character from the specified device
  • Iterates the end of the queue
  • Exits the critical section
  • Signals to wakeup that data has been receieved

Running Programs in UNIX/Mach

  • Execution of a program (image) is a process
  • O/S provides a simplified pseudo-computer environment for program execution
  • Process runs without direct access to I/O Ports
  • Access through kernel calls
  • Process has a virtual (simplified) address space and a process context
  • UNIX/Mach process environment consists of registers, stack and other data
  • Managed through process table entry

Process Table Contains

  • Context (thread)
  • Program counter
  • Registers for general/special purposes
  • Stack pointer
  • Virtual address space reference
  • Scheduling information, like blocked, runnable, or running status, priority and time used

Synchronization Primitives

  • Handle data shared between processes/threads
  • Manages critical sections that prevent data conflicts.
  • Two main are mutex and semaphores

Mutex Definition

  • Brackets a critical section to allow only one process at a time
  • Prevents race conditions and ensures data integrity

Semaphore Definition

  • Allows "N" processes to access a critical section at once
  • Used to control access to resources

Semaphores: "signal" function

  • Increments the internal counter of the semaphore

Semaphores: "wait" function

  • Waits until the internal counter is greater than zero, and then decrements the counter

Mutex Synchronization

  • Producer adds entries to the queue, and consumer removes them
  • Ensures that two processes aren't writing to the same memory at the same time

Implementing Mutual Exclusion

  • Achieved in hardware using special instructions like TEST_AND_SET
  • These ensure indivisible operations, preventing race conditions
  • Critical_begin sets the mutexFlag, and the critical_end resets it

Dekker's Algorithm

  • A software approach to mutual exclusion for two processes
  • Uses "need" flags and a "turn" variable to decide which process can enter the critical section

Semaphore Implementation with Mutexes

  • Critical sections are used with signal and wait
  • Professional implementations use tsleep() to block busy loops

Semaphore Producer/Consumer Example

  • Uses two semaphores, available_sem and used_sem, to manage the buffer
  • Critical sections are protected with semaphore to avoid race conditions

Co-Operating Sequential Processes

  • Semaphores can be used to coordinate two sequential streams
  • Semaphore_t U and Semaphore_t D
  • SEM_WAIT and SEM_SIGNAL are used

Semaphore Hints

  • Semaphores must be properly initialized
  • Always work from the definitions of wait_sem() and signal_sem()
  • A wait_sem should have a corresponding signal_sem on the same semaphore
  • The order of wait_sem operations is important, but the order of signal is less so

Deadlock Cause

  • Occurs when processes hold resources and require resources already held by other processes
  • Can be detected by the presence of a cycle in the resource allocation graph

Java synchronized Keyword

  • Is used on a whole method or code block to provide a critical section
  • Ensures that only one thread can access the synchronized section at a time

Inter-Process Communication (IPC) Mechanisms

  • Shared Memory: Shared process image
  • Semaphores/Mutexes: Integer values for flow control
  • Signals: Software "interrupts"
  • Pipes: Imitation file shared by processes

Signals Explained

  • Signals can indicate an important event
  • Process A runs, and Process B sends a signal
  • Process A suspends and calls a signal handler
  • Process A returns
  • Process B sees no direct notification

Signal Values

  • Represented by integers, similar to interrupts
  • Include HUP (hangup), INT (interrupt), QUIT (quit), ILL (illegal instruction), TRAP (trace trap), and KILL (kill process)
  • Some signals may vary between platforms
  • Can use kill -l command to know current configuration

Signal Example

  • Example uses #include <signal.h>
  • signalHandler gets defined
  • signal command registers the handler

Pipes Explained

  • A pair of file descriptors shared between processes
  • Buffer is common to both processes
  • Buffer not stored in the filesystem but in memory

Basic Process Scheduler Loop

  • When a process can no longer run, it is marked Runnable or Blocked
  • Save process context in the process table entry
  • A new process is then found to be Runnable and is executed
  • The state is then restored

Scheduling Algorithms

  • Queuing Discipline
  • Determines the order in which processes are executed

FIFO (First-In-First-Out)

  • If processses repeatedly join the queue its called "round robin"
  • Process is typically preemptive
  • Processes handled in order of arrival.

SJF (Shortest Job First)

  • Prioritizes the shortest jobs first
  • May jump to the head of the queue
  • It is nonpreemptive

Scheduling Algorithm Considerations

  • FIFO & round robin are generally considered fair
  • This is due being incapable of being stuck waiting forever
  • SJF provides the largest throughput due to always running the fastest task
  • SJF may be considered unfair due to processes being starved though

Scheduling In General

  • Preemptive schedulers will perform better than non-preemptive and are required for interactive systems
  • Schedulers will normally bias towards short jobs
  • Operators/users can manually change by using the command nice(1)
  • Always a trade-off between coarse and fine granularity

Scheduling Implementations

  • Preemption occurs frequently results in 'processor sharing'
  • The discipline is therefore FIFO

Batch Task

  • Insensitive to runtime gaps
  • Seeks overall task completion

Interactive Task

  • Sensitive to runtime gaps
  • Contains many I/O operations

Real-time Task

  • Critically sensitive to runtime gaps
  • Has a fixed fraction of CPU/unit requirements

Priority Queues

  • VMS/Windows
  • Some systems vary the priority dynamically; others do not

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Related Documents

More Like This

Use Quizgecko on...
Browser
Browser