Squashed commit of the following:

sched/sched:  Correct some build issues introduced by last set of changes.
    sched/sched:  Add new internal OS function nxsched_setaffinity() that is identical to sched_isetaffinity() except that it does not modify the errno value.  All usage of sched_setaffinity() within the OS is replaced with nxsched_setaffinity().
    sched/sched:  Internal functions sched_reprioritize() and sched_setpriority() no longer movidify the errno value.  Also renamed to nxsched_reprioritize() and sched_setpriority().
    sched/sched:  Add new internal OS function nxsched_getscheduler() that is identical to sched_getscheduler() except that it does not modify the errno value.  All usage of sched_getscheduler() within the OS is replaced with nxsched_getscheduler().
    sched/sched:  Add new internal OS function nxsched_setparam() that is identical to sched_setparam() except that it does not modify the errno value.  All usage of sched_setparam() within the OS is replaced with nxsched_setparam().
    sched/sched:  Add new internal OS function nxsched_getparam() that is identical to sched_getparam() except that it does not modify the errno value (actually, the previous value erroneously neglected to set the errno value to begin with, but this fixes both issues).  All usage of sched_getparam() within the OS is replaced with nxsched_getparam().
This commit is contained in:
Gregory Nutt 2018-01-30 11:07:36 -06:00
parent 947191780f
commit 170a50c690
30 changed files with 605 additions and 246 deletions

12
TODO
View File

@ -255,11 +255,13 @@ o Task/Scheduler (sched/)
message queue used in the OS. I am keeping this issue
open because (1) there are some known remaining calls that
that will modify the errno (such as dup(), dup2(),
sched_getparam(), sched_reprioritize(). sched_setaffinity(),
task_activate(), mq_open(), mq_close(), and others) and (2)
there may still be calls that create cancellation points.
Need to check things like open(), close(), read(), write(),
and possibly others.
task_activate(), mq_open(), mq_close(), and others) and
(2) there may still be calls that create cancellation
points. Need to check things like open(), close(), read(),
write(), and possibly others.
2018-01-30: This change has been completed for the case of
scheduler functions used within the OS: sched_getparam(),
sched_setparam(), sched_getscheduler(), and sched_setaffinity(),
Status: Open
Priority: Low. Things are working OK the way they are. But the design

View File

@ -45,6 +45,7 @@
#include <errno.h>
#include <debug.h>
#include <nuttx/sched.h>
#include <nuttx/arch.h>
#include <nuttx/kmalloc.h>
#include <nuttx/semaphore.h>
@ -477,7 +478,7 @@ FAR struct i2s_dev_s *lc823450_i2sdev_initialize(void)
/* Set the new affinity which assigns to CPU0 */
sched_setaffinity(getpid(), sizeof(cpuset1), &cpuset1);
(void)nxsched_setaffinity(getpid(), sizeof(cpuset1), &cpuset1);
nxsig_usleep(10 * 1000);
#endif
@ -486,7 +487,7 @@ FAR struct i2s_dev_s *lc823450_i2sdev_initialize(void)
#ifdef CONFIG_SMP
/* Restore the original affinity */
sched_setaffinity(getpid(), sizeof(cpuset0), &cpuset0);
(void)nxsched_setaffinity(getpid(), sizeof(cpuset0), &cpuset0);
nxsig_usleep(10 * 1000);
#endif

View File

@ -1,7 +1,7 @@
/****************************************************************************
* binfmt/binfmt_loadmodule.c
*
* Copyright (C) 2009, 2014, 2017 Gregory Nutt. All rights reserved.
* Copyright (C) 2009, 2014, 2017-2018 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -43,6 +43,7 @@
#include <debug.h>
#include <errno.h>
#include <nuttx/sched.h>
#include <nuttx/kmalloc.h>
#include <nuttx/binfmt/binfmt.h>
@ -88,11 +89,10 @@ static int load_default_priority(FAR struct binary_s *bin)
/* Get the priority of this thread */
ret = sched_getparam(0, &param);
ret = nxsched_getparam(0, &param);
if (ret < 0)
{
ret = -get_errno();
berr("ERROR: sched_getparam failed: %d\n", ret);
berr("ERROR: nxsched_getparam failed: %d\n", ret);
return ret;
}

View File

@ -49,6 +49,8 @@
# include <sched.h>
#endif
#include <nuttx/sched.h>
#ifdef CONFIG_RNDIS
# include <nuttx/usb/rndis.h>
#endif
@ -132,7 +134,7 @@ int lc823450_bringup(void)
/* NOTE: pid=4 is assumed to be lpwork */
sched_setaffinity(4, sizeof(cpu_set_t), &cpuset);
(void)nxsched_setaffinity(4, sizeof(cpu_set_t), &cpuset);
#endif
/* If we got here then perhaps not all initialization was successful, but

View File

@ -1,7 +1,7 @@
/****************************************************************************
* config/sim/src/sim_touchscreen.c
*
* Copyright (C) 2011, 2016-2017 Gregory Nutt. All rights reserved.
* Copyright (C) 2011, 2016-2018 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -48,6 +48,7 @@
#include <errno.h>
#include <debug.h>
#include <nuttx/sched.h>
#include <nuttx/board.h>
#include <nuttx/video/fb.h>
#include <nuttx/input/touchscreen.h>
@ -171,10 +172,10 @@ int sim_tsc_setup(int minor)
/* Set the client task priority */
param.sched_priority = CONFIG_SIM_CLIENTPRIO;
ret = sched_setparam(0, &param);
ret = nxsched_setparam(0, &param);
if (ret < 0)
{
gerr("ERROR: sched_setparam failed: %d\n" , ret);
gerr("ERROR: nxsched_setparam failed: %d\n" , ret);
return ret;
}

View File

@ -1,7 +1,7 @@
/****************************************************************************
* fs/aio/aioc_contain.c
*
* Copyright (C) 2014, 2017 Gregory Nutt. All rights reserved.
* Copyright (C) 2014, 2017-2018 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -42,6 +42,7 @@
#include <sched.h>
#include <errno.h>
#include <nuttx/sched.h>
#include <nuttx/fs/fs.h>
#include <nuttx/net/net.h>
@ -139,7 +140,7 @@ FAR struct aio_container_s *aio_contain(FAR struct aiocb *aiocbp)
aioc->aioc_pid = getpid();
#ifdef CONFIG_PRIORITY_INHERITANCE
DEBUGVERIFY(sched_getparam (aioc->aioc_pid, &param));
DEBUGVERIFY(nxsched_getparam (aioc->aioc_pid, &param));
aioc->aioc_prio = param.sched_priority;
#endif

View File

@ -1,7 +1,7 @@
/********************************************************************************
* include/nuttx/sched.h
*
* Copyright (C) 2007-2016 Gregory Nutt. All rights reserved.
* Copyright (C) 2007-2016, 2018 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -178,6 +178,34 @@
#define SPORADIC_FLAG_REPLENISH (1 << 2) /* Bit 2: Replenishment cycle */
/* Bits 3-7: Available */
/* Most internal nxsched_* interfaces are not available in the user space in
* PROTECTED and KERNEL builds. In that context, the application semaphore
* interfaces must be used. The differences between the two sets of
* interfaces are: (1) the nxsched_* interfaces do not cause cancellation
* points and (2) they do not modify the errno variable.
*
* This is only important when compiling libraries (libc or libnx) that are
* used both by the OS (libkc.a and libknx.a) or by the applications
* (libuc.a and libunx.a). The that case, the correct interface must be
* used for the build context.
*/
#if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__)
# define _SCHED_GETPARAM(t,p) nxsched_getparam(t,p)
# define _SCHED_SETPARAM(t,p) nxsched_setparam(t,p)
# define _SCHED_GETSCHEDULER(t) nxsched_getscheduler(t)
# define _SCHED_SETAFFINITY(t,c,m) nxsched_setaffinity(t,c,m)
# define _SCHED_ERRNO(r) (-(r))
# define _SCHED_ERRVAL(r) (r)
#else
# define _SCHED_GETPARAM(t,p) sched_getparam(t,p)
# define _SCHED_SETPARAM(t,p) sched_setparam(t,p)
# define _SCHED_GETSCHEDULER(t) sched_getscheduler(t)
# define _SCHED_SETAFFINITY(t,c,m) sched_setaffinity(t,c,m)
# define _SCHED_ERRNO(r) errno
# define _SCHED_ERRVAL(r) (-errno)
#endif
/********************************************************************************
* Public Type Definitions
********************************************************************************/
@ -879,6 +907,143 @@ void sched_suspend_scheduler(FAR struct tcb_s *tcb);
# define sched_suspend_scheduler(tcb)
#endif
/****************************************************************************
* Name: nxsched_getparam
*
* Description:
* This function gets the scheduling priority of the task specified by
* pid. It is identical in function, differing only in its return value:
* This function does not modify the errno variable.
*
* This is a non-standard, internal OS function and is not intended for
* use by application logic. Applications should use the standard
* sched_getparam().
*
* Inputs:
* pid - the task ID of the task. If pid is zero, the priority
* of the calling task is returned.
* param - A structure whose member sched_priority is the integer
* priority. The task's priority is copied to the sched_priority
* element of this structure.
*
* Return Value:
* 0 (OK) if successful, otherwise a negated errno value is returned to
* indicate the nature of the failure..
*
* This function can fail if param is null (EINVAL) or if pid does
* not correspond to any task (ESRCH).
*
****************************************************************************/
struct sched_param; /* Forward reference */
int nxsched_getparam (pid_t pid, FAR struct sched_param *param);
/****************************************************************************
* Name: nxsched_setparam
*
* Description:
* This function sets the priority of a specified task. It is identical
* to the function sched_setparam(), differing only in its return value:
* This function does not modify the errno variable.
*
* NOTE: Setting a task's priority to the same value has a similar effect
* to sched_yield() -- The task will be moved to after all other tasks
* with the same priority.
*
* This is a non-standard, internal OS function and is not intended for
* use by application logic. Applications should use the standard
* sched_setparam().
*
* Inputs:
* pid - the task ID of the task to reprioritize. If pid is zero, the
* priority of the calling task is changed.
* param - A structure whose member sched_priority is the integer priority.
* The range of valid priority numbers is from SCHED_PRIORITY_MIN
* through SCHED_PRIORITY_MAX.
*
* Return Value:
* 0 (OK) if successful, otherwise a negated errno value is returned to
* indicate the nature of the failure..
*
* EINVAL The parameter 'param' is invalid or does not make sense for the
* current scheduling policy.
* EPERM The calling task does not have appropriate privileges.
* ESRCH The task whose ID is pid could not be found.
*
****************************************************************************/
struct sched_param; /* Forward reference */
int nxsched_setparam(pid_t pid, FAR const struct sched_param *param);
/****************************************************************************
* Name: nxsched_getscheduler
*
* Description:
* sched_getscheduler() returns the scheduling policy currently
* applied to the task identified by pid. If pid equals zero, the
* policy of the calling task will be retrieved.
*
* This functions is identical to the function sched_getscheduler(),
* differing only in its return value: This function does not modify
* the errno variable.
*
* This is a non-standard, internal OS function and is not intended for
* use by application logic. Applications should use the standard
* sched_getscheduler().
*
* Inputs:
* pid - the task ID of the task to query. If pid is zero, the
* calling task is queried.
*
* Return Value:
* On success, sched_getscheduler() returns the policy for the task
* (either SCHED_FIFO or SCHED_RR). On error, a negated errno value
* returned:
*
* ESRCH The task whose ID is pid could not be found.
*
****************************************************************************/
int nxsched_getscheduler(pid_t pid);
/****************************************************************************
* Name: nxsched_setaffinity
*
* Description:
* sched_setaffinity() sets the CPU affinity mask of the thread whose ID
* is pid to the value specified by mask. If pid is zero, then the
* calling thread is used. The argument cpusetsize is the length (i
* bytes) of the data pointed to by mask. Normally this argument would
* be specified as sizeof(cpu_set_t).
*
* If the thread specified by pid is not currently running on one of the
* CPUs specified in mask, then that thread is migrated to one of the
* CPUs specified in mask.
*
* nxsched_setaffinity() is identical to the function sched_setparam(),
* differing only in its return value: This function does not modify
* the errno variable. This is a non-standard, internal OS function and
* is not intended for use by application logic. Applications should
* use the standard sched_setparam().
*
* Inputs:
* pid - The ID of thread whose affinity set will be modified.
* cpusetsize - Size of cpuset. MUST be sizeofcpu_set_t().
* mask - The location to return the thread's new affinity set.
*
* Return Value:
* 0 if successful. Otherwise, ERROR (-1) is returned, and errno is
* set appropriately:
*
* ESRCH The task whose ID is pid could not be found.
*
****************************************************************************/
#ifdef CONFIG_SMP
int nxsched_setaffinity(pid_t pid, size_t cpusetsize,
FAR const cpu_set_t *mask);
#endif
#undef EXTERN
#if defined(__cplusplus)
}

View File

@ -1,7 +1,7 @@
/****************************************************************************
* libc/string/lib_psa_init.c
*
* Copyright (C) 2013-2015 Gregory Nutt. All rights reserved.
* Copyright (C) 2013-2015, 2018 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -44,9 +44,7 @@
#include <assert.h>
#include <errno.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#include <nuttx/sched.h>
/****************************************************************************
* Public Functions
@ -82,17 +80,23 @@ int posix_spawnattr_init(posix_spawnattr_t *attr)
/* Set the default priority to the same priority as this task */
ret = sched_getparam(0, &param);
ret = _SCHED_GETPARAM(0, &param);
if (ret < 0)
{
return errno;
return _SCHED_ERRNO(ret);
}
attr->priority = param.sched_priority;
/* Set the default scheduler policy to the policy of this task */
attr->policy = sched_getscheduler(0);
ret = _SCHED_GETSCHEDULER(0);
if (ret < 0)
{
return _SCHED_ERRNO(ret);
}
attr->policy = ret;
#ifndef CONFIG_DISABLE_SIGNALS
/* Empty signal mask */

View File

@ -1,7 +1,7 @@
/****************************************************************************
* sched/paging/pg_miss.c
*
* Copyright (C) 2010, 2017 Gregory Nutt. All rights reserved.
* Copyright (C) 2010, 2017-2018 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -162,7 +162,7 @@ void pg_miss(void)
pginfo("New worker priority. %d->%d\n",
wtcb->sched_priority, ftcb->sched_priority);
sched_setpriority(wtcb, ftcb->sched_priority);
(void)nxsched_setpriority(wtcb, ftcb->sched_priority);
}
/* Signal the page fill worker thread.

View File

@ -2,7 +2,7 @@
* sched/paging/pg_worker.c
* Page fill worker thread implementation.
*
* Copyright (C) 2010-2011, 2017 Gregory Nutt. All rights reserved.
* Copyright (C) 2010-2011, 2017-2018 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -48,6 +48,7 @@
#include <errno.h>
#include <debug.h>
#include <nuttx/sched.h>
#include <nuttx/arch.h>
#include <nuttx/signal.h>
#include <nuttx/page.h>
@ -185,7 +186,7 @@ static void pg_callback(FAR struct tcb_s *tcb, int result)
{
pginfo("New worker priority. %d->%d\n",
wtcb->sched_priority, priority);
sched_setpriority(wtcb, priority);
(void)nxsched_setpriority(wtcb, priority);
}
/* Save the page fill result (don't permit the value -EBUSY) */
@ -296,7 +297,7 @@ static inline bool pg_dequeue(void)
pginfo("New worker priority. %d->%d\n",
wtcb->sched_priority, priority);
sched_setpriority(wtcb, priority);
(void)nxsched_setpriority(wtcb, priority);
}
/* Return with g_pftcb holding the pointer to
@ -458,7 +459,7 @@ static inline void pg_alldone(void)
g_pftcb = NULL;
pginfo("New worker priority. %d->%d\n",
wtcb->sched_priority, CONFIG_PAGING_DEFPRIO);
sched_setpriority(wtcb, CONFIG_PAGING_DEFPRIO);
(void)nxsched_setpriority(wtcb, CONFIG_PAGING_DEFPRIO);
}
/****************************************************************************

View File

@ -1,7 +1,8 @@
/****************************************************************************
* sched/pthread/pthread_create.c
*
* Copyright (C) 2007-2009, 2011, 2013-2017 Gregory Nutt. All rights reserved.
* Copyright (C) 2007-2009, 2011, 2013-2018 Gregory Nutt. All rights
* reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -49,6 +50,7 @@
#include <errno.h>
#include <queue.h>
#include <nuttx/sched.h>
#include <nuttx/arch.h>
#include <nuttx/semaphore.h>
#include <nuttx/kmalloc.h>
@ -193,7 +195,7 @@ static void pthread_start(void)
if (ptcb->cmn.sched_priority > ptcb->cmn.init_priority)
{
DEBUGVERIFY(sched_setpriority(&ptcb->cmn, ptcb->cmn.init_priority));
DEBUGVERIFY(nxsched_setpriority(&ptcb->cmn, ptcb->cmn.init_priority));
}
/* Pass control to the thread entry point. In the kernel build this has to
@ -321,19 +323,19 @@ int pthread_create(FAR pthread_t *thread, FAR const pthread_attr_t *attr,
* thread.
*/
ret = sched_getparam(0, &param);
if (ret == ERROR)
ret = nxsched_getparam(0, &param);
if (ret < 0)
{
errcode = get_errno();
errcode = -ret;
goto errout_with_join;
}
/* Get the scheduler policy for this thread */
policy = sched_getscheduler(0);
if (policy == ERROR)
policy = nxsched_getscheduler(0);
if (policy < 0)
{
errcode = get_errno();
errcode = -policy;
goto errout_with_join;
}
}
@ -547,10 +549,10 @@ int pthread_create(FAR pthread_t *thread, FAR const pthread_attr_t *attr,
if (ptcb->cmn.sched_priority < parent->sched_priority)
{
ret = sched_setpriority(&ptcb->cmn, parent->sched_priority);
ret = nxsched_setpriority(&ptcb->cmn, parent->sched_priority);
if (ret < 0)
{
ret = get_errno();
ret = -ret;
}
}
}

View File

@ -1,7 +1,7 @@
/****************************************************************************
* sched/pthread/pthread_getschedparam.c
*
* Copyright (C) 2007, 2008, 2015 Gregory Nutt. All rights reserved.
* Copyright (C) 2007, 2008, 2015, 2018 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -37,11 +37,16 @@
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <pthread.h>
#include <sched.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/sched.h>
#include "pthread/pthread.h"
/****************************************************************************
@ -90,30 +95,34 @@ int pthread_getschedparam(pthread_t thread, FAR int *policy,
sinfo("Thread ID=%d policy=0x%p param=0x%p\n", thread, policy, param);
if (!policy || !param)
if (policy == NULL || param == NULL)
{
ret = EINVAL;
}
else
{
/* Get the schedparams of the thread. */
/* Get the scheduler parameters of the thread. */
ret = sched_getparam((pid_t)thread, param);
if (ret != OK)
ret = nxsched_getparam((pid_t)thread, param);
if (ret < 0)
{
ret = EINVAL;
ret = -ret;
}
/* Return the policy. */
/* Get the scheduler policy. */
*policy = sched_getscheduler((pid_t)thread);
if (*policy == ERROR)
ret = nxsched_getscheduler((pid_t)thread);
if (ret < 0)
{
ret = get_errno();
ret = -ret;
}
else
{
*policy = ret;
ret = OK;
}
}
sinfo("Returning %d\n", ret);
return ret;
}

View File

@ -1,7 +1,7 @@
/****************************************************************************
* sched/pthread/pthread_setaffinity.c
*
* Copyright (C) 2016 Gregory Nutt. All rights reserved.
* Copyright (C) 2016, 2018 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -45,6 +45,8 @@
#include <errno.h>
#include <debug.h>
#include <nuttx/sched.h>
#include "pthread/pthread.h"
#ifdef CONFIG_SMP
@ -88,18 +90,11 @@ int pthread_setaffinity_np(pthread_t thread, size_t cpusetsize,
DEBUGASSERT(thread > 0 && cpusetsize == sizeof(cpu_set_t) &&
cpuset != NULL);
/* Let sched_setaffinity do all of the work */
/* Let nxsched_setaffinity do all of the work, adjusting the return value */
ret = sched_setaffinity((pid_t)thread, cpusetsize, cpuset);
if (ret < 0)
{
/* If sched_setaffinity() fails, return the errno */
ret = get_errno();
DEBUGASSERT(ret > 0);
}
return ret;
ret = nxsched_setaffinity((pid_t)thread, cpusetsize, cpuset);
return ret < 0 ? -ret : OK;
}
#endif /* CONFIG_SMP */

View File

@ -1,7 +1,7 @@
/****************************************************************************
* sched/pthread/pthread_setschedprio.c
*
* Copyright (C) 2007, 2009, 2015 Gregory Nutt. All rights reserved.
* Copyright (C) 2007, 2009, 2015, 2018 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -38,10 +38,14 @@
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <sched.h>
#include <errno.h>
#include <nuttx/sched.h>
#include <nuttx/arch.h>
#include "sched/sched.h"
/****************************************************************************
@ -83,25 +87,21 @@ int pthread_setschedprio(pthread_t thread, int prio)
* modified.
*/
ret = sched_getparam((pid_t)thread, &param);
ret = nxsched_getparam((pid_t)thread, &param);
if (ret < 0)
{
goto errout_with_errno;
return -ret;
}
#endif
/* Call sched_setparam() to change the priority */
/* Call nxsched_setparam() to change the priority */
param.sched_priority = prio;
ret = sched_setparam((pid_t)thread, &param);
if (ret >= 0)
ret = nxsched_setparam((pid_t)thread, &param);
if (ret < 0)
{
return OK;
return -ret;
}
#ifdef CONFIG_SCHED_SPORADIC
errout_with_errno:
#endif
ret = get_errno();
return ret;
return OK;
}

View File

@ -380,15 +380,15 @@ void sched_mergeprioritized(FAR dq_queue_t *list1, FAR dq_queue_t *list2,
bool sched_mergepending(void);
void sched_addblocked(FAR struct tcb_s *btcb, tstate_t task_state);
void sched_removeblocked(FAR struct tcb_s *btcb);
int sched_setpriority(FAR struct tcb_s *tcb, int sched_priority);
int nxsched_setpriority(FAR struct tcb_s *tcb, int sched_priority);
/* Priority inheritance support */
#ifdef CONFIG_PRIORITY_INHERITANCE
int sched_reprioritize(FAR struct tcb_s *tcb, int sched_priority);
int nxsched_reprioritize(FAR struct tcb_s *tcb, int sched_priority);
#else
# define sched_reprioritize(tcb,sched_priority) \
sched_setpriority(tcb,sched_priority)
# define nxsched_reprioritize(tcb,sched_priority) \
nxsched_setpriority(tcb,sched_priority)
#endif
/* Support for tickless operation */

View File

@ -1,7 +1,7 @@
/****************************************************************************
* sched/sched/sched_getaffinity.c
*
* Copyright (C) 2016 Gregory Nutt. All rights reserved.
* Copyright (C) 2016, 2018 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -44,6 +44,8 @@
#include <assert.h>
#include <errno.h>
#include <nuttx/sched.h>
#include "sched/sched.h"
/****************************************************************************
@ -51,7 +53,7 @@
****************************************************************************/
/****************************************************************************
* Name: sched_getscheduler
* Name: sched_getaffinity
*
* Description:
* sched_getaffinity() writes the affinity mask of the thread whose ID

View File

@ -1,7 +1,7 @@
/****************************************************************************
* sched/sched/sched_getparam.c
*
* Copyright (C) 2007, 2009, 2015 Gregory Nutt. All rights reserved.
* Copyright (C) 2007, 2009, 2015, 2018 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -41,6 +41,9 @@
#include <sys/types.h>
#include <sched.h>
#include <errno.h>
#include <nuttx/sched.h>
#include "clock/clock.h"
#include "sched/sched.h"
@ -50,11 +53,16 @@
****************************************************************************/
/****************************************************************************
* Name: sched_getparam
* Name: nxsched_getparam
*
* Description:
* This function gets the scheduling priority of the task
* specified by pid.
* This function gets the scheduling priority of the task specified by
* pid. It is identical to the function sched_getparam(), differing only
* in its return value: This function does not modify the errno variable.
*
* This is a non-standard, internal OS function and is not intended for
* use by application logic. Applications should use the standard
* sched_getparam().
*
* Inputs:
* pid - the task ID of the task. If pid is zero, the priority
@ -64,49 +72,48 @@
* element of this structure.
*
* Return Value:
* 0 (OK) if successful, otherwise -1 (ERROR).
* 0 (OK) if successful, otherwise a negated errno value is returned to
* indicate the nature of the failure..
*
* This function can fail if param is null or if pid does
* not correspond to any task.
*
* Assumptions:
* This function can fail if param is null (EINVAL) or if pid does
* not correspond to any task (ESRCH).
*
****************************************************************************/
int sched_getparam (pid_t pid, FAR struct sched_param *param)
int nxsched_getparam (pid_t pid, FAR struct sched_param *param)
{
FAR struct tcb_s *rtcb;
FAR struct tcb_s *tcb;
int ret = OK;
if (!param)
if (param == NULL)
{
return ERROR;
return -EINVAL;
}
/* Check if the task to restart is the calling task */
rtcb = this_task();
if ((pid == 0) || (pid == rtcb->pid))
if (pid == 0 || pid == rtcb->pid)
{
/* Return the priority if the calling task. */
param->sched_priority = (int)rtcb->sched_priority;
}
/* Ths pid is not for the calling task, we will have to look it up */
/* This PID is not for the calling task, we will have to look it up */
else
{
/* Get the TCB associated with this pid */
/* Get the TCB associated with this PID */
sched_lock();
tcb = sched_gettcb(pid);
if (!tcb)
{
/* This pid does not correspond to any known task */
/* This PID does not correspond to any known task */
ret = ERROR;
ret = -ESRCH;
}
else
{
@ -150,3 +157,39 @@ int sched_getparam (pid_t pid, FAR struct sched_param *param)
return ret;
}
/****************************************************************************
* Name: sched_getparam
*
* Description:
* This function gets the scheduling priority of the task specified by
* pid. This function is a simply wrapper around nxsched_getparam() that
* sets the errno value in the event of an error.
*
* Inputs:
* pid - the task ID of the task. If pid is zero, the priority
* of the calling task is returned.
* param - A structure whose member sched_priority is the integer
* priority. The task's priority is copied to the sched_priority
* element of this structure.
*
* Return Value:
* 0 (OK) if successful, otherwise -1 (ERROR) with the errno value set
* to indicate the nature of the problem.
*
* This function can fail if param is null (EINVAL) or if pid does
* not correspond to any task (ESRCH).
*
****************************************************************************/
int sched_getparam (pid_t pid, FAR struct sched_param *param)
{
int ret = nxsched_getparam(pid, param);
if (ret < 0)
{
set_errno(-ret);
ret = ERROR;
}
return ret;
}

View File

@ -1,7 +1,7 @@
/****************************************************************************
* sched/sched/sched_getscheduler.c
*
* Copyright (C) 2007, 2009, 2015 Gregory Nutt. All rights reserved.
* Copyright (C) 2007, 2009, 2015, 2018 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -43,6 +43,7 @@
#include <sched.h>
#include <errno.h>
#include <nuttx/sched.h>
#include <nuttx/arch.h>
#include "sched/sched.h"
@ -51,6 +52,64 @@
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nxsched_getscheduler
*
* Description:
* sched_getscheduler() returns the scheduling policy currently
* applied to the task identified by pid. If pid equals zero, the
* policy of the calling task will be retrieved.
*
* This functions is identical to the function sched_getscheduler(),
* differing only in its return value: This function does not modify
* the errno variable.
*
* This is a non-standard, internal OS function and is not intended for
* use by application logic. Applications should use the standard
* sched_getscheduler().
*
* Inputs:
* pid - the task ID of the task to query. If pid is zero, the
* calling task is queried.
*
* Return Value:
* On success, sched_getscheduler() returns the policy for the task
* (either SCHED_FIFO or SCHED_RR). On error, a negated errno value
* returned:
*
* ESRCH The task whose ID is pid could not be found.
*
****************************************************************************/
int nxsched_getscheduler(pid_t pid)
{
FAR struct tcb_s *tcb;
int policy;
/* Verify that the PID corresponds to a real task */
if (pid == 0)
{
tcb = this_task();
}
else
{
tcb = sched_gettcb(pid);
}
if (tcb == NULL)
{
return -ESRCH;
}
/* Return the scheduling policy from the TCB. NOTE that the user-
* interpretable values are 1 based; the TCB values are zero-based.
*/
policy = (tcb->flags & TCB_FLAG_POLICY_MASK) >> TCB_FLAG_POLICY_SHIFT;
return policy + 1;
}
/****************************************************************************
* Name: sched_getscheduler
*
@ -59,6 +118,9 @@
* applied to the task identified by pid. If pid equals zero, the
* policy of the calling task will be retrieved.
*
* sched_getscheduler() is a simply wrapper around nxsched_getscheduler()
* that sets the errno value in the event of an error.
*
* Inputs:
* pid - the task ID of the task to query. If pid is zero, the
* calling task is queried.
@ -70,36 +132,16 @@
*
* ESRCH The task whose ID is pid could not be found.
*
* Assumptions:
*
****************************************************************************/
int sched_getscheduler(pid_t pid)
{
FAR struct tcb_s *tcb;
int policy;
/* Verify that the PID corresponds to a real task */
if (!pid)
int ret = nxsched_getscheduler(pid);
if (ret < 0)
{
tcb = this_task();
}
else
{
tcb = sched_gettcb(pid);
set_errno(-ret);
ret = ERROR;
}
if (!tcb)
{
set_errno(ESRCH);
return ERROR;
}
/* Return the scheduling policy from the TCB. NOTE that the user-
* interpretable values are 1 based; the TCB values are zero-based.
*/
policy = (tcb->flags & TCB_FLAG_POLICY_MASK) >> TCB_FLAG_POLICY_SHIFT;
return policy + 1;
return ret;
}

View File

@ -1,7 +1,7 @@
/****************************************************************************
* sched/sched/sched_reprioritize.c
*
* Copyright (C) 2009, 2012 Gregory Nutt. All rights reserved.
* Copyright (C) 2009, 2012, 2018 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -43,6 +43,8 @@
#include <sched.h>
#include <errno.h>
#include <nuttx/sched.h>
#include "sched/sched.h"
#ifdef CONFIG_PRIORITY_INHERITANCE
@ -52,7 +54,7 @@
****************************************************************************/
/****************************************************************************
* Name: sched_reprioritize
* Name: nxsched_reprioritize
*
* Description:
* This function sets the priority of a specified task.
@ -66,26 +68,24 @@
* sched_priority - The new task priority
*
* Return Value:
* On success, sched_setparam() returns 0 (OK). On error, -1
* (ERROR) is returned, and errno is set appropriately.
* On success, sched_reporioritize() returns 0 (OK). On error, a negated
* errno value is returned.
*
* EINVAL The parameter 'param' is invalid or does not make sense for the
* current scheduling policy.
* EPERM The calling task does not have appropriate privileges.
* ESRCH The task whose ID is pid could not be found.
*
* Assumptions:
*
****************************************************************************/
int sched_reprioritize(FAR struct tcb_s *tcb, int sched_priority)
int nxsched_reprioritize(FAR struct tcb_s *tcb, int sched_priority)
{
/* This function is equivalent to sched_setpriority() BUT it also has the
/* This function is equivalent to nxsched_setpriority() BUT it also has the
* side effect of discarding all priority inheritance history. This is
* done only on explicit, user-initiated reprioritization.
*/
int ret = sched_setpriority(tcb, sched_priority);
int ret = nxsched_setpriority(tcb, sched_priority);
if (ret == 0)
{
/* Reset the base_priority -- the priority that the thread would return

View File

@ -1,7 +1,7 @@
/****************************************************************************
* sched/sched/sched_setaffinity.c
*
* Copyright (C) 2016 Gregory Nutt. All rights reserved.
* Copyright (C) 2016, 2018 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -53,7 +53,7 @@
****************************************************************************/
/****************************************************************************
* Name: sched_getscheduler
* Name: nxsched_setaffinity
*
* Description:
* sched_setaffinity() sets the CPU affinity mask of the thread whose ID
@ -66,10 +66,16 @@
* CPUs specified in mask, then that thread is migrated to one of the
* CPUs specified in mask.
*
* nxsched_setaffinity() is identical to the function sched_setparam(),
* differing only in its return value: This function does not modify
* the errno variable. This is a non-standard, internal OS function and
* is not intended for use by application logic. Applications should
* use the standard sched_setparam().
*
* Inputs:
* pid - The ID of thread whose affinity set will be modified.
* cpusetsize - Size of cpuset. MUST be sizeofcpu_set_t().
* cpuset - The location to return the thread's new affinity set.
* mask - The location to return the thread's new affinity set.
*
* Return Value:
* 0 if successful. Otherwise, ERROR (-1) is returned, and errno is
@ -79,12 +85,12 @@
*
****************************************************************************/
int sched_setaffinity(pid_t pid, size_t cpusetsize, FAR const cpu_set_t *mask)
int nxsched_setaffinity(pid_t pid, size_t cpusetsize,
FAR const cpu_set_t *mask)
{
FAR struct tcb_s *tcb;
irqstate_t flags;
int errcode = 0;
int ret;
int ret = OK;
DEBUGASSERT(cpusetsize == sizeof(cpu_set_t) && mask != NULL);
@ -102,7 +108,7 @@ int sched_setaffinity(pid_t pid, size_t cpusetsize, FAR const cpu_set_t *mask)
if (tcb == NULL)
{
errcode = ESRCH;
ret = -ESRCH;
goto errout_with_lock;
}
@ -113,7 +119,7 @@ int sched_setaffinity(pid_t pid, size_t cpusetsize, FAR const cpu_set_t *mask)
flags = enter_critical_section();
if ((tcb->flags & TCB_FLAG_CPU_LOCKED) != 0)
{
errcode = EINVAL;
ret = -EINVAL;
goto errout_with_csection;
}
@ -140,17 +146,13 @@ int sched_setaffinity(pid_t pid, size_t cpusetsize, FAR const cpu_set_t *mask)
/* No.. then we will need to move the task from the assigned
* task list to some other ready to run list.
*
* sched_setpriority() will do just what we want... it will remove
* nxsched_setpriority() will do just what we want... it will remove
* the task from its current position in the some assigned task list
* and then simply put it back in the right place. This works even
* if the task is this task.
*/
ret = sched_setpriority(tcb, tcb->sched_priority);
if (ret < 0)
{
errcode = get_errno();
}
ret = nxsched_setpriority(tcb, tcb->sched_priority);
}
}
@ -159,11 +161,47 @@ errout_with_csection:
errout_with_lock:
sched_unlock();
if (errcode != 0)
{
set_errno(errcode);
return ERROR;
return ret;
}
return OK;
/****************************************************************************
* Name: sched_setaffinity
*
* Description:
* sched_setaffinity() sets the CPU affinity mask of the thread whose ID
* is pid to the value specified by mask. If pid is zero, then the
* calling thread is used. The argument cpusetsize is the length (i
* bytes) of the data pointed to by mask. Normally this argument would
* be specified as sizeof(cpu_set_t).
*
* If the thread specified by pid is not currently running on one of the
* CPUs specified in mask, then that thread is migrated to one of the
* CPUs specified in mask.
*
* This function is a simply wrapper around nxsched_setaffinity() that sets
* the errno value in the event of an error.
*
* Inputs:
* pid - The ID of thread whose affinity set will be modified.
* cpusetsize - Size of cpuset. MUST be sizeofcpu_set_t().
* mask - The location to return the thread's new affinity set.
*
* Return Value:
* 0 if successful. Otherwise, ERROR (-1) is returned, and errno is
* set appropriately:
*
* ESRCH The task whose ID is pid could not be found.
*
****************************************************************************/
int sched_setaffinity(pid_t pid, size_t cpusetsize, FAR const cpu_set_t *mask)
{
int ret = nxsched_setaffinity(pid, cpusetsize, mask);
if (ret < 0)
{
set_errno(-ret);
ret = ERROR;
}
return ret;
}

View File

@ -1,7 +1,8 @@
/****************************************************************************
* sched/sched/sched_setparam.c
*
* Copyright (C) 2007, 2009, 2013, 2015-2016 Gregory Nutt. All rights reserved.
* Copyright (C) 2007, 2009, 2013, 2015-2016, 2018 Gregory Nutt. All
* rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -44,6 +45,7 @@
#include <assert.h>
#include <errno.h>
#include <nuttx/sched.h>
#include <nuttx/irq.h>
#include <nuttx/arch.h>
@ -55,15 +57,21 @@
****************************************************************************/
/****************************************************************************
* Name: sched_setparam
* Name: nxsched_setparam
*
* Description:
* This function sets the priority of a specified task.
* This function sets the priority of a specified task. It is identical
* to the function sched_setparam(), differing only in its return value:
* This function does not modify the errno variable.
*
* NOTE: Setting a task's priority to the same value has a similar effect
* to sched_yield() -- The task will be moved to after all other tasks
* with the same priority.
*
* This is a non-standard, internal OS function and is not intended for
* use by application logic. Applications should use the standard
* sched_setparam().
*
* Inputs:
* pid - the task ID of the task to reprioritize. If pid is zero, the
* priority of the calling task is changed.
@ -72,31 +80,27 @@
* through SCHED_PRIORITY_MAX.
*
* Return Value:
* On success, sched_setparam() returns 0 (OK). On error, -1 (ERROR) is
* returned, and errno is set appropriately.
* 0 (OK) if successful, otherwise a negated errno value is returned to
* indicate the nature of the failure..
*
* EINVAL The parameter 'param' is invalid or does not make sense for the
* current scheduling policy.
* EPERM The calling task does not have appropriate privileges.
* ESRCH The task whose ID is pid could not be found.
*
* Assumptions:
*
****************************************************************************/
int sched_setparam(pid_t pid, FAR const struct sched_param *param)
int nxsched_setparam(pid_t pid, FAR const struct sched_param *param)
{
FAR struct tcb_s *rtcb;
FAR struct tcb_s *tcb;
int errcode;
int ret;
/* Verify that the requested priority is in the valid range */
if (!param)
if (param == NULL)
{
errcode = EINVAL;
goto errout_with_errcode;
return -EINVAL;
}
/* Prohibit modifications to the head of the ready-to-run task
@ -122,7 +126,7 @@ int sched_setparam(pid_t pid, FAR const struct sched_param *param)
{
/* No task with this PID was found */
errcode = ESRCH;
ret = -ESRCH;
goto errout_with_lock;
}
}
@ -140,7 +144,7 @@ int sched_setparam(pid_t pid, FAR const struct sched_param *param)
if (param->sched_ss_max_repl < 1 ||
param->sched_ss_max_repl > CONFIG_SCHED_SPORADIC_MAXREPL)
{
errcode = EINVAL;
ret = -EINVAL;
goto errout_with_lock;
}
@ -174,7 +178,7 @@ int sched_setparam(pid_t pid, FAR const struct sched_param *param)
if (repl_ticks < budget_ticks)
#endif
{
errcode = EINVAL;
ret = -EINVAL;
goto errout_with_lock;
}
@ -209,7 +213,6 @@ int sched_setparam(pid_t pid, FAR const struct sched_param *param)
leave_critical_section(flags);
if (ret < 0)
{
errcode = -ret;
goto errout_with_lock;
}
}
@ -217,16 +220,53 @@ int sched_setparam(pid_t pid, FAR const struct sched_param *param)
/* Then perform the reprioritization */
ret = sched_reprioritize(tcb, param->sched_priority);
sched_unlock();
return ret;
ret = nxsched_reprioritize(tcb, param->sched_priority);
errout_with_lock:
set_errno(errcode);
sched_unlock();
return ERROR;
errout_with_errcode:
set_errno(errcode);
return ERROR;
return ret;
}
/****************************************************************************
* Name: sched_setparam
*
* Description:
* This function sets the priority of a specified task. This function is
* a simply wrapper around nxsched_setparam() that sets the errno value in
* the event of an error.
*
* NOTE: Setting a task's priority to the same value has a similar effect
* to sched_yield() -- The task will be moved to after all other tasks
* with the same priority.
*
* Inputs:
* pid - the task ID of the task to reprioritize. If pid is zero, the
* priority of the calling task is changed.
* param - A structure whose member sched_priority is the integer priority.
* The range of valid priority numbers is from SCHED_PRIORITY_MIN
* through SCHED_PRIORITY_MAX.
*
* Return Value:
* On success, sched_setparam() returns 0 (OK). On error, -1 (ERROR) is
* returned, and errno is set appropriately.
*
* EINVAL The parameter 'param' is invalid or does not make sense for the
* current scheduling policy.
* EPERM The calling task does not have appropriate privileges.
* ESRCH The task whose ID is pid could not be found.
*
* Assumptions:
*
****************************************************************************/
int sched_setparam(pid_t pid, FAR const struct sched_param *param)
{
int ret = nxsched_setparam(pid, param);
if (ret < 0)
{
set_errno(-ret);
ret = ERROR;
}
return ret;
}

View File

@ -1,7 +1,7 @@
/****************************************************************************
* sched/sched/sched_setpriority.c
*
* Copyright (C) 2009, 2013, 2016 Gregory Nutt. All rights reserved.
* Copyright (C) 2009, 2013, 2016, 2018 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -315,7 +315,7 @@ static inline void sched_blocked_setpriority(FAR struct tcb_s *tcb,
****************************************************************************/
/****************************************************************************
* Name: sched_setpriority
* Name: nxsched_setpriority
*
* Description:
* This function sets the priority of a specified task.
@ -329,19 +329,17 @@ static inline void sched_blocked_setpriority(FAR struct tcb_s *tcb,
* sched_priority - The new task priority
*
* Return Value:
* On success, sched_setparam() returns 0 (OK). On error, -1 (ERROR) is
* returned, and errno is set appropriately.
* On success, nxsched_setpriority() returns 0 (OK). On error, a negated
* errno value is returned.
*
* EINVAL The parameter 'param' is invalid or does not make sense for the
* current scheduling policy.
* EPERM The calling task does not have appropriate privileges.
* ESRCH The task whose ID is pid could not be found.
*
* Assumptions:
*
****************************************************************************/
int sched_setpriority(FAR struct tcb_s *tcb, int sched_priority)
int nxsched_setpriority(FAR struct tcb_s *tcb, int sched_priority)
{
irqstate_t flags;
@ -350,8 +348,7 @@ int sched_setpriority(FAR struct tcb_s *tcb, int sched_priority)
if (sched_priority < SCHED_PRIORITY_MIN ||
sched_priority > SCHED_PRIORITY_MAX)
{
set_errno(EINVAL);
return ERROR;
return -EINVAL;
}
/* We need to assure that there there is no interrupt activity while
@ -383,7 +380,6 @@ int sched_setpriority(FAR struct tcb_s *tcb, int sched_priority)
sched_readytorun_setpriority(tcb, sched_priority);
break;
/* CASE 3. The task is not in the ready to run list. Changing its
* Priority cannot effect the currently executing task.
*/

View File

@ -1,7 +1,8 @@
/****************************************************************************
* sched/sched/sched_setscheduler.c
*
* Copyright (C) 2007, 2009, 2012, 2015-2016 Gregory Nutt. All rights reserved.
* Copyright (C) 2007, 2009, 2012, 2015-2016, 2018 Gregory Nutt. All
* rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -88,9 +89,7 @@ int sched_setscheduler(pid_t pid, int policy,
{
FAR struct tcb_s *tcb;
irqstate_t flags;
#ifdef CONFIG_SCHED_SPORADIC
int errcode;
#endif
int ret;
/* Check for supported scheduling policy */
@ -278,15 +277,23 @@ int sched_setscheduler(pid_t pid, int policy,
/* Set the new priority */
ret = sched_reprioritize(tcb, param->sched_priority);
ret = nxsched_reprioritize(tcb, param->sched_priority);
if (ret < 0)
{
errcode = -ret;
goto errout_with_lock;
}
sched_unlock();
return (ret >= 0) ? OK : ERROR;
return OK;
#ifdef CONFIG_SCHED_SPORADIC
errout_with_irq:
set_errno(errcode);
leave_critical_section(flags);
#endif
errout_with_lock:
set_errno(errcode);
sched_unlock();
return ERROR;
#endif
}

View File

@ -1,7 +1,7 @@
/****************************************************************************
* sched/sched/sched_sporadic.c
*
* Copyright (C) 2015-2016 Gregory Nutt. All rights reserved.
* Copyright (C) 2015-2016, 2018 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -159,12 +159,11 @@ static int sporadic_set_lowpriority(FAR struct tcb_s *tcb)
* switch.
*/
ret = sched_reprioritize(tcb, sporadic->low_priority);
ret = nxsched_reprioritize(tcb, sporadic->low_priority);
if (ret < 0)
{
int errcode = get_errno();
serr("ERROR: sched_reprioritize failed: %d\n", errcode);
return -errcode;
serr("ERROR: nxsched_reprioritize failed: %d\n", ret);
return ret;
}
}
@ -239,12 +238,11 @@ static int sporadic_set_hipriority(FAR struct tcb_s *tcb)
/* Then reprioritize to the higher priority */
ret = sched_reprioritize(tcb, sporadic->hi_priority);
ret = nxsched_reprioritize(tcb, sporadic->hi_priority);
if (ret < 0)
{
int errcode = get_errno();
serr("ERROR: sched_reprioritize failed: %d\n", errcode);
return -errcode;
serr("ERROR: nxsched_reprioritize failed: %d\n", ret);
return ret;
}
return OK;

View File

@ -1,7 +1,7 @@
/****************************************************************************
* sched/sched/sched_yield.c
*
* Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved.
* Copyright (C) 2007, 2009, 2018 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -67,11 +67,14 @@
int sched_yield(void)
{
FAR struct tcb_s *rtcb = this_task();
int ret;
/* This equivalent to just resetting the task priority to its current value
* since this will cause the task to be rescheduled behind any other tasks
* at the same priority.
*/
return sched_setpriority(rtcb, rtcb->sched_priority);
ret = nxsched_setpriority(rtcb, rtcb->sched_priority);
return ret < 0 ? ERROR : OK;
}

View File

@ -1,7 +1,8 @@
/****************************************************************************
* sched/semaphore/sem_holder.c
*
* Copyright (C) 2009-2011, 2013, 2016-2017 Gregory Nutt. All rights reserved.
* Copyright (C) 2009-2011, 2013, 2016-2018 Gregory Nutt. All rights
* reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -387,7 +388,7 @@ static int nxsem_boostholderprio(FAR struct semholder_s *pholder,
* switch may occur during up_block_task() processing.
*/
(void)sched_setpriority(htcb, rtcb->sched_priority);
(void)nxsched_setpriority(htcb, rtcb->sched_priority);
}
else
{
@ -425,7 +426,7 @@ static int nxsem_boostholderprio(FAR struct semholder_s *pholder,
* will occur during up_block_task() processing.
*/
(void)sched_setpriority(htcb, rtcb->sched_priority);
(void)nxsched_setpriority(htcb, rtcb->sched_priority);
}
#endif
@ -535,7 +536,7 @@ static int nxsem_restoreholderprio(FAR struct tcb_s *htcb,
/* Reset the holder's priority back to the base priority. */
sched_reprioritize(htcb, htcb->base_priority);
(void)nxsched_reprioritize(htcb, htcb->base_priority);
}
/* There are multiple pending priority levels. The holder thread's
@ -577,7 +578,7 @@ static int nxsem_restoreholderprio(FAR struct tcb_s *htcb,
* base_priority)
*/
sched_setpriority(htcb, rpriority);
nxsched_setpriority(htcb, rpriority);
}
else
{
@ -617,7 +618,7 @@ static int nxsem_restoreholderprio(FAR struct tcb_s *htcb,
* priority.
*/
sched_reprioritize(htcb, htcb->base_priority);
(void)nxsched_reprioritize(htcb, htcb->base_priority);
#endif
}

View File

@ -1,7 +1,7 @@
/****************************************************************************
* sched/task/task_posixspawn.c
*
* Copyright (C) 2013 Gregory Nutt. All rights reserved.
* Copyright (C) 2013, 2018 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -43,6 +43,7 @@
#include <spawn.h>
#include <debug.h>
#include <nuttx/sched.h>
#include <nuttx/kthread.h>
#include <nuttx/binfmt/binfmt.h>
#include <nuttx/binfmt/symtab.h>
@ -391,14 +392,12 @@ int posix_spawn(FAR pid_t *pid, FAR const char *path,
/* Get the priority of this (parent) task */
ret = sched_getparam(0, &param);
ret = nxsched_getparam(0, &param);
if (ret < 0)
{
int errcode = get_errno();
serr("ERROR: sched_getparam failed: %d\n", errcode);
serr("ERROR: nxsched_getparam failed: %d\n", ret);
spawn_semgive(&g_spawn_parmsem);
return errcode;
return -ret;
}
/* Disable pre-emption so that the proxy does not run until waitpid

View File

@ -1,7 +1,7 @@
/****************************************************************************
* sched/task/task_spawn.c
*
* Copyright (C) 2013 Gregory Nutt. All rights reserved.
* Copyright (C) 2013, 2018 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -44,6 +44,8 @@
#include <spawn.h>
#include <debug.h>
#include <nuttx/sched.h>
#include "sched/sched.h"
#include "group/group.h"
#include "task/spawn.h"
@ -123,9 +125,10 @@ static int task_spawn_exec(FAR pid_t *pidp, FAR const char *name,
/* Set the default priority to the same priority as this task */
ret = sched_getparam(0, &param);
ret = nxsched_getparam(0, &param);
if (ret < 0)
{
ret = -ret;
goto errout;
}
@ -378,14 +381,12 @@ int task_spawn(FAR pid_t *pid, FAR const char *name, main_t entry,
/* Get the priority of this (parent) task */
ret = sched_getparam(0, &param);
ret = nxsched_getparam(0, &param);
if (ret < 0)
{
int errcode = get_errno();
serr("ERROR: sched_getparam failed: %d\n", errcode);
serr("ERROR: nxsched_getparam failed: %d\n", ret);
spawn_semgive(&g_spawn_parmsem);
return errcode;
return -ret;
}
/* Disable pre-emption so that the proxy does not run until waitpid

View File

@ -1,7 +1,7 @@
/****************************************************************************
* sched/task/task_spawnparms.c
*
* Copyright (C) 2013, 2015, 2017 Gregory Nutt. All rights reserved.
* Copyright (C) 2013, 2015, 2017-2018 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -194,7 +194,7 @@ void spawn_semtake(FAR sem_t *sem)
* attr - The attributes to use
*
* Returned Value:
* Errors are not reported by this function. This is because errors
* Errors are not reported by this function. This is not because errors
* cannot occur, but rather that the new task has already been started
* so there is no graceful way to handle errors detected in this context
* (unless we delete the new task and recover).
@ -208,6 +208,7 @@ void spawn_semtake(FAR sem_t *sem)
int spawn_execattrs(pid_t pid, FAR const posix_spawnattr_t *attr)
{
struct sched_param param;
int ret;
DEBUGASSERT(attr);
@ -223,17 +224,14 @@ int spawn_execattrs(pid_t pid, FAR const posix_spawnattr_t *attr)
if ((attr->flags & POSIX_SPAWN_SETSCHEDPARAM) != 0)
{
#ifdef CONFIG_SCHED_SPORADIC
int ret;
/* Get the current sporadic scheduling parameters. Those will not be
* modified.
*/
ret = sched_getparam(pid, &param);
ret = nxsched_getparam(pid, &param);
if (ret < 0)
{
int errcode = get_errno();
return -errcode;
return ret;
}
#endif
@ -250,7 +248,11 @@ int spawn_execattrs(pid_t pid, FAR const posix_spawnattr_t *attr)
sinfo("Setting priority=%d for pid=%d\n",
param.sched_priority, pid);
(void)sched_setparam(pid, &param);
ret = nxsched_setparam(pid, &param);
if (ret < 0)
{
return ret;
}
}
}
@ -261,7 +263,11 @@ int spawn_execattrs(pid_t pid, FAR const posix_spawnattr_t *attr)
else if ((attr->flags & POSIX_SPAWN_SETSCHEDULER) != 0)
{
(void)sched_getparam(0, &param);
ret = nxsched_getparam(0, &param);
if (ret < 0)
{
return ret;
}
}
/* Are we setting the scheduling policy? If so, use the priority

View File

@ -1,7 +1,7 @@
/****************************************************************************
* sched/work/work_inherit.c
*
* Copyright (C) 2014, 2016 Gregory Nutt. All rights reserved.
* Copyright (C) 2014, 2016, 2018 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -123,7 +123,7 @@ static void lpwork_boostworker(pid_t wpid, uint8_t reqprio)
* sched_unblock() processing.
*/
(void)sched_setpriority(wtcb, reqprio);
(void)nxsched_setpriority(wtcb, reqprio);
}
else
{
@ -160,7 +160,7 @@ static void lpwork_boostworker(pid_t wpid, uint8_t reqprio)
* sched_unlock() processing.
*/
(void)sched_setpriority(wtcb, reqprio);
(void)nxsched_setpriority(wtcb, reqprio);
}
#endif
}
@ -223,7 +223,7 @@ static void lpwork_restoreworker(pid_t wpid, uint8_t reqprio)
/* Reset the worker's priority back to the base priority. */
sched_reprioritize(wtcb, wtcb->base_priority);
(void)nxsched_reprioritize(wtcb, wtcb->base_priority);
}
/* There are multiple pending priority levels. The worker thread's
@ -264,7 +264,7 @@ static void lpwork_restoreworker(pid_t wpid, uint8_t reqprio)
* base_priority)
*/
sched_setpriority(wtcb, wpriority);
nxsched_setpriority(wtcb, wpriority);
}
else
{
@ -304,7 +304,7 @@ static void lpwork_restoreworker(pid_t wpid, uint8_t reqprio)
* priority.
*/
sched_reprioritize(wtcb, wtcb->base_priority);
(void)nxsched_reprioritize(wtcb, wtcb->base_priority);
#endif
}
}