• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 /*
3  *
4  * (C) COPYRIGHT 2020-2021 ARM Limited. All rights reserved.
5  *
6  * This program is free software and is provided to you under the terms of the
7  * GNU General Public License version 2 as published by the Free Software
8  * Foundation, and any use by you of this program is subject to the terms
9  * of such GNU license.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you can access it online at
18  * http://www.gnu.org/licenses/gpl-2.0.html.
19  *
20  */
21 
22 #ifndef _KBASE_CCSWE_H_
23 #define _KBASE_CCSWE_H_
24 
25 #include <linux/spinlock.h>
26 
27 /**
28  * struct kbase_ccswe - Cycle count software estimator.
29  *
30  * @access:         Spinlock protecting this structure access.
31  * @timestamp_ns:   Timestamp(ns) when the last frequency change
32  *                  occurred.
33  * @cycles_elapsed: Number of cycles elapsed before the last frequency
34  *                  change
35  * @gpu_freq:       Current GPU frequency(Hz) value.
36  * @prev_gpu_freq:  Previous GPU frequency(Hz) before the last frequency
37  *                  change.
38  */
39 struct kbase_ccswe {
40 	spinlock_t access;
41 	u64 timestamp_ns;
42 	u64 cycles_elapsed;
43 	u32 gpu_freq;
44 	u32 prev_gpu_freq;
45 };
46 
47 /**
48  * kbase_ccswe_init() - initialize the cycle count estimator.
49  *
50  * @self: Cycles count software estimator instance.
51  */
52 void kbase_ccswe_init(struct kbase_ccswe *self);
53 
54 
55 /**
56  * kbase_ccswe_cycle_at() - Estimate cycle count at given timestamp.
57  *
58  * @self: Cycles count software estimator instance.
59  * @timestamp_ns: The timestamp(ns) for cycle count estimation.
60  *
61  * The timestamp must be bigger than the timestamp of the penultimate
62  * frequency change. If only one frequency change occurred, the
63  * timestamp must be bigger than the timestamp of the frequency change.
64  * This is to allow the following code to be executed w/o synchronization.
65  * If lines below executed atomically, it is safe to assume that only
66  * one frequency change may happen in between.
67  *
68  *     u64 ts = ktime_get_raw_ns();
69  *     u64 cycle = kbase_ccswe_cycle_at(&ccswe, ts)
70  *
71  * Returns: estimated value of cycle count at a given time.
72  */
73 u64 kbase_ccswe_cycle_at(struct kbase_ccswe *self, u64 timestamp_ns);
74 
75 /**
76  * kbase_ccswe_freq_change() - update GPU frequency.
77  *
78  * @self:         Cycles count software estimator instance.
79  * @timestamp_ns: Timestamp(ns) when frequency change occurred.
80  * @gpu_freq:     New GPU frequency value.
81  *
82  * The timestamp must be bigger than the timestamp of the previous
83  * frequency change. The function is to be called at the frequency
84  * change moment (not later).
85  */
86 void kbase_ccswe_freq_change(
87 	struct kbase_ccswe *self, u64 timestamp_ns, u32 gpu_freq);
88 
89 /**
90  * kbase_ccswe_reset() - reset estimator state
91  *
92  * @self:    Cycles count software estimator instance.
93  */
94 void kbase_ccswe_reset(struct kbase_ccswe *self);
95 
96 #endif /* _KBASE_CCSWE_H_ */
97