Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4076669imu; Mon, 10 Dec 2018 12:42:24 -0800 (PST) X-Google-Smtp-Source: AFSGD/WFN5zcT752xWBj2ZAzKpYwN8+63vq0ek3VL57Fdw77VkMTP9zHPHwY2ooYJe60kkW7wdEb X-Received: by 2002:a17:902:ac8f:: with SMTP id h15mr12962324plr.245.1544474544145; Mon, 10 Dec 2018 12:42:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544474544; cv=none; d=google.com; s=arc-20160816; b=lYOC8QPDapH0/LLh3kL12C/ld4BDHRfY5pW0Wb/5nxTFUdy5efu9I71agdCqLr3hNM FcDSkVIwObkNnmKXSUQACiJWLVNyGqPfyjLAr9NJgkFfTnLJRHTr/jDN/gxMsCNmohSL o9OBwS4T2MWcukMC/JEbQEsG5EZJrFVTWLzneq9RC7plnHzL8ulLa/q2K4sF1vHMCKTH f+N8gV3BSq8luU9kNsYr2Wixg+uE6wCfDq9LQanSZ6QcynZQfQOPn2SnT2I7jrIhNf/V SQ+pjyGH8AuhYl56eH1c+uhL3c7IyJF7ni/karIWWvDdoPTQ27P9FY1vGge+B56PcY9n qUFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=uO+ufUU82TWadQrMXqULUVdOCHrLDfhG2uAIkwhjmlA=; b=tKHeYYjmarSX0FRWVJtZqiGeu+MYBtI8zzfuwmWeT9Jav5v8SNUCXUM9C4IhdoFBmh xh1gJ9SxSwvO58G9o3GjfNE6IrKhttMnVWdHuBjLzddvWux0QbDZ1QwgofrjbhYjTXHb 3YXCdYL+xxtfDTtP741sJWhm8fJsyAn8WSU54jF3Krj81Y19F2ng7AccJkglHh0WyxZ/ fTUChHC0VsuXl53kI+C2/vAAZ6g1MBITB8WHVYCs4rb83duICQu4q5uyvGOzNrmJC8gG uHjI3Ip7lISF7EE+eJGOUdNMKxUXW4ACKpx2aS2lulDUnizhufL3A4xwxt4tgGBCfTy4 E3+A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x32si10129647pgk.309.2018.12.10.12.42.08; Mon, 10 Dec 2018 12:42:24 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729688AbeLJUAV convert rfc822-to-8bit (ORCPT + 99 others); Mon, 10 Dec 2018 15:00:21 -0500 Received: from mga14.intel.com ([192.55.52.115]:29399 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728290AbeLJUAS (ORCPT ); Mon, 10 Dec 2018 15:00:18 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Dec 2018 12:00:17 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,339,1539673200"; d="scan'208";a="97676935" Received: from schen9-mobl3.jf.intel.com ([10.24.9.33]) by orsmga007.jf.intel.com with ESMTP; 10 Dec 2018 12:00:17 -0800 Subject: Re: [PATCH v2 1/2] swiotlb: add debugfs to track swiotlb buffer usage To: Dongli Zhang , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org Cc: konrad.wilk@oracle.com, hch@lst.de, m.szyprowski@samsung.com, robin.murphy@arm.com, joe.jin@oracle.com References: <1544402278-8175-1-git-send-email-dongli.zhang@oracle.com> From: Tim Chen Message-ID: <41becd27-8c3a-da2b-e5ed-e361ba20e4d4@linux.intel.com> Date: Mon, 10 Dec 2018 12:00:17 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.1 MIME-Version: 1.0 In-Reply-To: <1544402278-8175-1-git-send-email-dongli.zhang@oracle.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 12/9/18 4:37 PM, Dongli Zhang wrote: > > diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c > index 045930e..3979c2c 100644 > --- a/kernel/dma/swiotlb.c > +++ b/kernel/dma/swiotlb.c > @@ -35,6 +35,9 @@ > #include > #include > #include > +#ifdef CONFIG_DEBUG_FS > +#include > +#endif Seems like #ifdef CONFIG_DEBUG_FS is better located inside debugfs.h, instead of requiring every file that includes it to have a #ifdef CONFIG_DEBUG_FS. > > #include > #include > @@ -73,6 +76,13 @@ static phys_addr_t io_tlb_start, io_tlb_end; > */ > static unsigned long io_tlb_nslabs; > > +#ifdef CONFIG_DEBUG_FS > +/* > + * The number of used IO TLB block > + */ > +static unsigned long io_tlb_used; > +#endif > + > /* > * This is a free list describing the number of free entries available from > * each index > @@ -528,6 +538,9 @@ phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, > dev_warn(hwdev, "swiotlb buffer is full (sz: %zd bytes)\n", size); > return SWIOTLB_MAP_ERROR; > found: > +#ifdef CONFIG_DEBUG_FS > + io_tlb_used += nslots; > +#endif One nit I have about this patch is there are too many CONFIG_DEBUG_FS. For example here, instead of io_tlb_used, we can have a macro defined, perhaps something like inc_iotlb_used(nslots). It can be placed in the same section that swiotlb_create_debugfs is defined so there's a single place where all the CONFIG_DEBUG_FS stuff is located. Then define inc_iotlb_used to be null when we don't have CONFIG_DEBUG_FS. > spin_unlock_irqrestore(&io_tlb_lock, flags); > > /* > @@ -588,6 +601,10 @@ void swiotlb_tbl_unmap_single(struct device *hwdev, phys_addr_t tlb_addr, > */ > for (i = index - 1; (OFFSET(i, IO_TLB_SEGSIZE) != IO_TLB_SEGSIZE -1) && io_tlb_list[i]; i--) > io_tlb_list[i] = ++count; > + > +#ifdef CONFIG_DEBUG_FS > + io_tlb_used -= nslots; > +#endif > } > spin_unlock_irqrestore(&io_tlb_lock, flags); > } > @@ -883,3 +900,36 @@ const struct dma_map_ops swiotlb_dma_ops = { > .dma_supported = dma_direct_supported, > }; > EXPORT_SYMBOL(swiotlb_dma_ops); > + > +#ifdef CONFIG_DEBUG_FS > + Maybe move io_tlb_used definition here and define inc_iotlb_used here. > +static int __init swiotlb_create_debugfs(void) > +{ > + static struct dentry *d_swiotlb_usage; > + struct dentry *ent; > + > + d_swiotlb_usage = debugfs_create_dir("swiotlb", NULL); > + > + if (!d_swiotlb_usage) > + return -ENOMEM; > + > + ent = debugfs_create_ulong("io_tlb_nslabs", 0400, > + d_swiotlb_usage, &io_tlb_nslabs); > + if (!ent) > + goto fail; > + > + ent = debugfs_create_ulong("io_tlb_used", 0400, > + d_swiotlb_usage, &io_tlb_used); > + if (!ent) > + goto fail; > + > + return 0; > + > +fail: > + debugfs_remove_recursive(d_swiotlb_usage); > + return -ENOMEM; > +} > + > +late_initcall(swiotlb_create_debugfs); > + > +#endif > Thanks. Tim