Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp799571ybx; Wed, 6 Nov 2019 08:36:02 -0800 (PST) X-Google-Smtp-Source: APXvYqyYo/7B/+cZPi52ZjRepzZ03vrpw6AY+Rpk6W7NW7Fx84vPNplsmEo0nicJ7eCvM8d13KbM X-Received: by 2002:a17:906:4dda:: with SMTP id f26mr13052121ejw.89.1573058162742; Wed, 06 Nov 2019 08:36:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573058162; cv=none; d=google.com; s=arc-20160816; b=hjVVcqHXNwoCsvC4o+QriC3hSX9SSJQOWQSUf1Zs+eeE1xySMlnYsj42LsmPls1T0t izlSGKD8MFKRDHb5zjjv8L3HYj/XS7B5fxs4gEnHgEFw/zqC8yWgpwVK/bNNK6Knr4so IrPcRK1U10oHWlzKNMrQX3/+SyWh54XHHRMvX/Bngn1t068MTiQWaL6wDVUCvCV+nlQk CA9l3pc1R0bPYRG5sn3nmrqRbOGwQRvoWiwQcrWU+QDnkpKbitFI5mvxKfGfNw41yQ/r kD1AS9PVQUJ59keqUwfbc6A6/9wEiuggCz/ixEkQ8+BEuxSSBizA8X9HM05+s3idglM1 DVfw== 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=gJWB8dxPoxVQ+gdnfTIOzPdZmHOHb8gqaBS6cJrX02Q=; b=TGIO+bq/YOqc+sLy1550bH+R4TbLHurvek2z4iKbckSTIZag1yZFln9T+BBI62OZQm Ej+eEw5ZSXrWruVL00Q0RR0T7vlngaSSeoLP+eIvxGtQPwdqf7fMvmMSPZoV2WOqeSc7 CygsncVQkr9InHV0EEfEmBRK1RfRWnSeeouZqmJEok9fW7arbvRaGL+I6Uc10qh5LVF9 w4y3Zu6XMF3r4xwZbZCQ8rUQryEne03XdOKETZfL8I7sTqov2lZ4xajCGyJm/E/y34PB p3pNQeE8EPkb/c/eqtXckSXoVJUlQbwNEUxzLy+DwjLSfOjGGseVkboIewtQbbeeZ4zy 8l7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=U1naSvuP; 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 p17si1244189edm.269.2019.11.06.08.35.39; Wed, 06 Nov 2019 08:36:02 -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=U1naSvuP; 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 S1732290AbfKFQeP (ORCPT + 99 others); Wed, 6 Nov 2019 11:34:15 -0500 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:37340 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727570AbfKFQeO (ORCPT ); Wed, 6 Nov 2019 11:34:14 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573058054; 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=gJWB8dxPoxVQ+gdnfTIOzPdZmHOHb8gqaBS6cJrX02Q=; b=U1naSvuPwRqKkmxAR3nu7G/wPb06bXZec06D1TBR32Bt/eKRxAnOv74zJDBV1GhOesAnQS C5JC2MBRyFc2p0sjvuKW0yw3FtiOYX7WNOUBcw4QyXMj+k82VBaSkl4JsG2JWKoGxQGeIY +inbz7M8b/SEgGuRFWQLDjsU/itg1WI= 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-77-LXNUEEhONT2QWwy3pijlmQ-1; Wed, 06 Nov 2019 11:34:10 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5EE0B1005500; Wed, 6 Nov 2019 16:34:09 +0000 (UTC) Received: from krava (ovpn-204-115.brq.redhat.com [10.40.204.115]) by smtp.corp.redhat.com (Postfix) with SMTP id 00C2D60BF4; Wed, 6 Nov 2019 16:34:07 +0000 (UTC) Date: Wed, 6 Nov 2019 17:34:07 +0100 From: Jiri Olsa To: Andi Kleen Cc: acme@kernel.org, jolsa@kernel.org, linux-kernel@vger.kernel.org, Andi Kleen Subject: Re: [PATCH v4 3/9] perf evlist: Maintain evlist->all_cpus Message-ID: <20191106163407.GN30214@krava> References: <20191105002522.83803-1-andi@firstfloor.org> <20191105002522.83803-4-andi@firstfloor.org> MIME-Version: 1.0 In-Reply-To: <20191105002522.83803-4-andi@firstfloor.org> User-Agent: Mutt/1.12.1 (2019-06-15) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-MC-Unique: LXNUEEhONT2QWwy3pijlmQ-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 Mon, Nov 04, 2019 at 04:25:16PM -0800, Andi Kleen wrote: > From: Andi Kleen >=20 > Maintain a cpumap in the evlist that is the union of all the cpus > of the events. >=20 > This needs a cpumap merge operation. To make the merge operation > work efficiently maintain the cpumap in a sorted state. >=20 > The sorting is also needed for the affinity loop changes later. >=20 > Signed-off-by: Andi Kleen > --- > tools/perf/lib/cpumap.c | 42 ++++++++++++++++++++++++ > tools/perf/lib/evlist.c | 1 + > tools/perf/lib/include/internal/evlist.h | 1 + > tools/perf/lib/include/perf/cpumap.h | 2 ++ > 4 files changed, 46 insertions(+) >=20 > diff --git a/tools/perf/lib/cpumap.c b/tools/perf/lib/cpumap.c > index 2ca1fafa620d..5ca26a9d318f 100644 > --- a/tools/perf/lib/cpumap.c > +++ b/tools/perf/lib/cpumap.c > @@ -68,6 +68,11 @@ static struct perf_cpu_map *cpu_map__default_new(void) > =09return cpus; > } > =20 > +static int cmp_int(const void *a, const void *b) > +{ > +=09return *(const int *)a - *(const int*)b; > +} > + > static struct perf_cpu_map *cpu_map__trim_new(int nr_cpus, int *tmp_cpus= ) > { > =09size_t payload_size =3D nr_cpus * sizeof(int); > @@ -76,6 +81,7 @@ static struct perf_cpu_map *cpu_map__trim_new(int nr_cp= us, int *tmp_cpus) > =09if (cpus !=3D NULL) { > =09=09cpus->nr =3D nr_cpus; > =09=09memcpy(cpus->map, tmp_cpus, payload_size); > +=09=09qsort(cpus->map, nr_cpus, sizeof(int), cmp_int); > =09=09refcount_set(&cpus->refcnt, 1); > =09} =20 please move the sort into separate change > =20 > @@ -272,3 +278,39 @@ int perf_cpu_map__max(struct perf_cpu_map *map) > =20 > =09return max; > } > + > +struct perf_cpu_map *perf_cpu_map__update(struct perf_cpu_map *orig, > +=09=09=09=09=09 struct perf_cpu_map *other) > +{ it's more like perf_cpu_map__merge, right? > +=09int *tmp_cpus; > +=09int tmp_len; > +=09int i, j, k; > +=09struct perf_cpu_map *merged; > + > +=09if (!orig) { > +=09=09perf_cpu_map__get(other); > +=09=09return other; > +=09} > +=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=09tmp_cpus[k++] =3D orig->map[i++]; > +=09=09else > +=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 < tmp_len); > +=09merged =3D cpu_map__trim_new(k, tmp_cpus); > +=09free(tmp_cpus); > +=09return merged; > +} this is great function for automated test, please add thanks, jirka