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
/* 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)
{
18
	struct intel_engine_execlists_stats *stats = &engine->stats.execlists;
19 20
	unsigned long flags;

21 22
	if (stats->active) {
		stats->active++;
23 24
		return;
	}
25 26 27

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

30 31
	stats->start = ktime_get();
	stats->active++;
32

33
	write_seqcount_end(&stats->lock);
34 35
	local_irq_restore(flags);

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

static inline void intel_engine_context_out(struct intel_engine_cs *engine)
{
41
	struct intel_engine_execlists_stats *stats = &engine->stats.execlists;
42 43
	unsigned long flags;

44 45 46
	GEM_BUG_ON(!stats->active);
	if (stats->active > 1) {
		stats->active--;
47 48
		return;
	}
49 50

	local_irq_save(flags);
51
	write_seqcount_begin(&stats->lock);
52

53 54 55
	stats->active--;
	stats->total = ktime_add(stats->total,
				 ktime_sub(ktime_get(), stats->start));
56

57
	write_seqcount_end(&stats->lock);
58
	local_irq_restore(flags);
59 60 61
}

#endif /* __INTEL_ENGINE_STATS_H__ */