Skip to content

Commit ef75702

Browse files
Sai Prakash Ranjanwilldeacon
authored andcommitted
iommu/arm-smmu: Optimize ->tlb_flush_walk() for qcom implementation
Currently for iommu_unmap() of large scatter-gather list with page size elements, the majority of time is spent in flushing of partial walks in __arm_lpae_unmap() which is a VA based TLB invalidation invalidating page-by-page on iommus like arm-smmu-v2 (TLBIVA). For example: to unmap a 32MB scatter-gather list with page size elements (8192 entries), there are 16->2MB buffer unmaps based on the pgsize (2MB for 4K granule) and each of 2MB will further result in 512 TLBIVAs (2MB/4K) resulting in a total of 8192 TLBIVAs (512*16) for 16->2MB causing a huge overhead. On qcom implementation, there are several performance improvements for TLB cache invalidations in HW like wait-for-safe (for realtime clients such as camera and display) and few others to allow for cache lookups/updates when TLBI is in progress for the same context bank. So the cost of over-invalidation is less compared to the unmap latency on several usecases like camera which deals with large buffers. So, ASID based TLB invalidations (TLBIASID) can be used to invalidate the entire context for partial walk flush thereby improving the unmap latency. For this example of 32MB scatter-gather list unmap, this change results in just 16 ASID based TLB invalidations (TLBIASIDs) as opposed to 8192 TLBIVAs thereby increasing the performance of unmaps drastically. Test on QTI SM8150 SoC for 10 iterations of iommu_{map_sg}/unmap: (average over 10 iterations) Before this optimization: size iommu_map_sg iommu_unmap 4K 2.067 us 1.854 us 64K 9.598 us 8.802 us 1M 148.890 us 130.718 us 2M 305.864 us 67.291 us 12M 1793.604 us 390.838 us 16M 2386.848 us 518.187 us 24M 3563.296 us 775.989 us 32M 4747.171 us 1033.364 us After this optimization: size iommu_map_sg iommu_unmap 4K 1.723 us 1.765 us 64K 9.880 us 8.869 us 1M 155.364 us 135.223 us 2M 303.906 us 5.385 us 12M 1786.557 us 21.250 us 16M 2391.890 us 27.437 us 24M 3570.895 us 39.937 us 32M 4755.234 us 51.797 us Real world data also shows big difference in unmap performance as below: There were reports of camera frame drops because of high overhead in iommu unmap without this optimization because of frequent unmaps issued by camera of about 100MB/s taking more than 100ms thereby causing frame drops. Signed-off-by: Sai Prakash Ranjan <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent b1a1347 commit ef75702

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ static int qcom_adreno_smmu_init_context(struct arm_smmu_domain *smmu_domain,
193193
{
194194
struct adreno_smmu_priv *priv;
195195

196+
smmu_domain->cfg.flush_walk_prefer_tlbiasid = true;
197+
196198
/* Only enable split pagetables for the GPU device (SID 0) */
197199
if (!qcom_adreno_smmu_is_gpu_device(dev))
198200
return 0;
@@ -235,6 +237,14 @@ static const struct of_device_id qcom_smmu_client_of_match[] __maybe_unused = {
235237
{ }
236238
};
237239

240+
static int qcom_smmu_init_context(struct arm_smmu_domain *smmu_domain,
241+
struct io_pgtable_cfg *pgtbl_cfg, struct device *dev)
242+
{
243+
smmu_domain->cfg.flush_walk_prefer_tlbiasid = true;
244+
245+
return 0;
246+
}
247+
238248
static int qcom_smmu_cfg_probe(struct arm_smmu_device *smmu)
239249
{
240250
unsigned int last_s2cr = ARM_SMMU_GR0_S2CR(smmu->num_mapping_groups - 1);
@@ -358,6 +368,7 @@ static int qcom_smmu500_reset(struct arm_smmu_device *smmu)
358368
}
359369

360370
static const struct arm_smmu_impl qcom_smmu_impl = {
371+
.init_context = qcom_smmu_init_context,
361372
.cfg_probe = qcom_smmu_cfg_probe,
362373
.def_domain_type = qcom_smmu_def_domain_type,
363374
.reset = qcom_smmu500_reset,

drivers/iommu/arm/arm-smmu/arm-smmu.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,16 @@ static void arm_smmu_tlb_inv_range_s2(unsigned long iova, size_t size,
327327
static void arm_smmu_tlb_inv_walk_s1(unsigned long iova, size_t size,
328328
size_t granule, void *cookie)
329329
{
330-
arm_smmu_tlb_inv_range_s1(iova, size, granule, cookie,
331-
ARM_SMMU_CB_S1_TLBIVA);
332-
arm_smmu_tlb_sync_context(cookie);
330+
struct arm_smmu_domain *smmu_domain = cookie;
331+
struct arm_smmu_cfg *cfg = &smmu_domain->cfg;
332+
333+
if (cfg->flush_walk_prefer_tlbiasid) {
334+
arm_smmu_tlb_inv_context_s1(cookie);
335+
} else {
336+
arm_smmu_tlb_inv_range_s1(iova, size, granule, cookie,
337+
ARM_SMMU_CB_S1_TLBIVA);
338+
arm_smmu_tlb_sync_context(cookie);
339+
}
333340
}
334341

335342
static void arm_smmu_tlb_add_page_s1(struct iommu_iotlb_gather *gather,

drivers/iommu/arm/arm-smmu/arm-smmu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ struct arm_smmu_cfg {
346346
};
347347
enum arm_smmu_cbar_type cbar;
348348
enum arm_smmu_context_fmt fmt;
349+
bool flush_walk_prefer_tlbiasid;
349350
};
350351
#define ARM_SMMU_INVALID_IRPTNDX 0xff
351352

0 commit comments

Comments
 (0)