Skip to content
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

Add some struct #649

Merged
merged 2 commits into from
Jan 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 63 additions & 3 deletions eBPF_Supermarket/CPU_Subsystem/cpu_watcher/cpu_watcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// author: [email protected]
//
// eBPF map for libbpf sar
#include <asm/types.h>
#include <linux/version.h>

typedef long long unsigned int u64;
typedef unsigned int u32;
Expand All @@ -27,7 +29,7 @@ typedef unsigned int u32;
struct event {
long unsigned int t1;
long unsigned int t2;
long unsigned int delay;
long unsigned int delay;
};
#endif /* __CS_DELAY_H */

Expand Down Expand Up @@ -66,10 +68,68 @@ struct __irq_info {
/*----------------------------------------------*/
struct idleStruct {
u64 pad;
int state;
u32 cpu_id;
unsigned int state;
unsigned int cpu_id;
};


/*----------------------------------------------*/
/* 一些maps结构体的宏定义 */
/*----------------------------------------------*/
/// @brief 创建一个指定名字和键值类型的ebpf数组
/// @param name 新散列表的名字
/// @param type1 键的类型
/// @param type2 值的类型
/// @param MAX_ENTRIES map容量
#define BPF_ARRAY(name, type1,type2,MAX_ENTRIES ) \
struct \
{ \
__uint(type, BPF_MAP_TYPE_ARRAY); \
__uint(key_size, sizeof(type1)); \
__uint(value_size, sizeof(type2)); \
__uint(max_entries, MAX_ENTRIES); \
} name SEC(".maps")

/// @brief 创建一个指定名字和键值类型的ebpf散列表
/// @param name 新散列表的名字
/// @param type1 键的类型
/// @param type2 值的类型
/// @param MAX_ENTRIES 哈希map容量
#define BPF_HASH(name, type1,type2,MAX_ENTRIES ) \
struct \
{ \
__uint(type, BPF_MAP_TYPE_HASH); \
__uint(key_size, sizeof(type1)); \
__uint(value_size, sizeof(type2)); \
__uint(max_entries, MAX_ENTRIES); \
} name SEC(".maps")

/// @brief 创建一个指定名字和键值类型的ebpf每CPU数组
/// @param name 新散列表的名字
/// @param type1 键的类型
/// @param type2 值的类型
/// @param MAX_ENTRIES map容量
#define BPF_PERCPU_ARRAY(name, type1,type2,MAX_ENTRIES ) \
struct \
{ \
__uint(type, BPF_MAP_TYPE_PERCPU_ARRAY); \
__uint(key_size, sizeof(type1)); \
__uint(value_size, sizeof(type2)); \
__uint(max_entries, MAX_ENTRIES); \
} name SEC(".maps")

/// @brief 创建一个指定名字和键值类型的ebpf每CPU散列表
/// @param name 新散列表的名字
/// @param type1 键的类型
/// @param type2 值的类型
/// @param MAX_ENTRIES map容量
#define BPF_PERCPU_HASH(name, type1,type2,MAX_ENTRIES ) \
struct \
{ \
__uint(type, BPF_MAP_TYPE_PERCPU_HASH); \
__uint(key_size, sizeof(type1)); \
__uint(value_size, sizeof(type2)); \
__uint(max_entries, MAX_ENTRIES); \
} name SEC(".maps")