xref: /linux/drivers/gpu/drm/xe/xe_gt_stats.h (revision 1fd1dc41724319406b0aff221a352a400b0ddfc5)
1 /* SPDX-License-Identifier: MIT */
2 /*
3  * Copyright © 2024 Intel Corporation
4  */
5 
6 #ifndef _XE_GT_STATS_H_
7 #define _XE_GT_STATS_H_
8 
9 #include <linux/ktime.h>
10 
11 #include "xe_gt_stats_types.h"
12 
13 struct xe_gt;
14 struct drm_printer;
15 
16 #ifdef CONFIG_DEBUG_FS
17 int xe_gt_stats_print_info(struct xe_gt *gt, struct drm_printer *p);
18 void xe_gt_stats_clear(struct xe_gt *gt);
19 void xe_gt_stats_incr(struct xe_gt *gt, const enum xe_gt_stats_id id, int incr);
20 #else
21 static inline void
22 xe_gt_stats_incr(struct xe_gt *gt, const enum xe_gt_stats_id id,
23 		 int incr)
24 {
25 }
26 
27 #endif
28 
29 /**
30  * xe_gt_stats_ktime_us_delta() - Get delta in microseconds between now and a
31  * start time
32  * @start: Start time
33  *
34  * Helper for GT stats to get delta in microseconds between now and a start
35  * time, compiles out if GT stats are disabled.
36  *
37  * Return: Delta in microseconds between now and a start time
38  */
39 static inline s64 xe_gt_stats_ktime_us_delta(ktime_t start)
40 {
41 	return IS_ENABLED(CONFIG_DEBUG_FS) ?
42 		ktime_us_delta(ktime_get(), start) : 0;
43 }
44 
45 /**
46  * xe_gt_stats_ktime_get() - Get current ktime
47  *
48  * Helper for GT stats to get current ktime, compiles out if GT stats are
49  * disabled.
50  *
51  * Return: Get current ktime
52  */
53 static inline ktime_t xe_gt_stats_ktime_get(void)
54 {
55 	return IS_ENABLED(CONFIG_DEBUG_FS) ? ktime_get() : 0;
56 }
57 
58 #endif
59