init: use Prio_levels type instead of basic type

This commit is contained in:
Norman Feske 2017-03-06 15:42:30 +01:00 committed by Christian Helmuth
parent 06943f413d
commit 29c4ed45cc
5 changed files with 19 additions and 17 deletions

View File

@ -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_service> &parent_services,
Registry<Routed_service> &child_services)

View File

@ -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_service> &parent_services,
Registry<Routed_service> &child_services);

View File

@ -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();

View File

@ -26,6 +26,8 @@ namespace Init {
struct Ram_quota { size_t value; };
struct Prio_levels { long value; };
typedef List<List_element<Init::Child> > Child_list;
}

View File

@ -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 "