|
| 1 | +// SPDX-License-Identifier: BSD-3-Clause |
| 2 | +/* Copyright 2018-2021, Intel Corporation */ |
| 3 | + |
| 4 | +/* |
| 5 | + * ctl_debug.c -- implementation of the debug CTL namespace |
| 6 | + */ |
| 7 | + |
| 8 | +#include "ctl_debug.h" |
| 9 | +#include "ctl.h" |
| 10 | + |
| 11 | +static struct ctl *ctl_debug; |
| 12 | + |
| 13 | +static int alloc_pattern = 0; |
| 14 | + |
| 15 | +struct ctl *get_debug_ctl(void) { return ctl_debug; } |
| 16 | + |
| 17 | +/* |
| 18 | + * CTL_WRITE_HANDLER(alloc_pattern) -- sets the alloc_pattern field in heap |
| 19 | + */ |
| 20 | +static int CTL_WRITE_HANDLER(alloc_pattern, )(void *ctx, |
| 21 | + enum ctl_query_source source, |
| 22 | + void *arg, |
| 23 | + struct ctl_indexes *indexes) { |
| 24 | + /* suppress unused-parameter errors */ |
| 25 | + (void)source, (void)indexes, (void)ctx; |
| 26 | + |
| 27 | + int arg_in = *(int *)arg; |
| 28 | + alloc_pattern = arg_in; |
| 29 | + return 0; |
| 30 | +} |
| 31 | + |
| 32 | +/* |
| 33 | + * CTL_READ_HANDLER(alloc_pattern) -- returns alloc_pattern heap field |
| 34 | + */ |
| 35 | +static int CTL_READ_HANDLER(alloc_pattern, )(void *ctx, |
| 36 | + enum ctl_query_source source, |
| 37 | + void *arg, |
| 38 | + struct ctl_indexes *indexes) { |
| 39 | + /* suppress unused-parameter errors */ |
| 40 | + (void)source, (void)indexes, (void)ctx; |
| 41 | + |
| 42 | + int *arg_out = arg; |
| 43 | + *arg_out = alloc_pattern; |
| 44 | + return 0; |
| 45 | +} |
| 46 | + |
| 47 | +static const struct ctl_argument CTL_ARG(alloc_pattern) = CTL_ARG_LONG_LONG; |
| 48 | + |
| 49 | +static const struct ctl_node CTL_NODE(heap, )[] = {CTL_LEAF_RW(alloc_pattern), |
| 50 | + |
| 51 | + CTL_NODE_END}; |
| 52 | + |
| 53 | +static const struct ctl_node CTL_NODE(debug, )[] = {CTL_CHILD(heap, ), |
| 54 | + |
| 55 | + CTL_NODE_END}; |
| 56 | + |
| 57 | +/* |
| 58 | + * debug_ctl_register -- registers ctl nodes for "debug" module |
| 59 | + */ |
| 60 | +void debug_ctl_register(struct ctl *ctl) { CTL_REGISTER_MODULE(ctl, debug); } |
| 61 | + |
| 62 | +void initialize_debug_ctl(void) { |
| 63 | + ctl_debug = ctl_new(); |
| 64 | + debug_ctl_register(ctl_debug); |
| 65 | +} |
| 66 | + |
| 67 | +void deinitialize_debug_ctl(void) { ctl_delete(ctl_debug); } |
0 commit comments