Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp809924imm; Fri, 3 Aug 2018 11:59:24 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeGXZ5C8nZtdZUxvZX+AhOEfpS4ZMqIpDCh+7dHFDsHMTqY1ZwYwkRggI4cY9JPAEjUbtJD X-Received: by 2002:a62:4ece:: with SMTP id c197-v6mr5912335pfb.240.1533322764434; Fri, 03 Aug 2018 11:59:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533322764; cv=none; d=google.com; s=arc-20160816; b=QDgPuFS+Y1HpvbvxNu1hxFuENjywrmOJDGXp/F/p3/3T84PKZ5YeYvulVv3z9QsIAv mfZHmULbZJqzqv3sGEOZlAvVkDXs625VYCvRnrwArIVECpttssCfYUDV4ruap52LvMw3 q1n4BzbbbGz8saka7QLpzglb/ZpWtHlk9DOBkbcyIL67TOQAFOV5lAP/2cl5E21toXCr 5gPdJwCQYBSGJ5bQevCF+sdxO2oCC8uLkx3mkKzaY35/isuxfoQLI3yz26KK5jYlooiu 1qJoljiSAGzs5K203MKYIIrV0A3SYMMZjXtpZUXFeBYmueJUjIZPd0YKlcmc1NclOL8O kyWA== 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=rj40mg9Xb51R1c2uuHTuNoY8IlKKEY01gojzJ1OKAL0=; b=P40jfGG+LuMxQo/wrpHexKTaGmKyUo0N3GPRUquxWHaBID1KQwTJPBgrdg9DoewcWX KmGKk0PfGD+WRjXULZ5gprUApAL22fpr9QXkVbMwFZCZGGl8JqywZWuUUMS9vXHX7Elb lqdpcbui+NoxqwA9nwg3UIwjDGheOFyXat/SJLe7EbU6FPkqm1s6h6jOAyxrRpDpxEV8 RbYZVM/gLn3AKGU2NM9W6nTFRo6BeMvKfdoXwwy/1C/GsTDPK5IS7nN5O3lCQVpVqtBg yd6jTFoyMe6nHUmwm/pSFAY7h4zASejqyzWvChKc5r5dfs6cmMPSj0qeSnYhR9ZHJ6N/ b33A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ut7Lvj5f; 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 6-v6si5739503pfk.287.2018.08.03.11.59.10; Fri, 03 Aug 2018 11:59:24 -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=ut7Lvj5f; 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 S1731991AbeHCUzQ (ORCPT + 99 others); Fri, 3 Aug 2018 16:55:16 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:35165 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727953AbeHCUzP (ORCPT ); Fri, 3 Aug 2018 16:55:15 -0400 Received: by mail-pg1-f194.google.com with SMTP id e6-v6so3257369pgv.2 for ; Fri, 03 Aug 2018 11:57:44 -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=rj40mg9Xb51R1c2uuHTuNoY8IlKKEY01gojzJ1OKAL0=; b=ut7Lvj5flrqTKo5kvp9V8cPepJcnzyIlVbNGEE+/+I+Y3GJKssZxezNPbnHXcpY1vE 1FVeDUKMwFjlXc+It5U6g38dXrcYSwG89sIV0vM10Psd1bYQuUZpTqmP3WQPKpxpowzr qfAY1wyg4uNWwzEpGDMnkbxil2tTbVS7kOa1SqPIN2bbeUU9WY0MHiSdGcSzlGSmCkUj DNQiemln766XEeAstfQbJIiVrC3RNdM+MatxGWF4TpyLPhi5xocb6bCTkqpqVbHTyhmJ 0cUPImzl7A0oSwSfeppT4wm8Bdpr88IG0a3kEAvUgvIksTqHddgcNDG2tBZB2eN1fQsY OZ9Q== 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=rj40mg9Xb51R1c2uuHTuNoY8IlKKEY01gojzJ1OKAL0=; b=HvWFWNon+SILAc2ADBNz+N1H/Jo8vWgDSQj89H6VKfZgCvO/rAiR3zxzkmo2pXmXg/ pUMRh206pXGkIn6hJ+4FkY0TJ3Idt4PFRPviZj45w8Y6Q8kyOQeVYpi0i4BPN/OvnKQ/ AR2IQMM324q70ZByqsMP51b3UENukZjEA+cuS8JKLWAvIJ/JcWpfHK19/vQLJzRR0JQ/ IJ1622WJbtjFznP1v3/ke0d1e/wV5ZNq5NNoSffJohSJ3RyNckePFgkF2K/DnSfApAzX YBrzctUS8S8SU5gEKkovbFBw7kp4c1krCud8YjLuZbqOPuCWq16/6Aet/3ZE1yjKMxPI 5+0Q== X-Gm-Message-State: AOUpUlEu3SQMzdZTTYKckoNKjHd+XrAg9NIwso+R0bb6TpxjlS2UK2fI SAXVysQ7mRlmG4r5GnpKpUzzI91/JzQy+2a2/yE= X-Received: by 2002:a62:3545:: with SMTP id c66-v6mr5837945pfa.63.1533322663970; Fri, 03 Aug 2018 11:57:43 -0700 (PDT) MIME-Version: 1.0 References: <20180728002409.5781-1-xiyou.wangcong@gmail.com> <0939a9c3-e9c0-ae8a-3f56-0dde1ab2fc8e@linux.alibaba.com> In-Reply-To: <0939a9c3-e9c0-ae8a-3f56-0dde1ab2fc8e@linux.alibaba.com> From: Cong Wang Date: Fri, 3 Aug 2018 11:57:31 -0700 Message-ID: Subject: Re: [PATCH] sched/fair: sync expires_seq in distribute_cfs_runtime() To: Xunlei Pang Cc: Ben Segall , 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 8:24 PM Xunlei Pang wrote: > > Let's see the unthrottle cases. > 1. for the periodic timer > distribute_cfs_runtime updates the throttled cfs_rq->runtime_expires to > be a new value, so expire_cfs_rq_runtime does nothing because of: > rq_clock(rq_of(cfs_rq)) - cfs_rq->runtime_expires < 0 > > Afterwards assign_cfs_rq_runtime() will sync its expires_seq. Is there any guarantee rq_clock(cfs_rq) is always ahead of cfs_rq->runtime_expires in this case? I doubt, because cfs_rq->runtime_expires could be assigned by a sched_clock() on a different CPU running the periodic timer. Also, rq_clock() is behind sched_clock() on the same CPU too, sometimes it is merely hundreds of nanoseconds, sometimes it is tens of thousands nanoseconds in my environment. (I have a different patch to address this, but still not sure if it is correct.) > > 2. for the slack timer > the two expires_seq should be the same, so if clock drift happens soon, > expire_cfs_rq_runtime regards it as true clock drift: > cfs_rq->runtime_expires += TICK_NSEC > If it happens that global expires_seq advances, it also doesn't matter, > expire_cfs_rq_runtime will clear the stale expire_cfs_rq_runtime as > expected. Hmm, looks like due to the runtime_refresh_within() check in slack timer. > > > > >> > >> 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. > > I think Ben means it firstly gets a distributtion of 1 to run after > unthrottling, soon it will have a negative runtime_remaining, and go > to assign_cfs_rq_runtime(). That is obvious, being 1 in distribute_cfs_runtime is not relevant to the discussion here.