Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp4022232pxb; Mon, 4 Oct 2021 15:26:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz3yP1WkZ7CY/s5ZXIS5nlhrU0XDubDwtdm88LyQTofU+sH8h6p8+g+zdW1Y6fo6x+o/vV6 X-Received: by 2002:a17:90a:190:: with SMTP id 16mr33189206pjc.152.1633386372474; Mon, 04 Oct 2021 15:26:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633386372; cv=none; d=google.com; s=arc-20160816; b=RwiMLcdMfh8xU+piM78JmjjKMd9We3SfKCEAdk/u1S4L/ed5A4EHAsNideOQsLdkHG 9cUTNQF3nnswIfLReosaCR554ivCE5gmsx7QZEznAvMy8zhft92kFOEXF+JsC3EEJJ+F 7ztxlNcB/LXObUMfqhx5VXkBbzI0dtrJRlBR5FBZvnTZr8o1DhsSe5+POodMLX+g+YN3 lG44jXpHWcr2MrHOx7vRPqzwnft5eCOF+hSjnWMBd9xYD0IVayhA1Um3m2rfR06UXGHs A32Uwojbe0WEdG8hIB7ihdCDpBxl9WEaHmeDqWqQcD5wo/3/adjNKEfv5lcE8YFPK3ui v2oA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=jZYvnBu+h5fpypOTJgrae/H0nZsnFBVgGU3/1KedsVg=; b=PpMpC0RWbaM53SKd9lllwd51/vU46t3bLY1rHOSTbJJJzdd55Ln9cDBS328Aqp8H0m 1kz+isN1kp6FQJk0WP/u21rGmGnhWgBfx1mx0RRYH+GHXVpSye6olctS0uPqE8xbsSQ2 AQoukQSgM4q4HoMI8H8F6915L44VOgrbIiqh5CcHpMIjHcdMrQqe4vVw4ltBgwgvNT1Z uthzaAHDOKLxqc7vRthd1DneFtUpB6iE3HDxI2I9qgc92lnzm6Uhfd/NXBicHAmZBpEG jHIhS2Ca9t+h4fUvPR217i1jyks3uIZtY/KNBM4EAN5zVQft4E08LijkJXwXEfH4uWUJ 9gHQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u14si21817742pgk.369.2021.10.04.15.25.59; Mon, 04 Oct 2021 15:26:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235476AbhJDPd3 (ORCPT + 99 others); Mon, 4 Oct 2021 11:33:29 -0400 Received: from mga12.intel.com ([192.55.52.136]:40823 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234917AbhJDPd2 (ORCPT ); Mon, 4 Oct 2021 11:33:28 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10127"; a="205589003" X-IronPort-AV: E=Sophos;i="5.85,346,1624345200"; d="scan'208";a="205589003" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Oct 2021 07:37:24 -0700 X-IronPort-AV: E=Sophos;i="5.85,346,1624345200"; d="scan'208";a="622303735" Received: from shearne-mobl.ger.corp.intel.com (HELO tursulin-mobl2.home) ([10.213.208.122]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Oct 2021 07:37:23 -0700 From: Tvrtko Ursulin To: Intel-gfx@lists.freedesktop.org Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Tvrtko Ursulin Subject: [RFC 8/8] drm/i915: Connect with the process nice change notifier Date: Mon, 4 Oct 2021 15:36:50 +0100 Message-Id: <20211004143650.699120-9-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211004143650.699120-1-tvrtko.ursulin@linux.intel.com> References: <20211004143650.699120-1-tvrtko.ursulin@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tvrtko Ursulin Connect i915 with the process nice change notifier so that our scheduling can react to runtime adjustments, on top of previously added nice value inheritance at context create time. To achieve this we use the previously added map of clients per owning tasks in combination with the list of GEM contexts per client. To avoid possibly unnecessary complications the updated context nice value will only apply to future submissions against the context. Signed-off-by: Tvrtko Ursulin --- drivers/gpu/drm/i915/i915_drm_client.c | 31 ++++++++++++++++++++++++++ drivers/gpu/drm/i915/i915_drm_client.h | 3 +++ 2 files changed, 34 insertions(+) diff --git a/drivers/gpu/drm/i915/i915_drm_client.c b/drivers/gpu/drm/i915/i915_drm_client.c index 82b9636482ef..e34c1228f65b 100644 --- a/drivers/gpu/drm/i915/i915_drm_client.c +++ b/drivers/gpu/drm/i915/i915_drm_client.c @@ -7,10 +7,35 @@ #include #include +#include "gem/i915_gem_context.h" #include "i915_drm_client.h" #include "i915_gem.h" #include "i915_utils.h" +static int +clients_notify(struct notifier_block *nb, unsigned long val, void *ptr) +{ + struct i915_drm_clients *clients = + container_of(nb, typeof(*clients), prio_notifier); + struct i915_drm_client *client; + + rcu_read_lock(); + read_lock(&clients->lock); + hash_for_each_possible(clients->tasks, client, node, (uintptr_t)ptr) { + struct i915_gem_context *ctx; + + if (client->owner != ptr) + continue; + + list_for_each_entry_rcu(ctx, &client->ctx_list, client_link) + ctx->sched.nice = (int)val; + } + read_unlock(&clients->lock); + rcu_read_unlock(); + + return NOTIFY_DONE; +} + void i915_drm_clients_init(struct i915_drm_clients *clients, struct drm_i915_private *i915) { @@ -21,6 +46,10 @@ void i915_drm_clients_init(struct i915_drm_clients *clients, rwlock_init(&clients->lock); hash_init(clients->tasks); + + memset(&clients->prio_notifier, 0, sizeof(clients->prio_notifier)); + clients->prio_notifier.notifier_call = clients_notify; + register_user_nice_notifier(&clients->prio_notifier); } struct i915_drm_client *i915_drm_client_add(struct i915_drm_clients *clients) @@ -75,6 +104,8 @@ void __i915_drm_client_free(struct kref *kref) void i915_drm_clients_fini(struct i915_drm_clients *clients) { + unregister_user_nice_notifier(&clients->prio_notifier); + GEM_BUG_ON(!xa_empty(&clients->xarray)); xa_destroy(&clients->xarray); } diff --git a/drivers/gpu/drm/i915/i915_drm_client.h b/drivers/gpu/drm/i915/i915_drm_client.h index 42fd79f0558a..dda26aa42ac9 100644 --- a/drivers/gpu/drm/i915/i915_drm_client.h +++ b/drivers/gpu/drm/i915/i915_drm_client.h @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -24,6 +25,8 @@ struct i915_drm_clients { rwlock_t lock; DECLARE_HASHTABLE(tasks, 6); + + struct notifier_block prio_notifier; }; struct i915_drm_client { -- 2.30.2