Repository navigation
Expand file tree
/
Copy pathneuron_metrics.h
More file actions
219 lines (182 loc) · 9.05 KB
/
Copy pathneuron_metrics.h
File metadata and controls
219 lines (182 loc) · 9.05 KB
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright 2021, Amazon.com, Inc. or its affiliates. All Rights Reserved
*/
#include <linux/atomic.h>
#include "neuron_ds.h"
#include "share/neuron_driver_shared.h"
#ifndef _NEURON_METRICS_H
#define _NEURON_METRICS_H
#define NEURON_METRICS_VERSION_STRING_MAX_LEN 63
#define NEURON_METRICS_MAX_POSTING_BUF_SIZE 128
#define NEURON_METRICS_VERSION_CAPACITY 2 // version capacity (max distinct versions per device)
#define NEURON_METRICS_VERSION_MAX_CAPACITY 8 // number of versions to maintain in history
#define POST_TIME_ALWAYS 0xF
#define POST_TIME_TICK_0 0x0
#define POST_TIME_TICK_1 0x1
#define POST_TICK_COUNT 2
#define NMETRIC_TYPE_CONSTANT 0x0
#define NMETRIC_TYPE_VERSION 0x1
#define NMETRIC_TYPE_COUNTER 0x2
#define NMETRIC_TYPE_FW_IO_ERR 0x3
#define NMETRIC_TYPE_BITMAP 0x4
#define NMETRIC_TYPE_CONSTANT_U64 0x5
#define NMETRIC_TYPE_DRIVER_RESET 0x6
#define NMETRIC_TYPE_DRIVER_USERVER 0x7
#define NMETRIC_TYPE_UTILIZATION 0x8
#define NMETRIC_TYPE_ECC_ERR_COUNTER 0x9
#define NMETRIC_FLAG_VERS_ALLOW_TYPE (1)
#define NMETRIC_CONST_U64_FLAG_SKIP_ZERO (0x1ull << 0)
#define NMETRIC_CONST_U64_FLAG_PREFER_FREED (0x1ull << 1)
// The final driver metrics to be posted to CR.
// They are not stored in datastore
enum driver_final_metrics_idx {
NMETRIC_DRIVER_METRICS_IDX_MAX_DEVICE_RESET_TIME_MS = 0,
NMETRIC_DRIVER_METRICS_IDX_MAX_TPB_RESET_TIME_MS = 1,
NMETRIC_DRIVER_METRICS_IDX_AVG_DEVICE_RESET_TIME_MS = 2,
NMETRIC_DRIVER_METRICS_IDX_AVG_TPB_RESET_TIME_MS = 3,
NMETRIC_DRIVER_METRICS_IDX_DEVICE_RESET_FAILURE_COUNT = 4,
NMETRIC_DRIVER_METRICS_IDX_TPB_RESET_FAILURE_COUNT = 5,
NMETRIC_FINAL_DRIVER_METRICS_COUNT = 6,
};
// The intermediate driver metrics are not posted to CW.
// They are used to calculate the final driver metrics above.
// They are not stored in datastore
enum driver_intermediate_metrics_idx {
NMETRIC_DRIVER_METRICS_IDX_TOTAL_DEVICE_RESET_TIME_MS = 0,
NMETRIC_DRIVER_METRICS_IDX_TOTAL_TPB_RESET_TIME_MS = 1,
NMETRIC_DRIVER_METRICS_IDX_TOTAL_DEVICE_RESET_COUNT = 2,
NMETRIC_DRIVER_METRICS_IDX_TOTAL_TPB_RESET_COUNT = 3,
NMETRIC_INTERMEDIATE_DRIVER_METRICS_COUNT = 4,
};
struct nmetric_driver_metrics {
atomic64_t final_metrics[NMETRIC_FINAL_DRIVER_METRICS_COUNT]; // final driver metrics to be posted to CR. Not in datastore
atomic64_t intermediate_metrics[NMETRIC_INTERMEDIATE_DRIVER_METRICS_COUNT]; // intermediate driver metrics, and not posted to CW. Not in datastore
};
// Sadly, the 3 #defines below need to be updated when adding new metrics to nmetric_defs
// Number of metrics of type NMETRIC_TYPE_VERSION
#define NMETRIC_VERSION_COUNT 3
// Number of metrics of type NMETRIC_TYPE_CONSTANT
#define NMETRIC_CONSTANTS_COUNT 3
// Number of metrics of type NMETRIC_TYPE_COUNTER + the special case (type NMETRIC_TYPE_FW_IO_ERR)
#define NMETRIC_COUNTER_COUNT 30
// Number of metrics of type NMETRIC_TYPE_BITMAP
#define NMETRIC_BITMAP_COUNT 1
// Number of metrics of type NMETRIC_CONSTANT_U64
#define NMETRIC_CONSTANT_U64_COUNT 2
// Number of metrics of type NMETRIC_TYPE_ECC_ERR_COUNTER
#define NMETRIC_ECC_ERR_COUNT 3
typedef struct {
u8 index; // metric specific index
u8 type; // metric type
u8 count; // metric specific count
u8 tick; // tick index on which the metric is posted
u8 cw_id; // target cloudwatch id
u8 ds_id; // source datastore id
u8 flags; // metric specific flags
} nmetric_def_t;
// Create a metric id which is an unique combination of id, type and post time
#define NMETRIC_DEF(_index, _type, _count, _tick, _cw_id, _ds_id, _flags) { .index = _index, .type = _type, .count = _count, .tick = _tick, .cw_id = _cw_id, .ds_id = _ds_id, .flags = _flags }
#define NMETRIC_CONSTANT_DEF(idx, tick, cw_id) NMETRIC_DEF(idx, NMETRIC_TYPE_CONSTANT, 1, tick, cw_id, 0xFF, 0)
#define NMETRIC_VERSION_DEF(idx, tick, cw_id, ds_id, flags) NMETRIC_DEF(idx, NMETRIC_TYPE_VERSION, NEURON_METRICS_VERSION_CAPACITY, tick, cw_id, ds_id, flags)
#define NMETRIC_COUNTER_DEF(idx, tick, cw_id, ds_id) NMETRIC_DEF(idx, NMETRIC_TYPE_COUNTER, 1, tick, cw_id, ds_id, 0)
#define NMETRIC_UTILIZATION_DEF(idx, tick, cw_id, ds_id) NMETRIC_DEF(idx, NMETRIC_TYPE_UTILIZATION, 1, tick, cw_id, ds_id, 0)
#define NMETRIC_BITMAP_DEF(idx, tick, cw_id, ds_id) NMETRIC_DEF(idx, NMETRIC_TYPE_BITMAP, 1, tick, cw_id, ds_id, 0)
#define NMETRIC_CONSTANT_U64(idx, tick, cw_id, ds_id, flags) NMETRIC_DEF(idx, NMETRIC_TYPE_CONSTANT_U64, 1, tick, cw_id, ds_id, flags)
#define NMETRIC_DRIVER_DEF(idx, tick, cw_id) NMETRIC_DEF(idx, NMETRIC_TYPE_DRIVER_RESET, 1, tick, cw_id, 0xFF, 0)
#define NMETRIC_DRIVER_USERVER_DEF(idx, tick, cw_id) NMETRIC_DEF(idx, NMETRIC_TYPE_DRIVER_USERVER, 1, tick, cw_id, 0xFF, 0)
#define NMETRIC_DRIVER_ECC_ERR_DEF(idx, tick, cw_id) NMETRIC_DEF(idx, NMETRIC_TYPE_ECC_ERR_COUNTER, 1, tick, cw_id, 0xFF, 0)
struct nmetric_versions {
u32 version_usage_count[NEURON_METRICS_VERSION_MAX_CAPACITY];
u64 version_metrics[NEURON_METRICS_VERSION_MAX_CAPACITY];
};
enum nmetric_state {
NMETRIC_STATE_STOPPED = 0, // thread not active/signaled to exit the loop
NMETRIC_STATE_RUNNING = 1, // thread is active and periodically posting metrics
NMETRIC_STATE_PAUSED = 2, // thread is active, but periodic posting is skipped
NMETRIC_STATE_RESUMING = 3, // immediately wakes thread and transitions to NMETRIC_STATE_RUNNING
};
struct nmetric_aggregation_thread {
struct task_struct *thread; // aggregation thread that sends metrics every ~5 minutes
wait_queue_head_t wait_queue;
volatile enum nmetric_state state;
u64 last_logged_slow_tick; // Tick count from the start to when the last metric was posted
u64 last_logged_slow_tick_jiffies; // Last time we posted metrics in jiffies
u64 curr[NMETRIC_COUNTER_COUNT]; // metrics for the current session so far
u64 prev[NMETRIC_COUNTER_COUNT]; // recorded metrics from the last post
u64 freed[NMETRIC_COUNTER_COUNT]; // cache holding metrics that were freed before the posting period was reached
u64 ecc_prev[NMETRIC_ECC_ERR_COUNT]; // ECC error counts up to the current post
};
struct neuron_metrics {
struct nmetric_versions component_versions[NMETRIC_VERSION_COUNT];
u64 ds_freed_feature_bitmap_buf; // stores unsent feature bitmap metrics about to be freed from datastore
u64 ds_freed_metrics_buf[NMETRIC_COUNTER_COUNT]; // stores unsent metrics about to be freed from datastore
u64 ds_freed_const_u64_buf[NMETRIC_CONSTANT_U64_COUNT]; // stores unsent constant u64 values about to be freed from datastore
struct nmetric_aggregation_thread neuron_aggregation; // aggregation thread that periodically aggregates and posts metrics
u8 posting_buffer[NEURON_METRICS_MAX_POSTING_BUF_SIZE + 1];
struct nmetric_driver_metrics driver_metrics; // driver metrics. not in datastore
};
/**
* nmetric_init_constants_metrics() - Gathers and stores device constant information for metric posting.
*
* @note Should be called before metric posting is initialized
*
*/
void nmetric_init_constants_metrics(void);
/**
* nmetric_partial_aggregate() - Aggregates all metrics in specified datastore entry. Expects datastore lock to have been acquired
*
* @nd: neuron device
* @entry: valid initialized datastore entry to aggregate metrics from
*
*/
void nmetric_partial_aggregate(struct neuron_device *nd, struct neuron_datastore_entry *entry);
/**
* neuron_stop_thread() - Stop aggregation thread of specified neuron device
*
* @nd: neuron device
*
*/
void nmetric_stop_thread(struct neuron_device *nd);
/**
* nmetric_init_driver_metrics() - Initializes the driver metrics lock and values to 0
*
* @param nd - the neuron device
*/
void nmetric_init_driver_metrics(struct neuron_device *nd);
/** nmetric_init() - Initializes neuron metric aggregation for the driver
*
* @nd: neuron device
*
* Return: 0 on success, < 0 error code on failure
*/
int nmetric_init(struct neuron_device *nd);
/**
* nmetric_set_reset_time_metrics() - Set the max TPB or device reset time seen so far.
*
* @param cur_reset_time_ms: the current TPB or device reset time in milliseconds.
* @param is_device_reset: whether it is TPB or device reset.
*/
void nmetric_set_reset_time_metrics(struct neuron_device *nd, s64 cur_reset_time_ms, bool is_device_reset);
/**
* nmetric_increment_reset_failure_count() - Increment the reset failure count by 1 for a device or TPB reset failure.
*
* @param nd: neuron device
* @param is_device_reset: whether it is TPB or device reset.
*/
void nmetric_increment_reset_failure_count(struct neuron_device *nd, bool is_device_reset);
/**
* nmetric_set_performance_profile() - Set the current performance profile value for metrics posting.
*
* @param nd: neuron device
* @param profile: performance profile value
*/
void nmetric_set_performance_profile(struct neuron_device *nd, int profile);
/**
* nmetric_set_mode() - Enable or disable periodic posting of metrics.
*
* @param nd: neuron device
* @param mode: whether to change or maintain current behavior
*/
void nmetric_set_mode(struct neuron_device *nd, enum neuron_metrics_mode mode);
#endif