linux中采用用户级线程模拟实现EDF和RMS两种处理机实时调度算法之改进

该博客探讨了如何在Linux环境中通过用户级线程来改进EDF(Earliest Deadline First)和RMS(Rate Monotonic Scheduling)两种处理机实时调度算法。原始算法中的频繁时钟中断被优化,改为仅在需要重新调度任务时进行控制权切换,从而减少了线程切换次数。文章还提到了在编译时需要添加-lpthread参数以链接posix线程库。
摘要由CSDN通过智能技术生成

原算法中被选中任务每运行一个时间单位便将控制权交给主线程。再判断是否需要切换实时任务。实际上不需这样频繁的时钟中断。

故改进成。只在需要重新调度任务时才返回主控线程。且统计出线程切换次数(主线程切换不计)。

//编译

// pthread库不是Linux系统默认的库,所以在编译中需加-lpthread参数(posix线程库 )

gcc -lpthread -lm test.c -o test.out


#include "math.h"
#include "sched.h"
#include "pthread.h"
#include "stdlib.h"
#include "semaphore.h"
//@author vince
typedef struct{
	char task_id;
	int call_num; //times has been called
	int ci; //processing time
	int ti; //T
	int ci_left;
	int ti_left; //time left to next T
	int flag; //isActive,0_no,2_yes
	int arg; //argument
	pthread_t th; //thread
}task;

void proc(int *args);
void idle();
int select_proc();

int task_num=0;
int idle_num=0;

int alg; //1 for EDF, 2 for RMS
int curr_proc=-1; //index
int demo_time=100; //time for show

task *tasks;
pthread_mutex_t proc_wait[100]; //the one be chosed is unlocked
pthread
  • 9
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值