From d941d6bac345959f2646af6d1e4fd2f97f4828a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Tue, 25 Mar 2014 23:32:46 +0100 Subject: [PATCH] Minor cleanup. --- src/system/kernel/system_info.cpp | 104 +++++++++++++++--------------- 1 file changed, 53 insertions(+), 51 deletions(-) diff --git a/src/system/kernel/system_info.cpp b/src/system/kernel/system_info.cpp index 5fa166436e..4308c44b7f 100644 --- a/src/system/kernel/system_info.cpp +++ b/src/system/kernel/system_info.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2013, Haiku, Inc. + * Copyright (c) 2004-2014, Haiku, Inc. * Distributed under the terms of the MIT license. * * Authors: @@ -406,6 +406,57 @@ SystemNotificationService::Listener::OwnerDeleted(AssociatedDataOwner* owner) } +// #pragma mark - private functions + + +static void +count_topology_nodes(const cpu_topology_node* node, uint32& count) +{ + count++; + for (int32 i = 0; i < node->children_count; i++) + count_topology_nodes(node->children[i], count); +} + + +static int32 +get_logical_processor(const cpu_topology_node* node) +{ + while (node->level != CPU_TOPOLOGY_SMT) { + ASSERT(node->children_count > 0); + node = node->children[0]; + } + + return node->id; +} + + +static cpu_topology_node_info* +generate_topology_array(cpu_topology_node_info* topology, + const cpu_topology_node* node, uint32& count) +{ + if (count == 0) + return topology; + + static const topology_level_type mapTopologyLevels[] = { B_TOPOLOGY_SMT, + B_TOPOLOGY_CORE, B_TOPOLOGY_PACKAGE, B_TOPOLOGY_ROOT }; + + STATIC_ASSERT(sizeof(mapTopologyLevels) / sizeof(topology_level_type) + == CPU_TOPOLOGY_LEVELS + 1); + + topology->id = node->id; + topology->level = node->level; + topology->type = mapTopologyLevels[node->level]; + + arch_fill_topology_node(topology, get_logical_processor(node)); + + count--; + topology++; + for (int32 i = 0; i < node->children_count && count > 0; i++) + topology = generate_topology_array(topology, node->children[i], count); + return topology; +} + + // #pragma mark - @@ -459,7 +510,6 @@ get_cpu_info(uint32 firstCPU, uint32 cpuCount, cpu_info* info) } - status_t system_info_init(struct kernel_args *args) { @@ -531,61 +581,13 @@ _user_get_cpu_info(uint32 firstCPU, uint32 cpuCount, cpu_info* userInfo) } -static void -count_topology_nodes(const cpu_topology_node* node, uint32& count) -{ - count++; - for (int32 i = 0; i < node->children_count; i++) - count_topology_nodes(node->children[i], count); -} - - -static int32 -get_logical_processor(const cpu_topology_node* node) -{ - while (node->level != CPU_TOPOLOGY_SMT) { - ASSERT(node->children_count > 0); - node = node->children[0]; - } - - return node->id; -} - - -static cpu_topology_node_info* -generate_topology_array(cpu_topology_node_info* topology, - const cpu_topology_node* node, uint32& count) -{ - if (count == 0) - return topology; - - static const topology_level_type mapTopologyLevels[] = { B_TOPOLOGY_SMT, - B_TOPOLOGY_CORE, B_TOPOLOGY_PACKAGE, B_TOPOLOGY_ROOT }; - - STATIC_ASSERT(sizeof(mapTopologyLevels) / sizeof(topology_level_type) - == CPU_TOPOLOGY_LEVELS + 1); - - topology->id = node->id; - topology->level = node->level; - topology->type = mapTopologyLevels[node->level]; - - arch_fill_topology_node(topology, get_logical_processor(node)); - - count--; - topology++; - for (int32 i = 0; i < node->children_count && count > 0; i++) - topology = generate_topology_array(topology, node->children[i], count); - return topology; -} - - status_t _user_get_cpu_topology_info(cpu_topology_node_info* topologyInfos, uint32* topologyInfoCount) { if (topologyInfoCount == NULL || !IS_USER_ADDRESS(topologyInfoCount)) return B_BAD_ADDRESS; - + const cpu_topology_node* node = get_cpu_topology(); uint32 count = 0;