.. | .. |
---|
1 | | -/* SPDX-License-Identifier: GPL-2.0 */ |
---|
2 | 1 | /* |
---|
3 | 2 | * Expose some of the kernel scheduler routines |
---|
4 | 3 | * |
---|
5 | | - * Copyright (C) 1999-2019, Broadcom Corporation |
---|
6 | | - * |
---|
| 4 | + * Portions of this code are copyright (c) 2022 Cypress Semiconductor Corporation |
---|
| 5 | + * |
---|
| 6 | + * Copyright (C) 1999-2017, Broadcom Corporation |
---|
| 7 | + * |
---|
7 | 8 | * Unless you and Broadcom execute a separate written software license |
---|
8 | 9 | * agreement governing use of this software, this software is licensed to you |
---|
9 | 10 | * under the terms of the GNU General Public License version 2 (the "GPL"), |
---|
10 | 11 | * available at http://www.broadcom.com/licenses/GPLv2.php, with the |
---|
11 | 12 | * following added to such license: |
---|
12 | | - * |
---|
| 13 | + * |
---|
13 | 14 | * As a special exception, the copyright holders of this software give you |
---|
14 | 15 | * permission to link this software with independent modules, and to copy and |
---|
15 | 16 | * distribute the resulting executable under terms of your choice, provided that |
---|
.. | .. |
---|
17 | 18 | * the license of that module. An independent module is a module which is not |
---|
18 | 19 | * derived from this software. The special exception does not apply to any |
---|
19 | 20 | * modifications of the software. |
---|
20 | | - * |
---|
| 21 | + * |
---|
21 | 22 | * Notwithstanding the above, under no circumstances may you combine this |
---|
22 | 23 | * software in any way with any other Broadcom software provided under a license |
---|
23 | 24 | * other than the GPL, without Broadcom's express prior written consent. |
---|
.. | .. |
---|
29 | 30 | */ |
---|
30 | 31 | #include <linux/kernel.h> |
---|
31 | 32 | #include <linux/module.h> |
---|
| 33 | +#include <linux/version.h> |
---|
| 34 | +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)) |
---|
| 35 | +#include <uapi/linux/sched/types.h> |
---|
| 36 | +#else |
---|
32 | 37 | #include <linux/sched.h> |
---|
| 38 | +#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) */ |
---|
33 | 39 | #include <typedefs.h> |
---|
34 | 40 | #include <linuxver.h> |
---|
35 | 41 | |
---|
36 | 42 | int setScheduler(struct task_struct *p, int policy, struct sched_param *param) |
---|
37 | 43 | { |
---|
38 | 44 | int rc = 0; |
---|
39 | | -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)) |
---|
| 45 | +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 9, 0)) |
---|
| 46 | + switch (policy) { |
---|
| 47 | + case SCHED_FIFO: |
---|
| 48 | + if (param->sched_priority >= MAX_RT_PRIO/2) |
---|
| 49 | + /* If the priority is MAX_RT_PRIO/2 or higher, |
---|
| 50 | + * it is considered as high priority. |
---|
| 51 | + * sched_priority of FIFO task dosen't |
---|
| 52 | + * exceed MAX_RT_PRIO/2. |
---|
| 53 | + */ |
---|
| 54 | + sched_set_fifo(p); |
---|
| 55 | + else |
---|
| 56 | + /* For when you don't much care about FIFO, |
---|
| 57 | + * but want to be above SCHED_NORMAL. |
---|
| 58 | + */ |
---|
| 59 | + sched_set_fifo_low(p); |
---|
| 60 | + break; |
---|
| 61 | + case SCHED_NORMAL: |
---|
| 62 | + sched_set_normal(p, PRIO_TO_NICE(p->static_prio)); |
---|
| 63 | + break; |
---|
| 64 | + } |
---|
| 65 | +#else |
---|
40 | 66 | rc = sched_setscheduler(p, policy, param); |
---|
41 | | -#endif /* LinuxVer */ |
---|
| 67 | +#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(5, 9, 0) */ |
---|
42 | 68 | return rc; |
---|
43 | 69 | } |
---|
44 | 70 | |
---|
45 | 71 | int get_scheduler_policy(struct task_struct *p) |
---|
46 | 72 | { |
---|
47 | 73 | int rc = SCHED_NORMAL; |
---|
48 | | -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)) |
---|
49 | 74 | rc = p->policy; |
---|
50 | | -#endif /* LinuxVer */ |
---|
51 | 75 | return rc; |
---|
52 | 76 | } |
---|