Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp65534imm; Tue, 31 Jul 2018 13:57:02 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdaoznSB373ACfU1G+yVF0vU/1iMvFYLcBHTWfIhEPsBRbqgeq54zxvOsnVwuneENLBIn2/ X-Received: by 2002:a62:384:: with SMTP id 126-v6mr23663801pfd.11.1533070622334; Tue, 31 Jul 2018 13:57:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533070622; cv=none; d=google.com; s=arc-20160816; b=CtVPigHuWgoUHGd8bogUl1FrGrU5jiZpo1Hmhy1Gh4sLuxF1lbuP/Mslvo+om17sGO DD5tQ+aLyVjPD+33pnz/zp8Xxx6g7t8VRwNnb9pzCe9g2aXN+HnN6jKwlq9myhoCCBx3 gGoAgajIj3SmQBtitDBnBAt0Cm5Dd/KJGJtk/UJlfGoPI710rS+fMO1I8pPn+p4kO97Q hd2P8uDXyMdFsBKc2lYQxa/i9KWtnlugvfzs3pbrOFBslkTvonTlPjXJB4r73WTZYFb0 VZoGy8Zhse0hEk8V+9k3ESMfFvixHpqr7mfUMD6TxLKLz5kHziaAPPqFVS8W2856B6i5 yukQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature :arc-authentication-results; bh=PZbbiHCCogz+M+rcb6KX4ER9Aw/u8t1micIGGcN/aKQ=; b=sn54uv60vo9NWlqwTtaoWb/gtRniIZMi+hxHd4OzPgpn02a0JdEPWxEPG7cafIgQOX Qnud0Vrn+SUSApvlas2su11WvPpiqdYaKLoncaSPe8i5XBThmh+nG6ucVJWaCzrdHMZW ZGhUjznSSdf+jFvynFuGl8lvv5kPQPbO7Hy7WaEqlmOjiQ4M17IDl82w85HZyArrG/9C 0r1FXrAYWHc2nxY+zTFKltnbo5dzI2ckmyhWpCsGYgB7ELFZCS1WqeSQ6vUfEOxsIB6w +KwM5n4MJ+Be0+Qcc+/zNi5uZlRLBcKLd0+Uf/PuZT7Th0YMMrNmr4fD/NFxw8ALJmM+ dgQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="Cuvrot/9"; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r28-v6si14765591pgk.458.2018.07.31.13.56.42; Tue, 31 Jul 2018 13:57:02 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b="Cuvrot/9"; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729660AbeGaWhq (ORCPT + 99 others); Tue, 31 Jul 2018 18:37:46 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:33060 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726580AbeGaWhq (ORCPT ); Tue, 31 Jul 2018 18:37:46 -0400 Received: by mail-pg1-f193.google.com with SMTP id r5-v6so9672466pgv.0 for ; Tue, 31 Jul 2018 13:55:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=PZbbiHCCogz+M+rcb6KX4ER9Aw/u8t1micIGGcN/aKQ=; b=Cuvrot/9IuzTZpfH0QZeKoCWwvDQYtueZxBkS8rknX+hRa8/W8IfCzFop+CgulvEKm /reQxGbiD8JW+3ja+o+xF4mETDk+CUFxJGItpe0U88mZjO00YgX/23zMBesA5TJBAA71 9NmgG9XxBRTKswINNs+jF17jhVtyy9HRY62OL2EBDU5LIVQsplbqfGWUlwRpbUovgAUf csGhwxoBDP3lExnyzhzzVhUcjTt86ll3V5MwEeE+t2SdCdZB+ig5AHC2LWf/SQ152mRf fcwwXhr9eydM3IDux48xRUfSSCcglVUyMJd8++K1Fv7EkEwluFRymNQmZ2ksafOF7d+I X2sA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=PZbbiHCCogz+M+rcb6KX4ER9Aw/u8t1micIGGcN/aKQ=; b=Kf6MR8skDXSFBdT4rghYsjR3N+F4MzEHMbjNEMI41sqH353OxAgYFnDRZs2RejEi+n Sw4guZUtjlCtxBPE4gzigLMfJCbIEhVTBL6zX/ThAstYKB49H9xoJ3pwhtPaxZjWznMP WSsrKYusGTMdsZArWx4h/BLghSf36/sqxM+9lQKdmy41QIBMcjshOLuJC05BcMxym+83 4LhmtlcoZ/ffRSEYXH8cAbM/bPCEOCeCG2hYAixRrM6DdAKmAHHGcV2wboA8MEil9rSX tJSKQq5OFoUD56VWKKSPybIV2dYppCB6C/yDSokla4ERI8QgeO7D/Ji2RHzzoI1mb6St e4Hg== X-Gm-Message-State: AOUpUlEFn/yFo+8JRexJ2a5Zdt04drXQVamm7TMLvUvQaqnVMDVxooWo O86RnXdLZGVCawkXBkJ54NFpo/xetjzh710Rtz4= X-Received: by 2002:a62:9683:: with SMTP id s3-v6mr23834364pfk.191.1533070535605; Tue, 31 Jul 2018 13:55:35 -0700 (PDT) MIME-Version: 1.0 References: <20180728002409.5781-1-xiyou.wangcong@gmail.com> In-Reply-To: From: Cong Wang Date: Tue, 31 Jul 2018 13:55:23 -0700 Message-ID: Subject: Re: [PATCH] sched/fair: sync expires_seq in distribute_cfs_runtime() To: Ben Segall Cc: Xunlei Pang , LKML , Linus Torvalds , Peter Zijlstra , Thomas Gleixner Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 31, 2018 at 10:13 AM wrote: > > Xunlei Pang writes: > > > On 7/31/18 1:55 AM, Cong Wang wrote: > >> On Sun, Jul 29, 2018 at 10:29 PM Xunlei Pang wrote: > >>> > >>> Hi Cong, > >>> > >>> On 7/28/18 8:24 AM, Cong Wang wrote: > >>>> Each time we sync cfs_rq->runtime_expires with cfs_b->runtime_expires, > >>>> we should sync its ->expires_seq too. However it is missing > >>>> for distribute_cfs_runtime(), especially the slack timer call path. > >>> > >>> I don't think it's a problem, as expires_seq will get synced in > >>> assign_cfs_rq_runtime(). > >> > >> Sure, but there is a small window during which they are not synced. > >> Why do you want to wait until the next assign_cfs_rq_runtime() when > >> you already know runtime_expires is synced? > >> > >> Also, expire_cfs_rq_runtime() is called before assign_cfs_rq_runtime() > >> inside __account_cfs_rq_runtime(), which means the check of > >> cfs_rq->expires_seq is not accurate for unthrottling case if the clock > >> drift happens soon enough? > >> > > > > expire_cfs_rq_runtime(): > > if (cfs_rq->expires_seq == cfs_b->expires_seq) { > > /* extend local deadline, drift is bounded above by 2 ticks */ > > cfs_rq->runtime_expires += TICK_NSEC; > > } else { > > /* global deadline is ahead, expiration has passed */ > > cfs_rq->runtime_remaining = 0; > > } > > > > So if clock drift happens soon, then expires_seq decides the correct > > thing we should do: if cfs_b->expires_seq advanced, then clear the stale > > cfs_rq->runtime_remaining from the slack timer of the past period, then > > assign_cfs_rq_runtime() will refresh them afterwards, otherwise it is a > > real clock drift. I am still not getting where the race is? But expires_seq is supposed to be the same here, after distribute_cfs_runtime(), therefore runtime_remaining is not supposed to be cleared. Which part do I misunderstand? expires_seq should not be same here? Or you are saying a wrongly clear of runtime_remaning is fine? > > Nothing /important/ goes wrong because distribute_cfs_runtime only fills > runtime_remaining up to 1, not a real amount. No, runtime_remaining is updated right before expire_cfs_rq_runtime(): static void __account_cfs_rq_runtime(struct cfs_rq *cfs_rq, u64 delta_exec) { /* dock delta_exec before expiring quota (as it could span periods) */ cfs_rq->runtime_remaining -= delta_exec; expire_cfs_rq_runtime(cfs_rq); so almost certainly it can't be 1. Which means the following check could be passed: 4655 if (cfs_rq->runtime_remaining < 0) 4656 return; therefore we are reaching the clock drift logic code inside expire_cfs_rq_runtime() where expires_seq is supposed to be same as they should be sync'ed. Therefore without patch, we wrongly clear the runtime_remainng? Thanks.