Two-Level Stack Scheme for RTOS Memory Optimization

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

In Real-Time Operating Systems (RTOS) based systems, especially in low-cost Machine-Type Communications (MTC) devices, there is a need to reduce memory footprint and RAM usage due to high memory consumption by task stacks, which is challenging given the resource constraints and the fact that tasks are created during boot-up and remain active throughout the device's execution.

Innovation Solution

Implementing a two-level stack scheme where a first level stack is dedicated to each task for suspended states and a second level stack serves as a common pool for tasks in running or ready states, allowing stack pointer movement between levels based on task preemption and resource availability, thereby optimizing memory usage.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Reliability

If every task is allocated a separate stack area in traditional RTOS, then task execution reliability is ensured, but memory consumption increases significantly

Engineering Contradiction:
Improvetask execution reliabilityVSAvoidmemory consumption
Core Design Contradiction:
ReliabilityVSQuantity of substance

Solution Approach 1:

Multiple tasks share a common stack pool instead of each task having a dedicated stack. The stack manager dynamically allocates stack space from the common pool to tasks that need it, merging previously separate stack resources into a unified shared resource that serves multiple tasks.

Inventive Principle:
Principle #5Merging (Combining)

Solution Approach 2:

The stack allocation is made dynamic rather than static. Tasks can dynamically acquire and release stack space as needed during runtime. The stack manager continuously monitors and adjusts stack allocations based on current system state, allowing tasks to obtain stack memory when entering critical sections and release it when done.

Inventive Principle:
Principle #15Dynamics

2Reliability

If stack size is allocated to the highest possible stack limit for each task, then stack overflow is prevented, but unused stack memory is wasted

Engineering Contradiction:
Improvestack overflow preventionVSAvoidunused stack memory
Core Design Contradiction:
ReliabilityVSLoss of energy

Solution Approach 1:

The stack allocation parameters change dynamically based on task needs. Instead of allocating fixed maximum stack sizes to all tasks, the system adjusts the actual stack size allocated to each task based on its current requirements, using metrics like stack usage thresholds and task priority to determine optimal allocation.

Inventive Principle:
Principle #35Parameter changes

Solution Approach 2:

Unused or excess stack memory is recovered and made available for other tasks. When tasks release their stack space or when maximum usage thresholds are exceeded, the stack manager reclaims that memory and returns it to the common pool, making it available for allocation to other tasks that need stack space.

Inventive Principle:
Principle #34Discarding and recovering

3Stability of the object's composition

If tasks are created during boot-up and remain active throughout device execution, then system stability is maintained, but memory requirements remain high

Engineering Contradiction:
Improvesystem stabilityVSAvoidmemory requirements
Core Design Contradiction:
Stability of the object's compositionVSQuantity of substance

Solution Approach 1:

A single common stack pool serves multiple functions and multiple tasks simultaneously. Instead of having dedicated stacks for each task, the universal stack pool can be dynamically allocated to any task that needs it, making the same memory resource serve multiple purposes and multiple tasks throughout system operation.

Inventive Principle:
Principle #6Universality (Multi-functionality)

Data Source

PatentUS10248456B2Method and system for providing stack memory management in real-time operating systems
Publication Date: 2019.04.02 SAMSUNG ELECTRONICS CO LTD
  • US10248456B2 patent drawing
  • US10248456B2 patent drawing
  • US10248456B2 patent drawing

AI summary

A method and system for providing memory management in a Real-Time Operating System (RTOS) based system are provided. The method includes creating a plurality of tasks with a two level stack scheme comprising a first level stack and a second level stack, scheduling a first task for execution by moving a stack pointer from the first level stack to the second level stack, determining whether the first task is pre-empted, allocating the second level stack to the first task in a second state if the first task is not pre-empted, changing an active task for execution, determining whether the first task relinquishes control from the second state and is waiting for a resource, moving the stack pointer back from the second level stack to the first level stack if the first task relinquishes itself and providing the second level stack for use by a second task.