Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp2499056imd; Fri, 2 Nov 2018 12:29:56 -0700 (PDT) X-Google-Smtp-Source: AJdET5cmJGz+WDmZ6FQ0kHbH4HJZO/EJZbCvIdrggzD8nARKeofnVsLCtk7Os+cnS4lcydm9HPGZ X-Received: by 2002:a63:5b4a:: with SMTP id l10-v6mr9269873pgm.50.1541186996720; Fri, 02 Nov 2018 12:29:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541186996; cv=none; d=google.com; s=arc-20160816; b=FMu6z0xT/vhGNyBbJQ5H9cnki13j9omj7l+A9jO451NqS7XhS86AIYGX4u8iaMV10S RexYXe4aaJQXvZ7qX/Op7Uiy9s2URObJThLkjVIUVHbqCA3K3qXZujSa1CstRgt2JcvD k4hZldwG3O7x6hRfOM8VTCeMJ53ufM2NMMX4XNeSwP7Z6I0Us1cBZ07iR8dcHImTNtEv 1irJDfLC1NrEk4QNsG/bxAtRAjJcIi79aoKvaLyx8R99h8vEkqZ/RL1/cDTnuezbRft4 oH3RuGWPxQ/e+2a1EpZ67zTVV2V0HkVobXywRt3AIwB2b0t/R2iykmnx+bqaVmE3INx5 DmLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=iC3VDb6WFp9Zf4oRN8zLJcW+rc8403LTmcprf1Vhulk=; b=qnMZiIO7bYlBQ7V5aB8L9Mk76GnkP/jZMtwmOALqk9+4xiYDY3DAtJRmtTL6uH3L9F q48w6t6ndZKP0X6blZkoaLCJCV/FPC7Jo7rf2J/Dn2CPTT7CMjAw/+KNnyP+AB479duF SPBfFdOmfFWzkAKvqk2I9l3ayURzmbnMfZBUkvXMwdW7DM8z3Hs0lVywRFx+LPbMlXw5 2tcQ2P3hGU8U2an7wZSr9dp34L1AJjjdSV2pOup6hL7yE9qcOi3iIXDbmmV3Im2QKu0Z zu54RLdQ+UUwgNwK5PfXt797Lkn6u+SjYFlRIvMaDdtS0lRlYBrp4hER93nBxPn3i0zq El6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ZozdUsSK; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w6-v6si33049271pgp.42.2018.11.02.12.29.41; Fri, 02 Nov 2018 12:29:56 -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=pass header.i=@gmail.com header.s=20161025 header.b=ZozdUsSK; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726846AbeKCEg2 (ORCPT + 99 others); Sat, 3 Nov 2018 00:36:28 -0400 Received: from mail-it1-f194.google.com ([209.85.166.194]:53810 "EHLO mail-it1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725917AbeKCEg2 (ORCPT ); Sat, 3 Nov 2018 00:36:28 -0400 Received: by mail-it1-f194.google.com with SMTP id r12-v6so1858498ita.3; Fri, 02 Nov 2018 12:28:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=iC3VDb6WFp9Zf4oRN8zLJcW+rc8403LTmcprf1Vhulk=; b=ZozdUsSKBBjdTwWah/kjz17GgPiGzL1vdv7eAOGxdRPu6gxVJG7h3/dfivK0HCEXPq sTWXV8Siy3p54TSag/jX2095FnHwjy+yfGwdXu2kPNdfHq2HfRawtfwjUoyXG0pZmuC8 naLeplMRceAooLngUVTZnpcOmeTdnEL/m/mj2+H+qEQmLun3eqQKEg3MHjysaP90eoMb m6tPguw9rQaP66NWgSxUnqSn/cTZF7pkwJSmqgcHO5kWo8g/CGoQMFPWlRx08HyACOJg Gw4Et+hnrrm2b5ZEahe/PnFQo3m6olK+asDqnnXlqYcoB0Y72qMTgtkdLeNduVq3INaL nbzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=iC3VDb6WFp9Zf4oRN8zLJcW+rc8403LTmcprf1Vhulk=; b=G2AX/GtSLsEROmdf3cKqJIYdkAGPRWmQZ9pbmC00V7ixO9QBd7oNpKrqJ3upkNAysg Y3EP3h973bXzsRa7usNf3oyVqebC7uH9bCXqUkUURiOoD9pcRmQUPITuUUZfOwVmkT2k +IR1wtL+LnZUowiNrpn1sJLwbBWRZoS/hEoLjFN9HTN6uqS0H7L66C7Sp9bXOPwWznyi uAseOJOTMAwykVWZijbW+oTjworxDaOJMhYaw3rkc7RN1zreanP+BbR3AEN3i/HkuLO2 6h90jOQyLt6HdOtb3ekvYab/N6XYw1d3rXjj6aR8PQRF4RXjzJV+L51t3LG8TdhZL3NA NAZg== X-Gm-Message-State: AGRZ1gKM2+G8xuZTMEkZrIroxayKycUGTB0ejlzIzVE8nrJy0uoQOTRy JHvzAGNrg4ZwtcPla8gyhcurbjA96qX/X3Sut4M= X-Received: by 2002:a02:601c:: with SMTP id i28-v6mr12075369jac.105.1541186882251; Fri, 02 Nov 2018 12:28:02 -0700 (PDT) MIME-Version: 1.0 References: <313542172.8.1541171544337.JavaMail.zimbra@efficios.com> In-Reply-To: <313542172.8.1541171544337.JavaMail.zimbra@efficios.com> From: Andrew Pinski Date: Fri, 2 Nov 2018 12:27:49 -0700 Message-ID: Subject: Re: Supporting core-specific instruction sets (e.g. big.LITTLE) with restartable sequences To: mathieu.desnoyers@efficios.com Cc: Richard Henderson , Will Deacon , LKML , GNU C Library , "Carlos O'Donell" , Florian Weimer , "Joseph S. Myers" , Szabolcs Nagy , Thomas Gleixner , bmaurer@fb.com, Peter Zijlstra , "Paul E. McKenney" , boqun.feng@gmail.com, davejwatson@fb.com, pjt@google.com, linux-api@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Nov 2, 2018 at 8:12 AM Mathieu Desnoyers wrote: > > Hi Richard, > > I stumbled on these articles: > > - https://medium.com/@jadr2ddude/a-big-little-problem-a-tale-of-big-little-gone-wrong-e7778ce744bb > - https://www.mono-project.com/news/2016/09/12/arm64-icache/ > > and discussed them with Will Deacon. He told me you were looking into gcc atomics and it might be > worthwhile to discuss the possible use of the new rseq system call that has been added in Linux 4.18 > for those use-cases. > > Basically, the use-cases targeted are those where some cores on the system support a larger instruction > set than others. So for instance, some cores could use a faster atomic add instruction than others, which > should rely on a slower fallback. This is also the same story for reading the performance monitoring > unit counters from user-space: it depends on the feature-set supported by the CPU on which the instruction > is issued. Same applies to cores having different cache-line sizes. > > The main problem is that the kernel can migrate a thread at any point between user-space reading the > current cpu number and issuing the instruction. This is where rseq can help. > > The core idea to solve the instruction set issue is to set a mask of cpus supporting the new instruction > in a library constructor, and then load cpu_id, use it with the mask, and branch to either the new or > old instruction, all with a rseq critical section. If the kernel needs to abort due to preemption or > signal delivery, the abort behavior would be to issue the fallback (slow) atomic operation, which > guarantees progress even if single-stepping. > > As long as the load, test and branch is faster than the performance delta between the old and new atomic > instruction, it would be worth it. > > In the case of PMU read from user-space, using rseq to figure out how to issue the PMU read enables a > use-case which is not otherwise possible to do on big.LITTLE. On rseq abort, it would fallback to a > system call to read the PMU counter. This abort behavior guarantees forward progress. > > The second article is about cache line size discrepancy between CPUs. Here again, doing the cacheline > flushing in a rseq critical section could allow tuning it to characteristics of the actual core it is > running on. The fast-path would use a stride fitting the current core characteristics, and if rseq > needs to abort, the slow-path would fall-back to a conservative value which would fit all cores (smaller > cache line size on the overall system). Once again, this abort behavior guarantees forward progress. > This would only work, of course, if cacheline invalidation done on a big core end up being propagated > to other cores in a way that clears all the cache lines corresponding to the one targeted on the big > core. Cache flusing is only one thing that deals with cache line sizes difference. Another thing which either needs to be emulated in the software or disable is the "dc ZVA" instruction which is used in memset. There are most likely eithers too. For an example, dealing with dmb/dsb sizes. Thanks, Andrew > > Thoughts ? > > Thanks, > > Mathieu > > -- > Mathieu Desnoyers > EfficiOS Inc. > http://www.efficios.com