0
0
Embedded Cprogramming~5 mins

Why DMA is needed in Embedded C - Performance Analysis

Choose your learning style9 modes available
Time Complexity: Why DMA is needed
O(n)
Understanding Time Complexity

We want to understand how using DMA affects the time it takes to move data in embedded systems.

How does DMA change the work the CPU does when transferring data?

Scenario Under Consideration

Analyze the time complexity of CPU-driven data transfer versus DMA-driven transfer.


// CPU-driven data copy
for (int i = 0; i < n; i++) {
    dest[i] = src[i];
}

// DMA-driven data copy
// CPU starts DMA and continues other work
// DMA controller copies data independently
    

This code shows a simple loop where the CPU copies data byte by byte, compared to using DMA which handles copying without CPU involvement.

Identify Repeating Operations

Look at what repeats during data transfer.

  • Primary operation: Copying each data element from source to destination.
  • How many times: Exactly n times, where n is the data size.
How Execution Grows With Input

As the data size grows, the CPU copy loop runs more times, taking more CPU time.

Input Size (n)Approx. CPU Copy Operations
1010
100100
10001000

Pattern observation: CPU work grows directly with data size, so bigger data means more CPU time spent copying.

Final Time Complexity

Time Complexity: O(n)

This means the CPU time to copy data grows linearly with the amount of data.

Common Mistake

[X] Wrong: "Using DMA makes data transfer instant and cost-free for the CPU."

[OK] Correct: DMA still takes time to move data, but it frees the CPU to do other tasks during that time.

Interview Connect

Understanding how DMA changes CPU workload helps you explain efficient embedded system design clearly and confidently.

Self-Check

What if the CPU had to copy data in smaller chunks repeatedly instead of one big loop? How would that affect time complexity?