Skip to content

Instantly share code, notes, and snippets.

@TwoTau
Created March 26, 2019 19:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TwoTau/65a5a8f1ea16e1af7c167ae759c8efb0 to your computer and use it in GitHub Desktop.
Save TwoTau/65a5a8f1ea16e1af7c167ae759c8efb0 to your computer and use it in GitHub Desktop.
Resource Management Research (CompSci HL)

Identifying and evaluating resources

Resources include:

  • processors (sound, graphics, CPU)
  • storage (primary, secondary memory, cache)
  • bandwidth (of peripherals, network)
  • bus bandwidth
  • screen resolution

Resources vary in mainframes, servers, PCs, laptops, netbooks, tablets, phones, cameras, and music players. Some computers have fewer resources, which are cheaper but less efficient at processing. Specialization in resources gives computers advantages in security, customizability, and reliability.

Operating systems

The major role of an OS is to act as an interface between hardware and software programs by managing computer hardware and software resources. The OS does this by hiding the complexities of the hardware through abstraction. An OS on a headed device also has to create a Graphical User Interface (GUI) for the user.

Managing memory

Managing cache

Cache memory is extremely high-speed memory that is a buffer between the RAM and CPU. A block in the cache corresponds to a block in the main memory. The computer must find a given address in the cache through searching. The computer manages cache memory through three ways of mapping:

  • Fully associative: search the entire cache for an address
    • best utilization of cache space, but slow to search
  • Direct: each address has a specific location in the cache
    • efficient scheme but least effective in utilizing the full space of the cache
  • Set associative: each address is in a small set of locations
    • sort of a combination of associative and direct mapping

The computer decides which blocks in the main memory should be loaded into cache by prioritizing some blocks through locality of reference:

  • Spatial: if a block is accessed, nearby blocks will likely be accessed soon
  • Temporal: if a block is accessed repeatedly in a short period of time, it will likely be accessed again soon

Managing primary memory

Primary memory includes Random Access Memory (RAM, including DRAM, SRAM) and Read Only Memory (ROM, including P ROM, EP ROM). This stores the data/programs currently being processed. The OS ensures that programs are contained within their own allocated memory space to prevent corruption and security issues.

Managing secondary memory

Secondary memory includes fixed devices (hard drive, CD drive, etc) and removable devices (USB flash drive, BluRay drive, etc). This stores the data/programs that are not currently being used. If the power is lost, the data is still kept. The OS usually manages this storage by providing a folder structure for the user.

Managing virtual memory

Virtual memory is secondary memory that is being used as primary memory. When primary memory is filled, the OS moves some data from RAM to disk storage (virtual memory), freeing up space in RAM. The OS prefers not to use virtual memory when RAM is available because primary memory is faster than virtual memory.

Loading apps from memory

The loader is a part of the OS that loads programs. It places programs into memory and prepares to execute them. When executing the program, the OS converts logical addresses (addresses relative to the program location) to physical addresses (on the memory hardware itself).

Scheduling

Multiple cores

A multi-core processor is a computing component with multiple processing units (cores). Each core can run CPU instructions in parallel, allowing multiprocessing. This is different from multitasking, where multiple CPU instructions are run in time slices.

Time slices and interrupts

A time-slice is the amount of processing time each CPU process (like a program) gets. A 'too short' time-slice causes the CPU to consume too much processing time, but a 'too long' time-slice will cause processes to take longer to respond to input.

An interrupt is a signal to the CPU that tells it to handle another process with high priority. The OS pauses its current processes, executes the interrupt handler, then resumes its paused processes.
An example of a hardware interrupt is keyboard or mouse input. When a key is pressed, an interrupt is triggered. The OS calls an interrupt handler that reads the key into memory.

Polling

Polling is a simple process where the OS checks the state of another device. For example, the OS might poll a connected printer every half a second to check whether it is ready. An alternative to polling is interrupts, which are more efficient in terms of processor and bandwidth consumption.

Paging

Paging is when the OS retreives data from virtual memory to use in primary memory. The blocks retrieved are the same size and are called pages. Paging is done extremely quickly and is carried out by the computer's memory manager unit (MMU).

Context switching

In a single core computer, the processor uses time-sharing. Processes have their time-slices and run like this over time:

  • Core 1: ABCABCABCABCABC (A, B, and C are processes running at the same time)

In a triple core computer, processes can run like this:

  • Core 1: AAAAA
  • Core 2: BBBBB
  • Core 3: CCCCC

Priorities

Some processes such as interrupts have higher priority than others. The OS will make sure to execute higher-priority tasks before lower-priority tasks. In first-come, first-served scheduling, the CPU executes the processes that arrive first. In shortest-job next scheduling, the CPU executes the ready process with the smallest service time.

Hardware abstraction layers

Hardware abstractions hide the details of the hardware from the software. Layers are software routines that emulate some platform-specific details and give programs direct access to the hardware.

Scheduling used by the OS

The OS uses a scheduler to manage the execution of processes and enable multitasking. The processor reaches a compromise between its main goals:

  • maximize throughput (work done per time)
  • minimize wait time (initial time to startup)
  • minimize latency (time till first work is done)
  • maximize fairness (equal (by priority) time for each process)

Admin and machine policies

Admin policies are restrictions on user permissions, like file access and editing. Machine policies define and enable certain services like caching and storing data.

Dedicated operating system

A dedicated OS is an operating system is custom tailored to the needs of a specific type of device, such as Raspbian for Raspberry Pis.

Advantages of dedicated OS:

  • Security: harder to hack, safer to use
  • Customizability: do few functions at maximum efficiency
  • Prioritize: remove some functions for better memory efficiency
  • Reliability: fine tune some functions for the hardware

Disadvantages:

  • Proprietary: owned and protected by a trade name
  • Expensive: high initial and maintenance cost

Hiding complexity through the OS

The operating system hides complexity from the user by abstracting irrelevant hardware details.

  • processors (sound, graphics, CPU)
    • All external audio devices (speakers, headphones, earbuds) are abstracted into Playback devices or Recording devices by Windows.
    • Same with internal and external displays
    • JVM interprets compiled Java bytecode, so developers do not need to worry about what platform their Java program will run on
    • Java programmers do not have to manually time-slice their threads on a single or multi-core processor because the OS provides a high level API for multithreading
  • storage (primary, secondary memory, cache)
    • Drive letters (C:, D:, F:, etc) allow for different external storage drives to be accessed the same way by programs
    • Folder system organizes data, even though the data is not stored in a tree or linear structure on the hardware
  • bandwidth (of peripherals, network)
    • OS handles connecting to the internet and programs do not have to worry about writing different code depending on whether the hardware is using WiFi, ethernet, or cellular data.
  • bus bandwidth
    • OS handles hardware polling and hardware-level interrupts and provides a high level API for software that needs to connect to peripherals
  • screen resolution
    • OS gives programs an API to draw on the screen and the program does not need to worry about setting each pixel's RGB channels on the hardware level.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment