Mostrando entradas con la etiqueta CPU. Mostrar todas las entradas
Mostrando entradas con la etiqueta CPU. Mostrar todas las entradas

13/3/11

Motherboard Chipsets and the Memory Map

I’m going to write a few posts about computer internals with the goal of explaining how modern kernels work. I hope to make them useful to enthusiasts and programmers who are interested in this stuff but don’t have experience with it. The focus is on Linux, Windows, and Intel processors. Internals are a hobby for me, I have written a fair bit of kernel-mode code but haven’t done so in a while. This first post describes the layout of modern Intel-based motherboards, how the CPU accesses memory and the system memory map.

To start off let’s take a look at how an Intel computer is wired up nowadays. The diagram below shows the main components in a motherboard and dubious color taste:
As you look at this, the crucial thing to keep in mind is that the CPU doesn’t really know anything about what it’s connected to. It talks to the outside world through its pins but it doesn’t care what that outside world is. It might be a motherboard in a computer but it could be a toaster, network router, brain implant, or CPU test bench. There are three main ways by which the CPU and the outside communicate: memory address space, I/O address space, and interrupts. We only worry about motherboards and memory for now.

In a motherboard the CPU’s gateway to the world is the front-side bus connecting it to the northbridge. Whenever the CPU needs to read or write memory it does so via this bus. It uses some pins to transmit the physical memory address it wants to write or read, while other pins send the value to be written or receive the value being read. An Intel Core 2 QX6600 has 33 pins to transmit the physical memory address (so there are 233 choices of memory locations) and 64 pins to send or receive data (so data is transmitted in a 64-bit data path, or 8-byte chunks). This allows the CPU to physically address 64 gigabytes of memory (233 locations * 8 bytes) although most chipsets only handle up to 8 gigs of RAM.

Now comes the rub. We’re used to thinking of memory only in terms of RAM, the stuff programs read from and write to all the time. And indeed most of the memory requests from the processor are routed to RAM modules by the northbridge. But not all of them. Physical memory addresses are also used for communication with assorted devices on the motherboard (this communication is called memory-mapped I/O). These devices include video cards, most PCI cards (say, a scanner or SCSI card), and also the flash memory that stores the BIOS.

When the northbridge receives a physical memory request it decides where to route it: should it go to RAM? Video card maybe? This routing is decided via the memory address map. For each region of physical memory addresses, the memory map knows the device that owns that region. The bulk of the addresses are mapped to RAM, but when they aren’t the memory map tells the chipset which device should service requests for those addresses. This mapping of memory addresses away from RAM modules causes the classic hole in PC memory between 640KB and 1MB. A bigger hole arises when memory addresses are reserved for video cards and PCI devices. This is why 32-bit OSes have problems using 4 gigs of RAM. In Linux the file /proc/iomem neatly lists these address range mappings. The diagram below shows a typical memory map for the first 4 gigs of physical memory addresses in an Intel PC:
Memory layout for the first 4 gigabytes in an Intel system.

Actual addresses and ranges depend on the specific motherboard and devices present in the computer, but most Core 2 systems are pretty close to the above. All of the brown regions are mapped away from RAM. Remember that these are physical addresses that are used on the motherboard buses. Inside the CPU (for example, in the programs we run and write), the memory addresses are logical and they must be translated by the CPU into a physical address before memory is accessed on the bus.

The rules for translation of logical addresses into physical addresses are complex and they depend on the mode in which the CPU is running (real mode, 32-bit protected mode, and 64-bit protected mode). Regardless of the translation mechanism, the CPU mode determines how much physical memory can be accessed. For example, if the CPU is running in 32-bit mode, then it is only capable of physically addressing 4 GB (well, there is an exception called physical address extension, but ignore it for now). Since the top 1 GB or so of physical addresses are mapped to motherboard devices the CPU can effectively use only ~3 GB of RAM (sometimes less – I have a Vista machine where only 2.4 GB are usable). If the CPU is in real mode, then it can only address 1 megabyte of physical RAM (this is the only mode early Intel processors were capable of). On the other hand, a CPU running in 64-bit mode can physically access 64GB (few chipsets support that much RAM though). In 64-bit mode it is possible to use physical addresses above the total RAM in the system to access the RAM regions that correspond to physical addresses stolen by motherboard devices. This is called reclaiming memory and it’s done with help from the chipset.

That’s all the memory we need for the next post, which describes the boot process from power up until the boot loader is about to jump into the kernel. If you’d like to learn more about this stuff, I highly recommend the Intel manuals. I’m big into primary sources overall, but the Intel manuals in particular are well written and accurate. Here are some:
Datasheet for Intel G35 Chipset documents a representative chipset for Core 2 processors. This is the main source for this post.
Datasheet for Intel Core 2 Quad-Core Q6000 Sequence is a processor datasheet. It documents each pin in the processor (there aren’t that many actually, and after you group them there’s really not a lot to it). Fascinating stuff, though some bits are arcane.
■ The Intel Software Developer’s Manuals are outstanding. Far from arcane, they explain beautifully all sorts of things about the architecture. Volumes 1 and 3A have the good stuff (don’t be put off by the name, the “volumes” are small and you can read selectively).
Pádraig Brady suggested that I link to Ulrich Drepper’s excellent paper on memory. It’s great stuff. I was waiting to link to it in a post about memory, but the more the merrier.
(Pedraig Brady said:
I think it’s worth referencing Ulrich Drepper’s paper on memory,
which goes into more detail
) Sphere: Related Content

4/12/10

Taking A Closer Look At Windows Resource Monitor

What is your computer doing in there? On the exterior it is a mass of plastics and metals, roughly pressed together to provide your PC with a protective case. But is it protecting your PC from the outside, or is it protecting you from the strange and arcane things happening inside your PC?

Perhaps it is time to find out exactly what your computer is up to – particularly if your computer is behaving badly. There are many third-party tools that can clean, scrub, and protect your PC, but none of those will help you better understand what’s going on. A program that can help you understand what is going on ships with every Windows PC. It’s called Windows Resource Monitor. Let’s take a look at what it can tell us.

Opening Windows Resource Monitor
Of course, we need to open Windows Resource Monitor before we can do anything. Windows Resource Monitor is a feature that was added in Vista and carries over to Windows 7. As far as I can gather, the only way to open it is through the Windows Task Manager - so press CTRL-ALT-DEL and open it.
Once Task Manager is open, go to the Performance tab. In the lower right hand corner is a button labeled Resource Monitor. Click it, and you’re ready to go!

The Basics
Windows Resource Monitor will, by default, open up to the Overview tab. This provides general, but useful, information about your computer. The best way to start becoming acquainted with Windows Resource Monitor is probably the graphs on the right side of the Overview tab. There are graphs here for your processor, hard disk, network and memory. These graphs will tell you how much of each is being used.
A computer at idle should display each graph as nearly flat. There may be minor spikes in usage, typically due to background processes, but these spikes should be few and they shouldn’t significantly consume system resources.

Other usage scenarios will result in distinct patterns. For example, it is normal to see high disk activity and high network usage when you are downloading a file. It is also normal to see high disk activity while your virus scanning software is operating.

Sudden (or not-so-sudden), unexplained spikes are not normal. They may be the result of bloatware (unwanted programs that come pre-installed in your system), an inefficient antivirus program, a program that did not close correctly or even malware.

A Deeper Look At CPU Usage
Open the CPU tab of Windows Resource Monitor. When you do so, the graphs on the right will change. You’ll now be shown a graph for each core Windows detects (or two graphs for each core if you have an Intel processor with Hyper-Threading enabled). The total CPU usage graph remains, as well.

But the most important information here is not the graphs. What you’ll need to take a closer look at is the text information under the labels of Processes and Services. A process is an active application, while a service is a background application that conforms to special rules (it can run automatically on boot, it can run when no user is logged on, etc).
When it comes to checking out processor usage, however, you’ll organize both using the same tactic. Simply organize the processes or services by the average CPU value. Tada! You now know what programs are taking up your processor’s power. Please note that common processes and services can sometimes appear under odd names in Windows Resource Monitor. Be sure to Google an unknown program and identify it before you close it.

Analyzing Memory Usage
The way your computer uses its short-term memory (RAM) is important to overall performance. If you’re running low on available memory you’ll find that your computer’s performance becomes sluggish.

RAM usage can be found under the Memory tab. A new, useful line graph appears at the bottom of Windows Resource Monitor. This graph shows you how much memory is in use, how much is on stand-by (containing active data, but not actively in use) and how much is completely free.
Ideally you’ll want to see some free memory on this graph. The real problem, however, comes when your in-use memory fills up most of the graph. This means you simply don’t have any RAM left to use! You can free up memory by organizing processes by their Working memory share and shutting down memory hogs. If your system has limited memory, however, you may simply need to add more memory to your PC.

Hard Disk & Network Usage
Most users underestimate the effect their hard drive can have on overall system performance. The speed with which you can download files, install programs, transfer information, and open programs can all be affected by your hard drive’s performance. Sometimes a program, such an anti-virus scanner, will bombard your hard disk with requests for information.
Opening up the Disk tab will show you the Processes with Disk Activity display. This shows you all the active processes that are consuming your hard disk’s time. You’ll usually see a few common Windows processors, like System and svchost.exe, listed here. But you may also see other programs. This may clue you in as to why programs are loading slowly.

Finally, take a look at the Network tab. You will again see a Processes with Network Activity display, which is very useful for tracking down programs that are making unwanted network connections (although nasty malware is often programmed to dodge Windows Resource Monitor or disguise itself as a more innocent process). You can also analyze your active network connections using the TCP connections display.

Conclusion
Familiarzing yourself with Windows Resource Monitor is a great idea. It is a very effective program that can tell you a lot about why your computer is behaving well or poorly. You can track down runaway programs and close them, and you can also see if a hardware upgrade is necessary to use the programs you prefer.

COMMENTS:
- Ctrl + Shift + Esc will open Task Manager (XP, Vista and Windows 7) without having to go through Ctrl + Alt + Del. This appears to be disabled on some brand name machines, but will work for most people.
- You can also type Resource Monitor (or just resmon,as resmon.exe) directly into the searchbox in the Start Menu to open it directly, funny thing is lot of windows 7 users doesn't know about this built-in utiity. Sphere: Related Content
If you’ve thought about buying an Intel processor lately – or a computer with an Intel processor installed – you may have heard the term “Hyper-Threading” launched at your eardrums. You probably aren’t familiar with this term unless you stay up-to-date with the nitty-gritty of computer hardware.

Understanding Hyper-Threading is important, however, because it’s a major feature on some Intel processors. Like most major processor features, it can be twisted and turned by the sales reps you meet. I’ve had a Fry’ store employee tell me that Hyper-Threading effectively doubles the number of cores on a processor. Although true in a sense, it’s mostly an exaggeration.

Let’s take a look at what Hyper-Threading really means.

A Brief History Of Hyper-Threading
Depending on when you last bought a computer, you may remember Hyper-Threading as a feature that Intel introduced and then discontinued. This could understandably leave a sour taste in your mouth – why would Intel discontinue it if it wasn’t trouble?

The truth isn’t so grim. Hyper-Threading was for a time made available on certain Intel Pentium 4 and Intel Xeon processors. It was discontinued not because the feature itself was bad, but rather because the processor that used it turned out to be a bit of a misstep for other reasons. The Pentium 4 architecture was a minor disaster for Intel because it was incapable of going the direction Intel hoped (Intel wanted to have Pentium 4 processors with clock speeds of up to 10 GHz). As a result, Intel jumped back to designing processors based on the Pentium Pro family tree.

Hyper-Threading was gone, but not forgotten. Intel eventually found the time and resources to integrate it into another new processor architecture - Nehalem. This is the architecture that is the basis for all current Intel Core i3, i5 and i7 processors.

Nice Threads, Man
Despite all of the advancements we’ve made in the world of processors, they still have one major limitation – an individual processor core can only execute one instruction at a time. Let’s say, for example, that you have MS Office, Firefox and Skype all open at once. You feel like you’re multi-tasking, but in processor terms you’re not. The processor core executing data related to these programs executes one instruction at a time, but because it is so quick you don’t notice any delay.
But there is a delay. That delay is due to how the data from each program is fed to the processor. Each stream of data – or thread- in to the processor must be scheduled and executed by the core individually. Hyper-threading, however, makes it possible for each processor core to schedule and assign resources to two threads at once.

Imagine a worker on an assembly line. There two types of widgets coming to her, and she needs to do different things with each widget. However, sometimes there is a delay because the conveyor belt is too slow, or because the wrong widget was sent at the wrong time. Hyper-Threading is like adding another conveyor belt so there is now one dedicated to each type of widget. There is still only one worker, but now widgets can be brought to her more quickly and efficiently so she is waiting for work less often.

Not The Same As Doubling Cores
If you boot up a dual-core processor with Hyper-Threading and open Windows Task Manager you will find yourself staring at four graphs. This is where most of the confusion about Hyper-Threading doubling the number of cores come into play. I’ve even spoken with one poor fellow who thought he’d purchased a eight-core processor because he saw eight graphs in Windows Task Manager. That’s what the sales rep told him, so when he went home and saw eight graphs, he was hooked. Seeing was believing.
Two graphs appear in Windows for each core on a Hyper-Threading processor because Windows is detecting two logical processors for each core. The term “logical processor” sounds fancy, but a logical processor is by definition a processor that has no physical existence. Windows can send threads to each logical processor, but there is still just one core doing the actual execution, so a single core with Hyper-Threading is dramatically different from two seperate physical cores.

The Benefit Of Hyper-Threading
Alright, enough with the technical mumbo-jumbo. Now let’s get down to the most important part – how Hyper-Threading will impact the performance of the computer are thinking of building or buying.

In terms of day-to-day tasks like web browsing, email and word processing, Hyper-Threading won’t have much of an impact. Yes, Hyper-Threading is theoretically better at multi-tasking. However, today’s processors are so fast that basic programs are rarely limited by the speed of your processor. The way programs are coded can also be a limitation. You may sometimes find that you have numerous programs open, but only one of your processor cores is being put to much use. That’s because the programs are, for whatever reason, not having their work divided among the different cores available.
When you’re trying to do some heavy lifting, however, Hyper-Threading can be more helpful. The applications most likely to benefit are 3D rendering programs, heavy-duty audio/video transcoding apps, and scientific applications built for maximum multi-threaded performance. But you may also enjoy a performance boost when encoding audio files in iTunes, playing 3D games and zipping/unzipping folders. The boost in performance can be up to 30%, although there will also be situations where Hyper-Threading provides no boost at all.

Conclusion
As the performance boost figure of only up to 30% indicates, Hyper-Threading is not the same as doubling the number of cores on a processor. If a sales rep ever tells you that, be careful, because they’re either ignorant or happy to lie to you if they think it will help push hardware.

With that said, Hyper-Threading is a cool feature, and it’s worth having. It’s particularly good if you like to edit media often or you use your computer as a workstation for professional programs like Photoshop or Maya. Sphere: Related Content