首页 > 其他 > 详细

MIT6.828 Fall2018 笔记 - Homework 5: xv6 CPU alarm

时间:2020-04-06 00:34:35      阅读:131      评论:0      收藏:0      [点我收藏+]

Homework: xv6 CPU alarm

这里只写部分代码,其余的给出的提示已经很多了

trap.c中的case T_IRQ0 + IRQ_TIMER:里:

struct proc* p = myproc();
if (p != 0 && (tf->cs & 3) == 3) {
    p->current_ticks++;
    if (p->current_ticks == p->alarmticks) {
        p->current_ticks = 0;
        tf->esp -= 4;
        *(uint*)(tf->esp) = tf->eip;
        tf->eip = (uint)p->alarmhandler;
    }
}

proc.c中的allocproc函数里:

p->current_ticks = 0;
p->alarmticks = -1;

alarmtest.c

#include "types.h"
#include "stat.h"
#include "user.h"

void periodic();

int main(int argc, char* argv[]) {
    int i;
    printf(1, "alarmtest starting\n");
    alarm(1, periodic); // 此处我改成了1
    for (i = 0; i < 25 * 500000; i++) {
        if ((i % 250000) == 0)
            write(2, ".", 1);
    }
    exit();
}

void periodic() {
    printf(1, "alarm!\n");
}

输出:

xv6...
cpu1: starting 1
cpu0: starting 0
sb: size 1000 nblocks 941 ninodes 200 nlog 30 logstart 2 inodestart 32 bmap start 58
init: starting sh
$ alarmtest
alarmtest starting
....alarm!
..........alarm!
..............alarm!
.......alarm!
..........alarm!
....alarm!
.$

MIT6.828 Fall2018 笔记 - Homework 5: xv6 CPU alarm

原文:https://www.cnblogs.com/zsmumu/p/12639965.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!