[Eng-Spa] Context Switching at the Software Middleware Layer

avatar

Titulo.jpg

Hello, Friends of Hive and dear readers, it is a pleasure to be with you presenting topics of science, research, technology, and innovation.
Hola Amigos de Hive y apreciados lectores, un gusto estar con ustedes presentándoles temas de la ciencia, investigación, tecnología e innovación.

Separador AA.jpg

I explained in the post Process or Task Management at the Software Middleware Layer that a process can be running and by the logic of the system it must abandon that action and goes to new states such as Ready (when an interrupt is triggered or there is a call to a routine) or Waiting (I/O requirement) and can resume its execution thread later.

Expliqué en el post de Gestión de Procesos o Tareas en la Capa Intermedia de Software que un proceso puede estar ejecutándose y por la lógica del sistema este debe abandonar dicha acción y pasa a nuevos estados como Listo (cuando se activa una interrupción o hay un llamado a una rutina) o Espera (requrimiento de I/O), pudiendo retomar su hilo de ejecución más tarde.


Well, when these events occur internally, what is known as Context Switching is raised. A process is hidden from end-users, which must be carefully coded by the developers of intermediate layers of software, whose function is to remember and restore the states in which the active programs were before they changed state, to return to their normal thread of execution. Let's see what it refers to.

Pues bien, cuando suceden estos eventos internamente se levanta lo que se conoce como Cambio de Contexto. Proceso oculto a los usuarios finales, que deben ser minuciosamente codificados por los desarrolladores de capas intermedias de software, cuya función es recordar y restaurar los estados en que quedaron los programas activos antes de su cambo de estado, para así regresar a su hilo de ejecución normal. Veamos a continuación, a qué se refiere.

Separador AA.jpg

Desa.png


Context switches computationally require resources and facilities offered by the system architecture, hardware, and software. In addition, the activation of these depends on the execution policy of the processes or tasks, from here on I will use the task to refer to these execution entities.

Los cambios de contexto computacionalmente requieren de recursos y facilidades que ofrece la arquitectura del sistema, hardware y software. Además, de la activación de estos dependiendo de la política de ejecución de los procesos o tareas, de aquí en adelante utilizaré tarea para referirme a estas entidades de ejecución.


So, an application is a program that runs in a normal mode of operation limiting certain resources for the operation of the system. It makes requests to the middle software layer, such as the operating system, where it manages the system through functions and provides the facility that user tasks cannot interfere with each other.

Entonces, una aplicación es un programa que se ejecuta en un modo normal de operación limitando ciertos recursos para la operación del sistema. Realiza peticiones a la capa intermedia de software, como el sistema operativo, donde administra el sistema mediante funciones y provee la facilidad de que las tareas de usuario no puedan interfieran entre sí.


On the other hand, when the operating system is processing an exception with access to all resources, resulting from an interrupt, and subsequently returns control to a task, it rescinds its access rights to all resources, handing over control to the user program until the next interrupt.

Por otro lado, cuando el sistema operativo está procesando una excepción con acceso a todos los recursos, producto de una interrupción, y posteriormente devuelve el control a una tarea, éste rescinde sus derechos de acceso a todos los recursos, entregando el control al programa de usuario, hasta la próxima interrupción.


To do this, the operating system provides an SVC (SuperVisor Call) instruction, which results in the entry of an exception that places the processor in normal mode with access to all resources.

Para poder realizar lo anterior, el sistema operativo ofrece una instrucción del SVC (SuperVisor Call), que produce el ingreso de una excepción que coloca al procesador en el modo normal con acceso a todos los recursos.


n addition, the operating system may be required to do a context switch upon an internal periodic interrupt. Either, generated by a low processor consumption timer, used to count up to a given time, and then when it has reached the limit it requests the context switch operation or, one generated by software through an SVC instruction.

Además, el sistema operativo puede requerir hacer un cambio de contexto ante una interrupción periódica interna. Ya sea, generada por un temporizador de bajo consumo del procesador, utilizado para contar hasta un tiempo dado y luego cuando ha llegado al límite solicita la operación de cambio de contexto o, una generada por software mediante una instrucción del SVC.


Here a data set is generated that describes the state of the processor at a given time, during the execution of a task. Typically, the context of a task is the set of values taken by the processor registers at a particular instant.

Aquí se genera un conjunto de datos que describe el estado del procesador en un momento determinado, durante la ejecución de una tarea. Normalmente, el contexto de una tarea es el conjunto de valores tomados por los registros del procesador en un instante particular.


This context has an operating system data structure associated with each task that contains all the information necessary for task management. This is called a Task Control Block.

Este contexto tiene una estructura de datos del sistema operativo asociada a cada tarea que contiene toda la información necesaria para la gestión de tareas. A este se le llama Bloque de Control de Tareas (Task Control Block).


Let's look at the following example.

Veamos el siguiente ejemplo.


EjemploB.jpg
Figure 1. Example of Context Switching triggered by an Internal Timer Interrupt.
Figura 1. Ejemplo de Cambio de contexto activado por una interrupción Interna por temporizador.


Figure 1 shows the context switch operation, generated by a low processor consumption timer when a task is executed, after which the interrupt proceeds to store the significant data of the evicted task, using another software interrupt. This is followed by the scheduler that must have the new task ready and instructs the software interrupt to load its status data to proceed to execute it. The evicted task can be resumed when the corresponding status is raised again.

La Figura 1 muestra la operación de cambio de contexto, generada por un temporizador de bajo consumo del procesador cuando se ejecuta una tarea, luego de lapso se produce la interrupción que procede a almacenar los datos significativos de la tarea desalojada, mediante otra interrupción por software. Seguido, del planificador que debe tener lista la nueva tarea y ordena a la interrupción por software que cargue los datos de estado de ésta para proceder a ejecutarla. La tarea desalojada, podrá reanudarse cuando se levante nuevamente el estado correspondiente.

Separador 2.jpg

Cierre.jpg


Context switching requires data structures managed by the middle software layer where the information of each task involved in the system is stored, which is executed by the processor with rigorous hardware and/or software interrupt enablement, alternating the privileges of the system tasks.

Para el cambio de contexto son necesarias estructuras de datos manejadas por la capa intermedia de software donde se almacena la información de cada tarea involucrada en el sistema, las cuales son ejecutadas por el procesador con una rigurosa habilitación de interrupciones tanto por hardware y/o software, alternando los privilegios de las tareas del sistema.

Separador AA.jpg

See you soon, I hope the reading has been enriching.

Nos vemos pronto, espero que la lectura haya sido enriquecedora.


I invite you to visit me and follow me @alfonsoalfonsi.

Los invito a visitarme y seguirme en @alfonsoalfonsi.


Separador AA.jpg

Referencias.jpg


Amos, B. (2020). Hands-On RTOS with Microcontrollers: Building real-time embedded systems using FreeRTOS, STM32 MCUs, and SEGGER debug tools. Packt Publishing

Feria Martínez, J. F. (2021). Administración de sistemas operativos. Editorial Síntesis S.A.

Herrera, C., Hajek, D. & Narciso F. (2020). Principles of Operating Systems (2020 ed.). Amazon Digital Services LLC - KDP Print US.


Figure and Image Credits / Créditos a Figuras e Imágenes


Title image was made by @alfonsoalfonsi using CANVAS and PxHere image.

La imagen del Título fue realizado por @alfonsoalfonsi usando CANVAS e imagen de PxHere.


The separator is my property made with CANVAS and
klipartz image.

El separador es de mi propiedad realizado con CANVAS e imagen de klipartz image.


The banner and photographs are my property. Made with Power Point, Paint and Linerock Investment LTD ToonMe application.

El banner y las fotografías son de mi propiedad. Realizados con PowerPoint, Paint y Linerock Investment Aplicación ToonMe.

Baner ENG SPN.jpg



0
0
0.000
5 comments
avatar

Thanks for your contribution to the STEMsocial community. Feel free to join us on discord to get to know the rest of us!

Please consider delegating to the @stemsocial account (85% of the curation rewards are returned).

You may also include @stemsocial as a beneficiary of the rewards of this post to get a stronger support. 
 

0
0
0.000