Skip to content

Commit

Permalink
Revert "modify sortFun"
Browse files Browse the repository at this point in the history
This reverts commit 3bb0058.
  • Loading branch information
Monkey857 committed May 10, 2024
1 parent 3bb0058 commit 7725b23
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
2 changes: 1 addition & 1 deletion eBPF_Supermarket/kvm_watcher/docs/kvm_exit.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
## 示例输出

4391为主机上的虚拟机进程,4508、4509、4510...分别是虚拟机中的vcpu子进程,每隔两秒输出虚拟机中产生的exit事件及其处理延时等信息。
结果会以进程号(VM的唯一标识)以及线程号(VM中每个VCPU的唯一标识)的优先级依次从小到大的顺序输出。

```
ubuntu@rd350x:~/nans/lmp/eBPF_Supermarket/kvm_watcher$ sudo ./kvm_watcher -e
Expand Down
32 changes: 23 additions & 9 deletions eBPF_Supermarket/kvm_watcher/src/kvm_watcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -868,26 +868,40 @@ int sort_by_key(int fd, struct exit_key *keys, struct exit_value *values) {
struct exit_key lookup_key = {};
struct exit_key next_key = {};
struct exit_value exit_value;
int i = 0,j=0,count=0;
while(!bpf_map_get_next_key(fd,&lookup_key,&next_key)){
j = i-1;
struct exit_key temp_key = next_key;
int first = 1;
int i = 0, j;
int count = 0;
while (!bpf_map_get_next_key(fd, &lookup_key, &next_key)) {
count++;
if (first) {
first = 0;
bpf_map_lookup_elem(fd, &next_key, &exit_value);
keys[0] = next_key;
values[0] = exit_value;
i++;
lookup_key = next_key;
continue;
}
err = bpf_map_lookup_elem(fd, &next_key, &exit_value);
if (err < 0) {
fprintf(stderr, "failed to lookup exit_value: %d\n", err);
return -1;
}
// insert sort
j = i - 1;
struct exit_key temp_key = next_key;
struct exit_value temp_value = exit_value;
while(j >= 0 && (keys[j].pid > temp_key.pid || (keys[j].tid > temp_key.tid))){
while (j >= 0 &&
(keys[j].pid > temp_key.pid || (keys[j].tid > temp_key.tid))) {
keys[j + 1] = keys[j];
values[j + 1] = values[j];
values[j + 1] = values[j];
j--;
}
keys[j + 1] = temp_key;
i++;
keys[j + 1] = next_key;
values[j + 1] = temp_value;
// Move to the next key
lookup_key = next_key;
count ++;
i++;
}
return count;
}
Expand Down

0 comments on commit 7725b23

Please sign in to comment.