feat(ecat): 启动后把 ecat_native 提到 RealTime;跳拍优化实验脚本与报告
- esp32_server: Popen 后外部 SetPriorityClass(RT/High),native 自设会被钳成 High - 入库 skip_* 标定/实验脚本与 REPORT_ecat_skip_opt_20260917 - 前端 WIP:layout/app/polling/boot_ecat/index - 不含 lab/skip_meter 原始采样与 preview 截图
This commit is contained in:
@@ -178,6 +178,35 @@ g_ecat_log_fp = None # native stdout 落盘句柄(见 _ecat_autostart 内注
|
||||
g_ecat_lock = threading.Lock() # 串行化自动启动, 避免并发请求拉起多个进程
|
||||
|
||||
|
||||
def _set_ecat_realtime(pid: int) -> bool:
|
||||
"""把 ecat_native 提到 RealTime 进程优先级。
|
||||
|
||||
native 自己 SetPriorityClass(RT) 会被系统静默钳成 High(令牌无
|
||||
SeIncreaseBasePriorityPrivilege)。由本服务(启动方)从外部设置才能粘住。
|
||||
pdo 线程已是 TIME_CRITICAL:进程类 High→线程 15,RealTime→线程 31,
|
||||
后者才扛得住桌面 DPC/调度抢占。实测 1ms 档 late ~12/s → 个位数。
|
||||
失败返回 False,不影响启动。
|
||||
"""
|
||||
try:
|
||||
import ctypes
|
||||
import ctypes.wintypes as wt
|
||||
PROCESS_SET_INFORMATION = 0x0200
|
||||
REALTIME_PRIORITY_CLASS = 0x00000100
|
||||
HIGH_PRIORITY_CLASS = 0x00000080
|
||||
k32 = ctypes.WinDLL("kernel32", use_last_error=True)
|
||||
h = k32.OpenProcess(PROCESS_SET_INFORMATION, False, int(pid))
|
||||
if not h:
|
||||
return False
|
||||
try:
|
||||
if k32.SetPriorityClass(h, REALTIME_PRIORITY_CLASS):
|
||||
return True
|
||||
return bool(k32.SetPriorityClass(h, HIGH_PRIORITY_CLASS))
|
||||
finally:
|
||||
k32.CloseHandle(h)
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
|
||||
class _GuiApi:
|
||||
"""暴露给窗口内 JS (window.pywebview.api) 的 GUI 控制接口。"""
|
||||
|
||||
@@ -342,6 +371,10 @@ def _ecat_autostart():
|
||||
creationflags=getattr(subprocess, "CREATE_NO_WINDOW", 0),
|
||||
)
|
||||
logs.append(f"已自动启动 EtherCAT 原生守护进程(pid {g_ecat_child.pid})")
|
||||
if _set_ecat_realtime(g_ecat_child.pid):
|
||||
logs.append(f"EtherCAT 进程优先级已提到 RealTime(pid {g_ecat_child.pid})")
|
||||
else:
|
||||
logs.append("EtherCAT 进程 RealTime 提权失败(保持默认/High, 可手动设)")
|
||||
except OSError as e:
|
||||
return None, logs + [f"启动 EtherCAT 服务失败: {type(e).__name__}: {e}"]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user