Change the way thread priority is handled in binfmt/ to better match the way that priority is set up for the builtin tasks

git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5527 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo 2013-01-17 00:30:12 +00:00
parent e7e1c6aee0
commit caeef71797
13 changed files with 189 additions and 49 deletions

View File

@ -321,7 +321,7 @@ int elf_main(int argc, char *argv[])
/* Execute the ELF module */ /* Execute the ELF module */
ret = exec_module(&bin, 50); ret = exec_module(&bin);
mm_update(&g_mmstep, "after exec_module"); mm_update(&g_mmstep, "after exec_module");

View File

@ -243,7 +243,7 @@ int nxflat_main(int argc, char *argv[])
/* Execute the ELF module */ /* Execute the ELF module */
ret = exec_module(&bin, 50); ret = exec_module(&bin);
if (ret < 0) if (ret < 0)
{ {
err("ERROR: Failed to execute program '%s'\n", dirlist[i]); err("ERROR: Failed to execute program '%s'\n", dirlist[i]);

View File

@ -8,7 +8,7 @@
<tr align="center" bgcolor="#e4e4e4"> <tr align="center" bgcolor="#e4e4e4">
<td> <td>
<h1><big><font color="#3c34ec"><i>NuttX Binary Loader</i></font></big></h1> <h1><big><font color="#3c34ec"><i>NuttX Binary Loader</i></font></big></h1>
<p>Last Updated: December 17, 2012</p> <p>Last Updated: January 16, 2013</p>
</td> </td>
</tr> </tr>
</table> </table>
@ -141,7 +141,7 @@ struct binary_s
{ {
/* Information provided to the loader to load and bind a module */ /* Information provided to the loader to load and bind a module */
FAR const char *filename; /* Full path to the binary to be loaded<sup>1</sup> */ FAR const char *filename; /* Full path to the binary to be loaded */
FAR const char **argv; /* Argument list */ FAR const char **argv; /* Argument list */
FAR const struct symtab_s *exports; /* Table of exported symbols */ FAR const struct symtab_s *exports; /* Table of exported symbols */
int nexports; /* The number of symbols in exports[] */ int nexports; /* The number of symbols in exports[] */
@ -153,13 +153,33 @@ struct binary_s
main_t entrypt; /* Entry point into a program module */ main_t entrypt; /* Entry point into a program module */
FAR void *mapped; /* Memory-mapped, address space */ FAR void *mapped; /* Memory-mapped, address space */
FAR void *alloc[BINFMT_NALLOC]; /* Allocated address spaces */ FAR void *alloc[BINFMT_NALLOC]; /* Allocated address spaces */
/* Constructors/destructors */
#ifdef CONFIG_BINFMT_CONSTRUCTORS #ifdef CONFIG_BINFMT_CONSTRUCTORS
FAR binfmt_ctor_t *ctors; /* Pointer to a list of constructors */ FAR binfmt_ctor_t *ctors; /* Pointer to a list of constructors */
FAR binfmt_dtor_t *dtors; /* Pointer to a list of destructors */ FAR binfmt_dtor_t *dtors; /* Pointer to a list of destructors */
uint16_t nctors; /* Number of constructors in the list */ uint16_t nctors; /* Number of constructors in the list */
uint16_t ndtors; /* Number of destructors in the list */ uint16_t ndtors; /* Number of destructors in the list */
#endif #endif
/* Address environment.
*
* addrenv - This is the handle created by up_addrenv_create() that can be
* used to manage the tasks address space.
*/
#ifdef CONFIG_ADDRENV
task_addrenv_t addrenv; /* Task address environment */
#endif
size_t mapsize; /* Size of the mapped address region (needed for munmap) */ size_t mapsize; /* Size of the mapped address region (needed for munmap) */
/* Start-up information that is provided by the loader, but may be modified
* by the caller between load_module() and exec_module() calls.
*/
uint8_t priority; /* Task execution priority */
size_t stacksize; /* Size of the stack in bytes (unallocated) */ size_t stacksize; /* Size of the stack in bytes (unallocated) */
}; };
</pre></ul> </pre></ul>
@ -291,7 +311,7 @@ This is a NuttX internal function so it follows the convention that 0 (<code>OK<
<p><b>Function Prototype:</b></p> <p><b>Function Prototype:</b></p>
<ul><pre> <ul><pre>
#include &lt:nuttx/binfmt/binfmt.h&gt; #include &lt:nuttx/binfmt/binfmt.h&gt;
int exec_module(FAR const struct binary_s *bin, int priority); int exec_module(FAR const struct binary_s *bin);
</pre></ul> </pre></ul>
<p><b>Description:</b></p> <p><b>Description:</b></p>
<ul> <ul>

View File

@ -668,7 +668,7 @@ cat ../syscall/syscall.csv ../libc/lib.csv | sort >tmp.csv
</p> </p>
</ul> </ul>
<p><b><code>int exec_module(FAR const struct binary_s *bin, int priority)</code></b> <p><b><code>int exec_module(FAR const struct binary_s *bin)</code></b>
<ul> <ul>
<p><b>Description:</b> <p><b>Description:</b>
Execute a module that has been loaded into memory by load_module(). Execute a module that has been loaded into memory by load_module().

View File

@ -40,7 +40,6 @@
#include <nuttx/config.h> #include <nuttx/config.h>
#include <string.h> #include <string.h>
#include <sched.h>
#include <debug.h> #include <debug.h>
#include <errno.h> #include <errno.h>
@ -75,8 +74,7 @@
* *
* Description: * Description:
* This is a convenience function that wraps load_ and exec_module into * This is a convenience function that wraps load_ and exec_module into
* one call. The priority of the executed program is set to be the * one call.
* same as the priority of the calling thread.
* *
* Input Parameter: * Input Parameter:
* filename - Fulll path to the binary to be loaded * filename - Fulll path to the binary to be loaded
@ -95,18 +93,8 @@ int exec(FAR const char *filename, FAR const char **argv,
FAR const struct symtab_s *exports, int nexports) FAR const struct symtab_s *exports, int nexports)
{ {
struct binary_s bin; struct binary_s bin;
struct sched_param param;
int ret; int ret;
/* Get the priority of this thread */
ret = sched_getparam(0, &param);
if (ret < 0)
{
bdbg("ERROR: sched_getparam failed: %d\n", errno);
return ERROR;
}
/* Load the module into memory */ /* Load the module into memory */
memset(&bin, 0, sizeof(struct binary_s)); memset(&bin, 0, sizeof(struct binary_s));
@ -121,9 +109,9 @@ int exec(FAR const char *filename, FAR const char **argv,
return ERROR; return ERROR;
} }
/* Then start the module at the priority of this thread */ /* Then start the module */
ret = exec_module(&bin, param.sched_priority); ret = exec_module(&bin);
if (ret < 0) if (ret < 0)
{ {
bdbg("ERROR: Failed to execute program '%s'\n", filename); bdbg("ERROR: Failed to execute program '%s'\n", filename);

View File

@ -144,7 +144,7 @@ static inline int exec_ctors(FAR const struct binary_s *binp)
* *
****************************************************************************/ ****************************************************************************/
int exec_module(FAR const struct binary_s *binp, int priority) int exec_module(FAR const struct binary_s *binp)
{ {
FAR _TCB *tcb; FAR _TCB *tcb;
#ifndef CONFIG_CUSTOM_STACK #ifndef CONFIG_CUSTOM_STACK
@ -187,12 +187,12 @@ int exec_module(FAR const struct binary_s *binp, int priority)
/* Initialize the task */ /* Initialize the task */
ret = task_init(tcb, binp->filename, priority, stack, ret = task_init(tcb, binp->filename, binp->priority, stack,
binp->stacksize, binp->entrypt, binp->argv); binp->stacksize, binp->entrypt, binp->argv);
#else #else
/* Initialize the task */ /* Initialize the task */
ret = task_init(tcb, binp->filename, priority, stack, ret = task_init(tcb, binp->filename, binp->priority, stack,
binp->entrypt, binp->argv); binp->entrypt, binp->argv);
#endif #endif
if (ret < 0) if (ret < 0)

View File

@ -66,6 +66,39 @@
* Private Functions * Private Functions
****************************************************************************/ ****************************************************************************/
/****************************************************************************
* Name: load_default_priority
*
* Description:
* Set the default priority of the module to be loaded. This may be
* changed (1) by the actions of the binary format's load() method if
* the binary format contains priority informaition, or (2) by the user
* between calls to load_module() and exec_module().
*
* Returned Value:
* Zero (OK) is returned on success; Otherwise, -1 (ERROR) is returned and
* the errno variable is set appropriately.
*
****************************************************************************/
static int load_default_priority(FAR struct binary_s *bin)
{
struct sched_param param;
/* Get the priority of this thread */
ret = sched_getparam(0, &param);
if (ret < 0)
{
bdbg("ERROR: sched_getparam failed: %d\n", errno);
return ERROR;
}
/* Save that as the priority of child thread */
bin->priority = param.sched_priority;
}
/**************************************************************************** /****************************************************************************
* Name: load_absmodule * Name: load_absmodule
* *
@ -145,6 +178,16 @@ int load_module(FAR struct binary_s *bin)
if (bin && bin->filename) if (bin && bin->filename)
#endif #endif
{ {
/* Set the default priority of the new program. */
ret = load_default_priority(bin)
if (ret < 0)
{
/* The errno is already set in this case */
return ERROR;
}
/* Were we given a relative path? Or an absolute path to the file to /* Were we given a relative path? Or an absolute path to the file to
* be loaded? Absolute paths start with '/'. * be loaded? Absolute paths start with '/'.
*/ */

View File

@ -136,6 +136,7 @@ static int builtin_loadbinary(struct binary_s *binp)
binp->entrypt = g_builtins[index].main; binp->entrypt = g_builtins[index].main;
binp->stacksize = g_builtins[index].stacksize; binp->stacksize = g_builtins[index].stacksize;
binp->priority = g_builtins[index].priority;
return OK; return OK;
} }

View File

@ -41,9 +41,9 @@ BINFMT_CSRCS += builtin.c
# Builtin library interfaces # Builtin library interfaces
BINFMT_CSRCS += libbuiltin_utils.c BINFMT_CSRCS += libbuiltin_getname.c libbuiltin_isavail.c
# Hook the libelf subdirectory into the build # Hook the libbuiltin subdirectory into the build
VPATH += libbuiltin VPATH += libbuiltin
SUBDIRS += libbuiltin SUBDIRS += libbuiltin

View File

@ -0,0 +1,92 @@
/****************************************************************************
* binfmt/libbuiltin/libbuiltin_getname.c
*
* Originally by:
*
* Copyright (C) 2011 Uros Platise. All rights reserved.
* Author: Uros Platise <uros.platise@isotel.eu>
*
* With subsequent updates, modifications, and general maintenance by:
*
* Copyright (C) 2012-2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/binfmt/builtin.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: builtin_getname
*
* Description:
* Return the name of the application at index in the table of builtin
* applications.
*
****************************************************************************/
FAR const char *builtin_getname(int index)
{
if (index < 0 || index >= number_builtins())
{
return NULL;
}
return g_builtins[index].name;
}

View File

@ -1,5 +1,5 @@
/**************************************************************************** /****************************************************************************
* binfmt/libbuiltin/libbuiltin_utils.c * binfmt/libbuiltin/libbuiltin_isavail.c
* *
* Originally by: * Originally by:
* *
@ -76,25 +76,6 @@
* Public Functions * Public Functions
****************************************************************************/ ****************************************************************************/
/****************************************************************************
* Name: builtin_getname
*
* Description:
* Return the name of the application at index in the table of builtin
* applications.
*
****************************************************************************/
FAR const char *builtin_getname(int index)
{
if (index < 0 || index >= number_builtins())
{
return NULL;
}
return g_builtins[index].name;
}
/**************************************************************************** /****************************************************************************
* Name: builtin_isavail * Name: builtin_isavail
* *

View File

@ -290,6 +290,16 @@ nsh
2. This version has one builtin function: This configuration: 2. This version has one builtin function: This configuration:
apps/examples/hello. apps/examples/hello.
3. This configuration has BINFS enabled so that the builtin applications
can be made visible in the file system. For example:
NuttShell (NSH) NuttX-6.24
nsh> mount -t binfs /bin
nsh> ls /bin
/bin:
hello
nsh>
nsh2 nsh2
Description Description

View File

@ -117,6 +117,12 @@ struct binary_s
#endif #endif
size_t mapsize; /* Size of the mapped address region (needed for munmap) */ size_t mapsize; /* Size of the mapped address region (needed for munmap) */
/* Start-up information that is provided by the loader, but may be modified
* by the caller between load_module() and exec_module() calls.
*/
uint8_t priority; /* Task execution priority */
size_t stacksize; /* Size of the stack in bytes (unallocated) */ size_t stacksize; /* Size of the stack in bytes (unallocated) */
}; };
@ -221,15 +227,14 @@ int unload_module(FAR const struct binary_s *bin);
* *
****************************************************************************/ ****************************************************************************/
int exec_module(FAR const struct binary_s *bin, int priority); int exec_module(FAR const struct binary_s *bin);
/**************************************************************************** /****************************************************************************
* Name: exec * Name: exec
* *
* Description: * Description:
* This is a convenience function that wraps load_ and exec_module into * This is a convenience function that wraps load_ and exec_module into
* one call. The priority of the executed program is set to be the * one call.
* same as the priority of the calling thread.
* *
* Input Parameter: * Input Parameter:
* filename - Fulll path to the binary to be loaded * filename - Fulll path to the binary to be loaded