Lecture 6 - Resource constrained programming Flashcards

1
Q

What is a microcontroller?

A

A small computer
CPU, RAM, program storage, peripherals (ports, clocks, DAC/ADC, GPIO, other)

All components are on a single chip

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the difference between a PC and a micro controller?

A

Micro controller has weaker performance, but uses far less power.
Low transistor count and because of this really cheap.

Limited pluggability (keyboard, …) and peripherals

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the constraints of micro controllers that you need to have in mind when programming them?

A

Memory, performance, Code size (storage, limits on OS functionality, support libraries), power

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

When looking at performance constraints, what are some things we need to look at?

A

Algorithmic space-time tradeoff:
- More CPU time - less memory
- Less CPUtime - more memory

Most gains on algorithmic level - avoid doing unecessary work

Every function call adds overhead - use inlining, static functions, macros

Reduce Load/stores

Use a profiler to identify hotspots where optimization is needed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What do we need to think about when it comes to power constraints?

A

How you MCU operates most of the time: mostly sleep or mostly work

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How can we optimize power use for a MCU that is mostly sleeping?

A

Most of the time sleeping:
- Leakage is the main power eater
- circuit is mostly acting as resistor
- What hardware can we turn off on sleep
- What is the cost of waking up

Maximize sleep time: One wakeup is better than many smaller ones. Keep frequency high

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How can we optimize power use for a MCU that is mostly awake?

A

Most of the time working:
- Transistor toggling the main power eater
- Can we reduce CPU frequency
- Can we reduce voltage
- reduce expensive operations (load/store)

Reduce workloads:
- frequency gridlocked with voltage
- CPU power scaling per V is cubic
- clocking down is better than sleeping
- reduce workload to allow cpu to do that

P_dynamic = CV²f

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the CPU power formula?

A

P_cpu = P_dyn + P_sc + P_leak

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

When looking at storage constraints, what are factors we need to think about?

A

Optimizations:
- Store data efficiently
- generate data, don’t load them?
- Use the libraries we have available
- remove unused libraries

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

When looking at memory constraints (RAM), what are things we need to think about?

A

Algorithmic tradeoff:
- More CPU time - less memory

Code is either in RAM or ROM, if RAM
- Smaller code size -> less memory footprint
- keep track of what compiler puts in code

Stack cost - avoid recursion

use minimal datatypes, clever/simpler datastructures

structures alignes to the worst member. If one variable is 8 bytes(double), the structure must be 8-byte aligned (if power point was understood correctly?)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How can you set bits using bitmasks?

A

Use | operator (or)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How can you clear bits using bitmasks?

A

Use & operator (and)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How can you toggle bits using bitmasks?

A

Use ^ operator (xor)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How should you do conditional statements using bitmasks

A

if(KEY_A & KEY_DOWN)

Check if A has been pushed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What does the volatile keyword do?

A

Guarantees that the compiler won’t reorder volatile operations

Compiler won’t optimize away volatile operations

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are some pitfalls when it comes to volatile operations?

A

No guarantees on atomicity - threads can be rescheduled

17
Q

What can be used to ensure completion of instructions before program continue?

A

Barriers

barrier(): Code above will be issued before code below. This is a compiler directive, not an instruction. Volatile does this as well

mb(): Memory ops above completed before instructions below are issued

rmb(): read-memory-barrier, as mb, but for reads only

wmb(): Write-memory-barrier, as above, but for writes only

18
Q
A