Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4122541pxb; Mon, 1 Feb 2021 13:05:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJy0jUPcQtc2dLtxtD9i1Cr87h9rr/vAKn8NX02K0p8RITgdxoALrCJiv9RNLw+YiCeCo+yP X-Received: by 2002:a17:906:af92:: with SMTP id mj18mr19345797ejb.290.1612213524935; Mon, 01 Feb 2021 13:05:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612213524; cv=none; d=google.com; s=arc-20160816; b=SfdgsFHC3eQGh9SK3MGo8OSqWmKQtbjU35y/X6erPhRhNjpAQ+vV8ZDpTYicO/1jLh z6c+O2dtOKFpDF6CyRroEQaokCwey/3vd9IUqtzBC/SiVFIKd/1iFK33vpjqMOUWO4n2 zNKwmzfV/w2HTivIi3E8av59COlWY7TqTN3koBo/eCO6gMzXetxdoeuoJU9KeyvHWvuS BR6rGClJIPwQilQDmN2UBQcJ6ujIDB2frG2ANwYVemC4FNNzeu71K8+5FBLIMxiQSluP slfNXxShSqDCKteL0lguCFCPloiFHYkqIqjbtXqnKg+olk6SLXpkZOfDZ61JTUo+zyVF RYzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=8k+54hdZU4bIMIuE/qB/uIoqqs2NrOQg3MOYc8JAwIA=; b=oTrFpkqcWZxY6yzx5X2VK7kvrLNHjuHE7pkkNuyPs3wHLmMk2B+d6vLLxRSNXLr9OE sRA5oUb4JgEkACG0zSMfug0OtzY4PaklGvjeXDYjx2XOvvouVNv4cDBPY0bwUN9oiM7l 49Wj8zI2pDtBM+Q6UF9SyDE63K4SIiWEwlD4gYfPc1FAoGZ3gaQhuq0s62L3ZTMSr8cP NgZcPxrvD9wq2vaA+hH1wBNqalNEVaaAw3znWhWGVFQKuvJBlNozM3Okmt8Lu0mxBA7D QvInnbMJaGEFb5CiwXL0YJ7SVB3gC0p0p/veaNZHUTvt+uxw/ixspSqIJqOQnn9Wyfw/ QXAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=VmKk8nJ8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h13si5261462edw.220.2021.02.01.13.04.58; Mon, 01 Feb 2021 13:05:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=VmKk8nJ8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231226AbhBAVDv (ORCPT + 99 others); Mon, 1 Feb 2021 16:03:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229831AbhBAVDt (ORCPT ); Mon, 1 Feb 2021 16:03:49 -0500 Received: from mail-qt1-x836.google.com (mail-qt1-x836.google.com [IPv6:2607:f8b0:4864:20::836]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CFB8CC061756 for ; Mon, 1 Feb 2021 13:03:08 -0800 (PST) Received: by mail-qt1-x836.google.com with SMTP id r20so9821105qtm.3 for ; Mon, 01 Feb 2021 13:03:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=8k+54hdZU4bIMIuE/qB/uIoqqs2NrOQg3MOYc8JAwIA=; b=VmKk8nJ8618Xbxb/H896bZfhXIhO+dDFeUnBicg0JgMCZ2SFsaM6lJiSTgdnLMu79D fgKtrmUK5R3fe7Yl0eGTceLLC1GTeGVawyYLpw6NwDpWply35TF6br9QZ6olQ8kVvGpy wO6bCOtQ+xDPXWW6eFg27XfF7zy563tAIUsT781IJQD2I41Yr7aHKUPQzkf7COO8FXIc xvu2Ew+57rxCD3DCWw+JgekQy8f+aEcLR4rkRqxbH8g84l1W4x6REWxjjezelEiJt5kP ktSgklhXzDh78n5AWCjez+Se6nMTNaHgXldwBmPqqHOMSGaVZF6kOfVim4cFAH6JBh1u Tgmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=8k+54hdZU4bIMIuE/qB/uIoqqs2NrOQg3MOYc8JAwIA=; b=sNP+5/Yq8n3Advq40RKJ1xld8IPY4hKvePe/jeaGmR/DhzXKLKoqyZhQDGShEaHgJB Wj/EmAMs3KPQKdk7347lWskCkjhx294TrRAy9sQeeaaG92iHLUrfHwmARxebUCr1toxX EV+5CKSa3NqMamahuzwLIBRCiJ6T/+r8Y7sXmjfo8kxuE4tRuq/DfkVKRQkfNElRFdjk qAFef/YnwE94PAbD8yOjvpCOCOXo40QWg22KjsQ0jy/53VWzY/Klm7kfiskW9Z8GUqDU Rre9rI4VyMX47owGyQ/P7OdvdjqstKRjzeekPDVMNSlA99EsHRgwfrIZtSwZKX5rqoBJ RLNw== X-Gm-Message-State: AOAM531IF1/aNe1kblSYAekp3NVq6c8DqfdzPhZFmRVCH3SuPa/P8Sao 3FB5RHrkEgb+jQHcxnvmlPiHCDdri4rtf3Xk9fLrQw== X-Received: by 2002:ac8:6f0f:: with SMTP id g15mr3296448qtv.322.1612213387657; Mon, 01 Feb 2021 13:03:07 -0800 (PST) MIME-Version: 1.0 References: <20210126204240.418297-1-hridya@google.com> In-Reply-To: From: Hridya Valsaraju Date: Mon, 1 Feb 2021 13:02:30 -0800 Message-ID: Subject: Re: [Linaro-mm-sig] [PATCH v3] dmabuf: Add the capability to expose DMA-BUF stats in sysfs To: Daniel Vetter Cc: Sumit Semwal , Christian Koenig , Android Kernel Team , kernel test robot , Greg KH , LKML , DRI mailing list , Linaro MM SIG , Hyesoo Yu , Suren Baghdasaryan , "open list:DMA BUFFER SHARING FRAMEWORK" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Feb 1, 2021 at 10:37 AM Daniel Vetter wrote: > > On Thu, Jan 28, 2021 at 1:03 PM Sumit Semwal wr= ote: > > > > On Thu, 28 Jan 2021 at 17:23, Christian K=C3=B6nig > > wrote: > > > > > > Am 28.01.21 um 12:00 schrieb Sumit Semwal: > > > > Hi Hridya, > > > > > > > > On Wed, 27 Jan 2021 at 17:36, Greg KH = wrote: > > > >> On Tue, Jan 26, 2021 at 12:42:36PM -0800, Hridya Valsaraju wrote: > > > >>> This patch allows statistics to be enabled for each DMA-BUF in > > > >>> sysfs by enabling the config CONFIG_DMABUF_SYSFS_STATS. > > > >>> > > > >>> The following stats will be exposed by the interface: > > > >>> > > > >>> /sys/kernel/dmabuf/buffers//exporter_name > > > >>> /sys/kernel/dmabuf/buffers//size > > > >>> /sys/kernel/dmabuf/buffers//attachments//device > > > >>> /sys/kernel/dmabuf/buffers//attachments//map_counter > > > >>> > > > >>> The inode_number is unique for each DMA-BUF and was added earlier= [1] > > > >>> in order to allow userspace to track DMA-BUF usage across differe= nt > > > >>> processes. > > > >>> > > > >>> Currently, this information is exposed in > > > >>> /sys/kernel/debug/dma_buf/bufinfo. > > > >>> However, since debugfs is considered unsafe to be mounted in prod= uction, > > > >>> it is being duplicated in sysfs. > > > >>> > > > >>> This information will be used to derive DMA-BUF > > > >>> per-exporter stats and per-device usage stats for Android Bug rep= orts. > > > >>> The corresponding userspace changes can be found at [2]. > > > >>> Telemetry tools will also capture this information(along with oth= er > > > >>> memory metrics) periodically as well as on important events like = a > > > >>> foreground app kill (which might have been triggered by Low Memor= y > > > >>> Killer). It will also contribute to provide a snapshot of the sys= tem > > > >>> memory usage on other events such as OOM kills and Application No= t > > > >>> Responding events. > > > >>> > > > >>> A shell script that can be run on a classic Linux environment to = read > > > >>> out the DMA-BUF statistics can be found at [3](suggested by John > > > >>> Stultz). > > > >>> > > > >>> The patch contains the following improvements over the previous v= ersion: > > > >>> 1) Each attachment is represented by its own directory to allow c= reating > > > >>> a symlink to the importing device and to also provide room for fu= ture > > > >>> expansion. > > > >>> 2) The number of distinct mappings of each attachment is exposed = in a > > > >>> separate file. > > > >>> 3) The per-buffer statistics are now in /sys/kernel/dmabuf/buffer= s > > > >>> inorder to make the interface expandable in future. > > > >>> > > > >>> All of the improvements above are based on suggestions/feedback f= rom > > > >>> Daniel Vetter and Christian K=C3=B6nig. > > > >>> > > > >>> [1]: https://lore.kernel.org/patchwork/patch/1088791/ > > > >>> [2]: https://android-review.googlesource.com/q/topic:%22dmabuf-sy= sfs%22+(status:open%20OR%20status:merged) > > > >>> [3]: https://android-review.googlesource.com/c/platform/system/me= mory/libmeminfo/+/1549734 > > > >>> > > > >>> Signed-off-by: Hridya Valsaraju > > > >>> Reported-by: kernel test robot > > > > Thanks for the patch! > > > > > > > > Christian: If you're satisfied with the explanation around not > > > > directly embedding kobjects into the dma_buf and dma_buf_attachment > > > > structs, then with Greg's r-b from sysfs PoV, I think we can merge = it. > > > > Please let me know if you feel otherwise! > > > > > > From the technical side it looks clean to me, feel free to add my > > > acked-by while pushing. > > > > > > But I would at least try to convince Daniel on the design. At least s= ome > > > of his concerns seems to be valid and keep in mind that we need to > > > support this interface forever. > > > > Naturally. > > > > Since he didn't comment over Hridya's last clarification about the > > tracepoints to track total GPU memory allocations being orthogonal to > > this series, I assumed he agreed with it. > > The tracepoint being orthogonal didn't really look convincing to me, > since I do expect we'll need that at a much more generic level, at > allocators. Whether that's dma-buf heaps or in drm or wherever. And we > probably also need that to somehow align with cgroups accounting. > > But I guess for this it should be easy to extend however we see fit, > so retrofitting allocator sources and anything else we want/need for > the overall gpu memory account shouldn't be a problem. Also, it's > first, so the proof for showing it all works together is more on the > tracepoints :-) > > > Daniel, do you still have objections around adding this patch in? > > Needs docs (especially the uapi I think would be useful to document), > igt tests, that kind of stuff still I think? It's meant to be generic > uapi across drivers, generally we're a pile stricter for that (and yes > dma-buf heaps I think didn't do all that, so maybe there's an argument > for doing this a bit more sloppy or at least "the testsuite is > somewhere else"). Thank you for taking another look Daniel! I will try adding an IGT test for the sysfs files. Other than the documentation in Documentation/ABI/testing/sysfs-kernel-dmabuf-buffers(included in the patch), is there another place you would like to see the documentation copied to? Regards, Hridya > > But I think it would be good to have this all done. > -Daniel > > > > > > > > > Regards, > > > Christian. > > > > Best, > > Sumit. > > > > > > > > > > >>> --- > > > >>> Changes in v3: > > > >>> Fix a warning reported by the kernel test robot. > > > >>> > > > >>> Changes in v2: > > > >>> -Move statistics to /sys/kernel/dmabuf/buffers in oder to allow a= ddition > > > >>> of other DMA-BUF-related sysfs stats in future. Based on feedback= from > > > >>> Daniel Vetter. > > > >>> -Each attachment has its own directory to represent attaching dev= ices as > > > >>> symlinks and to introduce map_count as a separate file. Based on > > > >>> feedback from Daniel Vetter and Christian K=C3=B6nig. Thank you b= oth! > > > >>> -Commit messages updated to point to userspace code in AOSP that = will > > > >>> read the DMA-BUF sysfs stats. > > > >>> > > > >>> > > > >>> .../ABI/testing/sysfs-kernel-dmabuf-buffers | 52 ++++ > > > >>> drivers/dma-buf/Kconfig | 11 + > > > >>> drivers/dma-buf/Makefile | 1 + > > > >>> drivers/dma-buf/dma-buf-sysfs-stats.c | 285 +++++++++++= +++++++ > > > >>> drivers/dma-buf/dma-buf-sysfs-stats.h | 62 ++++ > > > >>> drivers/dma-buf/dma-buf.c | 37 +++ > > > >>> include/linux/dma-buf.h | 20 ++ > > > >>> 7 files changed, 468 insertions(+) > > > >>> create mode 100644 Documentation/ABI/testing/sysfs-kernel-dmabu= f-buffers > > > >>> create mode 100644 drivers/dma-buf/dma-buf-sysfs-stats.c > > > >>> create mode 100644 drivers/dma-buf/dma-buf-sysfs-stats.h > > > >> I don't know the dma-buf code at all, but from a sysfs/kobject poi= nt of > > > >> view, this patch looks good to me: > > > >> > > > >> Reviewed-by: Greg Kroah-Hartman > > > > Best, > > > > Sumit. > > > > _______________________________________________ > > > > Linaro-mm-sig mailing list > > > > Linaro-mm-sig@lists.linaro.org > > > > https://lists.linaro.org/mailman/listinfo/linaro-mm-sig > > > > > > > > > -- > > Thanks and regards, > > > > Sumit Semwal > > Linaro Consumer Group - Tech Lead > > Linaro.org =E2=94=82 Open source software for ARM SoCs > > _______________________________________________ > > dri-devel mailing list > > dri-devel@lists.freedesktop.org > > https://lists.freedesktop.org/mailman/listinfo/dri-devel > > > > -- > Daniel Vetter > Software Engineer, Intel Corporation > http://blog.ffwll.ch