Commit f8ad2c5f authored by Antônio Augusto Fröhlich's avatar Antônio Augusto Fröhlich
Browse files

Resolving exercise about real-time scheduling: both RM and EDF were wrong on the previous commit.

parent 19483130
......@@ -41,7 +41,7 @@ private:
void operator()() {
if(Criterion::dynamic)
_thread->criterion().update_at_job_release();
_thread->criterion().update();
Semaphore_Handler::operator()();
}
......@@ -131,10 +131,8 @@ private:
};
namespace Scheduling_Criteria {
void EDF::update_at_job_release() {
RTC::Microsecond now = Alarm::elapsed();
_priority = _deadline + (now - _last_release);
_last_release = now;
void EDF::update() {
_priority = _deadline + Alarm::elapsed();
}
};
......
......@@ -35,9 +35,7 @@ namespace Scheduling_Criteria
operator const volatile int() const volatile { return _priority; }
void update_at_job_release() {}
void update_at_job_begin() {}
void update_at_job_end() {}
void update() {}
protected:
volatile int _priority;
......@@ -97,11 +95,8 @@ namespace Scheduling_Criteria
static const bool preemptive = true;
public:
RM(int p): Priority(p), _deadline(0) {} // Aperiodic
RM(const RTC::Microsecond & d): Priority(PERIODIC), _deadline(d) {}
private:
RTC::Microsecond _deadline;
RM(int p): Priority(p) {} // Aperiodic
RM(const RTC::Microsecond & d): Priority(d) {}
};
// Deadline Monotonic
......@@ -148,14 +143,10 @@ namespace Scheduling_Criteria
EDF(int p): Priority(p), _deadline(0) {} // Aperiodic
EDF(const RTC::Microsecond & d): Priority(d), _deadline(d) {}
void update_at_job_release();
void update_at_job_begin() {}
void update_at_job_end() {}
void update();
private:
RTC::Microsecond _deadline;
static volatile RTC::Microsecond _last_release;
};
}
......
......@@ -153,10 +153,6 @@ protected:
if(charge) {
if(Criterion::timed)
_timer->reset();
if(Criterion::dynamic) {
prev->criterion().update_at_job_end();
next->criterion().update_at_job_begin();
}
}
if(prev != next) {
......
#ifndef __traits_h
#define __traits_h
#include <system/config.h>
__BEGIN_SYS
// Global Configuration
template <typename T>
struct Traits
{
static const bool enabled = true;
static const bool debugged = true;
};
template <> struct Traits<Build>
{
enum {LIBRARY};
static const unsigned int MODE = LIBRARY;
enum {IA32};
static const unsigned int ARCH = IA32;
enum {PC};
static const unsigned int MACH = PC;
};
// Utilities
template <> struct Traits<Debug>
{
static const bool error = true;
static const bool warning = true;
static const bool info = false;
static const bool trace = false;
};
template <> struct Traits<Lists>: public Traits<void>
{
static const bool debugged = false;
};
template <> struct Traits<Spin>: public Traits<void>
{
static const bool debugged = false;
};
template <> struct Traits<Heap>: public Traits<void>
{
};
// System Parts (mostly to fine control debbugin)
template <> struct Traits<Boot>: public Traits<void>
{
};
template <> struct Traits<Setup>: public Traits<void>
{
};
template <> struct Traits<Init>: public Traits<void>
{
};
// Common Mediators
template <> struct Traits<Serial_Display>: public Traits<void>
{
static const bool enabled = true;
static const int COLUMNS = 80;
static const int LINES = 24;
static const int TAB_SIZE = 8;
};
__END_SYS
#include __ARCH_TRAITS_H
#include __HEADER_MACH(config)
#include __MACH_TRAITS_H
__BEGIN_SYS
template <> struct Traits<Application>: public Traits<void>
{
static const unsigned int STACK_SIZE = 16 * 1024;
static const unsigned int HEAP_SIZE = 16 * 1024 * 1024;
};
template <> struct Traits<System>: public Traits<void>
{
static const unsigned int mode = Traits<Build>::MODE;
static const bool multithread = true;
static const bool multitask = false && (mode != Traits<Build>::LIBRARY);
static const bool multicore = false && multithread;
static const bool multiheap = (mode != Traits<Build>::LIBRARY) || Traits<Scratchpad>::enabled;
static const bool reboot = true;
static const unsigned int STACK_SIZE = 4 * 1024;
static const unsigned int HEAP_SIZE = 128 * Traits<Application>::STACK_SIZE;
};
// Abstractions
template <> struct Traits<Thread>: public Traits<void>
{
static const bool smp = Traits<System>::multicore;
typedef Scheduling_Criteria::DM Criterion;
static const unsigned int QUANTUM = 10000; // us
static const bool trace_idle = false;
};
template <> struct Traits<Address_Space>: public Traits<void>
{
static const bool enabled = Traits<System>::multiheap;
};
template <> struct Traits<Segment>: public Traits<void>
{
static const bool enabled = Traits<System>::multiheap;
};
template <> struct Traits<Alarm>: public Traits<void>
{
static const bool visible = false;
};
template <> struct Traits<Synchronizer>: public Traits<void>
{
static const bool enabled = Traits<System>::multithread;
};
__END_SYS
#endif
#ifndef __traits_h
#define __traits_h
#include <system/config.h>
__BEGIN_SYS
// Global Configuration
template <typename T>
struct Traits
{
static const bool enabled = true;
static const bool debugged = true;
};
template <> struct Traits<Build>
{
enum {LIBRARY};
static const unsigned int MODE = LIBRARY;
enum {IA32};
static const unsigned int ARCH = IA32;
enum {PC};
static const unsigned int MACH = PC;
};
// Utilities
template <> struct Traits<Debug>
{
static const bool error = true;
static const bool warning = true;
static const bool info = false;
static const bool trace = false;
};
template <> struct Traits<Lists>: public Traits<void>
{
static const bool debugged = false;
};
template <> struct Traits<Spin>: public Traits<void>
{
static const bool debugged = false;
};
template <> struct Traits<Heap>: public Traits<void>
{
};
// System Parts (mostly to fine control debbugin)
template <> struct Traits<Boot>: public Traits<void>
{
};
template <> struct Traits<Setup>: public Traits<void>
{
};
template <> struct Traits<Init>: public Traits<void>
{
};
// Common Mediators
template <> struct Traits<Serial_Display>: public Traits<void>
{
static const bool enabled = true;
static const int COLUMNS = 80;
static const int LINES = 24;
static const int TAB_SIZE = 8;
};
__END_SYS
#include __ARCH_TRAITS_H
#include __HEADER_MACH(config)
#include __MACH_TRAITS_H
__BEGIN_SYS
template <> struct Traits<Application>: public Traits<void>
{
static const unsigned int STACK_SIZE = 16 * 1024;
static const unsigned int HEAP_SIZE = 16 * 1024 * 1024;
};
template <> struct Traits<System>: public Traits<void>
{
static const unsigned int mode = Traits<Build>::MODE;
static const bool multithread = true;
static const bool multitask = false && (mode != Traits<Build>::LIBRARY);
static const bool multicore = false && multithread;
static const bool multiheap = (mode != Traits<Build>::LIBRARY) || Traits<Scratchpad>::enabled;
static const bool reboot = true;
static const unsigned int STACK_SIZE = 4 * 1024;
static const unsigned int HEAP_SIZE = 128 * Traits<Application>::STACK_SIZE;
};
// Abstractions
template <> struct Traits<Thread>: public Traits<void>
{
static const bool smp = Traits<System>::multicore;
typedef Scheduling_Criteria::EDF Criterion;
static const unsigned int QUANTUM = 10000; // us
static const bool trace_idle = false;
};
template <> struct Traits<Address_Space>: public Traits<void>
{
static const bool enabled = Traits<System>::multiheap;
};
template <> struct Traits<Segment>: public Traits<void>
{
static const bool enabled = Traits<System>::multiheap;
};
template <> struct Traits<Alarm>: public Traits<void>
{
static const bool visible = false;
};
template <> struct Traits<Synchronizer>: public Traits<void>
{
static const bool enabled = Traits<System>::multithread;
};
__END_SYS
#endif
#ifndef __traits_h
#define __traits_h
#include <system/config.h>
__BEGIN_SYS
// Global Configuration
template <typename T>
struct Traits
{
static const bool enabled = true;
static const bool debugged = true;
};
template <> struct Traits<Build>
{
enum {LIBRARY};
static const unsigned int MODE = LIBRARY;
enum {IA32};
static const unsigned int ARCH = IA32;
enum {PC};
static const unsigned int MACH = PC;
};
// Utilities
template <> struct Traits<Debug>
{
static const bool error = true;
static const bool warning = true;
static const bool info = false;
static const bool trace = false;
};
template <> struct Traits<Lists>: public Traits<void>
{
static const bool debugged = false;
};
template <> struct Traits<Spin>: public Traits<void>
{
static const bool debugged = false;
};
template <> struct Traits<Heap>: public Traits<void>
{
};
// System Parts (mostly to fine control debbugin)
template <> struct Traits<Boot>: public Traits<void>
{
};
template <> struct Traits<Setup>: public Traits<void>
{
};
template <> struct Traits<Init>: public Traits<void>
{
};
// Common Mediators
template <> struct Traits<Serial_Display>: public Traits<void>
{
static const bool enabled = true;
static const int COLUMNS = 80;
static const int LINES = 24;
static const int TAB_SIZE = 8;
};
__END_SYS
#include __ARCH_TRAITS_H
#include __HEADER_MACH(config)
#include __MACH_TRAITS_H
__BEGIN_SYS
template <> struct Traits<Application>: public Traits<void>
{
static const unsigned int STACK_SIZE = 16 * 1024;
static const unsigned int HEAP_SIZE = 16 * 1024 * 1024;
};
template <> struct Traits<System>: public Traits<void>
{
static const unsigned int mode = Traits<Build>::MODE;
static const bool multithread = true;
static const bool multitask = false && (mode != Traits<Build>::LIBRARY);
static const bool multicore = false && multithread;
static const bool multiheap = (mode != Traits<Build>::LIBRARY) || Traits<Scratchpad>::enabled;
static const bool reboot = true;
static const unsigned int STACK_SIZE = 4 * 1024;
static const unsigned int HEAP_SIZE = 128 * Traits<Application>::STACK_SIZE;
};
// Abstractions
template <> struct Traits<Thread>: public Traits<void>
{
static const bool smp = Traits<System>::multicore;
typedef Scheduling_Criteria::RM Criterion;
static const unsigned int QUANTUM = 10000; // us
static const bool trace_idle = false;
};
template <> struct Traits<Address_Space>: public Traits<void>
{
static const bool enabled = Traits<System>::multiheap;
};
template <> struct Traits<Segment>: public Traits<void>
{
static const bool enabled = Traits<System>::multiheap;
};
template <> struct Traits<Alarm>: public Traits<void>
{
static const bool visible = false;
};
template <> struct Traits<Synchronizer>: public Traits<void>
{
static const bool enabled = Traits<System>::multithread;
};
__END_SYS
#endif
// EPOS EDF Periodic Thread Abstraction Implementation
#include <scheduler.h>
#include <alarm.h>
__BEGIN_SYS
// Class attributes
volatile RTC::Microsecond Scheduling_Criteria::EDF::_last_release;
__END_SYS
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment