From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id DBD43C77B73 for ; Thu, 20 Apr 2023 13:14:59 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 39DDE10EC4A; Thu, 20 Apr 2023 13:14:57 +0000 (UTC) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by gabe.freedesktop.org (Postfix) with ESMTPS id ADE9710EC62; Thu, 20 Apr 2023 13:14:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1681996494; x=1713532494; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=5eYsgw1t5FJ2zGKYBNBywEbN7OwDYxEoQCcQImGZHcg=; b=L5kHjQoAuH9ed94ryQfDodFzGJAH2d8RkWeJguxhEYuHYVN5xZLozb0C Xx8Odlv/k4LNOGmUo/iShNuKOQJDaUwy7MuXvpygFZ0bv05XPWhOivlUh 4JWwWU6zd+S7A7rCTZpuThy4M+ogpRQPLp06VXxvsjXtd6Djab19z48cU FXqLU3XIIgu9SSCPzweHcBFCoChYzapOet8gNL+RO57qP9s6QDl63kD17 rYDgCd6nYbifnWdMmq4ybLOD5JSZHUKrdODx1wnmUBBXrK9/kAEhw9YLp 32CaSt856WEuqyF2NLsNtiDdu9lg3+5j2IkYB/0BE3v8KNFZ7h8lpAWzR Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10686"; a="325336126" X-IronPort-AV: E=Sophos;i="5.99,212,1677571200"; d="scan'208";a="325336126" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Apr 2023 06:14:53 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10686"; a="1021576962" X-IronPort-AV: E=Sophos;i="5.99,212,1677571200"; d="scan'208";a="1021576962" Received: from gbyrne6x-mobl1.ger.corp.intel.com (HELO [10.213.221.188]) ([10.213.221.188]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Apr 2023 06:14:51 -0700 Message-ID: Date: Thu, 20 Apr 2023 14:14:49 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.0 Content-Language: en-US To: Rob Clark References: <20230417155613.4143258-1-tvrtko.ursulin@linux.intel.com> <20230417155613.4143258-5-tvrtko.ursulin@linux.intel.com> <3c9d4aed-5c26-6a20-071c-8a3d24f3c9ce@linux.intel.com> From: Tvrtko Ursulin Organization: Intel Corporation UK Plc In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [Intel-gfx] [RFC 4/6] drm: Add simple fdinfo memory helpers X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daniel Vetter , Intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, Alex Deucher , =?UTF-8?Q?Christian_K=c3=b6nig?= Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" On 19/04/2023 15:32, Rob Clark wrote: > On Wed, Apr 19, 2023 at 6:16 AM Tvrtko Ursulin > wrote: >> >> >> On 18/04/2023 18:18, Rob Clark wrote: >>> On Mon, Apr 17, 2023 at 8:56 AM Tvrtko Ursulin >>> wrote: >>>> >>>> From: Tvrtko Ursulin >>>> >>>> For drivers who only wish to show one memory region called 'system, >>>> and only account the GEM buffer object handles under it. >>>> >>>> Signed-off-by: Tvrtko Ursulin >>>> --- >>>> drivers/gpu/drm/drm_file.c | 45 ++++++++++++++++++++++++++++++++++++++ >>>> include/drm/drm_file.h | 6 +++++ >>>> 2 files changed, 51 insertions(+) >>>> >>>> diff --git a/drivers/gpu/drm/drm_file.c b/drivers/gpu/drm/drm_file.c >>>> index e202f79e816d..1e70669dddf7 100644 >>>> --- a/drivers/gpu/drm/drm_file.c >>>> +++ b/drivers/gpu/drm/drm_file.c >>>> @@ -872,6 +872,51 @@ void drm_send_event(struct drm_device *dev, struct drm_pending_event *e) >>>> } >>>> EXPORT_SYMBOL(drm_send_event); >>>> >>>> +static void >>>> +add_obj(struct drm_gem_object *obj, struct drm_fdinfo_memory_stat *stats) >>>> +{ >>>> + u64 sz = obj->size; >>>> + >>>> + stats[0].size += sz; >>>> + >>>> + if (obj->handle_count > 1) >>>> + stats[0].shared += sz; >>>> + >>>> + if (!dma_resv_test_signaled(obj->resv, dma_resv_usage_rw(true))) >>>> + stats[0].active += sz; >>>> + >>>> + /* Not supported. */ >>>> + stats[0].resident = ~0ull; >>>> + stats[0].purgeable = ~0ull; >>> >>> Hmm, this kinda makes the simple helper not very useful. In my >>> version, you get something that is useful for all UMA drivers (which >>> all, IIRC, have some form of madv ioctl). I was kinda imagining that >>> for ttm drivers, my print_memory_stats() would just become a helper >>> and that TTM (or "multi-region") drivers would have their own thing. >> >> Hm how? Your version also needed a driver specific vfunc: > > Sure, but there is a possibility for a driver specific vfunc ;-) Indeed, they are there in both proposals! :) > And arguably we could move madv to drm_gem_object, along with get/put > pages tracking.. since all the UMA drivers pretty much do the same > thing. So maybe the vfunc is a temporary thing. > > Anyways, I could go back to my original version where it was a helper > called from the driver to print mem stats. That way, TTM drivers > could do their own thing. I must have missed that. So it was the same idea as in my RFC? Regards, Tvrtko > BR, > -R > >> +static enum drm_gem_object_status msm_gem_status(struct drm_gem_object *obj) >> +{ >> + struct msm_gem_object *msm_obj = to_msm_bo(obj); >> + enum drm_gem_object_status status = 0; >> + >> + if (msm_obj->pages) >> + status |= DRM_GEM_OBJECT_RESIDENT; >> + >> + if (msm_obj->madv == MSM_MADV_DONTNEED) >> + status |= DRM_GEM_OBJECT_PURGEABLE; >> + >> + return status; >> +} >> >> Regards, >> >> Tvrtko >> >>> >>> BR, >>> -R >>> >>>> +} >>>> + >>>> +char ** >>>> +drm_query_fdinfo_system_region(struct drm_device *dev, unsigned int *num) >>>> +{ >>>> + static char *region[] = { >>>> + "system", >>>> + }; >>>> + >>>> + *num = 1; >>>> + >>>> + return region; >>>> +} >>>> +EXPORT_SYMBOL(drm_query_fdinfo_system_region); >>>> + >>>> +void >>>> +drm_query_fdinfo_system_memory(struct drm_file *file, >>>> + struct drm_fdinfo_memory_stat *stats) >>>> +{ >>>> + struct drm_gem_object *obj; >>>> + int id; >>>> + >>>> + spin_lock(&file->table_lock); >>>> + idr_for_each_entry(&file->object_idr, obj, id) >>>> + add_obj(obj, stats); >>>> + spin_unlock(&file->table_lock); >>>> +} >>>> +EXPORT_SYMBOL(drm_query_fdinfo_system_memory); >>>> + >>>> static void >>>> print_stat(struct drm_printer *p, const char *stat, const char *region, u64 sz) >>>> { >>>> diff --git a/include/drm/drm_file.h b/include/drm/drm_file.h >>>> index 00d48beeac5c..dd7c6fb2c975 100644 >>>> --- a/include/drm/drm_file.h >>>> +++ b/include/drm/drm_file.h >>>> @@ -383,6 +383,12 @@ struct drm_fdinfo_memory_stat { >>>> u64 active; >>>> }; >>>> >>>> +char **drm_query_fdinfo_system_region(struct drm_device *dev, >>>> + unsigned int *num); >>>> +void drm_query_fdinfo_system_memory(struct drm_file *file, >>>> + struct drm_fdinfo_memory_stat *stats); >>>> + >>>> + >>>> /** >>>> * drm_is_primary_client - is this an open file of the primary node >>>> * @file_priv: DRM file >>>> -- >>>> 2.37.2 >>>>