<commit_before>/**
 * \file
 * \brief Kernel scheduling policy: Rate-Based Earliest Deadline (RBED)
 *
 * The algorithm is described in the paper "Dynamic Integrated
 * Scheduling of Hard Real-Time, Soft Real-Time and Non-Real-Time
 * Processes" by <NAME> of UC Santa Cruz.
 *
 * Note that while in the paper real number arithmetic is used on some
 * variables, we employ fixed-point integer arithmetic within #SPECTRUM
 * in these cases.
 */

/*
 * Copyright (c) 2007, 2008, 2009, 2010, ETH Zurich.
 * All rights reserved.
 *
 * This file is distributed under the terms in the attached LICENSE file.
 * If you do not find this file, copies can be found by writing to:
 * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group.
 */

/**
 * Implementation Notes
 *
 * real-time tasks:
 *  the behaviour of real-time tasks is characterized by four parameters: wcet
 *  (worst case execution time), period, deadline, and release_time.  Besides
 *  release_time, the values of these parameters are not changed by the
 *  scheduler. RT tasks are considered to be periodic. Note that the
 *  interpretation of the parameters is a little different than the original RBED
 *  paper.
 *
 *  ->release_time is the time that the task is ready to be scheduled. RT tasks
 *  with ->release_time in the future are not effectively considered to be on
 *  the runqueue and are ignored by the scheduler.  In order to meet its
 *  deadline the task needs to be scheduled no later than ->release_time +
 *  ->deadline. EDF guarantees this property, as long as the utilization rate
 *  is <= 1.
 *
 *  The execution of an rt task for a particular period ends either when: (a)
 *  the task runs outs of budget (->etime >= ->wcet), or (b) the task yields
 *  using scheduler_yield(). When this happens the task's ->etime is reset to
 *  0, while ->release_time is increased by ->period. Note that
 *  scheduler_remove() does not finalize the current period of the task. Also,
 *  note that depending on ->period, there might be a case that an rt task is
 *  not executed, even if the CPU is idle.
 *
 * best-effort tasks:
 *  for best-effort tasks the scheduler is responsible to assigns proper values
 *  the RT parameters. Also, To prioritize between BE tasks, the scheduler uses
 *  ->weight.
 */

#include <limits.h>
#ifndef SCHEDULER_SIMULATOR
#       include <kernel.h>
#       include <dispatch.h>
#       include <trace/trace.h>
#endif

#define SPECTRUM        1000000

/**
 * Minimum resource rate reserved for best-effort processes, in #SPECTRUM.
 * We set this to 10%.
 */
#define BETA            (SPECTRUM / 10)

#define MAX(a, b)       ((a) > (b) ? (a) : (b))
#define MIN(a, b)       ((a) < (b) ? (a) : (b))

#include <timer.h> // update_sched_timer

/**
 * Head and tail of the scheduling queue, respectively.
 */
static struct dcb *queue_head = NULL;
// queue_tail has to be global, as its used from assembly
struct dcb *queue_tail = NULL;

/// Last (currently) scheduled task, for accounting purposes
static struct dcb *lastdisp = NULL;

/**
 * CPU utilization in percent for hard real-time and soft real-time
 * processes, as well as weight for best-effort processes. 'w_be'
 * counts only runnable tasks.
 */
static unsigned int u_hrt = 0; ///< utilization for hard real-time tasks
static unsigned int u_srt = 0; ///< utilization for sort real-time tasks
static unsigned int w_be = 0;  ///< aggregate weight over all best-effort tasks
static unsigned int n_be = 0;  ///< number of best-efforst tasks
<commit_msg>schedule_rbed.c: move include of timer.h so that simulator compiles<commit_after>/**
 * \file
 * \brief Kernel scheduling policy: Rate-Based Earliest Deadline (RBED)
 *
 * The algorithm is described in the paper "Dynamic Integrated
 * Scheduling of Hard Real-Time, Soft Real-Time and Non-Real-Time
 * Processes" by <NAME> of UC Santa Cruz.
 *
 * Note that while in the paper real number arithmetic is used on some
 * variables, we employ fixed-point integer arithmetic within #SPECTRUM
 * in these cases.
 */

/*
 * Copyright (c) 2007, 2008, 2009, 2010, ETH Zurich.
 * All rights reserved.
 *
 * This file is distributed under the terms in the attached LICENSE file.
 * If you do not find this file, copies can be found by writing to:
 * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group.
 */

/**
 * Implementation Notes
 *
 * real-time tasks:
 *  the behaviour of real-time tasks is characterized by four parameters: wcet
 *  (worst case execution time), period, deadline, and release_time.  Besides
 *  release_time, the values of these parameters are not changed by the
 *  scheduler. RT tasks are considered to be periodic. Note that the
 *  interpretation of the parameters is a little different than the original RBED
 *  paper.
 *
 *  ->release_time is the time that the task is ready to be scheduled. RT tasks
 *  with ->release_time in the future are not effectively considered to be on
 *  the runqueue and are ignored by the scheduler.  In order to meet its
 *  deadline the task needs to be scheduled no later than ->release_time +
 *  ->deadline. EDF guarantees this property, as long as the utilization rate
 *  is <= 1.
 *
 *  The execution of an rt task for a particular period ends either when: (a)
 *  the task runs outs of budget (->etime >= ->wcet), or (b) the task yields
 *  using scheduler_yield(). When this happens the task's ->etime is reset to
 *  0, while ->release_time is increased by ->period. Note that
 *  scheduler_remove() does not finalize the current period of the task. Also,
 *  note that depending on ->period, there might be a case that an rt task is
 *  not executed, even if the CPU is idle.
 *
 * best-effort tasks:
 *  for best-effort tasks the scheduler is responsible to assigns proper values
 *  the RT parameters. Also, To prioritize between BE tasks, the scheduler uses
 *  ->weight.
 */

#include <limits.h>
#ifndef SCHEDULER_SIMULATOR
#       include <kernel.h>
#       include <dispatch.h>
#       include <trace/trace.h>
#       include <timer.h> // update_sched_timer
#endif

#define SPECTRUM        1000000

/**
 * Minimum resource rate reserved for best-effort processes, in #SPECTRUM.
 * We set this to 10%.
 */
#define BETA            (SPECTRUM / 10)

#define MAX(a, b)       ((a) > (b) ? (a) : (b))
#define MIN(a, b)       ((a) < (b) ? (a) : (b))


/**
 * Head and tail of the scheduling queue, respectively.
 */
static struct dcb *queue_head = NULL;
// queue_tail has to be global, as its used from assembly
struct dcb *queue_tail = NULL;

/// Last (currently) scheduled task, for accounting purposes
static struct dcb *lastdisp = NULL;

/**
 * CPU utilization in percent for hard real-time and soft real-time
 * processes, as well as weight for best-effort processes. 'w_be'
 * counts only runnable tasks.
 */
static unsigned int u_hrt = 0; ///< utilization for hard real-time tasks
static unsigned int u_srt = 0; ///< utilization for sort real-time tasks
static unsigned int w_be = 0;  ///< aggregate weight over all best-effort tasks
static unsigned int n_be = 0;  ///< number of best-efforst tasks

{'fraction_non_alphanumeric': 0.0906790383804302, 'fraction_numerical': 0.01068466188668635, 'mean_word_length': 3.33252131546894, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2093936', 'n_tokens_mistral': 2172, 'n_tokens_neox': 2049, 'n_words': 978}