intel_engine_stats.h 1.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/* SPDX-License-Identifier: MIT */
/*
 * Copyright © 2020 Intel Corporation
 */

#ifndef __INTEL_ENGINE_STATS_H__
#define __INTEL_ENGINE_STATS_H__

#include <linux/atomic.h>
#include <linux/ktime.h>
#include <linux/seqlock.h>

#include "i915_gem.h" /* GEM_BUG_ON */
#include "intel_engine.h"

static inline void intel_engine_context_in(struct intel_engine_cs *engine)
{
	unsigned long flags;

20 21
	if (engine->stats.active) {
		engine->stats.active++;
22 23
		return;
	}
24 25 26 27 28 29 30 31 32 33 34 35

	/* The writer is serialised; but the pmu reader may be from hardirq */
	local_irq_save(flags);
	write_seqcount_begin(&engine->stats.lock);

	engine->stats.start = ktime_get();
	engine->stats.active++;

	write_seqcount_end(&engine->stats.lock);
	local_irq_restore(flags);

	GEM_BUG_ON(!engine->stats.active);
36 37 38 39 40 41
}

static inline void intel_engine_context_out(struct intel_engine_cs *engine)
{
	unsigned long flags;

42 43 44
	GEM_BUG_ON(!engine->stats.active);
	if (engine->stats.active > 1) {
		engine->stats.active--;
45 46
		return;
	}
47 48 49 50 51 52 53 54 55 56 57

	local_irq_save(flags);
	write_seqcount_begin(&engine->stats.lock);

	engine->stats.active--;
	engine->stats.total =
		ktime_add(engine->stats.total,
			  ktime_sub(ktime_get(), engine->stats.start));

	write_seqcount_end(&engine->stats.lock);
	local_irq_restore(flags);
58 59 60
}

#endif /* __INTEL_ENGINE_STATS_H__ */