Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp4273194ybc; Fri, 15 Nov 2019 01:49:51 -0800 (PST) X-Google-Smtp-Source: APXvYqxTuHNO7yorVsIOVmjN30yiN/zxUXwzcViYRpJgEEA1vkH35s79zfLg6P99VQc0FO6od59j X-Received: by 2002:a17:906:70d2:: with SMTP id g18mr12844815ejk.18.1573811391728; Fri, 15 Nov 2019 01:49:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573811391; cv=none; d=google.com; s=arc-20160816; b=FysZayn1a+bLr5FCmUCwmegn+SClW/0I/Qd3mW7K1vLeyJxuCn8tR8v2U7tUkiHtB0 aoaKEGDqsq/8bXetcTIxz/w+cnNo1tBuhjaqEA6laWdK1rcXDmh3+nAIcSrr8qIXmST3 /tlJpCY5HW881WGsoSm8u3zOxqpJq5vqsJkzQcMl8YcslKcZH2GhsXGbTnZoYGDp2SlH KRsmC5hByike4LsfdpSo25ujviQG0sUsv9uufK6Yc0v147mVKO9RSJM+HBRXV+y4Z/K+ KX8aFXjm1aPmzxpK/u/2J/ri4PXt+srQAyamw1hBIz0HPwOjKFCSLgY9L8uk6YC/LXQl QPkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=uj6sdEmIB7g83WHkh7QpIccYXkWRGkoLJ7qlJ5xg4lc=; b=yQdVCrWAn+5FzLTSR6gtKQ+aqxuefKxPsAQnGuIoNNZsS6vfVyR/c7amBpwU9/BGhp fVvVB2djgR/BII4OLYkEnj4aoYOER3FJMGIFvX6hM8bAagvBstgBBImQIwk11mw/aJcb R32Ag69zR3RuFtzGwOUaUNWPycgskuogP11vlBcBMc9EzpC5INuVD9QWJEsI3Ezjxgmj oTOnNOghPubbUaaSn7d4lcaNcqNmQ5bDOJfFQQGjit/sTA2VBlGi20Rwc1yK3cD+SCGe M12U/uLvwjdNAFWlGGoQ8W+4dqmlaYJAFhxmxt/aT8zWUEvG90VMIhvC4aNYre3ZFxdU kl4Q== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y51si6364079edb.29.2019.11.15.01.49.25; Fri, 15 Nov 2019 01:49:51 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727279AbfKOJp5 (ORCPT + 99 others); Fri, 15 Nov 2019 04:45:57 -0500 Received: from out30-44.freemail.mail.aliyun.com ([115.124.30.44]:39137 "EHLO out30-44.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727097AbfKOJp5 (ORCPT ); Fri, 15 Nov 2019 04:45:57 -0500 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R181e4;CH=green;DM=||false|;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04407;MF=shile.zhang@linux.alibaba.com;NM=1;PH=DS;RN=11;SR=0;TI=SMTPD_---0Ti8k6bT_1573811150; Received: from ali-6c96cfdd1403.local(mailfrom:shile.zhang@linux.alibaba.com fp:SMTPD_---0Ti8k6bT_1573811150) by smtp.aliyun-inc.com(127.0.0.1); Fri, 15 Nov 2019 17:45:51 +0800 Subject: Re: [RFC PATCH v3 6/7] scripts/sorttable: Add ORC unwind tables sort concurrently To: Peter Zijlstra 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 References: <20191115064750.47888-1-shile.zhang@linux.alibaba.com> <20191115064750.47888-7-shile.zhang@linux.alibaba.com> <20191115091945.GT4114@hirez.programming.kicks-ass.net> From: Shile Zhang Message-ID: <2a6aa1ca-f26b-3dfd-ecbf-61e37a2a8242@linux.alibaba.com> Date: Fri, 15 Nov 2019 17:45:50 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: <20191115091945.GT4114@hirez.programming.kicks-ass.net> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2019/11/15 17:19, Peter Zijlstra wrote: > On Fri, Nov 15, 2019 at 02:47:49PM +0800, Shile Zhang wrote: > >> @@ -141,21 +306,44 @@ static int do_sort(Elf_Ehdr *ehdr, >> if (r(&s->sh_type) == SHT_SYMTAB_SHNDX) >> symtab_shndx = (Elf32_Word *)((const char *)ehdr + >> _r(&s->sh_offset)); >> - } >> >> +#if defined(SORTTABLE_64) && defined(UNWINDER_ORC_ENABLED) >> + /* locate the ORC unwind tables */ >> + if (!strcmp(secstrings + idx, ".orc_unwind_ip")) { >> + orctable.orc_ip_size = s->sh_size; >> + g_orc_ip_table = (int *)((void *)ehdr + >> + s->sh_offset); >> + } >> + if (!strcmp(secstrings + idx, ".orc_unwind")) { >> + orctable.orc_size = s->sh_size; >> + g_orc_table = (struct orc_entry *)((void *)ehdr + >> + s->sh_offset); >> + } >> +#endif >> + } /* for loop */ >> + >> +#if defined(SORTTABLE_64) && defined(UNWINDER_ORC_ENABLED) > Maybe something like: > > if (g_orc_table && g_orc_ip_table) { > if (pthread_create(...)) > ... > } else if (g_orc_table || g_orc_up_table) { > fprintf(stderr, "incomplete ORC tables...\n"); > } > >> + /* create thread to sort ORC unwind tables concurrently */ >> + if (pthread_create(&orc_sort_thread, NULL, sort_orctable, &orctable)) { >> + fprintf(stderr, >> + "pthread_create orc_sort_thread failed '%s': %s\n", >> + strerror(errno), fname); >> + goto out; >> + } >> +#endif >> if (!extab_sec) { >> fprintf(stderr, "no __ex_table in file: %s\n", fname); >> - return -1; >> + goto out; >> } >> >> if (!symtab_sec) { >> fprintf(stderr, "no .symtab in file: %s\n", fname); >> - return -1; >> + goto out; >> } >> >> if (!strtab_sec) { >> fprintf(stderr, "no .strtab in file: %s\n", fname); >> - return -1; >> + goto out; >> } >> >> extab_image = (void *)ehdr + _r(&extab_sec->sh_offset); >> @@ -192,7 +380,7 @@ static int do_sort(Elf_Ehdr *ehdr, >> fprintf(stderr, >> "no main_extable_sort_needed symbol in file: %s\n", >> fname); >> - return -1; >> + goto out; >> } >> >> sort_needed_sec = &shdr[get_secindex(r2(&sym->st_shndx), >> @@ -205,6 +393,20 @@ static int do_sort(Elf_Ehdr *ehdr, >> >> /* extable has been sorted, clear the flag */ >> w(0, sort_needed_loc); >> + rc = 0; >> >> - return 0; >> +out: >> +#if defined(SORTTABLE_64) && defined(UNWINDER_ORC_ENABLED) >> + { /* to avoid gcc warning about declaration */ >> + void *retval = NULL; > and then here: > > if (orc_sort_thread) { > void *retval = NULL; > pthread_join(...); > ... > } Thank you for your kindly advice! I'll change it in next version. >> + >> + /* wait for ORC tables sort done */ >> + pthread_join(orc_sort_thread, &retval); >> + if (retval) { >> + fprintf(stderr, "%s in file: %s\n", (char *)retval, fname); >> + rc = -1; >> + } >> + } >> +#endif >> + return rc; >> }