From nobody Thu Sep 18 02:38:58 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F3E3AC4332F for ; Mon, 12 Dec 2022 14:50:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232381AbiLLOuE (ORCPT ); Mon, 12 Dec 2022 09:50:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232361AbiLLOtx (ORCPT ); Mon, 12 Dec 2022 09:49:53 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47D6D13D33 for ; Mon, 12 Dec 2022 06:49:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:In-Reply-To:References; bh=Xh19w+wqYZm5Os/v/KfZys8SNBRBfUUmtMhDm02shFA=; b=rjnEBWmD6vjPJsg0ppsOZfvyd5 OFPAxw48sRQyyDUtDMG/IoCS1SBEF0Zxvbl+UPclq+Zw+LB/wWgjCVkbrMzSKg1eBi70ss1x6/+gr WlBrqLcNAXNOPcR9evD2eYUQi7Q5h5vTUkPLPlSILRp1nKU+KdIzInU3q1zRyf0iMTIEsSUsAdjFn a6+J6OpZW9YXfkZyOx6iwxHoHII4/Lu1Fi4uAZKN32D8na/i+dUwKIyu1zO8gj4XOFOaWyhNqNyUr QjkHCWLr0KFcPXSRy9CFBJtMXMoa/FY8wA7//5Ys8MWOwxC7MT7NakJUIinTM9AYuJOl+KIr8E+d9 JCboq33g==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1p4k7p-00B9Qj-EU; Mon, 12 Dec 2022 14:49:49 +0000 From: "Matthew Wilcox (Oracle)" To: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , linux-kernel@vger.kernel.org Cc: "Matthew Wilcox (Oracle)" Subject: [PATCH v2] sched: Make const-safe Date: Mon, 12 Dec 2022 14:49:46 +0000 Message-Id: <20221212144946.2657785-1-willy@infradead.org> X-Mailer: git-send-email 2.37.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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) --- v2: Also update the !FAIR_GROUP_SCHED case kernel/sched/core.c | 8 +++++--- kernel/sched/fair.c | 16 +++++++++------- kernel/sched/sched.h | 22 ++++++++++------------ 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 25b582b6ee5f..853188cb6c84 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -152,7 +152,7 @@ __read_mostly int scheduler_running; DEFINE_STATIC_KEY_FALSE(__sched_core_enabled); =20 /* kernel prio, less is more */ -static inline int __task_prio(struct task_struct *p) +static inline int __task_prio(const struct task_struct *p) { if (p->sched_class =3D=3D &stop_sched_class) /* trumps deadline */ return -2; @@ -174,7 +174,8 @@ static inline int __task_prio(struct task_struct *p) */ =20 /* real prio, less is less */ -static inline bool prio_less(struct task_struct *a, struct task_struct *b,= bool in_fi) +static inline bool prio_less(const struct task_struct *a, + const struct task_struct *b, bool in_fi) { =20 int pa =3D __task_prio(a), pb =3D __task_prio(b); @@ -194,7 +195,8 @@ static inline bool prio_less(struct task_struct *a, str= uct task_struct *b, bool return false; } =20 -static inline bool __sched_core_less(struct task_struct *a, struct task_st= ruct *b) +static inline bool __sched_core_less(const struct task_struct *a, + const struct task_struct *b) { if (a->core_cookie < b->core_cookie) return true; diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index c36aa54ae071..855470310903 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -468,7 +468,7 @@ is_same_group(struct sched_entity *se, struct sched_ent= ity *pse) return NULL; } =20 -static inline struct sched_entity *parent_entity(struct sched_entity *se) +static inline struct sched_entity *parent_entity(const struct sched_entity= *se) { return se->parent; } @@ -595,8 +595,8 @@ static inline u64 min_vruntime(u64 min_vruntime, u64 vr= untime) return min_vruntime; } =20 -static inline bool entity_before(struct sched_entity *a, - struct sched_entity *b) +static inline bool entity_before(const struct sched_entity *a, + const struct sched_entity *b) { return (s64)(a->vruntime - b->vruntime) < 0; } @@ -11728,7 +11728,8 @@ static inline void task_tick_core(struct rq *rq, st= ruct task_struct *curr) /* * se_fi_update - Update the cfs_rq->min_vruntime_fi in a CFS hierarchy if= needed. */ -static void se_fi_update(struct sched_entity *se, unsigned int fi_seq, boo= l forceidle) +static void se_fi_update(const struct sched_entity *se, unsigned int fi_se= q, + bool forceidle) { for_each_sched_entity(se) { struct cfs_rq *cfs_rq =3D cfs_rq_of(se); @@ -11753,11 +11754,12 @@ void task_vruntime_update(struct rq *rq, struct t= ask_struct *p, bool in_fi) se_fi_update(se, rq->core->core_forceidle_seq, in_fi); } =20 -bool cfs_prio_less(struct task_struct *a, struct task_struct *b, bool in_f= i) +bool cfs_prio_less(const struct task_struct *a, const struct task_struct *= b, + bool in_fi) { struct rq *rq =3D task_rq(a); - struct sched_entity *sea =3D &a->se; - struct sched_entity *seb =3D &b->se; + const struct sched_entity *sea =3D &a->se; + const struct sched_entity *seb =3D &b->se; struct cfs_rq *cfs_rqa; struct cfs_rq *cfs_rqb; s64 delta; diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 771f8ddb7053..cdf9f248e5bd 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -248,7 +248,7 @@ static inline void update_avg(u64 *avg, u64 sample) =20 #define SCHED_DL_FLAGS (SCHED_FLAG_RECLAIM | SCHED_FLAG_DL_OVERRUN | SCHED= _FLAG_SUGOV) =20 -static inline bool dl_entity_is_special(struct sched_dl_entity *dl_se) +static inline bool dl_entity_is_special(const struct sched_dl_entity *dl_s= e) { #ifdef CONFIG_CPU_FREQ_GOV_SCHEDUTIL return unlikely(dl_se->flags & SCHED_FLAG_SUGOV); @@ -260,8 +260,8 @@ static inline bool dl_entity_is_special(struct sched_dl= _entity *dl_se) /* * Tells if entity @a should preempt entity @b. */ -static inline bool -dl_entity_preempt(struct sched_dl_entity *a, struct sched_dl_entity *b) +static inline bool dl_entity_preempt(const struct sched_dl_entity *a, + const struct sched_dl_entity *b) { return dl_entity_is_special(a) || dl_time_before(a->deadline, b->deadline); @@ -1236,7 +1236,8 @@ static inline raw_spinlock_t *__rq_lockp(struct rq *r= q) return &rq->__lock; } =20 -bool cfs_prio_less(struct task_struct *a, struct task_struct *b, bool fi); +bool cfs_prio_less(const struct task_struct *a, const struct task_struct *= b, + bool fi); =20 /* * Helpers to check if the CPU's core cookie matches with the task's cookie @@ -1415,7 +1416,7 @@ static inline struct cfs_rq *task_cfs_rq(struct task_= struct *p) } =20 /* runqueue on which this entity is (to be) queued */ -static inline struct cfs_rq *cfs_rq_of(struct sched_entity *se) +static inline struct cfs_rq *cfs_rq_of(const struct sched_entity *se) { return se->cfs_rq; } @@ -1428,19 +1429,16 @@ static inline struct cfs_rq *group_cfs_rq(struct sc= hed_entity *grp) =20 #else =20 -static inline struct task_struct *task_of(struct sched_entity *se) -{ - return container_of(se, struct task_struct, se); -} +#define task_of(_se) container_of(_se, struct task_struct, se) =20 -static inline struct cfs_rq *task_cfs_rq(struct task_struct *p) +static inline struct cfs_rq *task_cfs_rq(const struct task_struct *p) { return &task_rq(p)->cfs; } =20 -static inline struct cfs_rq *cfs_rq_of(struct sched_entity *se) +static inline struct cfs_rq *cfs_rq_of(const struct sched_entity *se) { - struct task_struct *p =3D task_of(se); + const struct task_struct *p =3D task_of(se); struct rq *rq =3D task_rq(p); =20 return &rq->cfs; --=20 2.35.1