From patchwork Thu Aug 7 11:33:30 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 4690761 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 52D81C0338 for ; Thu, 7 Aug 2014 11:34:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 34C03201D5 for ; Thu, 7 Aug 2014 11:34:13 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 1EE4E2010F for ; Thu, 7 Aug 2014 11:34:11 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 797FA6E050; Thu, 7 Aug 2014 04:34:09 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from pegasos-out.vodafone.de (pegasos-out.vodafone.de [80.84.1.38]) by gabe.freedesktop.org (Postfix) with ESMTP id C74836E050 for ; Thu, 7 Aug 2014 04:34:07 -0700 (PDT) Received: from localhost (localhost.localdomain [127.0.0.1]) by pegasos-out.vodafone.de (Rohrpostix1 Daemon) with ESMTP id 15DCF2613EB; Thu, 7 Aug 2014 13:34:05 +0200 (CEST) X-Virus-Scanned: amavisd-new at vodafone.de X-Spam-Score: 0.165 X-Spam-Level: X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Authentication-Results: rohrpostix1.prod.vfnet.de (amavisd-new); dkim=softfail (invalid, public key: DNS query timeout for mail._domainkey.vodafone.de) header.i=@vodafone.de Received: from pegasos-out.vodafone.de ([127.0.0.1]) by localhost (rohrpostix1.prod.vfnet.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id IyFxGWUIMLeU; Thu, 7 Aug 2014 13:33:43 +0200 (CEST) Received: from smtp-03.vodafone.de (smtp-03.vodafone.de [10.215.254.38]) by pegasos-out.vodafone.de (Rohrpostix1 Daemon) with ESMTP id 732B0261408; Thu, 7 Aug 2014 13:33:43 +0200 (CEST) X-DKIM: OpenDKIM Filter v2.6.8 pegasos-out.vodafone.de 732B0261408 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vodafone.de; s=mail; t=1407411223; bh=skBpcRYFP6HMbYjq4x7fAWATidOGzZ599AZpevxqPi4=; h=From:To:Cc:Subject:Date; b=lguSaHLs4tD5RfBjb0l6IHW1Rs6Y5R1LJ4uBqDsRPgWaXGVNlYmkKxnpRn3TQweCZ PSPXYrqS4L1EWraHzokB2UKUa3TpUuyjSejOyOwjKSCW9kEVu9kgpsWGygwGl3ZhVz zntqk8RRih0jJojgNaMvXHYZ+nbyzS1GqSwuan7Q= X-Virus-Scanned: amavisd-new at vodafone.de Received: from smtp-03.vodafone.de ([127.0.0.1]) by localhost (xsmail-dmz7.prod.vfnet.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id f3pnVRzKnQqh; Thu, 7 Aug 2014 13:33:31 +0200 (CEST) From: =?UTF-8?q?Christian=20K=C3=B6nig?= To: dri-devel@lists.freedesktop.org Subject: [PATCH] drm/radeon: Adding UVD handle basis fps estimation v2 Date: Thu, 7 Aug 2014 13:33:30 +0200 Message-Id: <1407411210-1939-1-git-send-email-deathsimple@vodafone.de> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Marco A Benatto Adding a Frames Per Second estimation logic on UVD handles when it has being used. This estimation is per handle basis and will help on DPM profile calculation. v2 (chk): fix timestamp type, move functions around and cleanup code a bit. Signed-off-by: Marco A Benatto Signed-off-by: Christian König --- drivers/gpu/drm/radeon/radeon.h | 10 ++++++ drivers/gpu/drm/radeon/radeon_uvd.c | 64 +++++++++++++++++++++++++++++++++---- 2 files changed, 68 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h index 9e1732e..e92f6cb 100644 --- a/drivers/gpu/drm/radeon/radeon.h +++ b/drivers/gpu/drm/radeon/radeon.h @@ -1617,6 +1617,15 @@ int radeon_pm_get_type_index(struct radeon_device *rdev, #define RADEON_UVD_STACK_SIZE (1024*1024) #define RADEON_UVD_HEAP_SIZE (1024*1024) +#define RADEON_UVD_FPS_EVENTS_MAX 8 +#define RADEON_UVD_DEFAULT_FPS 60 + +struct radeon_uvd_fps { + uint64_t timestamp; + uint8_t event_index; + uint8_t events[RADEON_UVD_FPS_EVENTS_MAX]; +}; + struct radeon_uvd { struct radeon_bo *vcpu_bo; void *cpu_addr; @@ -1626,6 +1635,7 @@ struct radeon_uvd { struct drm_file *filp[RADEON_MAX_UVD_HANDLES]; unsigned img_size[RADEON_MAX_UVD_HANDLES]; struct delayed_work idle_work; + struct radeon_uvd_fps fps_info[RADEON_MAX_UVD_HANDLES]; }; int radeon_uvd_init(struct radeon_device *rdev); diff --git a/drivers/gpu/drm/radeon/radeon_uvd.c b/drivers/gpu/drm/radeon/radeon_uvd.c index 6bf55ec..ef5667a 100644 --- a/drivers/gpu/drm/radeon/radeon_uvd.c +++ b/drivers/gpu/drm/radeon/radeon_uvd.c @@ -237,6 +237,51 @@ void radeon_uvd_force_into_uvd_segment(struct radeon_bo *rbo) rbo->placement.lpfn = (256 * 1024 * 1024) >> PAGE_SHIFT; } +static void radeon_uvd_fps_clear_events(struct radeon_device *rdev, int idx) +{ + struct radeon_uvd_fps *fps = &rdev->uvd.fps_info[idx]; + unsigned i; + + fps->timestamp = jiffies_64; + fps->event_index = 0; + for (i = 0; i < RADEON_UVD_FPS_EVENTS_MAX; i++) + fps->events[i] = 0; +} + +static void radeon_uvd_fps_note_event(struct radeon_device *rdev, int idx) +{ + struct radeon_uvd_fps *fps = &rdev->uvd.fps_info[idx]; + uint64_t timestamp = jiffies_64; + unsigned rate = 0; + + uint8_t index = fps->event_index++; + fps->event_index %= RADEON_UVD_FPS_EVENTS_MAX; + + rate = div64_u64(HZ, max(timestamp - fps->timestamp, 1ULL)); + + fps->timestamp = timestamp; + fps->events[index] = min(rate, 120u); +} + +static unsigned radeon_uvd_estimate_fps(struct radeon_device *rdev, int idx) +{ + struct radeon_uvd_fps *fps = &rdev->uvd.fps_info[idx]; + unsigned i, valid = 0, count = 0; + + for (i = 0; i < RADEON_UVD_FPS_EVENTS_MAX; i++) { + /* We should ignore zero values */ + if (fps->events[i] != 0) { + count += fps->events[i]; + valid++; + } + } + + if (valid > 0) + return count / valid; + else + return RADEON_UVD_DEFAULT_FPS; +} + void radeon_uvd_free_handles(struct radeon_device *rdev, struct drm_file *filp) { int i, r; @@ -419,8 +464,10 @@ static int radeon_uvd_cs_msg(struct radeon_cs_parser *p, struct radeon_bo *bo, /* create or decode, validate the handle */ for (i = 0; i < RADEON_MAX_UVD_HANDLES; ++i) { - if (atomic_read(&p->rdev->uvd.handles[i]) == handle) + if (atomic_read(&p->rdev->uvd.handles[i]) == handle) { + radeon_uvd_fps_note_event(p->rdev, i); return 0; + } } /* handle not found try to alloc a new one */ @@ -428,6 +475,7 @@ static int radeon_uvd_cs_msg(struct radeon_cs_parser *p, struct radeon_bo *bo, if (!atomic_cmpxchg(&p->rdev->uvd.handles[i], 0, handle)) { p->rdev->uvd.filp[i] = p->filp; p->rdev->uvd.img_size[i] = img_size; + radeon_uvd_fps_clear_events(p->rdev, i); return 0; } } @@ -763,7 +811,7 @@ int radeon_uvd_get_destroy_msg(struct radeon_device *rdev, int ring, static void radeon_uvd_count_handles(struct radeon_device *rdev, unsigned *sd, unsigned *hd) { - unsigned i; + unsigned i, fps_rate = 0; *sd = 0; *hd = 0; @@ -772,10 +820,13 @@ static void radeon_uvd_count_handles(struct radeon_device *rdev, if (!atomic_read(&rdev->uvd.handles[i])) continue; - if (rdev->uvd.img_size[i] >= 720*576) - ++(*hd); - else - ++(*sd); + fps_rate = radeon_uvd_estimate_fps(rdev, i); + + if (rdev->uvd.img_size[i] >= 720*576) { + (*hd) += fps_rate > 30 ? 1 : 2; + } else { + (*sd) += fps_rate > 30 ? 1 : 2; + } } } @@ -805,6 +856,7 @@ void radeon_uvd_note_usage(struct radeon_device *rdev) set_clocks &= schedule_delayed_work(&rdev->uvd.idle_work, msecs_to_jiffies(UVD_IDLE_TIMEOUT_MS)); + if ((rdev->pm.pm_method == PM_METHOD_DPM) && rdev->pm.dpm_enabled) { unsigned hd = 0, sd = 0; radeon_uvd_count_handles(rdev, &sd, &hd);