Skip to content

Commit

Permalink
Block IO Scheduler (#158)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
houmkh and fslongjin authored Feb 4, 2023
1 parent 151251b commit f6ba114
Show file tree
Hide file tree
Showing 38 changed files with 829 additions and 262 deletions.
2 changes: 1 addition & 1 deletion kernel/src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export ASFLAGS := --64
LD_LIST := head.o


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



Expand Down
6 changes: 3 additions & 3 deletions kernel/src/arch/x86_64/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ use core::arch::asm;

/// @brief 获取当前cpu的apic id
#[inline]
pub fn arch_current_apic_id() -> u8 {
pub fn current_cpu_id() -> u8 {
let cpuid_res: u32;
unsafe {
asm!(
"mov eax, 1",
"cpuid",
"mov r15, ebx",
"mov r15, rbx",
lateout("r15") cpuid_res
);
}
return (cpuid_res >> 24) as u8;
return ((cpuid_res >> 24) & 0xff) as u8;
}

/// @brief 通过pause指令,让cpu休息一会儿。降低空转功耗
Expand Down
23 changes: 8 additions & 15 deletions kernel/src/common/blk_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,8 @@ struct block_device_request_packet
uint64_t LBA_start;
uint32_t count;
uint64_t buffer_vaddr;

uint8_t device_type; // 0: ahci
void (*end_handler)(ul num, ul arg);

wait_queue_node_t wait_queue;
};

/**
Expand All @@ -53,7 +50,6 @@ struct block_device_request_packet
*/
struct block_device_request_queue
{
wait_queue_node_t wait_queue_list;
struct block_device_request_packet *in_service; // 正在请求的结点
ul request_count;
};
Expand All @@ -64,13 +60,12 @@ struct block_device_request_queue
*/
struct block_device
{
sector_t bd_start_sector; // 该分区的起始扇区
uint64_t bd_start_LBA; // 起始LBA号
sector_t bd_sectors_num; // 该分区的扇区数
struct vfs_superblock_t *bd_superblock; // 执行超级块的指针
struct blk_gendisk *bd_disk; // 当前分区所属的磁盘
struct block_device_request_queue *bd_queue; // 请求队列
uint16_t bd_partno; // 在磁盘上的分区号
sector_t bd_start_sector; // 该分区的起始扇区
uint64_t bd_start_LBA; // 起始LBA号
sector_t bd_sectors_num; // 该分区的扇区数
struct vfs_superblock_t *bd_superblock; // 执行超级块的指针
struct blk_gendisk *bd_disk; // 当前分区所属的磁盘
uint16_t bd_partno; // 在磁盘上的分区号
};

// 定义blk_gendisk中的标志位
Expand All @@ -85,10 +80,8 @@ struct blk_gendisk
char disk_name[DISK_NAME_LEN]; // 磁盘驱动器名称
uint16_t part_cnt; // 磁盘分区计数
uint16_t flags;
struct block_device *partition; // 磁盘分区数组
const struct block_device_operation *fops; // 磁盘操作
struct block_device_request_queue *request_queue; // 磁盘请求队列
struct block_device *partition; // 磁盘分区数组
const struct block_device_operation *fops; // 磁盘操作
void *private_data;

mutex_t open_mutex; // open()/close()操作的互斥锁
};
2 changes: 1 addition & 1 deletion kernel/src/common/completion.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ long wait_for_completion_interruptible_timeout(struct completion *x, long timeou
void wait_for_multicompletion(struct completion x[], int n);
bool try_wait_for_completion(struct completion *x);
bool completion_done(struct completion *x);

struct completion *completion_alloc();
/**
* 测试函数声明 (测试代码辅助函数)
*/
Expand Down
40 changes: 20 additions & 20 deletions kernel/src/common/kthread.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once

#include <common/err.h>
#include <common/numa.h>
#include <process/proc-types.h>
#include <common/err.h>
#include <process/process.h>

/**
Expand All @@ -21,9 +21,7 @@ struct kthread_info_t
char *full_name; // 内核线程的名称
};

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

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

/**
* @brief 创建内核实时线程,并将其唤醒
*
*
* @param thread_fn 该内核线程要执行的函数
* @param data 传递给 thread_fn 的参数数据
* @param name_fmt printf-style format string for the thread name
* @param arg name_fmt的参数
*/
#define kthread_run_rt(thread_fn, data, name_fmt, ...) \
({ \
struct process_control_block *__kt = kthread_create(thread_fn, data, name_fmt, ##__VA_ARGS__); \
__kt=process_init_rt_pcb(__kt); \
if (!IS_ERR(__kt)){ \
process_wakeup(__kt);} \
__kt; \
#define kthread_run_rt(thread_fn, data, name_fmt, ...) \
({ \
struct process_control_block *__kt = kthread_create(thread_fn, data, name_fmt, ##__VA_ARGS__); \
__kt = process_init_rt_pcb(__kt); \
if (!IS_ERR(__kt)) \
{ \
process_wakeup(__kt); \
} \
__kt; \
})

/**
* @brief 向kthread发送停止信号,请求其结束
*
*
* @param pcb 内核线程的pcb
* @return int 错误码
*/
int kthread_stop(struct process_control_block * pcb);
int kthread_stop(struct process_control_block *pcb);

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

/**
* @brief 让当前内核线程退出,并返回result参数给kthread_stop()函数
*
*
* @param result 返回值
*/
void kthread_exit(long result);

/**
* @brief 初始化kthread机制(只应被process_init调用)
*
*
* @return int 错误码
*/
int kthread_mechanism_init();
Expand All @@ -119,7 +119,7 @@ struct kthread_info_t *to_kthread(struct process_control_block *pcb);

/**
* @brief 释放pcb指向的worker private
*
*
* @param pcb 要释放的pcb
*/
void free_kthread_struct(struct process_control_block *pcb);
Loading

0 comments on commit f6ba114

Please sign in to comment.