Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp4243063ybc; Fri, 15 Nov 2019 01:09:21 -0800 (PST) X-Google-Smtp-Source: APXvYqyFK/SvJEVqS5BwWNxAukp5SPciseEApARE/sCVmpeH3FkNvpyU2h06jLAzkLWFPP6hxTNZ X-Received: by 2002:a17:906:8054:: with SMTP id x20mr12157242ejw.68.1573808961832; Fri, 15 Nov 2019 01:09:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573808961; cv=none; d=google.com; s=arc-20160816; b=Hth6RQKCDr63hjpEsR2KSDjdrQgsDP7JwTmsvVTRkRsz2YNywJY1ri9gKd2xZZLJrA zDDQCIqWqKENFgK8VsHEk2IMqZCPMWfhDfqwgVxP9/oJr2ykukFyOSAx/flpmRVYvnSK OIDH2fiBEtjMH2prmIP7YSgmJOkWicDlc1iO9ElyZqIZolqNzjYINWAK1k1DqHWVQRVC 8ysCO0Slnvpsk8PxJU+McHyt4zAmoQl+0nmeNn8RwxBdQfL3gcbmhFNvM7sZWcNJhzyc ovUHbJnB8EGL2BFJEbURinO5enSZPNNC8CIdoRR4Fucjx1PDtMx4MqMdrxxE5AdsDMdW z5dQ== 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; bh=Wywu5hu/w55f41qJ3KYVl1DQLx0MMhrbVYtcMb7LQiU=; b=F2XiVISQPG9xsQL8ytVfpSLrvmu2BV1lDuCP6TmUEOBnwD8oVzQT4GWnQGmkysaQEN k/m+94bDl87FeCP+Y1JjHD4P+NUj+q+KGnSlsG6MQinvWml6ZT17+H1itl1Y7CK8oYLK DTuM7k+btvF4mpTEwXDg6i14PNxUEuYf7crX1PAsnWw3bL4kVP+e+kg4Nn2W86RNo4Ej 3swpmn2Xt6U/1BoQGnnxUR8ohZskHRAlIYx5+WQWmWfkzL+iFpwDeTsBK8It9Rq9Oywy btCA20PdBwJiGxQCHKZYwmxe5aBL7gZyyLBNg7dXXmywjl+85V35b5Wq8nZZVnxe0MXa ywWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=temperror (dns failure for signature) header.i=@infradead.org header.s=merlin.20170209 header.b=JWRjfXgp; 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 f2si5294784ejd.369.2019.11.15.01.08.56; Fri, 15 Nov 2019 01:09:21 -0800 (PST) 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=temperror (dns failure for signature) header.i=@infradead.org header.s=merlin.20170209 header.b=JWRjfXgp; 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 S1727077AbfKOJHn (ORCPT + 99 others); Fri, 15 Nov 2019 04:07:43 -0500 Received: from merlin.infradead.org ([205.233.59.134]:58230 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725829AbfKOJHn (ORCPT ); Fri, 15 Nov 2019 04:07:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=Wywu5hu/w55f41qJ3KYVl1DQLx0MMhrbVYtcMb7LQiU=; b=JWRjfXgpPe6mraasyPv85Cjqn JaxLy+jW5A0DomqL9rwK1XYh3zaMv41Aba5AOFAijR84ffzJlP1U9rkH3XBBFAT1UfAjU4vBYLv18 3zrmPWrqyA+zJcXIxPXpw2LznWr5vG4orDqm81t+MXBevKEI3PpOcdeLx7aAD+xfiKdMHaIgGVo1j d1MfTT9OJl2Q8GvqGdHguyOHBYuUq+7Ta+m8/2I2wXwoIJSmd9h/m8jnQJxR5rhMowtI6AfPWyH60 OlGSU9b9hXiZ4IF02OF9e9fYITev46N50c3IElq0NQyJAqnvMwxE9qYWAWjJQu5q+JX/gbCbeSQ1O uIbNewhmw==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1iVXZe-000558-Pg; Fri, 15 Nov 2019 09:07:26 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 8A9C1303DDD; Fri, 15 Nov 2019 10:06:15 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 96C1F29E4EBA3; Fri, 15 Nov 2019 10:07:23 +0100 (CET) Date: Fri, 15 Nov 2019 10:07:23 +0100 From: Peter Zijlstra To: Shile Zhang Cc: Josh Poimboeuf , Masahiro Yamada , Michal Marek , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H . Peter Anvin" , linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org Subject: Re: [RFC PATCH v3 6/7] scripts/sorttable: Add ORC unwind tables sort concurrently Message-ID: <20191115090723.GS4114@hirez.programming.kicks-ass.net> References: <20191115064750.47888-1-shile.zhang@linux.alibaba.com> <20191115064750.47888-7-shile.zhang@linux.alibaba.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191115064750.47888-7-shile.zhang@linux.alibaba.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Nov 15, 2019 at 02:47:49PM +0800, Shile Zhang wrote: > +#if defined(SORTTABLE_64) && defined(UNWINDER_ORC_ENABLED) > +/* ORC unwinder only support X86_64 */ > +#include > +#include > +#include > + > +#define ORC_REG_UNDEFINED 0 > +#define ERRSTRING_MAXSZ 256 > + > +struct orc_entry { > + s16 sp_offset; > + s16 bp_offset; > + unsigned sp_reg:4; > + unsigned bp_reg:4; > + unsigned type:2; > + unsigned end:1; > +} __attribute__((packed)); > + > +struct orctable_info { > + size_t orc_size; > + size_t orc_ip_size; > +} orctable; There's ./arch/x86/include/asm/orc_types.h for this. Please don't duplicate. objtool uses that same header. > +/** > + * sort - sort an array of elements > + * @base: pointer to data to sort > + * @num: number of elements > + * @size: size of each element > + * @cmp_func: pointer to comparison function > + * @swap_func: pointer to swap function > + * > + * This function does a heapsort on the given array. You may provide a > + * swap_func function optimized to your element type. > + * > + * Sorting time is O(n log n) both on average and worst-case. While > + * qsort is about 20% faster on average, it suffers from exploitable > + * O(n*n) worst-case behavior and extra memory requirements that make > + * it less suitable for kernel use. > + * > + * This code token out of /lib/sort.c. > + */ > +static void sort(void *base, size_t num, size_t size, > + int (*cmp_func)(const void *, const void *), > + void (*swap_func)(void *, void *, int size)) > +{ > + /* pre-scale counters for performance */ > + int i = (num/2 - 1) * size, n = num * size, c, r; > + > + /* heapify */ > + for ( ; i >= 0; i -= size) { > + for (r = i; r * 2 + size < n; r = c) { > + c = r * 2 + size; > + if (c < n - size && > + cmp_func(base + c, base + c + size) < 0) > + c += size; > + if (cmp_func(base + r, base + c) >= 0) > + break; > + swap_func(base + r, base + c, size); > + } > + } > + > + /* sort */ > + for (i = n - size; i > 0; i -= size) { > + swap_func(base, base + i, size); > + for (r = 0; r * 2 + size < i; r = c) { > + c = r * 2 + size; > + if (c < i - size && > + cmp_func(base + c, base + c + size) < 0) > + c += size; > + if (cmp_func(base + r, base + c) >= 0) > + break; > + swap_func(base + r, base + c, size); > + } > + } > +} Do we really need to copy the heapsort implementation? That is, why not use libc's qsort() ? This is userspace after all.