diff --git a/TODO b/TODO index b5ab5f89dae..05108babcc8 100644 --- a/TODO +++ b/TODO @@ -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 diff --git a/arch/arm/src/lc823450/lc823450_i2s.c b/arch/arm/src/lc823450/lc823450_i2s.c index fb9efa28df1..e3ed25364d0 100644 --- a/arch/arm/src/lc823450/lc823450_i2s.c +++ b/arch/arm/src/lc823450/lc823450_i2s.c @@ -45,6 +45,7 @@ #include #include +#include #include #include #include @@ -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 diff --git a/binfmt/binfmt_loadmodule.c b/binfmt/binfmt_loadmodule.c index 375616203a4..ea5def2acba 100644 --- a/binfmt/binfmt_loadmodule.c +++ b/binfmt/binfmt_loadmodule.c @@ -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 * * Redistribution and use in source and binary forms, with or without @@ -43,6 +43,7 @@ #include #include +#include #include #include @@ -88,11 +89,10 @@ static int load_default_priority(FAR struct binary_s *bin) /* Get the priority of this thread */ - ret = sched_getparam(0, ¶m); + ret = nxsched_getparam(0, ¶m); if (ret < 0) { - ret = -get_errno(); - berr("ERROR: sched_getparam failed: %d\n", ret); + berr("ERROR: nxsched_getparam failed: %d\n", ret); return ret; } diff --git a/configs/lc823450-xgevk/src/lc823450_bringup.c b/configs/lc823450-xgevk/src/lc823450_bringup.c index 8b41c839fe5..d80e5f0a020 100644 --- a/configs/lc823450-xgevk/src/lc823450_bringup.c +++ b/configs/lc823450-xgevk/src/lc823450_bringup.c @@ -49,6 +49,8 @@ # include #endif +#include + #ifdef CONFIG_RNDIS # include #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 diff --git a/configs/sim/src/sim_touchscreen.c b/configs/sim/src/sim_touchscreen.c index c3b15a8e5d7..c9e9a58f281 100644 --- a/configs/sim/src/sim_touchscreen.c +++ b/configs/sim/src/sim_touchscreen.c @@ -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 * * Redistribution and use in source and binary forms, with or without @@ -48,6 +48,7 @@ #include #include +#include #include #include #include @@ -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, ¶m); + ret = nxsched_setparam(0, ¶m); if (ret < 0) { - gerr("ERROR: sched_setparam failed: %d\n" , ret); + gerr("ERROR: nxsched_setparam failed: %d\n" , ret); return ret; } diff --git a/fs/aio/aioc_contain.c b/fs/aio/aioc_contain.c index ac492abbc37..ee8f18a6831 100644 --- a/fs/aio/aioc_contain.c +++ b/fs/aio/aioc_contain.c @@ -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 * * Redistribution and use in source and binary forms, with or without @@ -42,6 +42,7 @@ #include #include +#include #include #include @@ -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, ¶m)); + DEBUGVERIFY(nxsched_getparam (aioc->aioc_pid, ¶m)); aioc->aioc_prio = param.sched_priority; #endif diff --git a/include/nuttx/sched.h b/include/nuttx/sched.h index 86046e4d710..c251059a8b6 100644 --- a/include/nuttx/sched.h +++ b/include/nuttx/sched.h @@ -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 * * 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) } diff --git a/libc/spawn/lib_psa_init.c b/libc/spawn/lib_psa_init.c index 4ee16ff6262..64d58afc740 100644 --- a/libc/spawn/lib_psa_init.c +++ b/libc/spawn/lib_psa_init.c @@ -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 * * Redistribution and use in source and binary forms, with or without @@ -44,9 +44,7 @@ #include #include -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ +#include /**************************************************************************** * 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, ¶m); + ret = _SCHED_GETPARAM(0, ¶m); 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 */ diff --git a/sched/paging/pg_miss.c b/sched/paging/pg_miss.c index 6bec634e061..75beda6827b 100644 --- a/sched/paging/pg_miss.c +++ b/sched/paging/pg_miss.c @@ -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 * * 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. diff --git a/sched/paging/pg_worker.c b/sched/paging/pg_worker.c index 1c8ee188a4f..a2ded4c1aef 100644 --- a/sched/paging/pg_worker.c +++ b/sched/paging/pg_worker.c @@ -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 * * Redistribution and use in source and binary forms, with or without @@ -48,6 +48,7 @@ #include #include +#include #include #include #include @@ -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); } /**************************************************************************** diff --git a/sched/pthread/pthread_create.c b/sched/pthread/pthread_create.c index 54d5afec54b..da612bb1a7a 100644 --- a/sched/pthread/pthread_create.c +++ b/sched/pthread/pthread_create.c @@ -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 * * Redistribution and use in source and binary forms, with or without @@ -49,6 +50,7 @@ #include #include +#include #include #include #include @@ -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, ¶m); - if (ret == ERROR) + ret = nxsched_getparam(0, ¶m); + 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; } } } diff --git a/sched/pthread/pthread_getschedparam.c b/sched/pthread/pthread_getschedparam.c index a71bc488cdb..0167f172a19 100644 --- a/sched/pthread/pthread_getschedparam.c +++ b/sched/pthread/pthread_getschedparam.c @@ -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 * * Redistribution and use in source and binary forms, with or without @@ -37,11 +37,16 @@ * Included Files ****************************************************************************/ +#include + #include #include #include #include #include + +#include + #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; } - diff --git a/sched/pthread/pthread_setaffinity.c b/sched/pthread/pthread_setaffinity.c index cf8ccf639fd..87f91e9be96 100644 --- a/sched/pthread/pthread_setaffinity.c +++ b/sched/pthread/pthread_setaffinity.c @@ -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 * * Redistribution and use in source and binary forms, with or without @@ -45,6 +45,8 @@ #include #include +#include + #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 */ + diff --git a/sched/pthread/pthread_setschedprio.c b/sched/pthread/pthread_setschedprio.c index cf31d9f013f..e698d3bf29b 100644 --- a/sched/pthread/pthread_setschedprio.c +++ b/sched/pthread/pthread_setschedprio.c @@ -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 * * Redistribution and use in source and binary forms, with or without @@ -38,10 +38,14 @@ ****************************************************************************/ #include + #include #include #include + +#include #include + #include "sched/sched.h" /**************************************************************************** @@ -83,25 +87,21 @@ int pthread_setschedprio(pthread_t thread, int prio) * modified. */ - ret = sched_getparam((pid_t)thread, ¶m); + ret = nxsched_getparam((pid_t)thread, ¶m); 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, ¶m); - if (ret >= 0) + ret = nxsched_setparam((pid_t)thread, ¶m); + if (ret < 0) { - return OK; + return -ret; } -#ifdef CONFIG_SCHED_SPORADIC -errout_with_errno: -#endif - ret = get_errno(); - return ret; + return OK; } diff --git a/sched/sched/sched.h b/sched/sched/sched.h index d083dc6a59d..3dbbeeac6aa 100644 --- a/sched/sched/sched.h +++ b/sched/sched/sched.h @@ -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 */ diff --git a/sched/sched/sched_getaffinity.c b/sched/sched/sched_getaffinity.c index e7d355b50fe..fb0814027cc 100644 --- a/sched/sched/sched_getaffinity.c +++ b/sched/sched/sched_getaffinity.c @@ -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 * * Redistribution and use in source and binary forms, with or without @@ -44,6 +44,8 @@ #include #include +#include + #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 diff --git a/sched/sched/sched_getparam.c b/sched/sched/sched_getparam.c index 72833d9471f..e96c4451644 100644 --- a/sched/sched/sched_getparam.c +++ b/sched/sched/sched_getparam.c @@ -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 * * Redistribution and use in source and binary forms, with or without @@ -41,6 +41,9 @@ #include #include +#include + +#include #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; +} + diff --git a/sched/sched/sched_getscheduler.c b/sched/sched/sched_getscheduler.c index 47ba73fa9cc..1ca4cf64eda 100644 --- a/sched/sched/sched_getscheduler.c +++ b/sched/sched/sched_getscheduler.c @@ -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 * * Redistribution and use in source and binary forms, with or without @@ -43,6 +43,7 @@ #include #include +#include #include #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; } diff --git a/sched/sched/sched_reprioritize.c b/sched/sched/sched_reprioritize.c index d9431cf165e..66112c3da01 100644 --- a/sched/sched/sched_reprioritize.c +++ b/sched/sched/sched_reprioritize.c @@ -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 * * Redistribution and use in source and binary forms, with or without @@ -43,6 +43,8 @@ #include #include +#include + #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 diff --git a/sched/sched/sched_setaffinity.c b/sched/sched/sched_setaffinity.c index f7fb5928124..150d5019afe 100644 --- a/sched/sched/sched_setaffinity.c +++ b/sched/sched/sched_setaffinity.c @@ -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 * * 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 @@ -62,14 +62,20 @@ * 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 + * 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(). - * 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) + return ret; +} + +/**************************************************************************** + * 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(errcode); - return ERROR; + set_errno(-ret); + ret = ERROR; } - return OK; + return ret; } diff --git a/sched/sched/sched_setparam.c b/sched/sched/sched_setparam.c index 93bfccfe433..33307f15755 100644 --- a/sched/sched/sched_setparam.c +++ b/sched/sched/sched_setparam.c @@ -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 * * Redistribution and use in source and binary forms, with or without @@ -44,6 +45,7 @@ #include #include +#include #include #include @@ -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: + * 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. * ****************************************************************************/ -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; } diff --git a/sched/sched/sched_setpriority.c b/sched/sched/sched_setpriority.c index abad51b801d..1e8cbd41bfe 100644 --- a/sched/sched/sched_setpriority.c +++ b/sched/sched/sched_setpriority.c @@ -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 * * 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. */ diff --git a/sched/sched/sched_setscheduler.c b/sched/sched/sched_setscheduler.c index fecd1cf426a..6bee58f97e4 100644 --- a/sched/sched/sched_setscheduler.c +++ b/sched/sched/sched_setscheduler.c @@ -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 * * Redistribution and use in source and binary forms, with or without @@ -56,7 +57,7 @@ ****************************************************************************/ /**************************************************************************** - * Name:sched_setscheduler + * Name: sched_setscheduler * * Description: * sched_setscheduler() sets both the scheduling policy and the priority @@ -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 } diff --git a/sched/sched/sched_sporadic.c b/sched/sched/sched_sporadic.c index 90206c486e6..83349097ed2 100644 --- a/sched/sched/sched_sporadic.c +++ b/sched/sched/sched_sporadic.c @@ -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 * * 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; diff --git a/sched/sched/sched_yield.c b/sched/sched/sched_yield.c index c55a925dac0..e9e62920f93 100644 --- a/sched/sched/sched_yield.c +++ b/sched/sched/sched_yield.c @@ -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 * * 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; } + diff --git a/sched/semaphore/sem_holder.c b/sched/semaphore/sem_holder.c index 860032fb175..3080c3080fd 100644 --- a/sched/semaphore/sem_holder.c +++ b/sched/semaphore/sem_holder.c @@ -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 * * 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 } diff --git a/sched/task/task_posixspawn.c b/sched/task/task_posixspawn.c index 0792101884f..050b800a2a9 100644 --- a/sched/task/task_posixspawn.c +++ b/sched/task/task_posixspawn.c @@ -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 * * Redistribution and use in source and binary forms, with or without @@ -43,6 +43,7 @@ #include #include +#include #include #include #include @@ -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, ¶m); + ret = nxsched_getparam(0, ¶m); 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 diff --git a/sched/task/task_spawn.c b/sched/task/task_spawn.c index 852585d8c8e..e22193c5376 100644 --- a/sched/task/task_spawn.c +++ b/sched/task/task_spawn.c @@ -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 * * Redistribution and use in source and binary forms, with or without @@ -44,6 +44,8 @@ #include #include +#include + #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, ¶m); + ret = nxsched_getparam(0, ¶m); 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, ¶m); + ret = nxsched_getparam(0, ¶m); 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 diff --git a/sched/task/task_spawnparms.c b/sched/task/task_spawnparms.c index 1a9e5f79fcd..53c98777470 100644 --- a/sched/task/task_spawnparms.c +++ b/sched/task/task_spawnparms.c @@ -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 * * 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, ¶m); + ret = nxsched_getparam(pid, ¶m); 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, ¶m); + ret = nxsched_setparam(pid, ¶m); + 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, ¶m); + ret = nxsched_getparam(0, ¶m); + if (ret < 0) + { + return ret; + } } /* Are we setting the scheduling policy? If so, use the priority diff --git a/sched/wqueue/kwork_inherit.c b/sched/wqueue/kwork_inherit.c index 31c23b258b7..c648c4b4ede 100644 --- a/sched/wqueue/kwork_inherit.c +++ b/sched/wqueue/kwork_inherit.c @@ -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 * * 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 } }