00 Linux v.s. RT Linux v.s. ART-Linux Linux RT-Linux ART-Linux Linux kumagai@emura.mech.tohoku.ac.jp
1 1.1 Linux Yes, No.,. OS., Yes. Linux,.,, Linux., Linux.,, Linux. Linux.,,. Linux,.,, 0..,. RT-Linux (1)(2), ART-Linux (4)(5),.,... RT-Linux ART-Linux,., Linux OS, OS (6)..,,, MS-DOS,.,,. 2 00
1.2 1.2. Linux(UNIX), MS-DOS OS,, ( ) 1.3 ( ),.,,.,,.,,,,,,.,,., Linux,, Linux., RT-Linux, ART-Linux. Linux 3
2 Linux RTLinux ART-Linux Linux, ( ), (, ),.,,,,., Linux, ( ).,.,. 1 [ms] ( ),., Linux,,.,,,,. 2.1 Linux,,., ( ),., (, ).,. while(1) { DoControl(); usleep(15000); } // // 4 00
2.1 21 cycle_15.xy 20.5 Interval [ms] 20 19.5 19 0 100 200 300 400 500 600 700 800 900 1000 Cycle 2.1 15 [ms], 1000,,.,,. MS-DOS, CPU,,,., Linux ( ) CPU,,.,. 2.1., 20 [ms].,,. 20 [ms] 10 [ms] (Alpha Linux 2,1 [ms] )., Linux, 20 [ms], 10 [ms],. Linux 5
2 LINUX 6 5 Interval [ms] 4 3 2 1 0 0 10 20 30 40 50 Time [s] 2.2 5 [ms] 10000 20 [ms] 10 [ms],.,.,,. /usr/src/linux/include/asm/param.h HZ. 100 1000.,, lilo.,.,,., top 1000%.., 5 [ms] 2.2. 10000, 5 [ms]. ( ). 100 [Hz] (=10 [ms]), 1[kHz](=1 [ms]) ( 1k-Linux ).,,,., (HZ=100 ),,. 6 00
2.2 Misc process Cyclic process CPU idle Misc process Cyclic process CPU idle 2.3 ( ) 2.2,..,.,.,. 2.3 1k-Linux, 3 [ms] ( )., CPU., H CPU (, CPU ).. CPU,,. (=3 [ms]),.,,.,.,,,. Linux 7
2 LINUX 2.2.1 CPU Linux OS,, CPU (CPU ),. (, (2) ). CPU, CPU., ( ), ( ). CPU. CPU. CPU.. Linux(UNIX) ( :ps aux),., CPU,,., Linux,,, CPU..,,,, CPU, ( ).,. CPU.,, 1.,, ( ). ( ),., 10 [ms] ( 20 =200[ms])..,,.,,, CPU. 8 00
2.3 2.2.2 Linux,.,,.,,.,,.,, CPU.,,,, CPU.,.,, ( ).. CPU,.,,,,, CPU,. Linux,,,,.. 2.3 2.3.1,, ( ).,,,. Linux 9
2 LINUX,,,.. gettimeofday()., ( ).,,. Pentium CPU. 64, CPU,, CPU., CPU (8)., Linux,.. unsigned long long GetTick(void) { unsigned int h,l; /* read Pentium time-stamp counter */ asm (".byte 0x0f,0x31" : "=a" (l),"=d" (h)); return ((unsigned long long int)h<<32) l; } (, gcc O ). long long, 64bit (printf %Ld ).,, CPU,. CPU, ( 1% ).,,, CPU Pentium. 2.3.2,.,,.. 2.4. 2 3,6 [ms] 3. 4,5 [ms]. 2,., ( (2)). (, ). 10 00
2.3 Misc process Cyclic process(2) Cyclic process(1) CPU idle Misc process Cyclic process(2) Cyclic process(1) CPU idle 2.4 2 ( 3,6 [ms] 4,5 [ms] ),,,,. 2.3.3 CPU, CPU.,, CPU.,,. Linux, UNIX nice, nice() setpriority()., ±20. nice, 20,. 20, Linux 11
2 LINUX CPU. Linux 20 ( 1 ), 10 [ms] ( 0 )., 20( ) 0( ), 400[ms](=10 [ms] 40):200[ms] CPU ( )., 2, CPU.,, root.. CPU,., Linux CPU. sched setscheduler(),.,, X ( ),., ( 1 )..,. (nice 20), 1.,,.,. 1,,,,.,, CPU,. 12 00
2.4. ----------------------------------------------------------------------- # nice --20./program./program 20. --20 - + -20 ----------------------------------------------------------------------- nice(-20); nice <unistd.h> setpriority(prio_process, getpid(), -20); <sys/time.h><sys/resource.h> setpriority, ----------------------------------------------------------------------- struct sched_param sp; sp.sched_priority=99; // 1( )-99( ) sched_setscheduler(0,sched_fifo,&sp); <sched.h> ----------------------------------------------------------------------- 2.4,,.,., ( ).,.,,.... 20 [ms] linux/include/asm/param.h HZ., 1., HZ.,,. Linux 13
3 Linux Linux., OS,.,,OS.,, ( ),. Linux, I/O, root,. I/O,. 3.1 I/O (x86),., I/O,., I/O., Intel 86 CPU (, I/O ). 3.1.1 I/O, ( ). int ioperm(unsigned long from, unsigned long num, int turn on); I/O from, num. turn on 1,., 14 00
3.1 I/O (X86)., 0x3ff,, iopl(). int iopl(int level); I/O. level 3 ( 0)., PCI I/O 0x3ff,, iopl(3);.,, unistd.h, sys/io.h ( man iopl, man ioperm )., root. root (su), root (chown root ), setuid (chmod +s ).,, root,., root, ( or ). 3.1.2 I/O,, I/O. unsigned char inb(unsigned short port); unsigned short inw(unsigned short port); unsigned int inl(unsigned short port); port 1(inb), 2(inw), 4(inl). void outb(unsigned char value, unsigned short port); void outw(unsigned short value, unsigned short port); void outl(unsigned int value, unsigned short port); port 1(outb), 2(outw), 4(outl) value. asm/io.h, gcc O., MS-DOS out?., Segmentation Fault (SIGSEGV). Linux 15
3 LINUX 3.2 I/O, ( )., /dev/mem., read()/write()., lseek();., open( /dev/mem, O RDONLY(O RDWD)); lseek(fd, address, SEEK SET);, read/write(fd, buf, count);,., lseek();. Linux,,.,., mmap(), read/write(),. 3.3 PCI PCI I/O.,,,. PCI,,. /proc/pci. cat /proc/pci PCI. % cat /proc/pci PCI devices found: Bus 0, device 16, function 0: Multimedia video controller: Intel SAA7116 (rev 0). Medium devsel. IRQ 9. Master Capable. Latency=64. : Bus 0, device 15, function 0: Bridge: Unknown vendor Unknown device (rev 1). 16 00
3.3 PCI Delay [ms] 0.45 0.4 0.35 0.3 0.25 0.2 0.15 0.1 0.05 0 0 100 200 300 400 500 600 700 800 900 1000 Cycle intsel.xy 3.1 Vendor id=136c. Device id=9054. Medium devsel. Fast back-to-back capable. IRQ 10. Non-prefetchable 32 bit memory at 0xec002000. I/O at 0x1400. I/O at 0x14f0. :,, IDE.,,, Linux. Vendor id, Device id.,.. http://www.pcisig.com/membership/vendors/index.html,.,. Vendor=136c, Device=9054 48bit. 16, 0xec002000, 0x1400, 14f0 I/O, IRQ10. I/O 2,,, 0x14f0.,, 2,. Linux 17
3 LINUX 3.4,.,.,,,,., select() (10). 3.1., 366[MHz] Celeron 2, (1k-Linux 2.2.10, X,, ). [µs].,.,.,,.,, C (10).,,. 3.5, Linux. I/O, mmap (10)., PCI,, MS-DOS,.,. 18 00
4, Linux,.,,,..., OS,.,,,,. OS,.,, 1,,,,.,,,,,. WEB. http://www.mechatronics.mech.tohoku.ac.jp/~kumagai/linux/,,,. Linux 19
(1) Real-Time Linux, http://www.rtlinux.org/ (2), : LINUX /, (1999) (3) 99 RT-Linux, (1999) (4),, :,, 355/356(1998) (5) : ART-Linux, ART-Linux : ART-Linux 1999 11, CQ (1999) (6) : PC/AT OS, Vol.16 No.8, 8/13(1998) (7) : Linux ( 1/2 ), 17, 847/850(1999) (8) Intel Architectrue Softoware Developer s Manual Volume 3: System Programming Guide Order Number 243192, 14-14, Intel Corporation(1997) (http://www.intel.com/ PDF ) (9) : RT-Linux, http://www.mechatronics.mech.tohoku.ac.jp/~kumagai/linux/, (2000) (10) : Linux, http://www.mechatronics.mech.tohoku.ac.jp/~kumagai/linux/, (2000) 20 00