![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
linux内核
文章平均质量分 69
money_yuan
多多学习,努力赚钱,给家人一个好的生活
展开
-
【内核调度、调度组】【bandwidth throttle】
cfs bandwidth是针对task_group的配置,一个task_group的bandwidth使用一个struct cfs_bandwidth *cfs_b数据结构来控制struct cfs_bandwidthstruct cfs_bandwidth {#ifdef CONFIG_CFS_BANDWIDTH raw_spinlock_t lock; /*cfs bandwidth的监控周期,默认值是default_cfs_period() 0.1s */ ktime_.转载 2020-07-22 11:03:48 · 899 阅读 · 0 评论 -
【内核调度、EAS】【cpu boost和task boost的区别和联系】
cpu boostunsigned longboosted_cpu_util(int cpu, unsigned long util){ long margin; margin = schedtune_cpu_margin(util, cpu); trace_sched_boost_cpu(cpu, util, margin); return util + margin;}task的boost=util+marginstatic inline intschedtune_转载 2020-07-22 10:54:38 · 1888 阅读 · 0 评论 -
【内核调度、调度组】【struct sched_group】
struct sched_groupstruct sched_group { struct sched_group *next; /* Must be a circular list */ atomic_t ref; unsigned int group_weight; struct sched_group_capacity *sgc; int asym_prefer_cpu; /* cpu of highest priority in group */ const struct sc原创 2020-07-21 17:08:52 · 427 阅读 · 0 评论 -
【内核调度、负载均衡】【find_energy_efficient_cpu】
get_eenv/* * get_eenv - reset the eenv struct cached for this CPU * * When the eenv is returned, it is configured to do * energy calculations for the maximum number of CPUs * the task can be placed on. The prev_cpu entry is * filled in here. Calle原创 2020-07-21 14:33:45 · 2052 阅读 · 0 评论 -
【内核调度】【休眠进程的唤醒】【wake_up_process】
wake_up_process一般当队列里面为空的时候,核心调度器(是否是核心调度器还需要后续去confirm)会在已经睡眠的task中通过调用wake_up_process函数将其唤醒,然后选择合适的cpu来运行/** * wake_up_process - Wake up a specific process * @p: The process to be woken up. * * Attempt to wake up the nominated process and move i原创 2020-07-21 13:35:12 · 3905 阅读 · 0 评论 -
【负载均衡、负载计算】【propagate_entity_load_avg】
对于组调度而言,需要传播负载的变化到整个cfs列表里面。propagate_entity_load_avg就负责传播组调度负载的变化propagate_entity_load_avg/* Update task and its cfs_rq load average */static inline int propagate_entity_load_avg(struct sched_entity *se){ struct cfs_rq *cfs_rq; //只有group下面才有cfs_r原创 2020-07-21 10:20:33 · 608 阅读 · 1 评论 -
【内核调度、负载均衡】【entity_tick】
在scheduler_tick函数中会调用task_tick函数,具体到fair class,他的入口函数为task_tick_fair/* * scheduler tick hitting a task of our scheduling class: */ /* 获取到当前进程curr所在的调度实体 */static void task_tick_fair(struct rq *rq, struct task_struct *curr, int queued){ struct原创 2020-07-20 16:18:53 · 445 阅读 · 0 评论 -
【内核调度、负载计算】【WALT】【walt_update_task_ravg】
walt_update_task_ravg/* Reflect task activity on its demand and cpu's busy time statistics */void walt_update_task_ravg(struct task_struct *p, struct rq *rq, int event, u64 wallclock, u64 irqtime){ u64 old_window_start; if (walt_disabled || !原创 2020-07-20 11:27:50 · 1399 阅读 · 1 评论 -
【内核调度、负载计算】【calc_global_load_tick】
calc_global_load_tick是计算整个系统的负载,这个函数在scheduler_tick中被周期性的调用calc_global_load_tick/* * Called from scheduler_tick() to periodically update this CPU's * active count. */void calc_global_load_tick(struct rq *this_rq){ long delta; if (time_before(j原创 2020-07-20 13:53:30 · 608 阅读 · 0 评论 -
【内核调度、hotplug进程迁移】【migrate_tasks】
在cpu_down()时,需要调用migration_call() -> migrate_tasks()把cpu上所有runnable进程迁移到其他cpu;在cpu_up()时,并不需要在函数中迁移进程,直接等待负载均衡算法的迁移。migrate_tasks需要注意的是被迁移的task的dst cpu很有可能都是不一样的。/* * Migrate all tasks from the rq, sleeping tasks will be migrated by * try_to_wa原创 2020-07-16 17:45:32 · 1172 阅读 · 0 评论 -
【内核调度、负载均衡】【select_task_rq_fair】
在新建一个task或者block的task被唤醒的时候,也会执行负载均衡,调用的函数是select_task_rq_fair和内核周期性调度相似(寻找最忙的cpu上的任务,然后把该任务pull过来执行。或者从最忙的cpu上将当时正在执行的任务停掉,然后放到local cpu上去执行)。只是他寻找的是最idlest的cpu来运行taskselect_task_rq_fair/* * select_task_rq_fair: Select target runqueue for the waki原创 2020-07-16 17:26:48 · 1504 阅读 · 0 评论 -
【内核调度、负载均衡】【scheduler_tick】
scheduler_tick系统的软中断触发会周期性的调度scheduler_tick函数/* * This function gets called by the timer code, with HZ frequency. * We call it with interrupts disabled. */void scheduler_tick(void){ int cpu = smp_processor_id(); struct rq *rq = cpu_rq(cpu); st原创 2020-07-16 16:03:50 · 876 阅读 · 0 评论 -
【内核调度、负载计算】【cpu_load_update_active】
之前看了entity_load和cfs_rq的负载的计算,他们的核心code都是一样的,至于具体差别后面有时间再去看,现在来看看cpu级别的负载的计算cpu_load_update_activecpu级别的负载的计算主要是涉及到一个数组/* * Called from scheduler_tick() */void cpu_load_update_active(struct rq *this_rq){ unsigned long load = weighted_cpuload(thi原创 2020-07-16 15:23:57 · 749 阅读 · 0 评论 -
【内核调度、负载计算】【update_load_avg】
___update_load_avg之前版本的kernel没有accumulate_sum函数,而是直接将这部分放在本函数内执行。accumulate_sum详见https://blog.csdn.net/feifei_csdn/article/details/103814876主要是对time进行衰减/* * We can represent the historical contribution to runnable average as the * coefficients o原创 2020-07-16 13:55:37 · 1207 阅读 · 0 评论 -
【内核调度、负载计算】【update_curr】
1、update_currUpdate the current task's runtime statistics./* * Update the current task's runtime statistics. */static void update_curr(struct cfs_rq *cfs_rq){ struct sched_entity *curr = cfs_rq->curr; u64 now = rq_clock_task(rq_of(cfs_rq));原创 2020-07-08 11:20:43 · 1326 阅读 · 0 评论 -
【内核调度、负载均衡】【update_sd_lb_stats】
get_sd_load_idx这里面涉及到了一个unsigned long cpu_load[CPU_LOAD_IDX_MAX];数组。scheduler会更具不同的load balance类型(busy,newly idle,idle)选择不同的load进行计算,主要是在update_sg_lb_stats时进行计算/** * get_sd_load_idx - Obtain the load index for a given sched domain. * @sd: The sched_原创 2020-07-13 15:09:22 · 807 阅读 · 0 评论 -
【内核调度、负载均衡】【update_group_capacity】
MC层级的group_capacity的更新这里需要区分是MC层级还是DIE。他们的区别是sd->child是否为NULL。MC层级为NULL具体可以看update_cpu_capacity这个函数void update_group_capacity(struct sched_domain *sd, int cpu){ struct sched_domain *child = sd->child; struct sched_group *group, *sdg = sd-&g原创 2020-07-13 16:09:18 · 1006 阅读 · 0 评论 -
【内核调度、负载均衡】【calculate_imbalance】
calculate_imbalance函数对于该版本的kernel在网上没有找到相同的code,所以这里只是通过他的注释来确认。calculate_imbalance/** * calculate_imbalance - Calculate the amount of imbalance present(当下的) within the * groups of a given sched_domain during load balance. * @env: load balance e原创 2020-07-15 09:51:52 · 497 阅读 · 0 评论 -
【内核调度、负载均衡】【find_busiest_queue】
在最繁忙的group中去寻找最繁忙的cpufind_busiest_queue/* * find_busiest_queue - find the busiest runqueue among the cpus in group. */ //冒泡排序找到group内最忙的rqstatic struct rq *find_busiest_queue(struct lb_env *env, struct sched_group *group){ struct rq *bu原创 2020-07-15 10:33:41 · 343 阅读 · 0 评论 -
【内核调度、负载均衡】【load_balance】
pull taskpull task 是当前的cpu将busiest cpu上的task拉到自己身上来执行。/* * Check this_cpu to ensure it is balanced within domain. Attempt to move * tasks if there is an imbalance. */ // 找出负载最重的cpu,将busiest cpu上的部分task迁移到local cpu上。 // 返回的是迁移的task的数量static int l原创 2020-07-15 15:31:34 · 1198 阅读 · 0 评论 -
【内核调度、负载均衡】【detach_tasks】
detach_tasks在load balance中会将busiest cpu上的task detach掉,然后atach在local cpu上。返回值为detach的task的数量/* * detach_tasks() -- tries to detach up to imbalance weighted load from * busiest_rq, as part of a balancing operation(操作) within domain "sd". * * Returns原创 2020-07-15 16:42:56 · 857 阅读 · 0 评论 -
内核调度【一】【set_load_weight】
基于androidq的code来看内核调度1、nice值/** Nice levels are multiplicative, with a gentle 10% change for every* nice level changed. I.e. when a CPU-bound task goes from nice 0 to* nice 1, it will get ~1...原创 2020-07-06 10:18:49 · 390 阅读 · 1 评论 -
【输入子系统】【kernel层】
Kernel层Kernel层又分为三层,他们分别是事件处理层、输入核心层和设备驱动层,事件处理层主要负责和上层进行交互、输入核心层实现承上启下的作用给事件处理层和设备驱动层提供公共的接口。设备驱动层负责和底层输入设备打交道,获取来自输入设备的信息。1.1设备驱动1.1.1数据上报 Func remark Tpd_down(...翻译 2018-10-19 13:51:25 · 794 阅读 · 0 评论 -
i2c协议解析
i2c总线上有两根线,一根是数据线SDA,一根是时钟线SCL在空闲的时候,他们都是高电平I2C传输数据快速且简便,速率最高可以达到3.4M/si2C速率分为S(标准, 100kb/s)、F(快速, 400kb/s)和H(高速, 3.4Mb/s)模式。基本结构如下图所示: 1、I2c一个时钟周期里面传输一个位,从高位到低位,一般8位为一个数据起始的时候:SDA由...转载 2018-10-22 10:36:55 · 345 阅读 · 0 评论 -
ARM体系结构与编程模型总结
感觉这篇文章写得很好:https://blog.csdn.net/qq_32651225/article/details/78176567 ARM体系结构与编程模型ARM体系结构一、ARM处理器简介及RISC特点ARM处理器简介ARM(Advanced RISC Machines)是一个32位RISC(精简指令集)处理器架构,ARM处理器则是ARM架构下的微处理器。ARM处...转载 2018-10-29 20:58:05 · 171 阅读 · 0 评论 -
ARM体系架构
这个适合来做科普一:什么是嵌入式: 嵌入式是为了完成某个特定功能,在软件和硬件上进行了裁剪,低成本,低功耗(电源管理模块,软件判断硬件是否使用),便携式(封装),实时性(中断)比较强,代码可固化(一般固化到Flash(rom)中),计算机系统。二:什么是ARM: 1:是一个公司的名称 2:一种微处理器的架构 3:一种技术三:ARM芯片的特性: 1:...转载 2018-10-29 21:11:14 · 597 阅读 · 0 评论 -
【CPUMask】内核相关函数
Function Name:zalloc_cpumask_var_nodeFunction:static inline bool zalloc_cpumask_var_node(cpumask_var_t *mask, gfp_t flags, int node)Return Type:static inline boolParameter:TypeParameter NameRemarkscpu...转载 2018-06-26 18:56:15 · 806 阅读 · 0 评论 -
【sheduling domain】初始化
shedu domain内核定义的结构体如下:sd\sg\sgc 初始化的时候所有的cpu都在一个sceduling domain上面,那后面是需要将这个不同的cpu分配到不同的domain上去了。然后开始build schedule domain这个是MTK的一个芯片,但是大致可以看出DIE和MC的层级结构build domian主要就是填充sg、sd还有sgc这些...转载 2018-08-08 16:25:57 · 500 阅读 · 0 评论 -
【面试】【android驱动开发】
1、字符设备和块设备的区别字符设备是以字节为单位进行数据读写,只支持顺序读写,不支持随机读写。块设备是以块为单位进行数据读写,支持随机读写。还有他们的结构体、接口和注册方式都有所不同。具体详见:https://blog.csdn.net/bonnshore/article/details/7860997 2、内核空间和用户空间的区别、他们的通信方式有哪些?2.1区别...转载 2018-08-08 13:31:25 · 3092 阅读 · 0 评论 -
【ARM64】【cpu_topology】
static int __init parse_dt_topology(void){ struct device_node *cn, *map; int ret = 0; int cpu; /* (1) 找到dts中cpu topology的根节点"/cpus"" */ cn = of_find_node_by_path("/cpus"); i...转载 2018-08-07 15:56:58 · 803 阅读 · 0 评论 -
【sys/power】freeze、standby、mem、disk四个电源状态
System Power Management Sleep States(C) 2014 Intel Corp., Rafael J. Wysocki <rafael.j.wysocki@intel.com>The kernel supports up to four system sleep states generically(一般), although threeof ...转载 2018-06-27 16:56:24 · 13261 阅读 · 0 评论 -
【ERROR】内核定义标准错误输出
Errors: Linux System ErrorsWhen system requests fail, error code are returned. To understand the nature of the error these codes need to be interpreted. They are recorded in:- /usr/include/asm/errno....翻译 2018-06-20 16:04:19 · 225 阅读 · 0 评论 -
【init函数】内核init的顺序
转载:https://blog.csdn.net/cstk502/article/details/6579231在init.h 中有如下定义 #define pure_initcall(fn) __define_initcall("0",fn,1)#define core_initcall(fn) __define_initcall("1",fn,1)#define core_initcall...转载 2018-06-20 15:51:27 · 238 阅读 · 0 评论 -
【每CPU变量】
在接触dvfs驱动的时候时长涉及这一概念:最显著的是在网络子系统中,将计数器放到每CPU-变量中,更新计数器的时候无须上锁和处理缓存。转载 2018-07-02 10:56:56 · 186 阅读 · 0 评论 -
【owner=THIS MODULE】内核当前模块
转自:https://blog.csdn.net/a954423389/article/details/6101369结 构体struct module在内核中代表一个内核模块,通过insmod(实际执行init_module系统调用)把自己编写的内核模块插入内核时,模块便与一个 struct module结构体相关联,并成为内核的一部分。下面是结构体struct module的完整定义,接下来会...转载 2018-07-02 10:34:30 · 1083 阅读 · 0 评论 -
【module_platform_driver】宏解析
转自:https://blog.csdn.net/richu123/article/details/51331081该函数实际是一个宏,它在include/linux/platform_device.h中定义如下:[cpp] view plain copy /* module_platform_driver() - Helper macro for drivers that don't do *...转载 2018-07-02 10:25:34 · 362 阅读 · 0 评论 -
【同步机制】【自旋锁】【信号量】
1、读写自旋锁rwlock读写自旋锁(rwlock)是一种比自旋锁粒度更小的自旋锁机制,它保留了“自旋”的概念。但是在写操作方面,只能最多有一个写进程,在读方面,同时可拥有多个执行单元,当然读和写也不能同时进行。一句话:防写不防读write_lock_irqsave(lock,flags);//写者获取读写锁,同时保存中断标志,并禁止本地中断write_unlock_irqstore(lock,f...转载 2018-06-26 19:46:28 · 197 阅读 · 0 评论 -
【cpu数量】for_each_possible_cpu()/for_each_present_cpu()/for_each_online_cpu()区别
转自:https://blog.csdn.net/guowenyan001/article/details/44224759一、介绍假设一太机器上有8个CPU:1.1 cpu_possible_map 机器上最多有多少个CPU,包括本机的CPU,以及可以热插拔的CPU。 1. 假设cpu_possible_map为10,本机CPU个数为8个,则最多可以再添加2个可插拔C...转载 2018-06-26 18:31:29 · 1600 阅读 · 0 评论 -
【proc/interrupts】内核中断
首先是内核中断的分类,这里只是根据proc/interrupts下显示的中断进行分类,主要包含外部中断和IPI中断cat proc/interrupts CPU0 CPU1 CPU2 CPU3 CPU4 CPU5 CPU6 CPU7 1: 107049 104452 ...原创 2018-06-25 19:45:30 · 7020 阅读 · 0 评论 -
【kmalloc】分配内核内存
一、内存分区二、kmalloc:在用户空间,我们使用一个面向堆的内存分配函数malloc来分配连续的堆空间,在内核中对应使用kmalloc1、分配的空间连续 2、分配的内存里面保存了原有的数据 #include <linux/slab.h> void *kmalloc(size_t size, int flags); flag:GFP_ATOMIC用来从中断处理和进程上下文之外...转载 2018-06-21 10:41:40 · 390 阅读 · 0 评论