频繁设置CGroup触发linux内核bug导致CGroup running task不调度

#include <iostream>
#include <sys/types.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <sys/stat.h>
#include <pthread.h>
#include <sys/time.h>
#include <string> using namespace std;
std::string sub_cgroup_dir("/sys/fs/cgroup/cpu/test"); // common lib
bool is_dir(const std::string& path)
{
struct stat statbuf;
if (stat(path.c_str(), &statbuf) == 0 )
{
if (0 != S_ISDIR(statbuf.st_mode))
{
return true;
}
}
return false;
} bool write_file(const std::string& file_path, int num)
{
FILE* fp = fopen(file_path.c_str(), "w");
if (fp = NULL)
{
return false;
} std::string write_data = to_string(num);
fputs(write_data.c_str(), fp);
fclose(fp);
return true;
} // ms
long get_ms_timestamp()
{
timeval tv;
gettimeofday(&tv, NULL);
return (tv.tv_sec * 1000 + tv.tv_usec / 1000);
} // cgroup
bool create_cgroup()
{
if (is_dir(sub_cgroup_dir) == false)
{
if (mkdir(sub_cgroup_dir.c_str(), S_IRWXU | S_IRGRP) != 0)
{
cout << "mkdir cgroup dir fail" << endl;
return false;
}
} int pid = getpid();
cout << "pid is " << pid << endl;
std::string procs_path = sub_cgroup_dir + "/cgroup.procs";
return write_file(procs_path, pid);
} bool set_period(int period)
{
std::string period_path = sub_cgroup_dir + "/cpu.cfs_period_us";
return write_file(period_path, period);
} bool set_quota(int quota)
{
std::string quota_path = sub_cgroup_dir + "/cpu.cfs_quota_us";
return write_file(quota_path, quota);
} // thread
// param: ms interval
void* thread_func(void* param)
{
int i = 0;
int interval = (long)param;
long last = get_ms_timestamp(); while (true)
{
i++;
if (i % 1000 != 0)
{
continue;
} long current = get_ms_timestamp();
if ((current - last) >= interval)
{
usleep(1000);
last = current;
}
} pthread_exit(NULL);
} void test_thread()
{
const int k_thread_num = 10;
pthread_t pthreads[k_thread_num]; for (int i = 0; i < k_thread_num; i++)
{
if (pthread_create(&pthreads[i], NULL, thread_func, (void*)(i + 1)) != 0)
{
cout << "create thread fail" << endl;
}
else
{
cout << "create thread success,tid is " << pthreads[i] << endl;
}
}
} //argv[0] : period
//argv[1] : quota
int main(int argc,char* argv[])
{
if (argc <3)
{
cout << "usage : ./inactive timer $period $quota" << endl;
return -1;
} int period = stoi(argv[1]);
int quota = stoi(argv[2]);
cout << "period is " << period << endl;
cout << "quota is " << quota << endl; test_thread();
if (create_cgroup() == false)
{
cout << "create cgroup fail" << endl;
return -1;
} int i =0;
while (true)
{
if (i > 20)
{
i = 0;
} i++;
long current = get_ms_timestamp();
long last = current;
while ((current - last) < i)
{
usleep(1000);
current = get_ms_timestamp();
} set_period(period);
set_quota(quota);
} return 0;
}
2.1.2 编译
g++ -std=c++11 -lpthread trigger_cgroup_timer_inactive.cpp -o inactive_timer
2.1.3 在CentOS7.0~7.5的系统上执行程序
./inactive_timer 100000 10000







tg_set_cfs_quota()
tg_set_cfs_bandwidth()
/* restart the period timer (if active) to handle new period expiry */
if (runtime_enabled && cfs_b->timer_active) {
/* force a reprogram */
cfs_b->timer_active = 0;
__start_cfs_bandwidth(cfs_b);
}



频繁设置CGroup触发linux内核bug导致CGroup running task不调度的更多相关文章
- 再思linux内核在中断路径内不能睡眠/调度的原因(2010)【转】
转自:http://blog.csdn.net/maray/article/details/5770889 Linux内核中断路径中不能睡眠,为什么? 这里就行了很深入的讨论,值得一看:http:// ...
- uboot环境变量(设置bootargs向linux内核传递正确的参数)
这是我uboot的环境变量设置,在该设置下可以运行initram内核(从内存下载到nandflash再运行),但是运行nfs根文件系统的时候一直出错,各种错误.查看了很多资料后猜想应该是uboot传递 ...
- Linux内核升级导致无法启动,Kernel panic - not syncing Unable to mount root fs on unknown block(0,0)
问题原因:内核的某次升级,导致系统无法启动. 首先进入recovery模式:引导界面选择-->Ubuntu高级-->出现的选项中选择能够启动的recovery模式(几个内核版本分别试一下) ...
- Linux内核入门到放弃-进程管理和调度-《深入Linux内核架构》笔记
进程优先级 硬实时进程 软实时进程 普通进程 O(1)调度.完全公平调度器 抢占式多任务处理(preemptive multitasking):各个进程都分配到一定的时间段可以执行.时间段到期后,内核 ...
- Linux 内核超时导致虚拟机无法正常启动
问题描述 当 Linux 虚拟机启动时,通过串口输出或者启动日志, 观察到超时的报错.导致虚拟机无法正常启动和连接. 问题分析 常见的超时报错范例如下: 复制 INFO: task swapper:1 ...
- 别人的Linux私房菜(24-25)X Window设置介绍、Linux内核编译与管理
X Window主要组件为:X Server .X Client . Window Manager . Display Manager. X Server管理硬件,X Client则为应用程序,将所需 ...
- [Wolfgang Mauerer] 深入linux 内核架构 第二章 进程管理与调度【未完】
作为Linux开发爱好者,从事linux 开发有三年多时间.做过bsp移植,熟悉u-boot代码执行流程:看过几遍<linux 设备驱动程序开发>,分析过kernel启动流程,写过驱动, ...
- 内核futex的BUG导致程序hang死问题排查
https://mp.weixin.qq.com/s/sGS-Kw18sDnGEMfQrbPbVw 内核futex的BUG导致程序hang死问题排查 原创: 王领先 58架构师 今天 近日,Had ...
- 精《Linux内核精髓:精通Linux内核必会的75个绝技》一HACK #7 Cgroup、Namespace、Linux容器
HACK #7 Cgroup.Namespace.Linux容器 本节将介绍Cgroup与Namespace以及通过这两个功能实现的容器功能.CgroupCgroup(control group)是将 ...
- 初探内核之《Linux内核设计与实现》笔记下
定时器和时间管理 系统中有很多与时间相关的程序(比如定期执行的任务,某一时间执行的任务,推迟一段时间执行的任务),因此,时间的管理对于linux来说非常重要. 主要内容: 系统时间 定时器 定时器相关 ...
随机推荐
- vscode 一些扩展的推荐(前端)
- `Auto Rename Tag`:成对修改 HTML 标签名 - `Bracket Pair Colorizer`:括号匹配高亮 - `Color Highlight`:显示颜色代码的颜色 - ...
- MP逻辑删除
在实体类中加上@TableLogic注解 在配置类中加入逻辑删除插件
- Ubuntu与centos之间的文件传输
Ubuntu与centos之间的文件传输 默认端口:22 传输前确认端口是否开启 1.在Ubuntu上安装scp命令 apt-get install openssh-server 2.将U ...
- vue.js拓展无法启用
vue.js拓展无法启用 这里我以自己的谷歌浏览器演示 C:\Users\维磊\AppData\Local\Google\Chrome\User Data\Default\Extensions\nhd ...
- python读书笔记-网页制作
socket()函数 Python 中,我们用 socket()函数来创建套接字,语法格式如下: Socket 对象(内建)方法 Python Internet 模块:
- Anaconda与conda、pip与conda的区别 - 搬运
Anaconda与conda.pip与conda的区别 风影忍着 转自:https://zhuanlan.zhihu.com/p/379321816 作为一个Python初学者,在请教资深 ...
- mysql 中 insert 大量数据 避免时间戳相同 !!
时间函数 now() current_timestamp() 和 sysdate() CURRENT_TIMESTAMP and CURRENT_TIMESTAMP() are synonyms fo ...
- Java面向对象 --2
22.面向对象特征之二: 继 承 2020-04-29 21:39:33 01.多个类中存在相同属性和行为时,将这些内容抽取到单独一个类中,那么子类无需再定义这些属性和行为,只要继承父类即 ...
- Docker-界面化
docker-ui docker-ui只能便于我们查看系统的相关信息,镜像或者容器.在界面上做简单的处理,可处理单机版Docker. docker pull uifd/ui-for-docker do ...
- 解密Prompt系列3. 冻结LM微调Prompt: Prefix-Tuning & Prompt-Tuning & P-Tuning
这一章我们介绍在下游任务微调中固定LM参数,只微调Prompt的相关模型.这类模型的优势很直观就是微调的参数量小,能大幅降低LLM的微调参数量,是轻量级的微调替代品.和前两章微调LM和全部冻结的pro ...