为什么Windows/iOS操作很流畅而Linux/Android却很卡顿呢
Windows与众不同,其弱化了进程(其实应该是线程,但是我就统一写成进程吧,为了照顾不懂Windows内核原理的读者)的初始基优先级 ,而强化了动态优先级 ,更重要的是,动态优先级的值并非来自预测,而是来自于 事件 ,事件本身的紧急性反馈到了动态优先级的值,而事件本身的重要性则反馈到了时间片:
可以看出,Windows对于不同的事件定义了不同的优先级提升的具体数值, 将动态优先级的值和具体的事件做了精确的关联。 这些数值的定义上,甚至精细而贴心,详细的数值参见ntddk.h: // // Priority increment definitions. The comment for each definition gives // the names of the system services that use the definition when satisfying // a wait. //
// // Priority increment used when satisfying a wait on an executive event // (NtPulseEvent and NtSetEvent) //
#define EVENT_INCREMENT 1
// // Priority increment when no I/O has been done. This is used by device // and file system drivers when completing an IRP (IoCompleteRequest). //
#define IO_NO_INCREMENT 0
// // Priority increment for completing CD-ROM I/O. This is used by CD-ROM device // and file system drivers when completing an IRP (IoCompleteRequest) //
#define IO_CD_ROM_INCREMENT 1
// // Priority increment for completing disk I/O. This is used by disk device // and file system drivers when completing an IRP (IoCompleteRequest) //
#define IO_DISK_INCREMENT 1
// // Priority increment for completing keyboard I/O. This is used by keyboard // device drivers when completing an IRP (IoCompleteRequest) //
#define IO_KEYBOARD_INCREMENT 6
// // Priority increment for completing mailslot I/O. This is used by the mail- // slot file system driver when completing an IRP (IoCompleteRequest). //
#define IO_MAILSLOT_INCREMENT 2
// // Priority increment for completing mouse I/O. This is used by mouse device // drivers when completing an IRP (IoCompleteRequest) //
#define IO_MOUSE_INCREMENT 6
// // Priority increment for completing named pipe I/O. This is used by the // named pipe file system driver when completing an IRP (IoCompleteRequest). //
#define IO_NAMED_PIPE_INCREMENT 2
// // Priority increment for completing network I/O. This is used by network // device and network file system drivers when completing an IRP // (IoCompleteRequest). // // 网卡IO之所以优先级提升并不是很多,是因为首先网卡是有队列缓存的,而大多数的报文都是burst而来的,队列缓存可以平滑掉首包延迟,其次,由于光速极限,相比于网络延迟,主机调度延迟真的可以忽略不计。 #define IO_NETWORK_INCREMENT 2
// // Priority increment for completing parallel I/O. This is used by parallel // device drivers when completing an IRP (IoCompleteRequest) //
#define IO_PARALLEL_INCREMENT 1
// // Priority increment for completing serial I/O. This is used by serial device // drivers when completing an IRP (IoCompleteRequest) //
#define IO_SERIAL_INCREMENT 2
// // Priority increment for completing sound I/O. This is used by sound device // drivers when completing an IRP (IoCompleteRequest) //
#define IO_SOUND_INCREMENT 8
// // Priority increment for completing video I/O. This is used by video device // drivers when completing an IRP (IoCompleteRequest) //
#define IO_VIDEO_INCREMENT 1
// // Priority increment used when satisfying a wait on an executive semaphore // (NtReleaseSemaphore) //
#define SEMAPHORE_INCREMENT 1 ---------------------
|