如何通过实验确定进程/线程的调度量? [英] How to experimentally determine the scheduling quantum of a process/thread?

查看:135
本文介绍了如何通过实验确定进程/线程的调度量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只要对为什么要知道这一点?"的含义发表任何评论,这只是我好奇的一个难题,而不是出于任何实际原因我需要做的事情.

Just to head off any comments to the effect of "why do you need to know this??": This is just a puzzle I was curious about, not something I need to do for any practical reason.

考虑到典型的POSIX系统[1],您将如何设计一个实验来确定CPU绑定进程的调度时间[2]?

Given a typical POSIX system[1], how would you design an experiment to determine the scheduling quantum[2] of a CPU-bound process?

[1]:但不允许您通过syscall或/proc接口查询此信息的人

[1]: but NOT one that lets you query for this information through a syscall or /proc interface

[2]:调度时间"是指进程在CPU上运行的时间,在调度时间结束且操作系统允许其他进程运行之前,该进程不会阻塞或屈服.

[2]: "Scheduling quantum" is defined as the amount of time a process will run on the CPU without blocking or yielding before its scheduled time is over and the OS lets a different process run.

推荐答案

我不确定它的准确性如何,但这可能有用:

I'm not sure how accurate it would be, but this might work:

  1. 确保您的计算机处于闲置状态(或尽可能使计算机处于闲置状态)
  2. 关闭2N个线程(其中N是您计算机中的内核数).所有这些线程都应设置为以彼此相同的优先级运行.
  3. 每个线程应该运行一个无限循环,在此循环中,除了使用高分辨率计时器(例如,调用std :: chrono :: steady_clock :: now()或类似).
  4. 在循环的每次迭代中,每个线程都应检查结果时间值中的突然间隔",即时钟时间从(t)跳到(t + n毫秒),其中n大于通常的增量价值).这些差距最有可能表明某个线程被踢出CPU的时间段,以便另一个线程可以运行.
  5. 在某个时候,计算所有这些间隙大小的平均值,这就是您对调度程序的量子大小的估计.

请注意,这是假设您的时钟分辨率大于调度程序的量子大小;如果不是这样(例如,如果您尝试使用分辨率为10mS的时钟来测量5mS的量子长度),那么对于AFAICT来说,很难测量量子长度.

Note that this assumes that your clock's resolution is greater than the scheduler's quantum size; if it's not (e.g. if you trying to use a clock with 10mS resolution to measure a 5mS quantum length), then measuring the quantum length would be difficult AFAICT.

这篇关于如何通过实验确定进程/线程的调度量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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