-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathfengchi_oneplus_pad_3.patch
More file actions
9137 lines (9064 loc) · 250 KB
/
fengchi_oneplus_pad_3.patch
File metadata and controls
9137 lines (9064 loc) · 250 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/arch/arm64/configs/defconfig b/arch/arm64/configs/defconfig
index 60af93c04b45..5ba590235a8c 100644
--- a/arch/arm64/configs/defconfig
+++ b/arch/arm64/configs/defconfig
@@ -6,6 +6,7 @@ CONFIG_HIGH_RES_TIMERS=y
CONFIG_BPF_SYSCALL=y
CONFIG_BPF_JIT=y
CONFIG_PREEMPT=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 bebb76e87e97..a0c91fd40bf6 100644
--- a/arch/arm64/configs/gki_defconfig
+++ b/arch/arm64/configs/gki_defconfig
@@ -10,6 +10,7 @@ CONFIG_BPF_JIT_ALWAYS_ON=y
# CONFIG_BPF_UNPRIV_DEFAULT_OFF is not set
CONFIG_BPF_LSM=y
CONFIG_PREEMPT=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/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index 63029bc7c9dd..c0fee44f5417 100755
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -131,6 +131,7 @@
*(__dl_sched_class) \
*(__rt_sched_class) \
*(__fair_sched_class) \
+ *(__hmbird_sched_class) \
*(__idle_sched_class) \
__sched_class_lowest = .;
diff --git a/include/linux/sched.h b/include/linux/sched.h
index c2fb5603e211..39c797c5cc75 100755
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -73,6 +73,9 @@ struct task_delay_info;
struct task_group;
struct user_event_mm;
+#ifdef CONFIG_HMBIRD_SCHED
+#include <linux/sched/hmbird.h>
+#endif
/*
* Task state bitmask. NOTE! These bits are also
@@ -1921,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/hmbird.h b/include/linux/sched/hmbird.h
new file mode 100755
index 000000000000..3c7861e37ade
--- /dev/null
+++ b/include/linux/sched/hmbird.h
@@ -0,0 +1,381 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * HMBIRD scheduler class: Documentation/scheduler/hmbird.rst
+ *
+ * Copyright (c) 2024 OPlus.
+ * Copyright (c) 2024 Dao Huang
+ * Copyright (c) 2024 Yuxing Wang
+ * Copyright (c) 2024 Taiyu Li
+ */
+#ifndef _LINUX_SCHED_HMBIRD_H
+#define _LINUX_SCHED_HMBIRD_H
+
+#define HMBIRD_TS_IDX 1
+#define HMBIRD_OPS_IDX 14
+#define HMBIRD_RQ_IDX 15
+
+#define get_hmbird_ts(p) \
+ ((struct hmbird_entity *)(p->android_oem_data1[HMBIRD_TS_IDX]))
+
+#define get_hmbird_rq(rq) \
+ ((struct hmbird_rq *)(rq->android_oem_data1[HMBIRD_RQ_IDX]))
+
+#define get_hmbird_ops(rq) \
+ ((struct hmbird_ops *)(rq->android_oem_data1[HMBIRD_OPS_IDX]))
+
+#define SCHED_PROP_DEADLINE_MASK (0xFF) /* deadline for ext sched class */
+/*
+ * Every task has a DEADLINE_LEVEL which stands for
+ * max schedule latency this task can afford. LEVEL1~5
+ * for user-aware tasks, LEVEL6~9 for other tasks.
+ */
+#define SCHED_PROP_DEADLINE_LEVEL0 (0)
+#define SCHED_PROP_DEADLINE_LEVEL1 (1)
+#define SCHED_PROP_DEADLINE_LEVEL2 (2)
+#define SCHED_PROP_DEADLINE_LEVEL3 (3)
+#define SCHED_PROP_DEADLINE_LEVEL4 (4)
+#define SCHED_PROP_DEADLINE_LEVEL5 (5)
+#define SCHED_PROP_DEADLINE_LEVEL6 (6)
+#define SCHED_PROP_DEADLINE_LEVEL7 (7)
+#define SCHED_PROP_DEADLINE_LEVEL8 (8)
+#define SCHED_PROP_DEADLINE_LEVEL9 (9)
+/*
+ * Distinguish tasks into periodical tasks which requires
+ * low schedule latency and non-periodical tasks which are
+ * not sensitive to schedule latency.
+ */
+#define SCHED_HMBIRD_DSQ_TYPE_PERIOD (0) /* period dsq of hmbird */
+#define SCHED_HMBIRD_DSQ_TYPE_NON_PERIOD (1) /* non period dsq of hmbird */
+
+#define TOP_TASK_BITS_MASK (0xFF)
+#define TOP_TASK_BITS (8)
+#include <linux/llist.h>
+
+extern atomic_t non_hmbird_task;
+extern atomic_t __hmbird_ops_enabled;
+#define hmbird_enabled() atomic_read(&__hmbird_ops_enabled)
+#define MAX_GLOBAL_DSQS (10)
+
+enum hmbird_consts {
+ HMBIRD_SLICE_DFL = 1 * NSEC_PER_MSEC,
+ HMBIRD_SLICE_ISO = 8 * HMBIRD_SLICE_DFL,
+ HMBIRD_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 hmbird_dsq_id_flags {
+ HMBIRD_DSQ_FLAG_BUILTIN = 1LLU << 63,
+ HMBIRD_DSQ_FLAG_LOCAL_ON = 1LLU << 62,
+
+ HMBIRD_DSQ_INVALID = HMBIRD_DSQ_FLAG_BUILTIN | 0,
+ HMBIRD_DSQ_GLOBAL = HMBIRD_DSQ_FLAG_BUILTIN | 1,
+ HMBIRD_DSQ_LOCAL = HMBIRD_DSQ_FLAG_BUILTIN | 2,
+ HMBIRD_DSQ_LOCAL_ON = HMBIRD_DSQ_FLAG_BUILTIN | HMBIRD_DSQ_FLAG_LOCAL_ON,
+ HMBIRD_DSQ_LOCAL_CPU_MASK = 0xffffffffLLU,
+};
+
+enum hmbird_switch_type {
+ HMBIRD_SWITCH_PROC,
+ HMBIRD_SWITCH_ERR_WDT,
+ HMBIRD_SWITCH_ERR_HB,
+ HMBIRD_SWITCH_ERR_DSQ,
+ HMBIRD_EXIT_ERROR_STALL, /* watchdog detected stalled runnable tasks */
+ HMBIRD_EXIT_ERROR_HEARTBEAT, /* heart beat has stopped */
+};
+
+/*
+ * 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 hmbird_dispatch_q {
+ raw_spinlock_t lock;
+ struct list_head fifo; /* processed in dispatching order */
+ struct rb_root_cached priq;
+ u32 nr;
+ u64 id;
+ struct llist_node free_node;
+ struct rcu_head rcu;
+ u64 last_consume_at;
+ bool is_timeout;
+};
+
+/* hmbird_entity.flags */
+enum hmbird_ent_flags {
+ HMBIRD_TASK_QUEUED = 1 << 0, /* on hmbird runqueue */
+ HMBIRD_TASK_BAL_KEEP = 1 << 1, /* balance decided to keep current */
+ HMBIRD_TASK_ENQ_LOCAL = 1 << 2, /* used by hmbird_select_cpu_dfl, set HMBIRD_ENQ_LOCAL */
+
+ HMBIRD_TASK_OPS_PREPPED = 1 << 8, /* prepared for BPF scheduler enable */
+ HMBIRD_TASK_OPS_ENABLED = 1 << 9, /* task has BPF scheduler enabled */
+
+ HMBIRD_TASK_WATCHDOG_RESET = 1 << 16, /* task watchdog counter should be reset */
+ HMBIRD_TASK_DEQD_FOR_SLEEP = 1 << 17, /* last dequeue was for SLEEP */
+
+ HMBIRD_TASK_CURSOR = 1 << 31, /* iteration cursor, not a task */
+};
+
+/* hmbird_entity.dsq_flags */
+enum hmbird_ent_dsq_flags {
+ HMBIRD_TASK_DSQ_ON_PRIQ = 1 << 0, /* task is queued on the priority queue of a dsq */
+};
+
+#define RAVG_HIST_SIZE 5
+struct hmbird_sched_task_stats {
+ u64 mark_start;
+ u64 window_start;
+ u32 sum;
+ u32 sum_history[RAVG_HIST_SIZE];
+ int cidx;
+
+ u32 demand;
+ u16 demand_scaled;
+ void *sdsq;
+};
+
+struct hmbird_sched_rq_stats {
+ u64 window_start;
+ u64 latest_clock;
+ u32 prev_window_size;
+ u64 task_exec_scale;
+ u64 prev_runnable_sum;
+ u64 curr_runnable_sum;
+ int *sched_ravg_window_ptr;
+};
+
+/*
+ * The following is embedded in task_struct and contains all fields necessary
+ * for a task to be scheduled by HMBIRD.
+ */
+struct hmbird_entity {
+ struct hmbird_dispatch_q *dsq;
+ struct {
+ struct list_head fifo; /* dispatch order */
+ struct rb_node priq;
+ } dsq_node;
+ struct list_head watchdog_node;
+ u32 flags; /* protected by rq lock */
+ u32 dsq_flags; /* protected by dsq lock */
+ u32 weight;
+ s32 sticky_cpu;
+ s32 holding_cpu;
+ u32 kf_mask; /* see hmbird_kf_mask above */
+ struct task_struct *kf_tasks[2]; /* see HMBIRD_CALL_OP_TASK() */
+ atomic64_t ops_state;
+ unsigned long runnable_at;
+ u64 slice;
+ u64 dsq_vtime;
+ bool disallow; /* reject switching into HMBIRD */
+ u16 demand_scaled;
+
+ /* cold fields */
+ struct list_head tasks_node;
+ struct task_struct *task;
+ const struct sched_class *sched_class;
+ unsigned long sched_prop;
+ unsigned long top_task_prop;
+ struct hmbird_sched_task_stats sts;
+ unsigned long running_at;
+ int gdsq_idx;
+
+ s32 critical_affinity_cpu;
+ int dsq_sync_ux;
+};
+
+
+/*
+ * All variables use 64bits width,
+ * Avoid parsing problems caused by automatic alignment(with padding) of structures.
+ */
+
+/* NOTING : Must align to 64bits. */
+#define DESC_STR_LEN (32)
+/* Supporti up to three-dimensional arrays. */
+#define PARSE_DIMENS (3)
+struct meta_desc_t {
+ char desc_str[DESC_STR_LEN];
+ u64 len;
+ u64 parse[PARSE_DIMENS];
+};
+
+#define MAX_SWITCHS (5)
+struct hmbird_switch_t {
+ u64 switch_at;
+ u64 is_success;
+ u64 end_state;
+ u64 switch_reason;
+};
+#define SWITCH_ITEMS (sizeof(struct hmbird_switch_t) / sizeof(u64))
+
+#define MAX_EXCEPS (5)
+enum excep_id {
+ NO_CGROUP_L1,
+ MODULE_UNLOAD,
+ ALREADY_ENABLED,
+ ALREADY_DISABLED,
+ INIT_TASK_FAIL,
+ ALLOC_RQSCX_FAIL,
+ DSQ_ID_ERR,
+ CPU_NO_MASK,
+ SCAN_ENTITY_NULL,
+ ITER_RET_NULL,
+ DEQ_DEQING,
+ ENQ_EXIST1,
+ ENQ_EXIST2,
+ TASK_LINKED1,
+ TASK_UNLINKED,
+ TASK_LINKED2,
+ TASK_UNQUED,
+ TASK_UNWATCHED,
+ HMBIRD_OPN,
+ TASK_WATCHED,
+ RQ_NO_RUNNING,
+ EXTRA_FLAGS,
+ HOLDING_CPU1,
+ HOLDING_CPU2,
+ TASK_OPS_PREPPED,
+ TASK_OPS_UNPREPPED,
+ HMBIRD_OPS_ERR,
+ MAX_EXCEP_ID,
+};
+
+struct snap_misc_t {
+ u64 hmbird_enabled;
+ u64 curr_ss;
+ u64 hmbird_ops_enable_state_var;
+ u64 non_ext_task;
+ u64 parctrl_high_ratio;
+ u64 parctrl_low_ratio;
+ u64 parctrl_high_ratio_l;
+ u64 parctrl_low_ratio_l;
+ u64 isoctrl_high_ratio;
+ u64 isoctrl_low_ratio;
+ u64 misfit_ds;
+ u64 partial_enable;
+ u64 iso_free_rescue;
+ u64 isolate_ctrl;
+ u64 snap_jiffies;
+ u64 snap_time;
+};
+#define SNAP_ITEMS (sizeof(struct snap_misc_t) / sizeof(u64))
+
+struct panic_snapshot_t {
+ /* what time dose the first task of dsq turn in runnable, check starvation */
+ struct meta_desc_t runnable_at_meta;
+ u64 runnable_at[MAX_GLOBAL_DSQS];
+
+ struct meta_desc_t rq_nr_meta;
+ u64 rq_nr[NR_CPUS];
+
+ struct meta_desc_t scxrq_nr_meta;
+ u64 scxrq_nr[NR_CPUS];
+
+ struct meta_desc_t snap_misc_meta;
+ struct snap_misc_t snap_misc;
+};
+
+/*
+ * Do not record info in hot paths unless absolutely necessary,
+ * The impact on performance should be minimized.
+ */
+struct kernel_info_t {
+ struct meta_desc_t sw_rec_meta;
+ struct hmbird_switch_t sw_rec[MAX_SWITCHS];
+
+ struct meta_desc_t sw_idx_meta;
+ u64 sw_idx;
+
+ struct meta_desc_t excep_rec_meta;
+ u64 excep_rec[MAX_EXCEP_ID][MAX_EXCEPS];
+
+ struct meta_desc_t excep_idx_meta;
+ u64 excep_idx[MAX_EXCEP_ID];
+
+ /* snapshot while panic. */
+ struct panic_snapshot_t snap;
+};
+
+struct ko_info_t {};
+
+struct md_meta_t {
+ u64 self_len;
+ u64 unit_size;
+ u64 desc_meta_len;
+ u64 desc_str_len;
+ u64 switches;
+ u64 exceps;
+ u64 global_dsqs;
+ u64 parse_dimens;
+ u64 nr_cpus;
+ u64 real_cpus;
+ u64 nr_meta_desc;
+ u64 dump_real_size;
+};
+
+struct md_info_t {
+ struct md_meta_t meta;
+ struct kernel_info_t kern_dump;
+ struct ko_info_t ko_dump;
+};
+
+static inline void exceps_update(struct md_info_t *rec, int id, unsigned long jiffies)
+{
+ u64 *idx;
+
+ if (!rec)
+ return;
+
+ idx = &rec->kern_dump.excep_idx[id];
+ rec->kern_dump.excep_rec[id][*idx] = jiffies;
+ *idx = ++(*idx) % MAX_EXCEPS;
+}
+
+static inline void sw_update(struct md_info_t *rec, u64 switch_at,
+ u64 is_success, u64 end_state, u64 switch_reason)
+{
+ u64 *idx;
+
+ if (!rec)
+ return;
+
+ idx = &rec->kern_dump.sw_idx;
+ rec->kern_dump.sw_rec[*idx].switch_at = switch_at;
+ rec->kern_dump.sw_rec[*idx].is_success = is_success;
+ rec->kern_dump.sw_rec[*idx].end_state = end_state;
+ rec->kern_dump.sw_rec[*idx].switch_reason = switch_reason;
+ *idx = ++(*idx) % MAX_SWITCHS;
+}
+
+struct hmbird_ops {
+ bool (*scx_enable)(void);
+ bool (*check_non_task)(void);
+ void (*do_sched_yield_before)(long *skip);
+ void (*window_rollover_run_once)(struct rq *rq);
+ void (*hmbird_get_md_info)(unsigned long *vaddr, unsigned long *size);
+};
+
+void hmbird_free(struct task_struct *p);
+
+enum DSQ_SYNC_UX_FLAG {
+ DSQ_SYNC_UX_NONE = 0,
+ DSQ_SYNC_STATIC_UX = 1,
+ DSQ_SYNC_INHERIT_UX = 1 << 1,
+};
+
+#endif /* _LINUX_SCHED_HMBIRD_H */
diff --git a/include/linux/sched/hmbird_proc_val.h b/include/linux/sched/hmbird_proc_val.h
new file mode 100755
index 000000000000..e59708b16ea3
--- /dev/null
+++ b/include/linux/sched/hmbird_proc_val.h
@@ -0,0 +1,22 @@
+#ifndef __HMBORD_PROC_VAL_H__
+#define __HMBORD_PROC_VAL_H__
+
+extern int scx_enable;
+extern int partial_enable;
+extern int cpuctrl_high_ratio;
+extern int cpuctrl_low_ratio;
+extern int slim_stats;
+extern int hmbirdcore_debug;
+extern int slim_for_app;
+extern int misfit_ds;
+extern unsigned int highres_tick_ctrl;
+extern unsigned int highres_tick_ctrl_dbg;
+extern int cpu7_tl;
+extern int slim_walt_ctrl;
+extern int slim_walt_dump;
+extern int slim_walt_policy;
+extern int slim_gov_debug;
+extern int scx_gov_ctrl;
+extern int sched_ravg_window_frame_per_sec;
+
+#endif
\ No newline at end of file
diff --git a/include/linux/sched/hmbird_version.h b/include/linux/sched/hmbird_version.h
new file mode 100755
index 000000000000..b2843881c26f
--- /dev/null
+++ b/include/linux/sched/hmbird_version.h
@@ -0,0 +1,52 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2024 Oplus. All rights reserved.
+ */
+
+#ifndef _OPLUS_HMBIRD_VERSION_H_
+#define _OPLUS_HMBIRD_VERSION_H_
+#include <linux/of.h>
+#include <linux/string.h>
+#include <linux/printk.h>
+
+enum hmbird_version {
+ HMBIRD_UNINIT,
+ HMBIRD_GKI_VERSION,
+ HMBIRD_OGKI_VERSION,
+ HMBIRD_UNKNOW_VERSION,
+};
+
+static enum hmbird_version hmbird_version_type = HMBIRD_UNINIT;
+
+#define HMBIRD_VERSION_TYPE_CONFIG_PATH "/soc/oplus,hmbird/version_type"
+
+static inline enum hmbird_version get_hmbird_version_type(void)
+{
+ struct device_node *np = NULL;
+ const char *hmbird_version_str = NULL;
+ if (HMBIRD_UNINIT != hmbird_version_type)
+ return hmbird_version_type;
+ np = of_find_node_by_path(HMBIRD_VERSION_TYPE_CONFIG_PATH);
+ if (np) {
+ of_property_read_string(np, "type", &hmbird_version_str);
+ if (NULL != hmbird_version_str) {
+ if (strncmp(hmbird_version_str, "HMBIRD_OGKI", strlen("HMBIRD_OGKI")) == 0) {
+ hmbird_version_type = HMBIRD_OGKI_VERSION;
+ pr_debug("hmbird version use HMBIRD_OGKI_VERSION, set by dtsi");
+ } else if (strncmp(hmbird_version_str, "HMBIRD_GKI", strlen("HMBIRD_GKI")) == 0) {
+ hmbird_version_type = HMBIRD_GKI_VERSION;
+ pr_debug("hmbird version use HMBIRD_GKI_VERSION, set by dtsi");
+ } else {
+ hmbird_version_type = HMBIRD_UNKNOW_VERSION;
+ pr_debug("hmbird version use default HMBIRD_UNKNOW_VERSION, set by dtsi");
+ }
+ return hmbird_version_type;
+ }
+ }
+
+ hmbird_version_type = HMBIRD_UNKNOW_VERSION;
+ pr_debug("hmbird version use default HMBIRD_UNKNOW_VERSION");
+ return hmbird_version_type;
+}
+
+#endif /*_OPLUS_HMBIRD_VERSION_H_ */
diff --git a/include/linux/sched/sa_common.h b/include/linux/sched/sa_common.h
new file mode 100755
index 000000000000..6f76d7cfd7bf
--- /dev/null
+++ b/include/linux/sched/sa_common.h
@@ -0,0 +1,797 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2020-2022 Oplus. All rights reserved.
+ */
+
+
+#ifndef _OPLUS_SA_COMMON_H_
+#define _OPLUS_SA_COMMON_H_
+
+#include <linux/sched.h>
+#include <linux/list.h>
+#include <linux/types.h>
+#include <linux/atomic.h>
+#include <linux/hashtable.h>
+#include <linux/cgroup-defs.h>
+#if IS_ENABLED(CONFIG_SCHED_WALT)
+#include <linux/sched/walt.h>
+#endif
+#include <linux/vmalloc.h>
+#include <linux/mm.h>
+#include <linux/slab.h>
+#include <linux/version.h>
+#include <linux/sched/rt.h>
+
+#include "sa_oemdata.h"
+#include "sa_common_struct.h"
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
+#define OPLUS_UX_EEVDF_COMPATIBLE 1
+#endif
+
+#define SA_DEBUG_ON 0
+
+#if (SA_DEBUG_ON >= 1)
+#define DEBUG_BUG_ON(x) BUG_ON(x)
+#define DEBUG_WARN_ON(x) WARN_ON(x)
+#else
+#define DEBUG_BUG_ON(x)
+#define DEBUG_WARN_ON(x)
+#endif
+
+#define ux_err(fmt, ...) \
+ pr_err("[sched_assist][%s]"fmt, __func__, ##__VA_ARGS__)
+#define ux_warn(fmt, ...) \
+ pr_warn("[sched_assist][%s]"fmt, __func__, ##__VA_ARGS__)
+#define ux_debug(fmt, ...) \
+ pr_info("[sched_assist][%s]"fmt, __func__, ##__VA_ARGS__)
+
+#define UX_MSG_LEN 64
+#define UX_DEPTH_MAX 5
+
+/* define for debug */
+#define DEBUG_SYSTRACE (1 << 0)
+#define DEBUG_FTRACE (1 << 1)
+#define DEBUG_KMSG (1 << 2) /* used for frameboost */
+#define DEBUG_PIPELINE (1 << 3)
+#define DEBUG_DYNAMIC_HZ (1 << 4)
+#define DEBUG_DYNAMIC_PREEMPT (1 << 5)
+#define DEBUG_AMU_INSTRUCTION (1 << 6)
+#define DEBUG_VERBOSE (1 << 10) /* used for frameboost */
+#define DEBUG_SET_DSQ_ID (1 << 11) /* used for hmbird */
+
+/* define for sched assist feature */
+#define FEATURE_COMMON (1 << 0)
+#define FEATURE_SPREAD (1 << 1)
+
+#define UX_EXEC_SLICE (4000000U)
+
+/* define for sched assist thread type, keep same as the define in java file */
+#define SA_OPT_CLEAR (0)
+#define SA_TYPE_LIGHT (1 << 0)
+#define SA_TYPE_HEAVY (1 << 1)
+#define SA_TYPE_ANIMATOR (1 << 2)
+/* SA_TYPE_LISTPICK for camera */
+#define SA_TYPE_LISTPICK (1 << 3)
+#define SA_TYPE_MQ_VIP (1 << 4)
+#define SA_OPT_SET (1 << 7)
+#define SA_OPT_RESET (1 << 8)
+#define SA_OPT_SET_PRIORITY (1 << 9)
+
+/* The following ux value only used in kernel */
+#define SA_TYPE_SWIFT (1 << 14)
+/* clear ux type when dequeue */
+#define SA_TYPE_ONCE (1 << 15)
+#define SA_TYPE_INHERIT (1 << 16)
+/* SA_TYPE_COMBINED isn't marked in ux_state, it only exists in return value of function */
+#define SA_TYPE_COMBINED (1 << 17)
+#define SA_TYPE_URGENT_MASK (SA_TYPE_LIGHT|SA_TYPE_ANIMATOR|SA_TYPE_SWIFT)
+#define SCHED_ASSIST_UX_MASK (SA_TYPE_LIGHT|SA_TYPE_HEAVY|SA_TYPE_ANIMATOR|SA_TYPE_LISTPICK|SA_TYPE_SWIFT)
+
+/* load balance operation is performed on the following ux types */
+#define SCHED_ASSIST_LB_UX (SA_TYPE_SWIFT | SA_TYPE_ANIMATOR | SA_TYPE_LIGHT | SA_TYPE_HEAVY)
+#define POSSIBLE_UX_MASK (SA_TYPE_SWIFT | \
+ SA_TYPE_LIGHT | \
+ SA_TYPE_HEAVY | \
+ SA_TYPE_ANIMATOR | \
+ SA_TYPE_LISTPICK | \
+ SA_TYPE_ONCE | \
+ SA_TYPE_INHERIT)
+
+#define SCHED_ASSIST_UX_PRIORITY_MASK (0xFF000000)
+#define SCHED_ASSIST_UX_PRIORITY_SHIFT 24
+
+#define UX_PRIORITY_TOP_APP 0x0A000000
+#define UX_PRIORITY_AUDIO 0x0A000000
+#if IS_ENABLED(CONFIG_OPLUS_FEATURE_PIPELINE)
+#define UX_PRIORITY_PIPELINE_UI 0x06000000
+#define UX_PRIORITY_PIPELINE 0x05000000
+#endif
+
+/* define for sched assist scene type, keep same as the define in java file */
+#define SA_SCENE_OPT_CLEAR (0)
+#define SA_LAUNCH (1 << 0)
+#define SA_SLIDE (1 << 1)
+#define SA_CAMERA (1 << 2)
+#define SA_ANIM_START (1 << 3) /* we care about both launcher and top app */
+#define SA_ANIM (1 << 4) /* we only care about launcher */
+#define SA_INPUT (1 << 5)
+#define SA_LAUNCHER_SI (1 << 6)
+#define SA_SCENE_OPT_SET (1 << 7)
+
+#define ROOT_UID 0
+#define SYSTEM_UID 1000
+#define FIRST_APPLICATION_UID 10000
+#define LAST_APPLICATION_UID 19999
+#define PER_USER_RANGE 100000
+/* define for clear IM_FLAG
+if im_flag is 70, it should clear im_flag_audio (70 - 64 = 6)
+eg: gerrit patchset "30438485"
+ */
+#define IM_FLAG_CLEAR 64
+
+extern pid_t save_audio_tgid;
+extern pid_t save_top_app_tgid;
+extern unsigned int top_app_type;
+extern int global_lowend_plat_opt;
+
+#ifdef CONFIG_OPLUS_SCHED_HALT_MASK_PRT
+/* This must be the same as the definition of pause_type in walt_halt.c */
+enum oplus_pause_type {
+ OPLUS_HALT,
+ OPLUS_PARTIAL_HALT,
+
+ OPLUS_MAX_PAUSE_TYPE
+};
+extern cpumask_t cur_cpus_halt_mask;
+extern cpumask_t cur_cpus_phalt_mask;
+DECLARE_PER_CPU(int[OPLUS_MAX_PAUSE_TYPE], oplus_cur_pause_client);
+extern void sa_corectl_systrace_c(void);
+#endif /* CONFIG_OPLUS_SCHED_HALT_MASK_PRT */
+
+/* define for boost threshold unit */
+#define BOOST_THRESHOLD_UNIT (51)
+
+
+enum UX_STATE_TYPE {
+ UX_STATE_INVALID = 0,
+ UX_STATE_NONE,
+ UX_STATE_STATIC,
+ UX_STATE_INHERIT,
+ UX_STATE_COMBINED,
+ MAX_UX_STATE_TYPE,
+};
+
+enum INHERIT_UX_TYPE {
+ INHERIT_UX_BINDER = 0,
+ INHERIT_UX_RWSEM,
+ INHERIT_UX_MUTEX,
+ INHERIT_UX_FUTEX,
+ INHERIT_UX_PIFUTEX,
+ INHERIT_UX_MAX,
+};
+
+/*
+ * WANNING:
+ * new flag should be add before MAX_IM_FLAG_TYPE, never change
+ * the value of those existed flag type.
+ */
+enum IM_FLAG_TYPE {
+ IM_FLAG_NONE = 0,
+ IM_FLAG_SURFACEFLINGER,
+ IM_FLAG_HWC, /* Discarded */
+ IM_FLAG_RENDERENGINE,
+ IM_FLAG_WEBVIEW,
+ IM_FLAG_CAMERA_HAL,
+ IM_FLAG_AUDIO,
+ IM_FLAG_HWBINDER,
+ IM_FLAG_LAUNCHER,
+ IM_FLAG_LAUNCHER_NON_UX_RENDER,
+ IM_FLAG_SS_LOCK_OWNER,
+ IM_FLAG_FORBID_SET_CPU_AFFINITY = 11, /* forbid setting cpu affinity from app */
+ IM_FLAG_SYSTEMSERVER_PID,
+ IM_FLAG_MIDASD,
+ IM_FLAG_AUDIO_CAMERA_HAL, /* audio mode disable camera hal ux */
+ IM_FLAG_AFFINITY_THREAD,
+ IM_FLAG_TPD_SET_CPU_AFFINITY = 16,
+ IM_FLAG_COMPRESS_THREAD = 17, /* compress thread skips locking protect */
+ IM_FLAG_RENDER_THREAD = 18,
+ MAX_IM_FLAG_TYPE,
+};
+
+#define MAX_IM_FLAG_PRIO MAX_IM_FLAG_TYPE
+
+enum ots_state {
+ OTS_STATE_SET_AFFINITY,
+ OTS_STATE_DDL_ACTIVE,
+ OTS_STATE_DDL_ACTIVE_PREEMPTED,
+ OTS_STATE_MAX,
+};
+
+#ifdef CONFIG_OPLUS_FEATURE_TICK_GRAN
+DECLARE_PER_CPU(u64, retired_instrs);
+DECLARE_PER_CPU(u64, nvcsw);
+DECLARE_PER_CPU(u64, nivcsw);
+#endif
+
+struct ux_sched_cluster {
+ struct cpumask cpus;
+ unsigned long capacity;
+};
+
+#define OPLUS_NR_CPUS (8)
+#define OPLUS_MAX_CLS (5)
+struct ux_sched_cputopo {
+ int cls_nr;
+ struct ux_sched_cluster sched_cls[OPLUS_NR_CPUS];
+
+#if IS_ENABLED(CONFIG_OPLUS_FEATURE_LOADBALANCE)
+ cpumask_t oplus_cpu_array[2*OPLUS_MAX_CLS][OPLUS_MAX_CLS];
+#endif
+};
+
+struct oplus_rq {
+ /* CONFIG_OPLUS_FEATURE_SCHED_ASSIST */
+ struct rb_root_cached ux_list;
+ /* a tree to track minimum exec vruntime */
+ struct rb_root_cached exec_timeline;
+ /* malloc this spinlock_t instead of built-in to shrank size of oplus_rq */
+ spinlock_t *ux_list_lock;
+ int nr_running;
+ u64 min_vruntime;
+ u64 load_weight;
+
+#if IS_ENABLED(CONFIG_OPLUS_FEATURE_SCHED_DDL)
+ struct rb_root_cached ddl_root;
+ spinlock_t *ddl_lock;
+#endif
+
+#ifdef CONFIG_LOCKING_PROTECT
+#ifndef CONFIG_LOCKING_LAST_ENTITY
+ struct list_head locking_thread_list;
+ spinlock_t *locking_list_lock;
+ int rq_locking_task;
+#else
+ struct sched_entity *last_entity;
+#endif
+#endif
+
+#if IS_ENABLED(CONFIG_OPLUS_FEATURE_LOADBALANCE)
+ /* for loadbalance */
+ struct oplus_lb lb;
+#endif
+#ifdef CONFIG_OPLUS_FEATURE_TICK_GRAN
+ struct hrtimer *resched_timer;
+ int cpu;
+#endif
+};
+
+extern int global_debug_enabled;
+extern int global_sched_assist_enabled;
+extern int global_sched_assist_scene;
+extern int global_silver_perf_core;
+extern int global_sched_group_enabled;
+
+struct rq;
+
+#ifdef CONFIG_LOCKING_PROTECT
+struct sched_assist_locking_ops {
+ void (*check_preempt_tick)(struct task_struct *p,
+ unsigned long *ideal_runtime, bool *skip_preempt,
+ unsigned long delta_exec, struct cfs_rq *cfs_rq,
+ struct sched_entity *curr, unsigned int granularity);
+ void (*check_preempt_wakeup)(struct rq *rq, struct task_struct *p, bool *preempt, bool *nopreempt);
+ void (*state_systrace_c)(unsigned int cpu, struct task_struct *p);
+ void (*locking_tick_hit)(struct task_struct *prev, struct task_struct *next);
+#ifndef CONFIG_LOCKING_LAST_ENTITY
+ void (*replace_next_task_fair)(struct rq *rq,
+ struct task_struct **p, struct sched_entity **se, bool *repick, bool simple);
+ void (*enqueue_entity)(struct rq *rq, struct task_struct *p);
+ void (*dequeue_entity)(struct rq *rq, struct task_struct *p);
+#else
+ void (*set_last_entity)(struct task_struct *prev, struct task_struct *next, struct rq *rq);
+ void (*pick_last_entity)(struct rq *rq, struct task_struct **p, struct sched_entity **se, bool *repick, bool simple);
+ void (*clear_last_entity)(struct rq *rq, struct task_struct *p);
+#endif
+ void (*opt_ss_lock_contention)(struct task_struct *p, int old_im, int new_im);
+};
+
+extern struct sched_assist_locking_ops *locking_ops;
+
+
+#define LOCKING_CALL_OP(op, args...) \
+do { \
+ if (locking_ops && locking_ops->op) { \
+ locking_ops->op(args); \
+ } \
+} while (0)
+
+#define LOCKING_CALL_OP_RET(op, args...) \
+({ \
+ __typeof__(locking_ops->op(args)) __ret = 0; \
+ if (locking_ops && locking_ops->op) \
+ __ret = locking_ops->op(args); \
+ __ret; \
+})
+
+void register_sched_assist_locking_ops(struct sched_assist_locking_ops *ops);
+#endif
+
+/* attention: before insert .ko, task's list->prev/next is init with 0 */
+static inline bool oplus_list_empty(struct list_head *list)
+{
+ return list_empty(list) || (list->prev == 0 && list->next == 0);
+}
+
+static inline bool oplus_rbtree_empty(struct rb_root_cached *list)
+{
+ return (rb_first_cached(list) == NULL);
+}
+
+/**
+ * Check if there are ux tasks waiting to run on the specified cpu
+ */
+static inline bool orq_has_ux_tasks(struct oplus_rq *orq)
+{
+ return !oplus_rbtree_empty(&orq->ux_list);
+}
+
+/* attention: before insert .ko, task's node->__rb_parent_color is init with 0 */
+static inline bool oplus_rbnode_empty(struct rb_node *node)
+{
+ return RB_EMPTY_NODE(node) || (node->__rb_parent_color == 0);
+}
+
+static inline struct oplus_task_struct *ux_list_first_entry(struct rb_root_cached *list)
+{
+ struct rb_node *leftmost = rb_first_cached(list);
+ if (leftmost == NULL) {
+ return NULL;
+ }
+ return rb_entry(leftmost, struct oplus_task_struct, ux_entry);
+}
+
+static inline struct oplus_task_struct *exec_timeline_first_entry(struct rb_root_cached *tree)
+{
+ struct rb_node *leftmost = rb_first_cached(tree);
+ if (leftmost == NULL) {
+ return NULL;
+ }
+ return rb_entry(leftmost, struct oplus_task_struct, exec_time_node);
+}
+
+typedef bool (*migrate_task_callback_t)(struct task_struct *tsk, int src_cpu, int dst_cpu);
+extern migrate_task_callback_t fbg_migrate_task_callback;