代码拉取完成,页面将自动刷新
同步操作将从 openEuler/wayca-scheduler 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#!/usr/bin/python
#
# Author: Yicong Yang <young.yicong@outlook.com>
# Copyright (c) 2021 HiSilicon Technologies Co., Ltd.
#
# Wayca scheduler 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.
from time import sleep
from bcc import BPF
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("-f", "--cpufrom", type = int, help = "the cpu where the migration started from", required = True)
parser.add_argument("-t", "--cputo", type = int, help = "the cpu where the migration targeted to", required = True)
parser.add_argument("-p", "--pid", type = int, help = "the migration task's pid", required = True)
args = parser.parse_args()
cpu_from = args.cpufrom
cpu_to = args.cputo
pid = args.pid
bpf_text = """
#include <uapi/linux/ptrace.h>
#include <linux/sched.h>
#include <linux/types.h>
struct stats {
u64 last;
u64 total;
u64 counts;
u64 prev_cpu;
};
BPF_HASH(stat, int, struct stats, 1);
int trace_ts(struct pt_regs *ctx, struct task_struct *prev)
{
int cpu = bpf_get_smp_processor_id(), key = 0, cpu_from, cpu_to;
u64 ts = bpf_ktime_get_ns(), delta;
pid_t prev_pid, cur_pid;
struct stats *stat_p;
cur_pid = bpf_get_current_pid_tgid() & 0xffff;
prev_pid = prev->pid;
cpu_from = FROM;
cpu_to = TO;
if (cur_pid != PID)
return 0;
ts = bpf_ktime_get_ns();
stat_p = stat.lookup(&key);
if (!stat_p) {
struct stats init = {
.last = ts,
.total = 0,
.counts = 0,
.prev_cpu = cpu,
};
stat.update(&key, &init);
return 0;
}
if (cpu == cpu_from) {
stat_p->last = ts;
} else if (cpu == cpu_to && cpu != stat_p->prev_cpu) {
delta = ts - stat_p->last;
stat_p->total += delta;
stat_p->counts++;
}
stat_p->prev_cpu = cpu;
return 0;
}
"""
bpf_text = bpf_text.replace("FROM", "%d" % (cpu_from))
bpf_text = bpf_text.replace("TO", "%d" % (cpu_to))
bpf_text = bpf_text.replace("PID", "%d" % (pid))
b = BPF(text = bpf_text)
b.attach_kprobe(event="finish_task_switch", fn_name="trace_ts")
print("Start tracing...")
exiting = 0
while True:
try:
sleep(999999)
except KeyboardInterrupt:
exiting = 1
if exiting:
print("Exiting...")
for key, value in b["stat"].items():
if not value.counts:
break
print("Total %d migrations from %d -> %d, average cost %f ns" % (value.counts, cpu_from, cpu_to, value.total / value.counts))
exit()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。