From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 126656 invoked by alias); 24 Jul 2019 18:56:49 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 126512 invoked by uid 89); 24 Jul 2019 18:56:49 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-14.5 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_HELO_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 24 Jul 2019 18:56:48 +0000 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E109C307D970; Wed, 24 Jul 2019 18:56:45 +0000 (UTC) Received: from localhost.localdomain (ovpn-112-8.rdu2.redhat.com [10.10.112.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1D43C60BF7; Wed, 24 Jul 2019 18:56:42 +0000 (UTC) Subject: Re: [PATCH v4] Generalize get_most_common_single_value to return k_th value & count To: =?UTF-8?Q?Martin_Li=c5=a1ka?= , luoxhu , gcc-patches@gcc.gnu.org Cc: hubicka@ucw.cz, segher@kernel.crashing.org, wschmidt@linux.ibm.com References: <20190715082043.24541-1-luoxhu@linux.ibm.com> <622d5e32-f430-2b07-2902-463f8770e984@suse.cz> <7e334738-324f-1e0d-b368-ac4ce1d9869c@suse.cz> <5d895099-ed2a-66ab-23a7-67c81f8bea9e@linux.ibm.com> <6c388a29-f9fb-9865-18bd-50faabd4f8cf@foxlink.cz> From: Jeff Law Openpgp: preference=signencrypt Message-ID: <69a63575-7b0b-5aff-e0f5-79f3371eb4b1@redhat.com> Date: Wed, 24 Jul 2019 18:57:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: <6c388a29-f9fb-9865-18bd-50faabd4f8cf@foxlink.cz> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-IsSubscribed: yes X-SW-Source: 2019-07/txt/msg01603.txt.bz2 On 7/17/19 1:55 AM, Martin Liška wrote: > On 7/17/19 7:44 AM, luoxhu wrote: >> Hi Martin, >> Thanks for your review, v4 Changes as below: >> 1. Use decrease bubble sort. >> BTW, I have a question about hist->hvalue.counters[2], when will it become >> -1, please? Thanks. Currently, if it is -1, the function will return false. > Hi. > > Thanks for that. I made a minor changes to your patch, please see it in attachment. > -1 is a value that we use for invalidated histogram. That happens when you need > to fit in more values during instrumentation than you have counters in the histogram. > It helps to make reproducible builds of a software. > > Martin > > > most-common-value.patch > > diff --git a/gcc/profile.c b/gcc/profile.c > index 441cb8eb183..1151b491848 100644 > --- a/gcc/profile.c > +++ b/gcc/profile.c > @@ -743,6 +743,44 @@ compute_branch_probabilities (unsigned cfg_checksum, unsigned lineno_checksum) > free_aux_for_blocks (); > } > > +/* Sort the histogram value and count for TOPN and INDIR_CALL types. */ > + > +static void > +sort_hist_values (histogram_value hist) > +{ > + /* counters[2] equal to -1 means that all counters are invalidated. */ > + if (hist->hvalue.counters[2] == -1) > + return; > + > + gcc_assert (hist->type == HIST_TYPE_TOPN_VALUES > + || hist->type == HIST_TYPE_INDIR_CALL); > + > + gcc_assert (hist->n_counters == GCOV_TOPN_VALUES_COUNTERS); > + > + /* Hist value is organized as: > + [total_executions, value1, counter1, ..., value4, counter4] > + Use decrese bubble sort to rearrange it. The sort starts from