include/, sched/, and libc/: Add support for sporadic scheduling parameters in struct sched_param, posix_spawnattr_t, and pthread_attr_t. Update all user interfaces to pass sporadic scheduling parameters. Feature is dependent on EXPERIMENTAL and no changes have yet been made to core scheduling logic.

This commit is contained in:
Gregory Nutt
2015-07-23 13:16:32 -06:00
parent 13e837b957
commit 9095e8eab4
22 changed files with 352 additions and 144 deletions
+9 -24
View File
@@ -45,26 +45,6 @@
#include <debug.h>
#include <errno.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Type Declarations
****************************************************************************/
/****************************************************************************
* Global Variables
****************************************************************************/
/****************************************************************************
* Private Variables
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
@@ -98,13 +78,18 @@ int pthread_attr_getschedparam(FAR const pthread_attr_t *attr,
}
else
{
param->sched_priority = attr->priority;
param->sched_priority = (int)attr->priority;
#ifdef CONFIG_SCHED_SPORADIC
param->sched_ss_low_priority = (int)attr->low_priority;
param->sched_ss_max_repl = (int)attr->max_repl;
param->sched_ss_repl_period.tv_sec = attr->repl_period.tv_sec;
param->sched_ss_repl_period.tv_nsec = attr->repl_period.tv_nsec;
param->sched_ss_init_budget.tv_sec = attr->budget.tv_sec;
param->sched_ss_init_budget.tv_nsec = attr->budget.tv_nsec;
#endif
ret = OK;
}
sdbg("Returning %d\n", ret);
return ret;
}
+12 -29
View File
@@ -1,7 +1,7 @@
/****************************************************************************
* libc/pthread/pthread_attrsetschedparam.c
*
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
* Copyright (C) 2007-2009, 2011, 2015 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -45,30 +45,6 @@
#include <debug.h>
#include <errno.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Type Declarations
****************************************************************************/
/****************************************************************************
* Global Variables
****************************************************************************/
/****************************************************************************
* Private Variables
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Function: pthread_attr_setschedparam
*
@@ -86,7 +62,7 @@
****************************************************************************/
int pthread_attr_setschedparam(FAR pthread_attr_t *attr,
FAR const struct sched_param *param)
FAR const struct sched_param *param)
{
int ret;
@@ -98,11 +74,18 @@ int pthread_attr_setschedparam(FAR pthread_attr_t *attr,
}
else
{
attr->priority = (short)param->sched_priority;
attr->priority = (short)param->sched_priority;
#ifdef CONFIG_SCHED_SPORADIC
attr->low_priority = (uint8_t)param->sched_ss_low_priority;
attr->max_repl = (uint8_t)param->sched_ss_max_repl;
attr->repl_period.tv_sec = param->sched_ss_repl_period.tv_sec;
attr->repl_period.tv_nsec = param->sched_ss_repl_period.tv_nsec;
attr->budget.tv_sec = param->sched_ss_init_budget.tv_sec;
attr->budget.tv_nsec = param->sched_ss_init_budget.tv_nsec;
#endif
ret = OK;
}
sdbg("Returning %d\n", ret);
return ret;
}
+9 -1
View File
@@ -1,7 +1,7 @@
/****************************************************************************
* libc/string/lib_psa_getschedparam.c
*
* Copyright (C) 2013 Gregory Nutt. All rights reserved.
* Copyright (C) 2013, 2015 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -70,5 +70,13 @@ int posix_spawnattr_getschedparam(FAR const posix_spawnattr_t *attr,
{
DEBUGASSERT(attr && param);
param->sched_priority = attr->priority;
#ifdef CONFIG_SCHED_SPORADIC
param->sched_ss_low_priority = (int)attr->low_priority;
param->sched_ss_max_repl = (int)attr->max_repl;
param->sched_ss_repl_period.tv_sec = attr->repl_period.tv_sec;
param->sched_ss_repl_period.tv_nsec = attr->repl_period.tv_nsec;
param->sched_ss_init_budget.tv_sec = attr->budget.tv_sec;
param->sched_ss_init_budget.tv_nsec = attr->budget.tv_nsec;
#endif
return OK;
}
+19 -6
View File
@@ -1,7 +1,7 @@
/****************************************************************************
* libc/string/lib_psa_init.c
*
* Copyright (C) 2013-2014 Gregory Nutt. All rights reserved.
* Copyright (C) 2013-2015 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -88,22 +88,35 @@ int posix_spawnattr_init(posix_spawnattr_t *attr)
return errno;
}
attr->priority = param.sched_priority;
attr->priority = param.sched_priority;
/* Set the default scheduler policy to the policy of this task */
attr->policy = sched_getscheduler(0);
attr->policy = sched_getscheduler(0);
#ifndef CONFIG_DISABLE_SIGNALS
/* Empty signal masek */
/* Empty signal mask */
attr->sigmask = 0;
attr->sigmask = 0;
#endif
#ifdef CONFIG_SCHED_SPORADIC
/* Sporadic scheduling parameters */
attr->low_priority = (uint8_t)param.sched_ss_low_priority;
attr->max_repl = (uint8_t)param.sched_ss_max_repl;
attr->repl_period.tv_sec = param.sched_ss_repl_period.tv_sec;
attr->repl_period.tv_nsec = param.sched_ss_repl_period.tv_nsec;
attr->budget.tv_sec = param.sched_ss_init_budget.tv_sec;
attr->budget.tv_nsec = param.sched_ss_init_budget.tv_nsec;
#endif
#ifndef CONFIG_ARCH_ADDRENV
/* Default stack size */
attr->stacksize = CONFIG_TASK_SPAWN_DEFAULT_STACKSIZE;
attr->stacksize = CONFIG_TASK_SPAWN_DEFAULT_STACKSIZE;
#endif
return OK;
}
+12 -2
View File
@@ -1,7 +1,7 @@
/****************************************************************************
* libc/string/lib_psa_setschedparam.c
*
* Copyright (C) 2013 Gregory Nutt. All rights reserved.
* Copyright (C) 2013, 2015 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -69,6 +69,16 @@ int posix_spawnattr_setschedparam(FAR posix_spawnattr_t *attr,
FAR const struct sched_param *param)
{
DEBUGASSERT(attr && param && (unsigned)param->sched_priority <= 0xff);
attr->priority = (uint8_t)param->sched_priority;
attr->priority = (uint8_t)param->sched_priority;
#ifdef CONFIG_SCHED_SPORADIC
attr->low_priority = (uint8_t)param->sched_ss_low_priority;
attr->max_repl = (uint8_t)param->sched_ss_max_repl;
attr->repl_period.tv_sec = param->sched_ss_repl_period.tv_sec;
attr->repl_period.tv_nsec = param->sched_ss_repl_period.tv_nsec;
attr->budget.tv_sec = param->sched_ss_init_budget.tv_sec;
attr->budget.tv_nsec = param->sched_ss_init_budget.tv_nsec;
#endif
return OK;
}
+18 -5
View File
@@ -1,7 +1,7 @@
/****************************************************************************
* libc/wqueue/work_usrthread.c
*
* Copyright (C) 2009-2014 Gregory Nutt. All rights reserved.
* Copyright (C) 2009-2015 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -375,7 +375,7 @@ int work_usrstart(void)
pthread_t usrwork;
pthread_attr_t attr;
struct sched_param param;
int status;
int ret;
/* Set up the work queue lock */
@@ -386,13 +386,26 @@ int work_usrstart(void)
(void)pthread_attr_init(&attr);
(void)pthread_attr_setstacksize(&attr, CONFIG_LIB_USRWORKSTACKSIZE);
+#ifdef CONFIG_SCHED_SPORADIC
/* Get the current sporadic scheduling parameters. Those will not be
* modified.
*/
ret = set_getparam(pid, &param);
if (ret < 0)
{
int erroode = get_errno();
return -errcode;
}
#endif
param.sched_priority = CONFIG_LIB_USRWORKPRIORITY;
(void)pthread_attr_setschedparam(&attr, &param);
status = pthread_create(&usrwork, &attr, work_usrthread, NULL);
if (status != 0)
ret = pthread_create(&usrwork, &attr, work_usrthread, NULL);
if (ret != 0)
{
return -status;
return -ret;
}
/* Detach because the return value and completion status will not be