From patchwork Fri Jul 10 09:54:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgUMOpcm9u?= X-Patchwork-Id: 11661703 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1D5BC913 for ; Tue, 14 Jul 2020 07:04:30 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EF3C822205 for ; Tue, 14 Jul 2020 07:04:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="g2Sw/HtR" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EF3C822205 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5268D6E90D; Tue, 14 Jul 2020 07:02:46 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by gabe.freedesktop.org (Postfix) with ESMTPS id 12E9D6EBC5 for ; Fri, 10 Jul 2020 09:54:20 +0000 (UTC) Received: by mail-wr1-x442.google.com with SMTP id k6so5306932wrn.3 for ; Fri, 10 Jul 2020 02:54:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ztEfvDOenwmzhW91KrXpwCBICtYWbElja0rQb72V3Pc=; b=g2Sw/HtRWWNJ5encQ3nPzyJELqRZMCj5wm71m7O+SPkz1nmaO46NZsXat+Z8/XgW/L igZoeYAytqCjnVdz96EzvYEsJ7IsKnmxHZrqTYW2wQv+XEylqdz5q5jGeJpZ7hrNYYTF in5i4GW03rPLwBd80LItpC6LwoR3/Ta+osSktb5bjR2B+rKz15l+GkmrLZjtoL76QWWZ issqIjbbSocExDwwcamif8oOvMpYu+VhDW1ur+D0QUpXdEXnDAxATZHqB9ApguNsnVAq ieYgqcl0SZPKv9vlR+xVgokJAi5QJzwucw7NIXJ8i21XTB8YayKstmwxIqUH3JAjxdF1 kBMQ== 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:mime-version:content-transfer-encoding; bh=ztEfvDOenwmzhW91KrXpwCBICtYWbElja0rQb72V3Pc=; b=cc/clfMlJmdPFRwLQBiIWnEFUz5ArrkwPyocWEd4EIVFV3HNqJO09dtNeUvHzc/pK3 hqTLpLtHhMTG77MVoxYFofMseF7m89Su8IaqwxB5qndNp1NyddRcd00bK2GW3WKCIDJO NCXtngE68f8be0tJlWbQi6DFJ5BrFIXbcVqf7mlfDHdHkWATkJZO3SjDcVg5lBYnkPsb wf8ayTEKl2d+CsZDKzoLZqneYemo+rHFLXvMQPH11pJ8/QDqYKRnmNeqOeodbW62NrN9 S6aZpiZvC8+VpDxDLsNpWqvEsMnzYc0KnPUZavoM5z74QHjKRTrFizHmncOr7XY7Obix pc7w== X-Gm-Message-State: AOAM533C1WirNFOGYGdfc2jS6DU7duwbA9IbmZSe5//hiABKBrhg/l// i5jE86K+953QJw7uhS+OpIw= X-Google-Smtp-Source: ABdhPJwzCuVZOhYt/qbcLHI1t2KZzcXMm7lxjQOjcyDF+zp22T7tp6c5A+pU+XH8wU1rId7MRkLtcw== X-Received: by 2002:adf:f60c:: with SMTP id t12mr72601276wrp.198.1594374858621; Fri, 10 Jul 2020 02:54:18 -0700 (PDT) Received: from clement-Latitude-7490.numericable.fr (213-245-241-245.rev.numericable.fr. [213.245.241.245]) by smtp.gmail.com with ESMTPSA id u23sm10176092wru.94.2020.07.10.02.54.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jul 2020 02:54:17 -0700 (PDT) From: =?utf-8?b?Q2zDqW1lbnQgUMOpcm9u?= To: Rob Herring , Tomeu Vizoso , Steven Price , Alyssa Rosenzweig , Viresh Kumar , Nishanth Menon , Stephen Boyd , Maxime Ripard , Chen-Yu Tsai Subject: [PATCH v5 05/14] drm/panfrost: use spinlock instead of atomic Date: Fri, 10 Jul 2020 11:54:00 +0200 Message-Id: <20200710095409.407087-6-peron.clem@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200710095409.407087-1-peron.clem@gmail.com> References: <20200710095409.407087-1-peron.clem@gmail.com> MIME-Version: 1.0 X-Mailman-Approved-At: Tue, 14 Jul 2020 07:02:08 +0000 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?b?Q2zDqW1lbnQgUMOpcm9u?= , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Convert busy_count to a simple int protected by spinlock. Reviewed-by: Steven Price Reviewed-by: Alyssa Rosenzweig Signed-off-by: Clément Péron --- drivers/gpu/drm/panfrost/panfrost_devfreq.c | 43 +++++++++++++++------ drivers/gpu/drm/panfrost/panfrost_devfreq.h | 9 ++++- 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/drivers/gpu/drm/panfrost/panfrost_devfreq.c b/drivers/gpu/drm/panfrost/panfrost_devfreq.c index 962550363391..78753cfb59fb 100644 --- a/drivers/gpu/drm/panfrost/panfrost_devfreq.c +++ b/drivers/gpu/drm/panfrost/panfrost_devfreq.c @@ -12,16 +12,12 @@ static void panfrost_devfreq_update_utilization(struct panfrost_devfreq *pfdevfreq) { - ktime_t now; - ktime_t last; - - if (!pfdevfreq->devfreq) - return; + ktime_t now, last; now = ktime_get(); last = pfdevfreq->time_last_update; - if (atomic_read(&pfdevfreq->busy_count) > 0) + if (pfdevfreq->busy_count > 0) pfdevfreq->busy_time += ktime_sub(now, last); else pfdevfreq->idle_time += ktime_sub(now, last); @@ -59,10 +55,14 @@ static int panfrost_devfreq_get_dev_status(struct device *dev, { struct panfrost_device *pfdev = dev_get_drvdata(dev); struct panfrost_devfreq *pfdevfreq = &pfdev->pfdevfreq; + unsigned long irqflags; + + status->current_frequency = clk_get_rate(pfdev->clock); + + spin_lock_irqsave(&pfdevfreq->lock, irqflags); panfrost_devfreq_update_utilization(pfdevfreq); - status->current_frequency = clk_get_rate(pfdev->clock); status->total_time = ktime_to_ns(ktime_add(pfdevfreq->busy_time, pfdevfreq->idle_time)); @@ -70,6 +70,8 @@ static int panfrost_devfreq_get_dev_status(struct device *dev, panfrost_devfreq_reset(pfdevfreq); + spin_unlock_irqrestore(&pfdevfreq->lock, irqflags); + dev_dbg(pfdev->dev, "busy %lu total %lu %lu %% freq %lu MHz\n", status->busy_time, status->total_time, status->busy_time / (status->total_time / 100), @@ -100,6 +102,8 @@ int panfrost_devfreq_init(struct panfrost_device *pfdev) else if (ret) return ret; + spin_lock_init(&pfdevfreq->lock); + panfrost_devfreq_reset(pfdevfreq); cur_freq = clk_get_rate(pfdev->clock); @@ -162,15 +166,32 @@ void panfrost_devfreq_suspend(struct panfrost_device *pfdev) void panfrost_devfreq_record_busy(struct panfrost_devfreq *pfdevfreq) { + unsigned long irqflags; + + if (!pfdevfreq->devfreq) + return; + + spin_lock_irqsave(&pfdevfreq->lock, irqflags); + panfrost_devfreq_update_utilization(pfdevfreq); - atomic_inc(&pfdevfreq->busy_count); + + pfdevfreq->busy_count++; + + spin_unlock_irqrestore(&pfdevfreq->lock, irqflags); } void panfrost_devfreq_record_idle(struct panfrost_devfreq *pfdevfreq) { - int count; + unsigned long irqflags; + + if (!pfdevfreq->devfreq) + return; + + spin_lock_irqsave(&pfdevfreq->lock, irqflags); panfrost_devfreq_update_utilization(pfdevfreq); - count = atomic_dec_if_positive(&pfdevfreq->busy_count); - WARN_ON(count < 0); + + WARN_ON(--pfdevfreq->busy_count < 0); + + spin_unlock_irqrestore(&pfdevfreq->lock, irqflags); } diff --git a/drivers/gpu/drm/panfrost/panfrost_devfreq.h b/drivers/gpu/drm/panfrost/panfrost_devfreq.h index 0697f8d5aa34..3392df1020be 100644 --- a/drivers/gpu/drm/panfrost/panfrost_devfreq.h +++ b/drivers/gpu/drm/panfrost/panfrost_devfreq.h @@ -4,6 +4,7 @@ #ifndef __PANFROST_DEVFREQ_H__ #define __PANFROST_DEVFREQ_H__ +#include #include struct devfreq; @@ -14,10 +15,16 @@ struct panfrost_device; struct panfrost_devfreq { struct devfreq *devfreq; struct thermal_cooling_device *cooling; + ktime_t busy_time; ktime_t idle_time; ktime_t time_last_update; - atomic_t busy_count; + int busy_count; + /* + * Protect busy_time, idle_time, time_last_update and busy_count + * because these can be updated concurrently between multiple jobs. + */ + spinlock_t lock; }; int panfrost_devfreq_init(struct panfrost_device *pfdev);