From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: (qmail 19896 invoked from network); 16 Apr 2020 18:19:01 -0000 Received-SPF: pass (mother.openwall.net: domain of lists.openwall.com designates 195.42.179.200 as permitted sender) receiver=inbox.vuxu.org; client-ip=195.42.179.200 envelope-from= Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with UTF8ESMTPZ; 16 Apr 2020 18:19:01 -0000 Received: (qmail 14019 invoked by uid 550); 16 Apr 2020 18:18:59 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 14000 invoked from network); 16 Apr 2020 18:18:58 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=to:cc:references:from:autocrypt:subject:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=0Qi0HDVWGPJkXfVEyxRCoZzpUqh/lrO9FkaHwrFFh24=; b=ga3s9lwVFZ0AmT7MfpsD/6A4JkjXxM7BTdNRZVPmAlGCq6AMmonwyJSBUciYNS3aej g5eh1UD4cqsMvHvXp6Tz8q4jLruWwT7KG5cuKXSzUrnPkyTd3N41O9ZKTk1YJPhViFdx rBcgF0zOA0jxJGJ09+zudIcKix0ZXC7QxiMPi1H/og9SstgBo/QTFctO6buvdH9DATnM ziCbvIgBacFUS3AdtUXZyULiyc+RPICwuaDv4WyvtAU5Did1VLkOLyQ4/IyNplUeS7Ge IXaIIqEOdVvzcTczOpMBQiU+IQA5FczHynAiYmSc8y97IeqzKLVSlYYTIjOgMeQQMHqY r5Cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:references:from:autocrypt:subject :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=0Qi0HDVWGPJkXfVEyxRCoZzpUqh/lrO9FkaHwrFFh24=; b=tmGWipXMQ6YsVL5Q4AgqyKz1KkAguOHShHwu/8zTA3SMtjlk7bYUADKPsj8DCDkJGJ 5ye+qGE1DKj2/lhUecrEN9tzoKvg/mw/fU1s/unfeOL3kk749AvmdVNm7rYyB78Tav5v 8AF3l7TkAaYwiQCm0XrJsR4I8a+f/Mm7lKWSUVUbEDHTBNeLZCWLPv4u557wmc5gMJMj biv5a44zxIaadY43Y60jvrEPZifbtnOZQlHAhBiW603+6HulokgmJSwOVtzKUe6QcX42 ItPKbMScLTWae7QAHOLxQs2uB+NWQ4qc2/xAkFUUIfDPJWXLO/Bc3SpP9iayfjZVFwO4 RHHw== X-Gm-Message-State: AGi0PuaYvwfR9hX+WAcqFveVMP3zKLniP/WCEGgwObPUpZ1otMyuSE8I F5QAfGOqgTVJfQgyWqKMMy3agg== X-Google-Smtp-Source: APiQypLZZaaGyAoCR+wNWbAK6Mh0agBqM55xQz9k4JUpJU4xveM5VRf/8OWz+NxJgSSDPz3+9HaHVg== X-Received: by 2002:a0c:aa51:: with SMTP id e17mr11101535qvb.95.1587061126159; Thu, 16 Apr 2020 11:18:46 -0700 (PDT) To: Rich Felker Cc: Nicholas Piggin , libc-alpha@sourceware.org, musl@lists.openwall.com, linuxppc-dev@lists.ozlabs.org, libc-dev@lists.llvm.org References: <1586931450.ub4c8cq8dj.astroid@bobo.none> <20200415225539.GL11469@brightrain.aerifal.cx> <20200416153756.GU11469@brightrain.aerifal.cx> <4b2a7a56-dd2b-1863-50e5-2f4cdbeef47c@linaro.org> <20200416175932.GZ11469@brightrain.aerifal.cx> From: Adh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XuZ yv0XYxf1WF6dRizwFFbxvUZzIJp3spAao7jLsQj1DbD2s5+S1BW09A0mI/1DjB6EhNN+4bDB SJCOv/ReK3tFJXuj/HbyDrOdoMt8aIFbe7YFLEExHpSk+HgN05Lg5TyTro8oW7TSMTk+8a5M kzaH4UGXTTBDP/g5cfL3RFPl79ubXwARAQABwsFfBBgBCAAJBQJXFRpKAhsMAAoJEKqx7BSn lIjvI/8P/jg0jl4Tbvg3B5kT6PxJOXHYu9OoyaHLcay6Cd+ZrOd1VQQCbOcgLFbf4Yr+rE9l mYsY67AUgq2QKmVVbn9pjvGsEaz8UmfDnz5epUhDxC6yRRvY4hreMXZhPZ1pbMa6A0a/WOSt AgFj5V6Z4dXGTM/lNManr0HjXxbUYv2WfbNt3/07Db9T+GZkpUotC6iknsTA4rJi6u2ls0W9 1UIvW4o01vb4nZRCj4rni0g6eWoQCGoVDk/xFfy7ZliR5B+3Z3EWRJcQskip/QAHjbLa3pml xAZ484fVxgeESOoaeC9TiBIp0NfH8akWOI0HpBCiBD5xaCTvR7ujUWMvhsX2n881r/hNlR9g fcE6q00qHSPAEgGr1bnFv74/1vbKtjeXLCcRKk3Ulw0bY1OoDxWQr86T2fZGJ/HIZuVVBf3+ gaYJF92GXFynHnea14nFFuFgOni0Mi1zDxYH/8yGGBXvo14KWd8JOW0NJPaCDFJkdS5hu0VY 7vJwKcyHJGxsCLU+Et0mryX8qZwqibJIzu7kUJQdQDljbRPDFd/xmGUFCQiQAncSilYOcxNU EMVCXPAQTteqkvA+gNqSaK1NM9tY0eQ4iJpo+aoX8HAcn4sZzt2pfUB9vQMTBJ2d4+m/qO6+ cFTAceXmIoFsN8+gFN3i8Is3u12u8xGudcBPvpoy4OoG Message-ID: <4f824a37-e660-8912-25aa-fde88d4b79f3@linaro.org> Date: Thu, 16 Apr 2020 15:18:42 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: <20200416175932.GZ11469@brightrain.aerifal.cx> Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 8bit Subject: Re: [musl] Powerpc Linux 'scv' system call ABI proposal take 2 On 16/04/2020 14:59, Rich Felker wrote: > On Thu, Apr 16, 2020 at 02:50:18PM -0300, Adhemerval Zanella wrote: >> >> >> On 16/04/2020 12:37, Rich Felker wrote: >>> On Thu, Apr 16, 2020 at 11:16:04AM -0300, Adhemerval Zanella wrote: >>>>> My preference would be that it work just like the i386 AT_SYSINFO >>>>> where you just replace "int $128" with "call *%%gs:16" and the kernel >>>>> provides a stub in the vdso that performs either scv or the old >>>>> mechanism with the same calling convention. Then if the kernel doesn't >>>>> provide it (because the kernel is too old) libc would have to provide >>>>> its own stub that uses the legacy method and matches the calling >>>>> convention of the one the kernel is expected to provide. >>>> >>>> What about pthread cancellation and the requirement of checking the >>>> cancellable syscall anchors in asynchronous cancellation? My plan is >>>> still to use musl strategy on glibc (BZ#12683) and for i686 it >>>> requires to always use old int$128 for program that uses cancellation >>>> (static case) or just threads (dynamic mode, which should be more >>>> common on glibc). >>>> >>>> Using the i686 strategy of a vDSO bridge symbol would require to always >>>> fallback to 'sc' to still use the same cancellation strategy (and >>>> thus defeating this optimization in such cases). >>> >>> Yes, I assumed it would be the same, ignoring the new syscall >>> mechanism for cancellable syscalls. While there are some exceptions, >>> cancellable syscalls are generally not hot paths but things that are >>> expected to block and to have significant amounts of work to do in >>> kernelspace, so saving a few tens of cycles is rather pointless. >>> >>> It's possible to do a branch/multiple versions of the syscall asm for >>> cancellation but would require extending the cancellation handler to >>> support checking against multiple independent address ranges or using >>> some alternate markup of them. >> >> The main issue is at least for glibc dynamic linking is way more common >> than static linking and once the program become multithread the fallback >> will be always used. > > I'm not relying on static linking optimizing out the cancellable > version. I'm talking about how cancellable syscalls are pretty much > all "heavy" operations to begin with where a few tens of cycles are in > the realm of "measurement noise" relative to the dominating time > costs. Yes I am aware, but at same time I am not sure how it plays on real world. For instance, some workloads might issue kernel query syscalls, such as recv, where buffer copying might not be dominant factor. So I see that if the idea is optimizing syscall mechanism, we should try to leverage it as whole in libc. > >> And besides the cancellation performance issue, a new bridge vDSO mechanism >> will still require to setup some extra bridge for the case of the older >> kernel. In the scheme you suggested: >> >> __asm__("indirect call" ... with common clobbers); >> >> The indirect call will be either the vDSO bridge or an libc provided that >> fallback to 'sc' for !PPC_FEATURE2_SCV. I am not this is really a gain >> against: >> >> if (hwcap & PPC_FEATURE2_SCV) { >> __asm__(... with some clobbers); >> } else { >> __asm__(... with different clobbers); >> } > > If the indirect call can be made roughly as efficiently as the sc > sequence now (which already have some cost due to handling the nasty > error return convention, making the indirect call likely just as small > or smaller), it's O(1) additional code size (and thus icache usage) > rather than O(n) where n is number of syscall points. > > Of course it would work just as well (for avoiding O(n) growth) to > have a direct call to out-of-line branch like you suggested. Yes, but does it really matter to optimize this specific usage case for size? glibc, for instance, tries to leverage the syscall mechanism by adding some complex pre-processor asm directives. It optimizes the syscall code size in most cases. For instance, kill in static case generates on x86_64: 0000000000000000 <__kill>: 0: b8 3e 00 00 00 mov $0x3e,%eax 5: 0f 05 syscall 7: 48 3d 01 f0 ff ff cmp $0xfffffffffffff001,%rax d: 0f 83 00 00 00 00 jae 13 <__kill+0x13> 13: c3 retq While on musl: 0000000000000000 : 0: 48 83 ec 08 sub $0x8,%rsp 4: 48 63 ff movslq %edi,%rdi 7: 48 63 f6 movslq %esi,%rsi a: b8 3e 00 00 00 mov $0x3e,%eax f: 0f 05 syscall 11: 48 89 c7 mov %rax,%rdi 14: e8 00 00 00 00 callq 19 19: 5a pop %rdx 1a: c3 retq But I hardly think it pays off the required code complexity. Some for providing a O(1) bridge: this will require additional complexity to write it and setup correctly. > >> Specially if 'hwcap & PPC_FEATURE2_SCV' could be optimized with a >> TCB member (as we do on glibc) and if we could make the asm clever >> enough to not require different clobbers (although not sure if >> it would be possible). > > The easy way not to require different clobbers is just using the union > of the clobbers, no? Does the proposed new method clobber any > call-saved registers that would make it painful (requiring new call > frames to save them in)? As far I can tell, it should be ok.