From: Boris Ostrovsky <boris.ostrovsky@oracle.com>
To: Jan Beulich <JBeulich@suse.com>
Cc: xen-devel <xen-devel@lists.xenproject.org>, Keir Fraser <keir@xen.org>
Subject: Re: [PATCH] x86: reduce redundancy in tsc_[gs]et_info()
Date: Wed, 30 Apr 2014 11:08:56 -0400 [thread overview]
Message-ID: <53611208.3050505@oracle.com> (raw)
In-Reply-To: <53611C5D020000780000DCAC@mail.emea.novell.com>
[-- Attachment #1.1: Type: text/plain, Size: 4243 bytes --]
On 04/30/2014 09:53 AM, Jan Beulich wrote:
> - some of the case statements are effectively or mostly special cases
> of others, so there's no good reason not to share the code
> - in the "get" function, a variable can be made case-wide instead of
> having multiple instance of it (and those even with a pointless
> initializer)
> - minor formatting adjustments
>
> Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
>
> --- a/xen/arch/x86/time.c
> +++ b/xen/arch/x86/time.c
> @@ -1786,26 +1786,22 @@ void tsc_get_info(struct domain *d, uint
>
> switch ( *tsc_mode )
> {
> + uint64_t tsc;
> +
> case TSC_MODE_NEVER_EMULATE:
> - *elapsed_nsec = *gtsc_khz = 0;
> + *elapsed_nsec = *gtsc_khz = 0;
> break;
> - case TSC_MODE_ALWAYS_EMULATE:
> - *elapsed_nsec = get_s_time() - d->arch.vtsc_offset;
> - *gtsc_khz = d->arch.tsc_khz;
> - break;
> case TSC_MODE_DEFAULT:
> if ( d->arch.vtsc )
> {
> + case TSC_MODE_ALWAYS_EMULATE:
> *elapsed_nsec = get_s_time() - d->arch.vtsc_offset;
> *gtsc_khz = d->arch.tsc_khz;
> + break;
> }
> - else
> - {
> - uint64_t tsc = 0;
> - rdtscll(tsc);
> - *elapsed_nsec = scale_delta(tsc,&d->arch.vtsc_to_ns);
> - *gtsc_khz = cpu_khz;
> - }
> + rdtscll(tsc);
> + *elapsed_nsec = scale_delta(tsc, &d->arch.vtsc_to_ns);
> + *gtsc_khz = cpu_khz;
> break;
> case TSC_MODE_PVRDTSCP:
> if ( d->arch.vtsc )
> @@ -1815,10 +1811,9 @@ void tsc_get_info(struct domain *d, uint
> }
> else
> {
> - uint64_t tsc = 0;
> rdtscll(tsc);
> - *elapsed_nsec = (scale_delta(tsc,&d->arch.vtsc_to_ns) -
> - d->arch.vtsc_offset);
> + *elapsed_nsec = scale_delta(tsc, &d->arch.vtsc_to_ns) -
> + d->arch.vtsc_offset;
> *gtsc_khz = 0; /* ignored by tsc_set_info */
> }
> break;
> @@ -1875,28 +1870,24 @@ void tsc_set_info(struct domain *d,
>
> switch ( d->arch.tsc_mode = tsc_mode )
> {
> - case TSC_MODE_NEVER_EMULATE:
> - d->arch.vtsc = 0;
> - break;
> - case TSC_MODE_ALWAYS_EMULATE:
> - d->arch.vtsc = 1;
> - d->arch.vtsc_offset = get_s_time() - elapsed_nsec;
> - d->arch.tsc_khz = gtsc_khz ? gtsc_khz : cpu_khz;
> - set_time_scale(&d->arch.vtsc_to_ns, d->arch.tsc_khz * 1000 );
> - d->arch.ns_to_vtsc = scale_reciprocal(d->arch.vtsc_to_ns);
> - break;
> case TSC_MODE_DEFAULT:
> - d->arch.vtsc = 1;
> + case TSC_MODE_ALWAYS_EMULATE:
> d->arch.vtsc_offset = get_s_time() - elapsed_nsec;
> - d->arch.tsc_khz = gtsc_khz ? gtsc_khz : cpu_khz;
> - set_time_scale(&d->arch.vtsc_to_ns, d->arch.tsc_khz * 1000 );
> - /* use native TSC if initial host has safe TSC, has not migrated
> - * yet and tsc_khz == cpu_khz */
> - if ( host_tsc_is_safe() && incarnation == 0 &&
> - d->arch.tsc_khz == cpu_khz )
> + d->arch.tsc_khz = gtsc_khz ?: cpu_khz;
> + set_time_scale(&d->arch.vtsc_to_ns, d->arch.tsc_khz * 1000);
> + /*
> + * In default mode use native TSC if the host has safe TSC,
> + * the VM has not migrated yet, and tsc_khz == cpu_khz.
> + */
> + if ( tsc_mode == TSC_MODE_DEFAULT && host_tsc_is_safe() &&
> + incarnation == 0 && d->arch.tsc_khz == cpu_khz )
> + {
> + case TSC_MODE_NEVER_EMULATE:
> d->arch.vtsc = 0;
> - else
> - d->arch.ns_to_vtsc = scale_reciprocal(d->arch.vtsc_to_ns);
> + break;
> + }
> + d->arch.vtsc = 1;
> + d->arch.ns_to_vtsc = scale_reciprocal(d->arch.vtsc_to_ns);
> break;
> case TSC_MODE_PVRDTSCP:
> d->arch.vtsc = boot_cpu_has(X86_FEATURE_RDTSCP) &&
>
>
>
>
>
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xen.org
> http://lists.xen.org/xen-devel
[-- Attachment #1.2: Type: text/html, Size: 5126 bytes --]
[-- Attachment #2: Type: text/plain, Size: 126 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
prev parent reply other threads:[~2014-04-30 15:05 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-30 13:53 [PATCH] x86: reduce redundancy in tsc_[gs]et_info() Jan Beulich
2014-04-30 14:48 ` Andrew Cooper
2014-04-30 14:59 ` Jan Beulich
2014-04-30 15:08 ` Boris Ostrovsky [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=53611208.3050505@oracle.com \
--to=boris.ostrovsky@oracle.com \
--cc=JBeulich@suse.com \
--cc=keir@xen.org \
--cc=xen-devel@lists.xenproject.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.