1 /*- 2 * BSD LICENSE 3 * 4 * Copyright (c) Intel Corporation. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 11 * * Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * * Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in 15 * the documentation and/or other materials provided with the 16 * distribution. 17 * * Neither the name of Intel Corporation nor the names of its 18 * contributors may be used to endorse or promote products derived 19 * from this software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 */ 33 34 #include "spdk/stdinc.h" 35 36 #include "spdk/env.h" 37 #include "spdk/trace.h" 38 #include "spdk/log.h" 39 40 struct spdk_trace_flags *g_trace_flags = NULL; 41 static struct spdk_trace_register_fn *g_reg_fn_head = NULL; 42 43 uint64_t 44 spdk_trace_get_tpoint_mask(uint32_t group_id) 45 { 46 if (group_id >= SPDK_TRACE_MAX_GROUP_ID) { 47 SPDK_ERRLOG("%s: invalid group ID %d\n", __func__, group_id); 48 return 0ULL; 49 } 50 51 return g_trace_flags->tpoint_mask[group_id]; 52 } 53 54 void 55 spdk_trace_set_tpoints(uint32_t group_id, uint64_t tpoint_mask) 56 { 57 if (group_id >= SPDK_TRACE_MAX_GROUP_ID) { 58 SPDK_ERRLOG("%s: invalid group ID %d\n", __func__, group_id); 59 return; 60 } 61 62 g_trace_flags->tpoint_mask[group_id] |= tpoint_mask; 63 } 64 65 void 66 spdk_trace_clear_tpoints(uint32_t group_id, uint64_t tpoint_mask) 67 { 68 if (group_id >= SPDK_TRACE_MAX_GROUP_ID) { 69 SPDK_ERRLOG("%s: invalid group ID %d\n", __func__, group_id); 70 return; 71 } 72 73 g_trace_flags->tpoint_mask[group_id] &= ~tpoint_mask; 74 } 75 76 uint64_t 77 spdk_trace_get_tpoint_group_mask(void) 78 { 79 uint64_t mask = 0x0; 80 int i; 81 82 for (i = 0; i < SPDK_TRACE_MAX_GROUP_ID; i++) { 83 if (spdk_trace_get_tpoint_mask(i) != 0) { 84 mask |= (1ULL << i); 85 } 86 } 87 88 return mask; 89 } 90 91 void 92 spdk_trace_set_tpoint_group_mask(uint64_t tpoint_group_mask) 93 { 94 int i; 95 96 for (i = 0; i < SPDK_TRACE_MAX_GROUP_ID; i++) { 97 if (tpoint_group_mask & (1ULL << i)) { 98 spdk_trace_set_tpoints(i, -1ULL); 99 } 100 } 101 } 102 103 void 104 spdk_trace_register_owner(uint8_t type, char id_prefix) 105 { 106 struct spdk_trace_owner *owner; 107 108 assert(type != OWNER_NONE); 109 110 /* 'owner' has 256 entries and since 'type' is a uint8_t, it 111 * can't overrun the array. 112 */ 113 owner = &g_trace_flags->owner[type]; 114 assert(owner->type == 0); 115 116 owner->type = type; 117 owner->id_prefix = id_prefix; 118 } 119 120 void 121 spdk_trace_register_object(uint8_t type, char id_prefix) 122 { 123 struct spdk_trace_object *object; 124 125 assert(type != OBJECT_NONE); 126 127 /* 'object' has 256 entries and since 'type' is a uint8_t, it 128 * can't overrun the array. 129 */ 130 object = &g_trace_flags->object[type]; 131 assert(object->type == 0); 132 133 object->type = type; 134 object->id_prefix = id_prefix; 135 } 136 137 void 138 spdk_trace_register_description(const char *name, const char *short_name, 139 uint16_t tpoint_id, uint8_t owner_type, 140 uint8_t object_type, uint8_t new_object, 141 uint8_t arg1_is_ptr, const char *arg1_name) 142 { 143 struct spdk_trace_tpoint *tpoint; 144 145 assert(tpoint_id != 0); 146 assert(tpoint_id < SPDK_TRACE_MAX_TPOINT_ID); 147 148 tpoint = &g_trace_flags->tpoint[tpoint_id]; 149 assert(tpoint->tpoint_id == 0); 150 151 snprintf(tpoint->name, sizeof(tpoint->name), "%s", name); 152 snprintf(tpoint->short_name, sizeof(tpoint->short_name), "%s", short_name); 153 tpoint->tpoint_id = tpoint_id; 154 tpoint->object_type = object_type; 155 tpoint->owner_type = owner_type; 156 tpoint->new_object = new_object; 157 tpoint->arg1_is_ptr = arg1_is_ptr; 158 snprintf(tpoint->arg1_name, sizeof(tpoint->arg1_name), "%s", arg1_name); 159 } 160 161 void 162 spdk_trace_add_register_fn(struct spdk_trace_register_fn *reg_fn) 163 { 164 reg_fn->next = g_reg_fn_head; 165 g_reg_fn_head = reg_fn; 166 } 167 168 169 void 170 spdk_trace_flags_init(void) 171 { 172 struct spdk_trace_register_fn *reg_fn; 173 174 reg_fn = g_reg_fn_head; 175 while (reg_fn) { 176 reg_fn->reg_fn(); 177 reg_fn = reg_fn->next; 178 } 179 } 180