From patchwork Sat Jan 28 19:50:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Grazvydas Ignotas X-Patchwork-Id: 9543451 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 52E1D6046A for ; Sat, 28 Jan 2017 19:50:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4489628178 for ; Sat, 28 Jan 2017 19:50:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3960F28338; Sat, 28 Jan 2017 19:50:51 +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_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, 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]) (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 D577D28178 for ; Sat, 28 Jan 2017 19:50:50 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 244296E0B0; Sat, 28 Jan 2017 19:50:50 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-lf0-x241.google.com (mail-lf0-x241.google.com [IPv6:2a00:1450:4010:c07::241]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0E8FE6E0AD; Sat, 28 Jan 2017 19:50:48 +0000 (UTC) Received: by mail-lf0-x241.google.com with SMTP id x1so28547504lff.0; Sat, 28 Jan 2017 11:50:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=wwLV28Lfr/0Ts3W7NLHquedYtdeGPZ8yTz7UfEQ3P5M=; b=U/EzgLnjcUjJqDH5a9PbfYBF5hRkPkzDqbDriZRMZdIulmBZk+/FpzeEQsFn1i1vY8 BeWdeAvHJrxz1WY0ZtcDupXj1VSrrgkPpBQSbJ7NeYNYhddO2XOTl0JArmZZxjislfC4 P5hRC6QevU/Rre3gIncaNlD+4dRVk0oLm8NHv5t1ge8GLC4ghHRfEkwGYmKuTYPAbXhH AeDGTaPXRDkPBgRkW7Dh+30WE0r8aCCdmIlOH+Wju9yIztq0RjVIdEfrl0RVUKOCqv6m 6OzYweErOooWXDCpDJPZgdpGQ7a9CK/VOofFw9MQCrs6Dg0FRqfn3ohieidBeUeSPXtB JxZA== 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:mime-version :content-transfer-encoding; bh=wwLV28Lfr/0Ts3W7NLHquedYtdeGPZ8yTz7UfEQ3P5M=; b=VDup3NXSVv2AeWytf2SEUaKgRKfmZGX0YMy6Wl41Lu+/IlQyi2y70UESnmdzg28oEU /7rmlub8pwkFJbJPAwd64VemFZO4oakrF9XO5oa74KSocqKWWDJ2VUkh49C1FaSsWWKA Voee3flzmj+vOOXU1fp/yz3mCgYva/ylIU9Pjtib5VUpW9SMnaUVG80/ls6DiFIEFPb0 alSXS7J2gF7A8EFl55h3AryFwwpmhMPWzXc4BXgLOCFhbn4kNpKqQimthfNdZ19t5NHb b1emgtFJxgEWO48wrRwkOsbbzDAN6Xun/GA8Ovh9kU3dgI9Mq2U49SCHfb4sKaC3xV14 t7Yg== X-Gm-Message-State: AIkVDXJavgCxx3S30ZYuTZIhJSC3CfMS3okS7P7SpV/Qov8ilQQygGJOwqex31oEXHVzxQ== X-Received: by 10.25.92.145 with SMTP id u17mr4018103lfi.160.1485633046061; Sat, 28 Jan 2017 11:50:46 -0800 (PST) Received: from localhost.localdomain ([5.20.238.37]) by smtp.gmail.com with ESMTPSA id d16sm2340628lfj.28.2017.01.28.11.50.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 28 Jan 2017 11:50:45 -0800 (PST) From: Grazvydas Ignotas To: dri-devel@lists.freedesktop.org Subject: [PATCH libdrm 3/3] amdgpu: vamgr can be a struct instead of a pointer Date: Sat, 28 Jan 2017 21:50:44 +0200 Message-Id: <1485633044-4965-1-git-send-email-notasas@gmail.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Cc: amd-gfx@lists.freedesktop.org, Alex Xie 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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Alex Xie vamgr is an integral part of amdgpu_device. We don't need to calloc and free it. This can save CPU time, reduce heap fragmentation. Signed-off-by: Alex Xie Reviewed-by: Christian König [Grazvydas Ignotas: rebase, correct a typo in commit message] --- amdgpu/amdgpu_device.c | 16 +++++----------- amdgpu/amdgpu_internal.h | 2 +- amdgpu/amdgpu_vamgr.c | 2 +- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/amdgpu/amdgpu_device.c b/amdgpu/amdgpu_device.c index 11714e4..f473d2d 100644 --- a/amdgpu/amdgpu_device.c +++ b/amdgpu/amdgpu_device.c @@ -132,8 +132,7 @@ static int amdgpu_get_auth(int fd, int *auth) static void amdgpu_device_free_internal(amdgpu_device_handle dev) { amdgpu_vamgr_deinit(&dev->vamgr_32); - amdgpu_vamgr_deinit(dev->vamgr); - free(dev->vamgr); + amdgpu_vamgr_deinit(&dev->vamgr); util_hash_table_destroy(dev->bo_flink_names); util_hash_table_destroy(dev->bo_handles); pthread_mutex_destroy(&dev->bo_table_mutex); @@ -254,16 +253,12 @@ int amdgpu_device_initialize(int fd, if (r) goto cleanup; - dev->vamgr = calloc(1, sizeof(struct amdgpu_bo_va_mgr)); - if (dev->vamgr == NULL) - goto cleanup; - - amdgpu_vamgr_init(dev->vamgr, dev->dev_info.virtual_address_offset, + amdgpu_vamgr_init(&dev->vamgr, dev->dev_info.virtual_address_offset, dev->dev_info.virtual_address_max, dev->dev_info.virtual_address_alignment); max = MIN2(dev->dev_info.virtual_address_max, 0xffffffff); - start = amdgpu_vamgr_find_va(dev->vamgr, + start = amdgpu_vamgr_find_va(&dev->vamgr, max - dev->dev_info.virtual_address_offset, dev->dev_info.virtual_address_alignment, 0); if (start > 0xffffffff) @@ -282,10 +277,9 @@ int amdgpu_device_initialize(int fd, free_va: r = -ENOMEM; - amdgpu_vamgr_free_va(dev->vamgr, start, + amdgpu_vamgr_free_va(&dev->vamgr, start, max - dev->dev_info.virtual_address_offset); - amdgpu_vamgr_deinit(dev->vamgr); - free(dev->vamgr); + amdgpu_vamgr_deinit(&dev->vamgr); cleanup: if (dev->fd >= 0) diff --git a/amdgpu/amdgpu_internal.h b/amdgpu/amdgpu_internal.h index 7e237ac..cf119a5 100644 --- a/amdgpu/amdgpu_internal.h +++ b/amdgpu/amdgpu_internal.h @@ -85,7 +85,7 @@ struct amdgpu_device { struct drm_amdgpu_info_device dev_info; struct amdgpu_gpu_info info; /** The global VA manager for the whole virtual address space */ - struct amdgpu_bo_va_mgr *vamgr; + struct amdgpu_bo_va_mgr vamgr; /** The VA manager for the 32bit address space */ struct amdgpu_bo_va_mgr vamgr_32; }; diff --git a/amdgpu/amdgpu_vamgr.c b/amdgpu/amdgpu_vamgr.c index 4dc4253..2b1388e 100644 --- a/amdgpu/amdgpu_vamgr.c +++ b/amdgpu/amdgpu_vamgr.c @@ -238,7 +238,7 @@ int amdgpu_va_range_alloc(amdgpu_device_handle dev, if (flags & AMDGPU_VA_RANGE_32_BIT) vamgr = &dev->vamgr_32; else - vamgr = dev->vamgr; + vamgr = &dev->vamgr; va_base_alignment = MAX2(va_base_alignment, vamgr->va_alignment); size = ALIGN(size, vamgr->va_alignment);