diff mbox series

[kvm-unit-tests,v1,1/5] lib: s390x: smp: add functions to work with CPU indexes

Message ID 20220128185449.64936-2-imbrenda@linux.ibm.com (mailing list archive)
State New, archived
Headers show
Series s390x: smp: avoid hardcoded CPU addresses | expand

Commit Message

Claudio Imbrenda Jan. 28, 2022, 6:54 p.m. UTC
Knowing the number of active CPUs is not enough to know which ones are
active. This patch adds 2 new functions:

* smp_cpu_addr_from_idx to get the CPU address from the index
* smp_cpu_from_idx allows to retrieve the struct cpu from the index

This makes it possible for tests to avoid hardcoding the CPU addresses.
It is useful in cases where the address and the index might not match.

Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
---
 lib/s390x/smp.h |  2 ++
 lib/s390x/smp.c | 12 ++++++++++++
 2 files changed, 14 insertions(+)

Comments

David Hildenbrand Jan. 31, 2022, 1:50 p.m. UTC | #1
On 28.01.22 19:54, Claudio Imbrenda wrote:
> Knowing the number of active CPUs is not enough to know which ones are
> active. This patch adds 2 new functions:
> 
> * smp_cpu_addr_from_idx to get the CPU address from the index
> * smp_cpu_from_idx allows to retrieve the struct cpu from the index
> 
> This makes it possible for tests to avoid hardcoding the CPU addresses.
> It is useful in cases where the address and the index might not match.
> 
> Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
> ---
>  lib/s390x/smp.h |  2 ++
>  lib/s390x/smp.c | 12 ++++++++++++
>  2 files changed, 14 insertions(+)
> 
> diff --git a/lib/s390x/smp.h b/lib/s390x/smp.h
> index a2609f11..69aa4003 100644
> --- a/lib/s390x/smp.h
> +++ b/lib/s390x/smp.h
> @@ -37,6 +37,7 @@ struct cpu_status {
>  
>  int smp_query_num_cpus(void);
>  struct cpu *smp_cpu_from_addr(uint16_t addr);
> +struct cpu *smp_cpu_from_idx(uint16_t addr);

s/addr/idx/
Steffen Eiden Feb. 2, 2022, 4:55 p.m. UTC | #2
On 1/31/22 14:50, David Hildenbrand wrote:
> On 28.01.22 19:54, Claudio Imbrenda wrote:
>> Knowing the number of active CPUs is not enough to know which ones are
>> active. This patch adds 2 new functions:
>>
>> * smp_cpu_addr_from_idx to get the CPU address from the index
>> * smp_cpu_from_idx allows to retrieve the struct cpu from the index
>>
>> This makes it possible for tests to avoid hardcoding the CPU addresses.
>> It is useful in cases where the address and the index might not match.
>>
>> Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
With Davids nit
Reviewed-by Steffen Eiden <seiden@linux.ibm.com>
>> ---
>>   lib/s390x/smp.h |  2 ++
>>   lib/s390x/smp.c | 12 ++++++++++++
>>   2 files changed, 14 insertions(+)
>>
>> diff --git a/lib/s390x/smp.h b/lib/s390x/smp.h
>> index a2609f11..69aa4003 100644
>> --- a/lib/s390x/smp.h
>> +++ b/lib/s390x/smp.h
>> @@ -37,6 +37,7 @@ struct cpu_status {
>>   
>>   int smp_query_num_cpus(void);
>>   struct cpu *smp_cpu_from_addr(uint16_t addr);
>> +struct cpu *smp_cpu_from_idx(uint16_t addr);
> 
> s/addr/idx/
> 
>
Claudio Imbrenda Feb. 3, 2022, 1:33 p.m. UTC | #3
On Mon, 31 Jan 2022 14:50:37 +0100
David Hildenbrand <david@redhat.com> wrote:

> On 28.01.22 19:54, Claudio Imbrenda wrote:
> > Knowing the number of active CPUs is not enough to know which ones are
> > active. This patch adds 2 new functions:
> > 
> > * smp_cpu_addr_from_idx to get the CPU address from the index
> > * smp_cpu_from_idx allows to retrieve the struct cpu from the index
> > 
> > This makes it possible for tests to avoid hardcoding the CPU addresses.
> > It is useful in cases where the address and the index might not match.
> > 
> > Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
> > ---
> >  lib/s390x/smp.h |  2 ++
> >  lib/s390x/smp.c | 12 ++++++++++++
> >  2 files changed, 14 insertions(+)
> > 
> > diff --git a/lib/s390x/smp.h b/lib/s390x/smp.h
> > index a2609f11..69aa4003 100644
> > --- a/lib/s390x/smp.h
> > +++ b/lib/s390x/smp.h
> > @@ -37,6 +37,7 @@ struct cpu_status {
> >  
> >  int smp_query_num_cpus(void);
> >  struct cpu *smp_cpu_from_addr(uint16_t addr);
> > +struct cpu *smp_cpu_from_idx(uint16_t addr);  
> 
> s/addr/idx/
> 
> 

oops!

will fix
diff mbox series

Patch

diff --git a/lib/s390x/smp.h b/lib/s390x/smp.h
index a2609f11..69aa4003 100644
--- a/lib/s390x/smp.h
+++ b/lib/s390x/smp.h
@@ -37,6 +37,7 @@  struct cpu_status {
 
 int smp_query_num_cpus(void);
 struct cpu *smp_cpu_from_addr(uint16_t addr);
+struct cpu *smp_cpu_from_idx(uint16_t addr);
 bool smp_cpu_stopped(uint16_t addr);
 bool smp_sense_running_status(uint16_t addr);
 int smp_cpu_restart(uint16_t addr);
@@ -47,5 +48,6 @@  int smp_cpu_destroy(uint16_t addr);
 int smp_cpu_setup(uint16_t addr, struct psw psw);
 void smp_teardown(void);
 void smp_setup(void);
+uint16_t smp_cpu_addr_from_idx(uint16_t idx);
 
 #endif
diff --git a/lib/s390x/smp.c b/lib/s390x/smp.c
index b753eab5..64c647ec 100644
--- a/lib/s390x/smp.c
+++ b/lib/s390x/smp.c
@@ -46,6 +46,18 @@  struct cpu *smp_cpu_from_addr(uint16_t addr)
 	return NULL;
 }
 
+struct cpu *smp_cpu_from_idx(uint16_t idx)
+{
+	assert(idx < smp_query_num_cpus());
+	return &cpus[idx];
+}
+
+uint16_t smp_cpu_addr_from_idx(uint16_t idx)
+{
+	assert(idx < smp_query_num_cpus());
+	return cpus[idx].addr;
+}
+
 bool smp_cpu_stopped(uint16_t addr)
 {
 	uint32_t status;