mirror of
https://github.com/genodelabs/genode.git
synced 2024-12-19 05:37:54 +00:00
parent
a36465426b
commit
892f51ab1c
2
repos/os/recipes/src/log_core/content.mk
Normal file
2
repos/os/recipes/src/log_core/content.mk
Normal file
@ -0,0 +1,2 @@
|
||||
SRC_DIR = src/app/log_core
|
||||
include $(GENODE_DIR)/repos/base/recipes/src/content.inc
|
1
repos/os/recipes/src/log_core/hash
Normal file
1
repos/os/recipes/src/log_core/hash
Normal file
@ -0,0 +1 @@
|
||||
2017-12-13-b 766edac0917548ff49d04226d07e314b5b05b48a
|
3
repos/os/recipes/src/log_core/used_apis
Normal file
3
repos/os/recipes/src/log_core/used_apis
Normal file
@ -0,0 +1,3 @@
|
||||
base
|
||||
os
|
||||
timer_session
|
91
repos/os/run/log_core.run
Normal file
91
repos/os/run/log_core.run
Normal file
@ -0,0 +1,91 @@
|
||||
if {[have_spec linux]} {
|
||||
puts "\n Run script is not supported on this platform. \n";
|
||||
exit 0
|
||||
}
|
||||
if {[get_cmd_switch --autopilot] && ![have_include "power_on/qemu"]} {
|
||||
puts "\n Run script is not supported on this platform. \n";
|
||||
exit 0
|
||||
}
|
||||
|
||||
proc log_service { } {
|
||||
if { [get_cmd_switch --autopilot] } { return log }
|
||||
return ram
|
||||
}
|
||||
|
||||
build "core init drivers/timer server/vfs server/fs_log app/log_core"
|
||||
|
||||
create_boot_directory
|
||||
|
||||
install_config {
|
||||
<config>
|
||||
<parent-provides>
|
||||
<service name="CPU"/>
|
||||
<service name="IO_PORT"/>
|
||||
<service name="IRQ"/>
|
||||
<service name="LOG"/>
|
||||
<service name="PD"/>
|
||||
<service name="RAM"/>
|
||||
<service name="ROM"/>
|
||||
</parent-provides>
|
||||
<default-route>
|
||||
<any-service> <parent/> </any-service>
|
||||
</default-route>
|
||||
|
||||
<default caps="100"/>
|
||||
|
||||
<start name="timer">
|
||||
<resource name="CPU" quantum="10"/>
|
||||
<resource name="RAM" quantum="1M"/>
|
||||
<provides><service name="Timer"/></provides>
|
||||
</start>
|
||||
|
||||
<start name="vfs">
|
||||
<resource name="RAM" quantum="2M"/>
|
||||
<provides><service name="File_system"/></provides>
|
||||
<config>
|
||||
<vfs>
|
||||
<!-- be careful to avoid endless output loop for core.log -->
|
||||
<dir name="log_core"> <} [log_service] { name="log.log"/> </dir>
|
||||
</vfs>
|
||||
<policy label_prefix="fs_log" writeable="yes"/>
|
||||
</config>
|
||||
</start>
|
||||
|
||||
<start name="fs_log">
|
||||
<resource name="RAM" quantum="2M"/>
|
||||
<provides><service name="LOG"/></provides>
|
||||
<config>
|
||||
<policy label="log_core -> log"/>
|
||||
</config>
|
||||
<route>
|
||||
<service name="File_system"> <child name="vfs"/> </service>
|
||||
<any-service> <parent/> </any-service>
|
||||
</route>
|
||||
</start>
|
||||
|
||||
<start name="log_core">
|
||||
<resource name="RAM" quantum="10M"/>
|
||||
<config period_ms="2000"/>
|
||||
<route>
|
||||
<service name="ROM" unscoped_label="log_core"> <parent/> </service>
|
||||
<service name="ROM" unscoped_label="ld.lib.so"> <parent/> </service>
|
||||
<service name="ROM" label="log"> <parent label="core_log"/> </service>
|
||||
<service name="Timer"> <child name="timer"/> </service>
|
||||
<service name="LOG" label="log"> <child name="fs_log"/> </service>
|
||||
<service name="PD"> <parent/> </service>
|
||||
<service name="CPU"> <parent/> </service>
|
||||
<service name="LOG"> <parent/> </service>
|
||||
</route>
|
||||
</start>
|
||||
</config>
|
||||
}
|
||||
|
||||
build_boot_image "core init timer ld.lib.so vfs fs_log log_core"
|
||||
|
||||
append qemu_args " -nographic "
|
||||
|
||||
if { [get_cmd_switch --autopilot] } {
|
||||
run_genode_until {.*\[init -> vfs] \[.*\n} 20
|
||||
} else {
|
||||
run_genode_until forever
|
||||
}
|
126
repos/os/src/app/log_core/component.cc
Normal file
126
repos/os/src/app/log_core/component.cc
Normal file
@ -0,0 +1,126 @@
|
||||
/*
|
||||
* \brief Component transforming core and kernel output to Genode LOG output
|
||||
* \author Alexander Boettcher
|
||||
* \date 2016-12-22
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2016-2017 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.
|
||||
*/
|
||||
|
||||
/* base includes */
|
||||
#include <base/component.h>
|
||||
#include <log_session/connection.h>
|
||||
|
||||
/* os includes */
|
||||
#include <base/attached_rom_dataspace.h>
|
||||
#include <timer_session/connection.h>
|
||||
|
||||
|
||||
class Log
|
||||
{
|
||||
private:
|
||||
|
||||
Genode::Attached_rom_dataspace _rom_ds;
|
||||
Genode::Log_connection _log;
|
||||
|
||||
char _buffer [Genode::Log_session::MAX_STRING_LEN + 1];
|
||||
unsigned short _buf_pos { 0 };
|
||||
unsigned _rom_pos { 0 };
|
||||
|
||||
unsigned log_size() const { return _rom_ds.size() - sizeof(_rom_pos); }
|
||||
|
||||
char const * char_from_rom(unsigned offset = 0) const
|
||||
{
|
||||
return _rom_ds.local_addr<char const>() + sizeof(_rom_pos) +
|
||||
(_rom_pos + offset) % log_size();
|
||||
}
|
||||
|
||||
unsigned next_pos(unsigned pos) const {
|
||||
return (pos + 1) % log_size(); }
|
||||
|
||||
unsigned end_pos() const {
|
||||
return *_rom_ds.local_addr<unsigned volatile>() % log_size(); }
|
||||
|
||||
void _rom_to_log(unsigned const last_pos)
|
||||
{
|
||||
unsigned up_to_pos = last_pos;
|
||||
|
||||
for (; _rom_pos != next_pos(up_to_pos)
|
||||
; _rom_pos = next_pos(_rom_pos), up_to_pos = end_pos()) {
|
||||
|
||||
char const c = *char_from_rom();
|
||||
|
||||
_buffer[_buf_pos++] = c;
|
||||
|
||||
if (_buf_pos + 1U < sizeof(_buffer) && c != '\n')
|
||||
continue;
|
||||
|
||||
_buffer[_buf_pos] = 0;
|
||||
_log.write(Genode::Log_session::String(_buffer));
|
||||
_buf_pos = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
Log (Genode::Env &env, char const * const rom_name,
|
||||
char const * const log_name)
|
||||
: _rom_ds(env, rom_name), _log(env, log_name)
|
||||
{
|
||||
unsigned const pos = end_pos();
|
||||
|
||||
/* initial check whether already log wrapped at least one time */
|
||||
enum { COUNT_TO_CHECK_FOR_WRAP = 8 };
|
||||
for (unsigned i = 1; i <= COUNT_TO_CHECK_FOR_WRAP; i++) {
|
||||
if (*char_from_rom(pos + i) == 0)
|
||||
continue;
|
||||
|
||||
/* wrap detected, set pos behind last known pos */
|
||||
_rom_pos = next_pos(pos + 1) % log_size();
|
||||
break;
|
||||
}
|
||||
|
||||
_rom_to_log(pos);
|
||||
}
|
||||
|
||||
void log() { _rom_to_log(end_pos()); }
|
||||
};
|
||||
|
||||
struct Monitor
|
||||
{
|
||||
Genode::Env &env;
|
||||
|
||||
Log output { env, "log", "log" };
|
||||
|
||||
Timer::Connection timer { env };
|
||||
|
||||
Genode::Signal_handler<Monitor> interval { env.ep(), *this, &Monitor::check };
|
||||
|
||||
Monitor(Genode::Env &env) : env(env)
|
||||
{
|
||||
timer.sigh(interval);
|
||||
|
||||
Genode::addr_t period_ms = 1000;
|
||||
|
||||
try {
|
||||
Genode::Attached_rom_dataspace config { env, "config" };
|
||||
period_ms = config.xml().attribute_value("period_ms", 1000UL);
|
||||
} catch (...) { }
|
||||
|
||||
Genode::log("update every ", period_ms," ms");
|
||||
|
||||
timer.trigger_periodic(1000UL * period_ms);
|
||||
}
|
||||
|
||||
void check()
|
||||
{
|
||||
output.log();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
void Component::construct(Genode::Env &env) { static Monitor output(env); }
|
3
repos/os/src/app/log_core/target.mk
Normal file
3
repos/os/src/app/log_core/target.mk
Normal file
@ -0,0 +1,3 @@
|
||||
TARGET = log_core
|
||||
SRC_CC = component.cc
|
||||
LIBS = base
|
@ -105,3 +105,4 @@ nic_dump
|
||||
slab
|
||||
ada
|
||||
fs_report
|
||||
log_core
|
||||
|
Loading…
Reference in New Issue
Block a user