Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp6200218ybx; Mon, 11 Nov 2019 05:33:53 -0800 (PST) X-Google-Smtp-Source: APXvYqxoo7yXSrvQ0BHrhDAmerOtcw2e5hpH3BqJibXpZQVZ28FRP8P+ICchwGs/cIYwscQOOvAr X-Received: by 2002:aa7:d391:: with SMTP id x17mr26347213edq.43.1573479233795; Mon, 11 Nov 2019 05:33:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573479233; cv=none; d=google.com; s=arc-20160816; b=nDMAejPXeFbQPR9kYujIMSR1C6Jd+HdLlwSODN6hR/lcYL0v9jhKYDRE7S3nDbEXAy ij8IxsML6CJ5aNK+ZiH9pzm9VWrqY0xzkRcFuE3bbCWXtKs5LQ5YSjVuAnTB9PaKLkKv JOIQss1XsPuV4A1F07wfXNOyvzjm+cWcZAoSOHzD16EknMa1roy/VzTuRb03Twrb6Nx5 rtlHkA+iVQYeAomsx3lmdKjMO385D8bDJt8BU1FZZOFAGgKa3znY/aLciNRt3vS5xALO EneLGpxbjfdZTNV74cjVM7T6orRtiHhg++91XV+aHq+2h2J5y6lJDjoekAHOT7MxqdVP pAzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:user-agent:in-reply-to:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=QPQD8E2XCAm9S6Dc8C7OkBjON/HEZp/bVrno+fWX5wE=; b=dE5A8pfhLevNrXwRvdGKN+42hqD1tmfH6X7ALeFJey7Wn2cU4WJ4pPkL/V8ByYTXyb a/dNSxj3JvuxlFU6Ug99RGs/I9NS+v9+1i7EW7eROk/UfdqhIgnUl4YIVDT6kHtow5zE PVPitpPwb0NGW1SGOoNed9o7rANCyYT7GCztoqy1H33lOxiH7Ie3yDBPp0Y0qHfx9HvC pwNU1D25dRV7p+VxJ/0pzPgE7Mj5TSxN+EcJFllw/aAoD57jFADTVQoLk8AUlR1Ff7iY aRtIadKMCdDDKXdpNKbDuTLgenhGlXQlVE9IaO8iThsxusnQPfWZsBlGcYFC21HEcAMF uUkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=OV5sfXUo; 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=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t17si9872329ejg.44.2019.11.11.05.33.29; Mon, 11 Nov 2019 05:33:53 -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=pass header.i=@redhat.com header.s=mimecast20190719 header.b=OV5sfXUo; 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=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727024AbfKKNbo (ORCPT + 99 others); Mon, 11 Nov 2019 08:31:44 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:23045 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726843AbfKKNbo (ORCPT ); Mon, 11 Nov 2019 08:31:44 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573479103; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QPQD8E2XCAm9S6Dc8C7OkBjON/HEZp/bVrno+fWX5wE=; b=OV5sfXUoaMB5HYcn/7E92v8CxycJJAhN0lFaxFp/oCbcz+EJHUcAPDNAo3Y85amJpp9QDa migcKK71ufzMUxNLQuuhRl2hTlRMg3V77ZOchZ/pwvMichZuG274+ZMsXlA9vnvxITiknT lUV19vvbz80Nwyc+3WxkWYmHKRQduz0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-177-pW-gECs3OH-dVdv8impuaQ-1; Mon, 11 Nov 2019 08:31:40 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1D4901005502; Mon, 11 Nov 2019 13:31:39 +0000 (UTC) Received: from krava (unknown [10.40.205.88]) by smtp.corp.redhat.com (Postfix) with SMTP id F19D6608FB; Mon, 11 Nov 2019 13:31:37 +0000 (UTC) Date: Mon, 11 Nov 2019 14:31:37 +0100 From: Jiri Olsa To: Andi Kleen Cc: jolsa@kernel.org, acme@kernel.org, linux-kernel@vger.kernel.org, Andi Kleen Subject: Re: [PATCH v5 04/13] perf evlist: Maintain evlist->all_cpus Message-ID: <20191111133137.GH12923@krava> References: <20191107181646.506734-1-andi@firstfloor.org> <20191107181646.506734-5-andi@firstfloor.org> MIME-Version: 1.0 In-Reply-To: <20191107181646.506734-5-andi@firstfloor.org> User-Agent: Mutt/1.12.1 (2019-06-15) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: pW-gECs3OH-dVdv8impuaQ-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 07, 2019 at 10:16:37AM -0800, Andi Kleen wrote: SNIP > diff --git a/tools/perf/lib/cpumap.c b/tools/perf/lib/cpumap.c > index d81656b4635e..b9f573438b93 100644 > --- a/tools/perf/lib/cpumap.c > +++ b/tools/perf/lib/cpumap.c > @@ -286,3 +286,46 @@ int perf_cpu_map__max(struct perf_cpu_map *map) > =20 > =09return max; > } > + > +struct perf_cpu_map *perf_cpu_map__merge(struct perf_cpu_map *orig, > +=09=09=09=09=09 struct perf_cpu_map *other) > +{ > +=09int *tmp_cpus; > +=09int tmp_len; > +=09int i, j, k; > +=09struct perf_cpu_map *merged; > + > +=09if (!orig && !other) > +=09=09return NULL; > +=09if (!orig) { > +=09=09perf_cpu_map__get(other); > +=09=09return other; > +=09} > +=09if (!other) > +=09=09return orig; so we bump refcnt for other but not for orig? could you please put to the comment expected results wrt refcnt values for above cases? > +=09if (orig->nr =3D=3D other->nr && > +=09 !memcmp(orig->map, other->map, orig->nr * sizeof(int))) > +=09=09return orig; > +=09tmp_len =3D orig->nr + other->nr; > +=09tmp_cpus =3D malloc(tmp_len * sizeof(int)); > +=09if (!tmp_cpus) > +=09=09return NULL; > +=09i =3D j =3D k =3D 0; > +=09while (i < orig->nr && j < other->nr) { > +=09=09if (orig->map[i] <=3D other->map[j]) { > +=09=09=09if (orig->map[i] =3D=3D other->map[j]) > +=09=09=09=09j++; > +=09=09=09tmp_cpus[k++] =3D orig->map[i++]; > +=09=09} else > +=09=09=09tmp_cpus[k++] =3D other->map[j++]; > +=09} > +=09while (i < orig->nr) > +=09=09tmp_cpus[k++] =3D orig->map[i++]; > +=09while (j < other->nr) > +=09=09tmp_cpus[k++] =3D other->map[j++]; > +=09assert(k <=3D tmp_len); > +=09merged =3D cpu_map__trim_new(k, tmp_cpus); > +=09free(tmp_cpus); > +=09perf_cpu_map__put(orig); > +=09return merged; please use some comments and blank lines to separate the code above, it's too much.. ;-) SNIP > LIBPERF_API int perf_cpu_map__cpu(const struct perf_cpu_map *cpus, int i= dx); > LIBPERF_API int perf_cpu_map__nr(const struct perf_cpu_map *cpus); > diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-t= est.c > index 8b286e9b7549..5fa37cf7f283 100644 > --- a/tools/perf/tests/builtin-test.c > +++ b/tools/perf/tests/builtin-test.c > @@ -259,6 +259,11 @@ static struct test generic_tests[] =3D { > =09=09.desc =3D "Print cpu map", > =09=09.func =3D test__cpu_map_print, > =09}, > +=09{ > +=09=09.desc =3D "Merge cpu map", > +=09=09.func =3D test__cpu_map_merge, > +=09}, awesome ,thanks jirka