-
Notifications
You must be signed in to change notification settings - Fork 175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stack_Analyzer:Adapted to MagicEyes #720
Merged
Merged
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
fdcacea
new arrangement
GorilaMond 712fda4
update introduction
GorilaMond c4dfae9
update action
GorilaMond c289228
modify submodule
GorilaMond 06d585e
remove assets
GorilaMond 9989514
modify doc
GorilaMond 325166c
modify submodule
GorilaMond 1def496
modify ignore
GorilaMond 07c6e5e
modify ignore
GorilaMond ae1ef65
Merge branch 'develop' of github.com:linuxkerneltravel/lmp into struc…
GorilaMond a43bed5
Merge branch 'develop' of github.com:linuxkerneltravel/lmp into struc…
GorilaMond 48f3f67
adapt to MagicEyes
GorilaMond c1c8c08
update file header
GorilaMond 739e529
Achieve code consistency
GorilaMond 10bb16e
fix action err
GorilaMond 5dcb58a
fix off cpu probe mismatching
GorilaMond 22bba1e
fix bpf code
GorilaMond 869b045
Merge branch 'develop' of github.com:linuxkerneltravel/lmp into struc…
GorilaMond File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
132 changes: 0 additions & 132 deletions
132
MagicEyes/src/backend/system_diagnosis/stack_analyzer/bpf/pre_count.bpf.c
This file was deleted.
Oops, something went wrong.
File renamed without changes.
131 changes: 131 additions & 0 deletions
131
MagicEyes/src/backend/system_diagnosis/stack_analyzer/bpf/readahead.bpf.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
// Copyright 2023 The LMP Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://github.com/linuxkerneltravel/lmp/blob/develop/LICENSE | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// author: [email protected] | ||
// | ||
// 内核态bpf的预读取分析模块代码 | ||
|
||
#include "vmlinux.h" | ||
#include <bpf/bpf_helpers.h> | ||
#include <bpf/bpf_tracing.h> | ||
#include <bpf/bpf_core_read.h> | ||
|
||
#include "sa_ebpf.h" | ||
#include "task.h" | ||
#include "bpf/readahead.h" | ||
|
||
#define MINBLOCK_US 1ULL | ||
#define MAXBLOCK_US 99999999ULL | ||
|
||
DeclareCommonMaps(ra_tuple); | ||
DeclareCommonVar(); | ||
|
||
int apid = 0; | ||
BPF_HASH(in_ra, u32, psid); | ||
BPF_HASH(page_psid, struct page *, psid); | ||
|
||
SEC("fentry/page_cache_ra_unbounded") // fentry在内核函数page_cache_ra_unbounded进入时触发的挂载点 | ||
int BPF_PROG(page_cache_ra_unbounded) | ||
{ | ||
struct task_struct *curr = (struct task_struct *)bpf_get_current_task(); | ||
ignoreKthread(curr); | ||
u32 pid = get_task_ns_pid(curr); // 获取当前进程tgid,用户空间的pid即是tgid | ||
|
||
if ((apid >= 0 && pid != apid) || !pid || pid == self_pid) | ||
return 0; | ||
|
||
u32 tgid = get_task_ns_tgid(curr); | ||
bpf_map_update_elem(&pid_tgid, &pid, &tgid, BPF_ANY); // 更新pid_tgid表中的pid对应的值 | ||
comm *p = bpf_map_lookup_elem(&pid_comm, &pid); // p指向pid_comm表中pid对应的值 | ||
if (!p) | ||
{ | ||
comm name; | ||
bpf_get_current_comm(&name, COMM_LEN); // 获取当前进程名 | ||
bpf_map_update_elem(&pid_comm, &pid, &name, BPF_NOEXIST); // 在pid_comm表中更新pid对应的值 | ||
} | ||
|
||
psid apsid = { | ||
.pid = pid, | ||
.usid = u ? USER_STACK : -1, | ||
.ksid = k ? KERNEL_STACK : -1, | ||
}; | ||
|
||
ra_tuple *d = bpf_map_lookup_elem(&psid_count, &apsid); // d指向psid_count表中的apsid对应的类型为tuple的值 | ||
if (!d) | ||
{ | ||
ra_tuple a = {.expect = 0, .truth = 0}; // 初始化为0 | ||
bpf_map_update_elem(&psid_count, &apsid, &a, BPF_ANY); // 更新psid_count表中的apsid的值为a | ||
} | ||
bpf_map_update_elem(&in_ra, &pid, &apsid, BPF_ANY); // 更新in_ra表中的pid对应的值为apsid | ||
return 0; | ||
} | ||
|
||
SEC("fexit/alloc_pages") // fexit在内核函数alloc_pages退出时触发,挂载点为alloc_pages | ||
int BPF_PROG(filemap_alloc_folio_ret, gfp_t gfp, unsigned int order, u64 ret) | ||
{ | ||
u32 pid = bpf_get_current_pid_tgid() >> 32; // pid为当前进程的pid | ||
|
||
if ((apid >= 0 && pid != apid) || !pid) | ||
return 0; | ||
|
||
struct psid *apsid = bpf_map_lookup_elem(&in_ra, &pid); // apsid指向了当前in_ra中pid的表项内容 | ||
if (!apsid) | ||
return 0; | ||
|
||
ra_tuple *a = bpf_map_lookup_elem(&psid_count, apsid); // a是指向psid_count的apsid对应的内容 | ||
if (!a) | ||
return 0; | ||
|
||
const u32 lim = 1ul << order; // 1 为长整型,左移order位,即2^order 即申请页的大小 | ||
a->expect += lim; // a->expect+=页大小(未访问) | ||
u64 addr; | ||
bpf_core_read(&addr, sizeof(u64), &ret); // alloc_pages返回的值,即申请页的起始地址保存在addr中 | ||
for (int i = 0; i < lim && i < 1024; i++, addr += 0x1000) | ||
bpf_map_update_elem(&page_psid, &addr, apsid, BPF_ANY); // 更新page_psid表中的addr(从页的起始地址开始到页的结束地址)所对应的值为apsid | ||
|
||
return 0; | ||
} | ||
|
||
SEC("fexit/page_cache_ra_unbounded") | ||
int BPF_PROG(page_cache_ra_unbounded_ret) // fexit在内核函数page_cache_ra_unbounded退出时触发的挂载点 | ||
{ | ||
u32 pid = bpf_get_current_pid_tgid() >> 32; // 获取当前进程的pid | ||
|
||
if ((apid >= 0 && pid != apid) || !pid) | ||
return 0; | ||
|
||
bpf_map_delete_elem(&in_ra, &pid); // 删除了in_ra对应的pid的表项,即删除对应的栈计数信息 | ||
return 0; | ||
} | ||
|
||
SEC("fentry/mark_page_accessed") // fentry在内核函数/mark_page_accessed进入时触发的挂载点,用于标记页面(page)已经被访问 | ||
int BPF_PROG(mark_page_accessed, u64 page) | ||
{ | ||
u32 pid = bpf_get_current_pid_tgid() >> 32; // 获取当前进程的pid | ||
|
||
if ((apid >= 0 && pid != apid) || !pid) | ||
return 0; | ||
psid *apsid; | ||
apsid = bpf_map_lookup_elem(&page_psid, &page); // 查看page_psid对应的 地址page 对应类型为psid的值,并保存在apsid | ||
if (!apsid) | ||
return 0; | ||
ra_tuple *a = bpf_map_lookup_elem(&psid_count, apsid); // a指向psid_count的apsid的内容 | ||
if (!a) | ||
return 0; | ||
a->truth++; // 已访问 | ||
bpf_map_delete_elem(&page_psid, &page); // 删除page_psid的page对应的内容 | ||
return 0; | ||
} | ||
|
||
const char LICENSE[] SEC("license") = "GPL"; |
14 changes: 14 additions & 0 deletions
14
MagicEyes/src/backend/system_diagnosis/stack_analyzer/bpf/template.bpf.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
#include "vmlinux.h" | ||
#include <bpf/bpf_helpers.h> | ||
#include <bpf/bpf_tracing.h> | ||
#include <bpf/bpf_core_read.h> | ||
|
||
#include "sa_ebpf.h" | ||
#include "bpf/template.h" | ||
#include "task.h" | ||
|
||
DeclareCommonMaps(__u32); | ||
DeclareCommonVar(); | ||
|
||
const char LICENSE[] SEC("license") = "GPL"; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果不想include名字太长,也可以的,建议最起码带上你的工具名,这样对以后的集成工具使用者比较友好。就是你在代码里 #include “stack_analyzer/.skel.h”, 而不是直接的 #include “.skel.h” 。下次提交pr的时候再改就行