Skip to content

kali20gakki/msAgent / skills/host-cpu/msagent-perf-cpu-bind-tune

msagent-perf-cpu-bind-tune

Flagged

昇腾 NPU 多卡任务的 Host CPU 绑核方案求解器:覆盖 PyTorch 训练/离线推理与 vLLM-Ascend、SGLang 推理服务的 rank/worker/engine 分核,基于 NUMA 拓扑与 卡↔进程映射输出可执行、可回滚、可验证的绑核计划(taskset 前缀 / cpuset / OMP 环境变量),自动判定事前(env 片段)与事中(在线 sched_setaffinity)双形态。 触发:绑核方案、核怎么分、per-rank 绑核、NUMA 绑定方案、cpuset 划分、多卡分核、 CPU range 冲突、TTFT 或吞吐受 CPU 影响。 不用于:绑核没生效/绑核异常诊断(→ perf-cpu-config-audit);运行期是否落核 (→ perf-cpu-tracing);变慢根因归因(→ perf-cpu-perf-triage)。

scripts/workspace.py

View on GitHub
# -------------------------------------------------------------------------
# This file is part of the MindStudio project.
# Copyright (c) 2026 Huawei Technologies Co.,Ltd.
#
# MindStudio is licensed under Mulan PSL v2.
# You can use this software according to the terms and conditions of the Mulan PSL v2.
# You may obtain a copy of Mulan PSL v2 at:
#
#          http://license.coscl.org.cn/MulanPSL2
#
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
# See the Mulan PSL v2 for more details.
# -------------------------------------------------------------------------

"""工作空间与输出目录解析。

约定:
  工作空间 = Agent 运行时设置的工作路径(cwd),由宿主 / 远程执行插件决定;
  skill 不猜测自身安装位置,也不自行选择远端目录(远端拷贝与 cwd 由远程执行侧控制)。
  运行产物统一落 <workspace>/workspaces/<host>/<timestamp>/。

优先级:显式 root 参数 > HOSTCPU_WORKSPACE > 当前工作目录(cwd)。
"""

import os
import re
import socket
import time


def safe_name(value):
    """主机名等外部输入进路径前的清洗:仅保留字母数字/点/横线/下划线。

    socket.gethostname() 在个别环境可能返回含路径分隔符或超长字符串,
    统一替换并截断,防止产物落盘位置被意外改写。
    """
    cleaned = re.sub(r"[^\w.-]+", "_", str(value or "")).strip("._")
    # 截断后再 rstrip:避免第 64 个字符恰为 . / _ 时留下非法尾字符
    return (cleaned or "unknown")[:64].rstrip("._") or "unknown"


def workspace_root(root=None):
    if root:
        return os.path.abspath(os.path.expanduser(root))
    env = os.environ.get("HOSTCPU_WORKSPACE")
    if env:
        return os.path.abspath(os.path.expanduser(env))
    return os.path.abspath(os.getcwd())


def session_dir(host=None, timestamp=None, root=None, create=True):
    """计算(并默认创建)本次会话的产物目录。

    create=False 时只返回路径、不落盘——供 --dry-run 使用,
    保证 dry-run 语义为「不产生任何文件系统副作用」。
    """
    host = safe_name(host or socket.gethostname())
    timestamp = safe_name(timestamp or time.strftime("%Y%m%d-%H%M%S", time.localtime()))
    path = os.path.join(workspace_root(root), "workspaces", host, timestamp)
    if create:
        os.makedirs(path, exist_ok=True)
    return path
rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first.Stars: 194kUpdated Claude CodeCodexVerifiedInstall