|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Firmware profiler (RA8_EMU_PROFILE): sampling, hooks, reports. More...
Go to the source code of this file.
Enumerations | |
| enum | prof_mode_t : uint8_t { k_prof_off = 0U , k_prof_wall = 1U , k_prof_insn = 2U } |
| Profiler mode parsed from RA8_EMU_PROFILE. More... | |
Functions | |
| double | board_now_s (void) |
| Monotonic wall-clock seconds. | |
| void | prof_load (const emu_elf_source_t *elf) |
| Collect + sort FUNC symbols (RA8_EMU_PROFILE only) for PC bucketing. | |
| void | prof_add (uint32_t pc, double dt) |
Attribute wall seconds to the function owning pc (wall mode). | |
| void | prof_report (void) |
| Print the top hot functions (by wall time or instruction count). | |
| void | emu_prof_install (uc_engine *uc) |
| Arm the per-instruction profiling hook (insn mode only). | |
| prof_mode_t | emu_prof_mode (void) |
| The latched profiler mode. | |
| uint64_t | emu_prof_total_insns (void) |
| Total instructions retired under the per-instruction hook. | |
| void | emu_prof_set_stop_pc (uint32_t pc) |
| Set the RA8_EMU_STOP_PC early-stop address (0 disables). | |
| bool | emu_prof_stop_hit (void) |
| Whether the RA8_EMU_STOP_PC address was reached. | |
Firmware profiler (RA8_EMU_PROFILE): sampling, hooks, reports.
Two profiling modes, bucketed by ELF FUNC symbol:
The run loop reads the mode / instruction totals / RA8_EMU_STOP_PC state through the accessors here; everything else stays private to emu_prof.c.
Split out of the ra8_emulator main translation unit; behaviour unchanged.
Definition in file emu_prof.h.
| enum prof_mode_t : uint8_t |
Profiler mode parsed from RA8_EMU_PROFILE.
Selected once by prof_load() from the environment; the run loop branches its wall-sampling and idle-stop logic on the mode.
| Enumerator | |
|---|---|
| k_prof_off | Disabled (no env, zero cost). |
| k_prof_wall | =1: cheap chunk-start wall-time sampler. |
| k_prof_insn | =full/=insn: exact per-instruction + calls. |
Definition at line 50 of file emu_prof.h.
| double board_now_s | ( | void | ) |
Monotonic wall-clock seconds.
CLOCK_MONOTONIC as a double, the time base of the wall-sample profiler mode (and any other host-side wall measurement).
| 0.0 | Only if the clock read fails (it does not on supported hosts). |
Definition at line 31 of file emu_prof.c.
References s_nsec_per_sec.
Referenced by internal_run_loop_prologue().
| void emu_prof_install | ( | uc_engine * | uc | ) |
Arm the per-instruction profiling hook (insn mode only).
Installs the UC_HOOK_CODE that tallies every instruction, call entry, and call-chain sample. A no-op in off/wall modes so those runs pay nothing.
| [in,out] | uc | Unicorn engine to hook. |
uc is initialised. uc is untouched. Arm the per-instruction profiling hook (insn mode only).
Definition at line 940 of file emu_prof.c.
References internal_prof_insn_hook(), k_prof_insn, and s_prof_mode.
Referenced by internal_main_install_run_seams().
| prof_mode_t emu_prof_mode | ( | void | ) |
The latched profiler mode.
| k_prof_off | Profiling disabled. |
| k_prof_wall | Wall-time sampling. |
| k_prof_insn | Per-instruction profiling. |
The latched profiler mode; this step is contained within the emu prof model and uses bounded caller or module-owned storage.
The latched profiler mode.
Definition at line 949 of file emu_prof.c.
References s_prof_mode.
Referenced by internal_run_loop_prologue(), and internal_run_stop_prof_idle().
| void emu_prof_set_stop_pc | ( | uint32_t | pc | ) |
Set the RA8_EMU_STOP_PC early-stop address (0 disables).
The per-instruction hook ends the run the first time PC reaches this address, letting a profile span exactly the boot path. The caller clears the Thumb bit before passing.
| [in] | pc | Stop address (Thumb bit already cleared), or 0 to disable. |
Set the RA8_EMU_STOP_PC early-stop address (0 disables).
Definition at line 961 of file emu_prof.c.
References s_prof_stop_pc.
Referenced by internal_guard_apply_stop_pc().
| bool emu_prof_stop_hit | ( | void | ) |
Whether the RA8_EMU_STOP_PC address was reached.
| false | The stop PC is disabled or not yet reached. |
Whether the ra8_emu_stop_pc address was reached; this step is contained within the emu prof model and uses bounded caller or module-owned storage.
Whether the RA8_EMU_STOP_PC address was reached.
Definition at line 967 of file emu_prof.c.
References s_prof_stop_hit.
Referenced by internal_run_inner_check_stops(), and internal_run_loop_run_chunk().
| uint64_t emu_prof_total_insns | ( | void | ) |
Total instructions retired under the per-instruction hook.
The run loop's compute-idle auto-stop differences this counter per chunk to detect the steady idle frame loop.
| 0 | No instructions counted yet (or not in insn mode). |
Total instructions retired under the per-instruction hook.
Definition at line 955 of file emu_prof.c.
References s_prof_total_i.
Referenced by internal_run_stop_prof_idle().
| void prof_add | ( | uint32_t | pc, |
| double | dt ) |
Attribute wall seconds to the function owning pc (wall mode).
A no-op outside wall-sample mode. The run loop calls this once per chunk with the previous chunk's start PC and elapsed wall time.
| [in] | pc | Chunk-start program counter (bucketing key). |
| [in] | dt | Elapsed wall seconds to charge. |
dt is a non-negative wall-time delta. dt; otherwise nothing changed. Attribute wall seconds to the function owning pc (wall mode).
Definition at line 210 of file emu_prof.c.
References internal_prof_find(), k_prof_wall, s_prof, s_prof_mode, s_prof_n, and s_prof_total_s.
Referenced by internal_run_loop_prologue().
| void prof_load | ( | const emu_elf_source_t * | elf | ) |
Collect + sort FUNC symbols (RA8_EMU_PROFILE only) for PC bucketing.
Reads RA8_EMU_PROFILE to pick the mode; when enabled, walks the ELF .symtab for sized FUNC symbols, records each one's [entry, end) range and name, and sorts by entry address so per-PC lookup can binary-search. With the variable unset the profiler stays off at zero cost.
| [in] | elf | Open ELF source; symbol names are retained as source offsets. |
elf is a validated ELF32 source. Definition at line 160 of file emu_prof.c.
References elf_foreach_symbol(), internal_prof_cmp(), internal_prof_symbol(), k_prof_insn, k_prof_off, k_prof_wall, priv_emu_io_errf(), s_prof, s_prof_elf, s_prof_mode, s_prof_n, and strcmp().
Referenced by internal_main_install_run_seams().
| void prof_report | ( | void | ) |
Print the top hot functions (by wall time or instruction count).
The run-end report. In per-instruction mode it additionally emits the speedscope JSON export, the local HTML flamechart, the boot timeline, and the inclusive/self table. A no-op when profiling was off or nothing was sampled.
Print the top hot functions (by wall time or instruction count).
Definition at line 892 of file emu_prof.c.
References internal_prof_name(), internal_prof_report_flamechart(), k_prof_insn, k_prof_off, k_prof_top_n, priv_emu_io_err_text(), priv_emu_io_errf(), s_percent_scale, s_prof, s_prof_mode, s_prof_n, s_prof_total_i, s_prof_total_s, and s_samp_n.
Referenced by internal_run_print_stop_summary().