]> rtime.felk.cvut.cz Git - l4.git/blobdiff - l4/pkg/plr/server/src/fault_handlers/replicalog.cc
Update
[l4.git] / l4 / pkg / plr / server / src / fault_handlers / replicalog.cc
index a146cfaf7a7efff533b1573924d3edf29534035b..41bb508d74c72d96a93043ea0b8bdcf2ec1b67f6 100644 (file)
 #include "../configuration"
 #include "../memory"
 #include "../manager"
+#include "../log"
 
 #include <l4/plr/uu.h>
+#include <l4/plr/measurements.h>
 
 namespace Romain {
        extern InstanceManager *_the_instance_manager;
 }
 
+
+void *to_thread(void *arg)
+{
+       Romain::ReplicaLogObserver *o = reinterpret_cast<Romain::ReplicaLogObserver *>(arg);
+       INFO() << "Waiting for " << o->timeout() << " seconds.";
+       sleep(o->timeout());
+
+       if (o->want_cancel())
+               return NULL;
+
+       l4_debugger_set_object_name(pthread_l4_cap(pthread_self()), "romain::timout");
+
+#if EVENT_LOGGING
+       Measurements::GenericEvent* ev = Romain::globalLogBuf->next();
+       ev->header.tsc                 = Romain::globalLogBuf->getTime(Romain::Log::logLocalTSC);
+       ev->header.vcpu                = (l4_uint32_t)0xDEADBEEF;
+       ev->header.type                = Measurements::Thread_stop;
+#endif
+
+       Romain::_the_instance_manager->show_stats();
+
+       INFO() << "abort";
+
+       enter_kdebug("abort after logdump");
+
+       return NULL;
+}
+
+
 Romain::ReplicaLogObserver::ReplicaLogObserver()
+       : _cancel(false)
 {
-       for (unsigned i = 0; i < Romain::MAX_REPLICAS; ++i) {
+       _timeout = ConfigIntValue("general:logtimeout");
+       if (_timeout > 0) {
+               int err = pthread_create(&_to_thread, NULL, to_thread, this);
+               _check(err != 0, "error creating timeout thread");
+       }
+       for (l4_umword_t i = 0; i < Romain::MAX_REPLICAS; ++i) {
                buffers[i].local_addr = 0;
        }
 }
 
 
 void
-Romain::ReplicaLogObserver::map_eventlog(Romain::App_instance *i, int logsizeMB)
+Romain::ReplicaLogObserver::map_eventlog(Romain::App_instance *i, l4_mword_t logsizeMB)
 {
-       int size = logsizeMB << 20;
-       unsigned mapops = 0;
+       l4_mword_t size = logsizeMB << 20;
+       l4_umword_t mapops = 0;
        l4_addr_t local_map_addr = buffers[i->id()].local_addr;
        l4_addr_t remote_map_addr = Romain::REPLICA_LOG_ADDRESS;
 
        /* 1. map the TSC shared page read-only */
-       INFO() << "shared tsc @ " << Romain::_the_instance_manager->logbuf()->timestamp;
-       i->map_aligned(reinterpret_cast<l4_addr_t>(Romain::_the_instance_manager->logbuf()->timestamp),
+       INFO() << "shared tsc @ " << Romain::globalLogBuf->timestamp;
+       i->map_aligned(reinterpret_cast<l4_addr_t>(Romain::globalLogBuf->timestamp),
                       Romain::REPLICA_TSC_ADDRESS, L4_PAGESHIFT, L4_FPAGE_RO);
 
        /* Now initialize the shared event buffer */
        Measurements::EventBuf* buf = reinterpret_cast<Measurements::EventBuf*>(buffers[i->id()].local_addr);
        buf->index = 0;
        buf->sharedTSC = true;
-       buf->set_buffer((unsigned char*)remote_map_addr + sizeof(Measurements::GenericEvent), (logsizeMB << 20) - sizeof(Measurements::GenericEvent));
+       buf->set_buffer((l4_uint8_t*)remote_map_addr + sizeof(Measurements::GenericEvent), (logsizeMB << 20) - sizeof(Measurements::GenericEvent));
        INFO() << buf->index << " " << buf->size << std::endl;
 
        while (size > 0) {
 
-               unsigned sz, shift;
+               l4_umword_t sz, shift;
 
                if (size >= (4 << 20)) { // map 4 MB page
                        sz = L4_SUPERPAGESIZE;
@@ -82,7 +119,7 @@ void Romain::ReplicaLogObserver::startup_notify(Romain::App_instance *i,
 {
        static bool logregion_reserved = false;
 
-       int logMB = ConfigIntValue("general:replicalogsize");
+       l4_mword_t logMB = ConfigIntValue("general:replicalogsize");
        if (logMB == -1) { // use general logbuf size if no specific size was set
                logMB = ConfigIntValue("general:logbuf");
        }
@@ -119,8 +156,11 @@ Romain::ReplicaLogObserver::notify(Romain::App_instance *i,
 
 
 void
-Romain::ReplicaLogObserver::dump_eventlog(unsigned id) const
+Romain::ReplicaLogObserver::dump_eventlog(l4_umword_t id) const
 {
+       // prevent a potential timeout thread from dumping in parallel
+       const_cast<Romain::ReplicaLogObserver*>(this)->_cancel = true;
+
        INFO() << "Dumping ... " << id;
 
        Measurements::EventBuf *buf = reinterpret_cast<Measurements::EventBuf*>(buffers[id].local_addr);
@@ -131,7 +171,7 @@ Romain::ReplicaLogObserver::dump_eventlog(unsigned id) const
 
        INFO() << "file: " << filename;
 
-       unsigned oldest = buf->oldest();
+       l4_umword_t oldest = buf->oldest();
 
        INFO() << "oldest: " << oldest;
 
@@ -147,7 +187,7 @@ Romain::ReplicaLogObserver::dump_eventlog(unsigned id) const
        /* buf addr is relocated in replica AS -> need to retransform */
        char *bufaddr = ((l4_addr_t)buf->buffer - Romain::REPLICA_LOG_ADDRESS) + (char*)buf;
 
-       INFO() << "file: " << filename << " start " << dump_start << " size " << dump_size;
+       INFO() << "file: " << filename << " start " << std::hex << dump_start << " size " << dump_size;
        uu_dumpz_ringbuffer(filename, bufaddr,
                            buf->size * sizeof(Measurements::GenericEvent),
                            dump_start, dump_size);
@@ -157,7 +197,7 @@ Romain::ReplicaLogObserver::dump_eventlog(unsigned id) const
 void
 Romain::ReplicaLogObserver::status() const
 {
-       for (unsigned i = 0; i < Romain::MAX_REPLICAS; ++i) {
+       for (l4_umword_t i = 0; i < Romain::MAX_REPLICAS; ++i) {
                if (buffers[i].local_addr != 0) {
                        dump_eventlog(i);
                }