mohitmishra786/low-level-dev-skills

resource-optimization-lowend

Resource optimization skill for constrained embedded targets.

Vedi sorgente

Come usare

  1. Copia il comando e controlla il pacchetto prima di installarlo nel tuo ambiente agente.
  2. Controlla strumenti, credenziali e ambienti richiesti nel documento originale.
  3. Descrivi input e risultato desiderato; confronta l’output con le fonti.
npx skills add https://github.com/mohitmishra786/low-level-dev-skills --skill resource-optimization-lowend

Prima di iniziare

  • L’installazione non include abbonamenti, quote API o accesso ai file.
  • Stelle e installazioni indicano attività, non un test indipendente di qualità o sicurezza.
Documento Skill originale

Contenuto dal repository con titoli, esempi, codice, tabelle, link e immagini preservati.

Resource Optimization (Low-End Systems)

Purpose

Guide agents through flash and RAM optimization on constrained devices: compiler size flags, linker map analysis, stack usage measurement, dead code elimination, and size-vs-speed tradeoffs — for bare-metal and small RTOS images.

When to Use

  • Firmware exceeds flash budget
  • Stack overflow in production only
  • Choosing -Os vs -O2 on MCU
  • Finding unexpected .rodata or .bss growth

Workflow

1. Size measurement toolchain

bash
arm-none-eabi-size -A firmware.elf
arm-none-eabi-objdump -h firmware.elf
nm --size-sort -S firmware.elf | tail -20

2. Linker map file

ld
/* linker.ld */
OUTPUT_FORMAT("elf32-littlearm")
ENTRY(Reset_Handler)

SECTIONS
{
  /* ... */
}

/* Generate map */
/* gcc ... -Wl,-Map=firmware.map */
bash
grep -E '\.text|\.rodata|\.data|\.bss' firmware.map | head

Identify largest symbols and unexpected library pull-in.

3. Compiler flags

FlagEffect
-OsSize-first optimization
-ffunction-sections -fdata-sectionsPer-symbol sections
-Wl,--gc-sectionsDrop unused sections
-fltoCross-TU dead code elimination
-specs=nano.specsSmaller newlib (GCC ARM)
makefile
CFLAGS += -Os -ffunction-sections -fdata-sections
LDFLAGS += -Wl,--gc-sections -Wl,--print-memory-usage

4. Stack analysis

bash
# Static (if built with -fstack-usage)
find . -name '*.su' -exec cat {} \;

# Linker stack symbol
grep _estack firmware.map

Runtime: fill stack with pattern (0xDEADBEEF), run tests, scan high-water mark. FreeRTOS: uxTaskGetStackHighWaterMark.

5. RAM categories

SectionTactic
.bssShrink buffers; pool allocators
.dataMove const to flash (const → .rodata)
HeapAvoid malloc; fixed pools
StackReduce nesting; smaller ISR stacks

6. Size vs speed decision

Hot path in ISR or 1 kHz loop?
├── Yes → -O2 for that file (#pragma GCC optimize)
└── No  → -Os globally

7. Agent usage

/resource-optimization-lowend Find top 10 flash consumers in firmware.map and suggest -gc-sections fixes

Common Problems

SymptomCauseFix
printf pulls 20+ KBFull newlib printf_write retarget; tiny printf
--gc-sections broke IRQSection collectedKEEP() in linker script
Stack overflow lateDeep call + IRQ nestMeasure HW stack; increase _estack
RAM zero but big ELF.data not loadedCheck VMA/LMA
LTO link failMixed compiler versionsSame GCC for all objects

Related Skills

  • skills/embedded/linker-scripts — MEMORY/Sections layout
  • skills/baremetal/baremetal-startup — stack symbol
  • skills/baremetal/low-power-embedded — RAM retention
  • skills/compilers/gcc — optimization flags
  • skills/rust/rust-no-std — embedded Rust size patterns

Correlati per attività

dallo stesso repository

Altri Skills

Tutti gli Skills
mohitmishra786
Community

core-dumps

Core dump analysis skill for production crash triage. Use when loading core files in GDB or LLDB, enabling core dump generation on Linux/macOS, mapping symbols with debuginfo or debuginfod, or extracting backtraces from crashes without re-running the program. Activates on queries about core files, ulimit, coredumpctl, debuginfod, crash triage, or analyzing segfaults from production binaries.

installazioni
2
GitHub Stars
267
Aggiornato
27 giu
mohitmishra786
Community

custom-allocators

Custom allocator skill for memory allocation strategies. Use when implementing pool/slab/arena allocators, tuning jemalloc/mimalloc, writing Rust GlobalAlloc, or benchmarking allocator performance. Activates on queries about jemalloc, mimalloc, tcmalloc, arena allocator, GlobalAlloc, or fragmentation.

installazioni
2
GitHub Stars
267
Aggiornato
27 giu
mohitmishra786
Community

ebpf

eBPF skill for Linux observability and networking. Use when writing eBPF programs with libbpf or bpftrace, attaching kprobes/tracepoints/XDP hooks, debugging verifier errors, working with eBPF maps, or achieving CO-RE portability across kernel versions. Activates on queries about eBPF, bpftool, bpftrace, XDP programs, libbpf, verifier errors, eBPF maps, or kernel tracing with BPF.

installazioni
2
GitHub Stars
267
Aggiornato
27 giu
mohitmishra786
Community

flamegraphs

Flamegraph generation and interpretation skill. Use when converting perf, Valgrind Callgrind, or other profiler output into SVG flamegraphs using Brendan Gregg's FlameGraph tools, or when reading flamegraphs to identify performance bottlenecks. Activates on queries about flamegraphs, stackcollapse, flamegraph.svg, identifying hot frames, wide vs tall frames, or performance visualisation.

installazioni
2
GitHub Stars
267
Aggiornato
27 giu