Commit df7d085b authored by Jani Nikula's avatar Jani Nikula
Browse files

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: default avatarRodrigo Vivi <rodrigo.vivi@intel.com>
Link: https://lore.kernel.org/r/0a83d9489626121dcefcd4c1a05317399b5708f3.1757582214.git.jani.nikula@intel.com


Signed-off-by: default avatarJani Nikula <jani.nikula@intel.com>
parent a394f12a
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ i915-y += \
	i915_scatterlist.o \
	i915_switcheroo.o \
	i915_sysfs.o \
	i915_timer_util.o \
	i915_utils.o \
	intel_clock_gating.o \
	intel_cpu_info.o \
+3 −1
Original line number Diff line number Diff line
@@ -106,14 +106,16 @@
 * preemption, but just sampling the new tail pointer).
 *
 */

#include <linux/interrupt.h>
#include <linux/string_helpers.h>

#include "gen8_engine_cs.h"
#include "i915_drv.h"
#include "i915_reg.h"
#include "i915_timer_util.h"
#include "i915_trace.h"
#include "i915_vgpu.h"
#include "gen8_engine_cs.h"
#include "intel_breadcrumbs.h"
#include "intel_context.h"
#include "intel_engine_heartbeat.h"
+1 −0
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@
#include <linux/sysfs.h>

#include "i915_drv.h"
#include "i915_timer_util.h"
#include "intel_engine.h"
#include "intel_engine_heartbeat.h"
#include "sysfs_engines.h"
+36 −0
Original line number Diff line number Diff line
// SPDX-License-Identifier: MIT
/* Copyright © 2025 Intel Corporation */

#include <linux/jiffies.h>

#include "i915_timer_util.h"

void cancel_timer(struct timer_list *t)
{
	if (!timer_active(t))
		return;

	timer_delete(t);
	WRITE_ONCE(t->expires, 0);
}

void set_timer_ms(struct timer_list *t, unsigned long timeout)
{
	if (!timeout) {
		cancel_timer(t);
		return;
	}

	timeout = msecs_to_jiffies(timeout);

	/*
	 * Paranoia to make sure the compiler computes the timeout before
	 * loading 'jiffies' as jiffies is volatile and may be updated in
	 * the background by a timer tick. All to reduce the complexity
	 * of the addition and reduce the risk of losing a jiffy.
	 */
	barrier();

	/* Keep t->expires = 0 reserved to indicate a canceled timer. */
	mod_timer(t, jiffies + timeout ?: 1);
}
+23 −0
Original line number Diff line number Diff line
/* SPDX-License-Identifier: MIT */
/* Copyright © 2025 Intel Corporation */

#ifndef __I915_TIMER_UTIL_H__
#define __I915_TIMER_UTIL_H__

#include <linux/timer.h>
#include <asm/rwonce.h>

void cancel_timer(struct timer_list *t);
void set_timer_ms(struct timer_list *t, unsigned long timeout);

static inline bool timer_active(const struct timer_list *t)
{
	return READ_ONCE(t->expires);
}

static inline bool timer_expired(const struct timer_list *t)
{
	return timer_active(t) && !timer_pending(t);
}

#endif /* __I915_TIMER_UTIL_H__ */
Loading