Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

sched: Make const-safe

With a modified container_of() that preserves constness, the compiler
finds some pointers which should have been marked as const. task_of()
also needs to become const-preserving for the !FAIR_GROUP_SCHED case so
that cfs_rq_of() can take a const argument. No change to generated code.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20221212144946.2657785-1-willy@infradead.org

authored by

Matthew Wilcox (Oracle) and committed by
Peter Zijlstra
904cbab7 b344b8f2

+24 -22
+5 -3
kernel/sched/core.c
··· 152 152 DEFINE_STATIC_KEY_FALSE(__sched_core_enabled); 153 153 154 154 /* kernel prio, less is more */ 155 - static inline int __task_prio(struct task_struct *p) 155 + static inline int __task_prio(const struct task_struct *p) 156 156 { 157 157 if (p->sched_class == &stop_sched_class) /* trumps deadline */ 158 158 return -2; ··· 174 174 */ 175 175 176 176 /* real prio, less is less */ 177 - static inline bool prio_less(struct task_struct *a, struct task_struct *b, bool in_fi) 177 + static inline bool prio_less(const struct task_struct *a, 178 + const struct task_struct *b, bool in_fi) 178 179 { 179 180 180 181 int pa = __task_prio(a), pb = __task_prio(b); ··· 195 194 return false; 196 195 } 197 196 198 - static inline bool __sched_core_less(struct task_struct *a, struct task_struct *b) 197 + static inline bool __sched_core_less(const struct task_struct *a, 198 + const struct task_struct *b) 199 199 { 200 200 if (a->core_cookie < b->core_cookie) 201 201 return true;
+9 -7
kernel/sched/fair.c
··· 468 468 return NULL; 469 469 } 470 470 471 - static inline struct sched_entity *parent_entity(struct sched_entity *se) 471 + static inline struct sched_entity *parent_entity(const struct sched_entity *se) 472 472 { 473 473 return se->parent; 474 474 } ··· 595 595 return min_vruntime; 596 596 } 597 597 598 - static inline bool entity_before(struct sched_entity *a, 599 - struct sched_entity *b) 598 + static inline bool entity_before(const struct sched_entity *a, 599 + const struct sched_entity *b) 600 600 { 601 601 return (s64)(a->vruntime - b->vruntime) < 0; 602 602 } ··· 11852 11852 /* 11853 11853 * se_fi_update - Update the cfs_rq->min_vruntime_fi in a CFS hierarchy if needed. 11854 11854 */ 11855 - static void se_fi_update(struct sched_entity *se, unsigned int fi_seq, bool forceidle) 11855 + static void se_fi_update(const struct sched_entity *se, unsigned int fi_seq, 11856 + bool forceidle) 11856 11857 { 11857 11858 for_each_sched_entity(se) { 11858 11859 struct cfs_rq *cfs_rq = cfs_rq_of(se); ··· 11878 11877 se_fi_update(se, rq->core->core_forceidle_seq, in_fi); 11879 11878 } 11880 11879 11881 - bool cfs_prio_less(struct task_struct *a, struct task_struct *b, bool in_fi) 11880 + bool cfs_prio_less(const struct task_struct *a, const struct task_struct *b, 11881 + bool in_fi) 11882 11882 { 11883 11883 struct rq *rq = task_rq(a); 11884 - struct sched_entity *sea = &a->se; 11885 - struct sched_entity *seb = &b->se; 11884 + const struct sched_entity *sea = &a->se; 11885 + const struct sched_entity *seb = &b->se; 11886 11886 struct cfs_rq *cfs_rqa; 11887 11887 struct cfs_rq *cfs_rqb; 11888 11888 s64 delta;
+10 -12
kernel/sched/sched.h
··· 248 248 249 249 #define SCHED_DL_FLAGS (SCHED_FLAG_RECLAIM | SCHED_FLAG_DL_OVERRUN | SCHED_FLAG_SUGOV) 250 250 251 - static inline bool dl_entity_is_special(struct sched_dl_entity *dl_se) 251 + static inline bool dl_entity_is_special(const struct sched_dl_entity *dl_se) 252 252 { 253 253 #ifdef CONFIG_CPU_FREQ_GOV_SCHEDUTIL 254 254 return unlikely(dl_se->flags & SCHED_FLAG_SUGOV); ··· 260 260 /* 261 261 * Tells if entity @a should preempt entity @b. 262 262 */ 263 - static inline bool 264 - dl_entity_preempt(struct sched_dl_entity *a, struct sched_dl_entity *b) 263 + static inline bool dl_entity_preempt(const struct sched_dl_entity *a, 264 + const struct sched_dl_entity *b) 265 265 { 266 266 return dl_entity_is_special(a) || 267 267 dl_time_before(a->deadline, b->deadline); ··· 1244 1244 return &rq->__lock; 1245 1245 } 1246 1246 1247 - bool cfs_prio_less(struct task_struct *a, struct task_struct *b, bool fi); 1247 + bool cfs_prio_less(const struct task_struct *a, const struct task_struct *b, 1248 + bool fi); 1248 1249 1249 1250 /* 1250 1251 * Helpers to check if the CPU's core cookie matches with the task's cookie ··· 1424 1423 } 1425 1424 1426 1425 /* runqueue on which this entity is (to be) queued */ 1427 - static inline struct cfs_rq *cfs_rq_of(struct sched_entity *se) 1426 + static inline struct cfs_rq *cfs_rq_of(const struct sched_entity *se) 1428 1427 { 1429 1428 return se->cfs_rq; 1430 1429 } ··· 1437 1436 1438 1437 #else 1439 1438 1440 - static inline struct task_struct *task_of(struct sched_entity *se) 1441 - { 1442 - return container_of(se, struct task_struct, se); 1443 - } 1439 + #define task_of(_se) container_of(_se, struct task_struct, se) 1444 1440 1445 - static inline struct cfs_rq *task_cfs_rq(struct task_struct *p) 1441 + static inline struct cfs_rq *task_cfs_rq(const struct task_struct *p) 1446 1442 { 1447 1443 return &task_rq(p)->cfs; 1448 1444 } 1449 1445 1450 - static inline struct cfs_rq *cfs_rq_of(struct sched_entity *se) 1446 + static inline struct cfs_rq *cfs_rq_of(const struct sched_entity *se) 1451 1447 { 1452 - struct task_struct *p = task_of(se); 1448 + const struct task_struct *p = task_of(se); 1453 1449 struct rq *rq = task_rq(p); 1454 1450 1455 1451 return &rq->cfs;