版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/huangweiqing80/article/details/83088465
Linux内核可以看作一个服务进程(管理软硬件资源,响应用户进程的种种合理以及不合理的请求)。
" 内核线程 " 是一种 特殊进程 , 独立运行在 " 内核空间 " , 其将 " 内核函数 " 委托给 独立进程 , 该 " 独立进程 " 与 其它进程 ( 包括 普通进程 , 内核自身 , 用户级线程 ) 并行执行 ;
虽然讲解完了内核线程的创建过程,但是似乎又少点什么,那么下面我们来看两个细节:内核线程执行处理函数和内核线程上下文切换细节:
Linux下有3个特殊的进程,idle进程(PID = 0), init进程(PID = 1)和kthreadd(PID = 2)
进程是一个具有一定独立功能的程序关于某个数据集合的一次运行活动。它是操作系统动态执行的基本单元,在传统的操作系统中,进程既是基本的分配单元,也是基本的执行单元。进程的概念主要有两点:第一,进程是一个实体。每一个进程都有它自己的地址空间,一般情况下,包括文本区域(text region)、数据区域(data region)和堆栈(stack region)。文本区域存储处理器执行的代码;数据区域存储变量和进程执行期间使用的动态分配的内存;堆栈区域存储着活动过程调用的指令和本地变量。第二,进程是一个“执行中的程序”。程序是一个没有生命的实体,只有处理器赋予程序生命时(操作系统执行之),它才能成为一个活动的实体,我们称其为进程。
很多的小伙伴,被java IO 模型,搞得有点儿晕,一会儿是4种模型,一会儿又变成了5种模型。
wq = create_singlethread_workqueue("mydrv");
在原来配置的基础上,make menuconfig选中如下选项重新配置Linux,使之携带调试信息
Linux内核涉及进程和程序的所有算法都围绕一个名为task_struct的数据结构建立,该结构定义在/usr/include/sched.h中;task_struct数据结构提供了两个链表表头,用于实现进程家族关系;
当用户线程调用了 read 系统调用,内核(kernel)就开始了 IO 的第一个阶段:准备数据。很多时候,数据在一开始还没有到达(比如,还没有收到一个完整的Socket数据包),这个时候 kernel 就要等待足够的数据到来。
https://devarea.com/understanding-linux-kernel-preemption/#.XrKLcfnx05k
通过 ps 命令可以看到红色方框标出的都是父进程为2号进程的内核线程,2号进程即蓝色方框标出的进程 kthreadd,1号进程是绿色方框标出的进程 init,它们的父进程号都是0。
LinuxThreads 项目最初将多线程的概念引入了 Linux?,但是 LinuxThreads 并不遵守 POSIX 线程标准。尽管更新的 Native POSIX Thread Library(NPTL)库填补了一些空白,但是这仍然存在一些问题。本文为那些需要将自己的应用程序从 LinuxThreads 移植到 NPTL 上或者只是希望理解有何区别的开发人员介绍这两种 Linux 线程模型之间的区别。
前言: kvm-clock,tsc,hpet,acpi_pm,pit,rtc。。。这些词看着都晕了@@ 虚拟化场景下,容作者在这里一一道来。 分析: 1,Linux clocksource 以Li
关于进程和线程,在 Linux 中是一对儿很核心的概念。但是进程和线程到底有啥联系,又有啥区别,很多人还都没有搞清楚。
zabbix_agentd [10555]: cannot create Semaphore: [28] No space left on device
接上一篇分析: 《bootloader启动之【 Pre-loader -> Lk】》
前面我们了解到了0号进程是系统所有进程的先祖, 它的进程描述符init_task是内核静态创建的, 而它在进行初始化的时候, 通过kernel_thread的方式创建了两个内核线程,分别是kernel_init和kthreadd,其中kernel_init进程号为1
实时分为硬实时和软实时,硬实时要求绝对保证响应时间不超过期限,如果超过期限,会造成灾难性的后果,例如汽车在发生碰撞事故时必须快速展开安全气囊;软实时只需尽力使响应时间不超过期限,如果偶尔超过期限,不会造成灾难性的后果.
前言: 我大天朝人觉得什么东西含量不够,叫做有“水份”。内存的含量不足,叫“balloon”。作者是外语专业毕业的,感觉不同国度的人虽然语言不同,但是表达出来的东西很相似。有点意思~ 代码分析: 代码路径:linux-4.0.4/drivers/virtio/virtio_balloon.c 1,Linux的memory balloon的实现上,MODULE_DESCRIPTION是“Virtio balloon driver”,以及driver注册的逻辑中,都会提到virtio。简单来说,virtio是虚
经过一个多星期的内核折磨,今天终于可以写下自己移植内核的一些心得,网上有很多博客论坛都有谈到,但是这些又说的方式有些模糊,这里我综合的几个博客在重新说下内核替换编译的步骤、以及如何更新启动项grub。替换linux的内核一共有两种方式,第一种方式是下载官方kernel提供的源码包,进行编译替换;第二种直接下载内核安装包deb,进行升级替换。
实时系统要求对事件的响应时间不能超过规定的期限,响应时间是指从某个事件发生到负责处理这个事件的进程处理完成的时间间隔,最大响应时间应该是确定的、可以预测的。
前言: qemu发生了crash。这种类型的问题比较少见,这里说一下这个问题的分析过程。 分析: 1,coredump 生成的coredump,一种是配置了/proc/sys/kernel/cor
本节我们将从linux启动的第一个进程说起,以及后面第一个进程是如何启动1号进程,然后启动2号进程。然后系统中所有的进程关系图做个简单的介绍
DragonStub是依托于uboot提供的efi环境来运行的,它基于linux efi stub,负责把dragonos内核加载到对应的位置。并把FDT传递给dragonos内核。它主要是使得dragonos内核的引导不依赖于具体板卡,不用把设备树编译到内核里面去。
从本篇开始回顾总结Netty通信框架,尝试为读者揭开它的神秘面纱。Flink内部节点之间的通信是用Akka,比如JobManager和TaskManager之间的通信。而operator之间的数据传输是利用Netty。
本文主要讨论在高实时要求、高效能计算、DPDK等领域,Linux如何让某一个线程排他性独占CPU;独占CPU涉及的线程、中断隔离原理;以及如何在排他性独占的情况下,甚至让系统的timer tick也不打断独占任务,从而实现最低的延迟抖动。
在计算机系统中,CPU的功能是执行程序,总结起来就是我们在教科书上学到的:取指、译码、执行。那么问题来了,如果没有程序要执行,CPU要怎么办?也许您会说,停掉就是了啊。确实,是要停掉,但何时停、怎么停,却要仔细斟酌,因为实际的软硬件环境是非常复杂的。
对于这个问题可能很多朋友会说是为了高性能,个人觉得这是误解,多线程不等于高性能,从cpu(单核)的角度上看单线程才能带来最高性能。
exit是c语言的库函数,他最终调用_exit。在此之前,先清洗标准输出的缓存,调用用atexit注册的函数等, 在c语言的main函数中调用return就等价于调用exit。
大致意思就是,他看了一个面经,说虚拟内存是 2G 大小,然后他看了我的图解系统 PDF 里说虚拟内存是 4G,然后他就懵逼了。
在 Linux 中,进程是我们非常熟悉的东东了,哪怕是只写过一天代码的人也都用过它。但是你确定它不是你最熟悉的陌生人?我们今天通过深度剖析进程的创建过程,帮助你提高对进程的理解深度。
大家好,我是程栩,一个专注于性能的大厂程序员,分享包括但不限于计算机体系结构、性能优化、云原生的知识。
阅读了kernel的start_kernel代码后,学习了一下kernel_thread的使用
Linux 内核模块在概念和原理层面与动态链接模块(DLL或so)类似。但对于 Linux 来说,内核模块可以在系统运行期间动态扩展系统功能,而无须重新启动系统,更无须重新编译新的系统内核镜像。所以,内核模块这个特性为内核开发者提供了极大的便利,因为对于号称世界上最大软件项目的Linux来说,重启或重新编译的时间耗费肯定是巨大的。
2018 即将结束,年末正是各种基准测试对比轮番出炉的时候,通过这些报告,我们可以看到 Linux 性能的各个方面在 2018 是如何发展的。但本文的这份性能对比会更加深入 —— 将研究五个主流 Linux 发行版在过去近三年里所经历的性能变化,而测试对象则是从 2016 年初开始的 CentOS, Clear Linux, Fedora, Ubuntu 和 openSUSE,到目前为止已安装稳定更新的最新版本。
这种方式调试内核需要两台机器,一台用来运行Linux内核,另一台对内核进行调试。一般有以下三种常用的方案,可以根据电脑的性能或资金状况来选择。可以开两个Linux系统的虚拟机;也可以在物理机系统是linux上面装虚拟机,然后虚拟机运行一个linux;再就是买开发板来调试内核。以下是在windows上开两个虚拟机的流程描述。
在linux系统中, 我们接触最多的莫过于用户空间的任务,像用户线程或用户进程,因为他们太活跃了,也太耀眼了以至于我们感受不到内核线程的存在,但是内核线程却在背后默默地付出着,如内存回收,脏页回写,处理大量的软中断等,如果没有内核线程那么linux世界是那么的可怕!本文力求与完整介绍完内核线程的整个生命周期,如内核线程的创建、调度等等,当然本文还是主要从内存管理和进程调度两个维度来解析,且不会涉及到具体的内核线程如kswapd的实现,最后我们会以一个简单的内核模块来说明如何在驱动代码中来创建使用内核线程。
:wq 强制性写入文件并退出。即使文件没有被修改也强制写入,并更新文件的修改时间。
主流操作系统的线程模型有三种:内核线程模型、用户线程模型、混合线程模型,感兴趣的可以自己查阅相关资料 HotSpot虚拟机使用的是内核线程模型(Kernel-Level Thread, KLT):由操作系统内核(Kernel,下称内核)支持的线程,这种线程由内核来完成线程切换,一个线程对应一个内核线程,注意内核线程也是进程
前言: 在前文《[linux][memory]KSM技术分析》中,分析了KSM技术的基本实现原理。这里再总结一下使用ksm/uksm遇到的几个问题,并附加上作者对性能优化的尝试。 分析: 1,20M
上一篇已经介绍了关于Ubuntu18.04 实时内核的安装,此处介绍Ubuntu16.04的实时内核具体安装情况。
This chapter takes you deeper into the relationships between processes, the kernel, and system resources. There are three basic kinds of hardware resources: CPU, memory, and I/O. Processes vie for these resources, and the kernel’s job is to allocate resources fairly. The kernel itself is also a resource—a software resource that processes use to perform tasks such as creating new processes and communicating with other processes. Many of the tools that you see in this chapter are often thought of as performance-monitoring tools. They’re particularly helpful if your system is slowing to a crawl and you’re trying to figure out why. However, you shouldn’t get too distracted by performance; trying to optimize a system that’s already working correctly is often a waste of time. Instead, concentrate on understanding what the tools actually measure, and you’ll gain great insight into how the kernel works.
所谓实时,就是一个特定任务的执行时间必须是确定的,可预测的,并且在任何情况下都能保证任务的时限(最大执行时间限制)。实时又分软实时和硬实时,所谓软实时,就是对任务执行时限的要求不那么严苛,即使在一些情况下不能满足时限要求,也不会对系统本身产生致命影响,例如,媒体播放系统就是软实时的,它需要系统能够在1秒钟播放24帧,但是即使在一些严重负载的情况下不能在1秒钟内处理24帧,也是可以接受的。所谓硬实时,就是对任务的执行时限的要求非常严格,无论在什么情况下,任务的执行实现必须得到绝对保证,否则将产生灾难性后果,例如,飞行器自动驾驶和导航系统就是硬实时的,它必须要求系统能在限定的时限内完成特定的任务,否则将导致重大事故,如碰撞或爆炸等。
仅测试过debian10.2.0与deepin15.11 笔记本型号为magicbook 2500u 2018款
内核态文件操作 在用户态,我们操作文件可以用C库函数:open()、read()、write()等,但是在内核态没有库函数可用,这时就需要用内核的一些函数:filp_open、filp_close、vfs_read、vfs_write、set_fs、get_fs等函数,
领取专属 10元无门槛券
手把手带您无忧上云