I am reading some data from USB, do some packet processing and then send the result to the Ethernet port. The USB ports are connected to an onboard USB Hub where it communicates with the Microprocessor via PCIe bus. Also, the Ethernet HW communicates with the Microprocessor via PCIe bus. The program itself is small and written in C. (less than 100 KB).

How can I guarantee the DRAM is never used? Any suggestions, Compiler directives?

  • 3
    There's not enough information in your question to make it reasonably answerable. If not DRAM, then what? C uses memory by design. – Robert Harvey Jun 10 at 13:03
  • The usual way to make sure a tight loop stays in the cache is to simply keep it as small as possible. – Robert Harvey Jun 10 at 13:13
  • 2
    You listed a number of relatively irrelevant details but didn't mention what kind of operating system you use. If it's not a realtime OS that allows you to tightly control the hardware including CPU then you're at the mercy of the OS. Sooner or later its scheduler will run another task, evicting your cached code into RAM. – Hans-Martin Mosner Jun 10 at 13:38
  • 1
    Please expand your question to include more background detail and your design intent. You have received a number of downvotes likely because your question is poorly formed and lacks this background detail. – Jason K. Jun 10 at 16:51

The only way to guarantee that no DRAM gets used by your program is to make sure that the computer running your program uses some other kind of RAM modules.

Unless you have a severely underpowered processor in your system, such that 100% CPU time is required to copy bytes between modules on the PCIe bus, your program will spend part of the time waiting for data to arrive (and on a fast processor, it might be the majority of the time).

While your program is waiting for data, the processor will go off and do other things. During that time, your program has to exist somewhere and that can't be cache, because there is no mechanism to tell the processor that certain unused cache lines may not be removed. After all, cache is just an optimization in the processor to let it run faster than the memory bus can keep up with if every word has to be retrieved separately.

So, if your program can't stay in cache while waiting, you would want it in the next fastest place, so that you have the least amount of delay when the data it was waiting for arrives. That place happens to be the RAM of the computer.

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.