public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Claudio Imbrenda <imbrenda@linux.ibm.com>
To: Nico Boehr <nrb@linux.ibm.com>
Cc: kvm@vger.kernel.org, linux-s390@vger.kernel.org,
	frankja@linux.ibm.com, thuth@redhat.com
Subject: Re: [kvm-unit-tests PATCH v1 2/2] s390x: add cmm migration test
Date: Tue, 10 May 2022 15:45:20 +0200	[thread overview]
Message-ID: <20220510154520.52274a76@p-imbrenda> (raw)
In-Reply-To: <d87472c1556d8503bdda9e1cec26b5d910468cbc.camel@linux.ibm.com>

On Tue, 10 May 2022 15:25:09 +0200
Nico Boehr <nrb@linux.ibm.com> wrote:

> On Mon, 2022-05-09 at 15:58 +0200, Claudio Imbrenda wrote:
> > > +       for (i = 0; i < NUM_PAGES; i++) {
> > > +               switch(i % 4) {
> > > +                       case 0:
> > > +                               essa(ESSA_SET_STABLE, (unsigned
> > > long)pagebuf[i]);
> > > +                       break;
> > > +                       case 1:
> > > +                               essa(ESSA_SET_UNUSED, (unsigned
> > > long)pagebuf[i]);
> > > +                       break;
> > > +                       case 2:
> > > +                               essa(ESSA_SET_VOLATILE, (unsigned
> > > long)pagebuf[i]);
> > > +                       break;
> > > +                       case 3:
> > > +                               essa(ESSA_SET_POT_VOLATILE,
> > > (unsigned long)pagebuf[i]);
> > > +                       break;  
> > 
> > const int essa_commands[4] = {ESSA_SET_STABLE, ESSA_SET_UNUSED, ...
> > 
> > for (i = 0; i < NUM_PAGES; i++)
> >         essa(essa_commands[i % 4], ...
> > 
> > I think it would look more compact and more readable  
> 
> I like your idea a lot, but the compiler doesn't :-(:

ouch, I had completely forgotten about that.

> 
> /home/nrb/kvm-unit-tests/lib/asm/cmm.h: In function ‘main’:
> /home/nrb/kvm-unit-tests/lib/asm/cmm.h:32:9: error: ‘asm’ operand 2
> probably does not match constraints [-Werror]
>    32 |         asm volatile(".insn
> rrf,0xb9ab0000,%[extr_state],%[addr],%[new_state],0" \
>       |         ^~~
> /home/nrb/kvm-unit-tests/lib/asm/cmm.h:32:9: error: impossible
> constraint in ‘asm’
> 
> To satify the "i" constraint, new_state needs to be a compile time
> constant, which it won't be any more with your suggestion
> unfortunately. 
> 
> We can do crazy stuff like this in cmm.h:
> 
> #define __essa(state) \
> 	asm volatile(".insn
> rrf,0xb9ab0000,%[extr_state],%[addr],%[new_state],0" \
> 			: [extr_state] "=d" (extr_state) \
> 			: [addr] "a" (paddr), [new_state] "i"
> (state));
> static unsigned long essa(uint8_t state, unsigned long paddr)
> {
> 	uint64_t extr_state = 0;
> 
> 	switch(state) {
> 		case ESSA_SET_STABLE:
> 			__essa(ESSA_SET_STABLE);
> 		break;
> 		case ESSA_SET_UNUSED:
> 			__essa(ESSA_SET_UNUSED);
> 		break;
> 		case ESSA_SET_VOLATILE:
> 			__essa(ESSA_SET_VOLATILE);
> 		break;
> 		case ESSA_SET_POT_VOLATILE:
> 			__essa(ESSA_SET_POT_VOLATILE);
> 		break;
> 	}
> 
> 	return (unsigned long)extr_state;
> }
> 
> But that essentially just shifts the readability problem to a different
> file. What do you think?
> 
> Or we make essa a marco, which doesn't sound like a particularily
> attractive alternative either.

ok, next less ugly thing: unroll the loop

for (i = 0; i < NUM_PAGES; i += 4) {
	essa(ESSA_SET_STABLE, (unsigned long)pagebuf[i]);
	essa(ESSA_SET_UNUSED, (unsigned long)pagebuf[i + 1]);
	... etc
}

maybe assert(NUM_PAGES % 4 == 0) before that, just for good measure



  reply	other threads:[~2022-05-10 14:10 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-09 12:08 [kvm-unit-tests PATCH v1 0/2] s390x: add migration test for CMM Nico Boehr
2022-05-09 12:08 ` [kvm-unit-tests PATCH v1 1/2] lib: s390x: add header for CMM related defines Nico Boehr
2022-05-09 12:08 ` [kvm-unit-tests PATCH v1 2/2] s390x: add cmm migration test Nico Boehr
2022-05-09 13:58   ` Claudio Imbrenda
2022-05-10 13:25     ` Nico Boehr
2022-05-10 13:45       ` Claudio Imbrenda [this message]
2022-05-10 14:13         ` Nico Boehr
2022-05-09 14:00 ` [kvm-unit-tests PATCH v1 0/2] s390x: add migration test for CMM Claudio Imbrenda
2022-05-10 10:58   ` Nico Boehr
2022-05-10 12:47     ` Janosch Frank
2022-05-11  8:59       ` Nico Boehr

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=20220510154520.52274a76@p-imbrenda \
    --to=imbrenda@linux.ibm.com \
    --cc=frankja@linux.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=nrb@linux.ibm.com \
    --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