Skip to content

Commit f6ba114

Browse files
houmkhfslongjin
andauthored
Block IO Scheduler (#158)
* Block io调度器 * process_wakeup时,对cfs的进程,重设虚拟运行时间。解决由于休眠的进程,其虚拟运行时间过小,导致其他进程饥饿的问题 * 1、为AP核启动apic_timer,使其能够运行调度 2、增加kick_cpu功能,支持让某个特定核心立即运行调度器 3、wait_queue的唤醒,改为立即唤醒。 4、增加进程在核心间迁移的功能 5、CFS调度器为每个核心设置单独的IDLE进程pcb(pid均为0) 6、pcb中增加migrate_to字段 7、当具有多核时,io调度器在核心1上运行。 * io调度器文件位置修改 * 修改io的makefile * 更新makefile中的变量名 * 修改io调度器函数名 --------- Co-authored-by: login <longjin@ringotek.cn>
1 parent 151251b commit f6ba114

File tree

38 files changed

+829
-262
lines changed

38 files changed

+829
-262
lines changed

kernel/src/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export ASFLAGS := --64
1717
LD_LIST := head.o
1818

1919

20-
kernel_subdirs := common driver process debug filesystem time arch exception mm smp sched syscall ktest libs ipc
20+
kernel_subdirs := common driver process debug filesystem time arch exception mm smp sched syscall ktest libs ipc io
2121

2222

2323

kernel/src/arch/x86_64/cpu.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ use core::arch::asm;
22

33
/// @brief 获取当前cpu的apic id
44
#[inline]
5-
pub fn arch_current_apic_id() -> u8 {
5+
pub fn current_cpu_id() -> u8 {
66
let cpuid_res: u32;
77
unsafe {
88
asm!(
99
"mov eax, 1",
1010
"cpuid",
11-
"mov r15, ebx",
11+
"mov r15, rbx",
1212
lateout("r15") cpuid_res
1313
);
1414
}
15-
return (cpuid_res >> 24) as u8;
15+
return ((cpuid_res >> 24) & 0xff) as u8;
1616
}
1717

1818
/// @brief 通过pause指令,让cpu休息一会儿。降低空转功耗

kernel/src/common/blk_types.h

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,8 @@ struct block_device_request_packet
4040
uint64_t LBA_start;
4141
uint32_t count;
4242
uint64_t buffer_vaddr;
43-
4443
uint8_t device_type; // 0: ahci
4544
void (*end_handler)(ul num, ul arg);
46-
47-
wait_queue_node_t wait_queue;
4845
};
4946

5047
/**
@@ -53,7 +50,6 @@ struct block_device_request_packet
5350
*/
5451
struct block_device_request_queue
5552
{
56-
wait_queue_node_t wait_queue_list;
5753
struct block_device_request_packet *in_service; // 正在请求的结点
5854
ul request_count;
5955
};
@@ -64,13 +60,12 @@ struct block_device_request_queue
6460
*/
6561
struct block_device
6662
{
67-
sector_t bd_start_sector; // 该分区的起始扇区
68-
uint64_t bd_start_LBA; // 起始LBA号
69-
sector_t bd_sectors_num; // 该分区的扇区数
70-
struct vfs_superblock_t *bd_superblock; // 执行超级块的指针
71-
struct blk_gendisk *bd_disk; // 当前分区所属的磁盘
72-
struct block_device_request_queue *bd_queue; // 请求队列
73-
uint16_t bd_partno; // 在磁盘上的分区号
63+
sector_t bd_start_sector; // 该分区的起始扇区
64+
uint64_t bd_start_LBA; // 起始LBA号
65+
sector_t bd_sectors_num; // 该分区的扇区数
66+
struct vfs_superblock_t *bd_superblock; // 执行超级块的指针
67+
struct blk_gendisk *bd_disk; // 当前分区所属的磁盘
68+
uint16_t bd_partno; // 在磁盘上的分区号
7469
};
7570

7671
// 定义blk_gendisk中的标志位
@@ -85,10 +80,8 @@ struct blk_gendisk
8580
char disk_name[DISK_NAME_LEN]; // 磁盘驱动器名称
8681
uint16_t part_cnt; // 磁盘分区计数
8782
uint16_t flags;
88-
struct block_device *partition; // 磁盘分区数组
89-
const struct block_device_operation *fops; // 磁盘操作
90-
struct block_device_request_queue *request_queue; // 磁盘请求队列
83+
struct block_device *partition; // 磁盘分区数组
84+
const struct block_device_operation *fops; // 磁盘操作
9185
void *private_data;
92-
9386
mutex_t open_mutex; // open()/close()操作的互斥锁
9487
};

kernel/src/common/completion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ long wait_for_completion_interruptible_timeout(struct completion *x, long timeou
3030
void wait_for_multicompletion(struct completion x[], int n);
3131
bool try_wait_for_completion(struct completion *x);
3232
bool completion_done(struct completion *x);
33-
33+
struct completion *completion_alloc();
3434
/**
3535
* 测试函数声明 (测试代码辅助函数)
3636
*/

kernel/src/common/kthread.h

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#pragma once
22

3+
#include <common/err.h>
34
#include <common/numa.h>
45
#include <process/proc-types.h>
5-
#include <common/err.h>
66
#include <process/process.h>
77

88
/**
@@ -21,9 +21,7 @@ struct kthread_info_t
2121
char *full_name; // 内核线程的名称
2222
};
2323

24-
struct process_control_block *kthread_create_on_node(int (*thread_fn)(void *data),
25-
void *data,
26-
int node,
24+
struct process_control_block *kthread_create_on_node(int (*thread_fn)(void *data), void *data, int node,
2725
const char name_fmt[], ...);
2826
/**
2927
* @brief 在当前结点上创建一个内核线程
@@ -35,12 +33,12 @@ struct process_control_block *kthread_create_on_node(int (*thread_fn)(void *data
3533
*
3634
* 请注意,该宏会创建一个内核线程,并将其设置为停止状态
3735
*/
38-
#define kthread_create(thread_fn, data, name_fmt, arg...) \
36+
#define kthread_create(thread_fn, data, name_fmt, arg...) \
3937
kthread_create_on_node(thread_fn, data, NUMA_NO_NODE, name_fmt, ##arg)
4038

4139
/**
4240
* @brief 创建内核线程,并将其唤醒
43-
*
41+
*
4442
* @param thread_fn 该内核线程要执行的函数
4543
* @param data 传递给 thread_fn 的参数数据
4644
* @param name_fmt printf-style format string for the thread name
@@ -56,47 +54,49 @@ struct process_control_block *kthread_create_on_node(int (*thread_fn)(void *data
5654

5755
/**
5856
* @brief 创建内核实时线程,并将其唤醒
59-
*
57+
*
6058
* @param thread_fn 该内核线程要执行的函数
6159
* @param data 传递给 thread_fn 的参数数据
6260
* @param name_fmt printf-style format string for the thread name
6361
* @param arg name_fmt的参数
6462
*/
65-
#define kthread_run_rt(thread_fn, data, name_fmt, ...) \
66-
({ \
67-
struct process_control_block *__kt = kthread_create(thread_fn, data, name_fmt, ##__VA_ARGS__); \
68-
__kt=process_init_rt_pcb(__kt); \
69-
if (!IS_ERR(__kt)){ \
70-
process_wakeup(__kt);} \
71-
__kt; \
63+
#define kthread_run_rt(thread_fn, data, name_fmt, ...) \
64+
({ \
65+
struct process_control_block *__kt = kthread_create(thread_fn, data, name_fmt, ##__VA_ARGS__); \
66+
__kt = process_init_rt_pcb(__kt); \
67+
if (!IS_ERR(__kt)) \
68+
{ \
69+
process_wakeup(__kt); \
70+
} \
71+
__kt; \
7272
})
7373

7474
/**
7575
* @brief 向kthread发送停止信号,请求其结束
76-
*
76+
*
7777
* @param pcb 内核线程的pcb
7878
* @return int 错误码
7979
*/
80-
int kthread_stop(struct process_control_block * pcb);
80+
int kthread_stop(struct process_control_block *pcb);
8181

8282
/**
8383
* @brief 内核线程调用该函数,检查自身的标志位,判断自己是否应该执行完任务后退出
84-
*
84+
*
8585
* @return true 内核线程应该退出
8686
* @return false 无需退出
8787
*/
8888
bool kthread_should_stop(void);
8989

9090
/**
9191
* @brief 让当前内核线程退出,并返回result参数给kthread_stop()函数
92-
*
92+
*
9393
* @param result 返回值
9494
*/
9595
void kthread_exit(long result);
9696

9797
/**
9898
* @brief 初始化kthread机制(只应被process_init调用)
99-
*
99+
*
100100
* @return int 错误码
101101
*/
102102
int kthread_mechanism_init();
@@ -119,7 +119,7 @@ struct kthread_info_t *to_kthread(struct process_control_block *pcb);
119119

120120
/**
121121
* @brief 释放pcb指向的worker private
122-
*
122+
*
123123
* @param pcb 要释放的pcb
124124
*/
125125
void free_kthread_struct(struct process_control_block *pcb);

0 commit comments

Comments
 (0)