blob: 875fe06ec19d456009e5cd6f15ba48c22a4bec95 [file] [log] [blame]
Liam Girdwoodf4fc2322017-06-06 20:25:27 +01001/*
2 * Copyright (c) 2017, Intel Corporation
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the Intel Corporation nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 *
28 * Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>
29 */
30
Pierre-Louis Bossart81708a52018-04-04 18:46:50 -050031#ifndef __INCLUDE_SOF_SCHEDULE_H__
32#define __INCLUDE_SOF_SCHEDULE_H__
Liam Girdwoodf4fc2322017-06-06 20:25:27 +010033
34#include <stdint.h>
35#include <stddef.h>
36#include <errno.h>
Pierre-Louis Bossart81708a52018-04-04 18:46:50 -050037#include <sof/sof.h>
38#include <sof/lock.h>
39#include <sof/list.h>
40#include <sof/work.h>
Liam Girdwoodf4fc2322017-06-06 20:25:27 +010041
Tomasz Lauda311aa132018-07-02 18:53:51 +020042struct schedule_data;
Pierre-Louis Bossart81708a52018-04-04 18:46:50 -050043struct sof;
Liam Girdwoodf4fc2322017-06-06 20:25:27 +010044
45/* task states */
46#define TASK_STATE_INIT 0
47#define TASK_STATE_QUEUED 1
48#define TASK_STATE_RUNNING 2
49#define TASK_STATE_PREEMPTED 3
50#define TASK_STATE_COMPLETED 4
Liam Girdwood3488cce2017-08-10 11:59:08 +010051#define TASK_STATE_FREE 5
Liam Girdwood2ea55f82017-09-22 00:30:28 +010052#define TASK_STATE_CANCEL 6
Liam Girdwoodf4fc2322017-06-06 20:25:27 +010053
54/* task priorities - values same as Linux processes, gives scope for future.*/
55#define TASK_PRI_LOW 19
56#define TASK_PRI_MED 0
57#define TASK_PRI_HIGH -20
58
Liam Girdwood2ea55f82017-09-22 00:30:28 +010059
60/* task descriptor */
Liam Girdwoodf4fc2322017-06-06 20:25:27 +010061struct task {
62 uint16_t core; /* core id to run on */
63 int16_t priority; /* scheduling priority TASK_PRI_ */
Liam Girdwood2ea55f82017-09-22 00:30:28 +010064 uint64_t start; /* scheduling earliest start time */
65 uint64_t deadline; /* scheduling deadline */
Liam Girdwoodf4fc2322017-06-06 20:25:27 +010066 uint32_t state; /* TASK_STATE_ */
67 struct list_item list; /* list in scheduler */
Marcin Makad3200d12018-06-04 12:03:44 +010068 struct list_item irq_list; /* list for assigned irq level */
Liam Girdwood2ea55f82017-09-22 00:30:28 +010069
70 /* task function and private data */
Liam Girdwoodf4fc2322017-06-06 20:25:27 +010071 void *data;
Liam Girdwoodf4fc2322017-06-06 20:25:27 +010072 void (*func)(void *arg);
Liam Girdwood2ea55f82017-09-22 00:30:28 +010073
74 /* runtime duration in scheduling clock base */
75 uint64_t max_rtime; /* max time taken to run */
Liam Girdwoodf4fc2322017-06-06 20:25:27 +010076};
77
Tomasz Lauda311aa132018-07-02 18:53:51 +020078struct schedule_data **arch_schedule_get(void);
79
Liam Girdwoodf4fc2322017-06-06 20:25:27 +010080void schedule(void);
81
Liam Girdwood2ea55f82017-09-22 00:30:28 +010082void schedule_task(struct task *task, uint64_t start, uint64_t deadline);
Liam Girdwoodf4fc2322017-06-06 20:25:27 +010083
Liam Girdwoodd1e88b22017-11-16 20:09:39 +000084void schedule_task_idle(struct task *task, uint64_t deadline);
85
Liam Girdwoodf4fc2322017-06-06 20:25:27 +010086void schedule_task_complete(struct task *task);
87
Liam Girdwood2ea55f82017-09-22 00:30:28 +010088static inline void schedule_task_init(struct task *task, void (*func)(void *),
Liam Girdwoodf4fc2322017-06-06 20:25:27 +010089 void *data)
90{
91 task->core = 0;
Liam Girdwoodf4fc2322017-06-06 20:25:27 +010092 task->state = TASK_STATE_INIT;
93 task->func = func;
94 task->data = data;
Liam Girdwoodf4fc2322017-06-06 20:25:27 +010095}
96
Liam Girdwood2ea55f82017-09-22 00:30:28 +010097static inline void schedule_task_free(struct task *task)
Liam Girdwood3488cce2017-08-10 11:59:08 +010098{
99 task->state = TASK_STATE_FREE;
100 task->func = NULL;
101 task->data = NULL;
Liam Girdwood3488cce2017-08-10 11:59:08 +0100102}
103
Liam Girdwood2ea55f82017-09-22 00:30:28 +0100104static inline void schedule_task_config(struct task *task, uint16_t priority,
105 uint16_t core)
106{
107 task->priority = priority;
108 task->core = core;
109}
Liam Girdwood3488cce2017-08-10 11:59:08 +0100110
Pierre-Louis Bossart81708a52018-04-04 18:46:50 -0500111int scheduler_init(struct sof *sof);
Liam Girdwoodf4fc2322017-06-06 20:25:27 +0100112
Tomasz Laudace53ba12018-07-06 12:23:21 +0200113void scheduler_free(void);
114
Liam Girdwoodf4fc2322017-06-06 20:25:27 +0100115#endif