Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp582574imm; Wed, 20 Jun 2018 03:20:42 -0700 (PDT) X-Google-Smtp-Source: ADUXVKISsz7IIdkvyto4nPtT0MfR2w3FbgubTmaAIADSuF0oIJ3T0NYRx+5SFGpFS/c4u7CROD+R X-Received: by 2002:a62:8f8c:: with SMTP id n134-v6mr22253880pfd.66.1529490042610; Wed, 20 Jun 2018 03:20:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529490042; cv=none; d=google.com; s=arc-20160816; b=ezJIJtmqg4dx8Gqw0aWHPxfsl3OevfJrZSedtFo0aop9SYMg/chX7wBfhfWmrTFxq9 3NDbCxr8pMO41QATjCMJFELGRMqN1qmpVKks5eAVWGD4uCKh82bwQoDKroo6IOGzHriS PYeYYs/p1kPEeI18KV3sYSkdR1YYgr1PWP6NKhSRh8N0uPlAA3S2Q7qYEARfozUCr4cZ mAd2PDMYy1x3/hzWmr+cFP0nYzO3coi358pa0OD+JIzx9ivyE/3PKotdnLJc6DS2GVyc Gnn6gFhcFrxkJ+JmqvMuGBRCHcs21u4YlhoxMK3049C5Jv9zmYb5r0X5ew8XADWOeseS 51yw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=CqB5UqOWTixXaUJwbcnZNEy5+wVjC691ufCQNEiD77U=; b=ZoPguo/AvsUTo7etHaiOC7qQUvyO3x0p6F5GJXCpMw6S46sLEzdQO9hJvwyYFY+/Wk vMCifM8e5sS4RHRNrcED2HOMa8JoNqr4ChZE0g3J7BJugaHasrhtlH1on25dIjNgDVai CeyhCbb3QS3XJIG3Cbfgwev4VwKSPZhhtphQGRbEq0yUH3B1BY+3CIwnm9b8NAxmCv/c wKxmklO4OwALZWcv9ttINt5bP1qkukbIYrMu0jaUNIqnir4DFg7LIOhlgwt6qtqS8gfT 26u4d26bN5oSw2i4C/xtFfXSugi+IddzKhSjK81xBkPKBXbmhT5mrbV/gaWE/tXkjHqk ZvyQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q26-v6si842398pge.270.2018.06.20.03.20.28; Wed, 20 Jun 2018 03:20:42 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754122AbeFTKSo (ORCPT + 99 others); Wed, 20 Jun 2018 06:18:44 -0400 Received: from out30-131.freemail.mail.aliyun.com ([115.124.30.131]:42057 "EHLO out30-131.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752747AbeFTKSn (ORCPT ); Wed, 20 Jun 2018 06:18:43 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R171e4;CH=green;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e07402;MF=xlpang@linux.alibaba.com;NM=1;PH=DS;RN=4;SR=0;TI=SMTPD_---0T32GEb7_1529489915; Received: from localhost(mailfrom:xlpang@linux.alibaba.com fp:SMTPD_---0T32GEb7_1529489915) by smtp.aliyun-inc.com(127.0.0.1); Wed, 20 Jun 2018 18:18:35 +0800 From: Xunlei Pang To: Peter Zijlstra , Ingo Molnar , Ben Segall Cc: linux-kernel@vger.kernel.org Subject: [PATCH v2 2/2] sched/fair: Advance global expiration when period timer is restarted Date: Wed, 20 Jun 2018 18:18:34 +0800 Message-Id: <20180620101834.24455-2-xlpang@linux.alibaba.com> X-Mailer: git-send-email 2.14.1.40.g8e62ba1 In-Reply-To: <20180620101834.24455-1-xlpang@linux.alibaba.com> References: <20180620101834.24455-1-xlpang@linux.alibaba.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When period gets restarted after some idle time, start_cfs_bandwidth() doesn't update the expiration information, expire_cfs_rq_runtime() will see cfs_rq->runtime_expires smaller than rq clock and go to the clock drift logic, wasting needless cpu cycles on the scheduler hot path. Update the global expiration in start_cfs_bandwidth() to avoid frequent expire_cfs_rq_runtime() calls once a new period begins. Signed-off-by: Xunlei Pang --- kernel/sched/fair.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index e6bb68d52962..f167aca066cc 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -5204,13 +5204,18 @@ static void init_cfs_rq_runtime(struct cfs_rq *cfs_rq) void start_cfs_bandwidth(struct cfs_bandwidth *cfs_b) { + u64 overrun; + lockdep_assert_held(&cfs_b->lock); - if (!cfs_b->period_active) { - cfs_b->period_active = 1; - hrtimer_forward_now(&cfs_b->period_timer, cfs_b->period); - hrtimer_start_expires(&cfs_b->period_timer, HRTIMER_MODE_ABS_PINNED); - } + if (cfs_b->period_active) + return; + + cfs_b->period_active = 1; + overrun = hrtimer_forward_now(&cfs_b->period_timer, cfs_b->period); + cfs_b->runtime_expires += (overrun + 1) * ktime_to_ns(cfs_b->period); + cfs_b->expires_seq++; + hrtimer_start_expires(&cfs_b->period_timer, HRTIMER_MODE_ABS_PINNED); } static void destroy_cfs_bandwidth(struct cfs_bandwidth *cfs_b) -- 2.14.1.40.g8e62ba1