简体   繁体   English

测量进程上下文切换

[英]Measuring a process context switch

I am creating a C program to measure a process switch for a project, and I am having a couple difficulties. 我正在创建一个C程序来测量项目的进程切换,我遇到了一些困难。 The method I am using is to create 2 pipes, parentpipe and childpipe. 我正在使用的方法是创建2个管道,parentpipe和childpipe。 The parent writes one byte in to its pipe then reads the child pipe, theoretically forcing control to the child pipe. 父级将一个字节写入其管道,然后读取子管道,理论上强制控制子管道。 The child e reads the parent pipe and writes a byte to the child pipe. 子e读取父管道并将一个字节写入子管道。

Here are my issues: 这是我的问题:

  1. The processes aren't actually forced to switch. 这些进程实际上不会被强制切换。 If I use sleep instead of the above method then they switch, but I'm trying not to use sleep. 如果我使用睡眠而不是上面的方法然后他们切换,但我试图不使用睡眠。 How do i force them to switch? 我如何强迫他们切换?

  2. I am using CLOCK_MONOTONIC to measure and can't figure out where to put the start and stop for it. 我正在使用CLOCK_MONOTONIC进行测量,无法确定从哪里开始和停止它。 I keep getting junk values no matter where I put them (assuming I put one in each process:start in one and stop in the other). 无论我把它放在哪里,我都会不断得到垃圾值(假设我在每个过程中都放了一个:从一个开始然后停在另一个过程中)。 Where do i put the clocks? 我把时钟放在哪里?

Thank you for your help. 谢谢您的帮助。

  1. Be sure to select unbuffered i/o. 一定要选择无缓冲的i / o。 Otherwise read and write wait for more characters before returning, even when only one byte is requested. 否则,在返回之前,即使只请求一个字节,读写也会等待更多字符。

  2. Record CLOCK_MONOTONIC at the beginning of the program and subtract it from all subsequent timestamps. 在程序开头记录CLOCK_MONOTONIC,并从所有后续时间戳中减去它。 Typically CLOCK_MONOTONIC is implemented as the time since the system booted. 通常CLOCK_MONOTONIC实现为自系统启动以来的时间。 Suggesting where to put the measurement would be easier if you showed your code. 如果您展示代码,建议放置测量的位置会更容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM