Zephyr API Documentation 4.5.0-rc1
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
obj_core.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2023, Intel Corporation
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef ZEPHYR_INCLUDE_KERNEL_OBJ_CORE_H_
8#define ZEPHYR_INCLUDE_KERNEL_OBJ_CORE_H_
9
10#include <stdbool.h>
11#include <stddef.h>
12#include <stdint.h>
13#include <zephyr/sys/slist.h>
15
21
25#define K_OBJ_CORE(kobj) (&((kobj)->obj_core))
26
30#define K_OBJ_TYPE_ID_GEN(s) ((s[0] << 24) | (s[1] << 16) | (s[2] << 8) | (s[3]))
31
32/* Known kernel object types */
33
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")
68
69struct k_obj_type;
70struct k_obj_core;
71
75
76#ifdef CONFIG_OBJ_CORE
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)
80
81#define K_OBJ_CORE_LINK(objp) k_obj_core_link(objp)
82#else
83#define K_OBJ_CORE_INIT(objp, type) do { } while (0)
84#define K_OBJ_CORE_LINK(objp) do { } while (0)
85#endif /* CONFIG_OBJ_CORE */
86
90
97extern sys_slist_t z_obj_type_list;
98
101 size_t raw_size;
102 size_t query_size;
103
105 int (*raw)(struct k_obj_core *obj_core, void *stats);
107 int (*query)(struct k_obj_core *obj_core, void *stats);
109 int (*reset)(struct k_obj_core *obj_core);
111 int (*disable)(struct k_obj_core *obj_core);
113 int (*enable)(struct k_obj_core *obj_core);
114};
115
124 const void *start;
125 const void *end;
126 size_t stride;
127 bool indirect;
128};
129
131#define K_OBJ_TYPE_MAX_RANGES 3
132
144#ifdef CONFIG_OBJ_CORE_STATS
146 struct k_obj_core_stats_desc *stats_desc;
148 size_t stats_offset;
150 size_t stats_size;
151#endif /* CONFIG_OBJ_CORE_STATS */
152};
153
161 struct k_obj_type *type;
162#ifdef CONFIG_OBJ_CORE_STATS
163 void *stats;
164#endif /* CONFIG_OBJ_CORE_STATS */
165};
166
170
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),
174#else
175#define K_OBJ_TYPE_STATS_INITIALIZER(_stats, _soff, _ssz)
176#endif /* CONFIG_OBJ_CORE_STATS */
177
188#define K_OBJ_TYPE_INITIALIZER(_struct, _id, _stats, _soff, _ssz, ...) \
189 { \
190 .id = (_id), \
191 .obj_core_offset = offsetof(struct _struct, obj_core), \
192 .statics = { __VA_ARGS__ }, \
193 K_OBJ_TYPE_STATS_INITIALIZER(_stats, _soff, _ssz) \
194 }
195
204#define K_OBJ_RANGE_SECTION(_struct) \
205 { \
206 .start = STRUCT_SECTION_START(_struct), \
207 .end = STRUCT_SECTION_END(_struct), \
208 .stride = sizeof(struct _struct), \
209 .indirect = false, \
210 }
211
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))
231
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))
252
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 })
268
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__)
285
289
302struct k_obj_type *z_obj_type_init(struct k_obj_type *type,
303 uint32_t id, size_t off);
304
317void k_obj_type_init_range(struct k_obj_type *type, const void *start,
318 const void *end, size_t stride, bool indirect);
319
332
353 int (*func)(struct k_obj_core *obj_core, void *data),
354 void *data);
355
375 int (*func)(struct k_obj_core *obj_core, void *data),
376 void *data);
377
387void k_obj_core_init(struct k_obj_core *obj_core, struct k_obj_type *type);
388
406void k_obj_core_link(struct k_obj_core *obj_core);
407
418 struct k_obj_type *type);
419
430void k_obj_core_unlink(struct k_obj_core *obj_core);
431
443void k_obj_core_evict_range(const void *addr, size_t len);
444
446
452
453#ifdef CONFIG_OBJ_CORE_STATS
462static inline void k_obj_type_stats_init(struct k_obj_type *type,
463 struct k_obj_core_stats_desc *stats_desc)
464{
465 type->stats_desc = stats_desc;
466}
467
477static inline void k_obj_core_stats_init(struct k_obj_core *obj_core,
478 void *stats)
479{
480 obj_core->stats = stats;
481}
482#endif /* CONFIG_OBJ_CORE_STATS */
483
498int k_obj_core_stats_register(struct k_obj_core *obj_core, void *stats,
499 size_t stats_len);
500
514
530int k_obj_core_stats_raw(struct k_obj_core *obj_core, void *stats,
531 size_t stats_len);
532
549int k_obj_core_stats_query(struct k_obj_core *obj_core, void *stats,
550 size_t stats_len);
551
563int k_obj_core_stats_reset(struct k_obj_core *obj_core);
564
578
591
593#endif /* ZEPHYR_INCLUDE_KERNEL_OBJ_CORE_H_ */
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.