From patchwork Wed Aug 1 08:20:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nayan Deshmukh X-Patchwork-Id: 10551843 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1A7A69093 for ; Wed, 1 Aug 2018 08:20:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0DAF22AC33 for ; Wed, 1 Aug 2018 08:20:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 023BB2AEC4; Wed, 1 Aug 2018 08:20:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9C89F2AC33 for ; Wed, 1 Aug 2018 08:20:57 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 77AA189C60; Wed, 1 Aug 2018 08:20:56 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pl0-x241.google.com (mail-pl0-x241.google.com [IPv6:2607:f8b0:400e:c01::241]) by gabe.freedesktop.org (Postfix) with ESMTPS id 64D7489C59; Wed, 1 Aug 2018 08:20:54 +0000 (UTC) Received: by mail-pl0-x241.google.com with SMTP id u11-v6so2897588plq.5; Wed, 01 Aug 2018 01:20:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=016Q9PkrAbG9/0CKW7BPjQEUD6O0co1Kz4mFwlEgvuM=; b=HvXK++U35+jxjoGuUsScHQcUNAt5iOP3zDoZ+MoS+3uCoRDslCG2Qs6zx7GGAl4kO7 lPoyDdKzJY3Z9AAYskFWq8c6Gu6HEyYyU/F5Tfen2yxyzApD/saOJNItYirpF8+giyyL ooqdRWacfxaY4KxUwX6SgdWSISfWqshY/vd4/k1HLaLsNjyxxA1k5n2nMiLXon/wSJf8 /FpivKq4Au4YEV1YEFWzqOQM6JQqjjL1kSqPUq95T4mL5ki/qb7guq0rNnFzDtxv3gUw QFDEsXNsjcAahG9YnyGgOHHCUMz7N/XEcamqANhJNCvfuBVda5aydyw3jF8f53LTSN+2 hl3Q== X-Gm-Message-State: AOUpUlHatY/traQCJh2hA8ubl6/FeTfnd45wf2Z8MeyIQyCphgdk9wXM o9fwhVfIIYwTA4XSz2NfVqWH9BWa X-Google-Smtp-Source: AAOMgpdxBBWWUFo2DRnux1maUocY8KfKcZIyFWWoeMq/xNqYb63iCHi/QxOyBe5AeEh0wmYElVh6Ng== X-Received: by 2002:a17:902:4d46:: with SMTP id o6-v6mr15807024plh.59.1533111653818; Wed, 01 Aug 2018 01:20:53 -0700 (PDT) Received: from localhost.localdomain ([47.247.93.221]) by smtp.gmail.com with ESMTPSA id c1-v6sm13329283pfg.25.2018.08.01.01.20.50 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 01 Aug 2018 01:20:53 -0700 (PDT) From: Nayan Deshmukh To: dri-devel@lists.freedesktop.org Subject: [PATCH 3/4] drm/scheduler: add new function to get least loaded sched v2 Date: Wed, 1 Aug 2018 13:50:01 +0530 Message-Id: <20180801082002.20696-3-nayan26deshmukh@gmail.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180801082002.20696-1-nayan26deshmukh@gmail.com> References: <20180801082002.20696-1-nayan26deshmukh@gmail.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Nayan Deshmukh , amd-gfx@lists.freedesktop.org, christian.koenig@amd.com MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP The function selects the run queue from the rq_list with the least load. The load is decided by the number of jobs in a scheduler. v2: avoid using atomic read twice consecutively, instead store it locally Signed-off-by: Nayan Deshmukh --- drivers/gpu/drm/scheduler/gpu_scheduler.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/drivers/gpu/drm/scheduler/gpu_scheduler.c b/drivers/gpu/drm/scheduler/gpu_scheduler.c index 375f6f7f6a93..fb4e542660b0 100644 --- a/drivers/gpu/drm/scheduler/gpu_scheduler.c +++ b/drivers/gpu/drm/scheduler/gpu_scheduler.c @@ -255,6 +255,31 @@ static bool drm_sched_entity_is_ready(struct drm_sched_entity *entity) return true; } +/** + * drm_sched_entity_get_free_sched - Get the rq from rq_list with least load + * + * @entity: scheduler entity + * + * Return the pointer to the rq with least load. + */ +static struct drm_sched_rq * +drm_sched_entity_get_free_sched(struct drm_sched_entity *entity) +{ + struct drm_sched_rq *rq = NULL; + unsigned int min_jobs = UINT_MAX, num_jobs; + int i; + + for (i = 0; i < entity->num_rq_list; ++i) { + num_jobs = atomic_read(&entity->rq_list[i]->sched->num_jobs); + if (num_jobs < min_jobs) { + min_jobs = num_jobs; + rq = entity->rq_list[i]; + } + } + + return rq; +} + static void drm_sched_entity_kill_jobs_cb(struct dma_fence *f, struct dma_fence_cb *cb) {