Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sb13225001 #2

Closed
wants to merge 6 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
在中断中执行对count和ncount计数的过程
  • Loading branch information
aupu committed Aug 26, 2013
commit ae0015dfbc582aa14a47d0c78e3faadf1b2ee712
82 changes: 1 addition & 81 deletions myinterrupt.c
Original file line number Diff line number Diff line change
@@ -1,154 +1,74 @@
/*

* linux/mykernel/myinterrupt.c

*

* Kernel internal my_timer_handler

*

* Copyright (C) 2013 Mengning

*

*/

#include <linux/types.h>

#include <linux/string.h>

#include <linux/ctype.h>

#include <linux/tty.h>

#include <linux/vmalloc.h>



#include "mypcb.h"

extern tPCB task[MAX_TASK_NUM];

extern tPCB * my_current_task;

extern int task_count;





extern int count ;

extern int semaphore;

extern int ncount;

extern int intecount;



extern void nonmutex(int);



extern int mutex(int);

/*

* Called by timer interrupt.

* it runs in the name of current running process,

* so it use kernel stack of current running process

*/

//int icount = 0;

int miscount = 0;





void my_timer_handler(void)

{

tPCB * next;

tPCB * prev;

nonmutex(100000);

int isgetin = mutex(100000);

intecount ++;

miscount += (1-isgetin);

if(0 == isgetin)printk(KERN_NOTICE "I get in mutex %d times\n",miscount);

// printk(KERN_NOTICE ">>>my_timer_handler here<<<\n");

// printk(KERN_NOTICE "count = %d, ncount = %d \n",count,ncount);



if(my_current_task == NULL || my_current_task->next == NULL)

{

if(my_current_task == NULL || my_current_task->next == NULL){
return;

}

/* schedule */

next = my_current_task->next;

prev = my_current_task;

if(next->state == 0)/* -1 unrunnable, 0 runnable, >0 stopped */

{

// printk(KERN_NOTICE ">>>switch %d to %d<<<\n",prev->pid,next->pid);

/* switch to next process */

asm volatile(

"pushl %%ebp\n\t" /* save ebp */

"movl %%esp,%0\n\t" /* save esp */

"movl %2,%%esp\n\t" /* restore esp */

"movl $1f,%1\n\t" /* save eip */

"pushl %3\n\t"

"ret\n\t" /* restore eip */

"1:\t" /* next process start here */

"popl %%ebp\n\t"

: "=m" (prev->thread.sp),"=m" (prev->thread.ip)

: "m" (next->thread.sp),"m" (next->thread.ip)

);

my_current_task = next;

}



return;

}