Skip to content

Commit df7d085

Browse files
committed
drm/i915: split out i915_timer_util.[ch]
Move timer related utilities from i915_utils.[ch] to separate new files i915_timer_util.[ch]. Clean up related includes. Note: Arguably none of this should exist in i915 in the first place. At least isolate it better. Reviewed-by: Rodrigo Vivi <[email protected]> Link: https://lore.kernel.org/r/0a83d9489626121dcefcd4c1a05317399b5708f3.1757582214.git.jani.nikula@intel.com Signed-off-by: Jani Nikula <[email protected]>
1 parent a394f12 commit df7d085

File tree

7 files changed

+64
-45
lines changed

7 files changed

+64
-45
lines changed

drivers/gpu/drm/i915/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ i915-y += \
3232
i915_scatterlist.o \
3333
i915_switcheroo.o \
3434
i915_sysfs.o \
35+
i915_timer_util.o \
3536
i915_utils.o \
3637
intel_clock_gating.o \
3738
intel_cpu_info.o \

drivers/gpu/drm/i915/gt/intel_execlists_submission.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,16 @@
106106
* preemption, but just sampling the new tail pointer).
107107
*
108108
*/
109+
109110
#include <linux/interrupt.h>
110111
#include <linux/string_helpers.h>
111112

113+
#include "gen8_engine_cs.h"
112114
#include "i915_drv.h"
113115
#include "i915_reg.h"
116+
#include "i915_timer_util.h"
114117
#include "i915_trace.h"
115118
#include "i915_vgpu.h"
116-
#include "gen8_engine_cs.h"
117119
#include "intel_breadcrumbs.h"
118120
#include "intel_context.h"
119121
#include "intel_engine_heartbeat.h"

drivers/gpu/drm/i915/gt/sysfs_engines.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <linux/sysfs.h>
88

99
#include "i915_drv.h"
10+
#include "i915_timer_util.h"
1011
#include "intel_engine.h"
1112
#include "intel_engine_heartbeat.h"
1213
#include "sysfs_engines.h"
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// SPDX-License-Identifier: MIT
2+
/* Copyright © 2025 Intel Corporation */
3+
4+
#include <linux/jiffies.h>
5+
6+
#include "i915_timer_util.h"
7+
8+
void cancel_timer(struct timer_list *t)
9+
{
10+
if (!timer_active(t))
11+
return;
12+
13+
timer_delete(t);
14+
WRITE_ONCE(t->expires, 0);
15+
}
16+
17+
void set_timer_ms(struct timer_list *t, unsigned long timeout)
18+
{
19+
if (!timeout) {
20+
cancel_timer(t);
21+
return;
22+
}
23+
24+
timeout = msecs_to_jiffies(timeout);
25+
26+
/*
27+
* Paranoia to make sure the compiler computes the timeout before
28+
* loading 'jiffies' as jiffies is volatile and may be updated in
29+
* the background by a timer tick. All to reduce the complexity
30+
* of the addition and reduce the risk of losing a jiffy.
31+
*/
32+
barrier();
33+
34+
/* Keep t->expires = 0 reserved to indicate a canceled timer. */
35+
mod_timer(t, jiffies + timeout ?: 1);
36+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* SPDX-License-Identifier: MIT */
2+
/* Copyright © 2025 Intel Corporation */
3+
4+
#ifndef __I915_TIMER_UTIL_H__
5+
#define __I915_TIMER_UTIL_H__
6+
7+
#include <linux/timer.h>
8+
#include <asm/rwonce.h>
9+
10+
void cancel_timer(struct timer_list *t);
11+
void set_timer_ms(struct timer_list *t, unsigned long timeout);
12+
13+
static inline bool timer_active(const struct timer_list *t)
14+
{
15+
return READ_ONCE(t->expires);
16+
}
17+
18+
static inline bool timer_expired(const struct timer_list *t)
19+
{
20+
return timer_active(t) && !timer_pending(t);
21+
}
22+
23+
#endif /* __I915_TIMER_UTIL_H__ */

drivers/gpu/drm/i915/i915_utils.c

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -47,36 +47,6 @@ bool i915_error_injected(void)
4747

4848
#endif
4949

50-
void cancel_timer(struct timer_list *t)
51-
{
52-
if (!timer_active(t))
53-
return;
54-
55-
timer_delete(t);
56-
WRITE_ONCE(t->expires, 0);
57-
}
58-
59-
void set_timer_ms(struct timer_list *t, unsigned long timeout)
60-
{
61-
if (!timeout) {
62-
cancel_timer(t);
63-
return;
64-
}
65-
66-
timeout = msecs_to_jiffies(timeout);
67-
68-
/*
69-
* Paranoia to make sure the compiler computes the timeout before
70-
* loading 'jiffies' as jiffies is volatile and may be updated in
71-
* the background by a timer tick. All to reduce the complexity
72-
* of the addition and reduce the risk of losing a jiffy.
73-
*/
74-
barrier();
75-
76-
/* Keep t->expires = 0 reserved to indicate a canceled timer. */
77-
mod_timer(t, jiffies + timeout ?: 1);
78-
}
79-
8050
bool i915_vtd_active(struct drm_i915_private *i915)
8151
{
8252
if (device_iommu_mapped(i915->drm.dev))

drivers/gpu/drm/i915/i915_utils.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
#endif
3939

4040
struct drm_i915_private;
41-
struct timer_list;
4241

4342
#define MISSING_CASE(x) WARN(1, "Missing case (%s == %ld)\n", \
4443
__stringify(x), (long)(x))
@@ -270,19 +269,6 @@ static inline void __add_taint_for_CI(unsigned int taint)
270269
add_taint(taint, LOCKDEP_STILL_OK);
271270
}
272271

273-
void cancel_timer(struct timer_list *t);
274-
void set_timer_ms(struct timer_list *t, unsigned long timeout);
275-
276-
static inline bool timer_active(const struct timer_list *t)
277-
{
278-
return READ_ONCE(t->expires);
279-
}
280-
281-
static inline bool timer_expired(const struct timer_list *t)
282-
{
283-
return timer_active(t) && !timer_pending(t);
284-
}
285-
286272
static inline bool i915_run_as_guest(void)
287273
{
288274
#if IS_ENABLED(CONFIG_X86)

0 commit comments

Comments
 (0)