From patchwork Tue Jun 21 09:10:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 9189957 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 14A6360756 for ; Tue, 21 Jun 2016 09:10:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0201E27FB7 for ; Tue, 21 Jun 2016 09:10:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EB00627FC0; Tue, 21 Jun 2016 09:10:54 +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=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AB71027FB7 for ; Tue, 21 Jun 2016 09:10:54 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 330666E66F; Tue, 21 Jun 2016 09:10:48 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-lb0-x243.google.com (mail-lb0-x243.google.com [IPv6:2a00:1450:4010:c04::243]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8F6466E676 for ; Tue, 21 Jun 2016 09:10:45 +0000 (UTC) Received: by mail-lb0-x243.google.com with SMTP id ur4so1087421lbc.3 for ; Tue, 21 Jun 2016 02:10:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=kFHTB/gkxIIPR1mj2DQQuvWKF+4imA9UrtiKlS7SNxs=; b=j8O3/4RNRzQnl7Ra31c/eTsnaYbg/S0E6aVNjKVMdgIaSTpJyQPqbTFp3Rvey5z105 NO6dnLU9cnOI5xui867sqTt7XdSk+UX10wzI1h8K1lOaqQ5GV8IafQU+twFJjZXyCZaP 1RDCo9vHE93j8Z7a9tPDpGJBB2dROWJmFmI/I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=kFHTB/gkxIIPR1mj2DQQuvWKF+4imA9UrtiKlS7SNxs=; b=kEBsG4c6j7Y9Lg7gWdqASrrovtoeibMM0aC0Sa/4ilMoYMiD6j5s1T1j4tJJe8iQQ5 k61L+3ryZ6sFZbhqsF3WzZd1TQ1vZi9ZwLqzFTxYob4y1g3sqODC5ghR38hNyywn+blq Ps+btJLYMz4LLW0JLZ8220E9u9Ai8UoJLKxgb0BIF6P402nT1C5xTlsl2SNshHu9wN7c 6oSEcEKeENoxI9REQSz7Dza35eW37cuG4PUnQWeJbePSTeLzIGRfrX2b9VAPeF7lAoCF kCyGQPV3rPyN0dxyzob28HKNjRBoiKy9sUfdExsr1Q1JTAqJGZWRJ6fCSk+zgp21sL9b lDlw== X-Gm-Message-State: ALyK8tJKzVeJKQIX76L8nebDsVvBEa9Y2zfjSqgJRchNGKEGaPjueGoKIgvQC2NyuY2OdA== X-Received: by 10.194.242.37 with SMTP id wn5mr13171789wjc.135.1466500243351; Tue, 21 Jun 2016 02:10:43 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:56b5:0:ac27:b86c:7764:9429]) by smtp.gmail.com with ESMTPSA id v70sm1930380wmf.18.2016.06.21.02.10.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Jun 2016 02:10:42 -0700 (PDT) From: Daniel Vetter To: DRI Development Subject: [PATCH 02/10] drm: Don't compute obj counts expensively in get_resources Date: Tue, 21 Jun 2016 11:10:27 +0200 Message-Id: <1466500235-21282-3-git-send-email-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1466500235-21282-1-git-send-email-daniel.vetter@ffwll.ch> References: <1466500235-21282-1-git-send-email-daniel.vetter@ffwll.ch> Cc: Daniel Vetter , Intel Graphics Development X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Looping when we keep track of this is silly. Only thing we have to be careful is with sampling the connector count. To avoid inconsisten results due to gcc re-computing this, use READ_ONCE. And to avoid surprising userspace, make sure we don't copy more connectors than planned, and report the actual number of connectors copied. That way any racing hot-add/remove will be handled. Signed-off-by: Daniel Vetter --- drivers/gpu/drm/drm_crtc.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c index 28c109ff7330..4f18299dc630 100644 --- a/drivers/gpu/drm/drm_crtc.c +++ b/drivers/gpu/drm/drm_crtc.c @@ -1842,10 +1842,10 @@ int drm_mode_getresources(struct drm_device *dev, void *data, struct drm_crtc *crtc; struct drm_encoder *encoder; int ret = 0; - int connector_count = 0; - int crtc_count = 0; + int connector_count = READ_ONCE(dev->mode_config.num_connector); + int crtc_count = dev->mode_config.num_crtc; int fb_count = 0; - int encoder_count = 0; + int encoder_count = dev->mode_config.num_encoder; int copied = 0; uint32_t __user *fb_id; uint32_t __user *crtc_id; @@ -1883,15 +1883,6 @@ int drm_mode_getresources(struct drm_device *dev, void *data, /* mode_config.mutex protects the connector list against e.g. DP MST * connector hot-adding. CRTC/Plane lists are invariant. */ mutex_lock(&dev->mode_config.mutex); - drm_for_each_crtc(crtc, dev) - crtc_count++; - - drm_for_each_connector(connector, dev) - connector_count++; - - drm_for_each_encoder(encoder, dev) - encoder_count++; - card_res->max_height = dev->mode_config.max_height; card_res->min_height = dev->mode_config.min_height; card_res->max_width = dev->mode_config.max_width; @@ -1938,6 +1929,7 @@ int drm_mode_getresources(struct drm_device *dev, void *data, } copied++; } + connector_count = copied; } card_res->count_connectors = connector_count;