From 29c4ed45cc698e16d671c3c0428645c37c76c908 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Mon, 6 Mar 2017 15:42:30 +0100 Subject: [PATCH] init: use Prio_levels type instead of basic type --- repos/os/src/init/child.cc | 2 +- repos/os/src/init/child.h | 18 +++++++++--------- repos/os/src/init/main.cc | 2 +- repos/os/src/init/types.h | 2 ++ repos/os/src/init/utils.h | 12 ++++++------ 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/repos/os/src/init/child.cc b/repos/os/src/init/child.cc index 90680b6333..bf98db273f 100644 --- a/repos/os/src/init/child.cc +++ b/repos/os/src/init/child.cc @@ -621,7 +621,7 @@ Init::Child::Child(Env &env, Name_registry &name_registry, Ram_quota ram_limit, Ram_limit_accessor &ram_limit_accessor, - long prio_levels, + Prio_levels prio_levels, Affinity::Space const &affinity_space, Registry &parent_services, Registry &child_services) diff --git a/repos/os/src/init/child.h b/repos/os/src/init/child.h index 558e9988c0..43024bfc27 100644 --- a/repos/os/src/init/child.h +++ b/repos/os/src/init/child.h @@ -134,7 +134,7 @@ class Init::Child : Child_policy, Child_service::Wakeup } }; - Resources _resources_from_start_node(Xml_node start_node, long prio_levels, + Resources _resources_from_start_node(Xml_node start_node, Prio_levels prio_levels, Affinity::Space const &affinity_space) { size_t cpu_quota_pc = 0; @@ -156,13 +156,13 @@ class Init::Child : Child_policy, Child_service::Wakeup } }); - return Resources { log2(prio_levels), - priority_from_xml(start_node, prio_levels), - Affinity(affinity_space, - affinity_location_from_xml(affinity_space, start_node)), - Ram_quota { ram_bytes }, - cpu_quota_pc, - constrain_phys }; + return Resources { log2(prio_levels.value), + priority_from_xml(start_node, prio_levels), + Affinity(affinity_space, + affinity_location_from_xml(affinity_space, start_node)), + Ram_quota { ram_bytes }, + cpu_quota_pc, + constrain_phys }; } Resources _resources; @@ -360,7 +360,7 @@ class Init::Child : Child_policy, Child_service::Wakeup Name_registry &name_registry, Ram_quota ram_limit, Ram_limit_accessor &ram_limit_accessor, - long prio_levels, + Prio_levels prio_levels, Affinity::Space const &affinity_space, Registry &parent_services, Registry &child_services); diff --git a/repos/os/src/init/main.cc b/repos/os/src/init/main.cc index 415ae8f651..ee2d610459 100644 --- a/repos/os/src/init/main.cc +++ b/repos/os/src/init/main.cc @@ -255,7 +255,7 @@ void Init::Main::_handle_config() _default_route.construct(_heap, _config.xml().sub_node("default-route")); } catch (...) { } - long const prio_levels = prio_levels_from_xml(_config.xml()); + Prio_levels const prio_levels = prio_levels_from_xml(_config.xml()); Affinity::Space const affinity_space = affinity_space_from_xml(_config.xml()); _update_aliases_from_config(); diff --git a/repos/os/src/init/types.h b/repos/os/src/init/types.h index cbf48111f8..46f08d80aa 100644 --- a/repos/os/src/init/types.h +++ b/repos/os/src/init/types.h @@ -26,6 +26,8 @@ namespace Init { struct Ram_quota { size_t value; }; + struct Prio_levels { long value; }; + typedef List > Child_list; } diff --git a/repos/os/src/init/utils.h b/repos/os/src/init/utils.h index ef29314ffc..f75bb46c15 100644 --- a/repos/os/src/init/utils.h +++ b/repos/os/src/init/utils.h @@ -151,19 +151,19 @@ namespace Init { /** * Read priority-levels declaration from config */ - inline long prio_levels_from_xml(Xml_node config) + inline Prio_levels prio_levels_from_xml(Xml_node config) { long const prio_levels = config.attribute_value("prio_levels", 0UL); if (prio_levels && (prio_levels != (1 << log2(prio_levels)))) { warning("prio levels is not power of two, priorities are disabled"); - return 0; + return Prio_levels { 0 }; } - return prio_levels; + return Prio_levels { prio_levels }; } - inline long priority_from_xml(Xml_node start_node, long prio_levels) + inline long priority_from_xml(Xml_node start_node, Prio_levels prio_levels) { long priority = Cpu_session::DEFAULT_PRIORITY; try { start_node.attribute("priority").value(&priority); } @@ -178,8 +178,8 @@ namespace Init { */ priority = -priority; - if (priority && (priority >= prio_levels)) { - long new_prio = prio_levels ? prio_levels-1 : 0; + if (priority && (priority >= prio_levels.value)) { + long new_prio = prio_levels.value ? prio_levels.value - 1 : 0; char name[Service::Name::capacity()]; start_node.attribute("name").value(name, sizeof(name)); warning(Cstring(name), ": invalid priority, upgrading "