1 // SPDX-License-Identifier: MIT
2 /*
3  * Copyright © 2024 Intel Corporation
4  */
5 
6 #include <linux/atomic.h>
7 
8 #include <drm/drm_print.h>
9 
10 #include "xe_gt.h"
11 #include "xe_gt_stats.h"
12 
13 /**
14  * xe_gt_stats_incr - Increments the specified stats counter
15  * @gt: GT structure
16  * @id: xe_gt_stats_id type id that needs to be incremented
17  * @incr: value to be incremented with
18  *
19  * Increments the specified stats counter.
20  */
xe_gt_stats_incr(struct xe_gt * gt,const enum xe_gt_stats_id id,int incr)21 void xe_gt_stats_incr(struct xe_gt *gt, const enum xe_gt_stats_id id, int incr)
22 {
23 	if (id >= __XE_GT_STATS_NUM_IDS)
24 		return;
25 
26 	atomic64_add(incr, &gt->stats.counters[id]);
27 }
28 
29 static const char *const stat_description[__XE_GT_STATS_NUM_IDS] = {
30 	"tlb_inval_count",
31 	"vma_pagefault_count",
32 	"vma_pagefault_kb",
33 };
34 
35 /**
36  * xe_gt_stats_print_info - Print the GT stats
37  * @gt: GT structure
38  * @p: drm_printer where it will be printed out.
39  *
40  * This prints out all the available GT stats.
41  */
xe_gt_stats_print_info(struct xe_gt * gt,struct drm_printer * p)42 int xe_gt_stats_print_info(struct xe_gt *gt, struct drm_printer *p)
43 {
44 	enum xe_gt_stats_id id;
45 
46 	for (id = 0; id < __XE_GT_STATS_NUM_IDS; ++id)
47 		drm_printf(p, "%s: %lld\n", stat_description[id],
48 			   atomic64_read(&gt->stats.counters[id]));
49 
50 	return 0;
51 }
52