ÉèÖÃLinuxϵͳÒÔÖ§³Öʵʱ²Ù×÷ϵͳ¿ª·¢
ÉèÖÃlinuxϵͳÒÔÖ§³Öʵʱ²Ù×÷ϵͳ¿ª·¢
Ëæ×ÅǶÈëʽϵͳµÄÉú³¤£¬ÊµÊ±²Ù×÷ϵͳ£¨RTOS£©ÔÚÖÖÖÖÓ¦ÓÃÁìÓòÖлñµÃÁËÆÕ±éµÄÓ¦Óá£ÎªÁËÖ§³ÖRTOSµÄ¿ª·¢£¬ÎÒÃÇÐèÒª¶ÔLinuxϵͳ¾ÙÐÐÉèÖã¬ÒÔÖª×ãʵʱÐԺͿÉÕ¹ÍûÐÔµÄÒªÇó¡£±¾ÎĽ«ÏÈÈÝÔõÑùÔÚLinuxϵͳÖÐÉèÖÃʵʱ²Ù×÷ϵͳ¿ª·¢ÇéÐΣ¬²¢ÌṩһЩ´úÂëʾÀý¡£
Ò»¡¢ÄÚºËÉèÖÃ
Ê×ÏÈ£¬ÎÒÃÇÐèÒª¶ÔLinuxÄں˾ÙÐÐÉèÖã¬ÒÔÆôÓÃʵʱÐԵĹ¦Ð§¡£¿ÉÒÔͨ¹ýÒÔÏ°취¾ÙÐÐÉèÖãº
ÏÂÔØLinuxÄÚºËÔ´Âë¡£
Ê×ÏÈ£¬ÎÒÃÇÐèÒªÏÂÔØLinuxÄں˵ÄÔ´Âë¡£¿ÉÒÔ´ÓLinux¹Ù·½ÍøÕ¾£¨www.kernel.org£©ÉÏÏÂÔØ×îеÄÎȹ̰æÄÚºËÔ´Âë¡£
±àÒëÄںˡ£
½âѹÏÂÔصÄÄÚºËÔ´Â룬²¢½øÈë½âѹºóµÄĿ¼¡£ÔËÐÐÒÔÏÂÏÂÁî±àÒëÄںˣº
make menuconfig
µÇ¼ºó¸´ÖÆ
Õ⽫Æô¶¯ÄÚºËÉèÖò˵¥¡£Ôڲ˵¥ÖУ¬ÎÒÃÇÐèÒª¶ÔÒÔÏÂÑ¡Ïî¾ÙÐÐÉèÖãº
General setup -> Preemption model
Ñ¡Ôñ”Fully preemptible kernel (RT)”¡£Õ⽫ÆôÓÃÄں˵ÄʵʱÐÔ¡£
Processor type and features -> Preemption Model
Ñ¡Ôñ”Voluntary Kernel Preemption (Desktop)”¡£Õ⽫ÆôÓÃÄں˵ĿÉÇÀÕ¼ÐÔ£¬Ìá¸ßʵʱÐÔÄÜ¡£
Processor type and features -> Timer frequency
½«×¼Ê±Æ÷ƵÂÊÉèÖÃΪ1000 HZ¡£
Processor type and features -> Timer tick handling
Ñ¡Ôñ”Standard clock tick”¡£Õ⽫ÆôÓñê×¼µÄʱÖÓÖÐÖ¹´¦Öóͷ£¡£
Processor type and features -> Timer slack
½«×¼Ê±Æ÷ËÉи¶ÈÉèÖÃΪ1¡£
Power management options -> CPU Frequency scaling
½ûÓÃCPUƵÂʵ÷Àí¹¦Ð§£¬ÒÔ×èֹƵÂÊÇ뻶ÔʵʱÐÔµÄÓ°Ïì¡£
Power management options -> CPU idle -> CPU idle governor
Ñ¡Ôñ”Menu”¡£Õ⽫½ûÓÃCPU¿ÕÏÐ״̬µÄ×Ô¶¯ÖÎÀí¡£
Íê³ÉÉèÖúó£¬ÉúÑIJ¢Í˳ö²Ëµ¥¡£È»ºó£¬ÔËÐÐÒÔÏÂÏÂÁî±àÒëÄںˣº
make -j4
µÇ¼ºó¸´ÖÆ
Õ⽫ʹÓÃ4¸öÏ߳̾ÙÐбàÒ롣ƾ֤ϵͳµÄÐÔÄÜ£¬¿ÉÒÔ×ÔÐе÷½âÏß³ÌÊý¡£
±àÒëÍê³Éºó£¬ÔËÐÐÒÔÏÂÏÂÁî×°ÖÃеÄÄںˣº
make modules_install make install
µÇ¼ºó¸´ÖÆ
×°ÖÃÍê³Éºó£¬ÖØÆôϵͳ£¬²¢Ñ¡ÔñбàÒëµÄÄÚºËÆô¶¯¡£
¶þ¡¢ÊµÊ±ÐÔ¹¦Ð§¿â
ÔÚÉèÖúÃÄں˺ó£¬ÎÒÃÇ»¹ÐèҪװÖÃһЩʵʱÐÔ¹¦Ð§¿â£¬ÒÔÖ§³Öʵʱ²Ù×÷ϵͳµÄ¿ª·¢¡£
×°ÖÃʵʱÐÔ¶ÔÐÔÄÜÓ°Ïì½ÏСµÄµ÷ÀíÆ÷
LinuxÄÚºËĬÈϵĵ÷ÀíÆ÷£¨CFS£©¶ÔʵʱÐÔÄÜÓ°Ïì½Ï´ó£¬¿ÉÒÔ˼Á¿×°ÖÃһЩÌæ»»µÄµ÷ÀíÆ÷£¬Èç”Real-Time Preemption Patch”£¨PREEMPT-RT£©ºÍ”Staircase Deadline Scheduler”£¨SDS£©¡£
×°ÖÃÕâЩµ÷ÀíÆ÷µÄÏêϸ°ì·¨¿ÉÒԲο¼Æä¹Ù·½Îĵµ¡£
×°ÖÃʵʱÐÔ¹¦Ð§¿â
¿ÉÒÔʹÓÃÒÔÏÂÏÂÁî×°ÖÃʵʱÐÔ¹¦Ð§¿â£º
sudo apt-get install libc6-dev-i386 sudo apt-get install libncurses5-dev sudo apt-get install build-essential
µÇ¼ºó¸´ÖÆ
Èý¡¢ÊµÊ±²Ù×÷ϵͳ¿ª·¢Ê¾Àý
ÉèÖÃÍêʵʱÐÔ¹¦Ð§ºó£¬ÎÒÃÇ¿ÉÒÔ×îÏȾÙÐÐʵʱ²Ù×÷ϵͳµÄ¿ª·¢¡£ÏÂÃæÊÇÒ»¸ö¼òÆÓµÄʾÀý£¬Õ¹Ê¾ÔõÑùÔÚLinuxϵͳÖÐʹÓÃʵʱÐÔ¹¦Ð§¡£
Ê×ÏÈ£¬½¨ÉèÒ»¸öеÄCÎļþ£¬Èç”realtime.c”£¬²¢Ð´ÈëÒÔÏ´úÂ룺
#include <stdio.h> #include <pthread.h> #include <sched.h> #include <stdlib.h> void *realtime_thread(void *arg) { struct sched_param param; param.sched_priority = 99; if (sched_setscheduler(0, SCHED_FIFO, ¶m) == -1) { perror("sched_setscheduler() failed"); exit(EXIT_FAILURE); } // ʵʱÏ̵߳ĴúÂë // ... return NULL; } int main() { pthread_t thread_id; pthread_create(&thread_id, NULL, realtime_thread, NULL); pthread_join(thread_id, NULL); return 0; }
µÇ¼ºó¸´ÖÆ
ÔÚÉÏÃæµÄ´úÂëÖУ¬ÎÒÃÇͨ¹ýpthread¿â½¨ÉèÁËÒ»¸öʵʱỊ̈߳¬²¢½«ÆäÉèÖÃΪ×î¸ßÓÅÏȼ¶£¨99£©¡£ÔÚʵʱÏ̵߳ĴúÂëÖУ¬¿ÉÒÔ±àдÐèҪʵʱÐÔ°ü¹ÜµÄʹÃü¡£
±àÒë¸Ã´úÂ룬¿ÉÒÔʹÓÃÒÔÏÂÏÂÁ
gcc -o realtime realtime.c -lpthread
µÇ¼ºó¸´ÖÆ
ÔËÐÐÌìÉúµÄ¿ÉÖ´ÐÐÎļþ£¬¼´¿ÉÔÚLinuxϵͳÖÐÔËÐÐʵʱÐÔʹÃü¡£
×ܽá
ͨ¹ýÉÏÊö°ì·¨£¬ÎÒÃÇ¿ÉÒÔÀÖ³ÉÉèÖÃLinuxϵͳÒÔÖ§³Öʵʱ²Ù×÷ϵͳµÄ¿ª·¢¡£ÉèÖÃÄں˺Í×°ÖÃʵʱÐÔ¹¦Ð§¿âºó£¬¿ÉÒÔ±àд²¢ÔËÐоßÓÐʵʱÐÔÒªÇóµÄʹÃü¡£Õ⽫ΪǶÈëʽϵͳµÄ¿ª·¢Ìṩ¸ü´óµÄÎÞаÐԺͿÉÕ¹ÍûÐÔ¡£
ÒÔÉϾÍÊÇÉèÖÃLinuxϵͳÒÔÖ§³Öʵʱ²Ù×÷ϵͳ¿ª·¢µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡