2008-01-01 14:54:10 +00:00
|
|
|
/****************************************************************************
|
2021-03-08 18:39:04 -03:00
|
|
|
* arch/arm/src/common/arm_exit.c
|
2007-04-28 19:39:18 +00:00
|
|
|
*
|
2020-04-30 10:58:54 -06:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2007-04-28 19:39:18 +00:00
|
|
|
*
|
2020-04-30 10:58:54 -06:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2007-04-28 19:39:18 +00:00
|
|
|
*
|
2020-04-30 10:58:54 -06:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2007-04-28 19:39:18 +00:00
|
|
|
*
|
2008-01-01 14:54:10 +00:00
|
|
|
****************************************************************************/
|
2007-04-28 19:39:18 +00:00
|
|
|
|
2008-01-01 14:54:10 +00:00
|
|
|
/****************************************************************************
|
2007-04-28 19:39:18 +00:00
|
|
|
* Included Files
|
2008-01-01 14:54:10 +00:00
|
|
|
****************************************************************************/
|
2007-04-28 19:39:18 +00:00
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
2009-12-16 20:05:51 +00:00
|
|
|
|
2007-04-28 19:39:18 +00:00
|
|
|
#include <sched.h>
|
|
|
|
#include <debug.h>
|
2009-05-19 20:14:44 +00:00
|
|
|
|
2017-01-13 11:08:24 -06:00
|
|
|
#include <nuttx/arch.h>
|
|
|
|
#include <nuttx/irq.h>
|
2007-04-28 19:39:18 +00:00
|
|
|
#ifdef CONFIG_DUMP_ON_EXIT
|
2017-01-13 11:08:24 -06:00
|
|
|
# include <nuttx/fs/fs.h>
|
2007-04-28 19:39:18 +00:00
|
|
|
#endif
|
|
|
|
|
2014-08-08 16:44:08 -06:00
|
|
|
#include "task/task.h"
|
2014-08-08 17:53:55 -06:00
|
|
|
#include "sched/sched.h"
|
2014-08-27 16:31:02 -06:00
|
|
|
#include "group/group.h"
|
2016-11-24 13:33:43 -06:00
|
|
|
#include "irq/irq.h"
|
2020-04-30 19:20:29 -06:00
|
|
|
#include "arm_internal.h"
|
2014-08-08 16:44:08 -06:00
|
|
|
|
2016-06-17 15:21:07 -06:00
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef CONFIG_DEBUG_SCHED_INFO
|
|
|
|
# undef CONFIG_DUMP_ON_EXIT
|
|
|
|
#endif
|
|
|
|
|
2008-01-01 14:54:10 +00:00
|
|
|
/****************************************************************************
|
2008-01-30 18:49:31 +00:00
|
|
|
* Private Functions
|
2008-01-01 14:54:10 +00:00
|
|
|
****************************************************************************/
|
2007-04-28 19:39:18 +00:00
|
|
|
|
2008-01-01 14:54:10 +00:00
|
|
|
/****************************************************************************
|
2007-04-28 19:39:18 +00:00
|
|
|
* Name: _up_dumponexit
|
|
|
|
*
|
|
|
|
* Description:
|
2008-01-30 18:49:31 +00:00
|
|
|
* Dump the state of all tasks whenever on task exits. This is debug
|
|
|
|
* instrumentation that was added to check file-related reference counting
|
|
|
|
* but could be useful again sometime in the future.
|
2007-04-28 19:39:18 +00:00
|
|
|
*
|
2008-01-01 14:54:10 +00:00
|
|
|
****************************************************************************/
|
2007-04-28 19:39:18 +00:00
|
|
|
|
2016-06-17 15:21:07 -06:00
|
|
|
#ifdef CONFIG_DUMP_ON_EXIT
|
2013-02-04 18:46:28 +00:00
|
|
|
static void _up_dumponexit(FAR struct tcb_s *tcb, FAR void *arg)
|
2007-04-28 19:39:18 +00:00
|
|
|
{
|
2013-01-26 22:25:21 +00:00
|
|
|
FAR struct filelist *filelist;
|
2007-04-28 19:39:18 +00:00
|
|
|
int i;
|
2021-03-16 20:13:02 +08:00
|
|
|
int j;
|
2007-11-23 21:16:43 +00:00
|
|
|
|
2021-11-29 01:05:19 +08:00
|
|
|
sinfo(" TCB=%p name=%s pid=%d\n", tcb, tcb->name, tcb->pid);
|
2016-06-17 15:21:07 -06:00
|
|
|
sinfo(" priority=%d state=%d\n", tcb->sched_priority, tcb->task_state);
|
2007-11-20 20:32:33 +00:00
|
|
|
|
2013-01-26 22:25:21 +00:00
|
|
|
filelist = tcb->group->tg_filelist;
|
2021-03-16 20:13:02 +08:00
|
|
|
for (i = 0; i < filelist->fl_rows; i++)
|
2007-04-28 19:39:18 +00:00
|
|
|
{
|
2021-03-16 20:13:02 +08:00
|
|
|
for (j = 0; j < CONFIG_NFILE_DESCRIPTORS_PER_BLOCK; j++)
|
2007-04-28 19:39:18 +00:00
|
|
|
{
|
2021-03-16 20:13:02 +08:00
|
|
|
struct inode *inode = filelist->fl_files[i][j].f_inode;
|
|
|
|
if (inode)
|
|
|
|
{
|
|
|
|
sinfo(" fd=%d refcount=%d\n",
|
|
|
|
i * CONFIG_NFILE_DESCRIPTORS_PER_BLOCK + j,
|
|
|
|
inode->i_crefs);
|
|
|
|
}
|
2007-04-28 19:39:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-01-01 14:54:10 +00:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
2007-04-28 19:39:18 +00:00
|
|
|
|
2008-01-01 14:54:10 +00:00
|
|
|
/****************************************************************************
|
2020-06-04 14:31:23 +08:00
|
|
|
* Name: up_exit
|
2007-04-28 19:39:18 +00:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This function causes the currently executing task to cease
|
2008-01-30 18:49:31 +00:00
|
|
|
* to exist. This is a special case of task_delete() where the task to
|
|
|
|
* be deleted is the currently executing task. It is more complex because
|
2009-06-25 17:44:35 +00:00
|
|
|
* a context switch must be perform to the next ready to run task.
|
2007-04-28 19:39:18 +00:00
|
|
|
*
|
2008-01-01 14:54:10 +00:00
|
|
|
****************************************************************************/
|
2007-04-28 19:39:18 +00:00
|
|
|
|
2020-06-04 14:31:23 +08:00
|
|
|
void up_exit(int status)
|
2007-04-28 19:39:18 +00:00
|
|
|
{
|
2018-11-24 18:20:57 -06:00
|
|
|
struct tcb_s *tcb = this_task();
|
2007-04-28 19:39:18 +00:00
|
|
|
|
2017-01-13 11:08:24 -06:00
|
|
|
/* Make sure that we are in a critical section with local interrupts.
|
|
|
|
* The IRQ state will be restored when the next task is started.
|
2007-04-28 19:39:18 +00:00
|
|
|
*/
|
|
|
|
|
2020-01-02 10:49:34 -06:00
|
|
|
enter_critical_section();
|
2007-04-28 19:39:18 +00:00
|
|
|
|
2018-11-24 18:20:57 -06:00
|
|
|
sinfo("TCB=%p exiting\n", tcb);
|
2007-04-28 19:39:18 +00:00
|
|
|
|
2016-06-17 15:21:07 -06:00
|
|
|
#ifdef CONFIG_DUMP_ON_EXIT
|
2016-06-20 11:59:15 -06:00
|
|
|
sinfo("Other tasks:\n");
|
2020-05-09 08:04:45 -06:00
|
|
|
nxsched_foreach(_up_dumponexit, NULL);
|
2007-04-28 19:39:18 +00:00
|
|
|
#endif
|
|
|
|
|
2008-01-30 18:49:31 +00:00
|
|
|
/* Destroy the task at the head of the ready to run list. */
|
2007-04-28 19:39:18 +00:00
|
|
|
|
2020-01-02 10:49:34 -06:00
|
|
|
nxtask_exit();
|
2007-04-28 19:39:18 +00:00
|
|
|
|
|
|
|
/* Now, perform the context switch to the new ready-to-run task at the
|
|
|
|
* head of the list.
|
|
|
|
*/
|
|
|
|
|
2016-02-06 13:41:28 -06:00
|
|
|
tcb = this_task();
|
2007-04-28 19:39:18 +00:00
|
|
|
|
2020-12-22 08:49:19 +09:00
|
|
|
/* Adjusts time slice for SCHED_RR & SCHED_SPORADIC cases
|
|
|
|
* NOTE: the API also adjusts the global IRQ control for SMP
|
|
|
|
*/
|
|
|
|
|
|
|
|
nxsched_resume_scheduler(tcb);
|
|
|
|
|
2014-08-27 16:31:02 -06:00
|
|
|
#ifdef CONFIG_ARCH_ADDRENV
|
|
|
|
/* Make sure that the address environment for the previously running
|
|
|
|
* task is closed down gracefully (data caches dump, MMU flushed) and
|
|
|
|
* set up the address environment for the new thread at the head of
|
|
|
|
* the ready-to-run list.
|
|
|
|
*/
|
|
|
|
|
2020-01-02 10:49:34 -06:00
|
|
|
group_addrenv(tcb);
|
2014-08-27 16:31:02 -06:00
|
|
|
#endif
|
|
|
|
|
2007-04-28 19:39:18 +00:00
|
|
|
/* Then switch contexts */
|
|
|
|
|
2020-04-30 12:17:44 +08:00
|
|
|
arm_fullcontextrestore(tcb->xcp.regs);
|
2007-04-28 19:39:18 +00:00
|
|
|
}
|