Received: by 10.213.65.68 with SMTP id h4csp996446imn; Tue, 20 Mar 2018 23:09:26 -0700 (PDT) X-Google-Smtp-Source: AG47ELtuHMUJQbqdlVgKhdDN6kkn5WiPxHr65E93CEwJCoUXgB/QI4RDdtr8e0BzfnPSivWRmCIf X-Received: by 2002:a17:902:5204:: with SMTP id z4-v6mr19485467plh.385.1521612566543; Tue, 20 Mar 2018 23:09:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521612566; cv=none; d=google.com; s=arc-20160816; b=YcTvRNwhdGOm+KHM5OOBpIC15f/2g3WodcEQEp+OXrw9rp5A1bXmWThfTjXwQZxfZ9 OccFIoKFLfgylZvMTd5GXCViGiegBifH6wcIBTZbQ/XuU3BQETdV6/GihM22ztHnSmCc BgYy7AJxWGLae/mhJJBioQuNv0lPItVE5ktET/6xCrLeqKM8ghdYN1gHJhMjwS6iALqa 5HiL7bJMpKXzAJsAVKxrNesyW5jTAftaWueQdytX8QxT2sy+QMjrotidFRNsxm2BuRDR Vcmdv3dD9B/CB1FDUnNgHrwhxpi0c4VXPEh8UkwDAmKmjBtzVxYYy5FJ60PamhG/DAeG Xinw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :references:in-reply-to:date:cc:to:from:subject:message-id :arc-authentication-results; bh=za4K3eJyU8fOoHAOZ4yoNqdTuW6lblqM9JuMH2C8s6s=; b=hAeYbf8paRSDqKEeHkYtqXd80IY2+yhqZEV1BdpnF7HCdQY/HYjNrVOa7ui9A1p1YM PBLZMkJUqK5GqGbHlLpiMqRVGEMDOocJsE2mWve/Q24sjrrHs1nApONXXjMy28O6gqVr ZoGXc1J0HkGye+zPIX+2nWYDcCyhkzPHY/tI7ukE7w3NALMbjS3+iN3QdGpIstjSlrp3 vnml2Fe8LbTtZY7bTp/0VId11VFFyz/gDmzeucOeTQNA/w/z3K+7oshiNTfuM6boU0Gx mZ208Xt0p5lneaEJhf2PqbK1ykyrAheFIPXnKeaA53BBTGW9Hl7L3jPminSRkbRqaH3n JRoA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j8si2344922pgt.582.2018.03.20.23.09.12; Tue, 20 Mar 2018 23:09:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751533AbeCUGID (ORCPT + 99 others); Wed, 21 Mar 2018 02:08:03 -0400 Received: from mailgw01.mediatek.com ([210.61.82.183]:47396 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1751317AbeCUGIC (ORCPT ); Wed, 21 Mar 2018 02:08:02 -0400 X-UUID: e14c575aa01c46be98a7a3af3705fd9a-20180321 Received: from mtkcas08.mediatek.inc [(172.21.101.126)] by mailgw01.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 1575236254; Wed, 21 Mar 2018 14:07:58 +0800 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs03n1.mediatek.inc (172.21.101.181) with Microsoft SMTP Server (TLS) id 15.0.1210.3; Wed, 21 Mar 2018 14:07:57 +0800 Received: from [172.21.77.33] (172.21.77.33) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1210.3 via Frontend Transport; Wed, 21 Mar 2018 14:07:57 +0800 Message-ID: <1521612477.12038.4.camel@mtkswgap22> Subject: Re: update vruntime incorrectly When use rt_mutex From: Kathleen Chang To: Peter Zijlstra CC: , , , , , , , Matt Fleming , Date: Wed, 21 Mar 2018 14:07:57 +0800 In-Reply-To: <1521611526.11277.2.camel@mtkswgap22> References: <1521099370.7712.4.camel@mtkswgap22> <20180316095113.GA4064@hirez.programming.kicks-ass.net> <1521611526.11277.2.camel@mtkswgap22> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.2.3-0ubuntu6 Content-Transfer-Encoding: 7bit MIME-Version: 1.0 X-MTK: N Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 2018-03-21 at 13:52 +0800, Kathleen Chang wrote: > > > On Fri, 2018-03-16 at 10:51 +0100, Peter Zijlstra wrote: > > On Thu, Mar 15, 2018 at 03:36:10PM +0800, Kathleen Chang wrote: > > > hi, > > > > > > We found the vruntime might update incorrectly when use rt_mutex. > > > > That's nice, on what kernel? kernel-4.9 > > > > Also, your email is very hard to make sense of. > > > > > <> > > > When the Task is waking, update vruntime incorrectly. > > > 1. When there is a CFS task (A) hold rt_mutex_lock and the state is > > > TASK_WAKING (on_rq=0), a RT task (B) want to hold this rt_mutex_lock. > > > Update vruntime incorrectly. > > > > > > RT task (B) > > > rt_mutex_setprio (cfs->RT) -> Task is waking , and update > > > vruntime > > > > > > queued = task_on_rq_queued(p); // task is waking, queued=0 > > > running = task_current(rq, p); > > > if (queued) /* don't update vruntime here! */ > > > dequeue_task(rq, p, queue_flag); > > > if (running) > > > put_prev_task(rq, p); > > > > > > check_class_changed(rq, p, prev_class, oldprio); -> > > > switched_from_fair -> > > > detach_task_cfs_rq > > > ( due to task is waking, and bypass > > > vruntime-=cfs_rq.min_vruntime) > > > > > > static void detach_task_cfs_rq(struct task_struct *p) > > > { > > > struct sched_entity *se = &p->se; > > > struct cfs_rq *cfs_rq = cfs_rq_of(se); > > > > > > if (!vruntime_normalized(p)) { // return 1, then p->state is > > > TASK_WAKING > > > /* > > > * Fix up our vruntime so that the current sleep doesn't > > > * cause 'unlimited' sleep bonus. > > > */ > > > place_entity(cfs_rq, se, 0); > > > check_vruntime(8, se, cfs_rq->min_vruntime); > > > se->vruntime -= cfs_rq->min_vruntime; > > > > So here we subtract min_vruntime, > When the p->state is TASK_WAKING, vruntime_normlized will return 1 and if(!vruntime_normalized(p)) will be 0 in this case, doesn't subtract min_vruntime. > > > > > > > se->normalized = true; > > > > this doesn't exist.. which makes me wonder what you're looking at, > > > > > } > > > > > > detach_entity_cfs_rq(se); > > > } > > > > > > // when p->state is TASK_WAKING, the task's vruntime is normalized > > > static inline bool vruntime_normalized(struct task_struct *p) > > > { > > > ..... > > > if (!se->sum_exec_runtime || p->state == TASK_WAKING) > > > return true; > > > > > > } > > > > > > 2. When the task (A) which holds the rt_muex_lock unlock the > > > rt_mutex_lock. > > > Task (A) must be on_rq=1 > > > > > > rt_mutex_setprio (RT->CFS) > > > if (queued) > > > enqueue_task(rq, p, queue_flag); ); > > > /* vruntime += cfs_rq.min_vruntime */ > > > > And here we're adding min_vruntime. > > > > > if (running) > > > set_curr_task(rq, p); > > > > > > that result in vruntime accumulates > > > > So what exactly is the problem? > > When the p->state is TASK_WAKING, detach_task_cfs_rq doesn't subtract min_vruntime and adding min_vruntime in enqueue_task, That result in vruntime accumulates to a extreme large number. > >