File: intel_engine_stats.h

package info (click to toggle)
linux 6.1.8-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,488,076 kB
  • sloc: ansic: 23,401,844; asm: 266,744; sh: 108,976; makefile: 49,705; python: 36,927; perl: 36,810; cpp: 6,044; yacc: 4,904; lex: 2,722; awk: 1,440; ruby: 25; sed: 5
file content (61 lines) | stat: -rw-r--r-- 1,327 bytes parent folder | download | duplicates (15)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* 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)
{
	struct intel_engine_execlists_stats *stats = &engine->stats.execlists;
	unsigned long flags;

	if (stats->active) {
		stats->active++;
		return;
	}

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

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

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

	GEM_BUG_ON(!stats->active);
}

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

	GEM_BUG_ON(!stats->active);
	if (stats->active > 1) {
		stats->active--;
		return;
	}

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

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

	write_seqcount_end(&stats->lock);
	local_irq_restore(flags);
}

#endif /* __INTEL_ENGINE_STATS_H__ */