public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Vitaly Kuznetsov <vkuznets@redhat.com>
To: Wanpeng Li <kernellwp@gmail.com>
Cc: "the arch\/x86 maintainers" <x86@kernel.org>,
	devel@linuxdriverproject.org,
	"linux-kernel\@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"K. Y. Srinivasan" <kys@microsoft.com>,
	Haiyang Zhang <haiyangz@microsoft.com>,
	Stephen Hemminger <sthemmin@microsoft.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Jork Loeser <Jork.Loeser@microsoft.com>,
	Simon Xiao <sixiao@microsoft.com>,
	Andy Lutomirski <luto@kernel.org>,
	Andy Shevchenko <andy.shevchenko@gmail.com>,
	Paolo Bonzini <pbonzini@redhat.com>, kvm <kvm@vger.kernel.org>
Subject: Re: [PATCH v10 0/9] Hyper-V: paravirtualized remote TLB flushing and hypercall improvements
Date: Mon, 06 Nov 2017 10:14:41 +0100	[thread overview]
Message-ID: <87d14vrcou.fsf@vitty.brq.redhat.com> (raw)
In-Reply-To: <CANRm+Cz7SgUJ3o2O=uDn+un4JYiqQ-aANhf4tNNArfbv6a_uOQ@mail.gmail.com> (Wanpeng Li's message of "Mon, 6 Nov 2017 16:43:51 +0800")

[-- Attachment #1: Type: text/plain, Size: 2617 bytes --]

Wanpeng Li <kernellwp@gmail.com> writes:

> 2017-08-03 0:09 GMT+08:00 Vitaly Kuznetsov <vkuznets@redhat.com>:
>> Changes since v9:
>> - Rebase to 4.13-rc3.
>> - Drop PATCH1 as it was already taken by Greg to char-misc tree. There're no
>>   functional dependencies on this patch so the series can go through a different tree
>>   (and it actually belongs to x86 if I got Ingo's comment right).
>> - Add in missing void return type in PATCH1 [Colin King, Ingo Molnar, Greg KH]
>> - A few minor fixes in what is now PATCH7: add pr_fmt, tiny style fix in
>>   hyperv_flush_tlb_others() [Andy Shevchenko]
>> - Fix "error: implicit declaration of function 'virt_to_phys'" in PATCH2
>>   reported by kbuild test robot (#include <asm/io.h>)
>> - Add Steven's 'Reviewed-by:' to PATCH9.
>>
>> Original description:
>>
>> Hyper-V supports hypercalls for doing local and remote TLB flushing and
>> gives its guests hints when using hypercall is preferred. While doing
>> hypercalls for local TLB flushes is probably not practical (and is not
>> being suggested by modern Hyper-V versions) remote TLB flush with a
>> hypercall brings significant improvement.
>>
>> To test the series I wrote a special 'TLB trasher': on a 16 vCPU guest I
>> was creating 32 threads which were doing 100000 mmap/munmaps each on some
>> big file. Here are the results:
>>
>> Before:
>> # time ./pthread_mmap ./randfile
>> real    3m33.118s
>> user    0m3.698s
>> sys     3m16.624s
>>
>> After:
>> # time ./pthread_mmap ./randfile
>> real    2m19.920s
>> user    0m2.662s
>> sys     2m9.948s
>>
>> This series brings a number of small improvements along the way: fast
>> hypercall implementation and using it for event signaling, rep hypercalls
>> implementation, hyperv tracing subsystem (which only traces the newly added
>> remote TLB flush for now).
>>
>
> Hi Vitaly,
>
> Could you attach your benchmark? I'm interested in to try the
> implementation in paravirt kvm.
>

Oh, this would be cool) I briefly discussed the idea with Radim (one of
KVM maintainers) during the last KVM Forum and he wasn't opposed to the
idea. Need to talk to Paolo too. Good thing is that we have everything
in place for guests now (HAVE_RCU_TABLE_FREE is enabled globaly on x86).

Please see the microbenchmark attached. Adjust defines in the beginning
to match your needs. It is not anything smart, basically just a TLB
trasher.

In theory, the best result is achived when we're overcommiting the host
by running multiple vCPUs on each pCPU. In this case PV tlb flush avoids
touching vCPUs which are not scheduled and avoid the wait on the main
CPU.

-- 
  Vitaly


[-- Attachment #2: pthread_mmap.c --]
[-- Type: text/plain, Size: 1457 bytes --]

#include <pthread.h>
#include <stdio.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>

#define nthreads 48
#define pagecount 16384
#define nrounds 1000
#define nchunks 20
#define PAGE_SIZE 4096

int fd;
unsigned long v;

void *threadf(void *ptr)
{
	unsigned long *addr[nchunks];
	int i, j, k;
	struct timespec ts = {0};
	int ret;

	ts.tv_nsec = random() % 1024;

	for (j = 0; j < nrounds; j++) {
		for (i = 0; i < nchunks; i++) {
			addr[i] = mmap(NULL, PAGE_SIZE * pagecount, PROT_READ, MAP_SHARED, fd, i * PAGE_SIZE);
			if (addr[i] == MAP_FAILED) {
				fprintf(stderr, "mmap\n");
				exit(1);
			}
		}

		nanosleep(&ts, NULL);

		for (i = 0; i < nchunks; i++) {
			v += *addr[i];
		}


		nanosleep(&ts, NULL);

		for (i = 0; i < nchunks; i++) {
			munmap(addr[i], PAGE_SIZE * pagecount);
		}
	}
}

int main(int argc, char *argv[]) {
	pthread_t thr[nthreads];
	int i;

	srandom(time(NULL));

	if (argc < 2) {
		fprintf(stderr, "usage: %s <some-big-file>\n", argv[0]);
		exit(1);
	}

	fd = open(argv[1], O_RDONLY);
	if (fd < 0) {
		fprintf(stderr, "open\n");
		exit(1);
	}
	
	for (i = 0; i < nthreads; i++) {
		if(pthread_create(&thr[i], NULL, threadf, NULL)) {
			fprintf(stderr, "pthread_create\n");
			exit(1);
		}
	}

	for (i = 0; i < nthreads; i++) {
		if(pthread_join(thr[i], NULL)) {
			fprintf(stderr, "pthread_join\n");
			exit(1);
		}
	}

	return 0;
}

  reply	other threads:[~2017-11-06  9:14 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-02 16:09 [PATCH v10 0/9] Hyper-V: paravirtualized remote TLB flushing and hypercall improvements Vitaly Kuznetsov
2017-08-02 16:09 ` [PATCH v10 1/9] x86/hyper-v: include hyperv/ only when CONFIG_HYPERV is set Vitaly Kuznetsov
2017-08-10 16:37   ` [tip:x86/platform] x86/hyper-v: Include " tip-bot for Vitaly Kuznetsov
2017-08-02 16:09 ` [PATCH v10 2/9] x86/hyper-v: make hv_do_hypercall() inline Vitaly Kuznetsov
2017-08-10 16:37   ` [tip:x86/platform] x86/hyper-v: Make " tip-bot for Vitaly Kuznetsov
2017-08-02 16:09 ` [PATCH v10 3/9] x86/hyper-v: fast hypercall implementation Vitaly Kuznetsov
2017-08-10 16:37   ` [tip:x86/platform] x86/hyper-v: Introduce " tip-bot for Vitaly Kuznetsov
2017-08-02 16:09 ` [PATCH v10 4/9] hyper-v: use fast hypercall for HVCALL_SIGNAL_EVENT Vitaly Kuznetsov
2017-08-10 16:38   ` [tip:x86/platform] hyper-v: Use " tip-bot for Vitaly Kuznetsov
2017-08-02 16:09 ` [PATCH v10 5/9] x86/hyper-v: implement rep hypercalls Vitaly Kuznetsov
2017-08-10 16:38   ` [tip:x86/platform] x86/hyper-v: Implement " tip-bot for Vitaly Kuznetsov
2017-08-02 16:09 ` [PATCH v10 6/9] hyper-v: globalize vp_index Vitaly Kuznetsov
2017-08-10 16:39   ` [tip:x86/platform] hyper-v: Globalize vp_index tip-bot for Vitaly Kuznetsov
2017-08-02 16:09 ` [PATCH v10 7/9] x86/hyper-v: use hypercall for remote TLB flush Vitaly Kuznetsov
2017-08-10 16:39   ` [tip:x86/platform] x86/hyper-v: Use " tip-bot for Vitaly Kuznetsov
2017-08-10 18:21   ` tip-bot for Vitaly Kuznetsov
2017-08-10 18:56     ` Peter Zijlstra
2017-08-10 18:59       ` KY Srinivasan
2017-08-10 19:08         ` Jork Loeser
2017-08-10 19:27           ` Peter Zijlstra
2017-08-11  1:15             ` Jork Loeser
2017-08-11  9:03               ` Peter Zijlstra
2017-08-11 11:29                 ` Kirill A. Shutemov
2017-08-11 16:16                 ` Linus Torvalds
2017-08-11 16:26                   ` Peter Zijlstra
2017-08-14 13:20                     ` Vitaly Kuznetsov
2017-08-16 16:42                       ` Vitaly Kuznetsov
2017-08-16 21:41                         ` Boris Ostrovsky
2017-08-17  7:58                           ` Vitaly Kuznetsov
2017-08-11  9:23             ` Vitaly Kuznetsov
2017-08-11 10:56               ` Peter Zijlstra
2017-08-11 11:05                 ` [Xen-devel] " Andrew Cooper
2017-08-11 12:07                   ` Peter Zijlstra
2017-08-16  0:02                     ` Steven Rostedt
2017-08-11 12:22                 ` Juergen Gross
2017-08-11 12:35                   ` Peter Zijlstra
2017-08-11 12:46                     ` Juergen Gross
2017-08-11 12:54                       ` Peter Zijlstra
2017-08-11 13:07                         ` Juergen Gross
2017-08-11 13:39                           ` Peter Zijlstra
2017-08-02 16:09 ` [PATCH v10 8/9] x86/hyper-v: support extended CPU ranges for TLB flush hypercalls Vitaly Kuznetsov
2017-08-31 20:01   ` [tip:x86/platform] x86/hyper-v: Support " tip-bot for Vitaly Kuznetsov
2017-08-02 16:09 ` [PATCH v10 9/9] tracing/hyper-v: trace hyperv_mmu_flush_tlb_others() Vitaly Kuznetsov
2017-08-31 20:01   ` [tip:x86/platform] tracing/hyper-v: Trace hyperv_mmu_flush_tlb_others() tip-bot for Vitaly Kuznetsov
2017-08-10 11:58 ` [PATCH v10 0/9] Hyper-V: paravirtualized remote TLB flushing and hypercall improvements Vitaly Kuznetsov
2017-08-10 15:12   ` Ingo Molnar
2017-08-10 15:17     ` Vitaly Kuznetsov
2017-08-10 16:03 ` Ingo Molnar
2017-08-10 17:00   ` Vitaly Kuznetsov
2017-08-31 11:43 ` Vitaly Kuznetsov
2017-08-31 12:22   ` Ingo Molnar
2017-08-31 14:53     ` Vitaly Kuznetsov
2017-08-31 20:01       ` Ingo Molnar
2017-11-06  8:43 ` Wanpeng Li
2017-11-06  9:14   ` Vitaly Kuznetsov [this message]
2017-11-06  9:57     ` Wanpeng Li
2017-11-06 10:10       ` Vitaly Kuznetsov
2017-11-06 11:07         ` Wanpeng Li

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=87d14vrcou.fsf@vitty.brq.redhat.com \
    --to=vkuznets@redhat.com \
    --cc=Jork.Loeser@microsoft.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=devel@linuxdriverproject.org \
    --cc=haiyangz@microsoft.com \
    --cc=hpa@zytor.com \
    --cc=kernellwp@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=kys@microsoft.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mingo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=rostedt@goodmis.org \
    --cc=sixiao@microsoft.com \
    --cc=sthemmin@microsoft.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox