From 3f972699884a1c9eb9e4d89b05699a6c321f45cd Mon Sep 17 00:00:00 2001 From: Alexander Boettcher Date: Mon, 13 Jul 2020 09:34:37 +0200 Subject: [PATCH] sculpt_manager: add graphical CPU affinity config Fixes #3820 --- repos/gems/src/app/sculpt_manager/main.cc | 19 ++- .../src/app/sculpt_manager/model/component.h | 10 +- .../app/sculpt_manager/model/runtime_state.h | 15 +- .../app/sculpt_manager/view/popup_dialog.cc | 25 +++ .../app/sculpt_manager/view/popup_dialog.h | 12 ++ .../sculpt_manager/view/resource_dialog.cc | 147 ++++++++++++++++++ .../app/sculpt_manager/view/resource_dialog.h | 74 +++++++++ 7 files changed, 290 insertions(+), 12 deletions(-) create mode 100644 repos/gems/src/app/sculpt_manager/view/resource_dialog.cc create mode 100644 repos/gems/src/app/sculpt_manager/view/resource_dialog.h diff --git a/repos/gems/src/app/sculpt_manager/main.cc b/repos/gems/src/app/sculpt_manager/main.cc index 071c2b7094..8b00fc276f 100644 --- a/repos/gems/src/app/sculpt_manager/main.cc +++ b/repos/gems/src/app/sculpt_manager/main.cc @@ -363,6 +363,7 @@ struct Sculpt::Main : Input_event_handler, Attached_rom_dataspace _editor_saved_rom { _env, "report -> runtime/editor/saved" }; + Affinity::Space _affinity_space { 1, 1 }; /** * Panel_dialog::State interface @@ -886,7 +887,7 @@ struct Sculpt::Main : Input_event_handler, Start_name new_construction(Component::Path const &pkg, Component::Info const &info) override { - return _runtime_state.new_construction(pkg, info); + return _runtime_state.new_construction(pkg, info, _affinity_space); } void _apply_to_construction(Popup_dialog::Action::Apply_to &fn) override @@ -1091,6 +1092,14 @@ struct Sculpt::Main : Input_event_handler, _handle_pci_devices(); _handle_runtime_config(); + /* + * Read static platform information + */ + _platform.xml().with_sub_node("affinity-space", [&] (Xml_node const &node) { + _affinity_space = Affinity::Space(node.attribute_value("width", 1U), + node.attribute_value("height", 1U)); + }); + /* * Generate initial config/managed/deploy configuration */ @@ -1686,11 +1695,9 @@ void Sculpt::Main::_generate_runtime_config(Xml_generator &xml) const gen_parent_service(xml); }); - _platform.xml().with_sub_node("affinity-space", [&] (Xml_node const &node) { - xml.node("affinity-space", [&] () { - xml.attribute("width", node.attribute_value("width", 1U)); - xml.attribute("height", node.attribute_value("height", 1U)); - }); + xml.node("affinity-space", [&] () { + xml.attribute("width", _affinity_space.width()); + xml.attribute("height", _affinity_space.height()); }); xml.node("start", [&] () { diff --git a/repos/gems/src/app/sculpt_manager/model/component.h b/repos/gems/src/app/sculpt_manager/model/component.h index f9d3249b8e..59ff5d2c08 100644 --- a/repos/gems/src/app/sculpt_manager/model/component.h +++ b/repos/gems/src/app/sculpt_manager/model/component.h @@ -37,12 +37,18 @@ struct Sculpt::Component : Noncopyable uint64_t ram { }; size_t caps { }; + Affinity::Space const affinity_space; + Affinity::Location affinity_location { 0, 0, + affinity_space.width(), + affinity_space.height() }; + bool blueprint_known = false; List_model routes { }; - Component(Allocator &alloc, Path const &path, Info const &info) - : _route_update_policy(alloc), path(path), info(info) { } + Component(Allocator &alloc, Path const &path, Info const &info, + Affinity::Space const space) + : _route_update_policy(alloc), path(path), info(info), affinity_space (space) { } ~Component() { diff --git a/repos/gems/src/app/sculpt_manager/model/runtime_state.h b/repos/gems/src/app/sculpt_manager/model/runtime_state.h index be182fc976..bcf0da8950 100644 --- a/repos/gems/src/app/sculpt_manager/model/runtime_state.h +++ b/repos/gems/src/app/sculpt_manager/model/runtime_state.h @@ -107,11 +107,12 @@ class Sculpt::Runtime_state : public Runtime_info */ Launched_child(Allocator &alloc, Start_name const &name, Component::Path const &pkg_path, - Component::Info const &info) + Component::Info const &info, + Affinity::Space const space) : name(name), launcher(), launched(false) { - construction.construct(alloc, pkg_path, info); + construction.construct(alloc, pkg_path, info, space); } void gen_deploy_start_node(Xml_generator &xml) const @@ -125,6 +126,11 @@ class Sculpt::Runtime_state : public Runtime_info if (construction.constructed()) { xml.attribute("pkg", construction->path); + xml.attribute("xpos", construction->affinity_location.xpos()); + xml.attribute("ypos", construction->affinity_location.ypos()); + xml.attribute("width", construction->affinity_location.width()); + xml.attribute("height", construction->affinity_location.height()); + xml.node("route", [&] () { construction->routes.for_each([&] (Route const &route) { route.gen_xml(xml); }); }); @@ -363,7 +369,8 @@ class Sculpt::Runtime_state : public Runtime_info } Start_name new_construction(Component::Path const pkg, - Component::Info const &info) + Component::Info const &info, + Affinity::Space const space) { /* allow only one construction at a time */ discard_construction(); @@ -377,7 +384,7 @@ class Sculpt::Runtime_state : public Runtime_info _currently_constructed = new (_alloc) Registered(_launched_children, _alloc, - unique_name, pkg, info); + unique_name, pkg, info, space); return unique_name; } diff --git a/repos/gems/src/app/sculpt_manager/view/popup_dialog.cc b/repos/gems/src/app/sculpt_manager/view/popup_dialog.cc index 1b7b64bce2..c6d989122d 100644 --- a/repos/gems/src/app/sculpt_manager/view/popup_dialog.cc +++ b/repos/gems/src/app/sculpt_manager/view/popup_dialog.cc @@ -85,6 +85,25 @@ void Popup_dialog::_gen_pkg_elements(Xml_generator &xml, }); }); + if (_resources.constructed() && component.affinity_space.total() > 1) { + xml.node("frame", [&] { + xml.node("vbox", [&] () { + bool const selected = _route_selected(_resources->start_name()); + + if (!selected) + _gen_route_entry(xml, _resources->start_name(), + "Resource assignment", false, "enter"); + + if (selected) { + _gen_route_entry(xml, "back", "Resource assignment", + true, "back"); + + _resources->generate(xml); + } + }); + }); + } + /* * Display "Add component" button once all routes are defined */ @@ -457,6 +476,12 @@ void Popup_dialog::click(Action &action) _state = ROUTE_SELECTED; _selected_route.construct(clicked_route); } + + if (_resources.constructed()) { + action.apply_to_construction([&] (Component &component) { + _resources->click(component); + }); + } } } } diff --git a/repos/gems/src/app/sculpt_manager/view/popup_dialog.h b/repos/gems/src/app/sculpt_manager/view/popup_dialog.h index be14bcb844..6a21c21f65 100644 --- a/repos/gems/src/app/sculpt_manager/view/popup_dialog.h +++ b/repos/gems/src/app/sculpt_manager/view/popup_dialog.h @@ -30,6 +30,8 @@ #include #include +#include + namespace Sculpt { struct Popup_dialog; } @@ -113,6 +115,8 @@ struct Sculpt::Popup_dialog : Dialog Activatable_item _install_item { }; Hoverable_item _route_item { }; + Constructible _resources { }; + enum State { TOP_LEVEL, DEPOT_REQUESTED, DEPOT_SHOWN, DEPOT_SELECTION, INDEX_REQUESTED, INDEX_SHOWN, PKG_REQUESTED, PKG_SHOWN, ROUTE_SELECTED }; @@ -194,6 +198,10 @@ struct Sculpt::Popup_dialog : Dialog _install_item.match(hover, "frame", "vbox", "float", "vbox", "float", "button", "name"), _route_item .match(hover, "frame", "vbox", "frame", "vbox", "hbox", "name")); + if (_resources.constructed() && + hover_result == Dialog::Hover_result::UNMODIFIED) + return _resources->hover(hover, "frame", "vbox", "frame", "vbox"); + return hover_result; } @@ -448,6 +456,10 @@ struct Sculpt::Popup_dialog : Dialog if (_state < PKG_REQUESTED) return; + if (!_resources.constructed()) + _resources.construct(construction.affinity_space, + construction.affinity_location); + _pkg_rom_missing = blueprint_rom_missing(blueprint, construction.path); _pkg_missing = blueprint_missing (blueprint, construction.path); diff --git a/repos/gems/src/app/sculpt_manager/view/resource_dialog.cc b/repos/gems/src/app/sculpt_manager/view/resource_dialog.cc new file mode 100644 index 0000000000..24055d695e --- /dev/null +++ b/repos/gems/src/app/sculpt_manager/view/resource_dialog.cc @@ -0,0 +1,147 @@ +/* + * \brief Resource assignment dialog + * \author Alexander Boettcher + * \date 2020-07-22 + */ + +/* + * Copyright (C) 2020 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU Affero General Public License version 3. + */ + +#include + +using namespace Sculpt; + +void Resource_dialog::_gen_affinity_entry(Xml_generator &xml, + Start_name const &name) const +{ + gen_named_node(xml, "hbox", name, [&] () { + gen_named_node(xml, "float", "center", [&] () { + xml.attribute("north", "yes"); + xml.attribute("south", "yes"); + + xml.node("vbox", [&] () { + if (_space.height() > 1) { + xml.node("label", [&] () { + xml.attribute("text", String<12>("Cores 0-", _space.width() - 1)); + }); + } else { + xml.node("label", [&] () { + xml.attribute("text", String<12>("CPUs 0-", _space.width() - 1)); + }); + } + for (unsigned y = 0; y < _space.height(); y++) { + bool const row = unsigned(_location.ypos()) <= y && y < _location.ypos() + _location.height(); + String<12> const row_id("row", y); + + gen_named_node(xml, "hbox", row_id, [&] () { + if (_space.height() > 1) { + xml.node("label", [&] () { + xml.attribute("text", String<12>("Thread ", y)); + }); + } + for (unsigned x = 0; x < _space.width(); x++) { + String<12> const name_cpu("cpu", x, "x", y); + bool const column = unsigned(_location.xpos()) <= x && x < _location.xpos() + _location.width(); + gen_named_node(xml, "button", name_cpu, [&] () { + if (row && column) + xml.attribute("selected", "yes"); + + xml.attribute("style", "radio"); + _space_item.gen_hovered_attr(xml, name_cpu); + xml.node("hbox", [&] () { }); + }); + } + }); + } + }); + }); + }); +} + +void Resource_dialog::click(Component &component) +{ + if (component.affinity_space.total() <= 1) + return; + + Route::Id const clicked_space = _space_item._hovered; + if (!clicked_space.valid()) + return; + + for (unsigned y = 0; y < component.affinity_space.height(); y++) { + for (unsigned x = 0; x < component.affinity_space.width(); x++) { + String<12> const name_cpu("cpu", x, "x", y); + if (name_cpu != clicked_space) + continue; + + unsigned loc_x = _location.xpos(); + unsigned loc_y = _location.ypos(); + unsigned loc_w = _location.width(); + unsigned loc_h = _location.height(); + + bool handled_x = false; + bool handled_y = false; + + if (x < loc_x) { + loc_w += loc_x - x; + loc_x = x; + handled_x = true; + } else if (x >= loc_x + loc_w) { + loc_w = x - loc_x + 1; + handled_x = true; + } + + if (y < loc_y) { + loc_h += loc_y - y; + loc_y = y; + handled_y = true; + } else if (y >= loc_y + loc_h) { + loc_h = y - loc_y + 1; + handled_y = true; + } + + if (handled_x && !handled_y) { + handled_y = true; + } else + if (handled_y && !handled_x) { + handled_x = true; + } + + if (!handled_x) { + if ((x - loc_x) < (loc_x + loc_w - x)) { + if (x - loc_x + 1 < loc_w) { + loc_w -= x - loc_x + 1; + loc_x = x + 1; + } else { + loc_w = loc_x + loc_w - x; + loc_x = x; + } + } else { + loc_w = x - loc_x; + } + } + + if (!handled_y) { + if ((y - loc_y) < (loc_y + loc_h - y)) { + if (y - loc_y + 1 < loc_h) { + loc_h -= y - loc_y + 1; + loc_y = y + 1; + } else { + loc_h = loc_y + loc_h - y; + loc_y = y; + } + } else { + loc_h = y - loc_y; + } + } + + _location = Affinity::Location(loc_x, loc_y, + loc_w, loc_h); + + component.affinity_location = _location; + } + } +} diff --git a/repos/gems/src/app/sculpt_manager/view/resource_dialog.h b/repos/gems/src/app/sculpt_manager/view/resource_dialog.h new file mode 100644 index 0000000000..6492336aba --- /dev/null +++ b/repos/gems/src/app/sculpt_manager/view/resource_dialog.h @@ -0,0 +1,74 @@ +/* + * \brief Resource assignment dialog + * \author Alexander Boettcher + * \date 2020-07-22 + */ + +/* + * Copyright (C) 2020 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU Affero General Public License version 3. + */ + +#ifndef _VIEW__RESOURCE_DIALOG_H_ +#define _VIEW__RESOURCE_DIALOG_H_ + +/* Genode includes */ +#include +#include + +/* local includes */ +#include +#include +#include + +namespace Sculpt { struct Resource_dialog; } + + +struct Sculpt::Resource_dialog : Noncopyable, Dialog +{ + Affinity::Space const _space; + Affinity::Location _location; + Hoverable_item _space_item { }; + + + Resource_dialog(Affinity::Space space, + Affinity::Location loc) + : _space(space), _location(loc) + { } + + void _gen_affinity_entry(Xml_generator &, Start_name const &) const; + + Hover_result hover(Xml_node hover_node) override + { + Dialog::Hover_result const hover_result = hover(hover_node); + return hover_result; + } + + template + Hover_result hover(Xml_node hover, ARGS &&... args) + { + Dialog::Hover_result const hover_result = Dialog::any_hover_changed( + _space_item.match(hover, args..., "hbox", "float", "vbox", "hbox", "button", "name")); + + return hover_result; + } + + Start_name start_name() const { return "cpus"; } + + void click(Component &); + + void generate(Xml_generator &xml) const override + { + _gen_affinity_entry(xml, start_name()); + } + + void reset() override + { + _space_item._hovered = Hoverable_item::Id(); + _location = Affinity::Location(); + } +}; + +#endif /* _VIEW__RESOURCE_DIALOG_H_ */