Browse Source

iommu/arm-smmu-v3: Use burst-polling for sync completion

While CMD_SYNC is unlikely to complete immediately such that we never go
round the polling loop, with a lightly-loaded queue it may still do so
long before the delay period is up. If we have no better completion
notifier, use similar logic as we have for SMMUv2 to spin a number of
times before each backoff, so that we have more chance of catching syncs
which complete relatively quickly and avoid delaying unnecessarily.

Signed-off-by: Robin Murphy <robin.murphy@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
Robin Murphy 8 years ago
parent
commit
8ff0f72371
1 changed files with 6 additions and 2 deletions
  1. 6 2
      drivers/iommu/arm-smmu-v3.c

+ 6 - 2
drivers/iommu/arm-smmu-v3.c

@@ -419,6 +419,7 @@
 /* High-level queue structures */
 /* High-level queue structures */
 #define ARM_SMMU_POLL_TIMEOUT_US	100
 #define ARM_SMMU_POLL_TIMEOUT_US	100
 #define ARM_SMMU_CMDQ_SYNC_TIMEOUT_US	1000000 /* 1s! */
 #define ARM_SMMU_CMDQ_SYNC_TIMEOUT_US	1000000 /* 1s! */
+#define ARM_SMMU_CMDQ_SYNC_SPIN_COUNT	10
 
 
 #define MSI_IOVA_BASE			0x8000000
 #define MSI_IOVA_BASE			0x8000000
 #define MSI_IOVA_LENGTH			0x100000
 #define MSI_IOVA_LENGTH			0x100000
@@ -769,7 +770,7 @@ static void queue_inc_prod(struct arm_smmu_queue *q)
 static int queue_poll_cons(struct arm_smmu_queue *q, bool sync, bool wfe)
 static int queue_poll_cons(struct arm_smmu_queue *q, bool sync, bool wfe)
 {
 {
 	ktime_t timeout;
 	ktime_t timeout;
-	unsigned int delay = 1;
+	unsigned int delay = 1, spin_cnt = 0;
 
 
 	/* Wait longer if it's a CMD_SYNC */
 	/* Wait longer if it's a CMD_SYNC */
 	timeout = ktime_add_us(ktime_get(), sync ?
 	timeout = ktime_add_us(ktime_get(), sync ?
@@ -782,10 +783,13 @@ static int queue_poll_cons(struct arm_smmu_queue *q, bool sync, bool wfe)
 
 
 		if (wfe) {
 		if (wfe) {
 			wfe();
 			wfe();
-		} else {
+		} else if (++spin_cnt < ARM_SMMU_CMDQ_SYNC_SPIN_COUNT) {
 			cpu_relax();
 			cpu_relax();
+			continue;
+		} else {
 			udelay(delay);
 			udelay(delay);
 			delay *= 2;
 			delay *= 2;
+			spin_cnt = 0;
 		}
 		}
 	}
 	}