kfsw-services/src/limits-parameters/limits_table.c
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include <errno.h> | ||
| 2 | #include <stdint.h> | ||
| 3 | |||
| 4 | #include <zephyr/sys/util.h> | ||
| 5 | |||
| 6 | #include <kfsw/services/limits.h> | ||
| 7 | #include <kfsw/services/parameter.h> | ||
| 8 | |||
| 9 | static uint8_t limits_rules; | ||
| 10 | static uint8_t limits_running; | ||
| 11 | static uint8_t limits_last_index; | ||
| 12 | static uint16_t limits_error_line; | ||
| 13 | static uint32_t limits_sweeps; | ||
| 14 | static uint32_t limits_fires; | ||
| 15 | static uint32_t limits_failures; | ||
| 16 | static uint32_t limits_remote_failures; | ||
| 17 | static uint16_t limits_failed_by; | ||
| 18 | static uint32_t limits_parse_errors; | ||
| 19 | static uint32_t limits_last_ms; | ||
| 20 | |||
| 21 | 26 | static void sample_state(void) | |
| 22 | { | ||
| 23 | struct kfsw_limits_status status; | ||
| 24 | |||
| 25 | 26 | kfsw_limits_get_status(&status); | |
| 26 | 26 | limits_rules = status.rules; | |
| 27 | 26 | limits_running = status.running ? 1U : 0U; | |
| 28 | 26 | limits_last_index = status.last_fired_index; | |
| 29 | 26 | limits_error_line = status.error_line; | |
| 30 | 26 | limits_sweeps = status.sweeps; | |
| 31 | 26 | limits_fires = status.fires; | |
| 32 | 26 | limits_failures = status.failures; | |
| 33 | 26 | limits_remote_failures = status.remote_failures; | |
| 34 | 26 | limits_failed_by = status.failed_by; | |
| 35 | 26 | limits_parse_errors = status.parse_errors; | |
| 36 | 26 | limits_last_ms = status.last_fired_ms; | |
| 37 | 26 | } | |
| 38 | |||
| 39 | 2 | static void sample_rules(void *value) | |
| 40 | { | ||
| 41 | 2 | sample_state(); | |
| 42 | 2 | *(uint8_t *)value = limits_rules; | |
| 43 | 2 | } | |
| 44 | |||
| 45 | ✗ | static void sample_running(void *value) | |
| 46 | { | ||
| 47 | ✗ | sample_state(); | |
| 48 | ✗ | *(uint8_t *)value = limits_running; | |
| 49 | ✗ | } | |
| 50 | |||
| 51 | 2 | static void sample_last_index(void *value) | |
| 52 | { | ||
| 53 | 2 | sample_state(); | |
| 54 | 2 | *(uint8_t *)value = limits_last_index; | |
| 55 | 2 | } | |
| 56 | |||
| 57 | ✗ | static void sample_error_line(void *value) | |
| 58 | { | ||
| 59 | ✗ | sample_state(); | |
| 60 | ✗ | *(uint16_t *)value = limits_error_line; | |
| 61 | ✗ | } | |
| 62 | |||
| 63 | ✗ | static void sample_sweeps(void *value) | |
| 64 | { | ||
| 65 | ✗ | sample_state(); | |
| 66 | ✗ | *(uint32_t *)value = limits_sweeps; | |
| 67 | ✗ | } | |
| 68 | |||
| 69 | 2 | static void sample_fires(void *value) | |
| 70 | { | ||
| 71 | 2 | sample_state(); | |
| 72 | 2 | *(uint32_t *)value = limits_fires; | |
| 73 | 2 | } | |
| 74 | |||
| 75 | ✗ | static void sample_failures(void *value) | |
| 76 | { | ||
| 77 | ✗ | sample_state(); | |
| 78 | ✗ | *(uint32_t *)value = limits_failures; | |
| 79 | ✗ | } | |
| 80 | |||
| 81 | ✗ | static void sample_parse_errors(void *value) | |
| 82 | { | ||
| 83 | ✗ | sample_state(); | |
| 84 | ✗ | *(uint32_t *)value = limits_parse_errors; | |
| 85 | ✗ | } | |
| 86 | |||
| 87 | ✗ | static void sample_last_ms(void *value) | |
| 88 | { | ||
| 89 | ✗ | sample_state(); | |
| 90 | ✗ | *(uint32_t *)value = limits_last_ms; | |
| 91 | ✗ | } | |
| 92 | |||
| 93 | 4 | static void sample_remote_failures(void *value) | |
| 94 | { | ||
| 95 | 4 | sample_state(); | |
| 96 | 4 | *(uint32_t *)value = limits_remote_failures; | |
| 97 | 4 | } | |
| 98 | |||
| 99 | 16 | static void sample_failed_by(void *value) | |
| 100 | { | ||
| 101 | 16 | sample_state(); | |
| 102 | 16 | *(uint16_t *)value = limits_failed_by; | |
| 103 | 16 | } | |
| 104 | |||
| 105 | 4 | static int validate_enabled(const union kfsw_param_scalar *value) | |
| 106 | { | ||
| 107 | 4 | return (value->u8 > 1U) ? -ERANGE : 0; | |
| 108 | } | ||
| 109 | |||
| 110 | 4 | static int validate_interval(const union kfsw_param_scalar *value) | |
| 111 | { | ||
| 112 | 4 | if ((value->u32 != 0U) && ((value->u32 < KFSW_LIMITS_INTERVAL_MIN_MS) || | |
| 113 | ✗ | (value->u32 > KFSW_LIMITS_INTERVAL_MAX_MS))) { | |
| 114 | ✗ | return -ERANGE; | |
| 115 | } | ||
| 116 | 4 | return 0; | |
| 117 | } | ||
| 118 | |||
| 119 | 4 | static void apply_interval(const union kfsw_param_scalar *value) | |
| 120 | { | ||
| 121 | 4 | (void)kfsw_limits_set_interval_ms(value->u32); | |
| 122 | 4 | } | |
| 123 | |||
| 124 | static const struct kfsw_param_definition limits_param_definitions[] = { | ||
| 125 | { | ||
| 126 | .offset = 0x00U, | ||
| 127 | .type = KFSW_PARAM_U8, | ||
| 128 | .flags = KFSW_PARAM_FLAG_READ_ONLY, | ||
| 129 | .name = "limits_rules", | ||
| 130 | .description = "Rules in force", | ||
| 131 | .value = &limits_rules, | ||
| 132 | .default_value = {.u8 = 0U}, | ||
| 133 | .sample = sample_rules, | ||
| 134 | }, | ||
| 135 | { | ||
| 136 | .offset = 0x01U, | ||
| 137 | .type = KFSW_PARAM_U8, | ||
| 138 | .flags = KFSW_PARAM_FLAG_READ_ONLY, | ||
| 139 | .name = "limits_running", | ||
| 140 | .description = "Whether the periodic sweep is scheduled", | ||
| 141 | .value = &limits_running, | ||
| 142 | .default_value = {.u8 = 0U}, | ||
| 143 | .sample = sample_running, | ||
| 144 | }, | ||
| 145 | { | ||
| 146 | .offset = 0x02U, | ||
| 147 | .type = KFSW_PARAM_U8, | ||
| 148 | .flags = KFSW_PARAM_FLAG_PERSISTENT | KFSW_PARAM_FLAG_LIVE, | ||
| 149 | .name = "limits_enabled", | ||
| 150 | .description = "0 stops the sweeps and keeps the loaded rules", | ||
| 151 | .value = &kfsw_limits_enabled, | ||
| 152 | .default_value = {.u8 = 1U}, | ||
| 153 | .validate = validate_enabled, | ||
| 154 | }, | ||
| 155 | { | ||
| 156 | .offset = 0x04U, | ||
| 157 | .type = KFSW_PARAM_U32, | ||
| 158 | .unit = "ms", | ||
| 159 | .flags = KFSW_PARAM_FLAG_PERSISTENT | KFSW_PARAM_FLAG_LIVE, | ||
| 160 | .name = "limits_interval_ms", | ||
| 161 | .description = "Between periodic sweeps; 0 or 100 to 3600000", | ||
| 162 | .value = &kfsw_limits_interval_ms, | ||
| 163 | .default_value = {.u32 = CONFIG_KFSW_LIMITS_INTERVAL_MS}, | ||
| 164 | .validate = validate_interval, | ||
| 165 | .changed = apply_interval, | ||
| 166 | }, | ||
| 167 | { | ||
| 168 | .offset = 0x08U, | ||
| 169 | .type = KFSW_PARAM_U32, | ||
| 170 | .flags = KFSW_PARAM_FLAG_READ_ONLY, | ||
| 171 | .name = "limits_sweeps", | ||
| 172 | .description = "Sweeps completed while enabled", | ||
| 173 | .value = &limits_sweeps, | ||
| 174 | .default_value = {.u32 = 0U}, | ||
| 175 | .sample = sample_sweeps, | ||
| 176 | }, | ||
| 177 | { | ||
| 178 | .offset = 0x0cU, | ||
| 179 | .type = KFSW_PARAM_U32, | ||
| 180 | .flags = KFSW_PARAM_FLAG_READ_ONLY, | ||
| 181 | .name = "limits_fires", | ||
| 182 | .description = "Actions released", | ||
| 183 | .value = &limits_fires, | ||
| 184 | .default_value = {.u32 = 0U}, | ||
| 185 | .sample = sample_fires, | ||
| 186 | }, | ||
| 187 | { | ||
| 188 | .offset = 0x10U, | ||
| 189 | .type = KFSW_PARAM_U32, | ||
| 190 | .flags = KFSW_PARAM_FLAG_READ_ONLY, | ||
| 191 | .name = "limits_failures", | ||
| 192 | .description = "Parameter reads and releases that failed", | ||
| 193 | .value = &limits_failures, | ||
| 194 | .default_value = {.u32 = 0U}, | ||
| 195 | .sample = sample_failures, | ||
| 196 | }, | ||
| 197 | { | ||
| 198 | .offset = 0x14U, | ||
| 199 | .type = KFSW_PARAM_U32, | ||
| 200 | .flags = KFSW_PARAM_FLAG_READ_ONLY, | ||
| 201 | .name = "limits_parse_errors", | ||
| 202 | .description = "Rule files refused for a bad line", | ||
| 203 | .value = &limits_parse_errors, | ||
| 204 | .default_value = {.u32 = 0U}, | ||
| 205 | .sample = sample_parse_errors, | ||
| 206 | }, | ||
| 207 | { | ||
| 208 | .offset = 0x18U, | ||
| 209 | .type = KFSW_PARAM_U32, | ||
| 210 | .unit = "ms", | ||
| 211 | .flags = KFSW_PARAM_FLAG_READ_ONLY, | ||
| 212 | .name = "limits_last_fired_ms", | ||
| 213 | .description = "Uptime of the last release; 0 before any", | ||
| 214 | .value = &limits_last_ms, | ||
| 215 | .default_value = {.u32 = 0U}, | ||
| 216 | .sample = sample_last_ms, | ||
| 217 | }, | ||
| 218 | { | ||
| 219 | .offset = 0x1cU, | ||
| 220 | .type = KFSW_PARAM_U8, | ||
| 221 | .flags = KFSW_PARAM_FLAG_READ_ONLY, | ||
| 222 | .name = "limits_last_fired", | ||
| 223 | .description = "Index of the rule that fired last; 255 before any", | ||
| 224 | .value = &limits_last_index, | ||
| 225 | .default_value = {.u8 = KFSW_LIMITS_NO_RULE}, | ||
| 226 | .sample = sample_last_index, | ||
| 227 | }, | ||
| 228 | { | ||
| 229 | .offset = 0x1eU, | ||
| 230 | .type = KFSW_PARAM_U16, | ||
| 231 | .flags = KFSW_PARAM_FLAG_READ_ONLY, | ||
| 232 | .name = "limits_error_line", | ||
| 233 | .description = "Line that got the last file refused; 0 for none", | ||
| 234 | .value = &limits_error_line, | ||
| 235 | .default_value = {.u16 = 0U}, | ||
| 236 | .sample = sample_error_line, | ||
| 237 | }, | ||
| 238 | { | ||
| 239 | .offset = 0x20U, | ||
| 240 | .type = KFSW_PARAM_U32, | ||
| 241 | .flags = KFSW_PARAM_FLAG_READ_ONLY, | ||
| 242 | .name = "limits_remote_failures", | ||
| 243 | .description = "Remote reads that failed, counted per rule", | ||
| 244 | .value = &limits_remote_failures, | ||
| 245 | .default_value = {.u32 = 0U}, | ||
| 246 | .sample = sample_remote_failures, | ||
| 247 | }, | ||
| 248 | { | ||
| 249 | .offset = 0x24U, | ||
| 250 | .type = KFSW_PARAM_U16, | ||
| 251 | .flags = KFSW_PARAM_FLAG_READ_ONLY, | ||
| 252 | .name = "limits_failed_by", | ||
| 253 | .description = "Last node whose read failed; 0 on recovery or load", | ||
| 254 | .value = &limits_failed_by, | ||
| 255 | .default_value = {.u16 = 0U}, | ||
| 256 | .sample = sample_failed_by, | ||
| 257 | }, | ||
| 258 | }; | ||
| 259 | |||
| 260 | KFSW_PARAM_TABLE_FITS_THE_LINK(limits_param_definitions); | ||
| 261 | |||
| 262 | const struct kfsw_param_definition_set kfsw_limits_param_definitions = { | ||
| 263 | .table = KFSW_LIMITS_PARAM_TABLE_ID, | ||
| 264 | .name = KFSW_LIMITS_PARAM_TABLE_NAME, | ||
| 265 | .description = "Parameter limits", | ||
| 266 | .definitions = limits_param_definitions, | ||
| 267 | .count = ARRAY_SIZE(limits_param_definitions), | ||
| 268 | }; | ||
| 269 |