编程介的小学生 2017-09-19 09:46 采纳率: 20.5%
浏览 863
已采纳

Harmonic Periods

Description

In real-time scheduling, predictability is very important, i.e., we would like to know the whole schedule before we really run the tasks. Rate-monotonic scheduling is very popular in real-time scheduling for periodic tasks, where tasks with shorter periods have higher priority. However, it is still dicult to know the start time and finish time of each task and they might be dierent in each period, especially for tasks with low priority, i.e. long period. The hyperperiod, the least common multiple of all periods,is usually too big to be practical to describe the whole schedule. However, if the task periods are harmonic, i.e. are multiples, it is possible to find the start time and finish time of each task quickly because the schedule becomes more regular.


Figure 1 shows that periodic tasks T1, T2, T3, T4 with execution times 1, 1, 3, 1 and periods 2, 4, 16, 32 respectively are schedulable, each task finishes execution in its period, using the Rate-Monotonic scheduling algorithm since T1, T2, T3, T4 finish execution at time 1, 2, 12, 16 respectively. T3 is preempted by T1 and T2 at time 4 and time 8 and resume at time 7 and time 11.
Input

All the input numbers are positive integers, < 500000, separated by a space or new line. The first line is the number of task sets. Then, the task sets are listed set by set. Each task set is listed by a line of the number of tasks, <= 100, and lines of task execution time and period pairs, execution time < period. The periods are harmonic, not sorted, and are different in a task set.
Output

For each task set, find and print out the finish time of the task with the largest period using rate-monotonic scheduling, if schedulable; otherwise print out -1.
Sample Input

3
4
1 2
1 4
3 16
1 32
3
1 4
4 8
256 1024
3
1 2
3 8
1 4
Sample Output

16
1024
-1

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-10-05 01:28
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能