git: 84eaf2ccc6aa - x86: stop punishing VMs with low priority for TSC timecounter

Maxim Sobolev sobomax at freebsd.org
Wed Dec 23 17:00:10 UTC 2020


Thanks! The slowdown in my experience mostly comes from the fact that only
TSC has userspace-mapped implementation for the clock_gettime(2) and
friends. Combined of course with the fact that syscall is still
horrendously expensive on VM. So if you have say 10 threads calling
clock_gettime() 100 times per second (not uncommon for RTP/RTC apps) that
causes 1,000 context switches just to do that. Let alone any useful
workload the  app might be doing.

Unless the MFC is planned it might also be a good idea to document that for
12.x/11.x, the issue can easily be worked around by forcing TSC via loader
tunable / sysctl.

-Max

On Wed., Dec. 23, 2020, 2:46 a.m. Konstantin Belousov, <kib at freebsd.org>
wrote:

> The branch main has been updated by kib:
>
> URL:
> https://cgit.FreeBSD.org/src/commit/?id=84eaf2ccc6aa05da7b7389991d3023698b756e3f
>
> commit 84eaf2ccc6aa05da7b7389991d3023698b756e3f
> Author:     Konstantin Belousov <kib at FreeBSD.org>
> AuthorDate: 2020-12-21 17:02:31 +0000
> Commit:     Konstantin Belousov <kib at FreeBSD.org>
> CommitDate: 2020-12-23 10:45:15 +0000
>
>     x86: stop punishing VMs with low priority for TSC timecounter
>
>     I suspect that virtualization techniques improved from the time when we
>     have to effectively disable TSC use in VM.  For instance, it was
> reported
>     (complained) in https://github.com/JuliaLang/julia/issues/38877 that
>     FreeBSD is groundlessly slow on AWS with some loads.
>
>     Remove the check and start watching for complaints.
>
>     Reviewed by:    emaste, grehan
>     Discussed with: cperciva
>     Sponsored by:   The FreeBSD Foundation
>     Differential Revision:  https://reviews.freebsd.org/D27629
> ---
>  sys/x86/x86/tsc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/sys/x86/x86/tsc.c b/sys/x86/x86/tsc.c
> index c8e9be0c3cd5..6b5242fb5d4f 100644
> --- a/sys/x86/x86/tsc.c
> +++ b/sys/x86/x86/tsc.c
> @@ -499,7 +499,7 @@ test_tsc(int adj_max_count)
>         uint64_t *data, *tsc;
>         u_int i, size, adj;
>
> -       if ((!smp_tsc && !tsc_is_invariant) || vm_guest)
> +       if ((!smp_tsc && !tsc_is_invariant))
>                 return (-100);
>         size = (mp_maxid + 1) * 3;
>         data = malloc(sizeof(*data) * size * N, M_TEMP, M_WAITOK);
>
>


More information about the dev-commits-src-all mailing list