控制程序执行

发布于 2024-08-10 05:27:46 字数 456 浏览 2 评论 0原文

我正在为多线程应用程序编写小型调试程序。我的想法是运行正在调试的目标,例如 100 纳秒,然后暂停并检查其内存。然而,这(只是伪代码)

nanosleep(100);             //sleep debuger for 100 nanosec and let a program run
kill(target_app_pid, SIGSTOP); //stop target app

不起作用,因为进程切换可能在 nanosleep 之后发生,并且目标将根据需要运行更长时间。有没有办法给进程“定义”的时间片然后挂起它?我能想到的唯一解决方案是添加系统调用并修复调度程序以实现我的要求,但这需要付出巨大的努力和许多错误。 也许为调试器进程设置“实时”优先级会有帮助?它会是干净的解决方案吗?

还假设我可以记录目标应用程序的源代码。是否可以设置某种计时器并在一段(非常小且精确的)时间后休眠整个过程?

I am writing small debugging program for multithread apps. My idea is to run the target, that is being debuged for for example 100 nanosecs, then pause and examine its memory. However this ( just pseudocode )

nanosleep(100);             //sleep debuger for 100 nanosec and let a program run
kill(target_app_pid, SIGSTOP); //stop target app

wouldn't work, because process-switch could happen right after nanosleep and target would run longer as required. Is there any way in to give a process "defined" time slice and then suspend it? Only solution that I can imagine is add system calls and fix the scheduler to achieve what I require but this assumes great effort and many bugs.
Perhaps setting "real-time" priority for debuger process can help? Would it be clean solution?

Assume too, that I can insrument source code of target app. Is it possible to set up some kind of timer and sleep the whole process after some (very small and precise) period of time?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

楠木可依 2024-08-17 05:27:46

你真的认为你可以nanosleep 100 纳秒吗?您的内核中的 HZ 值是多少?最接近这个睡眠顺序的是 udelay(),但这是在内核中,您可以在其中禁用抢占,而不是在用户态。查看 Linux 内核源代码中的 linux/include/delay.hinit/calibrate.c

Do you really think you can nanosleep for 100 nanoseconds? What's the HZ value in your kernel? The closest you get to this order of sleep is udelay(), but that's in the kernel where you can disable preemption, not in user-land. Check out linux/include/delay.h and init/calibrate.c in the Linux kernel source.

听你说爱我 2024-08-17 05:27:46

由于 Linux 充其量只是一个“软实时”操作系统(尤其是在用户空间中工作),因此很难获得您所追求的精度类型。

如果您使用嵌入式处理器,nanosleepmicrosleep 调用通常作为自旋循环实现。在启动期间,处理器的特征是“校准”该自旋循环。然而,获得这种类型的精度仍然需要非常详细地了解处理器架构以及正在执行的内容(在指令级别)。

较新版本的 Linux 内核确实有一些高速定时器实现,但您仍然关注微秒分辨率。

如果您在桌面系统上运行,我不知道为什么需要这种级别的精度。

Since linux is at best a "soft real time" OS (especially working in user space), it will be difficult to get the type of precision you are after.

If you are working on an embedded processor, the nanosleep and microsleep calls are often implemented as a spin loop. During boot, the processor is characterized to "calibrate" this spin loop. Still, however, getting this type of precision requires a very detailed understanding of the processor architecture and what is being executed (at the instruction level).

Newer versions of the linux kernel do have some high-speed timer implementations, but you are still looking at microsecond resolution.

If you are running on a desktop system, I have no idea why you need this level of precision.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文