Skip to content

Commit

Permalink
core: remove Core_env
Browse files Browse the repository at this point in the history
This patch adjusts the last remaining callers of 'core_env' and removes
the 'Core_env' interface.

- Core's RAM/cap accounts are now represented by 'Core_account'
  implementing the 'Pd_account' interface.

- The former parts of 'Core_env' are now initialized in sequence
  in 'bootstrap_component'.

- 'Core_child' has been moved to a header to reduce the code in
  'main.cc' to a bare minimum. This as a preparation for the
  plan of making 'main.cc' specific for each kernel.

Fixes genodelabs#5408
  • Loading branch information
nfeske committed Dec 18, 2024
1 parent 4aabe39 commit 44860e8
Show file tree
Hide file tree
Showing 16 changed files with 270 additions and 322 deletions.
6 changes: 3 additions & 3 deletions repos/base-linux/src/core/platform.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
#include <base/internal/capability_space_tpl.h>

/* local includes */
#include "platform.h"
#include "core_env.h"
#include "resource_path.h"
#include <platform.h>
#include <core_region_map.h>
#include <resource_path.h>

/* Linux includes */
#include <core_linux_syscalls.h>
Expand Down
1 change: 0 additions & 1 deletion repos/base-nova/src/core/pager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include <platform_thread.h>
#include <imprint_badge.h>
#include <cpu_thread_component.h>
#include <core_env.h>

/* NOVA includes */
#include <nova/syscalls.h>
Expand Down
1 change: 0 additions & 1 deletion repos/base-nova/src/core/vm_session_component.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include <util/flex_iterator.h>

/* core includes */
#include <core_env.h>
#include <cpu_thread_component.h>
#include <dataspace_component.h>
#include <vm_session_component.h>
Expand Down
60 changes: 60 additions & 0 deletions repos/base/src/core/include/core_account.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* \brief RAM and cap account of the core component
* \author Norman Feske
* \date 2024-12-17
*/

/*
* Copyright (C) 2016-2024 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 _CORE__INCLUDE__CORE_ACCOUNT_H_
#define _CORE__INCLUDE__CORE_ACCOUNT_H_

namespace Core { struct Core_account; }


struct Core::Core_account : Rpc_object<Pd_account>
{
Rpc_entrypoint &_ep;

Ram_quota_guard ram_quota_guard;
Cap_quota_guard cap_quota_guard;

Core::Account<Ram_quota> ram_account { ram_quota_guard, "core" };
Core::Account<Cap_quota> cap_account { cap_quota_guard, "core" };

Core_account(Rpc_entrypoint &ep, Ram_quota ram, Cap_quota caps)
: _ep(ep), ram_quota_guard(ram), cap_quota_guard(caps) { ep.manage(this); }

Transfer_result _with_pd(Capability<Pd_account> cap, auto const &fn)
{
if (this->cap() == cap)
return Transfer_result::OK;

return _ep.apply(cap, [&] (Pd_session_component *pd_ptr) {
Transfer_result result = Transfer_result::INVALID;
if (pd_ptr)
fn(*pd_ptr, result);
return result; });
}

Transfer_result transfer_quota(Capability<Pd_account> to, Cap_quota amount) override
{
return _with_pd(to, [&] (Pd_session_component &pd, Transfer_result &result) {
pd.with_cap_account([&] (Account<Cap_quota> &to) {
result = cap_account.transfer_quota(to, amount); }); });
}

Transfer_result transfer_quota(Capability<Pd_account> to, Ram_quota amount) override
{
return _with_pd(to, [&] (Pd_session_component &pd, Transfer_result &result) {
pd.with_ram_account([&] (Account<Ram_quota> &to) {
result = ram_account.transfer_quota(to, amount); }); });
}
};

#endif /* _CORE__INCLUDE__CORE_ACCOUNT_H_ */
113 changes: 113 additions & 0 deletions repos/base/src/core/include/core_child.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*
* \brief Child policy for the init component
* \author Norman Feske
* \date 2024-12-17
*/

/*
* Copyright (C) 2016-2024 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 _CORE__INCLUDE__CORE_CHILD_H_
#define _CORE__INCLUDE__CORE_CHILD_H_

/* Genode includes */
#include <base/service.h>
#include <base/child.h>

/* core includes */
#include <core_account.h>

namespace Core { class Core_child; }


class Core::Core_child : public Child_policy
{
private:

Registry<Service> &_services;
Rpc_entrypoint &_ep;
Region_map &_core_rm;
Ram_allocator &_core_ram;
Core_account &_core_account;

Capability<Cpu_session> _core_cpu_cap;
Cpu_session &_core_cpu;

Cap_quota const _cap_quota;
Ram_quota const _ram_quota;

Id_space<Parent::Server> _server_ids { };

Child _child { _core_rm, _ep, *this };

public:

Core_child(Registry<Service> &services, Rpc_entrypoint &ep,
Region_map &core_rm, Ram_allocator &core_ram,
Core_account &core_account,
Cpu_session &core_cpu, Capability<Cpu_session> core_cpu_cap,
Cap_quota cap_quota, Ram_quota ram_quota)
:
_services(services), _ep(ep), _core_rm(core_rm), _core_ram(core_ram),
_core_account(core_account),
_core_cpu_cap(core_cpu_cap), _core_cpu(core_cpu),
_cap_quota(Child::effective_quota(cap_quota)),
_ram_quota(Child::effective_quota(ram_quota))
{ }


/****************************
** Child-policy interface **
****************************/

Name name() const override { return "init"; }

Route resolve_session_request(Service::Name const &name,
Session_label const &label,
Session::Diag const diag) override
{
Service *service = nullptr;
_services.for_each([&] (Service &s) {
if (!service && s.name() == name)
service = &s; });

if (!service)
throw Service_denied();

return Route { .service = *service,
.label = label,
.diag = diag };
}

void init(Pd_session &, Capability<Pd_session> cap) override
{
_ep.apply(cap, [&] (Pd_session_component *pd_ptr) {
if (pd_ptr)
pd_ptr->ref_accounts(_core_account.ram_account,
_core_account.cap_account); });

_core_account.transfer_quota(cap, _cap_quota);
_core_account.transfer_quota(cap, _ram_quota);
}

void init(Cpu_session &session, Capability<Cpu_session> cap) override
{
session.ref_account(_core_cpu_cap);
_core_cpu.transfer_quota(cap, Cpu_session::quota_lim_upscale(100, 100));
}

Ram_allocator &session_md_ram() override { return _core_ram; }

Pd_account &ref_account() override { return _core_account; }
Capability<Pd_account> ref_account_cap() const override { return _core_account.cap(); }

size_t session_alloc_batch_size() const override { return 128; }

Id_space<Parent::Server> &server_id_space() override { return _server_ids; }
};

#endif /* _CORE__INCLUDE__CORE_CHILD_H_ */
98 changes: 0 additions & 98 deletions repos/base/src/core/include/core_env.h

This file was deleted.

5 changes: 3 additions & 2 deletions repos/base/src/core/include/pd_root.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
#ifndef _CORE__INCLUDE__PD_ROOT_H_
#define _CORE__INCLUDE__PD_ROOT_H_

/* Genode */
/* Genode includes */
#include <root/component.h>
#include <pd_session/connection.h>

/* Core */
/* core includes */
#include <pd_session_component.h>

namespace Core { class Pd_root; }
Expand Down
18 changes: 17 additions & 1 deletion repos/base/src/core/include/pd_session_component.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class Core::Pd_session_component : public Session_object<Pd_session>
_constrained_md_ram_alloc(*this, _ram_quota_guard(), _cap_quota_guard()),
_constrained_core_ram_alloc(_ram_quota_guard(), _cap_quota_guard(), core_mem),
_sliced_heap(_constrained_md_ram_alloc, local_rm),
_ram_ds_factory(ep, phys_alloc, phys_range, local_rm,
_ram_ds_factory(ep, phys_alloc, phys_range,
_constrained_core_ram_alloc),
_signal_broker(_sliced_heap, signal_ep, signal_ep),
_rpc_cap_factory(_sliced_heap),
Expand All @@ -168,6 +168,22 @@ class Core::Pd_session_component : public Session_object<Pd_session>

~Pd_session_component();

void ref_accounts(Account<Ram_quota> &ram_ref, Account<Cap_quota> &cap_ref)
{
_ram_account.construct(_ram_quota_guard(), _label, ram_ref);
_cap_account.construct(_cap_quota_guard(), _label, cap_ref);
}

void with_ram_account(auto const &fn)
{
if (_ram_account.constructed()) fn(*_ram_account);
}

void with_cap_account(auto const &fn)
{
if (_cap_account.constructed()) fn(*_cap_account);
}

/**
* Initialize cap and RAM accounts without providing a reference account
*
Expand Down
1 change: 0 additions & 1 deletion repos/base/src/core/include/ram_dataspace_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ class Core::Ram_dataspace_factory : public Ram_allocator,
Ram_dataspace_factory(Rpc_entrypoint &ep,
Range_allocator &phys_alloc,
Phys_range phys_range,
Region_map &,
Allocator &allocator)
:
_ep(ep), _phys_alloc(phys_alloc), _phys_range(phys_range),
Expand Down
1 change: 1 addition & 0 deletions repos/base/src/core/include/rm_session_component.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <base/rpc_server.h>
#include <rm_session/rm_session.h>
#include <base/session_object.h>
#include <base/heap.h>

/* core includes */
#include <region_map_component.h>
Expand Down
3 changes: 3 additions & 0 deletions repos/base/src/core/include/signal_transmitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ namespace Core {
* argument.
*/
void init_core_signal_transmitter(Rpc_entrypoint &ep);


Rpc_entrypoint &core_signal_ep(Rpc_entrypoint &core_ep);
}

#endif /* _CORE__INCLUDE__SIGNAL_TRANSMITTER_H_ */
Loading

0 comments on commit 44860e8

Please sign in to comment.