Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2334137imm; Fri, 7 Sep 2018 14:52:27 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbNqFWZ3qLsejYimRK92CceMYztPgOXe2nYdSTYung+qqNTtI1tF+TlSsy4pXsEv1/z3Jbz X-Received: by 2002:a17:902:163:: with SMTP id 90-v6mr10054663plb.322.1536357147903; Fri, 07 Sep 2018 14:52:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536357147; cv=none; d=google.com; s=arc-20160816; b=zwp3UFOqTz+97mlI9jKt/TT2p43ys+1EY6WEY1/9ZIIxpGhf2lz2OhJZvcG1KuJFz0 Q6nJKjG2PeJnVJDnlDfk8oOWOHcg4zEANYBjWWrRTRCRLA+bRKnPgzftvUtJ2qIVqS0G noG+JAjh7d/II9WFtQIyuuMuLY/lxruCK9iO1W9jdgL87WZudET6RMpFOfvyu+qVCHX/ ozKXDTADP3P+14EnFC7AIZ9i2fIZg0fWFSWvLcNYsYRcVVZYDg2arnVL5vrgz3+EEdO6 OmG0aVqLTNtvkuFMMGIoeV4y4cyio4eq2jHqXjQkfUua5d4vd8KHTnpHMDZTPqOuUTDq 18sg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=eGc+7tfgjNsz8T/8mN4E1fpzKHW2V/dwOJvC2L85sqk=; b=b5RjjxLIJaZR6ENGKnJMOXQyMnAYiOjj4Fhgww7oc90tNQ8fvzg0lhw/X7wwG/AmyP 60hIuP1XMUZYahTtDV9by0Ca10CIrqlbvKct7BRCYTA7Qp+qY5osTerEQvmQMsc/LrZh 4y+e1qHt6cBh/JHuP5XDHSP/IxImJQVLT6OB+ZuqsB1DcszLROsluHuueaFWbFLGtfEp Ji+DeDlodEpCKtueYZRSG3D6z8qpi6HFlpjg8SoPdwd18ZdkSB/Xy3m8AfPzYde3+bGl tm78w3+zyYDxbu5y8TY1i06NfoWWBRZ+yjKPl+uzSgze7MTNgrcgmDx47Gxe9wLIuEKo 6n8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.de header.s=amazon201209 header.b=Vcqv9f+G; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g20-v6si9421963pgb.239.2018.09.07.14.52.12; Fri, 07 Sep 2018 14:52:27 -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=@amazon.de header.s=amazon201209 header.b=Vcqv9f+G; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730477AbeIHCdP (ORCPT + 99 others); Fri, 7 Sep 2018 22:33:15 -0400 Received: from smtp-fw-4101.amazon.com ([72.21.198.25]:55298 "EHLO smtp-fw-4101.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730055AbeIHCZj (ORCPT ); Fri, 7 Sep 2018 22:25:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1536356564; x=1567892564; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=eGc+7tfgjNsz8T/8mN4E1fpzKHW2V/dwOJvC2L85sqk=; b=Vcqv9f+GvOwvzGs9gUKOEXiUfYSYJjHkbdtwihU4SZCq3GbY+NhrSzAz OTkXVOza7AfEGtpHmtkLwHKwAmSnXowc2glQeDr0CcHduyXmn+vf+9Hgy HGj0Gtn2ZherHGN+CqXkuhWfXSrqCm67fP50OgpM8pk14T9j1z0MUxlTP Q=; X-IronPort-AV: E=Sophos;i="5.53,343,1531785600"; d="scan'208";a="737530492" Received: from iad6-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2a-53356bf6.us-west-2.amazon.com) ([10.124.125.6]) by smtp-border-fw-out-4101.iad4.amazon.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 07 Sep 2018 21:42:43 +0000 Received: from u7588a65da6b65f.ant.amazon.com (pdx2-ws-svc-lb17-vlan3.amazon.com [10.247.140.70]) by email-inbound-relay-2a-53356bf6.us-west-2.amazon.com (8.14.7/8.14.7) with ESMTP id w87Lgc2F089294 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Fri, 7 Sep 2018 21:42:40 GMT Received: from u7588a65da6b65f.ant.amazon.com (localhost [127.0.0.1]) by u7588a65da6b65f.ant.amazon.com (8.15.2/8.15.2/Debian-3) with ESMTPS id w87LgbFB027662 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 7 Sep 2018 23:42:37 +0200 Received: (from jschoenh@localhost) by u7588a65da6b65f.ant.amazon.com (8.15.2/8.15.2/Submit) id w87Lga9e027652; Fri, 7 Sep 2018 23:42:36 +0200 From: =?UTF-8?q?Jan=20H=2E=20Sch=C3=B6nherr?= To: Ingo Molnar , Peter Zijlstra Cc: =?UTF-8?q?Jan=20H=2E=20Sch=C3=B6nherr?= , linux-kernel@vger.kernel.org Subject: [RFC 43/60] cosched: Add for_each_sched_entity() variant for owned entities Date: Fri, 7 Sep 2018 23:40:30 +0200 Message-Id: <20180907214047.26914-44-jschoenh@amazon.de> X-Mailer: git-send-email 2.9.3.1.gcba166c.dirty In-Reply-To: <20180907214047.26914-1-jschoenh@amazon.de> References: <20180907214047.26914-1-jschoenh@amazon.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a new loop constuct for_each_owned_sched_entity(), which iterates over all owned scheduling entities, stopping when it encounters a leader change. This allows relatively straight-forward adaptations of existing code, where the leader only handles that part of the hierarchy it actually owns. Include some lockdep goodness, so that we detect incorrect usage. Signed-off-by: Jan H. Schönherr --- kernel/sched/fair.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index f72a72c8c3b8..f55954e7cedc 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -521,6 +521,76 @@ find_matching_se(struct sched_entity **se, struct sched_entity **pse) static __always_inline void account_cfs_rq_runtime(struct cfs_rq *cfs_rq, u64 delta_exec); +#ifdef CONFIG_COSCHEDULING +struct sched_entity *owned_parent_entity(struct sched_entity *se) +{ + struct rq *prq, *rq = hrq_of(cfs_rq_of(se)); + + lockdep_assert_held(&rq->lock); + + se = parent_entity(se); + if (!se) + return NULL; + + prq = hrq_of(cfs_rq_of(se)); + if (rq == prq) + return se; + +#ifdef CONFIG_SCHED_DEBUG + if (!rq->sdrq_data.parent_locked) { + int leader = rq->sdrq_data.leader; + int pleader = READ_ONCE(prq->sdrq_data.leader); + + SCHED_WARN_ON(leader == pleader); + } else { + int leader = rq->sdrq_data.leader; + int pleader = prq->sdrq_data.leader; + + SCHED_WARN_ON(leader != pleader); + } +#endif + + if (!rq->sdrq_data.parent_locked) + return NULL; + + lockdep_assert_held(&prq->lock); + return se; +} + +static inline int leader_of(struct sched_entity *se) +{ + struct rq *rq = hrq_of(cfs_rq_of(se)); + + lockdep_assert_held(&rq->lock); + return rq->sdrq_data.leader; +} + +static inline int __leader_of(struct sched_entity *se) +{ + struct rq *rq = hrq_of(cfs_rq_of(se)); + + return READ_ONCE(rq->sdrq_data.leader); +} +#else +struct sched_entity *owned_parent_entity(struct sched_entity *se) +{ + return parent_entity(se); +} + +static inline int leader_of(struct sched_entity *se) +{ + return cpu_of(rq_of(cfs_rq_of(se))); +} + +static inline int __leader_of(struct sched_entity *se) +{ + return leader_of(se); +} +#endif + +#define for_each_owned_sched_entity(se) \ + for (; se; se = owned_parent_entity(se)) + /************************************************************** * Scheduling class tree data structure manipulation methods: */ -- 2.9.3.1.gcba166c.dirty