summaryrefslogtreecommitdiff
path: root/power-libperfmgr/power-helper.h
blob: eebd0f9e2003ae8119d8b1b16d8b70deed21515c (plain)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
 * Copyright (c) 2018, The Linux Foundation. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 * *    * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above
 *       copyright notice, this list of conditions and the following
 *       disclaimer in the documentation and/or other materials provided
 *       with the distribution.
 *     * Neither the name of The Linux Foundation nor the names of its
 *       contributors may be used to endorse or promote products derived
 *       from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef __POWER_HELPER_H__
#define __POWER_HELPER_H__

#ifdef __cplusplus
extern "C" {
#endif

// These values are used as indices in getSubsystemLowPowerStats(), as source IDs
// in stats_section instances, and (in the case of the _COUNT values) to dimension
// containers.  The values used as indices need to be contiguous, but others do
// not (which is why SYSTEM_STATES is all the way at the end; it is not used as
// an index, but only as a source ID).
enum stats_source {
    // Master stats
    MASTER_APSS = 0,
    MASTER_MPSS,
    MASTER_ADSP,
    MASTER_SLPI,
    MASTER_CDSP,  // Not technically used, but included for precautionary stats tracking
    // The following masters are supported by the RPMh stats driver, but not
    // in use on our devices.
    // MASTER_GPU,
    // MASTER_DISPLAY,
    MASTER_COUNT, // Total master sources

    // Subsystem stats.  (Numbering starts at MASTER_COUNT to preserve
    // contiguous source numbering.)
    SUBSYSTEM_WLAN = MASTER_COUNT,
    // Uncomment when Citadel returns
    //SUBSYSTEM_CITADEL,

    // Don't add any lines after this line
    STATS_SOURCE_COUNT, // Total sources of any kind excluding system states
    SUBSYSTEM_COUNT = STATS_SOURCE_COUNT - MASTER_COUNT,

    SYSTEM_STATES
};

enum master_sleep_states {
    MASTER_SLEEP = 0,

    // Don't add any lines after this line
    MASTER_SLEEP_STATE_COUNT
};

enum master_stats {
    SLEEP_CUMULATIVE_DURATION_MS = 0,
    SLEEP_ENTER_COUNT,
    SLEEP_LAST_ENTER_TSTAMP_MS,

    // Don't add any lines after this line
    MASTER_STATS_COUNT
};

enum wlan_sleep_states {
    WLAN_STATE_ACTIVE = 0,
    WLAN_STATE_DEEP_SLEEP,

    // Don't add any lines after this line
    WLAN_SLEEP_STATE_COUNT
};

// Note that stats for both WLAN sleep states are in a single section of the
// source file, so there's only 1 stats section despite having 2 states
enum wlan_stats {
    CUMULATIVE_SLEEP_TIME_MS = 0,
    CUMULATIVE_TOTAL_ON_TIME_MS,
    DEEP_SLEEP_ENTER_COUNTER,
    LAST_DEEP_SLEEP_ENTER_TSTAMP_MS,

    // Don't add any lines after this line
    WLAN_STATS_COUNT
};

enum system_sleep_states {
    SYSTEM_STATE_AOSD = 0,
    SYSTEM_STATE_CXSD,

    //Don't add any lines after this line
    SYSTEM_SLEEP_STATE_COUNT
};

enum system_state_stats {
    TOTAL_COUNT = 0,
    ACCUMULATED_TIME_MS,

    //Don't add any lines after this line
    SYSTEM_STATE_STATS_COUNT
};

#ifndef ARRAY_SIZE
#define ARRAY_SIZE(x) (sizeof((x))/sizeof((x)[0]))
#endif

struct stats_section {
    enum stats_source source;
    const char *label;
    const char **stats_labels;
    size_t num_stats;
};

int extract_master_stats(uint64_t *list, size_t list_length);
int extract_wlan_stats(uint64_t *list, size_t list_length);
int extract_system_stats(uint64_t *list, size_t list_length);

#ifdef __cplusplus
}
#endif

#endif //__POWER_HELPER_H__