Sunday, October 30, 2011

x86 Segment Registers

8080 is a 8-bit CPU with 16-bit address lines. 16 bits define an address space of 64K. At that time, the prevalent OS is CP/M-80. CP/M loads itself to the top of the installed memory. (This allows CP/M to reside in ROM.) More importantly, it allows the transient (user) program to start at a fixed location in low memory, at address 0100h (256 bytes from the start of memory).

The first 256 bytes are called PSP (program segment prefix) which contains various odd bit of information and buffer for disk I/O. Program will be loaded at 0100h, follow by a section of unused memory. At the end is CP/M. Above that are addresses that are not supported by any installed RAM.

8086 has 20 address lines which gave an address space of 1MB (16x64K). To allow programs written for CP/M to run in (or port to) 8086, segment register was used to point to the starting address for a 64K memory area within the 1M address space. While the CPU can see the full 1MB of memory, the segment register restrict the access to 64K at a time. CP/M program runs in the 64K segment similar to 8080.


Segmenation model was a big plus in allowing more memory to be addressed than a linear model in a 16-bit architecture of 8080.  But when the CPU architecture moved on to 32-bit and 64-bit, the segmentation model is no longer required.

A segment starts on paragraph boundary (16-bytes). To form a 20-bit address, 2 registers are used. One of them is segment register which form the "base". There are 6 segment registers:

CS - code segment
DS - data segment
SS - stack segment
ES - extra segment (a spare segement)
FS and GS are clones for ES

While the segmentation scheme makes porting of CP/M program easy, this has severely complicated the programming model beyond CP/M.

Friday, October 21, 2011

CPU Architecture

Architecture is "what the CPU does". It comprises like instruction set and registers. x86 CPU archtiecture evolves but attained high degree of backward compatibility. New instructions were added and width of the CPU expanded from 8 to 16 to 32 to 64 bits. Intel's 32-bits architecture is called IA-32. The new 64-bit architecture is called x86-64 which was invented by AMD. Inte;'s 64-bit architecture is called IA-64 Itanium which was not backward compatible to IA-32.

A CPU's microarchitecture is an implementation of an architecture. Different techniques are used to improve the throughput and speed of the execution (E.g. prefetch, cache, micro-op fusion etc.).

Monday, August 29, 2011

Broadband

Most LAN technology uses baseband signalling which mean only one signal is transmitted through the medium at a time. Broadband signaling on the other hand allows multiple signals on the medium simultaneously.

Sunday, August 28, 2011

Layer 1 Devices

Repeaters are the most basic form of forwarding device. They associate with Layer 1 as they do not have the ability to inspect the content of the headers. They simply regenerate the exact copy of the electrical signal. They are primarily used to extend the distance of cable run. They are seldonly used now due to advance of fibre optics that spans great distance.

Hub, or concentrator are simply multiport repeaters. The concept is the same. A signal delivered to any port on the hub is regenerated and forwarded to all ports. Again, there is no examination of frame. Hub is generally deployed in small LAN. When the number of nodes increases, perform degrades significantly as bandwidth are contended.

Ethernet is a baseband medium, meaning only 1 signal will be transmitted at any one time. When 2 nodes attempt to transmit at the same time, collision results. The nodes will reattempt to transmit at a later time. Therefore, hubs and repeaters in a network form a collison domain.

As the size of network grow, the collision domain becomes less efficent. Solution needs to partition the collision domain.

Monday, August 8, 2011

Memory Access

First level cache often has access time between 1 to 3 processor cycles. Access to second level cache requires 20 to 30 cycles and access to memory will needs >100 cycles.

In a multi-core system, each core has memory directly attached to it. Access to the local memory is faster than access to the memory connected to another core.

One approach is to interleave memory, commonly at cache line boundary so that application would access local and remote memory alternatively. On average, application will experience memory latency which is average of the local and remote memory access. This architecture is called uniform memory architecture (UMA) where all processor see uniform memory latency

Another approach is to accept the difference memory region will have different access frequency and make the OS aware of this. This architecture is called cache coherent nonuniform memory architecture (ccNUMA). OS will attempted to assign process to run on the same processor to maximize local memory access.

Cache

Direct mapped cache - each cache line in memory maps directly to a fixed cache line position. If the cache is 4KB in size, every memory location in 4KB apart maps to the same cache line.

N-way associative cache - each cache line in memory maps to a set of N possible location in cache. The location chosen will be determined by some replacement policies (e.g. random or LRU etc).

Fully associative cache - each cache line in memory maps to any position in cache. This is rarely implemented because of its complexity

First level cache access time is 1 to 3 cycles.  Second level cache access time is 20 to 30 cycles.  Memory access takes more than 100 cycles.  The reason for having multiple level of cache because the larger the cach, the longer it takes to find out if an item is stored there.

Saturday, August 6, 2011

Initial RAM Disk in Linux

In the final boot step, the Linux kernel will execute a series of run_init_process calls:

run_init_process("/sbin/init");
run_init_process("/etc/init");
run_init_process("/bin/init");
run_init_process("/bin/sh");
panic("no init found.  try passing init= option  tp kernel.")

The run_init call execite program in a filesystem already mounted, else the kernel will panic.  Linux kernel contains 2 mechanisms to mount an early root file system to perform certain start up functions.
(1) initial RAM disk (initrd) is the legacy method. Support for this must be compiled into the kernel. It is a small, self-contained root file system that usually contains directives to load specific device driveers before the end of boot cycle. For example, Red Hat and Ubbuntu uses initrd to load the EXT3 file system driver before mounting the real root file system.
The bootloader pass the initrd image to the kernel. A common scenario is that the bootloader loads the kernel image into memory and loads the initrd image to another address ranges. Bootloader than passes the load address of initrd to kernel. In other scenario (ARM architecture), the initrd and kernel image are simply concatenated into a single composite image. The address and size of the intird is passed to kernel using the kernel command line. One note is that the initrd image is universally compressed.
When Linux boots, it detects the presence of initrd image. It copies the compressed binary file from the physical location in RAM to proper kernel ramdisk and mounts it as the root file system. It then looks for a special file in the initial ramdisk called linuxrc. This file contains directives (commands)required before mounting the real root file system. After the kernel copies the ramdisk from physcial address into the kernel ramdisk, it releases the physical memory. This is similar to transfer the initrd image from real memory to virtual memory of the kernel.

As part of the Linux boot process, the kernel must locate andmount a root file system. The kernel decides what and where to mount in a funciton called prepare_namespace() in /init/do_mount.c.

If initrd support is enabled in the kernel and the kernel command line is so configured, kernel decompresses the initrd image and copy the content to ramdisk under /dev/ram. At this point, we have a proper file system on a kernel ramdisk. The kernel effectively mounted the ramdisk device as its root file system. Finally, kernel spawn a kernel thread ti execute the linuxrc file. When linuxrc is done, kernel unmounts the initrd and proceed to the final stage of system boot. If the real, root device has a directory called /initrd, Linux will mount initrd file system on this path. Otherwise, the initrd will be discarded.

If the kernel command line contains a root= paramter specifying a ramdisk (e.g. root=/dev/ram0), the previous described behaviour will change. First, the processing of the linuexrc file is skipped. Second, no attempt is made to mount another file system as root. It means the initrd is the only root file system. This is useful if minimal system configuration is intended.

(2) initiramfs is the preferred mechanism for executing early user space programs. It is coneptually simliar to initrd and its purpose is also similar: to load drivers that might be required to mount the real file system.
Initramfs is much easier to use by developer as it is a cpio archive whereas initrd is a gzipped file system image.