Latency

什么叫实时操作系统

Not fast

just preditable


study lock, and write the table

study the ip related knowledge


▪A system is real timewhen timelinessis a dimension of correctness

几个术语补充下:

优先级反转:高优先级的进程等待低优先级的进程

比如:A有个系统调用,在kernel里面很慢才转过来,而B在A后,而B是desktop类型的process,比如鼠标,那么B就等着A。

优先级继承:为了解决上面这个问题的,如果A在B后,A就继承B的优先级。


CFS summery

▪Default scheduler used(>= 2.6.23) is the Completely FairScheduler (CFS)
▪The CFS works by evenlyallocating the amount of time available for processing among the processes thatcould be run
▪CFS use the Red-BlackTree, with operation time : O(LogN)
–When tasks aren’t running, each builds up a CPUallocation debt proportional to the number of taskswaiting.
–When the currently running task pays back, it goes to theback of the line and begins building a CPU debt again.
–The task with the highest time debt is then pulled from the list and run.
–There is some tuning for priority, in which case the debt accumulates faster.
▪Processes in a groupare treated as one scheduling entity when calculating the CPU time debt
我来补充下:
实际上红黑树每次取节点的时候是取最左边的叶子节点,而具体的运行过程,也就是cpu time debt的增加过程就是增加task的running_time,然后选出最小的running_time的个体放在最左边,这样可以保证大家都可以响应的。


–First In First Out(FIFO)
•When a task becomes runnable, it interrupts any other tasks with a lower priority andcontinues to run until the process waits on IO (like the disk or networkdevice) or voluntarily yields to another process.
–Round Robin (RR)
•Similar to FIFO scheduling, except that tasks run for a fixed amount oftime before they’re automatically moved to the back of the line.


▪The current project embodying this work is the CONFIG_PREEMPT_RT patch at http://rt.wiki.kernel.org
▪Thisproject first focused on reducing the latency in the Linux kernel by making itmore “preemptable”
▪When first ported to a multiprocessor system,kernel’s race conditions were solved by using the Big Kernel Lock (BKL)
–BKL wasa spinlock, thecode requesting the lock waited in a loop. Result in a system that couldn’t bescheduled in a real-time sense.
▪Preemptionis vital to real-time systems
Interruptionis necessary to meet deadlines

BKL还没有研究它它就没了。。。spinlock....


实际上这个项目关注了如下一些东西:

1. 高精度的始终。1ms是远远不够的。

这个已经被Merge到main line中。

2. 优先级继承

3. SOFT irq threads schedule (bottom half)


页面回收机制中的clock算法是怎样,可以看看。

FIFO是跑到等待IO,这个第一次听说

另外linux / real-time schedule 为什么分开?

需要研究下jiffy, HZ, and high resolution timer和real-time kernel project的关系。

优先级继承要看看代码

希望研究下soft irq和bf之间的关系


▪CFQ I/O scheduler:
–Thedefault I/O scheduler. It tries to distribute bandwidth equally amongall processes, suitable for desktop systems.
▪Anticipatoryscheduler:
–Attemptsto reorder theread requests so that reads and writes adjacent to each other on the disk’smedia occur one after another, allowing the device to operate more efficiently
▪Deadline I/Oscheduler:
–Attemptsto maximize throughput by reordering requests and is coded to reduce latency. When severalrequests for I/O occur, the deadline scheduler uses a round-robinalgorithm to distribute I/O resources.

如何去编写实时代码

1. lock memory

lock current + future

–mlockall(MCL_CURRENT| MCL_FUTURE)
•MCL_CURRENT : keep all currently allocated pages in memory
•MCL_FUTURE : lock any newly allocated pages

ulimit -l

notice: fork的时候lock memory不被继承

2. 尽量不要使用堆

因为malloc不知道需要耗费多长时间

只有去用的时候才会真正alloc

3.

▪All I/O operations are nondeterministic and nearly all generate page faults,because the kernel maps a page of memory to transfer from the device into yourprocess.
▪Time can vary wildlydepending on the state of the media
–Garbage-collectionactivity
–Databuffer
–Separatethread etc…
▪Use lower latency I/O scheduler if  I/Ominimal latency is important
▪Tradeoffs :
–Buffereddata may be lost if a program crash or inadvertent power-down
–Ifmaking the buffer too small, the buffer may overrun
–Extracode to manage the buffer for simultaneously read and written

4. 使用线程库,并且尽量减小线程的stack size。

5. 使用latencyTOP来评估latency

▪Download and build theuser program by :
–$ wgethttp://www.latencytop.org/download/latencytop-0.5.tar.gz

./latencytop -d

6. 增加延迟的一些设备

▪System Management Interrupts (SMI)
–A SMIcan be triggered for power management when a USB keyboard or mouse is pluggedin or removed
–Manydesktop machines have some SMI services and therefore aren’t usually fit forreal time
▪VGA Console
–The VGAhardware generates latencies of up to 1 millisecond
–Use aserial console instead, which can be scheduled
–Avoidthe VGA text console
▪DMA Bus Mastering
–Busmastering means that during this process, other devices can’t use the system’sbus
–DMA busmastering is a way to boost throughput but not necessarily reduce the amount ofjitter in the system

难怪服务器版的都么有usb controller。






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值