genode/repos/base-fiasco/src/core/platform_thread.cc

174 lines
4.3 KiB
C++
Raw Normal View History

2011-12-22 16:19:25 +01:00
/*
* \brief Fiasco thread facility
* \author Christian Helmuth
* \date 2006-04-11
*
* This provides a thread object and uses l4_inter_task_ex_regs() for L4 thread
* manipulation.
*/
/*
* Copyright (C) 2006-2017 Genode Labs GmbH
2011-12-22 16:19:25 +01:00
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU Affero General Public License version 3.
2011-12-22 16:19:25 +01:00
*/
/* Genode includes */
#include <base/log.h>
2011-12-22 16:19:25 +01:00
#include <util/string.h>
#include <cpu_session/cpu_session.h>
2011-12-22 16:19:25 +01:00
/* core includes */
#include <platform_thread.h>
/* base-internal includes */
#include <base/internal/capability_space_tpl.h>
2011-12-22 16:19:25 +01:00
/* Fiasco includes */
namespace Fiasco {
#include <l4/sys/types.h>
#include <l4/sys/syscalls.h>
#include <l4/sys/utcb.h>
#include <l4/sys/kdebug.h>
}
using namespace Genode;
using namespace Fiasco;
int Platform_thread::start(void *ip, void *sp)
{
l4_umword_t dummy, old_eflags;
l4_threadid_t thread = _l4_thread_id;
l4_threadid_t pager = _pager
? Capability_space::ipc_cap_data(_pager->cap()).dst
: L4_INVALID_ID;
2011-12-22 16:19:25 +01:00
l4_threadid_t preempter = L4_INVALID_ID;
l4_threadid_t cap_handler = L4_INVALID_ID;
l4_inter_task_ex_regs(thread, (l4_umword_t)ip, (l4_umword_t)sp,
&preempter, &pager, &cap_handler,
&old_eflags, &dummy, &dummy,
0, l4_utcb_get());
if (old_eflags == ~0UL)
warning("old eflags == ~0 on ex_regs ",
Hex(thread.id.task), ".", Hex(thread.id.lthread));
2011-12-22 16:19:25 +01:00
fiasco_register_thread_name(thread, _name);
return 0;
}
void Platform_thread::pause()
{
warning(__func__, " not implemented");
2011-12-22 16:19:25 +01:00
}
void Platform_thread::resume()
{
warning(__func__, " not implemented");
2011-12-22 16:19:25 +01:00
}
void Platform_thread::bind(int thread_id, l4_threadid_t l4_thread_id, Platform_pd *pd)
{
_thread_id = thread_id;
_l4_thread_id = l4_thread_id;
_platform_pd = pd;
}
void Platform_thread::unbind()
{
l4_umword_t dummy, old_eflags;
l4_threadid_t thread = _l4_thread_id;
l4_threadid_t pager = thread;
l4_threadid_t preempter = L4_INVALID_ID;
l4_threadid_t cap_handler = L4_INVALID_ID;
fiasco_register_thread_name(thread, "<dead>");
/*
* The Fiasco thread is halted by setting itself as pager and forcing
* pagefault at 0, where Genode never maps a page. The bottom line is the
* thread blocks in IPC to itself.
*/
l4_inter_task_ex_regs(thread, 0, 0,
&preempter, &pager, &cap_handler,
&old_eflags, &dummy, &dummy,
0, l4_utcb_get());
if (old_eflags == ~0UL)
warning("old eflags == ~0 on ex_regs ",
Hex(thread.id.task), ".", Hex(thread.id.lthread));
2011-12-22 16:19:25 +01:00
_thread_id = THREAD_INVALID;
_l4_thread_id = L4_INVALID_ID;
_platform_pd = 0;
}
Follow practices suggested by "Effective C++" The patch adjust the code of the base, base-<kernel>, and os repository. To adapt existing components to fix violations of the best practices suggested by "Effective C++" as reported by the -Weffc++ compiler argument. The changes follow the patterns outlined below: * A class with virtual functions can no longer publicly inherit base classed without a vtable. The inherited object may either be moved to a member variable, or inherited privately. The latter would be used for classes that inherit 'List::Element' or 'Avl_node'. In order to enable the 'List' and 'Avl_tree' to access the meta data, the 'List' must become a friend. * Instead of adding a virtual destructor to abstract base classes, we inherit the new 'Interface' class, which contains a virtual destructor. This way, single-line abstract base classes can stay as compact as they are now. The 'Interface' utility resides in base/include/util/interface.h. * With the new warnings enabled, all member variables must be explicitly initialized. Basic types may be initialized with '='. All other types are initialized with braces '{ ... }' or as class initializers. If basic types and non-basic types appear in a row, it is nice to only use the brace syntax (also for basic types) and align the braces. * If a class contains pointers as members, it must now also provide a copy constructor and assignment operator. In the most cases, one would make them private, effectively disallowing the objects to be copied. Unfortunately, this warning cannot be fixed be inheriting our existing 'Noncopyable' class (the compiler fails to detect that the inheriting class cannot be copied and still gives the error). For now, we have to manually add declarations for both the copy constructor and assignment operator as private class members. Those declarations should be prepended with a comment like this: /* * Noncopyable */ Thread(Thread const &); Thread &operator = (Thread const &); In the future, we should revisit these places and try to replace the pointers with references. In the presence of at least one reference member, the compiler would no longer implicitly generate a copy constructor. So we could remove the manual declaration. Issue #465
2017-12-21 15:42:15 +01:00
void Platform_thread::state(Thread_state)
2011-12-22 16:19:25 +01:00
{
warning(__func__, " not implemented");
throw Cpu_thread::State_access_failed();
}
Thread_state Platform_thread::state()
{
Thread_state s;
2011-12-22 16:19:25 +01:00
l4_umword_t old_eflags, ip, sp;
l4_threadid_t thread = _l4_thread_id;
l4_threadid_t pager = L4_INVALID_ID;
l4_threadid_t preempter = L4_INVALID_ID;
l4_threadid_t cap_handler = L4_INVALID_ID;
l4_inter_task_ex_regs(thread, ~0UL, ~0UL,
&preempter, &pager, &cap_handler,
&old_eflags, &ip, &sp,
L4_THREAD_EX_REGS_NO_CANCEL, l4_utcb_get());
if (old_eflags == ~0UL)
warning("old eflags == ~0 on ex_regs ",
Hex(thread.id.task), ".", Hex(thread.id.lthread));
2011-12-22 16:19:25 +01:00
/* fill thread state structure */
s.ip = ip;
s.sp = sp;
2011-12-22 16:19:25 +01:00
return s;
2011-12-22 16:19:25 +01:00
}
void Platform_thread::cancel_blocking()
{
l4_umword_t dummy;
l4_threadid_t invalid = L4_INVALID_ID;
l4_inter_task_ex_regs(_l4_thread_id, ~0UL, ~0UL,
&invalid, &invalid, &invalid,
&dummy, &dummy, &dummy, 0, l4_utcb_get());
}
Platform_thread::Platform_thread(size_t, const char *name, unsigned,
Affinity::Location, addr_t,
thread API & CPU session: accounting of CPU quota In the init configuration one can configure the donation of CPU time via 'resource' tags that have the attribute 'name' set to "CPU" and the attribute 'quantum' set to the percentage of CPU quota that init shall donate. The pattern is the same as when donating RAM quota. ! <start name="test"> ! <resource name="CPU" quantum="75"/> ! </start> This would cause init to try donating 75% of its CPU quota to the child "test". Init and core do not preserve CPU quota for their own requirements by default as it is done with RAM quota. The CPU quota that a process owns can be applied through the thread constructor. The constructor has been enhanced by an argument that indicates the percentage of the programs CPU quota that shall be granted to the new thread. So 'Thread(33, "test")' would cause the backing CPU session to try to grant 33% of the programs CPU quota to the thread "test". By now, the CPU quota of a thread can't be altered after construction. Constructing a thread with CPU quota 0 doesn't mean the thread gets never scheduled but that the thread has no guaranty to receive CPU time. Such threads have to live with excess CPU time. Threads that already existed in the official repositories of Genode were adapted in the way that they receive a quota of 0. This commit also provides a run test 'cpu_quota' in base-hw (the only kernel that applies the CPU-quota scheme currently). The test basically runs three threads with different physical CPU quota. The threads simply count for 30 seconds each and the test then checks wether the counter values relate to the CPU-quota distribution. fix #1275
2014-10-16 11:15:46 +02:00
int thread_id)
2011-12-22 16:19:25 +01:00
: _thread_id(thread_id), _l4_thread_id(L4_INVALID_ID), _pager(0)
{
strncpy(_name, name, sizeof(_name));
}
Platform_thread::~Platform_thread()
{
/*
* We inform our protection domain about thread destruction, which will end up in
* Thread::unbind()
*/
if (_platform_pd)
_platform_pd->unbind_thread(this);
}