-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathfengchi_oneplus_13s.patch
More file actions
21125 lines (20994 loc) · 607 KB
/
fengchi_oneplus_13s.patch
File metadata and controls
21125 lines (20994 loc) · 607 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
diff --git a/Documentation/scheduler/index.rst b/Documentation/scheduler/index.rst
index 0b650bb550e6..3170747226f6 100644
--- a/Documentation/scheduler/index.rst
+++ b/Documentation/scheduler/index.rst
@@ -19,7 +19,6 @@ Scheduler
sched-nice-design
sched-rt-group
sched-stats
- sched-ext
sched-debug
text_files
diff --git a/Documentation/scheduler/sched-ext.rst b/Documentation/scheduler/sched-ext.rst
deleted file mode 100644
index 84c30b44f104..000000000000
--- a/Documentation/scheduler/sched-ext.rst
+++ /dev/null
@@ -1,230 +0,0 @@
-==========================
-Extensible Scheduler Class
-==========================
-
-sched_ext is a scheduler class whose behavior can be defined by a set of BPF
-programs - the BPF scheduler.
-
-* sched_ext exports a full scheduling interface so that any scheduling
- algorithm can be implemented on top.
-
-* The BPF scheduler can group CPUs however it sees fit and schedule them
- together, as tasks aren't tied to specific CPUs at the time of wakeup.
-
-* The BPF scheduler can be turned on and off dynamically anytime.
-
-* The system integrity is maintained no matter what the BPF scheduler does.
- The default scheduling behavior is restored anytime an error is detected,
- a runnable task stalls, or on invoking the SysRq key sequence
- :kbd:`SysRq-S`.
-
-Switching to and from sched_ext
-===============================
-
-``CONFIG_SCHED_CLASS_EXT`` is the config option to enable sched_ext and
-``tools/sched_ext`` contains the example schedulers.
-
-sched_ext is used only when the BPF scheduler is loaded and running.
-
-If a task explicitly sets its scheduling policy to ``SCHED_EXT``, it will be
-treated as ``SCHED_NORMAL`` and scheduled by CFS until the BPF scheduler is
-loaded. On load, such tasks will be switched to and scheduled by sched_ext.
-
-The BPF scheduler can choose to schedule all normal and lower class tasks by
-calling ``scx_bpf_switch_all()`` from its ``init()`` operation. In this
-case, all ``SCHED_NORMAL``, ``SCHED_BATCH``, ``SCHED_IDLE`` and
-``SCHED_EXT`` tasks are scheduled by sched_ext. In the example schedulers,
-this mode can be selected with the ``-a`` option.
-
-Terminating the sched_ext scheduler program, triggering :kbd:`SysRq-S`, or
-detection of any internal error including stalled runnable tasks aborts the
-BPF scheduler and reverts all tasks back to CFS.
-
-.. code-block:: none
-
- # make -j16 -C tools/sched_ext
- # tools/sched_ext/scx_example_simple
- local=0 global=3
- local=5 global=24
- local=9 global=44
- local=13 global=56
- local=17 global=72
- ^CEXIT: BPF scheduler unregistered
-
-If ``CONFIG_SCHED_DEBUG`` is set, the current status of the BPF scheduler
-and whether a given task is on sched_ext can be determined as follows:
-
-.. code-block:: none
-
- # cat /sys/kernel/debug/sched/ext
- ops : simple
- enabled : 1
- switching_all : 1
- switched_all : 1
- enable_state : enabled
-
- # grep ext /proc/self/sched
- ext.enabled : 1
-
-The Basics
-==========
-
-Userspace can implement an arbitrary BPF scheduler by loading a set of BPF
-programs that implement ``struct sched_ext_ops``. The only mandatory field
-is ``ops.name`` which must be a valid BPF object name. All operations are
-optional. The following modified excerpt is from
-``tools/sched/scx_example_simple.bpf.c`` showing a minimal global FIFO
-scheduler.
-
-.. code-block:: c
-
- s32 BPF_STRUCT_OPS(simple_init)
- {
- if (!switch_partial)
- scx_bpf_switch_all();
- return 0;
- }
-
- void BPF_STRUCT_OPS(simple_enqueue, struct task_struct *p, u64 enq_flags)
- {
- if (enq_flags & SCX_ENQ_LOCAL)
- scx_bpf_dispatch(p, SCX_DSQ_LOCAL, enq_flags);
- else
- scx_bpf_dispatch(p, SCX_DSQ_GLOBAL, enq_flags);
- }
-
- void BPF_STRUCT_OPS(simple_exit, struct scx_exit_info *ei)
- {
- exit_type = ei->type;
- }
-
- SEC(".struct_ops")
- struct sched_ext_ops simple_ops = {
- .enqueue = (void *)simple_enqueue,
- .init = (void *)simple_init,
- .exit = (void *)simple_exit,
- .name = "simple",
- };
-
-Dispatch Queues
----------------
-
-To match the impedance between the scheduler core and the BPF scheduler,
-sched_ext uses DSQs (dispatch queues) which can operate as both a FIFO and a
-priority queue. By default, there is one global FIFO (``SCX_DSQ_GLOBAL``),
-and one local dsq per CPU (``SCX_DSQ_LOCAL``). The BPF scheduler can manage
-an arbitrary number of dsq's using ``scx_bpf_create_dsq()`` and
-``scx_bpf_destroy_dsq()``.
-
-A CPU always executes a task from its local DSQ. A task is "dispatched" to a
-DSQ. A non-local DSQ is "consumed" to transfer a task to the consuming CPU's
-local DSQ.
-
-When a CPU is looking for the next task to run, if the local DSQ is not
-empty, the first task is picked. Otherwise, the CPU tries to consume the
-global DSQ. If that doesn't yield a runnable task either, ``ops.dispatch()``
-is invoked.
-
-Scheduling Cycle
-----------------
-
-The following briefly shows how a waking task is scheduled and executed.
-
-1. When a task is waking up, ``ops.select_cpu()`` is the first operation
- invoked. This serves two purposes. First, CPU selection optimization
- hint. Second, waking up the selected CPU if idle.
-
- The CPU selected by ``ops.select_cpu()`` is an optimization hint and not
- binding. The actual decision is made at the last step of scheduling.
- However, there is a small performance gain if the CPU
- ``ops.select_cpu()`` returns matches the CPU the task eventually runs on.
-
- A side-effect of selecting a CPU is waking it up from idle. While a BPF
- scheduler can wake up any cpu using the ``scx_bpf_kick_cpu()`` helper,
- using ``ops.select_cpu()`` judiciously can be simpler and more efficient.
-
- Note that the scheduler core will ignore an invalid CPU selection, for
- example, if it's outside the allowed cpumask of the task.
-
-2. Once the target CPU is selected, ``ops.enqueue()`` is invoked. It can
- make one of the following decisions:
-
- * Immediately dispatch the task to either the global or local DSQ by
- calling ``scx_bpf_dispatch()`` with ``SCX_DSQ_GLOBAL`` or
- ``SCX_DSQ_LOCAL``, respectively.
-
- * Immediately dispatch the task to a custom DSQ by calling
- ``scx_bpf_dispatch()`` with a DSQ ID which is smaller than 2^63.
-
- * Queue the task on the BPF side.
-
-3. When a CPU is ready to schedule, it first looks at its local DSQ. If
- empty, it then looks at the global DSQ. If there still isn't a task to
- run, ``ops.dispatch()`` is invoked which can use the following two
- functions to populate the local DSQ.
-
- * ``scx_bpf_dispatch()`` dispatches a task to a DSQ. Any target DSQ can
- be used - ``SCX_DSQ_LOCAL``, ``SCX_DSQ_LOCAL_ON | cpu``,
- ``SCX_DSQ_GLOBAL`` or a custom DSQ. While ``scx_bpf_dispatch()``
- currently can't be called with BPF locks held, this is being worked on
- and will be supported. ``scx_bpf_dispatch()`` schedules dispatching
- rather than performing them immediately. There can be up to
- ``ops.dispatch_max_batch`` pending tasks.
-
- * ``scx_bpf_consume()`` tranfers a task from the specified non-local DSQ
- to the dispatching DSQ. This function cannot be called with any BPF
- locks held. ``scx_bpf_consume()`` flushes the pending dispatched tasks
- before trying to consume the specified DSQ.
-
-4. After ``ops.dispatch()`` returns, if there are tasks in the local DSQ,
- the CPU runs the first one. If empty, the following steps are taken:
-
- * Try to consume the global DSQ. If successful, run the task.
-
- * If ``ops.dispatch()`` has dispatched any tasks, retry #3.
-
- * If the previous task is an SCX task and still runnable, keep executing
- it (see ``SCX_OPS_ENQ_LAST``).
-
- * Go idle.
-
-Note that the BPF scheduler can always choose to dispatch tasks immediately
-in ``ops.enqueue()`` as illustrated in the above simple example. If only the
-built-in DSQs are used, there is no need to implement ``ops.dispatch()`` as
-a task is never queued on the BPF scheduler and both the local and global
-DSQs are consumed automatically.
-
-``scx_bpf_dispatch()`` queues the task on the FIFO of the target DSQ. Use
-``scx_bpf_dispatch_vtime()`` for the priority queue. See the function
-documentation and usage in ``tools/sched_ext/scx_example_simple.bpf.c`` for
-more information.
-
-Where to Look
-=============
-
-* ``include/linux/sched/ext.h`` defines the core data structures, ops table
- and constants.
-
-* ``kernel/sched/ext.c`` contains sched_ext core implementation and helpers.
- The functions prefixed with ``scx_bpf_`` can be called from the BPF
- scheduler.
-
-* ``tools/sched_ext/`` hosts example BPF scheduler implementations.
-
- * ``scx_example_simple[.bpf].c``: Minimal global FIFO scheduler example
- using a custom DSQ.
-
- * ``scx_example_qmap[.bpf].c``: A multi-level FIFO scheduler supporting
- five levels of priority implemented with ``BPF_MAP_TYPE_QUEUE``.
-
-ABI Instability
-===============
-
-The APIs provided by sched_ext to BPF schedulers programs have no stability
-guarantees. This includes the ops table callbacks and constants defined in
-``include/linux/sched/ext.h``, as well as the ``scx_bpf_`` kfuncs defined in
-``kernel/sched/ext.c``.
-
-While we will attempt to provide a relatively stable API surface when
-possible, they are subject to change without warning between kernel
-versions.
diff --git a/MAINTAINERS b/MAINTAINERS
index ff6b9ea9b788..46ca82b0b506 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -19125,8 +19125,6 @@ R: Ben Segall <bsegall@google.com> (CONFIG_CFS_BANDWIDTH)
R: Mel Gorman <mgorman@suse.de> (CONFIG_NUMA_BALANCING)
R: Daniel Bristot de Oliveira <bristot@redhat.com> (SCHED_DEADLINE)
R: Valentin Schneider <vschneid@redhat.com> (TOPOLOGY)
-R: Tejun Heo <tj@kernel.org> (SCHED_EXT)
-R: David Vernet <void@manifault.com> (SCHED_EXT)
L: linux-kernel@vger.kernel.org
S: Maintained
T: git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git sched/core
@@ -19135,7 +19133,6 @@ F: include/linux/sched.h
F: include/linux/wait.h
F: include/uapi/linux/sched.h
F: kernel/sched/
-F: tools/sched_ext/
SCSI LIBSAS SUBSYSTEM
R: John Garry <john.g.garry@oracle.com>
diff --git a/arch/arm64/configs/defconfig b/arch/arm64/configs/defconfig
index f93980c09d7f..5ba590235a8c 100644
--- a/arch/arm64/configs/defconfig
+++ b/arch/arm64/configs/defconfig
@@ -6,8 +6,7 @@ CONFIG_HIGH_RES_TIMERS=y
CONFIG_BPF_SYSCALL=y
CONFIG_BPF_JIT=y
CONFIG_PREEMPT=y
-CONFIG_SLIM_SCHED=y
-CONFIG_SCHED_CLASS_EXT=y
+CONFIG_HMBIRD_SCHED=y
CONFIG_IRQ_TIME_ACCOUNTING=y
CONFIG_BSD_PROCESS_ACCT=y
CONFIG_BSD_PROCESS_ACCT_V3=y
diff --git a/arch/arm64/configs/gki_defconfig b/arch/arm64/configs/gki_defconfig
index 42c199371c79..ef087e70fba4 100644
--- a/arch/arm64/configs/gki_defconfig
+++ b/arch/arm64/configs/gki_defconfig
@@ -10,8 +10,7 @@ CONFIG_BPF_JIT_ALWAYS_ON=y
# CONFIG_BPF_UNPRIV_DEFAULT_OFF is not set
CONFIG_BPF_LSM=y
CONFIG_PREEMPT=y
-CONFIG_SLIM_SCHED=y
-CONFIG_SCHED_CLASS_EXT=y
+CONFIG_HMBIRD_SCHED=y
CONFIG_IRQ_TIME_ACCOUNTING=y
CONFIG_TASKSTATS=y
CONFIG_TASK_DELAY_ACCT=y
diff --git a/drivers/gpu/drm/msm/msm_drv.c b/drivers/gpu/drm/msm/msm_drv.c
index 4bd028fa7500..5825ce9d6d7b 100755
--- a/drivers/gpu/drm/msm/msm_drv.c
+++ b/drivers/gpu/drm/msm/msm_drv.c
@@ -510,6 +510,9 @@ static int msm_drm_init(struct device *dev, const struct drm_driver *drv)
}
sched_set_fifo(ev_thread->worker->task);
+#ifdef CONFIG_HMBIRD_SCHED
+ hmbird_set_sched_prop(ev_thread->worker->task, SCHED_PROP_DEADLINE_LEVEL3);
+#endif
}
ret = drm_vblank_init(ddev, priv->num_crtcs);
diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
index bd001445815e..dcf2e1ebf9c5 100644
--- a/drivers/tty/sysrq.c
+++ b/drivers/tty/sysrq.c
@@ -524,7 +524,6 @@ static const struct sysrq_key_op *sysrq_key_table[62] = {
NULL, /* P */
NULL, /* Q */
NULL, /* R */
- /* S: May be registered by sched_ext for resetting */
NULL, /* S */
NULL, /* T */
NULL, /* U */
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index 3b9dde0c15c0..c0fee44f5417 100755
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -131,7 +131,7 @@
*(__dl_sched_class) \
*(__rt_sched_class) \
*(__fair_sched_class) \
- *(__ext_sched_class) \
+ *(__hmbird_sched_class) \
*(__idle_sched_class) \
__sched_class_lowest = .;
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 6991b190b8dc..39c797c5cc75 100755
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -73,7 +73,9 @@ struct task_delay_info;
struct task_group;
struct user_event_mm;
-#include <linux/sched/ext.h>
+#ifdef CONFIG_HMBIRD_SCHED
+#include <linux/sched/hmbird.h>
+#endif
/*
* Task state bitmask. NOTE! These bits are also
@@ -298,11 +300,6 @@ enum {
extern void scheduler_tick(void);
-#ifdef CONFIG_SLIM_SCHED
-extern enum hrtimer_restart scheduler_tick_no_balance(struct hrtimer *timer);
-extern void stop_shadow_tick_timer(void);
-#endif
-
#define MAX_SCHEDULE_TIMEOUT LONG_MAX
extern long schedule_timeout(long timeout);
@@ -1523,13 +1520,8 @@ struct task_struct {
*/
struct callback_head l1d_flush_kill;
#endif
-#ifdef CONFIG_SLIM_SCHED
- ANDROID_KABI_USE(1, unsigned long sched_prop);
- ANDROID_KABI_USE(2, struct sched_ext_entity *scx);
-#else
ANDROID_KABI_RESERVE(1);
ANDROID_KABI_RESERVE(2);
-#endif
ANDROID_KABI_RESERVE(3);
ANDROID_KABI_RESERVE(4);
ANDROID_KABI_RESERVE(5);
@@ -1932,6 +1924,91 @@ static inline int task_nice(const struct task_struct *p)
return PRIO_TO_NICE((p)->static_prio);
}
+#ifdef CONFIG_HMBIRD_SCHED
+static inline bool task_is_top_task(struct task_struct *p)
+{
+ return (((struct hmbird_entity *)(p->android_oem_data1[HMBIRD_TS_IDX]))
+ ->top_task_prop & TOP_TASK_BITS_MASK);
+}
+
+static inline int get_top_task_prop(struct task_struct *p)
+{
+ return get_hmbird_ts(p)->top_task_prop;
+}
+
+static inline int set_top_task_prop(struct task_struct *p, u64 set, u64 clear)
+{
+ if (set)
+ get_hmbird_ts(p)->top_task_prop |= set;
+ if (clear)
+ get_hmbird_ts(p)->top_task_prop &= ~clear;
+ return 0;
+}
+
+static inline void reset_top_task_prop(struct task_struct *p)
+{
+ get_hmbird_ts(p)->top_task_prop = 0;
+}
+
+static inline int hmbird_set_sched_prop(struct task_struct *p, unsigned long sp)
+{
+ struct hmbird_entity *entity = get_hmbird_ts(p);
+
+ if (entity) {
+ entity->sched_prop = sp;
+ }
+ return 0;
+}
+
+static inline unsigned long hmbird_get_sched_prop(struct task_struct *p)
+{
+ struct hmbird_entity *entity = get_hmbird_ts(p);
+
+ if (entity)
+ return entity->sched_prop;
+ else
+ return 0;
+}
+
+static inline void hmbird_set_dsq_id(struct task_struct *p, unsigned long dsq)
+{
+ unsigned long new_dsq;
+ struct hmbird_entity *entity = get_hmbird_ts(p);
+
+ if (entity) {
+ new_dsq = (entity->sched_prop & ~SCHED_PROP_DEADLINE_MASK) | dsq;
+ entity->sched_prop = new_dsq;
+ }
+}
+
+static inline unsigned long hmbird_get_dsq_id(struct task_struct *p)
+{
+ struct hmbird_entity *entity = get_hmbird_ts(p);
+
+ if (entity)
+ return (entity->sched_prop & SCHED_PROP_DEADLINE_MASK);
+ else
+ return 0;
+}
+
+static inline void hmbird_set_dsq_sync_ux(struct task_struct *p, int val)
+{
+ struct hmbird_entity *entity = get_hmbird_ts(p);
+
+ if (entity)
+ entity->dsq_sync_ux = val;
+}
+
+static inline int hmbird_get_dsq_sync_ux(struct task_struct *p)
+{
+ struct hmbird_entity *entity = get_hmbird_ts(p);
+
+ if (entity)
+ return entity->dsq_sync_ux;
+ else
+ return 0;
+}
+#endif
extern int can_nice(const struct task_struct *p, const int nice);
extern int task_curr(const struct task_struct *p);
diff --git a/include/linux/sched/ext.h b/include/linux/sched/ext.h
deleted file mode 100755
index b737a00c1373..000000000000
--- a/include/linux/sched/ext.h
+++ /dev/null
@@ -1,647 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-/*
- * BPF extensible scheduler class: Documentation/scheduler/sched-ext.rst
- *
- * Copyright (c) 2022 Meta Platforms, Inc. and affiliates.
- * Copyright (c) 2022 Tejun Heo <tj@kernel.org>
- * Copyright (c) 2022 David Vernet <dvernet@meta.com>
- */
-#ifndef _LINUX_SCHED_EXT_H
-#define _LINUX_SCHED_EXT_H
-
-#ifdef CONFIG_SCHED_CLASS_EXT
-
-#include <linux/llist.h>
-
-enum scx_consts {
- SCX_OPS_NAME_LEN = 128,
- SCX_EXIT_REASON_LEN = 128,
- SCX_EXIT_BT_LEN = 64,
- SCX_EXIT_MSG_LEN = 1024,
-
- SCX_SLICE_DFL = 20 * NSEC_PER_MSEC,
- SCX_SLICE_INF = U64_MAX, /* infinite, implies nohz */
-};
-
-/*
- * DSQ (dispatch queue) IDs are 64bit of the format:
- *
- * Bits: [63] [62 .. 0]
- * [ B] [ ID ]
- *
- * B: 1 for IDs for built-in DSQs, 0 for ops-created user DSQs
- * ID: 63 bit ID
- *
- * Built-in IDs:
- *
- * Bits: [63] [62] [61..32] [31 .. 0]
- * [ 1] [ L] [ R ] [ V ]
- *
- * 1: 1 for built-in DSQs.
- * L: 1 for LOCAL_ON DSQ IDs, 0 for others
- * V: For LOCAL_ON DSQ IDs, a CPU number. For others, a pre-defined value.
- */
-enum scx_dsq_id_flags {
- SCX_DSQ_FLAG_BUILTIN = 1LLU << 63,
- SCX_DSQ_FLAG_LOCAL_ON = 1LLU << 62,
-
- SCX_DSQ_INVALID = SCX_DSQ_FLAG_BUILTIN | 0,
- SCX_DSQ_GLOBAL = SCX_DSQ_FLAG_BUILTIN | 1,
- SCX_DSQ_LOCAL = SCX_DSQ_FLAG_BUILTIN | 2,
- SCX_DSQ_LOCAL_ON = SCX_DSQ_FLAG_BUILTIN | SCX_DSQ_FLAG_LOCAL_ON,
- SCX_DSQ_LOCAL_CPU_MASK = 0xffffffffLLU,
-};
-
-enum scx_exit_type {
- SCX_EXIT_NONE,
- SCX_EXIT_DONE,
-
- SCX_EXIT_UNREG = 64, /* BPF unregistration */
- SCX_EXIT_SYSRQ, /* requested by 'S' sysrq */
-
- SCX_EXIT_ERROR = 1024, /* runtime error, error msg contains details */
- SCX_EXIT_ERROR_BPF, /* ERROR but triggered through scx_bpf_error() */
- SCX_EXIT_ERROR_STALL, /* watchdog detected stalled runnable tasks */
-};
-
-/*
- * scx_exit_info is passed to ops.exit() to describe why the BPF scheduler is
- * being disabled.
- */
-struct scx_exit_info {
- /* %SCX_EXIT_* - broad category of the exit reason */
- enum scx_exit_type type;
- /* textual representation of the above */
- char reason[SCX_EXIT_REASON_LEN];
- /* number of entries in the backtrace */
- u32 bt_len;
- /* backtrace if exiting due to an error */
- unsigned long bt[SCX_EXIT_BT_LEN];
- /* extra message */
- char msg[SCX_EXIT_MSG_LEN];
-};
-
-/* sched_ext_ops.flags */
-enum scx_ops_flags {
- /*
- * Keep built-in idle tracking even if ops.update_idle() is implemented.
- */
- SCX_OPS_KEEP_BUILTIN_IDLE = 1LLU << 0,
-
- /*
- * By default, if there are no other task to run on the CPU, ext core
- * keeps running the current task even after its slice expires. If this
- * flag is specified, such tasks are passed to ops.enqueue() with
- * %SCX_ENQ_LAST. See the comment above %SCX_ENQ_LAST for more info.
- */
- SCX_OPS_ENQ_LAST = 1LLU << 1,
-
- /*
- * An exiting task may schedule after PF_EXITING is set. In such cases,
- * bpf_task_from_pid() may not be able to find the task and if the BPF
- * scheduler depends on pid lookup for dispatching, the task will be
- * lost leading to various issues including RCU grace period stalls.
- *
- * To mask this problem, by default, unhashed tasks are automatically
- * dispatched to the local DSQ on enqueue. If the BPF scheduler doesn't
- * depend on pid lookups and wants to handle these tasks directly, the
- * following flag can be used.
- */
- SCX_OPS_ENQ_EXITING = 1LLU << 2,
-
- /*
- * CPU cgroup knob enable flags
- */
- SCX_OPS_CGROUP_KNOB_WEIGHT = 1LLU << 16, /* cpu.weight */
-
- SCX_OPS_ALL_FLAGS = SCX_OPS_KEEP_BUILTIN_IDLE |
- SCX_OPS_ENQ_LAST |
- SCX_OPS_ENQ_EXITING |
- SCX_OPS_CGROUP_KNOB_WEIGHT,
-};
-
-/* argument container for ops.enable() and friends */
-struct scx_enable_args {
-};
-
-/* argument container for ops->cgroup_init() */
-struct scx_cgroup_init_args {
- /* the weight of the cgroup [1..10000] */
- u32 weight;
-};
-
-enum scx_cpu_preempt_reason {
- /* next task is being scheduled by &sched_class_rt */
- SCX_CPU_PREEMPT_RT,
- /* next task is being scheduled by &sched_class_dl */
- SCX_CPU_PREEMPT_DL,
- /* next task is being scheduled by &sched_class_stop */
- SCX_CPU_PREEMPT_STOP,
- /* unknown reason for SCX being preempted */
- SCX_CPU_PREEMPT_UNKNOWN,
-};
-
-/*
- * Argument container for ops->cpu_acquire(). Currently empty, but may be
- * expanded in the future.
- */
-struct scx_cpu_acquire_args {};
-
-/* argument container for ops->cpu_release() */
-struct scx_cpu_release_args {
- /* the reason the CPU was preempted */
- enum scx_cpu_preempt_reason reason;
-
- /* the task that's going to be scheduled on the CPU */
- struct task_struct *task;
-};
-
-/**
- * struct sched_ext_ops - Operation table for BPF scheduler implementation
- *
- * Userland can implement an arbitrary scheduling policy by implementing and
- * loading operations in this table.
- */
-struct sched_ext_ops {
- /**
- * select_cpu - Pick the target CPU for a task which is being woken up
- * @p: task being woken up
- * @prev_cpu: the cpu @p was on before sleeping
- * @wake_flags: SCX_WAKE_*
- *
- * Decision made here isn't final. @p may be moved to any CPU while it
- * is getting dispatched for execution later. However, as @p is not on
- * the rq at this point, getting the eventual execution CPU right here
- * saves a small bit of overhead down the line.
- *
- * If an idle CPU is returned, the CPU is kicked and will try to
- * dispatch. While an explicit custom mechanism can be added,
- * select_cpu() serves as the default way to wake up idle CPUs.
- */
- s32 (*select_cpu)(struct task_struct *p, s32 prev_cpu, u64 wake_flags);
-
- /**
- * enqueue - Enqueue a task on the BPF scheduler
- * @p: task being enqueued
- * @enq_flags: %SCX_ENQ_*
- *
- * @p is ready to run. Dispatch directly by calling scx_bpf_dispatch()
- * or enqueue on the BPF scheduler. If not directly dispatched, the bpf
- * scheduler owns @p and if it fails to dispatch @p, the task will
- * stall.
- */
- void (*enqueue)(struct task_struct *p, u64 enq_flags);
-
- /**
- * dequeue - Remove a task from the BPF scheduler
- * @p: task being dequeued
- * @deq_flags: %SCX_DEQ_*
- *
- * Remove @p from the BPF scheduler. This is usually called to isolate
- * the task while updating its scheduling properties (e.g. priority).
- *
- * The ext core keeps track of whether the BPF side owns a given task or
- * not and can gracefully ignore spurious dispatches from BPF side,
- * which makes it safe to not implement this method. However, depending
- * on the scheduling logic, this can lead to confusing behaviors - e.g.
- * scheduling position not being updated across a priority change.
- */
- void (*dequeue)(struct task_struct *p, u64 deq_flags);
-
- /**
- * dispatch - Dispatch tasks from the BPF scheduler and/or consume DSQs
- * @cpu: CPU to dispatch tasks for
- * @prev: previous task being switched out
- *
- * Called when a CPU's local dsq is empty. The operation should dispatch
- * one or more tasks from the BPF scheduler into the DSQs using
- * scx_bpf_dispatch() and/or consume user DSQs into the local DSQ using
- * scx_bpf_consume().
- *
- * The maximum number of times scx_bpf_dispatch() can be called without
- * an intervening scx_bpf_consume() is specified by
- * ops.dispatch_max_batch. See the comments on top of the two functions
- * for more details.
- *
- * When not %NULL, @prev is an SCX task with its slice depleted. If
- * @prev is still runnable as indicated by set %SCX_TASK_QUEUED in
- * @prev->scx.flags, it is not enqueued yet and will be enqueued after
- * ops.dispatch() returns. To keep executing @prev, return without
- * dispatching or consuming any tasks. Also see %SCX_OPS_ENQ_LAST.
- */
- void (*dispatch)(s32 cpu, struct task_struct *prev);
-
- /**
- * runnable - A task is becoming runnable on its associated CPU
- * @p: task becoming runnable
- * @enq_flags: %SCX_ENQ_*
- *
- * This and the following three functions can be used to track a task's
- * execution state transitions. A task becomes ->runnable() on a CPU,
- * and then goes through one or more ->running() and ->stopping() pairs
- * as it runs on the CPU, and eventually becomes ->quiescent() when it's
- * done running on the CPU.
- *
- * @p is becoming runnable on the CPU because it's
- *
- * - waking up (%SCX_ENQ_WAKEUP)
- * - being moved from another CPU
- * - being restored after temporarily taken off the queue for an
- * attribute change.
- *
- * This and ->enqueue() are related but not coupled. This operation
- * notifies @p's state transition and may not be followed by ->enqueue()
- * e.g. when @p is being dispatched to a remote CPU. Likewise, a task
- * may be ->enqueue()'d without being preceded by this operation e.g.
- * after exhausting its slice.
- */
- void (*runnable)(struct task_struct *p, u64 enq_flags);
-
- /**
- * running - A task is starting to run on its associated CPU
- * @p: task starting to run
- *
- * See ->runnable() for explanation on the task state notifiers.
- */
- void (*running)(struct task_struct *p);
-
- /**
- * stopping - A task is stopping execution
- * @p: task stopping to run
- * @runnable: is task @p still runnable?
- *
- * See ->runnable() for explanation on the task state notifiers. If
- * !@runnable, ->quiescent() will be invoked after this operation
- * returns.
- */
- void (*stopping)(struct task_struct *p, bool runnable);
-
- /**
- * quiescent - A task is becoming not runnable on its associated CPU
- * @p: task becoming not runnable
- * @deq_flags: %SCX_DEQ_*
- *
- * See ->runnable() for explanation on the task state notifiers.
- *
- * @p is becoming quiescent on the CPU because it's
- *
- * - sleeping (%SCX_DEQ_SLEEP)
- * - being moved to another CPU
- * - being temporarily taken off the queue for an attribute change
- * (%SCX_DEQ_SAVE)
- *
- * This and ->dequeue() are related but not coupled. This operation
- * notifies @p's state transition and may not be preceded by ->dequeue()
- * e.g. when @p is being dispatched to a remote CPU.
- */
- void (*quiescent)(struct task_struct *p, u64 deq_flags);
-
- /**
- * yield - Yield CPU
- * @from: yielding task
- * @to: optional yield target task
- *
- * If @to is NULL, @from is yielding the CPU to other runnable tasks.
- * The BPF scheduler should ensure that other available tasks are
- * dispatched before the yielding task. Return value is ignored in this
- * case.
- *
- * If @to is not-NULL, @from wants to yield the CPU to @to. If the bpf
- * scheduler can implement the request, return %true; otherwise, %false.
- */
- bool (*yield)(struct task_struct *from, struct task_struct *to);
-
- /**
- * core_sched_before - Task ordering for core-sched
- * @a: task A
- * @b: task B
- *
- * Used by core-sched to determine the ordering between two tasks. See
- * Documentation/admin-guide/hw-vuln/core-scheduling.rst for details on
- * core-sched.
- *
- * Both @a and @b are runnable and may or may not currently be queued on
- * the BPF scheduler. Should return %true if @a should run before @b.
- * %false if there's no required ordering or @b should run before @a.
- *
- * If not specified, the default is ordering them according to when they
- * became runnable.
- */
- bool (*core_sched_before)(struct task_struct *a,struct task_struct *b);
-
- /**
- * set_weight - Set task weight
- * @p: task to set weight for
- * @weight: new eight [1..10000]
- *
- * Update @p's weight to @weight.
- */
- void (*set_weight)(struct task_struct *p, u32 weight);
-
- /**
- * set_cpumask - Set CPU affinity
- * @p: task to set CPU affinity for
- * @cpumask: cpumask of cpus that @p can run on
- *
- * Update @p's CPU affinity to @cpumask.
- */
- void (*set_cpumask)(struct task_struct *p, struct cpumask *cpumask);
-
- /**
- * update_idle - Update the idle state of a CPU
- * @cpu: CPU to udpate the idle state for
- * @idle: whether entering or exiting the idle state
- *
- * This operation is called when @rq's CPU goes or leaves the idle
- * state. By default, implementing this operation disables the built-in
- * idle CPU tracking and the following helpers become unavailable:
- *
- * - scx_bpf_select_cpu_dfl()
- * - scx_bpf_test_and_clear_cpu_idle()
- * - scx_bpf_pick_idle_cpu()
- * - scx_bpf_any_idle_cpu()
- *
- * The user also must implement ops.select_cpu() as the default
- * implementation relies on scx_bpf_select_cpu_dfl().
- *
- * If you keep the built-in idle tracking, specify the
- * %SCX_OPS_KEEP_BUILTIN_IDLE flag.
- */
- void (*update_idle)(s32 cpu, bool idle);
-
- /**
- * cpu_acquire - A CPU is becoming available to the BPF scheduler
- * @cpu: The CPU being acquired by the BPF scheduler.
- * @args: Acquire arguments, see the struct definition.
- *
- * A CPU that was previously released from the BPF scheduler is now once
- * again under its control.
- */
- void (*cpu_acquire)(s32 cpu, struct scx_cpu_acquire_args *args);
-
- /**
- * cpu_release - A CPU is taken away from the BPF scheduler
- * @cpu: The CPU being released by the BPF scheduler.
- * @args: Release arguments, see the struct definition.
- *
- * The specified CPU is no longer under the control of the BPF
- * scheduler. This could be because it was preempted by a higher
- * priority sched_class, though there may be other reasons as well. The
- * caller should consult @args->reason to determine the cause.
- */
- void (*cpu_release)(s32 cpu, struct scx_cpu_release_args *args);
-
- /**
- * cpu_online - A CPU became online
- * @cpu: CPU which just came up
- *
- * @cpu just came online. @cpu doesn't call ops.enqueue() or run tasks
- * associated with other CPUs beforehand.
- */
- void (*cpu_online)(s32 cpu);
-
- /**
- * cpu_offline - A CPU is going offline
- * @cpu: CPU which is going offline
- *
- * @cpu is going offline. @cpu doesn't call ops.enqueue() or run tasks
- * associated with other CPUs afterwards.
- */
- void (*cpu_offline)(s32 cpu);
-
- /**
- * prep_enable - Prepare to enable BPF scheduling for a task
- * @p: task to prepare BPF scheduling for
- * @args: enable arguments, see the struct definition
- *
- * Either we're loading a BPF scheduler or a new task is being forked.
- * Prepare BPF scheduling for @p. This operation may block and can be
- * used for allocations.
- *
- * Return 0 for success, -errno for failure. An error return while
- * loading will abort loading of the BPF scheduler. During a fork, will
- * abort the specific fork.
- */
- s32 (*prep_enable)(struct task_struct *p, struct scx_enable_args *args);
-
- /**
- * enable - Enable BPF scheduling for a task
- * @p: task to enable BPF scheduling for
- * @args: enable arguments, see the struct definition
- *
- * Enable @p for BPF scheduling. @p is now in the cgroup specified for
- * the preceding prep_enable() and will start running soon.
- */
- void (*enable)(struct task_struct *p, struct scx_enable_args *args);
-
- /**
- * cancel_enable - Cancel prep_enable()
- * @p: task being canceled
- * @args: enable arguments, see the struct definition
- *
- * @p was prep_enable()'d but failed before reaching enable(). Undo the
- * preparation.
- */
- void (*cancel_enable)(struct task_struct *p,
- struct scx_enable_args *args);
-
- /**
- * disable - Disable BPF scheduling for a task
- * @p: task to disable BPF scheduling for
- *
- * @p is exiting, leaving SCX or the BPF scheduler is being unloaded.
- * Disable BPF scheduling for @p.
- */
- void (*disable)(struct task_struct *p);
-
- /*
- * All online ops must come before ops.init().
- */
-
- /**
- * init - Initialize the BPF scheduler
- */
- s32 (*init)(void);
-
- /**
- * exit - Clean up after the BPF scheduler
- * @info: Exit info
- */
- void (*exit)(struct scx_exit_info *info);
-
- /**
- * dispatch_max_batch - Max nr of tasks that dispatch() can dispatch
- */
- u32 dispatch_max_batch;
-
- /**
- * flags - %SCX_OPS_* flags
- */
- u64 flags;
-
- /**
- * timeout_ms - The maximum amount of time, in milliseconds, that a
- * runnable task should be able to wait before being scheduled. The
- * maximum timeout may not exceed the default timeout of 30 seconds.
- *
- * Defaults to the maximum allowed timeout value of 30 seconds.
- */
- u32 timeout_ms;
-
- /**
- * name - BPF scheduler's name
- *
- * Must be a non-zero valid BPF object name including only isalnum(),
- * '_' and '.' chars. Shows up in kernel.sched_ext_ops sysctl while the
- * BPF scheduler is enabled.
- */
- char name[SCX_OPS_NAME_LEN];
-};
-
-/*
- * Dispatch queue (dsq) is a simple FIFO which is used to buffer between the
- * scheduler core and the BPF scheduler. See the documentation for more details.
- */
-struct scx_dispatch_q {
- raw_spinlock_t lock;
- struct list_head fifo; /* processed in dispatching order */
- struct rb_root_cached priq; /* processed in p->scx.dsq_vtime order */
- u32 nr;
- u64 id;
- struct llist_node free_node;
- struct rcu_head rcu;
-};
-
-/* scx_entity.flags */
-enum scx_ent_flags {
- SCX_TASK_QUEUED = 1 << 0, /* on ext runqueue */
- SCX_TASK_BAL_KEEP = 1 << 1, /* balance decided to keep current */
- SCX_TASK_ENQ_LOCAL = 1 << 2, /* used by scx_select_cpu_dfl() to set SCX_ENQ_LOCAL */
-
- SCX_TASK_OPS_PREPPED = 1 << 8, /* prepared for BPF scheduler enable */
- SCX_TASK_OPS_ENABLED = 1 << 9, /* task has BPF scheduler enabled */
-
- SCX_TASK_WATCHDOG_RESET = 1 << 16, /* task watchdog counter should be reset */
- SCX_TASK_DEQD_FOR_SLEEP = 1 << 17, /* last dequeue was for SLEEP */