topology: system cpu topology

This commit is contained in:
Matheus
2024-10-05 11:32:39 -03:00
parent 8315d5642e
commit 3152d1bc3c
3 changed files with 71 additions and 0 deletions
+36
View File
@@ -0,0 +1,36 @@
#include <kernel/topology.h>
#include <kernel/slab.h>
#include <logging.h>
#include <mutex.h>
#include <spinlock.h>
#include <util.h>
static scache_t *slab_cache;
topology_node_t topology_root;
static MUTEX_DEFINE(allocate_mutex);
static SPINLOCK_DEFINE(tree_lock);
topology_node_t *topology_create_node(void) {
MUTEX_ACQUIRE(&allocate_mutex, false);
if (unlikely(slab_cache == NULL)) {
slab_cache = slab_newcache(sizeof(topology_node_t), 0, NULL, NULL);
__assert(slab_cache);
}
topology_node_t *node = slab_allocate(slab_cache);
MUTEX_RELEASE(&allocate_mutex);
return node;
}
void topology_insert(topology_node_t *node, topology_node_t *parent, int id, cpu_t *cpu) {
long old_ipl = spinlock_acquireraiseipl(&tree_lock, IPL_MAX);
node->id = id;
node->cpu = cpu;
node->parent = parent;
node->sibling = node->parent->children;
node->parent->children = node;
spinlock_releaseloweripl(&tree_lock, old_ipl);
}