forked from thesofproject/sof
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschedule.c
More file actions
77 lines (62 loc) · 1.88 KB
/
schedule.c
File metadata and controls
77 lines (62 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// SPDX-License-Identifier: BSD-3-Clause
//
// Copyright(c) 2019 Intel Corporation. All rights reserved.
//
// Author: Bartosz Kokoszko <bartoszx.kokoszko@linux.intel.com>
/* Generic scheduler */
#include <rtos/alloc.h>
#include <sof/lib/uuid.h>
#include <sof/list.h>
#include <sof/schedule/schedule.h>
#include <rtos/task.h>
#include <ipc/topology.h>
#include <errno.h>
#include <stdint.h>
LOG_MODULE_REGISTER(schedule, CONFIG_SOF_LOG_LEVEL);
/* 3dee06de-f25a-4e10-ae1f-abc9573873ea */
DECLARE_SOF_UUID("schedule", sch_uuid, 0x3dee06de, 0xf25a, 0x4e10,
0xae, 0x1f, 0xab, 0xc9, 0x57, 0x38, 0x73, 0xea);
DECLARE_TR_CTX(sch_tr, SOF_UUID(sch_uuid), LOG_LEVEL_INFO);
int schedule_task_init(struct task *task,
const struct sof_uuid_entry *uid, uint16_t type,
uint16_t priority, enum task_state (*run)(void *data),
void *data, uint16_t core, uint32_t flags)
{
if (type >= SOF_SCHEDULE_COUNT) {
tr_err(&sch_tr, "schedule_task_init(): invalid task type");
return -EINVAL;
}
task->uid = uid;
task->type = type;
task->priority = priority;
task->core = core;
task->flags = flags;
task->state = SOF_TASK_STATE_INIT;
task->ops.run = run;
task->data = data;
return 0;
}
static void scheduler_register(struct schedule_data *scheduler)
{
struct schedulers **sch = arch_schedulers_get();
if (!*sch) {
/* init schedulers list */
*sch = rzalloc(SOF_MEM_ZONE_SYS, 0, SOF_MEM_CAPS_RAM,
sizeof(**sch));
list_init(&(*sch)->list);
}
list_item_append(&scheduler->list, &(*sch)->list);
}
void scheduler_init(int type, const struct scheduler_ops *ops, void *data)
{
struct schedule_data *sch;
if (!ops || !ops->schedule_task || !ops->schedule_task_cancel ||
!ops->schedule_task_free)
return;
sch = rzalloc(SOF_MEM_ZONE_SYS, 0, SOF_MEM_CAPS_RAM, sizeof(*sch));
list_init(&sch->list);
sch->type = type;
sch->ops = ops;
sch->data = data;
scheduler_register(sch);
}