操作系统中的实时调度程序 [英] RealTime scheduler in operating system

查看:71
本文介绍了操作系统中的实时调度程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人可以帮助以C ++实现的操作系统中提供RealTime Scheduler的源代码,谢谢.

Is there any one can help provide the source code for RealTime scheduler in operating system, implemented in C++, Thanks. so appreciated.

推荐答案



完全有效的问题.

C中有许多带有源代码的RTOS-es

问题在于,如果您正在寻找裸露的骨头,那么很难找到,因为大多数OS中都会实现TCP/IP.

这是经典的RTOS-XINU,它的优点是它有一本很好的书逐步介绍了它.

https://sites.google.com/site/avrxinu/the-team [ ^ ]

这是从中重新安排的代码,作为从上述链接下载代码时获得的示例:

Perfectly valid question.

There are many RTOS-es available with source code in C

The problem is that if you are looking for bare bones one, it is hard to find as most will have TCP/IP implemented in the OS.

Here is a classic RTOS - XINU, the advantage being it has a great book explaining it step by step.

https://sites.google.com/site/avrxinu/the-team[^]

Here is the reschedule code from it as an example of what you get when you download it from the above link:

#include <conf.h>
#include <kernel.h>
#include <proc.h>
#include <q.h>
#include <inttypes.h>

extern void panic();
extern int insert();
extern int getlast();
extern void ctxsw();
char * getSP(void);

/*------------------------------------------------------------------------
 * resched  --  reschedule processor to highest priority ready process
 *
 * Notes:	Upon entry, currpid gives current process id.
 *		Proctab[currpid].pstate gives correct NEXT state for
 *			current process if other than PRREADY.
 *------------------------------------------------------------------------
 */

int resched(void)
{
	register struct	pentry volatile *optr;	/* pointer to old process entry */
	register struct	pentry volatile *nptr;	/* pointer to new process entry */
	int newpid;

	preempt = QUANTUM;		/* reset preemption counter	*/

	/* no switch needed if current process priority higher than next */
	
	if ( ( (optr= &proctab[currpid])->pstate == PRCURR) &&
             ( lastkey(rdytail) < optr->pprio) )	{
//		kprintf("resched: No Switch currpid=%d\n", currpid);
		return(OK);
	}
	
	/* force context switch */
	if (optr->pstate == PRCURR) {
		optr->pstate = PRREADY;
		insert(currpid,rdyhead,optr->pprio);
	}

	/* remove highest priority process at end of ready list */
	
	if ( (newpid = getlast(rdytail)) == EMPTY )
		return(EMPTY);
	
	nptr = &proctab[ ( currpid = newpid ) ];
	nptr->pstate = PRCURR;		/* mark it currently running	*/
//	kprintf("resched: Yes Switch currpid=%d\n", currpid);

	ctxsw(&optr->pregs[0],&nptr->pregs[0]);	/* switch context from old to new */

	return(OK);
}

/*
void dump_Stack(int pid)
{
    struct pentry *p;
    char *saddr;
    int j;

    p = &proctab[pid];
    if (pid == currpid)
	saddr = getSP()+8;
    else
	saddr = p->pSP;
    kprintf("\nProcess %d stack %p\n",pid,saddr);
    while ((unsigned)saddr < (unsigned)p->pbase)
    {
	j = *++saddr;
	kprintf("0X%02x\n",j&0xff);
    }
}
*/

char *getSP(void)
{
    char * mySP;

    asm volatile(
		 "in %A0, __SP_L__" "\n\t"
		 "in %B0, __SP_H__" "\n\t"
		 : "=d" (mySP)
		 :
		 );

    return (mySP+2);
}</inttypes.h></q.h></proc.h></kernel.h></conf.h>



1)这是一个AVR端口,但这无关紧要
2)如上所示,任何RTOS都有少量的汇编器

享受



1) It is an AVR port, but this is irrelevant
2) Any RTOS will have a small amount of assembler as you can see above

Enjoy


这篇关于操作系统中的实时调度程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆