From: Janosch Frank <frankja@linux.ibm.com>
To: Claudio Imbrenda <imbrenda@linux.ibm.com>
Cc: kvm@vger.kernel.org, thuth@redhat.com, david@redhat.com,
borntraeger@de.ibm.com, cohuck@redhat.com,
linux-s390@vger.kernel.org
Subject: Re: [kvm-unit-tests PATCH v3 2/8] s390x: Consolidate sclp read info
Date: Thu, 17 Dec 2020 15:48:51 +0100 [thread overview]
Message-ID: <36133ccd-3dc2-bc9a-9c83-376a31e98454@linux.ibm.com> (raw)
In-Reply-To: <20201217124722.0686a76d@ibm-vm>
On 12/17/20 12:47 PM, Claudio Imbrenda wrote:
> On Fri, 11 Dec 2020 05:00:33 -0500
> Janosch Frank <frankja@linux.ibm.com> wrote:
>
>> Let's only read the information once and pass a pointer to it instead
>> of calling sclp multiple times.
>>
>> Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
>> Reviewed-by: Cornelia Huck <cohuck@redhat.com>
>> ---
>> lib/s390x/io.c | 1 +
>> lib/s390x/sclp.c | 31 +++++++++++++++++++++++++------
>> lib/s390x/sclp.h | 3 +++
>> lib/s390x/smp.c | 27 +++++++++++----------------
>> 4 files changed, 40 insertions(+), 22 deletions(-)
>>
>> diff --git a/lib/s390x/io.c b/lib/s390x/io.c
>> index 1ff0589..6a1da63 100644
>> --- a/lib/s390x/io.c
>> +++ b/lib/s390x/io.c
>> @@ -34,6 +34,7 @@ void setup(void)
>> {
>> setup_args_progname(ipl_args);
>> setup_facilities();
>> + sclp_read_info();
>> sclp_console_setup();
>> sclp_memory_setup();
>> smp_setup();
>> diff --git a/lib/s390x/sclp.c b/lib/s390x/sclp.c
>> index 08a4813..bf1d9c0 100644
>> --- a/lib/s390x/sclp.c
>> +++ b/lib/s390x/sclp.c
>> @@ -23,6 +23,8 @@ extern unsigned long stacktop;
>> static uint64_t storage_increment_size;
>> static uint64_t max_ram_size;
>> static uint64_t ram_size;
>> +char _read_info[PAGE_SIZE] __attribute__((__aligned__(4096)));
>
> why not __aligned__((PAGE_SIZE)) ?
Because aligned is not defined as a compiler attribute in the lib AFAIK.
I can of course use PAGE_SIZE though.
>
>> +static ReadInfo *read_info;
>
> I wonder if a union would be cleaner? although later on you check if
> the pointer is NULL to see if the information is there, so I guess it
> can stay
I'm rather wondering if we want to replace that with an allocation,
these PAGE_SIZE arrays are just looking strange.
Let me put that on my TODO list for next year...
>
>>
>> char _sccb[PAGE_SIZE] __attribute__((__aligned__(4096)));
>> static volatile bool sclp_busy;
>> @@ -108,6 +110,24 @@ static void sclp_read_scp_info(ReadInfo *ri, int
>> length) report_abort("READ_SCP_INFO failed");
>> }
>>
>> +void sclp_read_info(void)
>> +{
>> + sclp_read_scp_info((void *)_read_info, SCCB_SIZE);
>> + read_info = (ReadInfo *)_read_info;
>> +}
>> +
>> +int sclp_get_cpu_num(void)
>> +{
>> + assert(read_info);
>> + return read_info->entries_cpu;
>> +}
>> +
>> +CPUEntry *sclp_get_cpu_entries(void)
>> +{
>> + assert(read_info);
>> + return (void *)read_info + read_info->offset_cpu;
>
> are you doing arithmetic on a void pointer? please don't, it's ugly and
> against the specs. moreover you do have a char pointer...
>
> why not:
> return (CPUEntry *)(_read_info + read_info->offset_cpu);
I seem to be one of those crazy persons who actually like void pointers.
Your suggestion looks good too, I'll replace my code with it.
>
>> +}
>> +
>> /* Perform service call. Return 0 on success, non-zero otherwise. */
>> int sclp_service_call(unsigned int command, void *sccb)
>> {
>> @@ -125,23 +145,22 @@ int sclp_service_call(unsigned int command,
>> void *sccb)
>> void sclp_memory_setup(void)
>> {
>> - ReadInfo *ri = (void *)_sccb;
>> uint64_t rnmax, rnsize;
>> int cc;
>>
>> - sclp_read_scp_info(ri, SCCB_SIZE);
>> + assert(read_info);
>>
>> /* calculate the storage increment size */
>> - rnsize = ri->rnsize;
>> + rnsize = read_info->rnsize;
>> if (!rnsize) {
>> - rnsize = ri->rnsize2;
>> + rnsize = read_info->rnsize2;
>> }
>> storage_increment_size = rnsize << 20;
>>
>> /* calculate the maximum memory size */
>> - rnmax = ri->rnmax;
>> + rnmax = read_info->rnmax;
>> if (!rnmax) {
>> - rnmax = ri->rnmax2;
>> + rnmax = read_info->rnmax2;
>> }
>> max_ram_size = rnmax * storage_increment_size;
>>
>> diff --git a/lib/s390x/sclp.h b/lib/s390x/sclp.h
>> index 9a6aad0..acd86d5 100644
>> --- a/lib/s390x/sclp.h
>> +++ b/lib/s390x/sclp.h
>> @@ -268,6 +268,9 @@ void sclp_wait_busy(void);
>> void sclp_mark_busy(void);
>> void sclp_console_setup(void);
>> void sclp_print(const char *str);
>> +void sclp_read_info(void);
>> +int sclp_get_cpu_num(void);
>> +CPUEntry *sclp_get_cpu_entries(void);
>> int sclp_service_call(unsigned int command, void *sccb);
>> void sclp_memory_setup(void);
>> uint64_t get_ram_size(void);
>> diff --git a/lib/s390x/smp.c b/lib/s390x/smp.c
>> index c4f02dc..dfcfd28 100644
>> --- a/lib/s390x/smp.c
>> +++ b/lib/s390x/smp.c
>> @@ -23,7 +23,6 @@
>> #include "smp.h"
>> #include "sclp.h"
>>
>> -static char cpu_info_buffer[PAGE_SIZE]
>> __attribute__((__aligned__(4096))); static struct cpu *cpus;
>> static struct cpu *cpu0;
>> static struct spinlock lock;
>> @@ -32,8 +31,7 @@ extern void smp_cpu_setup_state(void);
>>
>> int smp_query_num_cpus(void)
>> {
>> - struct ReadCpuInfo *info = (void *)cpu_info_buffer;
>> - return info->nr_configured;
>> + return sclp_get_cpu_num();
>> }
>>
>> struct cpu *smp_cpu_from_addr(uint16_t addr)
>> @@ -226,10 +224,10 @@ void smp_teardown(void)
>> {
>> int i = 0;
>> uint16_t this_cpu = stap();
>> - struct ReadCpuInfo *info = (void *)cpu_info_buffer;
>> + int num = smp_query_num_cpus();
>>
>> spin_lock(&lock);
>> - for (; i < info->nr_configured; i++) {
>> + for (; i < num; i++) {
>> if (cpus[i].active &&
>> cpus[i].addr != this_cpu) {
>> sigp_retry(cpus[i].addr, SIGP_STOP, 0, NULL);
>> @@ -243,22 +241,19 @@ extern uint64_t *stackptr;
>> void smp_setup(void)
>> {
>> int i = 0;
>> + int num = smp_query_num_cpus();
>> unsigned short cpu0_addr = stap();
>> - struct ReadCpuInfo *info = (void *)cpu_info_buffer;
>> + struct CPUEntry *entry = sclp_get_cpu_entries();
>>
>> spin_lock(&lock);
>> - sclp_mark_busy();
>> - info->h.length = PAGE_SIZE;
>> - sclp_service_call(SCLP_READ_CPU_INFO, cpu_info_buffer);
>> + if (num > 1)
>> + printf("SMP: Initializing, found %d cpus\n", num);
>>
>> - if (smp_query_num_cpus() > 1)
>> - printf("SMP: Initializing, found %d cpus\n",
>> info->nr_configured); -
>> - cpus = calloc(info->nr_configured, sizeof(cpus));
>> - for (i = 0; i < info->nr_configured; i++) {
>> - cpus[i].addr = info->entries[i].address;
>> + cpus = calloc(num, sizeof(cpus));
>> + for (i = 0; i < num; i++) {
>> + cpus[i].addr = entry[i].address;
>> cpus[i].active = false;
>> - if (info->entries[i].address == cpu0_addr) {
>> + if (entry[i].address == cpu0_addr) {
>> cpu0 = &cpus[i];
>> cpu0->stack = stackptr;
>> cpu0->lowcore = (void *)0;
>
next prev parent reply other threads:[~2020-12-17 14:50 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-11 10:00 [kvm-unit-tests PATCH v3 0/8] s390x: Add SIE library and simple test Janosch Frank
2020-12-11 10:00 ` [kvm-unit-tests PATCH v3 1/8] s390x: Add test_bit to library Janosch Frank
2020-12-11 10:00 ` [kvm-unit-tests PATCH v3 2/8] s390x: Consolidate sclp read info Janosch Frank
2020-12-11 12:06 ` Thomas Huth
2020-12-17 11:47 ` Claudio Imbrenda
2020-12-17 14:48 ` Janosch Frank [this message]
2020-12-11 10:00 ` [kvm-unit-tests PATCH v3 3/8] s390x: SCLP feature checking Janosch Frank
2020-12-17 12:18 ` Claudio Imbrenda
2020-12-17 15:21 ` Janosch Frank
2020-12-17 15:24 ` Thomas Huth
2020-12-11 10:00 ` [kvm-unit-tests PATCH v3 4/8] s390x: Split assembly and move to s390x/asm/ Janosch Frank
2020-12-11 12:18 ` Thomas Huth
2020-12-14 10:34 ` Janosch Frank
2020-12-17 12:54 ` Claudio Imbrenda
2020-12-17 13:14 ` Claudio Imbrenda
2020-12-17 15:22 ` Janosch Frank
2020-12-11 10:00 ` [kvm-unit-tests PATCH v3 5/8] s390x: sie: Add SIE to lib Janosch Frank
2020-12-17 9:37 ` Thomas Huth
2020-12-17 15:45 ` Janosch Frank
2020-12-17 14:42 ` Claudio Imbrenda
2020-12-11 10:00 ` [kvm-unit-tests PATCH v3 6/8] s390x: sie: Add first SIE test Janosch Frank
2020-12-17 9:41 ` Thomas Huth
2020-12-17 14:48 ` Claudio Imbrenda
2020-12-18 11:17 ` Cornelia Huck
2020-12-11 10:00 ` [kvm-unit-tests PATCH v3 7/8] s390x: Add diag318 intercept test Janosch Frank
2020-12-17 9:53 ` Thomas Huth
2020-12-17 9:59 ` Christian Borntraeger
2020-12-17 10:34 ` Thomas Huth
2020-12-17 14:31 ` Janosch Frank
2020-12-17 15:31 ` Janosch Frank
2020-12-17 15:36 ` Thomas Huth
2020-12-17 14:58 ` Claudio Imbrenda
2020-12-17 15:25 ` Janosch Frank
2020-12-11 10:00 ` [kvm-unit-tests PATCH v3 8/8] s390x: Fix sclp.h style issues Janosch Frank
2020-12-17 14:55 ` Claudio Imbrenda
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=36133ccd-3dc2-bc9a-9c83-376a31e98454@linux.ibm.com \
--to=frankja@linux.ibm.com \
--cc=borntraeger@de.ibm.com \
--cc=cohuck@redhat.com \
--cc=david@redhat.com \
--cc=imbrenda@linux.ibm.com \
--cc=kvm@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=thuth@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox