Arm 中的任务切换

Cru*_*her 5 arm context-switch

我正在阅读 Arm 架构参考手册,我想我有一些理论问题。

好吧,一开始我很困惑上下文切换是否意味着任务切换?

其次,通过对Intel 80386架构的体验,我记得有任务描述符和其他一些自动保存任务状态的机制,在arm中它是如何完成的?比如说“手动”,通过将寄存器保存在堆栈中来完成吗?

该 ASID(应用程序空间 ID)是否与我之前询问的内容相关联?

Nik*_*ntz 0

如果您有 2 个线程,每个线程都有一个堆栈(寄存器值的数组),那么如果您有一个保存线程状态并切换到另一个线程的 ISR,那么这就是上下文切换。最简单的示例是具有 2 个线程(1 个生产者,1 个消费者)的操作系统,其中开关看起来与此处的代码类似。

/*
 * threadswitch - change thread
 * 
 * The thread stack-pointer is supplied as a parameter.
 * The old thread's stack-pointer value is saved to the array
 * os_thread_info_array, and a new thread is selected from the array.
 * The stack pointer of the new thread is returned.
 */
unsigned int os_internal_threadswitch( unsigned int old_sp )
{
  unsigned int new_sp;

  os_number_of_thread_switches += 1; /* Increase thread-switch counter. */

  /* Print line 1 of an informational message. */
  printf( "\nPerforming thread-switch number %d. The system has been running for %d ticks.\n",
          os_number_of_thread_switches,
          os_get_internal_globaltime() );

  /* Save the stack pointer of the old thread. */
  os_thread_info_array[ os_currently_running_thread ].thread_sp = old_sp;

  /* Print part 1 of a message saying which threads are involved this time. */
  printf( "Switching from thread-ID %d ",
          os_thread_info_array[ os_currently_running_thread ].thread_id );

  /* Perform the scheduling decision (round-robin). */
  os_currently_running_thread += 1;
  if( os_currently_running_thread >= os_current_thread_count )
  {
    os_currently_running_thread = 0;
  }

  /* Print part 2 of the informational message. */
  printf( "to thread-ID %d.\n",
          os_thread_info_array[ os_currently_running_thread ].thread_id );

  /* Get the stack pointer of the new thread. */
  new_sp = os_thread_info_array[ os_currently_running_thread ].thread_sp;

  /* Return. */
  return( new_sp );
}
Run Code Online (Sandbox Code Playgroud)