Skip to content

Commit

Permalink
Merge branch 'linuxkerneltravel:develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
albertxu216 authored Sep 7, 2024
2 parents e4d47de + b3873cd commit 3c28138
Show file tree
Hide file tree
Showing 47 changed files with 1,717 additions and 275 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/ebpf_net_manager.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ jobs:
cd testenv
sudo ./testenv.sh setup --name veth-basic02
cd ..
cd net_manager
sudo timeout -s SIGINT 5 ./xdp_loader -d eth0 -S || if [[ $? != 124 && $? != 0 ]];then exit $?;fi
sudo ./xdp_loader -d eth0 -S
sudo timeout -s SIGINT 5 ./netmanager -d eth0 -S || if [[ $? != 124 && $? != 0 ]];then exit $?;fi
sudo ./netmanager -d eth0 -S


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
"prettier": "3.0.2",
"ts-loader": "^9.4.2",
"typescript": "^4.9.5",
"webpack": "^5.75.0",
"webpack": "^5.94.0",
"webpack-cli": "^5.0.1"
},
"dependencies": {
Expand Down
278 changes: 137 additions & 141 deletions MagicEyes/src/visualization/vscode_ext/lmp_ext_vscode/yarn.lock

Large diffs are not rendered by default.

Binary file not shown.
116 changes: 108 additions & 8 deletions eBPF_Supermarket/Filesystem_Subsystem/fast_fuse/difuse/src/difuse.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,25 @@
#define DIRECTORY_TYPE 2
#define MAX_INODES 1000 //最大 inode 数量
#define HASH_SIZE 1024
#define CHUNK_SIZE 4096 // 数据块的大小

uint32_t next_ino = 1;

struct dfs_data
{
int chunk_size;
char *data;
size_t size;
struct dfs_data *next;
};

static struct dfs_data *allocate_data_block()
{
struct dfs_data *new_data = (struct dfs_data *)malloc(sizeof(struct dfs_data));
new_data->data = (char *)malloc(CHUNK_SIZE);
new_data->next = NULL;
return new_data;
}

struct dfs_inode
{
uint32_t ino; //inode编号
Expand Down Expand Up @@ -401,16 +410,106 @@ static int di_read(const char *path, char *buf, size_t size, off_t offset, struc
if (dentry->ftype != FILE_TYPE)
return -EISDIR;

if (offset < dentry->inode->size)
struct dfs_inode *inode = dentry->inode;
size_t file_size = inode->size;

if (offset >= file_size)
return 0;

if (offset + size > file_size)
size = file_size - offset;

// 初始化缓冲区
memset(buf, 0, size);

// 从数据块中读取数据
size_t bytes_read = 0;
struct dfs_data *data_block = inode->data_pointer;

// 遍历数据块
while (data_block != NULL && bytes_read < size)
{
if (offset + size > dentry->inode->size)
size = dentry->inode->size - offset;
memcpy(buf, "dummy_content", size);
// 计算当前块的有效数据长度
size_t block_size = data_block->size;
if (offset >= block_size)
{
offset -= block_size;
}
else
{
// 从当前块读取数据
size_t to_read = block_size - offset;
if (to_read > size - bytes_read)
to_read = size - bytes_read;

// 复制数据到缓冲区
memcpy(buf + bytes_read, ((char *)data_block) + offset, to_read);
bytes_read += to_read;
offset = 0;
}

data_block = data_block->next;
}

return bytes_read;
}

static int di_write(const char *path, const char *buf, size_t size, off_t offset, struct fuse_file_info *fi)
{
(void)fi;
struct dfs_dentry *dentry = look_up(root, path);

if (dentry == NULL) return -ENOENT;
if (dentry->ftype != FILE_TYPE) return -EISDIR;

struct dfs_inode *inode = dentry->inode;
struct dfs_data *data_block = inode->data_pointer;

if (data_block == NULL)
{
data_block = allocate_data_block();
inode->data_pointer = data_block;
}

size_t bytes_written = 0;
size_t total_offset = offset;

while (data_block != NULL && total_offset >= data_block->size)
{
total_offset -= data_block->size;
if (data_block->next == NULL)
{
data_block->next = allocate_data_block();
}
data_block = data_block->next;
}

while (bytes_written < size)
{
size_t space_in_block = CHUNK_SIZE - total_offset;
size_t to_write = size - bytes_written;

if (to_write > space_in_block) to_write = space_in_block;

memcpy(data_block->data + total_offset, buf + bytes_written, to_write);

total_offset = 0;
bytes_written += to_write;
data_block->size += to_write;

if (bytes_written < size && data_block->next == NULL)
{
data_block->next = allocate_data_block();
}
data_block = data_block->next;
}

if (offset + bytes_written > inode->size)
{
inode->size = offset + bytes_written;
}
else
size = 0;

return size;
return bytes_written;
}

static void *di_init(struct fuse_conn_info *conn, struct fuse_config *cfg)
Expand All @@ -430,6 +529,7 @@ static struct fuse_operations difs_ops = {
.getattr = di_getattr,
.open = di_open,
.read = di_read,
.write = di_write,
.mkdir = di_mkdir,
.create = dfs_create,
.utimens = di_utimens,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,6 @@ int BPF_KPROBE(get_page_from_freelist, gfp_t gfp_mask, unsigned int order, int a
struct contig_page_info ctg_info = {};
fill_contig_page_info(z, a_order, &ctg_info);
bpf_map_update_elem(&orders,&order_key,&ctg_info,BPF_ANY);
bpf_printk("Order: %d, Free pages: %lu, Free blocks total: %lu, Free blocks suitable: %lu",
a_order, ctg_info.free_pages, ctg_info.free_blocks_total, ctg_info.free_blocks_suitable);
bpf_printk("2");
}

bpf_map_update_elem(&zones, &zone_key, &zone_data, BPF_ANY);
Expand Down
66 changes: 52 additions & 14 deletions eBPF_Supermarket/Memory_Subsystem/mem_watcher/mem_watcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -1193,18 +1193,39 @@ static int process_memleak(struct memleak_bpf *skel_memleak, struct env env)
}

// ================================================== fraginfo====================================================================
void print_nodes(int fd) {
struct pgdat_info pinfo;
__u64 key = 0, next_key;
printf(" Node ID PGDAT_PTR NR_ZONES \n");
while (bpf_map_get_next_key(fd, &key, &next_key) == 0) {
bpf_map_lookup_elem(fd, &next_key, &pinfo);
printf(" %5d 0x%llx %5d\n",
pinfo.node_id, pinfo.pgdat_ptr, pinfo.nr_zones);
key = next_key;
}
}
//compute order
static int __fragmentation_index(unsigned int order, long unsigned int total,long unsigned int suitable,long unsigned int free) {
unsigned long requested = 1UL << order;
if (order > MAX_ORDER)
return 0;
if (!total)
return 0;
if (suitable)
return -1000;
double res1,res2;
res1 = (double)(free * 1000ULL)/requested;
res1 +=1000;
res2 = (double)res1/total;
return 1000 - res2;
}
static int unusable_free_index(unsigned int order, long unsigned int total,long unsigned int suitable,long unsigned int free)
{
/* No free memory is interpreted as all free memory is unusable */
if (free == 0)
return 1000;

/*
* Index should be a value between 0 and 1. Return a value to 3
* decimal places.
*
* 0 => no fragmentation
* 1 => high fragmentation
*/
long unsigned int res1 = free - (suitable<<order);
double res = (res1*1000ULL)/free;
return res;

}
void print_zones(int fd) {
struct zone_info zinfo;
__u64 key = 0, next_key;
Expand All @@ -1217,6 +1238,17 @@ void print_zones(int fd) {
}

}
void print_nodes(int fd) {
struct pgdat_info pinfo;
__u64 key = 0, next_key;
printf(" Node ID PGDAT_PTR NR_ZONES \n");
while (bpf_map_get_next_key(fd, &key, &next_key) == 0) {
bpf_map_lookup_elem(fd, &next_key, &pinfo);
printf(" %5d 0x%llx %5d\n",
pinfo.node_id, pinfo.pgdat_ptr, pinfo.nr_zones);
key = next_key;
}
}
void print_orders(int fd) {
struct order_zone okey = {};
struct ctg_info oinfo;
Expand All @@ -1235,11 +1267,17 @@ void print_orders(int fd) {
qsort(entries, entry_count, sizeof(struct order_entry), compare_entries);

// 打印排序后的
printf(" Order Zone_PTR Free Pages Free Blocks Total Free Blocks Suitable\n");
printf(" Order Zone_PTR Free Pages Free Blocks Total Free Blocks Suitable SCOREA SCOREB\n");
for (int i = 0; i < entry_count; i++) {
printf(" %-8u 0x%-25llx %-20lu %-20lu %-20lu\n",
int res = __fragmentation_index(entries[i].okey.order,entries[i].oinfo.free_blocks_total,entries[i].oinfo.free_blocks_suitable,entries[i].oinfo.free_pages);
int tmp = unusable_free_index(entries[i].okey.order,entries[i].oinfo.free_blocks_total,entries[i].oinfo.free_blocks_suitable,entries[i].oinfo.free_pages);
int part1 = res/1000;
int dec1 = res%1000;
int part2 = tmp/1000;
int dec2 = tmp%1000;
printf(" %-8u 0x%-25llx %-20lu %-20lu %-20lu %2d.%03d %d.%03d\n",
entries[i].okey.order, entries[i].okey.zone_ptr, entries[i].oinfo.free_pages,
entries[i].oinfo.free_blocks_total, entries[i].oinfo.free_blocks_suitable);
entries[i].oinfo.free_blocks_total, entries[i].oinfo.free_blocks_suitable,part1,dec1,part2,dec2);
}
}

Expand Down
Loading

0 comments on commit 3c28138

Please sign in to comment.