How does hardware (cpu or similar) provide any protection for the OS's essential memory [duplicate] - cpu

This question already has answers here:
What enforces memory protection in an OS?
(3 answers)
How do Operating Systems prevent programs from accessing memory?
(3 answers)
Closed 10 months ago.
So basically this might be a dumb question but how does hardware (cpu or related) protect virtual data even though all the cpu or any other hardware is doing is sending electricity around, it wouldn't make alot of sense for hardware to allow anything virtual allocated to be protected since of course its just electrical current. If it is actually possible for hardware to provide software/memory protection then how does it do it?

Related

Is there any scenario when we would resort to a process instead of a goroutine? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
I understand that goroutines are very light weight and we can spawn thousands of them but I want to know if there is some scenario when we should spawn a process instead of a goroutine (like hitting some kind of process boundaries in terms of resource or something else). Can spawning a new process in some scenario be beneficial in terms of resource utilization or some other dimension?
To get things started, here's three reasons. I'm sure there's more.
Reason #1
In a perfect world, CPUs would be busy doing the most important work they can (and not wasted doing the less important work while more important work waits).
To do this, whatever controls what work a CPU does (the scheduler) has to know how important each piece of work is. This is normally done with (e.g.) thread priorities. When there are 2 or more processes that are isolated from each other, whatever controls what work a CPU does can't be part of either process. Otherwise you get a situation where one process is consuming CPU time doing unimportant work because it can't know that there's a different process that wants the CPU for more important work.
This is why things like "goroutines" are broken (inferior to plain old threads). They simply can't do the right thing (unless there's never more than one process that wants CPU time).
Processes (combined with "process priorities") can fix that problem (while adding multiple other problems).
Reason #2
In a perfect world, software would never crash. The reality is that sometimes processes do crash (and sometimes the reason has nothing to do with software - e.g. a hardware flaw). Specifically, when one process crashes often there's no sane way to tell how much damage was done within that process, so the entire process typically gets terminated. To deal with this problem people use some form of redundancy (multiple redundant processes).
Reason #3
In a perfect world, all CPUs and all memory would be equal. In reality things don't scale up like that, so you get things like ccNUMA where a CPU can access memory in the same NUMA domain quickly, but the same CPU can't access memory in a different NUMA domain as quickly. To cope with that, ideally (when allocating memory) you'd want to tell the OS "this memory needs low latency more than bandwidth" (and OS would allocate memory for the fastest/closest NUMA domain only) or you'd tell the OS "this memory needs high bandwidth more than low latency" (and the OS would allocate memory from all NUMA domains). Sadly every language I've ever seen has "retro joke memory management" (without any kind of "bandwidth vs. latency vs. security" hints); which means that the only control you get is the choice between "one process spread across all NUMA domains vs. one process for each NUMA domain".

How are instructions embedded in the processor and boards of a computer [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
So, the processor has a clock that turns on and off which is a predetermined instruction. How are these instructions loaded into the processor as instructions? I am just visualizing a clean slate with the CPU how do we teach or tell the CPU to do what it does?
Also, if we are at a clean slate how do we load the data into a computer to recognize binary?
I'm sorry if this is an overload on questions, I'm just super curious..
Instruction execution starts at a hardwired address known as the reset vector. The instructions are programmed in memory; the means by which that is done varies depending on the memory technology used and the type of processor.
For standalone CPUs with no on-chip memory, the initial code will normally be in some kind of external read-only random-access memory (ROM) often called a bootrom - this for example is the BIOS on a PC motherboard. On modern platforms these ROMs normally use a technology known as NOR Flash which can be electrically erased and reprogrammed, either by loading them on a dedicated programmer or in-circuit (so for example a PC can rewrite its own BIOS flash).
For microcontrollers (MCU) with on-chip memory, these often have on-chip flash ROM and can also be electrically programmed typically using an on-chip programming and debug interface known as a JTAG interface (proprietary interfaces also exist on some devices). Some MCUs include mask ROM that is not rewritable which contains a simple (or primary) bootloader. Usually you can select how an MCU boots.
The job of the bootloader is to load more complex code into memory (electrically programmable ROM or RAM) and execute it. Often a primary bootloader in mask ROM is too simple and restricted to do very much, and will load a more complete bootloader that then loads an OS. For example a common scenario is for an processor to have a primary bootloader that loads code from a simple non-random access memory such as NAND flash or SD card; this may then load a more fully featured bootloader such as UBOOT typically used to load Linux for example. This secondary bootloader can support more complex devices boot sources such as a hard-disk, network, CD, USB.
Typically CPU's used to read either address zero or 0xFFFF-(address length-1) (add F's if your address room is larger) and take that as the start address of the boot loader.
There is also the possibility that the CPU starts by loading a micro code into the CPU and then starts the real assembler code from a predetermined address.

What are the likely causes of the same program running significantly slower on only slightly different machines? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I have a mix of Dell machines, all bought at the same time, with only slightly different specs. The Windows Experience index is almost identical.
Yet my program runs at a speed difference of 25-40% (i.e. really noticeable) on the machines.
They are all out-of-the-box business Dells, no extra programs running (not that take up significant resources anyway).
My program is graphics-based, loading in a lot of data and then processing it on the CPU. CPU usage is identical on all machines, I only use a single thread.
I'd expect maybe 5-10% variation based on the processors (according to benchmarks).
My programmer spidey-sense tells me that something is wrong here.
Is this going to be something like cache misses? Is there anything else I should be looking at?
I have used debugging programs such as WinDbg for these situations. There are a lot of tools in those programs to nail down where the exact bottleneck is. E.g. Run them side by side and identify which point the slower machine is lagging. If physical specs of the machines are identical, it is most likely some difference in network configuration if there is a bottleneck when it is downloading the graphics. In that case, a tool such as WireShark would show you what hops the application is taking over the network to retrieve the data. If netwrok configuration is identical, I wouldn't rule out a physcial problem with the machine such as faulty ram or dodgy network cable. Also, check out the running processes side by side and see if there is any difference, kill unnessessary tasks that may be taking up memory on the slower computer and remove if necessary.

where does OSs keep the programs that are not used for some minutes? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
Typically in a working environment, I have many windows open, Outlook, 2/3 word docuements, few windows in browser, notepad++, some vpn client, excel etc..
Having said that, there are chances that about 40% of these apps are not frequently used, but are referred only sparingly. They occupy memory none-the-less.
Now, how does a typical OS deal with that kind of memory consumption ? does it suspend that app to hard disk (pagefile , or linux swap area etc) thereby freeing up that memory for usage, or does it keep occupying the memory there as it is.
Can this suspension be a practical solution, doable thing ? Are there any downsides ? response time ?
Is there some study material I can refer to for reading on this topic/direction..
would appreciate the help here.
The detailed answer depends on your OS and how it implements its memory management, but here is a generality:
The OS doesnt look at memory in terms of how many processes are in RAM, it looks at in terms of discrete units called pages. Most processes have several pages of RAM. Pages that are least referenced can be swapped out of RAM and onto the hard disk when physical RAM becomes scarce. Rarely, therefore, is an entire process swapped out of RAM, but only certain parts of it. It could be, for example, that some aspect of your currently running program is idle (ie the page is rarely accessed). In that case, it could be swapped out even though the process is in the foreground.
Try the wiki article for starters on how this process works and the many methods to implement it.

Why are GPUs more powerful than CPUs [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
The community reviewed whether to reopen this question 2 months ago and left it closed:
Original close reason(s) were not resolved
Improve this question
How are GPUs more faster then CPUs? I've read articles that talk about how GPU's are much faster in breaking passwords than CPUs. If thats the case then why can't CPUs be designed in the same way as GPUs to be even in speed?
GPU get their speed for a cost. A single GPU core actually works much slower than a single CPU core. For example, Fermi GTX 580 has a core clock of 772MHz. You wouldn't want your CPU with such a low core clock nowadays...
The GPU however has several cores (up to 16) each operating in a 32-wide SIMD mode. That brings 500 operations done in parallel. Common CPUs however have up to 4 or 8 cores and can operate in 4-wide SIMD which gives much lower parallelism.
Certain types of algorithms (graphics processing, linear algebra, video encoding, etc...) can be easily parallelized on such a huge number of cores. Breaking passwords falls into that category.
Other algorithms however are really hard to parallelize. There is ongoing research in this area... Those algorithms would perform really badly if they were run on the GPU.
The CPU companies are now trying to approach the GPU parallelism without sacrificing the capability of running single-threaded programs. But the task is not an easy one. The Larabee project (currently abandoned) is a good example of the problems. Intel has been working on it for years but it is still not available on the market.
GPUs are designed with one goal in mind: process graphics really fast. Since this is the only concern they have, there have been some specialized optimizations in place that allow for certain calculations to go a LOT faster than they would in a traditional processor.
In the case of password cracking (or the molecular dynamic "folding at home" project) what has happened is that programmers have found ways of leveraging these optimized processes to do things like crunch passwords at a faster rate.
Your standard CPU has to do a lot more different calculation and processing types that what graphics processors do, so they can't be optimized in a similar manner.

Resources