频繁设置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来说非常重要. 主要内容: 系统时间 定时器 定时器相关 ...
随机推荐
- HTML第四章作业
学生实践4.1.3 1 <!doctype html> 2 <html> 3 <head> 4 <meta charset="utf-8" ...
- python 安装fbprophet模块的艰辛历程
fbprophet这个模块是我目前见过最难装的一个模块,我安装这个包安装了3天,气死我了,需求的依赖包太多,而且对依赖包的版本有极高的要求,所以建议在装这个模块的时候在一个空的虚拟环境下安装,这样依赖 ...
- .net 反射简单介绍
1.什么是反射 反射是.NET中的重要机制,通过反射,可以在运行时获得程序或程序集中每一个类型(包括类.结构.委托.接口和枚举等)的成员和成员的信息.有了反射,即可对每一个类型了如指掌.另外我还可以直 ...
- 使用hugo在gitee上写blog
1. 安装hugo 1)下载 Hugo Releases,选择hugo_xxx_Windows-64bit.zip(xxx位版本). 2)设置路径 我的电脑->属性->高级系统设置-> ...
- Cloneable的使用
Cloneable的使用 在开发过程中,拷贝实例是常见的一种操作,如果一个类中的字段较多,而我们又采用在客户端中逐字段复制的方 法进行拷贝操作的话,将不可避免的造成客户端代码繁杂冗长,而且也无法对类中 ...
- Qt中的渲染
Qt中3种不同的渲染方式 1 )Qt::AA_UseDesktopOpenGL 使用显卡的openGL库,且要求支持openGL 2.1及以上的版本.因此很多老旧设备是不满足版本要求的(windows ...
- C++ read 读取字节数与设置不一样
当需要读取二进制文件时,C++可以采用ofstream流,并设置模式为ios::binary,就可以通过read函数进行按照字节读取了. 需要注意的是: 如果模式未进行设置,默认将以文本方式读取,此时 ...
- bug单建单规范
bug提单保证,清晰.简单.明了. 标题: [版本][服务器][模块][必现/偶现]bug标题(最短的话描述bug) 例:[0.9.0][dev][系统][必现]点击商店,跳转到仓库页面 bug模 ...
- Inno 设置文件或注册表ACL(访问控制权限)
欢迎访问我的个人博客:xie-kang.com 在[Files]区段或者[Registry]区段中可以设置Permissions属性,从而达到指定操作ACL(访问控制权限),使用方法如下: <用 ...
- 局部异常因子(Local Outlier Factor, LOF)算法详解及实验
局部异常因子(Local Outlier Factor, LOF)通过计算样本点的局部相对密度来衡量这个样本点的异常情况,可以算是一类无监督学习算法.下面首先对算法的进行介绍,然后进行实验. LOF算 ...