频繁设置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来说非常重要. 主要内容: 系统时间 定时器 定时器相关 ...
随机推荐
- maya灯光导入houdini插件开发
加入工作室时师兄给了两道测试题,由于第一道是完善师兄的一个houdini项目管理插件,我只是开发了一些小功能,所以不好意思拿出来. 第二道题就完全是由自己开发的一个小插件,功能是把maya里的灯光导入 ...
- iOS Unity 项目解析
本文旨在记录Unity 导出的iOS 项目笔记,另带接入SDK的终极方案,顺带对比Android 项目 1蓝色的目录 Data 这个就是项目的数据,每个项目不一样也就是这个目录不一样,是不是可以把这个 ...
- PCB封装设计建议:
1,通孔型元器件建议孔直径比元器件管脚直径大0.2-0.3mm左右,焊盘铜皮外沿一般是0.3-1mm(相当于直径应该加0.6-2mm)宽大元件可再大一点,对于设计单面板的,则最小铜皮外沿应大于1mm以 ...
- [C# 学习笔记]运用 GDI+ 的 Matrix 进行显示图形的平移和缩放
C# 学习中,想尝试着做一个工控方面的上位机,可以读取CAD绘制的图形,然后把它显示出来,后面让运动控制器去走CAD里面的轨迹. 一.用netDXF 开源包,对DXF文件进行解析.解析后的直线.圆.圆 ...
- 有关C++数据结构
1.临时变量的访问速度远远大于成员变量. 2.C++中唯一一种函数返回值可以做左值的就是引用,本质上也是指针. 3.成员函数末尾加const,表示只读成员函数,不能修改成员变量的值.只读成员函数仅仅用 ...
- loadrunner添加/清除 cookies
web_add_cookie("reloadCount=1;domain={Host}"); 清除 cookies web_cleanup_cookies():
- c# Visual Studio|There is no editor available for ***,make sure the application for the file type(.vb) is installed问题解决方法
这个问题出现在在使用VS编码当中,电脑意外关机,导致的文件的缺失或者损坏. 使用反编译软件(如:ILSpy)对编译后的 .EXE文件进行反编译,在翻遍的结果中将相关代码拷贝至目标路径下,替换所需文件. ...
- Serverless 架构演进与实践
Serverless 架构演进与实践 1. 介绍 Serverless 并不仅仅是一个概念,很多地方都已经有了它的影子和思想,本文将给大家介绍最近比较火的 Serverless. 首先放出官方对 Se ...
- PC端,知乎在不想登录的情况下一打开就弹出登录框的无痛解决办法
基于chrome浏览器 第一步: chrome://settings/content/javascript 第二步:添加禁用项 [*.]zhihu.com
- conda使用杂记
总纲 https://docs.anaconda.com/anaconda/navigator/ 其中有链接 miniconda https://docs.anaconda.com/anaconda/ ...