Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp6456386rwb; Tue, 22 Nov 2022 13:44:21 -0800 (PST) X-Google-Smtp-Source: AA0mqf44MG3VeJMMCK1QCADyNiFZo+bcJLFP++YzmqBjigcs9joRAoj2NceJ3nectfO2gau0UcJi X-Received: by 2002:a17:906:3e18:b0:78d:8d70:8bf8 with SMTP id k24-20020a1709063e1800b0078d8d708bf8mr6037904eji.15.1669153460868; Tue, 22 Nov 2022 13:44:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669153460; cv=none; d=google.com; s=arc-20160816; b=d1Y3lYIMUAhWJhsnOwxhKi8R1jFeNHLhoJI9K4bH/Bktg/9PFHinJQ+t2zkAfOhP7f I1oQJXg/+kN6R0oMsCkzcWUugFCpBdb0b3rnPOUaNJuWwVcPduUdLD7hqhsdMcb1m4E/ caCCDiIy9XM+/A2qHQ53XC/gAa7/eVRouCOWEhnoP6bUCdAh+eE6wUloUnAbU7y9iZLC bvajA2fTm1EIQl8VyTPzP5GE97J8UfPp+n46M8dAXOQHQ4ObfSAyiyxHiH64SA3UimD4 lHqI5OqdVxopvPN/WNFVXQO3dpimedNZANE1aGJIb5cIFIcfINqSwbTT5oNq6x74V/cj 9jcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:sender:dkim-signature; bh=XYbx+av6DBnORVcQ2ULxfCSTDy21R06QMcTObHYEV34=; b=UweW7qQi75DQZq1DUUfD6JeR7BbGeZQl892gjyawDVFxvibNcDJGs+g44NvPHqYvxi Gtaw2nHiR5jmceNzEUwF2k+MKNcJuQEriJg8763IbzNMJE2uG/frDFCca55fxB/y9tHY rV3w57HV7x5CsiuAg6IZNYgDRQwSIiB0a4FV74A9j6OxjMs60YwNJLyJPXY5rlbA4SSi Mua0DNlvABX9l+bZBo3gQVOGFHC/UjF0QT/mv/GqCO6DxspguuQ37xXHz8Oq9EtK67AZ ZKQvKChBx33eJxmYoGlLwLTcezRGjdjClgow3RKNLDVjuAWjN73uksmi6+MMidY9VoWm +M+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=YGgKFSzV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y12-20020a056402270c00b004593671898esi13514933edd.611.2022.11.22.13.43.59; Tue, 22 Nov 2022 13:44:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=YGgKFSzV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235020AbiKVV30 (ORCPT + 90 others); Tue, 22 Nov 2022 16:29:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233174AbiKVV3Z (ORCPT ); Tue, 22 Nov 2022 16:29:25 -0500 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35CD322529; Tue, 22 Nov 2022 13:29:23 -0800 (PST) Received: by mail-pl1-x634.google.com with SMTP id k7so14877286pll.6; Tue, 22 Nov 2022 13:29:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:from:to:cc:subject:date:message-id :reply-to; bh=XYbx+av6DBnORVcQ2ULxfCSTDy21R06QMcTObHYEV34=; b=YGgKFSzVDtg4WqE7blC+H6hUzPYoBzvcBGqcO8VWfLHbMTqWNn4bE7btkALc2ygD5T D2Xj8asn40IU8QFMvKIiMRt9BNe+DUkTI09kpbDa7g6S4DYFTI1rHz51KuXDTKNuj/Sh Njuax5n6GHUJW8GAskJ2gtcmll/eWEZMsPzskTGXNZq1xDdhzPToaaPHs1DMAxoR4CXC g4T4/4TWRfjOCE9jGNmZHF8RmxInIK24wUW/svb5XVdP3I4wtMt1v020nT6Bdw3YBKkC HS1n2b8c0YyB6P4nGoAjBTrENJqPW49nR/dgfsFdWHaBGUsSvvgdvsl3W2dE202ZTirX l7Lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XYbx+av6DBnORVcQ2ULxfCSTDy21R06QMcTObHYEV34=; b=Z4qVrnG+f8eVTaMAD6HKNcG2lG/JqKDgsknZGsDf5iEOPG8WjcW5lZ5+qQlNqq2W4q HIF1vFvjdmCwzy+En5TV7ywd5pKQVr9yLDx6e9gMHT2nshQgPIo/UrPaoo1HIXnZO2nI 5wX3fcZ1euBcvj72g+aoL2AGo8UL1l+XkF4jXjHPKmivI+fIR/BFlq7n7G6ATUXOkaka SZ+ppCEL2uau4Q4nkmkII+JSEEJ6mAeFgRuD8A6bSIatgwQHe8vOJZ0Q5u/+SG7Q1iu6 EDgasuDmXdd3fQRWgEtIuHbjxFKSiffJMuSv7tBR+DbSKSlwOdJh9inJAIE8F2tup0ar dp+A== X-Gm-Message-State: ANoB5pnv3f4K6FFt/Su6w1gueIlgrR4RciXU1KeFujBheSGtZvqzWqyD HnitSks1RqjXHZUmhiLNRS0= X-Received: by 2002:a17:903:2407:b0:17f:3da:f19d with SMTP id e7-20020a170903240700b0017f03daf19dmr8588893plo.147.1669152562517; Tue, 22 Nov 2022 13:29:22 -0800 (PST) Received: from localhost ([2620:10d:c090:400::5:bb3]) by smtp.gmail.com with ESMTPSA id b8-20020aa78ec8000000b005627ddbc7a4sm11086709pfr.191.2022.11.22.13.29.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Nov 2022 13:29:22 -0800 (PST) Sender: Tejun Heo Date: Tue, 22 Nov 2022 11:29:20 -1000 From: Tejun Heo To: Tvrtko Ursulin Cc: Intel-gfx@lists.freedesktop.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Johannes Weiner , Zefan Li , Dave Airlie , Daniel Vetter , Rob Clark , =?iso-8859-1?Q?St=E9phane?= Marchesin , "T . J . Mercier" , Kenny.Ho@amd.com, Christian =?iso-8859-1?Q?K=F6nig?= , Brian Welty , Tvrtko Ursulin Subject: Re: [RFC 11/13] cgroup/drm: Introduce weight based drm cgroup control Message-ID: References: <20221109161141.2987173-1-tvrtko.ursulin@linux.intel.com> <20221109161141.2987173-12-tvrtko.ursulin@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221109161141.2987173-12-tvrtko.ursulin@linux.intel.com> X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Nov 09, 2022 at 04:11:39PM +0000, Tvrtko Ursulin wrote: > +DRM scheduling soft limits > +~~~~~~~~~~~~~~~~~~~~~~~~~~ > + > +Because of the heterogenous hardware and driver DRM capabilities, soft limits > +are implemented as a loose co-operative (bi-directional) interface between the > +controller and DRM core. > + > +The controller configures the GPU time allowed per group and periodically scans > +the belonging tasks to detect the over budget condition, at which point it > +invokes a callback notifying the DRM core of the condition. > + > +DRM core provides an API to query per process GPU utilization and 2nd API to > +receive notification from the cgroup controller when the group enters or exits > +the over budget condition. > + > +Individual DRM drivers which implement the interface are expected to act on this > +in the best-effort manner only. There are no guarantees that the soft limits > +will be respected. Soft limits is a bit of misnomer and can be confused with best-effort limits such as memory.high. Prolly best to not use the term. > +static bool > +__start_scanning(struct drm_cgroup_state *root, unsigned int period_us) > +{ > + struct cgroup_subsys_state *node; > + bool ok = false; > + > + rcu_read_lock(); > + > + css_for_each_descendant_post(node, &root->css) { > + struct drm_cgroup_state *drmcs = css_to_drmcs(node); > + > + if (!css_tryget_online(node)) > + goto out; > + > + drmcs->active_us = 0; > + drmcs->sum_children_weights = 0; > + > + if (node == &root->css) > + drmcs->per_s_budget_ns = > + DIV_ROUND_UP_ULL(NSEC_PER_SEC * period_us, > + USEC_PER_SEC); > + else > + drmcs->per_s_budget_ns = 0; > + > + css_put(node); > + } > + > + css_for_each_descendant_post(node, &root->css) { > + struct drm_cgroup_state *drmcs = css_to_drmcs(node); > + struct drm_cgroup_state *parent; > + u64 active; > + > + if (!css_tryget_online(node)) > + goto out; > + if (!node->parent) { > + css_put(node); > + continue; > + } > + if (!css_tryget_online(node->parent)) { > + css_put(node); > + goto out; > + } > + parent = css_to_drmcs(node->parent); > + > + active = drmcs_get_active_time_us(drmcs); > + if (active > drmcs->prev_active_us) > + drmcs->active_us += active - drmcs->prev_active_us; > + drmcs->prev_active_us = active; > + > + parent->active_us += drmcs->active_us; > + parent->sum_children_weights += drmcs->weight; > + > + css_put(node); > + css_put(&parent->css); > + } > + > + ok = true; > + > +out: > + rcu_read_unlock(); > + > + return ok; > +} A more conventional and scalable way to go about this would be using an rbtree keyed by virtual time. Both CFS and blk-iocost are examples of this, but I think for drm, it can be a lot simpler. Thanks. -- tejun