【内核调度、负载均衡】【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 number of detached tasks if successful and 0 otherwise.
 */
 // 返回值为detach的task的数量
static int detach_tasks(struct lb_env *env, struct rq_flags *rf)
{
	//src_rq是busiest的rq
	struct list_head *tasks = &env->src_rq->cfs_tasks;
	struct task_struct *p;
	unsigned long load;
	int detached = 0;

	lockdep_assert_held(&env->src_rq->lock);

	if (env->imbalance <= 0)
		return 0;
	/* (7.6.1) 遍历busiest rq中的进程 */
	while (!list_empty(tasks)) {
		/*
		 * We don't want to steal all, otherwise we may be treated likewise,
		 * which could at worst lead to a livelock crash.
		 */
		 /* (7.6.2) 如果dest cpu不是idle,不能将busiest cpu迁移到idle状态 */  
		if (env->idle != CPU_NOT_IDLE && env->src_rq->nr_running <= 1)
			break;

		p = list_first_entry(tasks, struct task_struct, se.group_node);

		env->loop++;
		/* We've more or less seen every task there is, call it quits */
		/* (7.6.3) 遍历任务最多不超过sysctl_sched_nr_migrate(32) */
		if (env->loop > env->loop_max)
			break;

		/* take a breather every nr_migrate tasks */
		/* (7.6.4) 每sched_nr_migrate_break个任务遍历需要跳出休息一下,
         如果没有达到env->loop_max,后面会重来*/
		if (env->loop > env->loop_break) {
			env->loop_break += sched_nr_migrate_break;
			env->flags |= LBF_NEED_BREAK;
			break;
		}
		/* (7.6.5) 判断任务是否支持迁移? */
		if (!can_migrate_task(p, env))
			goto next;
		/* (7.6.6) 获取p进程相对顶层cfs_rq的负载, 
					根据负载判断进程是否适合迁移*/
		load = task_h_load(p);
		// LB_MIN 定义的是false
		if (sched_feat(LB_MIN) && load < 16 && !env->sd->nr_balance_failed)
			goto next;

		if ((load / 2) > env->imbalance)
			goto next;
		// 把task加到env的list里面
		detach_task(p, env, rf);
		list_add(&p->se.group_node, &env->tasks);

		detached++;
		env->imbalance -= load;

#ifdef CONFIG_PREEMPT
		/*
		 * NEWIDLE balancing is a sourc
-exception_panic_reason:Oops - Undefined instruction: Fatal exception -exception_file_infoi:not-bugon -exception_task_id:18051 -exception_task_family:[ptz-bgd-1-IMAGE, 18051][main, 585] -exception_pc_symbol:[<ffffffc0082310f4>] propagate_entity_load_avg+0xf8/0x35c -exception_stack_info:[<ffffffc001806994>] get_exception_stack_info+0x150/0x2d8 [sysdump] [<ffffffc0018067ec>] prepare_exception_info+0x16c/0x1c4 [sysdump] [<ffffffc0018099c4>] sysdump_panic_event+0x76c/0x8ec [sysdump] [<ffffffc0082044fc>] atomic_notifier_call_chain+0x8c/0x138 [<ffffffc0081b4d64>] panic+0x1b8/0x44c [<ffffffc0081137bc>] die+0x5a0/0x67c [<ffffffc008114748>] do_el1_undef+0x68/0x98 [<ffffffc00977cd60>] el1_undef+0x34/0x54 [<ffffffc00977cc04>] el1h_64_sync_handler+0x54/0xb4 [<ffffffc008091310>] el1h_64_sync+0x7c/0x80 [<ffffffc0082310f4>] propagate_entity_load_avg+0xf8/0x35c [<ffffffc008230da4>] update_load_avg+0x1b4/0x40c [<ffffffc008231b74>] propagate_entity_cfs_rq+0x88/0x1f4 [<ffffffc0082341f8>] detach_entity_cfs_rq+0x84/0xb4 [<ffffffc0082331d4>] migrate_task_rq_fair+0x64/0x1c0 [<ffffffc0082182d8>] set_task_cpu+0xd8/0x2ac [<ffffffc0018d6c20>] lb_pull_tasks+0x1b8/0x278 [unisoc_sched] [<ffffffc0018d3028>] android_rvh_sched_newidle_balance+0x298/0x344 [unisoc_sched] [<ffffffc008238b48>] newidle_balance+0x88/0x79c [<ffffffc00823d21c>] pick_next_task_fair+0x5c/0x3dc [<ffffffc0091ef33c>] binder_wait_for_work+0x178/0x48c [<ffffffc0091ec080>] binder_thread_read+0x270/0x2bc4 [<ffffffc0091e7e98>] binder_ioctl_write_read+0x120/0x588 [<ffffffc0091e2bbc>] binder_ioctl+0x1c4/0xfd8 [<ffffffc0085eff20>] __arm64_sys_ioctl+0x184/0x20c [<ffffffc00811fb68>] invoke_syscall+0x60/0x150 [<ffffffc00811fa9c>] el0_svc_common+0x8c/0xf8 [<ffffffc00811f9a0>] do_el0_svc+0x28/0x98 [<ffffffc00977d248>] el0_svc+0x24/0x84 [<ffffffc00977d1c0>] el0t_64_sync_handler+0x88/0xec [<ffffffc00809164c>] el0t_64_sync+0x1b8/0x1bc
最新发布
06-20
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值