Skip to content

Commit

Permalink
Merge pull request #2 from 702nADOS/genode-taskmanager
Browse files Browse the repository at this point in the history
taskmanager work in progress
  • Loading branch information
DK87 authored Oct 13, 2016
2 parents 18307e7 + f3db42a commit 1e8613f
Show file tree
Hide file tree
Showing 26 changed files with 462 additions and 52 deletions.
69 changes: 69 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# options: x86 arm
TOOLCHAIN_TARGET ?= arm

# options: see tool/create_builddir
GENODE_TARGET ?= foc_pbxa9

BUILD_DIR ?= build
TOOLCHAIN_BUILD_DIR ?= $(BUILD_DIR)/toolchain-$(TOOLCHAIN_TARGET)
GENODE_BUILD_DIR ?= $(BUILD_DIR)/genode-$(GENODE_TARGET)
BUILD_CONF = $(GENODE_BUILD_DIR)/etc/build.conf

all: toolchain ports platform

# ================================================================
# Genode toolchain. Only needs to be done once per target (x86/arm).
toolchain:
mkdir -p $(TOOLCHAIN_BUILD_DIR)
cd $(TOOLCHAIN_BUILD_DIR);\
../../tool/tool_chain $(TOOLCHAIN_TARGET)
#
# ================================================================


# ================================================================
# Download Genode external sources. Only needs to be done once per system.
ports: foc libports

foc:
$(MAKE) -j -C repos/base-foc prepare

libports:
$(MAKE) -C repos/libports prepare
#
# ================================================================


# ================================================================
# Genode build process. Rebuild subtargets as needed.
platform: genode_build_dir taskmanager

genode_build_dir:
tool/create_builddir $(GENODE_TARGET) BUILD_DIR=$(GENODE_BUILD_DIR)
printf 'REPOSITORIES += $$(GENODE_DIR)/repos/libports\n' >> $(BUILD_CONF)
printf 'REPOSITORIES += $$(GENODE_DIR)/repos/taskmanager\n' >> $(BUILD_CONF)

taskmanager:
$(MAKE) -j -C $(GENODE_BUILD_DIR) taskmanager

# Delete build directory for all target systems. In some cases, subfolders in the contrib directory might be corrupted. Remove manually and re-prepare if necessary.
clean:
rm -rf $(BUILD_DIR)
#
# ================================================================


# ================================================================
# Run Genode with an active dom0 server.
run:
$(MAKE) -j -C $(GENODE_BUILD_DIR) run/taskmanager
#
# ================================================================

# ================================================================
# Requiered packages for relaunched systems
packages:
sudo apt-get update
sudo apt-get install libncurses5-dev texinfo autogen autoconf2.64 g++ libexpat1-dev flex bison gperf cmake libxml2-dev libtool zlib1g-dev libglib2.0-dev make pkg-config gawk subversion expect git libxml2-utils syslinux xsltproc yasm iasl lynx
#
# ================================================================
65 changes: 65 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# genode-taskmanager
The taskmanager is a userspace application for monitoring purpose. It shows all threads currently running on the machine, with their IDs, execution time, ram quota, ram used and overall system load.

### Building
The custom Makefile builds the entire Fiasco.OC and Genode system including its toolchain and external dependencies into a `build/` and `contrib/` directory respectively. To manually execute steps within the build process see the Makefile or the Genode documentation:
http://genode.org/documentation/developer-resources/getting_started

The toolchain installs executables to `/usr/local/genode-gcc` as part of the Genode `tool_chain` script. Everything else stays within the repository.

After a first clone of this branch run `make` once. This will do the following:

* build and install Genode toolchain for `arm` or `x86` (target `toolchain`)
* download required external libraries into the `contrib` folder (target `ports`)
* create the target-specific build directory (target `genode_build_dir`)
* build taskmanager (target `taskmanager`)

After this, only build the targets you need. Inter-target dependencies are not set properly. When changing target platform, use the make target `platform` to only rebuild `genode_build_dir` and `taskmanager`.

To run the Genode taskmanager type `make run`

The Makefile will need additional adjustments for other kernels than Fiasco.OC.

### Required packages
The following packages are required for building the Genode toolchain:

`sudo apt-get install libncurses5-dev texinfo autogen autoconf2.64 g++ libexpat1-dev flex bison gperf cmake libXml2-dev libtool zlib1g-dev libglib2.0-dev`

For building Genode:

`sudo apt-get install make pkg-config gawk subversion expect git`

For running Genode in QEMU:

`sudo apt-get install libxml2-utils syslinux`

Inside QEMU run, if you are told to:

`git submodule update --init pixman`
`git submodule update --init dtc`

For some additional ports you may need:

`sudo apt-get install xsltproc yasm iasl lynx`

### Folder structure
Custom repos:

| Folder | Description |
| ----------------------------------- | ------------------------------------------------ |
| `repos/taskmanager/run/` | run file configuration for task manager |
| `repos/taskmanager/src/taskmanager/re/` | taskmanager |
| `repos/taskmanager/src/idle/` | idle process to show system load |

The provided Makefile creates the following directories:

| Folder | Description |
| --------------------------- | ------------------------- |
| `build/` | all build files |
| `build/toolchain-TARGET/` | Genode toolchain |
| `build/genode-TARGET/` | Genode build dir |
| `contrib/` | external Genode libraries |

### Fine-grained CPU time
The Fiasco.OC kernel by default only returns timing information at a resolution of 1ms. Granularity can be increased by changing line 51 of `build/genode-TARGET/kernel/fiasco.oc/globalconfig.out` to
`CONFIG_FINE_GRAINED_CPUTIME=y`
5 changes: 4 additions & 1 deletion repos/base-foc/src/core/include/cpu_session_component.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ namespace Genode {
{
return { _session_label, _name,
_platform_thread.execution_time(),
_platform_thread.affinity() };
_platform_thread.affinity(),
_platform_thread.prio() };
}


Expand Down Expand Up @@ -245,6 +246,8 @@ namespace Genode {
int transfer_quota(Cpu_session_capability, size_t);
Quota quota() override;

void set(Ram_session_capability ram_cap);


/***********************************
** Fiasco.OC specific extensions **
Expand Down
6 changes: 5 additions & 1 deletion repos/base-foc/src/core/include/platform_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ namespace Genode {
class Platform_pd;
class Platform_thread
{

private:

enum State { DEAD, RUNNING };
Expand Down Expand Up @@ -175,8 +176,11 @@ namespace Genode {
/**
* Return execution time consumed by the thread
*/
unsigned long long execution_time() const { return 0; }
unsigned long long execution_time() const;

unsigned prio() const;

unsigned id() const;

/*******************************
** Fiasco-specific Accessors **
Expand Down
22 changes: 22 additions & 0 deletions repos/base-foc/src/core/platform_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,28 @@ Weak_ptr<Address_space> Platform_thread::address_space()
}


unsigned long long Platform_thread::execution_time() const
{
unsigned long long time = 0;

if (_utcb) {
l4_thread_stats_time(_thread.local.dst());
time = *(l4_kernel_clock_t*)&l4_utcb_mr()->mr[0];
}

return time;
}

unsigned Platform_thread::prio() const
{
return _prio;
}

unsigned Platform_thread::id() const
{
return _thread.local.dst();
}

Platform_thread::Platform_thread(const char *name, unsigned prio, addr_t)
: _state(DEAD),
_core_thread(false),
Expand Down
46 changes: 40 additions & 6 deletions repos/base/include/base/trace/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ namespace Genode { namespace Trace {
struct Policy_id;
struct Subject_id;
struct Execution_time;
struct Subject_info;
struct CPU_info;
struct RAM_info;
} }


Expand Down Expand Up @@ -81,7 +82,7 @@ struct Genode::Trace::Execution_time
/**
* Subject information
*/
class Genode::Trace::Subject_info
class Genode::Trace::CPU_info
{
public:

Expand All @@ -108,20 +109,23 @@ class Genode::Trace::Subject_info
Policy_id _policy_id;
Execution_time _execution_time;
Affinity::Location _affinity;
unsigned _prio;

public:

Subject_info() : _state(INVALID) { }
CPU_info() : _state(INVALID) { }

Subject_info(Session_label const &session_label,
CPU_info(Session_label const &session_label,
Thread_name const &thread_name,
State state, Policy_id policy_id,
Execution_time execution_time,
Affinity::Location affinity)
Affinity::Location affinity,
unsigned prio
)
:
_session_label(session_label), _thread_name(thread_name),
_state(state), _policy_id(policy_id),
_execution_time(execution_time), _affinity(affinity)
_execution_time(execution_time), _affinity(affinity), _prio(prio)
{ }

Session_label const &session_label() const { return _session_label; }
Expand All @@ -130,6 +134,36 @@ class Genode::Trace::Subject_info
Policy_id policy_id() const { return _policy_id; }
Execution_time execution_time() const { return _execution_time; }
Affinity::Location affinity() const { return _affinity; }
unsigned prio() const { return _prio; }
};

class Genode::Trace::RAM_info
{
private:

Session_label _session_label;
Thread_name _thread_name;
size_t _ram_quota;
size_t _ram_used;

public:

RAM_info() {}

RAM_info(Session_label const &session_label,
Thread_name const &thread_name,
size_t ram_quota,
size_t ram_used
)
:
_session_label(session_label), _thread_name(thread_name),
_ram_quota(ram_quota), _ram_used(ram_used)
{ }

Session_label const &session_label() const { return _session_label; }
Thread_name const &thread_name() const { return _thread_name; }
size_t ram_quota() const { return _ram_quota; }
size_t ram_used() const { return _ram_used; }
};

#endif /* _INCLUDE__BASE__TRACE__TYPES_H_ */
3 changes: 3 additions & 0 deletions repos/base/include/cpu_session/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ struct Genode::Cpu_session_client : Rpc_client<Cpu_session>
Ram_dataspace_capability utcb(Thread_capability thread) override {
return call<Rpc_utcb>(thread); }

void set(Ram_session_capability ram_cap) override {
call<Rpc_set>(ram_cap); }

void kill_thread(Thread_capability thread) override {
call<Rpc_kill_thread>(thread); }

Expand Down
6 changes: 5 additions & 1 deletion repos/base/include/cpu_session/cpu_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ struct Genode::Cpu_session : Session
static size_t quota_lim_downscale(size_t const value, size_t const limit) {
return ((T)value * limit) >> Cpu_session::QUOTA_LIMIT_LOG2; }

virtual void set(Ram_session_capability ram_cap) = 0;

/*********************
** RPC declaration **
*********************/
Expand Down Expand Up @@ -331,6 +333,7 @@ struct Genode::Cpu_session : Session
GENODE_RPC(Rpc_ref_account, int, ref_account, Cpu_session_capability);
GENODE_RPC(Rpc_transfer_quota, int, transfer_quota, Cpu_session_capability, size_t);
GENODE_RPC(Rpc_quota, Quota, quota);
GENODE_RPC(Rpc_set, void, set, Ram_session_capability);

/*
* 'GENODE_RPC_INTERFACE' declaration done manually
Expand Down Expand Up @@ -361,8 +364,9 @@ struct Genode::Cpu_session : Session
Meta::Type_tuple<Rpc_ref_account,
Meta::Type_tuple<Rpc_transfer_quota,
Meta::Type_tuple<Rpc_quota,
Meta::Type_tuple<Rpc_set,
Meta::Empty>
> > > > > > > > > > > > > > > > > > > > Rpc_functions;
> > > > > > > > > > > > > > > > > > > > > Rpc_functions;
};

struct Genode::Cpu_session::Quota
Expand Down
2 changes: 2 additions & 0 deletions repos/base/include/ram_session/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ struct Genode::Ram_session_client : Rpc_client<Ram_session>
size_t quota() override { return call<Rpc_quota>(); }

size_t used() override { return call<Rpc_used>(); }

void set_label(char *label) override { call<Rpc_set_label>(label); }
};

#endif /* _INCLUDE__RAM_SESSION__CLIENT_H_ */
5 changes: 4 additions & 1 deletion repos/base/include/ram_session/ram_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ struct Genode::Ram_session : Session
return q > u ? q - u : 0;
}

virtual void set_label(char *label) = 0;


/*********************
** RPC declaration **
Expand All @@ -133,9 +135,10 @@ struct Genode::Ram_session : Session
GENODE_RPC(Rpc_transfer_quota, int, transfer_quota, Ram_session_capability, size_t);
GENODE_RPC(Rpc_quota, size_t, quota);
GENODE_RPC(Rpc_used, size_t, used);
GENODE_RPC(Rpc_set_label, void, set_label, char*);

GENODE_RPC_INTERFACE(Rpc_alloc, Rpc_free, Rpc_ref_account,
Rpc_transfer_quota, Rpc_quota, Rpc_used);
Rpc_transfer_quota, Rpc_quota, Rpc_used, Rpc_set_label);
};

#endif /* _INCLUDE__RAM_SESSION__RAM_SESSION_H_ */
7 changes: 5 additions & 2 deletions repos/base/include/trace_session/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,11 @@ struct Genode::Trace::Session_client : Genode::Rpc_client<Genode::Trace::Session
void resume(Subject_id subject) override {
call<Rpc_resume>(subject); }

Subject_info subject_info(Subject_id subject) override {
return call<Rpc_subject_info>(subject); }
CPU_info cpu_info(Subject_id subject) override {
return call<Rpc_cpu_info>(subject); }

RAM_info ram_info(Subject_id subject) override {
return call<Rpc_ram_info>(subject); }

Dataspace_capability buffer(Subject_id subject) override {
return call<Rpc_buffer>(subject); }
Expand Down
Loading

0 comments on commit 1e8613f

Please sign in to comment.