Commit Graph

50 Commits

Author SHA1 Message Date
Huamonarch
e4233cc23d fix: add period_ms to linear and drift models to prevent unbounded divergence
Without period, y=k*t+b and y=base+drift_rate*t grow infinitely, which is
unrealistic for industrial simulation. period_ms makes t wrap modulo the period,
producing sawtooth patterns that simulate per-cycle behavior (e.g. tension build-up
per coil, sensor drift per shift).
2026-05-13 16:34:00 +08:00
Huamonarch
256aa07c1c docs: add comprehensive RNG project README 2026-05-13 16:14:42 +08:00
Huamonarch
47dd4fad4b fix: qualify is_same_v with std:: in FlowData constructor 2026-05-13 16:02:27 +08:00
Huamonarch
f41ce0c40f fix: GuassRand use sigma as stddev directly instead of sqrt(sigma) 2026-05-13 15:53:25 +08:00
Huamonarch
5ee17627e9 fix: address code review issues
- read_csv.hpp: replace std::exit(1) with std::runtime_error throw
- read_csv.hpp: remove duplicate #pragma once
- RNG.cc: wrap JSON load in try-catch to prevent crash on missing config
- Generator.cc: fix comments to reflect actual 3-pass structure
2026-05-13 15:46:06 +08:00
Huamonarch
d9b4ee8eb3 fix: prevent ValvePairModel stuck-state by freezing prev_action during delay 2026-05-13 15:43:56 +08:00
Huamonarch
10bb9937d6 chore: remove unused BaseData.h 2026-05-13 15:33:36 +08:00
Huamonarch
7385b7cc6e build: add model/ source directory to CMake 2026-05-13 15:27:22 +08:00
Huamonarch
022993ab5a feat: load rng_models.json on startup 2026-05-13 15:26:19 +08:00
Huamonarch
4821cb9d36 refactor: replace hardcoded signal mappings with ModelRegistry 2026-05-13 15:24:32 +08:00
Huamonarch
b4bb27f1e5 feat: add ModelRegistry with JSON loading and composite model
Add CompositeModel for combining base+noise models, ModelRegistry singleton
with JSON-based model template loading, per-instance-key model isolation,
and inline CSV/valve pair/composite syntax parsing in createModel.
2026-05-13 15:20:51 +08:00
Huamonarch
4f83e41c0c feat: add ValvePairModel with jitter/flash/over-delay 2026-05-13 15:15:14 +08:00
Huamonarch
3ce03911c3 feat: add 3 boolean signal models 2026-05-13 15:13:31 +08:00
Huamonarch
2ef663af81 feat: add CsvReplayModel for CSV data replay 2026-05-13 15:12:04 +08:00
Huamonarch
afd753f803 feat: add 7 analog signal models (constant, normal, linear, sine, uniform, spike, drift) 2026-05-13 15:10:37 +08:00
Huamonarch
6afce89326 feat: add IModel base interface 2026-05-13 15:07:59 +08:00
Huamonarch
ae5f55c8ac feat: add rng_models.json with model templates 2026-05-13 15:07:06 +08:00
Huamonarch
70a976fe58 chore: add .worktrees/ to .gitignore 2026-05-13 15:04:31 +08:00
Huamonarch
7339801f2f docs: add RNG parameterized models implementation plan
11 tasks covering JSON config, 14 model classes, ModelRegistry factory,
Generator refactoring, valve_pair linking, and CMake updates.
2026-05-13 15:02:58 +08:00
Huamonarch
302aa82e38 docs: add valve_pair jitter/over-delay fault simulation params
delay_jitter_ms for natural timing variation, delay_over_prob/delay_over_ms
for simulating occasional valve timeout faults (e.g. once per day).
2026-05-13 14:47:35 +08:00
Huamonarch
a93801fea5 docs: fix rng_models.json path to absolute Linux path 2026-05-13 14:38:17 +08:00
Huamonarch
71feae9e79 docs: add RNG parameterized models design spec
Config-driven random number generation with model templates in JSON and
signal-to-model binding via DB2 tables[1] field. Supports 9 analog modes,
4 boolean modes including valve_pair timing simulation.
2026-05-13 14:32:58 +08:00
Huamonarch
11e5a6aeef Use angle-bracket include for async_db_worker.h
Matches codebase convention: all includes use <> paths, never "".
2026-05-13 13:51:49 +08:00
Huamonarch
f80a917ab7 Async-ify ExpTimes DB persistence with global singleton worker thread
Add AsyncDbWorker: a persistent background thread with dedup queue that
executes DB2 writes asynchronously, keeping the mon 20ms cycle free of
blocking I/O.

Changes:
- async_db_worker.h/.cc: singleton worker, submit() with rule_id dedup,
  drain_and_stop() for clean shutdown
- eqp_stat.h/.cc: new update_static(ruleid, shear_times, running_time)
  overload that skips redundant DB reads for known values (reduces
  5 SELECTs to 3 per persist cycle)
- exp_times.cc: extract persist_exp_times() as a standalone function,
  update_history_times() snapshots values and submits to worker
  (returns immediately), reset_dev_data() uses direct SHM update
- eqpalg_icei.cpp: alg_mgr_.reset() → drain_and_stop() in destructor
  ensures all algorithm threads are stopped before draining the worker

Risk: re-run cmake .. to pick up the new async_db_worker.cc file.
2026-05-13 13:32:50 +08:00
Huamonarch
6ed178b367 Fix: protect update_history_times snapshot restore from DB failures
Three fixes in update_history_times():
1. Wrap DB operations in try-catch — exception no longer skips the
   snapshot restore, preventing permanent loss of accumulated counts
2. Treat get_history_times() -1 return (DB failure) as skip, not as
   "record exists" → no more silent UPDATE on non-existent rows
3. Only call update_static and advance last_load_time_ on success,
   so a failed persist retries on the next cycle instead of waiting
   another rw_time_ minutes
2026-05-13 12:59:16 +08:00
Huamonarch
b3932b0af8 Fix: update_cold must not overwrite SHM stat_values and fetch_mark
Mon's update_map_rule() called update_cold() which blindly copied
RuleStatLocal's stat_values (always empty in mon) and fetch_mark
(always false in mon) into SHM, destroying accumulated data and
breaking the mon-cron handshake.

stat_values and fetch_mark are managed exclusively by the
add_stat_value/get_stat_value handshake. The cold sync path only
needs to transport running_time and shear_times.
2026-05-13 11:22:42 +08:00
Huamonarch
02447c733a Replace U+00B5 (MICRO SIGN) with plain 'us' to avoid Unicode warning
Gitea flags U+00B5 as ambiguous — visually identical to U+03BC
(GREEK SMALL LETTER MU). Using 'us' is the standard engineering
abbreviation and avoids the warning.
2026-05-13 10:33:08 +08:00
Huamonarch
9bb810d9ed Replace broken ColdMutex with dual-layer ShmSpinLock + std::mutex
The old ColdMutex (interprocess_mutex) was in process-local anonymous
namespace storage, so each process had its own copy — no actual
cross-process exclusion. Even if moved to SHM, interprocess_mutex is
not robust: a crash while holding the lock would deadlock on restart.

New design:
- ShmSpinLock: atomic<pid_t> in shared memory, kill(pid,0) detects
  dead owners (ESRCH → takeover), crash-safe by construction
- std::mutex: process-local, handles intra-process thread contention
  without burning CPU on the SHM spinlock
- DualLock: locks local first, then shm; unlocks in reverse

9 lock sites in MapRuleStat upgraded to std::lock_guard<DualLock>.
2026-05-13 10:21:55 +08:00
Huamonarch
b8596d311f Remove rm -rf of MapRuleStat_boost.mmap on startup
Dynamic shared-memory vectors no longer cause segfaults from
unbounded growth, so the brute-force file deletion on every
start is unnecessary. Consistent with e21b2af which removed
the same pattern for TaskData_boost.mmap.
2026-05-13 09:47:52 +08:00
Huamonarch
df79a9a1a5 Fix: add default constructor to TaskRecord for map operator[]
boost::container::map::operator[] default-constructs the mapped_type
when the key doesn't exist. TaskRecord lacked a default constructor
after the e21b2af refactor (only had an allocator-arg constructor).
Added a static vec_allocator_f (matching RuleStatShm.h pattern) and a
default constructor that initializes data_record with it.
2026-05-13 09:27:29 +08:00
Huamonarch
0a5397345c Fix: access TaskRecord::data_record vector after TaskData refactor
Commit e21b2af changed TaskShm map value from DataRecord (flat array)
to TaskRecord (struct wrapping shm_vector_f), but three call sites in
exp_base.cpp didn't drill into the .data_record member — they called
size()/operator[]/push_back() on TaskRecord itself, which has none.
2026-05-13 09:15:20 +08:00
Huamonarch
2c62f9c4a3 Add change documentation for 2026-05-12 eqpalg optimizations 2026-05-12 17:22:34 +08:00
Huamonarch
e21b2af2a6 Replace fixed 518MB array in TaskData with dynamic shared-memory vector
DataRecord used a fixed float[129600000] consuming 5GB disk even when
collecting only a few hundred data points. Replaced with shm_vector_f
that grows on demand via push_back. Removes the need for rm -rf on
process exit — vector destructor frees memory back to the segment.
Also drops now-unnecessary task_data_size member.
2026-05-12 17:19:44 +08:00
Huamonarch
1ca922a4ef Fix task thread lifecycle: self-destruct when idle, synchronized cleanup
HandlerExec in task mode now sets is_running_=false when rule_pointers_
and once_exec_queue_ are both empty. Manager cleanup uses two-phase
lock (shared_lock scan + unique_lock destroy/erase) synchronized with
exec_task via handles_mutex. exec_task checks is_running_ before submit
and destroys dead handlers to prevent task loss. Also fix logReset
self-assignment no-op.
2026-05-12 17:11:07 +08:00
Huamonarch
1e70af7a9d Remove rm -rf of shared memory file from EqpAlgICEI destructor
The workaround was needed because bipc::string items in shared memory would
segfault on restart when tag names exceeded SSO length. Now that display
data (items, etc.) lives in local-memory DisplayCache and only cold doubles
remain in shared memory, the dangling-allocator bug no longer exists.
Deleting the file also broke mon-cron IPC across restarts.
2026-05-12 16:17:09 +08:00
Huamonarch
973921fc4b Split RuleStat display from cold data paths to reduce lock contention
Display data (alarm_value, current_value, limit_up/down, items, unit) now
goes to a local-memory DisplayCache and is serialized to JSON without any
shared memory lock. Cold data (stat_values, running_time, shear_times, etc.)
stays in shared memory for mon-cron IPC, protected by a real interprocess
mutex (boost::interprocess::interprocess_mutex) instead of the broken
process-local std::mutex. AlgBase::rule_stat_ is now RuleStatLocal with
standard types — zero changes to algorithm subclass code.
2026-05-12 15:46:01 +08:00
Huamonarch
6a28112cd7 Final comment cleanup batch 2026-05-09 13:35:17 +08:00
Huamonarch
38bbdb5b34 Remove comment from roller3.cpp 2026-05-09 13:33:07 +08:00
Huamonarch
339074c1b4 Remove comment from manager.cc 2026-05-09 13:32:38 +08:00
Huamonarch
ecf02306b2 Remove final remaining comment from distribution.h 2026-05-09 13:32:24 +08:00
Huamonarch
c53b108500 Remove last remaining comments from eqpalg 2026-05-09 13:32:10 +08:00
Huamonarch
62a97cdf9d Remove remaining comments (exp_times, STA.h, gb_item_memory) 2026-05-09 13:31:22 +08:00
Huamonarch
48c9fe7f22 Remove remaining irrelevant comments from eqpalg (final batch) 2026-05-09 13:31:06 +08:00
Huamonarch
e3207fa593 Remove remaining irrelevant comments from eqpalg (glitch_detection, roller, STA) 2026-05-09 13:30:42 +08:00
Huamonarch
224c2c45c4 Remove irrelevant comments from eqpalg source files
Cleaned 66 files across all eqpalg subdirectories:
- Removed commented-out dead code
- Removed redundant Chinese inline comments that restate variable/function names
- Removed trailing ///< annotations on self-explanatory fields
- Removed namespace closing comments
- Preserved all file headers, Doxygen documentation, and logic explanations
- No code changes — only comment removal
2026-05-09 13:30:09 +08:00
Huamonarch
ef6612d2ea Add eqpalg optimization recommendations document
Covers 10 issues with root cause analysis, severity assessment,
and concrete solutions:
- P0: update_map_rule() global mutex bottleneck on shared memory map
- P0: Thread allocation imbalance (default taskSeq=0)
- P1: GetDataJson() full deep copy, event_handler lock hold time,
  cache_data() busy-loop, AlgBase::lm lock splitting
- P2-P3: tag index pre-resolution, cron batching, task thread cleanup
- Long-term: Memcached migration, thread pool, code path separation
2026-05-09 13:02:45 +08:00
Huamonarch
09b48b07e5 Add READMEs for all infrastructure services and overall project
- EIS_README.md: Overall project architecture, data flow, service inventory
- zmqp/zmqc_readme: ActiveMQ producer/consumer bridging ICE
- zcache_readme: Data cache hub with address mapping and type conversion
- zhd_readme: Real-time snapshot persistence to iHyperDB
- zinit_readme: DB2-to-shared-memory initialization service
- zsub/zudp/zdsf/rcv_readme: Data receiver layer for different on-site protocols
2026-05-09 12:13:00 +08:00
Huamonarch
bd7e93ae68 Add READMEs for RICS, eqpm, dsm and update eqpalg README with corrections
- RICS_readme.md: Rule information centralized display service
- eqpm_readme.md: Equipment predictive maintenance & status monitoring
- dsm_readme.md: Data save manager for historical data archiving
- eqpalg_readme.md: Corrected architecture, data flow, variable system,
  thread model, and inter-process relationships
2026-05-09 11:46:17 +08:00
Huamonarch
92a23222f7 Add eqpalg_readme.md — detailed documentation of equipment algorithm process 2026-05-09 11:30:37 +08:00
Huamonarch
7e602c7bc1 Initial commit: EIS C++ project with multi-process code 2026-05-09 11:23:45 +08:00