* include/sched.h
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __INCLUDE_SCHED_H
#define __INCLUDE_SCHED_H
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <stdint.h>
#include <stdbool.h>
#include <strings.h>
#include <time.h>
* Pre-processor Definitions
****************************************************************************/
#define SCHED_FIFO 0
#define SCHED_RR 1
#define SCHED_SPORADIC 2
#define SCHED_OTHER 3
#define SCHED_NORMAL 3
#define SCHED_BATCH 4
#define SCHED_IDLE 5
#define SS_REPL_MAX CONFIG_SCHED_SPORADIC_MAXREPL
#define TASK_CANCEL_ENABLE (0)
#define TASK_CANCEL_DISABLE (1)
#define TASK_CANCEL_DEFERRED (0)
#define TASK_CANCEL_ASYNCHRONOUS (1)
#define PTHREAD_KEYS_MAX CONFIG_TLS_NELEM
#define CPU_SETSIZE CONFIG_SMP_NCPUS
#define CPU_ZERO(s) do { *(s) = 0; } while (0)
#define CPU_SET(c,s) do { *(s) |= (1u << (c)); } while (0)
#define CPU_CLR(c,s) do { *(s) &= ~(1u << (c)); } while (0)
#define CPU_ISSET(c,s) ((*(s) & (1u << (c))) != 0)
#define CPU_COUNT(s) popcountl(*s)
* FAR const cpu_set_t *srcset2);
*/
#define CPU_AND(d,s1,s2) do { *(d) = *(s1) & *(s2); } while (0)
* FAR const cpu_set_t *srcset2);
*/
#define CPU_OR(d,s1,s2) do { *(d) = *(s1) | *(s2); } while (0)
* FAR const cpu_set_t *srcset2);
*/
#define CPU_XOR(d,s1,s2) do { *(d) = *(s1) ^ *(s2); } while (0)
#define CPU_EQUAL(s1,s2) (*(s1) == *(s2))
#define CPU_ALLOC(n) (FAR cpu_set_t *)malloc(sizeof(cpu_set_t));
#define CPU_FREE(s) free(s)
#define CPU_ALLOC_SIZE(n) sizeof(cpu_set_t)
#define CPU_ZERO_S(n,s) memset(s, 0, n)
#define CPU_SET_S(c,n,s) CPU_SET(c,s)
#define CPU_CLR_S(c,n,s) CPU_CLR(c,s)
#define CPU_ISSET_S(c,n,s) CPU_ISSET(c,s)
#define CPU_COUNT_S(n,s) CPU_COUNT(s)
* FAR const cpu_set_t *srcset1,
* FAR const cpu_set_t *srcset2);
*/
#define CPU_AND_S(n,d,s1,s2) CPU_AND(d,s1,s2)
* FAR const cpu_set_t *srcset1,
* FAR const cpu_set_t *srcset2);
*/
#define CPU_OR_S(n,d,s1,s2) CPU_OR(d,s1,s2)
* FAR const cpu_set_t *srcset1,
* FAR const cpu_set_t *srcset2);
*/
#define CPU_XOR_S(n,d,s1,s2) CPU_XOR(d,s1,s2)
* FAR const cpu_set_t *set2);
*/
#define CPU_EQUAL_S(n,s1,s2) CPU_EQUAL(s1,s2)
* Public Type Definitions
****************************************************************************/
struct sched_param
{
int sched_priority;
#ifdef CONFIG_SCHED_SPORADIC
int sched_ss_low_priority;
* server */
struct timespec sched_ss_repl_period;
* server. */
struct timespec sched_ss_init_budget;
int sched_ss_max_repl;
* sporadic server. */
#endif
};
* Public Data
****************************************************************************/
#ifndef __ASSEMBLY__
#undef EXTERN
#if defined(__cplusplus)
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
* Public Function Prototypes
****************************************************************************/
#ifndef CONFIG_BUILD_KERNEL
int task_create(FAR const char *, int, int,
main_t, FAR char * const[]);
int task_create_with_stack(FAR const char *, int,
FAR void *, int,
main_t, FAR char * const[]);
#endif
int task_delete(pid_t);
int task_restart(pid_t);
int task_setcancelstate(int, FAR int *);
int task_setcanceltype(int, FAR int *);
void task_testcancel(void);
int sched_getcpu(void);
int sched_setparam(pid_t, FAR const struct sched_param *);
int sched_getparam(pid_t, FAR struct sched_param *);
int sched_setscheduler(pid_t, int,
FAR const struct sched_param *);
int sched_getscheduler(pid_t);
int sched_yield(void);
int sched_get_priority_max(int);
int sched_get_priority_min(int);
int sched_rr_get_interval(pid_t, FAR struct timespec *);
#ifdef CONFIG_SMP
int sched_setaffinity(pid_t pid, size_t cpusetsize,
FAR const cpu_set_t *mask);
int sched_getaffinity(pid_t pid, size_t cpusetsize, FAR cpu_set_t *mask);
int sched_cpucount(FAR const cpu_set_t *set);
#else
# define sched_setaffinity(p, c, m) 0
# define sched_getaffinity(p, c, m) (*(m) |= (1 << 0), 0)
# define sched_cpucount(s) 1
#endif
int sched_lockcount(void);
bool sched_idletask(void);
#ifdef CONFIG_SCHED_BACKTRACE
int sched_backtrace(pid_t, FAR void **, int, int);
void sched_dumpstack(pid_t);
#else
# define sched_backtrace(tid, buffer, size, skip) 0
# define sched_dumpstack(tid)
#endif
#undef EXTERN
#if defined(__cplusplus)
}
#endif
#endif
#endif