public inbox for linux-s390@vger.kernel.org
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: "Collin L. Walling" <walling@linux.vnet.ibm.com>,
	linux-s390@vger.kernel.org, kvm@vger.kernel.org
Cc: Christian Borntraeger <borntraeger@de.ibm.com>,
	Cornelia Huck <cohuck@redhat.com>,
	Janosch Frank <frankja@linux.vnet.ibm.com>
Subject: Re: [PATCH v2] KVM: s390: take care of clock-comparator sign control
Date: Tue, 6 Feb 2018 18:02:18 +0100	[thread overview]
Message-ID: <6a30e2cc-0d55-df88-ed04-532284adfd4e@redhat.com> (raw)
In-Reply-To: <f3db97d6-4eed-0b60-0573-21f301f87a56@linux.vnet.ibm.com>


>>   static u64 __calculate_sltime(struct kvm_vcpu *vcpu)
>>   {
>> -	u64 now, cputm, sltime = 0;
>> +	u64 now, cputm, ckc, sltime = 0;
>> +	int64_t ckc_signed, now_signed;
>>
>>   	if (ckc_interrupts_enabled(vcpu)) {
>> -		now = kvm_s390_get_tod_clock_fast(vcpu->kvm);
>> -		sltime = tod_to_ns(vcpu->arch.sie_block->ckc - now);
>> -		/* already expired or overflow? */
>> -		if (!sltime || vcpu->arch.sie_block->ckc <= now)
>> +		if (vcpu->arch.sie_block->gcr[0] & 0x0020000000000000ul &&
>> +		    test_kvm_facility(vcpu->kvm, 139)) {
>> +			now = kvm_s390_get_tod_clock_fast(vcpu->kvm);
>> +			ckc = vcpu->arch.sie_block->ckc;
> 
> 
> Shouldn't you be using now_signed and ckc_signed here?

Yes indeed.

> 
> 
>> +			if (ckc < now)
>> +				sltime = tod_to_ns(now - ckc);
>> +		} else {
>> +			now_signed = kvm_s390_get_tod_clock_fast(vcpu->kvm);
>> +			ckc_signed = vcpu->arch.sie_block->ckc;
> 
> and the unsigned ones here?
> 
> Also you could just compare vcpu->arch.sie_block->ckc and 
> kvm_s390_get_tod_clock_fast(vcpu->kvm)

That leads to ugly long lines (for the comparison and the calculation)

> 
>> +			if (ckc_signed < now_signed)
>> +				sltime = tod_to_ns(now_signed - ckc_signed);
> 
> 
> Shouldn't we only calculate sleep time if ckc is greater than now (in 
> both cases)?
> 

I think you're right!

(this was a 5min hack originally titled RFC, but I screwed up my command
line because I was sending a QEMU patch in between)

Will resend, thanks for having a look! :)

> 
>> +		}
>> +		/* already expired */
>> +		if (!sltime)
>>   			return 0;
>>   		if (cpu_timer_interrupts_enabled(vcpu)) {
>>   			cputm = kvm_s390_get_cpu_timer(vcpu);
> 
> Other than that, this is a heck of a lot easier to read than what we had 
> before.
> 


-- 

Thanks,

David / dhildenb

      reply	other threads:[~2018-02-06 17:02 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-05 10:40 [PATCH v2] KVM: s390: take care of clock-comparator sign control David Hildenbrand
2018-02-05 12:46 ` Christian Borntraeger
2018-02-05 13:22   ` Christian Borntraeger
2018-02-05 13:49   ` David Hildenbrand
2018-02-06 16:34 ` Collin L. Walling
2018-02-06 17:02   ` David Hildenbrand [this message]

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=6a30e2cc-0d55-df88-ed04-532284adfd4e@redhat.com \
    --to=david@redhat.com \
    --cc=borntraeger@de.ibm.com \
    --cc=cohuck@redhat.com \
    --cc=frankja@linux.vnet.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=walling@linux.vnet.ibm.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