Liam Girdwood | f4fc232 | 2017-06-06 20:25:27 +0100 | [diff] [blame] | 1 | /* |
| 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 Bossart | 81708a5 | 2018-04-04 18:46:50 -0500 | [diff] [blame] | 31 | #ifndef __INCLUDE_SOF_SCHEDULE_H__ |
| 32 | #define __INCLUDE_SOF_SCHEDULE_H__ |
Liam Girdwood | f4fc232 | 2017-06-06 20:25:27 +0100 | [diff] [blame] | 33 | |
| 34 | #include <stdint.h> |
| 35 | #include <stddef.h> |
| 36 | #include <errno.h> |
Pierre-Louis Bossart | 81708a5 | 2018-04-04 18:46:50 -0500 | [diff] [blame] | 37 | #include <sof/sof.h> |
| 38 | #include <sof/lock.h> |
| 39 | #include <sof/list.h> |
| 40 | #include <sof/work.h> |
Liam Girdwood | f4fc232 | 2017-06-06 20:25:27 +0100 | [diff] [blame] | 41 | |
Tomasz Lauda | 311aa13 | 2018-07-02 18:53:51 +0200 | [diff] [blame] | 42 | struct schedule_data; |
Pierre-Louis Bossart | 81708a5 | 2018-04-04 18:46:50 -0500 | [diff] [blame] | 43 | struct sof; |
Liam Girdwood | f4fc232 | 2017-06-06 20:25:27 +0100 | [diff] [blame] | 44 | |
| 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 Girdwood | 3488cce | 2017-08-10 11:59:08 +0100 | [diff] [blame] | 51 | #define TASK_STATE_FREE 5 |
Liam Girdwood | 2ea55f8 | 2017-09-22 00:30:28 +0100 | [diff] [blame] | 52 | #define TASK_STATE_CANCEL 6 |
Liam Girdwood | f4fc232 | 2017-06-06 20:25:27 +0100 | [diff] [blame] | 53 | |
| 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 Girdwood | 2ea55f8 | 2017-09-22 00:30:28 +0100 | [diff] [blame] | 59 | |
| 60 | /* task descriptor */ |
Liam Girdwood | f4fc232 | 2017-06-06 20:25:27 +0100 | [diff] [blame] | 61 | struct task { |
| 62 | uint16_t core; /* core id to run on */ |
| 63 | int16_t priority; /* scheduling priority TASK_PRI_ */ |
Liam Girdwood | 2ea55f8 | 2017-09-22 00:30:28 +0100 | [diff] [blame] | 64 | uint64_t start; /* scheduling earliest start time */ |
| 65 | uint64_t deadline; /* scheduling deadline */ |
Liam Girdwood | f4fc232 | 2017-06-06 20:25:27 +0100 | [diff] [blame] | 66 | uint32_t state; /* TASK_STATE_ */ |
| 67 | struct list_item list; /* list in scheduler */ |
Marcin Maka | d3200d1 | 2018-06-04 12:03:44 +0100 | [diff] [blame] | 68 | struct list_item irq_list; /* list for assigned irq level */ |
Liam Girdwood | 2ea55f8 | 2017-09-22 00:30:28 +0100 | [diff] [blame] | 69 | |
| 70 | /* task function and private data */ |
Liam Girdwood | f4fc232 | 2017-06-06 20:25:27 +0100 | [diff] [blame] | 71 | void *data; |
Liam Girdwood | f4fc232 | 2017-06-06 20:25:27 +0100 | [diff] [blame] | 72 | void (*func)(void *arg); |
Liam Girdwood | 2ea55f8 | 2017-09-22 00:30:28 +0100 | [diff] [blame] | 73 | |
| 74 | /* runtime duration in scheduling clock base */ |
| 75 | uint64_t max_rtime; /* max time taken to run */ |
Liam Girdwood | f4fc232 | 2017-06-06 20:25:27 +0100 | [diff] [blame] | 76 | }; |
| 77 | |
Tomasz Lauda | 311aa13 | 2018-07-02 18:53:51 +0200 | [diff] [blame] | 78 | struct schedule_data **arch_schedule_get(void); |
| 79 | |
Liam Girdwood | f4fc232 | 2017-06-06 20:25:27 +0100 | [diff] [blame] | 80 | void schedule(void); |
| 81 | |
Liam Girdwood | 2ea55f8 | 2017-09-22 00:30:28 +0100 | [diff] [blame] | 82 | void schedule_task(struct task *task, uint64_t start, uint64_t deadline); |
Liam Girdwood | f4fc232 | 2017-06-06 20:25:27 +0100 | [diff] [blame] | 83 | |
Liam Girdwood | d1e88b2 | 2017-11-16 20:09:39 +0000 | [diff] [blame] | 84 | void schedule_task_idle(struct task *task, uint64_t deadline); |
| 85 | |
Liam Girdwood | f4fc232 | 2017-06-06 20:25:27 +0100 | [diff] [blame] | 86 | void schedule_task_complete(struct task *task); |
| 87 | |
Liam Girdwood | 2ea55f8 | 2017-09-22 00:30:28 +0100 | [diff] [blame] | 88 | static inline void schedule_task_init(struct task *task, void (*func)(void *), |
Liam Girdwood | f4fc232 | 2017-06-06 20:25:27 +0100 | [diff] [blame] | 89 | void *data) |
| 90 | { |
| 91 | task->core = 0; |
Liam Girdwood | f4fc232 | 2017-06-06 20:25:27 +0100 | [diff] [blame] | 92 | task->state = TASK_STATE_INIT; |
| 93 | task->func = func; |
| 94 | task->data = data; |
Liam Girdwood | f4fc232 | 2017-06-06 20:25:27 +0100 | [diff] [blame] | 95 | } |
| 96 | |
Liam Girdwood | 2ea55f8 | 2017-09-22 00:30:28 +0100 | [diff] [blame] | 97 | static inline void schedule_task_free(struct task *task) |
Liam Girdwood | 3488cce | 2017-08-10 11:59:08 +0100 | [diff] [blame] | 98 | { |
| 99 | task->state = TASK_STATE_FREE; |
| 100 | task->func = NULL; |
| 101 | task->data = NULL; |
Liam Girdwood | 3488cce | 2017-08-10 11:59:08 +0100 | [diff] [blame] | 102 | } |
| 103 | |
Liam Girdwood | 2ea55f8 | 2017-09-22 00:30:28 +0100 | [diff] [blame] | 104 | static 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 Girdwood | 3488cce | 2017-08-10 11:59:08 +0100 | [diff] [blame] | 110 | |
Pierre-Louis Bossart | 81708a5 | 2018-04-04 18:46:50 -0500 | [diff] [blame] | 111 | int scheduler_init(struct sof *sof); |
Liam Girdwood | f4fc232 | 2017-06-06 20:25:27 +0100 | [diff] [blame] | 112 | |
Tomasz Lauda | ce53ba1 | 2018-07-06 12:23:21 +0200 | [diff] [blame] | 113 | void scheduler_free(void); |
| 114 | |
Liam Girdwood | f4fc232 | 2017-06-06 20:25:27 +0100 | [diff] [blame] | 115 | #endif |