From: Cornelia Huck <cohuck@redhat.com>
To: David Hildenbrand <david@redhat.com>
Cc: Thomas Huth <thuth@redhat.com>,
qemu-s390x@nongnu.org, Alexander Graf <agraf@suse.de>,
qemu-devel@nongnu.org,
Christian Borntraeger <borntraeger@de.ibm.com>,
Richard Henderson <rth@twiddle.net>
Subject: Re: [Qemu-devel] [qemu-s390x] [PATCH v3 5/9] s390x/tcg: properly implement the TOD
Date: Tue, 26 Jun 2018 14:27:02 +0200 [thread overview]
Message-ID: <20180626142702.444a3457.cohuck@redhat.com> (raw)
In-Reply-To: <384da416-9ce3-30aa-7bff-0ff0652cb8f4@redhat.com>
On Tue, 26 Jun 2018 14:06:00 +0200
David Hildenbrand <david@redhat.com> wrote:
> >> @@ -34,10 +58,24 @@ static void qemu_s390_tod_class_init(ObjectClass *oc, void *data)
> >> tdc->set = qemu_s390_tod_set;
> >> }
> >>
> >> +static void qemu_s390_tod_init(Object *obj)
> >> +{
> >> + S390TODState *td = S390_TOD(obj);
> >> + struct tm tm;
> >> +
> >> + qemu_get_timedate(&tm, 0);
> >> + td->base.high = 0;
> >> + td->base.low = TOD_UNIX_EPOCH + (time2tod(mktimegm(&tm)) * 1000000000ULL);
> >> + if (td->base.low < TOD_UNIX_EPOCH) {
> >> + td->base.high += 1;
> >> + }
> >> +}
> >
> > Nit: It would be sufficient to do this in the realize() function instead.
>
> Then I'll have to overwrite the realize function and store the
> parent_realize function - something that I want to avoid if not really
> necessary.
Agreed. I'd just leave it as it is now.
>
> (for now it was also done in the cpu initfn, so that should be fine)
>
> >
> >> static TypeInfo qemu_s390_tod_info = {
> >> .name = TYPE_QEMU_S390_TOD,
> >> .parent = TYPE_S390_TOD,
> >> .instance_size = sizeof(S390TODState),
> >> + .instance_init = qemu_s390_tod_init,
> >> .class_init = qemu_s390_tod_class_init,
> >> .class_size = sizeof(S390TODClass),
> >> };
> > [...]
> >> diff --git a/target/s390x/misc_helper.c b/target/s390x/misc_helper.c
> >> index dd5273949b..be341b5295 100644
> >> --- a/target/s390x/misc_helper.c
> >> +++ b/target/s390x/misc_helper.c
> >> @@ -28,6 +28,8 @@
> >> #include "qemu/timer.h"
> >> #include "exec/exec-all.h"
> >> #include "exec/cpu_ldst.h"
> >> +#include "qapi/error.h"
> >> +#include "tcg_s390x.h"
> >>
> >> #if !defined(CONFIG_USER_ONLY)
> >> #include "sysemu/cpus.h"
> >> @@ -39,6 +41,7 @@
> >> #include "hw/s390x/ioinst.h"
> >> #include "hw/s390x/s390-pci-inst.h"
> >> #include "hw/boards.h"
> >> +#include "hw/s390x/tod.h"
> >> #endif
> >>
> >> /* #define DEBUG_HELPER */
> >> @@ -138,25 +141,32 @@ void HELPER(spx)(CPUS390XState *env, uint64_t a1)
> >> /* Store Clock */
> >> uint64_t HELPER(stck)(CPUS390XState *env)
> >> {
> >> - uint64_t time;
> >> + S390TODState *td = s390_get_todstate();
> >> + S390TODClass *tdc = S390_TOD_GET_CLASS(td);
> >> + S390TOD tod;
> >>
> >> - time = env->tod_offset +
> >> - time2tod(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL));
> >> -
> >> - return time;
> >> + tdc->get(td, &tod, &error_abort);
> >> + return tod.low;
> >> }
> >>
> >> /* Set Clock Comparator */
> >> void HELPER(sckc)(CPUS390XState *env, uint64_t time)
> >> {
> >> + S390TODState *td = s390_get_todstate();
> >> + S390TODClass *tdc = S390_TOD_GET_CLASS(td);
> >> + S390TOD tod_base;
> >> +
> >> if (time == -1ULL) {
> >> return;
> >> }
> >>
> >> env->ckc = time;
> >>
> >> + tdc->get(td, &tod_base, &error_abort);
> >> + tod_base.low -= time2tod(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL));
> >
> > So the tdc->get first adds the time2tod, and then you subtract it here
> > again? Can't you simply use td->base.low directly instead?
>
> That might be a good idea, previously I had tdc->get_base(), but dropped
> it because it cannot be implemented for KVM.
>
> Simply accessing the member here should be fine. Thanks!
So, we're guaranteed to have td->base.low at the correct value? (Sorry,
having a bit of a hard time following around here.)
>
> >
> >> /* difference between origins */
> >> - time -= env->tod_offset;
> >> + time -= tod_base.low;
> >>
> >> /* nanoseconds */
> >> time = tod2time(time);
> >> @@ -164,6 +174,14 @@ void HELPER(sckc)(CPUS390XState *env, uint64_t time)
> >> timer_mod(env->tod_timer, time);
> >> }
> >
> > ... I found only nits, so with or without my suggested modifications:
> >
> > Reviewed-by: Thomas Huth <thuth@redhat.com>
> >
>
>
next prev parent reply other threads:[~2018-06-26 12:27 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-25 11:53 [Qemu-devel] [PATCH v3 0/9] s390x: TOD refactoring + TCG CPU hotplug support David Hildenbrand
2018-06-25 11:53 ` [Qemu-devel] [PATCH v3 1/9] s390x/tcg: avoid overflows in time2tod/tod2time David Hildenbrand
2018-06-26 10:04 ` Thomas Huth
2018-06-25 11:53 ` [Qemu-devel] [PATCH v3 2/9] s390x/kvm: pass values instead of pointers to kvm_s390_set_clock_*() David Hildenbrand
2018-06-25 15:50 ` Cornelia Huck
2018-06-25 15:54 ` David Hildenbrand
2018-06-25 16:03 ` Cornelia Huck
2018-06-26 9:54 ` [Qemu-devel] [qemu-s390x] " David Hildenbrand
2018-06-26 9:57 ` Cornelia Huck
2018-06-25 11:53 ` [Qemu-devel] [PATCH v3 3/9] s390x/tod: factor out TOD into separate device David Hildenbrand
2018-06-25 11:53 ` [Qemu-devel] [PATCH v3 4/9] s390x/tcg: drop tod_basetime David Hildenbrand
2018-06-25 11:53 ` [Qemu-devel] [PATCH v3 5/9] s390x/tcg: properly implement the TOD David Hildenbrand
2018-06-26 10:34 ` [Qemu-devel] [qemu-s390x] " Thomas Huth
2018-06-26 12:06 ` David Hildenbrand
2018-06-26 12:27 ` Cornelia Huck [this message]
2018-06-26 12:28 ` David Hildenbrand
2018-06-26 12:29 ` Cornelia Huck
2018-06-25 11:53 ` [Qemu-devel] [PATCH v3 6/9] s390x/tcg: SET CLOCK COMPARATOR can clear CKC interrupts David Hildenbrand
2018-06-26 12:30 ` Cornelia Huck
2018-06-27 11:15 ` [Qemu-devel] [qemu-s390x] " Thomas Huth
2018-06-25 11:53 ` [Qemu-devel] [PATCH v3 7/9] s390x/tcg: implement SET CLOCK David Hildenbrand
2018-06-27 11:17 ` [Qemu-devel] [qemu-s390x] " Thomas Huth
2018-06-25 11:53 ` [Qemu-devel] [PATCH v3 8/9] s390x/tcg: rearm the CKC timer during migration David Hildenbrand
2018-06-25 11:53 ` [Qemu-devel] [PATCH v3 9/9] s390x/tcg: fix CPU hotplug with single-threaded TCG David Hildenbrand
2018-06-26 12:33 ` Cornelia Huck
2018-06-27 11:19 ` [Qemu-devel] [qemu-s390x] " Thomas Huth
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=20180626142702.444a3457.cohuck@redhat.com \
--to=cohuck@redhat.com \
--cc=agraf@suse.de \
--cc=borntraeger@de.ibm.com \
--cc=david@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-s390x@nongnu.org \
--cc=rth@twiddle.net \
--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;
as well as URLs for NNTP newsgroup(s).