Received: by 10.213.65.68 with SMTP id h4csp3360938imn; Tue, 3 Apr 2018 03:39:14 -0700 (PDT) X-Google-Smtp-Source: AIpwx485udOVipM+rGN7yr8Cf+JumcuL/akbg+Y4wSaej9VXzIKx1KKJ7h13rLSh+NSPTX8M0bLx X-Received: by 10.98.210.7 with SMTP id c7mr10074444pfg.92.1522751954648; Tue, 03 Apr 2018 03:39:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522751954; cv=none; d=google.com; s=arc-20160816; b=f6sm7mJYA8gPYc0GTEb2bXr8fBnnTRQRFDA2/uy+i77RfPjW8nyxNacZzBOaZ5EQSD HOvuBSUazhpaj8d1tmpfiORM2cugAR5Q7w0C7MmsV7h04Ug0gankWLeRovROh3yJfwvC 2oiCDkNLjuYcZZSg1yAaLAEGFDqkpqsaQJBu/OGH0QTYULZLt0v1Ufz7VgwrooH1E4pk fKJ4GDHmWFPbCV/JFXrxmzf0s6VaRKTSR6Zm7cHVi1sJl7ESOGMRelXB1SLwEYxtf76Y /9R5V6LqAVZ8rskNGa+DhirffEUu/cx5VTIRFbtqGx2t9CRrixJanxiKurN/RHonyMzx +b6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=A2wZVwWRepTkieZH7jqmgsIt/bs9Zuv7u087ZPVpAqY=; b=Ksmo9qtXMq6tKUK8MgcYWHcY4Lh8g+6ppNeLFATr6Fn8qz7vXGD4pkzyKFiUB77ODh isVf0JIBBcJTArq0cmRLFcr4TzLM8kk1rf58UwbXIkm/Xy2hnnFpqphhinjVALwFl89B PbO8su70tb5lIGzFdCxZJGOMAXZKRjLJjjRcDSMPwlAKrWs3CayHYxY+Cyktc2oRVi8W UUo0TKA7ddQqcFyptclQjUUiLvl259ImjJIT9F4D8AggTjzs4ndIN+UIDDy4HJNCIwAq ID8vA0DtOZeLQ7agBZncFmaeS7fVHqY4zBxWKjPFQOGF94oc3w9dTpK65s6L+PQ7gouS ALiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=racNTnbE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b91-v6si250591plb.90.2018.04.03.03.38.58; Tue, 03 Apr 2018 03:39:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=racNTnbE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755261AbeDCKhC (ORCPT + 99 others); Tue, 3 Apr 2018 06:37:02 -0400 Received: from mail-wr0-f193.google.com ([209.85.128.193]:36007 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754915AbeDCKg7 (ORCPT ); Tue, 3 Apr 2018 06:36:59 -0400 Received: by mail-wr0-f193.google.com with SMTP id y55so18206967wry.3; Tue, 03 Apr 2018 03:36:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=A2wZVwWRepTkieZH7jqmgsIt/bs9Zuv7u087ZPVpAqY=; b=racNTnbEv7Q4wFDXydIydsMambPgfe5jgmC8dZEowJu04bcc4aa3ezB6z60sYmcP3p mJFoyBty2CvbjcWSJieAoEjz398sPzN7rZTQFSZGCsMtxOAkkuhQZUQaK4MmsuBkxUQL V0efuiFtSPunuAIZJqCsjp/GOtV4nDzGHwmG26+4yaDBW4TUrbCUE9QKcJxhWYDQ8QZo HX3bHfaYQhgntMyKPK30KL+Bxf0hMLdNV/lkevh+l9o9b7jlGmRmZuIKvMJK2rhU2pL3 siaGlh008UEU3yLr7akGfWw4fFIHIUghujKxHvnpiuIZWFLWuHcuv7B6zW37YdM67xJT gSVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to:user-agent; bh=A2wZVwWRepTkieZH7jqmgsIt/bs9Zuv7u087ZPVpAqY=; b=c/QJsKNLsW7iYtLwAivaka6HSy9C3A5+WIdMHdS9SF7ol1djRh5SvlqxoODISh4TsI pLXPDjgKoQpwGAarqTno8ndu/JKCjtleDIOYVtinuh9B9vjlXpkosq+L7bvVzKkgdbxj LxuPdn/TRCPeAduD12KuulZGA22/2R3Ttvc2AOB7RYuLGRoJtuHyfmsU3TzGcaIHCgzc T+GawaBgkm7Do5O8LIj2HeZnZMssoT7HOqlAaXSSR9jd5nQlgP27dU+ahMUo/RjiXlaB Snp4TLoa1o59W8BtH6TfN6i1P9bkOTaXpSDsJdZYgDdDa0+18QKwyOP3znkCBAxDHbqa Po0A== X-Gm-Message-State: AElRT7EpOsPlQdG9KuI/kO8vJiBn266FUMF9OyIWnKOGfko5OE2boEsW +5GQRPXkFiSzgD/sanKqxH0= X-Received: by 10.223.176.98 with SMTP id g31mr9117197wra.256.1522751818445; Tue, 03 Apr 2018 03:36:58 -0700 (PDT) Received: from gmail.com (2E8B0CD5.catv.pool.telekom.hu. [46.139.12.213]) by smtp.gmail.com with ESMTPSA id z12sm1611685wrg.20.2018.04.03.03.36.56 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 Apr 2018 03:36:57 -0700 (PDT) Date: Tue, 3 Apr 2018 12:36:55 +0200 From: Ingo Molnar To: Pavel Machek Cc: Thomas Gleixner , David Laight , 'Rahul Lakkireddy' , "x86@kernel.org" , "linux-kernel@vger.kernel.org" , "netdev@vger.kernel.org" , "mingo@redhat.com" , "hpa@zytor.com" , "davem@davemloft.net" , "akpm@linux-foundation.org" , "torvalds@linux-foundation.org" , "ganeshgr@chelsio.com" , "nirranjan@chelsio.com" , "indranil@chelsio.com" , Andy Lutomirski , Peter Zijlstra , Fenghua Yu , Eric Biggers Subject: Re: [RFC PATCH 0/3] kernel: add support for 256-bit IO access Message-ID: <20180403103655.oa235p3h65twf4ct@gmail.com> References: <7f0ddb3678814c7bab180714437795e0@AcuMS.aculab.com> <7f8d811e79284a78a763f4852984eb3f@AcuMS.aculab.com> <20180320082651.jmxvvii2xvmpyr2s@gmail.com> <20180320090802.qw4tqjmhy6yfd6sf@gmail.com> <20180320105427.bm4od7cpessbraag@gmail.com> <20180403084932.GA3926@amd> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180403084932.GA3926@amd> User-Agent: NeoMutt/20170609 (1.8.3) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Pavel Machek wrote: > > > > Yeah, so generic memcpy() replacement is only feasible I think if the most > > > > optimistic implementation is actually correct: > > > > > > > > - if no preempt disable()/enable() is required > > > > > > > > - if direct access to the AVX[2] registers does not disturb legacy FPU state in > > > > any fashion > > > > > > > > - if direct access to the AVX[2] registers cannot raise weird exceptions or have > > > > weird behavior if the FPU control word is modified to non-standard values by > > > > untrusted user-space > > > > > > > > If we have to touch the FPU tag or control words then it's probably only good for > > > > a specialized API. > > > > > > I did not mean to have a general memcpy replacement. Rather something like > > > magic_memcpy() which falls back to memcpy when AVX is not usable or the > > > length does not justify the AVX stuff at all. > > > > OK, fair enough. > > > > Note that a generic version might still be worth trying out, if and only if it's > > safe to access those vector registers directly: modern x86 CPUs will do their > > non-constant memcpy()s via the common memcpy_erms() function - which could in > > theory be an easy common point to be (cpufeatures-) patched to an AVX2 variant, if > > size (and alignment, perhaps) is a multiple of 32 bytes or so. > > How is AVX2 supposed to help the memcpy speed? > > If the copy is small, constant overhead will dominate, and I don't > think AVX2 is going to be win there. There are several advantages: 1) "REP; MOVS" (also called ERMS) has a significant constant "setup cost". In the scheme I suggested (and if it's possible) then single-register AVX2 access on the other hand has a setup cost on the "few cycles" order of magnitude. 2) AVX2 have various non-temporary load and store behavioral variants - while "REP; MOVS" doesn't (or rather, any such caching optimizations, to the extent they exist, are hidden in the microcode). > If the copy is big, well, the copy loop will likely run out of L1 and maybe even > out of L2, and at that point speed of the loop does not matter because memory is > slow...? In many cases "memory" will be something very fast, such as another level of cache. Also, on NUMA "memory" can also be something locally wired to the CPU - again accessible at ridiculous bandwidths. Nevertheless ERMS is probably wins for the regular bulk memcpy by a few percentage points, so I don't think AVX2 is a win in the generic large-memcpy case, as long as continued caching of both the loads and the stores is beneficial. Thanks, Ingo