#1212 closed defect (fixed)

timeslice not working after task mode change

Reported by: Xudong Guan Owned by: Joel Sherrill
Priority: normal Milestone: 4.8
Component: score Version: 4.6
Severity: major Keywords:
Cc: xudong.guan@… Blocked By:
Blocking:

Description

Time slicing will not happen if task mode is changed from a non-timeslicing mode to the time slicing mode after it was started (i.e. by itself in its task body).

An example that reproduces the bug is attached below.

Analysis: The cpu_time_budget field of the victim task is 0 after task creation and is still 0 after task mode change to TIMESLICE. As a result, _Thread_Tickle_timeslice() will cause an underflow of cpu_time_budget, which practically disables timeslicing.

Patch #1 prevents this possible underflow. Patch #2 reset the cpu_time_budget field after mode change.

Patch #1:
diff --git a/src/rtems/cpukit/score/src/threadtickletimeslice.c b/src/rtems/cpukit/score/src/threadtickletimeslice.c
index 786f5c5..3d308bc 100644
--- a/src/rtems/cpukit/score/src/threadtickletimeslice.c
+++ b/src/rtems/cpukit/score/src/threadtickletimeslice.c
@@ -72,7 +72,7 @@ void _Thread_Tickle_timeslice( void )

case THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE:
case THREAD_CPU_BUDGET_ALGORITHM_EXHAUST_TIMESLICE:

  • if ( --executing->cpu_time_budget == 0 ) {

+ if ( (int)(--executing->cpu_time_budget) <= 0 ) {

_Thread_Reset_timeslice();
executing->cpu_time_budget = _Thread_Ticks_per_timeslice;

}

Patch #2:
diff --git a/src/rtems/cpukit/rtems/src/taskmode.c b/src/rtems/cpukit/rtems/src/taskmode.c
index 142812e..77f3a03 100644
--- a/src/rtems/cpukit/rtems/src/taskmode.c
+++ b/src/rtems/cpukit/rtems/src/taskmode.c
@@ -85,9 +85,10 @@ rtems_status_code rtems_task_mode(

executing->is_preemptible = _Modes_Is_preempt(mode_set) ? TRUE : FALSE;

if ( mask & RTEMS_TIMESLICE_MASK ) {

  • if ( _Modes_Is_timeslice(mode_set) )

+ if ( _Modes_Is_timeslice(mode_set) ) {

executing->budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE;

  • else

+ executing->cpu_time_budget = _Thread_Ticks_per_timeslice;
+ } else

executing->budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_NONE;

}

Attachments (1)

test.c (3.5 KB) - added by Xudong Guan on Jan 12, 2007 at 9:56:35 AM.
This source file will reproduce the time slicing problem.

Download all attachments as: .zip

Change History (2)

Changed on Jan 12, 2007 at 9:56:35 AM by Xudong Guan

Attachment: test.c added

This source file will reproduce the time slicing problem.

comment:1 Changed on Aug 5, 2008 at 12:12:47 PM by Joel Sherrill

Resolution: fixed
Status: newclosed

Fix applied to all active branches. Thanks. Sorry for the long delay in applying this.

Note: See TracTickets for help on using tickets.