CNDP 22.08.0
Loading...
Searching...
No Matches
cli_cmap.h
1/* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright (c) 2019-2022 Intel Corporation.
3 */
4
5#ifndef __CLI_CMAP_H
6#define __CLI_CMAP_H
7
8#include <stdint.h> // for uint16_t, uint8_t, uint32_t
9
10#include "cne_common.h" // for CNDP_API
11
12#define MAX_LINE_SIZE 4096
13
14#define PROC_CPUINFO "/proc/cpuinfo"
15
16typedef union {
17 struct {
18 uint8_t lid; /* Logical core ID */
19 uint8_t sid; /* CPU socket ID */
20 uint8_t cid; /* Physical CPU core ID */
21 uint8_t tid; /* Hyper-thread ID */
22 };
23 uint32_t word;
24} lc_info_t;
25
26typedef struct lcore {
27 struct lcore *next;
28 lc_info_t u;
29} lcore_t;
30
31struct cmap {
32 uint16_t num_cores;
33 uint16_t sid_cnt;
34 uint16_t cid_cnt;
35 uint16_t tid_cnt;
36 lc_info_t *linfo;
37 char *model;
38 int cache_size;
39};
40
41typedef lcore_t *(*do_line_fn)(const char *line, lcore_t *);
42typedef unsigned (*getter_fn)(const lcore_t *);
43typedef void (*setter_fn)(lcore_t *, unsigned new_val);
44
45typedef struct action {
46 const char *desc;
47 do_line_fn fn;
48} action_t;
49
56CNDP_API struct cmap *cmap_create(void);
57
64CNDP_API char *cmap_cpu_model(void);
65
72CNDP_API void cmap_free(struct cmap *cmap);
73
82static inline unsigned int
83cmap_socket_id(const lcore_t *lc)
84{
85 return lc->u.sid;
86}
87
98static inline void
99cmap_set_socket_id(lcore_t *lc, unsigned v)
100{
101 lc->u.sid = v;
102}
103
112static inline unsigned int
113cmap_core_id(const lcore_t *lc)
114{
115 return lc->u.cid;
116}
117
128static inline void
129cmap_set_core_id(lcore_t *lc, unsigned v)
130{
131 lc->u.cid = v;
132}
133
142static inline unsigned int
143cmap_thread_id(const lcore_t *lc)
144{
145 return lc->u.tid;
146}
147
156static inline unsigned int
157cmap_cnt(lcore_t *lc, getter_fn get)
158{
159 unsigned cnt = 0;
160
161 if (!get)
162 return cnt;
163
164 while (lc) {
165 if (cnt < get(lc))
166 cnt = get(lc);
167 lc = lc->next;
168 }
169 return cnt + 1;
170}
171
172#endif /*_CLI_CMAP_H */