2010-08-14 09:56:13 +08:00
|
|
|
/****************************************************************************
|
2014-08-09 05:08:07 +08:00
|
|
|
* sched/paging/pg_miss.c
|
2010-08-14 09:56:13 +08:00
|
|
|
*
|
2024-09-11 19:45:11 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
2021-02-08 23:33:58 +08: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
|
2010-08-14 09:56:13 +08:00
|
|
|
*
|
2021-02-08 23:33:58 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2010-08-14 09:56:13 +08:00
|
|
|
*
|
2021-02-08 23:33:58 +08: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.
|
2010-08-14 09:56:13 +08:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2021-05-18 14:59:14 +08:00
|
|
|
#include <assert.h>
|
2010-08-14 09:56:13 +08:00
|
|
|
#include <errno.h>
|
2010-08-31 10:21:12 +08:00
|
|
|
#include <debug.h>
|
2010-08-14 09:56:13 +08:00
|
|
|
|
|
|
|
#include <nuttx/arch.h>
|
|
|
|
#include <nuttx/sched.h>
|
|
|
|
#include <nuttx/page.h>
|
2017-10-07 22:22:18 +08:00
|
|
|
#include <nuttx/signal.h>
|
2010-08-14 09:56:13 +08:00
|
|
|
|
2024-03-01 03:21:23 +08:00
|
|
|
#ifdef CONFIG_LEGACY_PAGING
|
2010-08-14 09:56:13 +08:00
|
|
|
|
2014-08-09 07:53:55 +08:00
|
|
|
#include "sched/sched.h"
|
2014-08-09 05:08:07 +08:00
|
|
|
#include "paging/paging.h"
|
2010-08-14 09:56:13 +08:00
|
|
|
|
|
|
|
/****************************************************************************
|
2015-10-03 06:30:35 +08:00
|
|
|
* Public Functions
|
2010-08-14 09:56:13 +08:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: pg_miss
|
|
|
|
*
|
|
|
|
* Description:
|
2010-08-14 11:51:03 +08:00
|
|
|
* This function is called from architecture-specific memory segmentation
|
2010-08-14 09:56:13 +08:00
|
|
|
* fault handling logic. This function will perform the following
|
|
|
|
* operations:
|
|
|
|
*
|
|
|
|
* 1) Sanity checking.
|
|
|
|
* - ASSERT if the currently executing task is the page fill worker
|
2013-08-27 23:40:19 +08:00
|
|
|
* thread. The page fill worker thread is how the page fault
|
2010-08-14 09:56:13 +08:00
|
|
|
* is resolved and all logic associated with the page fill worker
|
|
|
|
* must be "locked" and always present in memory.
|
|
|
|
* - ASSERT if an interrupt was executing at the time of the exception.
|
|
|
|
* 2) Block the currently executing task.
|
2022-11-15 16:52:40 +08:00
|
|
|
* - Call up_switch_context() to block the task at the head of the
|
|
|
|
* ready-to-run list. This should cause an interrupt level context
|
|
|
|
* switch to the next highest priority task.
|
2010-08-14 09:56:13 +08:00
|
|
|
* - The blocked task will be marked with state TSTATE_WAIT_PAGEFILL
|
|
|
|
* and will be retained in the g_waitingforfill prioritized task
|
|
|
|
* list.
|
|
|
|
* 3) Boost the page fill worker thread priority.
|
|
|
|
* - Check the priority of the task at the head of the g_waitingforfill
|
|
|
|
* list. If the priority of that task is higher than the current
|
|
|
|
* priority of the page fill worker thread, then boost the priority
|
|
|
|
* of the page fill worker thread to that priority.
|
|
|
|
* 4) Signal the page fill worker thread.
|
|
|
|
* - Is there a page fill pending? If not then signal the worker
|
|
|
|
* thread to start working on the queued page fill requests.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* None - The head of the ready-to-run list is assumed to be task that
|
|
|
|
* caused the exception.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None - Either this function function succeeds or an assertion occurs.
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* - It is assumed that this function is called from the level of an
|
|
|
|
* exception handler and that all interrupts are disabled.
|
|
|
|
* - It is assumed that currently executing task (the one at the head of
|
|
|
|
* the ready-to-run list) is the one that cause the fault. This will
|
|
|
|
* always be true unless the page fault occurred in an interrupt handler.
|
|
|
|
* Interrupt handling logic must always be present and "locked" into
|
|
|
|
* memory.
|
|
|
|
* - As mentioned above, the task causing the page fault must not be the
|
2010-08-14 11:51:03 +08:00
|
|
|
* page fill worker thread because that is the only way to complete the
|
|
|
|
* page fill.
|
2010-08-14 09:56:13 +08:00
|
|
|
*
|
|
|
|
* NOTES:
|
|
|
|
* 1. One way to accomplish this would be a two pass link phase:
|
|
|
|
* - In the first phase, create a partially linked objected containing
|
|
|
|
* all interrupt/exception handling logic, the page fill worker thread
|
|
|
|
* plus all parts of the IDLE thread (which must always be available
|
|
|
|
* for execution).
|
|
|
|
* - All of the .text and .rodata sections of this partial link should
|
|
|
|
* be collected into a single section.
|
|
|
|
* - The second link would link the partially linked object along with
|
|
|
|
* the remaining object to produce the final binary. The linker
|
|
|
|
* script should position the "special" section so that it lies
|
|
|
|
* in a reserved, "non-swappable" region.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void pg_miss(void)
|
|
|
|
{
|
2016-02-07 07:44:41 +08:00
|
|
|
FAR struct tcb_s *ftcb = this_task();
|
2013-02-05 02:46:28 +08:00
|
|
|
FAR struct tcb_s *wtcb;
|
2010-08-14 09:56:13 +08:00
|
|
|
|
|
|
|
/* Sanity checking
|
|
|
|
*
|
|
|
|
* ASSERT if the currently executing task is the page fill worker thread.
|
2013-08-27 23:40:19 +08:00
|
|
|
* The page fill worker thread is how the page fault is resolved and
|
2010-08-14 09:56:13 +08:00
|
|
|
* all logic associated with the page fill worker must be "locked" and
|
|
|
|
* always present in memory.
|
|
|
|
*/
|
|
|
|
|
2016-06-21 01:59:15 +08:00
|
|
|
pginfo("Blocking TCB: %p PID: %d\n", ftcb, ftcb->pid);
|
2010-08-14 09:56:13 +08:00
|
|
|
DEBUGASSERT(g_pgworker != ftcb->pid);
|
|
|
|
|
|
|
|
/* Block the currently executing task
|
2022-11-15 16:52:40 +08:00
|
|
|
* - Call up_switch_context() to block the task at the head of the
|
|
|
|
* ready-to-run list. This should cause an interrupt level context
|
|
|
|
* switch to the next highest priority task.
|
2010-08-14 09:56:13 +08:00
|
|
|
* - The blocked task will be marked with state TSTATE_WAIT_PAGEFILL
|
|
|
|
* and will be retained in the g_waitingforfill prioritized task list.
|
2018-11-30 20:54:15 +08:00
|
|
|
*
|
|
|
|
* Need to firstly check that this is not the idle task,descheduling
|
|
|
|
* that isn't going to end well.
|
2010-08-14 09:56:13 +08:00
|
|
|
*/
|
|
|
|
|
2022-10-28 14:22:17 +08:00
|
|
|
DEBUGASSERT(!is_idle_task(ftcb));
|
2022-11-13 20:39:14 +08:00
|
|
|
|
2024-01-19 20:57:04 +08:00
|
|
|
/* Remove the tcb task from the running list. */
|
2022-11-13 20:39:14 +08:00
|
|
|
|
2024-01-19 20:57:04 +08:00
|
|
|
nxsched_remove_self(ftcb);
|
2022-11-13 20:39:14 +08:00
|
|
|
|
|
|
|
/* Add the task to the specified blocked task list */
|
|
|
|
|
|
|
|
ftcb->task_state = TSTATE_WAIT_PAGEFILL;
|
2024-03-19 12:33:08 +08:00
|
|
|
nxsched_add_prioritized(ftcb, list_waitingforfill());
|
2022-11-13 20:39:14 +08:00
|
|
|
|
2024-01-19 20:57:04 +08:00
|
|
|
/* Now, perform the context switch */
|
2022-11-13 20:39:14 +08:00
|
|
|
|
2024-01-19 20:57:04 +08:00
|
|
|
up_switch_context(this_task(), ftcb);
|
2010-08-14 09:56:13 +08:00
|
|
|
|
|
|
|
/* Boost the page fill worker thread priority.
|
|
|
|
* - Check the priority of the task at the head of the g_waitingforfill
|
|
|
|
* list. If the priority of that task is higher than the current
|
|
|
|
* priority of the page fill worker thread, then boost the priority
|
|
|
|
* of the page fill worker thread to that priority.
|
|
|
|
*/
|
|
|
|
|
2020-05-09 22:04:45 +08:00
|
|
|
wtcb = nxsched_get_tcb(g_pgworker);
|
2010-08-14 09:56:13 +08:00
|
|
|
DEBUGASSERT(wtcb != NULL);
|
|
|
|
|
|
|
|
if (wtcb->sched_priority < ftcb->sched_priority)
|
|
|
|
{
|
|
|
|
/* Reprioritize the page fill worker thread */
|
|
|
|
|
2016-06-21 01:59:15 +08:00
|
|
|
pginfo("New worker priority. %d->%d\n",
|
|
|
|
wtcb->sched_priority, ftcb->sched_priority);
|
2020-05-10 02:40:14 +08:00
|
|
|
nxsched_set_priority(wtcb, ftcb->sched_priority);
|
2010-08-14 09:56:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Signal the page fill worker thread.
|
|
|
|
* - Is there a page fill pending? If not then signal the worker
|
|
|
|
* thread to start working on the queued page fill requests.
|
|
|
|
*/
|
|
|
|
|
2010-08-16 00:50:25 +08:00
|
|
|
if (!g_pftcb)
|
2010-08-14 09:56:13 +08:00
|
|
|
{
|
2016-06-21 01:59:15 +08:00
|
|
|
pginfo("Signaling worker. PID: %d\n", g_pgworker);
|
2023-03-25 04:12:41 +08:00
|
|
|
nxsig_kill(g_pgworker, SIGPAGING);
|
2010-08-14 09:56:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-01 03:21:23 +08:00
|
|
|
#endif /* CONFIG_LEGACY_PAGING */
|