7#ifndef ZEPHYR_INCLUDE_KERNEL_OBJ_CORE_H_
8#define ZEPHYR_INCLUDE_KERNEL_OBJ_CORE_H_
25#define K_OBJ_CORE(kobj) (&((kobj)->obj_core))
30#define K_OBJ_TYPE_ID_GEN(s) ((s[0] << 24) | (s[1] << 16) | (s[2] << 8) | (s[3]))
35#define K_OBJ_TYPE_CONDVAR_ID K_OBJ_TYPE_ID_GEN("COND")
37#define K_OBJ_TYPE_CPU_ID K_OBJ_TYPE_ID_GEN("CPU_")
39#define K_OBJ_TYPE_EVENT_ID K_OBJ_TYPE_ID_GEN("EVNT")
41#define K_OBJ_TYPE_FIFO_ID K_OBJ_TYPE_ID_GEN("FIFO")
43#define K_OBJ_TYPE_KERNEL_ID K_OBJ_TYPE_ID_GEN("KRNL")
45#define K_OBJ_TYPE_LIFO_ID K_OBJ_TYPE_ID_GEN("LIFO")
47#define K_OBJ_TYPE_MEM_BLOCK_ID K_OBJ_TYPE_ID_GEN("MBLK")
49#define K_OBJ_TYPE_MBOX_ID K_OBJ_TYPE_ID_GEN("MBOX")
51#define K_OBJ_TYPE_MEM_SLAB_ID K_OBJ_TYPE_ID_GEN("SLAB")
53#define K_OBJ_TYPE_MSGQ_ID K_OBJ_TYPE_ID_GEN("MSGQ")
55#define K_OBJ_TYPE_MUTEX_ID K_OBJ_TYPE_ID_GEN("MUTX")
57#define K_OBJ_TYPE_PIPE_ID K_OBJ_TYPE_ID_GEN("PIPE")
59#define K_OBJ_TYPE_QUEUE_ID K_OBJ_TYPE_ID_GEN("QUEU")
61#define K_OBJ_TYPE_SEM_ID K_OBJ_TYPE_ID_GEN("SEM4")
63#define K_OBJ_TYPE_STACK_ID K_OBJ_TYPE_ID_GEN("STCK")
65#define K_OBJ_TYPE_THREAD_ID K_OBJ_TYPE_ID_GEN("THRD")
67#define K_OBJ_TYPE_TIMER_ID K_OBJ_TYPE_ID_GEN("TIMR")
77#define K_OBJ_CORE_INIT(_objp, _obj_type) \
78 extern struct k_obj_type _obj_type; \
79 k_obj_core_init(_objp, &_obj_type)
81#define K_OBJ_CORE_LINK(objp) k_obj_core_link(objp)
83#define K_OBJ_CORE_INIT(objp, type) do { } while (0)
84#define K_OBJ_CORE_LINK(objp) do { } while (0)
131#define K_OBJ_TYPE_MAX_RANGES 3
144#ifdef CONFIG_OBJ_CORE_STATS
162#ifdef CONFIG_OBJ_CORE_STATS
171#ifdef CONFIG_OBJ_CORE_STATS
172#define K_OBJ_TYPE_STATS_INITIALIZER(_stats, _soff, _ssz) \
173 .stats_desc = (_stats), .stats_offset = (_soff), .stats_size = (_ssz),
175#define K_OBJ_TYPE_STATS_INITIALIZER(_stats, _soff, _ssz)
188#define K_OBJ_TYPE_INITIALIZER(_struct, _id, _stats, _soff, _ssz, ...) \
191 .obj_core_offset = offsetof(struct _struct, obj_core), \
192 .statics = { __VA_ARGS__ }, \
193 K_OBJ_TYPE_STATS_INITIALIZER(_stats, _soff, _ssz) \
204#define K_OBJ_RANGE_SECTION(_struct) \
206 .start = STRUCT_SECTION_START(_struct), \
207 .end = STRUCT_SECTION_END(_struct), \
208 .stride = sizeof(struct _struct), \
225#define K_OBJ_TYPE_DEFINE(_type_var, _struct, _id, _stats) \
226 STRUCT_SECTION_START_EXTERN(_struct); \
227 STRUCT_SECTION_END_EXTERN(_struct); \
228 static STRUCT_SECTION_ITERABLE(k_obj_type, _type_var) = \
229 K_OBJ_TYPE_INITIALIZER(_struct, _id, _stats, 0, 0, \
230 K_OBJ_RANGE_SECTION(_struct))
244#define K_OBJ_TYPE_DEFINE_STATS(_type_var, _struct, _id, _stats, _member) \
245 STRUCT_SECTION_START_EXTERN(_struct); \
246 STRUCT_SECTION_END_EXTERN(_struct); \
247 static STRUCT_SECTION_ITERABLE(k_obj_type, _type_var) = \
248 K_OBJ_TYPE_INITIALIZER(_struct, _id, _stats, \
249 offsetof(struct _struct, _member), \
250 sizeof(((struct _struct *)0)->_member), \
251 K_OBJ_RANGE_SECTION(_struct))
265#define K_OBJ_TYPE_DEFINE_TYPE_ONLY(_type_var, _struct, _id, _stats) \
266 static STRUCT_SECTION_ITERABLE(k_obj_type, _type_var) = \
267 K_OBJ_TYPE_INITIALIZER(_struct, _id, _stats, 0, 0, { 0 })
282#define K_OBJ_TYPE_DEFINE_RANGES(_type_var, _struct, _id, _stats, ...) \
283 static STRUCT_SECTION_ITERABLE(k_obj_type, _type_var) = \
284 K_OBJ_TYPE_INITIALIZER(_struct, _id, _stats, 0, 0, __VA_ARGS__)
318 const void *end,
size_t stride,
bool indirect);
353 int (*func)(
struct k_obj_core *obj_core,
void *data),
375 int (*func)(
struct k_obj_core *obj_core,
void *data),
453#ifdef CONFIG_OBJ_CORE_STATS
462static inline void k_obj_type_stats_init(
struct k_obj_type *type,
465 type->stats_desc = stats_desc;
477static inline void k_obj_core_stats_init(
struct k_obj_core *obj_core,
480 obj_core->stats = stats;
void k_obj_type_init_range(struct k_obj_type *type, const void *start, const void *end, size_t stride, bool indirect)
Register the permanent objects of an object type.
#define K_OBJ_TYPE_MAX_RANGES
Maximum number of permanent object ranges of an object type.
Definition obj_core.h:131
struct k_obj_type * k_obj_type_find(uint32_t type_id)
Find a specific object type by ID.
int k_obj_type_walk_locked(struct k_obj_type *type, int(*func)(struct k_obj_core *obj_core, void *data), void *data)
Walk the object cores of an object type.
int k_obj_type_walk_unlocked(struct k_obj_type *type, int(*func)(struct k_obj_core *obj_core, void *data), void *data)
Walk the object cores of an object type.
void k_obj_core_evict_range(const void *addr, size_t len)
Unregister every kernel object located in a memory range.
void k_obj_core_link(struct k_obj_core *obj_core)
Register the kernel object with its object type.
void k_obj_core_unlink(struct k_obj_core *obj_core)
Unregister the kernel object from its object type.
void k_obj_core_init_and_link(struct k_obj_core *obj_core, struct k_obj_type *type)
Automatically link the kernel object after initializing it.
void k_obj_core_init(struct k_obj_core *obj_core, struct k_obj_type *type)
Initialize the core of the kernel object.
int k_obj_core_stats_enable(struct k_obj_core *obj_core)
Resume gathering the stats associated with the kernel object.
int k_obj_core_stats_reset(struct k_obj_core *obj_core)
Reset the stats associated with the kernel object.
int k_obj_core_stats_query(struct k_obj_core *obj_core, void *stats, size_t stats_len)
Retrieve the statistics associated with the kernel object.
int k_obj_core_stats_disable(struct k_obj_core *obj_core)
Stop gathering the stats associated with the kernel object.
int k_obj_core_stats_raw(struct k_obj_core *obj_core, void *stats, size_t stats_len)
Retrieve the raw statistics associated with the kernel object.
int k_obj_core_stats_deregister(struct k_obj_core *obj_core)
Deregister kernel object from gathering statistics.
int k_obj_core_stats_register(struct k_obj_core *obj_core, void *stats, size_t stats_len)
Register kernel object for gathering statistics.
struct _slist sys_slist_t
Single-linked list structure.
Definition slist.h:54
struct _snode sys_snode_t
Single-linked list node structure.
Definition slist.h:44
Header file for the single-linked list API.
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
Object core statistics descriptor.
Definition obj_core.h:100
int(* raw)(struct k_obj_core *obj_core, void *stats)
Function pointer to retrieve internal representation of stats.
Definition obj_core.h:105
int(* reset)(struct k_obj_core *obj_core)
Function pointer to reset object's statistics.
Definition obj_core.h:109
size_t raw_size
Internal representation stats buffer size.
Definition obj_core.h:101
int(* query)(struct k_obj_core *obj_core, void *stats)
Function pointer to retrieve reported statistics.
Definition obj_core.h:107
size_t query_size
Stats buffer size used for reporting.
Definition obj_core.h:102
int(* enable)(struct k_obj_core *obj_core)
Function pointer to enable object's statistics gathering.
Definition obj_core.h:113
int(* disable)(struct k_obj_core *obj_core)
Function pointer to disable object's statistics gathering.
Definition obj_core.h:111
Object core structure.
Definition obj_core.h:160
struct k_obj_type * type
Object type to which object belongs.
Definition obj_core.h:161
Contiguous range of permanent objects of one type.
Definition obj_core.h:123
bool indirect
Elements are pointers to the objects.
Definition obj_core.h:127
const void * start
First element.
Definition obj_core.h:124
size_t stride
Element size.
Definition obj_core.h:126
const void * end
One past the last element.
Definition obj_core.h:125
Object type structure.
Definition obj_core.h:134
size_t obj_core_offset
Offset to obj_core field.
Definition obj_core.h:137
struct k_obj_range statics[3]
Permanent objects of this type, walked in place; a zero stride ends the list.
Definition obj_core.h:139
uint32_t skipped
Registrations refused because the object lives in stack storage.
Definition obj_core.h:143
uint32_t dropped
Registrations refused because the registry was full.
Definition obj_core.h:141
sys_snode_t node
Node within list of object types.
Definition obj_core.h:135
uint32_t id
Unique type ID.
Definition obj_core.h:136
Iterable sections helpers.