source: rtems/cpukit/score/src/threadtickletimeslice.c @ 0faa9dad

4.115
Last change on this file since 0faa9dad was 0faa9dad, checked in by Joel Sherrill <joel.sherrill@…>, on 11/24/10 at 15:51:28

2010-11-24 Gedare Bloom <giddyup44@…>

PR 1647/cpukit

  • posix/src/nanosleep.c, posix/src/sched_yield.c, rtems/src/taskwakeafter.c, sapi/include/confdefs.h, sapi/include/rtems/config.h, sapi/src/exinit.c, score/Makefile.am, score/preinstall.am, score/include/rtems/score/prioritybitmap.h, score/include/rtems/score/thread.h, score/inline/rtems/score/thread.inl, score/src/thread.c, score/src/threadchangepriority.c, score/src/threadclearstate.c, score/src/threadclose.c, score/src/threadinitialize.c, score/src/threadready.c, score/src/threadresume.c, score/src/threadsetpriority.c, score/src/threadsetstate.c, score/src/threadsettransient.c, score/src/threadsuspend.c, score/src/threadtickletimeslice.c: Refactor scheduler out of thread handler to facilitate alternate scheduler implementations.
  • score/src/threadyieldprocessor.c: Removed.
  • score/src/schedulerprioritythreadschedulerupdate.c, score/src/schedulerprioritythreadschedulerfree.c, score/src/schedulerpriorityblock.c, score/src/scheduler.c, score/src/schedulerprioritythreadschedulerallocate.c, score/src/schedulerpriorityunblock.c, score/src/schedulerpriority.c, score/src/schedulerpriorityyield.c, score/include/rtems/score/schedulerpriority.h, score/include/rtems/score/scheduler.h, score/inline/rtems/score/scheduler.inl, score/inline/rtems/score/schedulerpriority.inl: New files.
  • Property mode set to 100644
File size: 2.7 KB
Line 
1/*
2 *  Thread Handler
3 *
4 *
5 *  COPYRIGHT (c) 1989-2009.
6 *  On-Line Applications Research Corporation (OAR).
7 *
8 *  The license and distribution terms for this file may be
9 *  found in found in the file LICENSE in this distribution or at
10 *  http://www.rtems.com/license/LICENSE.
11 *
12 *  $Id$
13 */
14
15#if HAVE_CONFIG_H
16#include "config.h"
17#endif
18
19#include <rtems/system.h>
20#include <rtems/score/apiext.h>
21#include <rtems/score/context.h>
22#include <rtems/score/interr.h>
23#include <rtems/score/isr.h>
24#include <rtems/score/object.h>
25#include <rtems/score/priority.h>
26#include <rtems/score/scheduler.h>
27#include <rtems/score/states.h>
28#include <rtems/score/sysstate.h>
29#include <rtems/score/thread.h>
30#include <rtems/score/threadq.h>
31#include <rtems/score/userext.h>
32#include <rtems/score/wkspace.h>
33
34/*PAGE
35 *
36 *  _Thread_Tickle_timeslice
37 *
38 *  This scheduler routine determines if timeslicing is enabled
39 *  for the currently executing thread and, if so, updates the
40 *  timeslice count and checks for timeslice expiration.
41 *
42 *  Input parameters:   NONE
43 *
44 *  Output parameters:  NONE
45 */
46
47void _Thread_Tickle_timeslice( void )
48{
49  Thread_Control *executing;
50
51  executing = _Thread_Executing;
52
53  #ifdef __RTEMS_USE_TICKS_FOR_STATISTICS__
54    /*
55     *  Increment the number of ticks this thread has been executing
56     */
57    executing->cpu_time_used++;
58  #endif
59
60  /*
61   *  If the thread is not preemptible or is not ready, then
62   *  just return.
63   */
64
65  if ( !executing->is_preemptible )
66    return;
67
68  if ( !_States_Is_ready( executing->current_state ) )
69    return;
70
71  /*
72   *  The cpu budget algorithm determines what happens next.
73   */
74
75  switch ( executing->budget_algorithm ) {
76    case THREAD_CPU_BUDGET_ALGORITHM_NONE:
77      break;
78
79    case THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE:
80    #if defined(RTEMS_SCORE_THREAD_ENABLE_EXHAUST_TIMESLICE)
81      case THREAD_CPU_BUDGET_ALGORITHM_EXHAUST_TIMESLICE:
82    #endif
83      if ( (int)(--executing->cpu_time_budget) <= 0 ) {
84
85        /*
86         *  A yield performs the ready chain mechanics needed when
87         *  resetting a timeslice.  If no other thread's are ready
88         *  at the priority of the currently executing thread, then the
89         *  executing thread's timeslice is reset.  Otherwise, the
90         *  currently executing thread is placed at the rear of the
91         *  FIFO for this priority and a new heir is selected.
92         */
93        _Scheduler_Yield( );
94        executing->cpu_time_budget = _Thread_Ticks_per_timeslice;
95      }
96      break;
97
98    #if defined(RTEMS_SCORE_THREAD_ENABLE_SCHEDULER_CALLOUT)
99      case THREAD_CPU_BUDGET_ALGORITHM_CALLOUT:
100        if ( --executing->cpu_time_budget == 0 )
101          (*executing->budget_callout)( executing );
102        break;
103    #endif
104  }
105}
Note: See TracBrowser for help on using the repository browser.