CentOS8实时FIFO进程未接收到XCPU信号

如何解决CentOS8实时FIFO进程未接收到XCPU信号

背景

我的脑海中有一个非常精确的程序,因此需要使用实时调度策略。该程序应该做什么是不可能的。在编写实际程序之前,我想先测试一下一些东西-实时和“正常”调度策略之间的一些差异,例如(例如,我注意到nanosleep使用实时FIFO的精度要高10倍)调度和99个优先级),当然还有SIGXCPU信号,如果信号超过一次性软允许的CPU时间,则应将其发送到实时进程。即使我的进程正在无限循环地消耗CPU时间,我也没有收到它。

环境

我正在使用vultr上托管的CentOS8-1核,512MB RAM,最新版本的内核和每个软件包。如果没有运行我的实时进程,top将显示2-3个进程正在运行(systemd是主要进程),并且有80多个正在休眠。所有活动进程似乎都具有正常的调度策略,优先级设置为20,这是最低的。
我的实时流程的代码如下:

#define _GNU_SOURCE

// most of these are useless yes,were used before for testing
// and I just did not care to remove them,but that shouldn't change anything,right

#include <sched.h>
#include <unistd.h>
#include <sys/types.h>

#include <stdio.h>
#include <stdatomic.h>
#include <signal.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
#include <errno.h>

static uint64_t GetTimeoutTime(const uint64_t nanoseconds) {
  struct timespec tp = { .tv_sec = 0,.tv_nsec = 0 };
  (void) clock_gettime(CLOCK_MONOTONIC,&tp);
  return (uint64_t)(tp.tv_sec) * 1000000000 + (uint64_t)(nanoseconds / 1000000000) * 1000000000 + (uint64_t)(tp.tv_nsec) + nanoseconds - (uint64_t)(nanoseconds / 1000000000) * 1000000000;
}

static int siga(int signum,void (*handler)(int)) {
  return sigaction(signum,&((struct sigaction){ .sa_handler = handler,.sa_flags = 0,.sa_mask = 0 }),NULL);
}

static void xcpu(int sig) {
  puts("xcpu called");
  (void) pthread_yield(); // to not get killed
}

int main() {
  uint64_t g = 0;
  uint64_t t1,t2;
  int err = siga(SIGXCPU,xcpu);
  if(err != 0) {
    puts("e");
    printf("%d\n",err);
  }
  if(sched_setscheduler(getpid(),SCHED_FIFO,&((struct sched_param){ .sched_priority = 99 })) != 0) {
    puts("err");
  }
  while(1) {
    t1 = GetTimeoutTime(0); // just some stuff to make the process busy
    t2 = GetTimeoutTime(0) - t1; // I was using this code before,thus left it there
    g += t2;
  }
  printf("avg %lf\n",(double)(g) / 10000.0); // just to make it seem as g is not useless
  return 0;
}

结果是-该进程持续占用90%以上的CPU,正在运行,并且一直未收到任何信号。我实际上使程序运行了大约15分钟,并且什么也没发生-该过程没有被杀死。我的意思是,FIFO调度不应该在线程运行时删除它们,对吗?那就是Round Robin的工作,所以我不太了解会导致这种现象的原因。我的线程是否在我不知情的情况下进入睡眠状态?
将截止时间设置为2 ^ 63-(1、2、3)个数字的DEADLINE调度是否比当前FIFO解决方案更好?我只是想大部分时间为自己获取大部分CPU,因为除了我自己的进程外,什么也不会使用CPU(唯一的区别是实时调度策略会带来一些好处,其中之一我在一开始就注意到并描述了-纳米睡眠的精度提高了。还有其他好处吗?)

解决方法

好的,我找到了答案。
问题在于RTIME的软硬限制。我认为默认情况下它们是很低的,但是现在我再次检查以确保。软限制和硬限制均为2 ^ 63。将软限制降低到1e6,将硬限制降低到1e7之后,我的进程开始每秒接收XCPU信号。使用getrlimitsetrlimit函数进行检查和降低(有关更多信息,请参见man。)。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-