Received: by 2002:a05:7412:98c1:b0:fa:551:50a7 with SMTP id kc1csp1861839rdb; Mon, 8 Jan 2024 12:45:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IFpmcV+VUpkoTCYTIMkGwmWK5JS7HOa9iVMfFlzTJVij3KwGI7qVSCIVc8qJoijtNUQGtGM X-Received: by 2002:a17:902:ecc8:b0:1d4:6e68:31fe with SMTP id a8-20020a170902ecc800b001d46e6831femr2411859plh.49.1704746704905; Mon, 08 Jan 2024 12:45:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704746704; cv=none; d=google.com; s=arc-20160816; b=gLMvO0hZGpfe+4hPwbefptFBwSTTVx80f4WmxS4tzQHqxK2ABYv+PGrmzGFT+b72rI xjxqKZysjvBO3DhLZrzPaxCRLaSHoTFUgwSGdfQNmCdZAWUQtdohPHrguFbrQegBI3cd PW9cGo/n2IDdDHs6laGEhnx3ds7IOy5V2MzenhnJ1jOZ3An+uVKBuDETdsUvuMF8czTb rcRX2z/7j0iCjfNNJvKPO9d2Qn68Bi5Aonz2wj3IfT4np0LJ6fY7EuhV7Cg6LSO9rve3 FvL0XwmkcDgH3pn8SpRfGc5MlzySBQwte9C93bbPSDNaHOPxM7H47kja4p8kyIkQZTU+ hkFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:dkim-signature:dkim-signature:date; bh=QFJeHLw9GqQjgm3FgM7p7sOy93Z0Ypb7HjJTBpJG3O4=; fh=eVIZrwuudlpgfXW4idpODC63zz0suJcfjdFxnBYLnto=; b=b5FjeWUl88yGAUvI5ZO/Af2eYuiRVdhZYamHsGzmngo5flbV9rv9BaIZGAHLh5c0z+ FKfZvA6oIJmO/xUs5riYxjFVprXigEHHOl1bStA7QwBxs13hKR0MMba7zH/d7p5/qoHT R+Fcns6854EUG/m5/hKJJZcWTonuNgWBY/mffHCP1a4KszgEc/WBP/EAhaw3sworHZNt Joh8v+971x5ygluZs+entsTrhAjXh23sZxkQuhAKRWvsj2laoQMFryQ6na7aQuYJ69jT 5+6NMTi4T75UqAeCOAxz19g/OB+2WJglQ5ZXMndyBSXI+EuSMU4osowC4txTbo5u+fbk jc9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="bzt7U+/W"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=UkgPg0Vu; spf=pass (google.com: domain of linux-kernel+bounces-20103-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-20103-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id u8-20020a170902b28800b001d524935f03si379941plr.576.2024.01.08.12.45.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jan 2024 12:45:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-20103-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="bzt7U+/W"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=UkgPg0Vu; spf=pass (google.com: domain of linux-kernel+bounces-20103-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-20103-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id ED96B284E70 for ; Mon, 8 Jan 2024 20:44:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F37B65577A; Mon, 8 Jan 2024 20:44:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="bzt7U+/W"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="UkgPg0Vu" X-Original-To: linux-kernel@vger.kernel.org Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B71FF4653E for ; Mon, 8 Jan 2024 20:44:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Date: Mon, 8 Jan 2024 21:44:48 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1704746689; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QFJeHLw9GqQjgm3FgM7p7sOy93Z0Ypb7HjJTBpJG3O4=; b=bzt7U+/W2wueF3ZyEvkRbDnY9Xe1TPDS/cu37+INvXFswbDOZ9DJAmKTgBNj7O1TtS7xbP q5nJSKzZ69fjbrX+nE9v46voHIVDbS7bV67LO5YvJ4t2b2gZREQOa3iUiVtjtsvZh4Rs0l 3lVTImw/fw98wwmHPAk1uhlhkjirXUOAJ0ytCr8YY6iSi1bxo89GPmuUKEvKEMschzoJ4U crp1o5Ar7GKTV+nkBoNy2md9a4fPtpYJCloyUVVDKg9bPGzv2YfaOWSTjlreHFOwnhe4GO qURQz+qCcAKfd2uBaGmeKRv/v+6LUQyvhAeIgNG9oRy5yW4F/dhHhThW11j5ZA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1704746689; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QFJeHLw9GqQjgm3FgM7p7sOy93Z0Ypb7HjJTBpJG3O4=; b=UkgPg0VuU9/DJID5oFyG5SAC8mwxbwH9zoayBjaH1aPk1owx29WmNSIHFu5RQYR6X7Uq9u sC2u8FaismFOZzCQ== From: Nam Cao To: Alexandre Ghiti Cc: Paul Walmsley , Palmer Dabbelt , Albert Ou , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Jisheng Zhang Subject: Re: [PATCH v2] riscv: Add support for BATCHED_UNMAP_TLB_FLUSH Message-ID: <20240108214448.025977ac@namcao> In-Reply-To: <20240108214346.5fd93127@namcao> References: <20240108193640.344929-1-alexghiti@rivosinc.com> <20240108214346.5fd93127@namcao> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Mon, 8 Jan 2024 21:43:46 +0100 Nam Cao wrote: > On Mon, 8 Jan 2024 20:36:40 +0100 Alexandre Ghiti wrote: > > Allow to defer the flushing of the TLB when unmapping pages, which allows > > to reduce the numbers of IPI and the number of sfence.vma. > > > > The ubenchmarch used in commit 43b3dfdd0455 ("arm64: support > > batched/deferred tlb shootdown during page reclamation/migration") that > > was multithreaded to force the usage of IPI shows good performance > > improvement on all platforms: > > > > * Unmatched: ~34% > > * TH1520 : ~78% > > * Qemu : ~81% > > > > In addition, perf on qemu reports an important decrease in time spent > > dealing with IPIs: > > > > Before: 68.17% main [kernel.kallsyms] [k] __sbi_rfence_v02_call > > After : 8.64% main [kernel.kallsyms] [k] __sbi_rfence_v02_call > > > > * Benchmark: > > > > int stick_this_thread_to_core(int core_id) { > > int num_cores = sysconf(_SC_NPROCESSORS_ONLN); > > if (core_id < 0 || core_id >= num_cores) > > return EINVAL; > > > > cpu_set_t cpuset; > > CPU_ZERO(&cpuset); > > CPU_SET(core_id, &cpuset); > > > > pthread_t current_thread = pthread_self(); > > return pthread_setaffinity_np(current_thread, > > sizeof(cpu_set_t), &cpuset); > > } > > > > static void *fn_thread (void *p_data) > > { > > int ret; > > pthread_t thread; > > > > stick_this_thread_to_core((int)p_data); > > > > while (1) { > > sleep(1); > > } > > > > return NULL; > > } > > > > int main() > > { > > volatile unsigned char *p = mmap(NULL, SIZE, PROT_READ | PROT_WRITE, > > MAP_SHARED | MAP_ANONYMOUS, -1, 0); > > pthread_t threads[4]; > > int ret; > > > > for (int i = 0; i < 4; ++i) { > > ret = pthread_create(&threads[i], NULL, fn_thread, (void *)i); > > if (ret) > > { > > printf("%s", strerror (ret)); > > } > > } > > > > memset(p, 0x88, SIZE); > > > > for (int k = 0; k < 10000; k++) { > > /* swap in */ > > for (int i = 0; i < SIZE; i += 4096) { > > (void)p[i]; > > } > > > > /* swap out */ > > madvise(p, SIZE, MADV_PAGEOUT); > > } > > > > for (int i = 0; i < 4; i++) > > { > > pthread_cancel(threads[i]); > > } > > > > for (int i = 0; i < 4; i++) > > { > > pthread_join(threads[i], NULL); > > } > > > > return 0; > > } > > > > Signed-off-by: Alexandre Ghiti > > Reviewed-by: Jisheng Zhang > > Tested-by: Jisheng Zhang # Tested on TH1520 > > Before: > real 0m36.674s > user 0m0.173s > sys 0m36.493s > After: > real 0m18.016s > user 0m0.125s > sys 0m17.885s > > Tested-by: Nam Cao I forgot to mention: this is for Starfive's Visionfive 2 board. Best regards, Nam