[PATCH 3/5] xen/sched: retrieve scheduler id by name

Luca Fancellu posted 5 patches 3 years, 11 months ago
There is a newer version of this series
[PATCH 3/5] xen/sched: retrieve scheduler id by name
Posted by Luca Fancellu 3 years, 11 months ago
Add a public function to retrieve the scheduler id by the scheduler
name.

Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
---
 xen/common/sched/core.c | 11 +++++++++++
 xen/include/xen/sched.h | 11 +++++++++++
 2 files changed, 22 insertions(+)

diff --git a/xen/common/sched/core.c b/xen/common/sched/core.c
index 8f4b1ca10d1c..9696d3c1d769 100644
--- a/xen/common/sched/core.c
+++ b/xen/common/sched/core.c
@@ -2947,6 +2947,17 @@ void scheduler_enable(void)
     scheduler_active = true;
 }
 
+int __init sched_get_id_by_name(const char *sched_name)
+{
+    unsigned int i;
+
+    for ( i = 0; i < NUM_SCHEDULERS; i++ )
+        if ( schedulers[i] && !strcmp(schedulers[i]->opt_name, sched_name) )
+            return schedulers[i]->sched_id;
+
+    return -1;
+}
+
 /* Initialise the data structures. */
 void __init scheduler_init(void)
 {
diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h
index a50df1bccdc0..a67a9eb2fe9d 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);
-- 
2.17.1


Re: [PATCH 3/5] xen/sched: retrieve scheduler id by name
Posted by Juergen Gross 3 years, 11 months ago
On 15.02.22 11:15, Luca Fancellu wrote:
> Add a public function to retrieve the scheduler id by the scheduler
> name.
> 
> Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
> ---
>   xen/common/sched/core.c | 11 +++++++++++
>   xen/include/xen/sched.h | 11 +++++++++++
>   2 files changed, 22 insertions(+)
> 
> diff --git a/xen/common/sched/core.c b/xen/common/sched/core.c
> index 8f4b1ca10d1c..9696d3c1d769 100644
> --- a/xen/common/sched/core.c
> +++ b/xen/common/sched/core.c
> @@ -2947,6 +2947,17 @@ void scheduler_enable(void)
>       scheduler_active = true;
>   }
>   
> +int __init sched_get_id_by_name(const char *sched_name)
> +{
> +    unsigned int i;
> +
> +    for ( i = 0; i < NUM_SCHEDULERS; i++ )
> +        if ( schedulers[i] && !strcmp(schedulers[i]->opt_name, sched_name) )
> +            return schedulers[i]->sched_id;
> +
> +    return -1;
> +}
> +

Please make use of this function in scheduler_init(), as this
functionality is open coded there, too.


Juergen
Re: [PATCH 3/5] xen/sched: retrieve scheduler id by name
Posted by Luca Fancellu 3 years, 11 months ago

> On 15 Feb 2022, at 10:40, Juergen Gross <jgross@suse.com> wrote:
> 
> On 15.02.22 11:15, Luca Fancellu wrote:
>> Add a public function to retrieve the scheduler id by the scheduler
>> name.
>> Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
>> ---
>>  xen/common/sched/core.c | 11 +++++++++++
>>  xen/include/xen/sched.h | 11 +++++++++++
>>  2 files changed, 22 insertions(+)
>> diff --git a/xen/common/sched/core.c b/xen/common/sched/core.c
>> index 8f4b1ca10d1c..9696d3c1d769 100644
>> --- a/xen/common/sched/core.c
>> +++ b/xen/common/sched/core.c
>> @@ -2947,6 +2947,17 @@ void scheduler_enable(void)
>>      scheduler_active = true;
>>  }
>>  +int __init sched_get_id_by_name(const char *sched_name)
>> +{
>> +    unsigned int i;
>> +
>> +    for ( i = 0; i < NUM_SCHEDULERS; i++ )
>> +        if ( schedulers[i] && !strcmp(schedulers[i]->opt_name, sched_name) )
>> +            return schedulers[i]->sched_id;
>> +
>> +    return -1;
>> +}
>> +
> 
> Please make use of this function in scheduler_init(), as this
> functionality is open coded there, too.
> 

Ok I will change the code in scheduler_init to use the new function.

Cheers,
Luca

> 
> Juergen
> <OpenPGP_0xB0DE9DD628BF132F.asc>