Skip to content

luaengine: expose device state entries - #100

Merged
mmicko merged 3 commits into
mamedev:masterfrom
lucab:lucab/mame-lua/devstate
Jan 11, 2015
Merged

mmicko merged 3 commits into
mamedev:masterfrom
lucab:lucab/mame-lua/devstate

Conversation

@lucab

@lucab lucab commented Jan 11, 2015

Copy link
Copy Markdown
Contributor

These commits expose device_state_entry to LUA, providing methods
to enumerate available states for a device object, as well as getting
and setting their values. Mostly usefull to inspect and manipulate registers content.

Signed-off-by: Luca Bruno lucab@debian.org

lucab added 3 commits January 11, 2015 10:19
Don't mix names and tags when exposing devices to LUA.
While at it, also provide the shortname.

Signed-off-by: Luca Bruno <lucab@debian.org>
Provide a Stack<UINT64> specialization for luabridge, later
needed by some APIs.

Signed-off-by: Luca Bruno <lucab@debian.org>
This commit exposes device_state_entry to LUA, providing methods
to enumerate available states for a device object, as well as getting
and setting their values.
It is mostly usefull to inspect and manipulate registers content.

Signed-off-by: Luca Bruno <lucab@debian.org>
mmicko added a commit that referenced this pull request Jan 11, 2015
luaengine: expose device state entries
@mmicko
mmicko merged commit bad1ab3 into mamedev:master Jan 11, 2015
@galibert

Copy link
Copy Markdown
Member

It's buggy though. You need to call the pre- methods before reading state,
and the post- methods after changing it.

OG.

On Sun, Jan 11, 2015 at 10:43 AM, Miodrag Milanović <
notifications@github.com> wrote:

Merged #100 #100.

—
Reply to this email directly or view it on GitHub
#100 (comment).

@lucab

lucab commented Jan 11, 2015

Copy link
Copy Markdown
Contributor Author

@galibert sorry, I'm still getting used to mame core and may miss some details here and there. Thanks for patiently checking my PRs.

I have some doubts after your last comment:

  • Should I go up to device_t::pre_save/post_load (notify all interface?) or are device_state_interface::interface_pre_save/interface_post_load (notify state interface?) enough?
  • What's their relation with `device_state_entry::state_import/state_export``? Should I care here?
  • I don't see how to link a device_state_entry to its parent device_state_interface? Is there a way to retrieve it that I'm not seeing? If not, should I add an upward pointer in the child?
  • Should I also take care of these notification mechanisms when dealing with address_space memory I/O?
  • A posteriori, I suspect that friend-ing lua_engine to device_state_entry is a big no-no

@galibert

Copy link
Copy Markdown
Member

Don't worry, I don't understand all of it either. And I wrote the original
version of the save state subsystem :-)

For presave, you need to extract the pre-save part of
save_manager::write_file in its own method. I mean the "for
(state_callback *func = m_presave_list.first(); func != NULL; func =
func->next()) func->m_func();" part. Save for post_load, of course.

I'm in the process of adding the device to the state_entry structure, and
also making it public. It's essentially for the same use case as you,
except it's access from the debugger. So don't worry about the friend
thingy, it'll be fixable better later.

As for state_import/export it's used for the display and modification of
registers in the debugger, so no worry there.

Best,

OG.

On Sun, Jan 11, 2015 at 5:23 PM, Luca Bruno notifications@github.com
wrote:

@galibert https://github.com/galibert sorry, I'm still getting used to
mame core and may miss some details here and there. Thanks for patiently
checking my PRs.

I have some doubts after your last comment:

  • Should I go up to device_t::pre_save/post_load (notify all
    interface?) or are
    device_state_interface::interface_pre_save/interface_post_load (notify
    state interface?) enough?
  • What's their relation with
    device_state_entry::state_import/state_export`? Should I care here?
  • I don't see how to link a device_state_entry to its parent
    device_state_interface? Is there a way to retrieve it that I'm not
    seeing? If not, should I add an upward pointer in the child?
  • Should I also take care of these notification mechanisms when
    dealing with address_space memory I/O?
  • A posteriori, I suspect that friend-ing lua_engine to
    device_state_entry is a big no-no

—
Reply to this email directly or view it on GitHub
#100 (comment).

drblythe added a commit to drblythe/mame-sgi that referenced this pull request Oct 24, 2026
…vity (task mamedev#100)

m_checkints_addrs (the sticky per-PC checkints-armed set, real
production code, not diagnostic-gated) grows for the entire session
with no clear()/bound anywhere - confirmed via a live gdb backtrace
that its periodic bucket-array rehash (351,061 buckets by ~95s into
boot) is a real ~11-13ms host-side stall, unrelated to the triggering
compile's own instruction count and affecting every build, not just
diagnostic runs.

Mitigates the immediate tail-latency problem with a one-time
reserve(1'000'000) on first insert (same pattern already proven on
m_diag_usermode_recompile_counts this session), converting the
periodic rehash stalls into one predictable upfront allocation.
Verified: over_10ms_threshold dropped to 0 after this fix.

Adds MAME_SGI_CHECKINTS_ARMED_FRACTION_DIAG to answer the follow-on
architectural question directly rather than guess: is the per-PC
sticky-set granularity buying real selectivity, or is checkints armed
for most compiled PCs anyway? Measured 99.01% armed (333,568 of
336,918 distinct compiled PCs) - the granularity buys almost nothing,
which favors reconsidering the whole mechanism over further optimizing
its bookkeeping. Important caveat carried in this diagnostic's own
comment: a blanket unconditional force was already tried once
(2026-07-23) and caused a 100%-reproducible early-boot TLB miss/kernel
fault, never root-caused - the 99% figure only weakens the selectivity
argument for keeping this mechanism, it says nothing about whether that
old structural bug is fixed. Diagnostic left enabled by deliberate
choice while this scoping question stays open (see wiki/tasks.md task
mamedev#100).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
drblythe added a commit to drblythe/mame-sgi that referenced this pull request Oct 24, 2026
…ostics (task mamedev#97)

Built to answer a real question this project had only measured
indirectly before: Bug B's own documented 373.9ms freeze (task mamedev#75,
console.md) was correlated to a full drc_cache flush after the fact via
two unrelated diagnostics, matched by timestamp - no direct instrument
existed for "how much real host wall-clock time does a single
compile/flush event cost" until now. This is a genuinely different axis
from perf_ab_stats.sh's aggregate instructions/cycles comparison, which
can't distinguish "374ms in one lump" from "374ms spread across many
small pieces".

MAME_SGI_STALL_DURATION_DIAG times execute_run()'s three
code_compile_block()/code_flush_cache() call sites (including a third,
previously-unattributed one inside code_compile_block()'s own
abort_compilation retry, which regenerates the entire static handler
set and was silently folding its cost into whatever compile call
triggered it) with real std::chrono wall-clock reads, reporting
per-event max/total and a count over a DoS-relevant threshold (10ms,
matching the confirmed 100Hz guest tick period - tight enough to catch
"could this discretely miss a transient real-world event", not just
"would a human perceive a stutter").

MAME_SGI_COMPILE_LENGTH_CORRELATION_DIAG answers whether a long compile
is a function of how far describe_code() had to traverse: tracks total
opcode_desc count and describe_code()'s own share of each compile's
duration, computing a Pearson correlation coefficient plus a log-scale
duration histogram at clean exit. Investigation built on these two
instruments found the real cause of this project's own ~11-13ms "long
compile" outliers was periodic libstdc++ hash-table rehashing in two
unbounded structures (m_diag_usermode_recompile_counts, fixed here with
a one-time reserve(); m_checkints_addrs, spun off as task mamedev#100) - not
compile length itself, which describe_code() timing directly ruled out
(0.01-0.16% share of outlier ns).

Both diagnostics disabled by default (non-trivial cost at ~1M compile
events/boot) - a deliberate-measurement toggle, not left on for
ordinary play, per their own header comments.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants