Skip to content

Commit fecae13

Browse files
davejiangvinodkoul
authored andcommitted
dmaengine: idxd: add per file user counters for completion record faults
Add counters per opened file for the char device in order to keep track how many completion record faults occurred and how many of those faults failed the writeback by the driver after attempt to fault in the page. The counters are managed by xarray that associates the PASID with struct idxd_user_context. Tested-by: Tony Zhu <[email protected]> Signed-off-by: Dave Jiang <[email protected]> Co-developed-by: Fenghua Yu <[email protected]> Signed-off-by: Fenghua Yu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vinod Koul <[email protected]>
1 parent 2442b74 commit fecae13

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

drivers/dma/idxd/cdev.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ struct idxd_user_context {
3939
struct mm_struct *mm;
4040
unsigned int flags;
4141
struct iommu_sva *sva;
42+
u64 counters[COUNTER_MAX];
4243
};
4344

4445
static void idxd_cdev_dev_release(struct device *dev)
@@ -84,6 +85,23 @@ static void idxd_xa_pasid_remove(struct idxd_user_context *ctx)
8485
mutex_unlock(&wq->uc_lock);
8586
}
8687

88+
void idxd_user_counter_increment(struct idxd_wq *wq, u32 pasid, int index)
89+
{
90+
struct idxd_user_context *ctx;
91+
92+
if (index >= COUNTER_MAX)
93+
return;
94+
95+
mutex_lock(&wq->uc_lock);
96+
ctx = xa_load(&wq->upasid_xa, pasid);
97+
if (!ctx) {
98+
mutex_unlock(&wq->uc_lock);
99+
return;
100+
}
101+
ctx->counters[index]++;
102+
mutex_unlock(&wq->uc_lock);
103+
}
104+
87105
static int idxd_cdev_open(struct inode *inode, struct file *filp)
88106
{
89107
struct idxd_user_context *ctx;

drivers/dma/idxd/idxd.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@ struct idxd_pmu {
127127

128128
#define IDXD_MAX_PRIORITY 0xf
129129

130+
enum {
131+
COUNTER_FAULTS = 0,
132+
COUNTER_FAULT_FAILS,
133+
COUNTER_MAX
134+
};
135+
130136
enum idxd_wq_state {
131137
IDXD_WQ_DISABLED = 0,
132138
IDXD_WQ_ENABLED,
@@ -713,6 +719,7 @@ int idxd_wq_add_cdev(struct idxd_wq *wq);
713719
void idxd_wq_del_cdev(struct idxd_wq *wq);
714720
int idxd_copy_cr(struct idxd_wq *wq, ioasid_t pasid, unsigned long addr,
715721
void *buf, int len);
722+
void idxd_user_counter_increment(struct idxd_wq *wq, u32 pasid, int index);
716723

717724
/* perfmon */
718725
#if IS_ENABLED(CONFIG_INTEL_IDXD_PERFMON)

drivers/dma/idxd/irq.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ static void idxd_evl_fault_work(struct work_struct *work)
240240
evl->batch_fail[entry_head->batch_id] = false;
241241

242242
copy_size = cr_size;
243+
idxd_user_counter_increment(wq, entry_head->pasid, COUNTER_FAULTS);
243244
break;
244245
case DSA_COMP_BATCH_EVL_ERR:
245246
bf = &evl->batch_fail[entry_head->batch_id];
@@ -251,6 +252,7 @@ static void idxd_evl_fault_work(struct work_struct *work)
251252
*result = 1;
252253
*bf = false;
253254
}
255+
idxd_user_counter_increment(wq, entry_head->pasid, COUNTER_FAULTS);
254256
break;
255257
case DSA_COMP_DRAIN_EVL:
256258
copy_size = cr_size;
@@ -282,6 +284,7 @@ static void idxd_evl_fault_work(struct work_struct *work)
282284
switch (fault->status) {
283285
case DSA_COMP_CRA_XLAT:
284286
if (copied != copy_size) {
287+
idxd_user_counter_increment(wq, entry_head->pasid, COUNTER_FAULT_FAILS);
285288
dev_dbg_ratelimited(dev, "Failed to write to completion record: (%d:%d)\n",
286289
copy_size, copied);
287290
if (entry_head->batch)
@@ -290,6 +293,7 @@ static void idxd_evl_fault_work(struct work_struct *work)
290293
break;
291294
case DSA_COMP_BATCH_EVL_ERR:
292295
if (copied != copy_size) {
296+
idxd_user_counter_increment(wq, entry_head->pasid, COUNTER_FAULT_FAILS);
293297
dev_dbg_ratelimited(dev, "Failed to write to batch completion record: (%d:%d)\n",
294298
copy_size, copied);
295299
}

0 commit comments

Comments
 (0)