From nobody Mon Feb 9 20:31:38 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=arm.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1647617182448546.3443840244922; Fri, 18 Mar 2022 08:26:22 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.292104.496082 (Exim 4.92) (envelope-from ) id 1nVEUK-0002YU-Kt; Fri, 18 Mar 2022 15:26:00 +0000 Received: by outflank-mailman (output) from mailman id 292104.496082; Fri, 18 Mar 2022 15:26:00 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nVEUK-0002YC-HT; Fri, 18 Mar 2022 15:26:00 +0000 Received: by outflank-mailman (input) for mailman id 292104; Fri, 18 Mar 2022 15:25:59 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nVEUI-0001ka-RN for xen-devel@lists.xenproject.org; Fri, 18 Mar 2022 15:25:58 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id b58755b9-a6cf-11ec-853c-5f4723681683; Fri, 18 Mar 2022 16:25:57 +0100 (CET) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1CBF01515; Fri, 18 Mar 2022 08:25:57 -0700 (PDT) Received: from e125770.cambridge.arm.com (e125770.cambridge.arm.com [10.1.195.16]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C08113F7D7; Fri, 18 Mar 2022 08:25:55 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: b58755b9-a6cf-11ec-853c-5f4723681683 From: Luca Fancellu To: xen-devel@lists.xenproject.org Cc: bertrand.marquis@arm.com, wei.chen@arm.com, George Dunlap , Dario Faggioli , Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu Subject: [PATCH v3 3/6] xen/sched: retrieve scheduler id by name Date: Fri, 18 Mar 2022 15:25:38 +0000 Message-Id: <20220318152541.7460-4-luca.fancellu@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220318152541.7460-1-luca.fancellu@arm.com> References: <20220318152541.7460-1-luca.fancellu@arm.com> X-ZM-MESSAGEID: 1647617184247100001 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add a static function to retrieve the scheduler pointer using the scheduler name. Add a public function to retrieve the scheduler id by the scheduler name that makes use of the new static function. Take the occasion to replace open coded scheduler search with the new static function in scheduler_init. Signed-off-by: Luca Fancellu Reviewed-by: Juergen Gross --- Changes in v3: - add R-by Changes in v2: - replace open coded scheduler search in scheduler_init (Juergen) --- xen/common/sched/core.c | 40 ++++++++++++++++++++++++++-------------- xen/include/xen/sched.h | 11 +++++++++++ 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/xen/common/sched/core.c b/xen/common/sched/core.c index 19ab67818106..48ee01420fb8 100644 --- a/xen/common/sched/core.c +++ b/xen/common/sched/core.c @@ -2947,10 +2947,30 @@ void scheduler_enable(void) scheduler_active =3D true; } =20 +static inline +const struct scheduler *__init sched_get_by_name(const char *sched_name) +{ + unsigned int i; + + for ( i =3D 0; i < NUM_SCHEDULERS; i++ ) + if ( schedulers[i] && !strcmp(schedulers[i]->opt_name, sched_name)= ) + return schedulers[i]; + + return NULL; +} + +int __init sched_get_id_by_name(const char *sched_name) +{ + const struct scheduler *scheduler =3D sched_get_by_name(sched_name); + + return scheduler ? scheduler->sched_id : -1; +} + /* Initialise the data structures. */ void __init scheduler_init(void) { struct domain *idle_domain; + const struct scheduler *scheduler; int i; =20 scheduler_enable(); @@ -2981,25 +3001,17 @@ void __init scheduler_init(void) schedulers[i]->opt_name); schedulers[i] =3D NULL; } - - if ( schedulers[i] && !ops.name && - !strcmp(schedulers[i]->opt_name, opt_sched) ) - ops =3D *schedulers[i]; } =20 - if ( !ops.name ) + scheduler =3D sched_get_by_name(opt_sched); + if ( !scheduler ) { printk("Could not find scheduler: %s\n", opt_sched); - for ( i =3D 0; i < NUM_SCHEDULERS; i++ ) - if ( schedulers[i] && - !strcmp(schedulers[i]->opt_name, CONFIG_SCHED_DEFAULT) ) - { - ops =3D *schedulers[i]; - break; - } - BUG_ON(!ops.name); - printk("Using '%s' (%s)\n", ops.name, ops.opt_name); + scheduler =3D sched_get_by_name(CONFIG_SCHED_DEFAULT); + BUG_ON(!scheduler); + printk("Using '%s' (%s)\n", scheduler->name, scheduler->opt_name); } + ops =3D *scheduler; =20 if ( cpu_schedule_up(0) ) BUG(); diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 415b939ba8ae..4050e22544f9 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -756,6 +756,17 @@ void sched_destroy_domain(struct domain *d); long sched_adjust(struct domain *, struct xen_domctl_scheduler_op *); long sched_adjust_global(struct xen_sysctl_scheduler_op *); int sched_id(void); + +/* + * sched_get_id_by_name - retrieves a scheduler id given a scheduler name + * @sched_name: scheduler name as a string + * + * returns: + * positive value being the scheduler id, on success + * negative value if the scheduler name is not found. + */ +int sched_get_id_by_name(const char *sched_name); + void vcpu_wake(struct vcpu *v); long vcpu_yield(void); void vcpu_sleep_nosync(struct vcpu *v); --=20 2.17.1