Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp649701imw; Fri, 15 Jul 2022 10:11:53 -0700 (PDT) X-Google-Smtp-Source: AGRyM1slvhv+OzEgwNGfVeQvE1PNglDPU9mEkoq0/fnPFem8OQnMulUwNV9qAaKeE4rT7VlfXmdA X-Received: by 2002:a05:620a:4502:b0:6b4:6c2f:e7b7 with SMTP id t2-20020a05620a450200b006b46c2fe7b7mr10229181qkp.11.1657905113572; Fri, 15 Jul 2022 10:11:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657905113; cv=none; d=google.com; s=arc-20160816; b=b4IWogqi27zYtjDnWdLsf3punUJMwtNXydmqdLREJFIHASiu9v4HLkGjhOrFIiS+Gx pxAIVMt1LyxMiMITCl7jBXuuKs834v6H/eUqUmTqYRgPTwvEJLee6yKNZeTeS7VQ5zv+ 5Qrc+X5f4pLRGmmLGFj+zy/g9jZZTpnBTt/pRcY32Vzsh4Wvee1tW6T5SSHeK3ohEJdW N2siO924VZZW8QFRRpX2q958zSy6j5lz+KEdzGWpvM4SOZm62fKuJmRc089URK0UW00z 0Elkj+6nA9dAU+xnrMhrxdXnP83tc6Rj6r6fRTGsIjuuNXmJksTyhlBZlGKFkY3GC3JO AA4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=tsymxV+5M24pPXH3QqQTNrAk6PRXpSjbDyG398pyk64=; b=QX0J7n7kDhqKtzuryx0smT7h7NXrTY15zl75M9az03+0PG6Srcit4XW32a3Fvpmgb4 zO2C5/R3/3t2aiiDSw6aUoN88RkSdUF+/uzAsA/4wn7Hk/i2ahYXFM0pdh+W+lchheEt uD7ATQyeu2V7v7/ISYy4tWRTTO35L8jEHt9Bb0ZE9c3Muy7rJN9CKSo5tD94tjz5xx85 FYdurv6Rzab4ZggdNM4vZwihFCdr96zQYxaR+WWqqffm6jJjUGVPHgdKl53ZOje7daXr 5ggrmjh2s9TD1bCpHu1+DbUuH+1kZL8HU1qVQyCdA6wRsfQWcWp+e+hZZqLbv4wpVkMo iVEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=PaXFRqZb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z20-20020a05622a029400b0031ed6315f1csi2691315qtw.369.2022.07.15.10.11.36; Fri, 15 Jul 2022 10:11:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=PaXFRqZb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235467AbiGORBy (ORCPT + 99 others); Fri, 15 Jul 2022 13:01:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235394AbiGORBv (ORCPT ); Fri, 15 Jul 2022 13:01:51 -0400 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CFCDC82F87 for ; Fri, 15 Jul 2022 10:01:50 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id az2-20020a05600c600200b003a301c985fcso3144968wmb.4 for ; Fri, 15 Jul 2022 10:01:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=tsymxV+5M24pPXH3QqQTNrAk6PRXpSjbDyG398pyk64=; b=PaXFRqZbS2vYPwidy+gX7fEd/Iz7nWSXaBdLxtE9h5WXaFeqYEWHPyu+jRlMA4k2op xDpCtZ1js6OEfv4SXZtldXyXuBYP/n6dDjhT8WeaM9GeYP/HRLqm1iAuOEZk53gFAD55 Q5CBXBBuNf0BtoIKBW+g+tz1M5yWHoxefZeqv+c7s1U55CF/Yc8hbostSdxWYhzL07J5 zzgwLjaSlqPgNbvtMQ03GI5ONQk+aJUCgSLYJKkEs+5+CemeTIfhCpLTntSKBZPYr4Y3 9AGbsXq6H0eV+NskTVHfa2esu4/u+L0WQIE2nnT05HEXEwUB+6jEOvyIt/n9o+A7GJ9T YI6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=tsymxV+5M24pPXH3QqQTNrAk6PRXpSjbDyG398pyk64=; b=NrPWCmnB9L+m5V4iI1LWD3ZVNKidqH0MR9YLMYeX5PdM6oxRzZCCixTnIf0xqXRrfx q3XNlY5MC/J+4RvW/gI33XkzkA/7+40a73hv2Oj6y9RDDHiLYJVXxOIV4DxicJzszhQC o6M0ch84ltSZjWGOboqL7hrn+2gRVrQCSX/R1LND8jZM51sZUbaFpyVxP7fqwX7OBnvr 0gF64wgrNQbVSTx670jVA0jUU6zuz/b/CEBw318+a/dVQkO3Q/+DAHpIxeh7BGf7Fu7/ ev+nvOqixoL9Sa59U4xTDq4DVA6e/o5wVQlbtXWMkceV/xuw/CEWOVJhfLPB09xrJG0W GnsA== X-Gm-Message-State: AJIora/phkBxxAWkSB9cjS4YjaXs7YDJ4Z+ulvH1k879cu3z2ki6Xn+d YVNCNpaLNlbK8u4i5xIeiyx7pLLOe4IBOPhmJZglrw== X-Received: by 2002:a05:600c:4e8f:b0:3a1:8b21:ebbc with SMTP id f15-20020a05600c4e8f00b003a18b21ebbcmr15406013wmq.149.1657904509095; Fri, 15 Jul 2022 10:01:49 -0700 (PDT) MIME-Version: 1.0 References: <20220614143353.1559597-1-irogers@google.com> In-Reply-To: <20220614143353.1559597-1-irogers@google.com> From: Ian Rogers Date: Fri, 15 Jul 2022 10:01:36 -0700 Message-ID: Subject: Re: [PATCH v2 0/6] Corrections to cpu map event encoding To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , James Clark , Kees Cook , "Gustavo A. R. Silva" , Adrian Hunter , Riccardo Mancini , German Gomez , Colin Ian King , Song Liu , Dave Marchevsky , Athira Rajeev , Alexey Bayduraev , Leo Yan , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Stephane Eranian Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 14, 2022 at 7:33 AM Ian Rogers wrote: > > A mask encoding of a cpu map is laid out as: > u16 nr > u16 long_size > unsigned long mask[]; > However, the mask may be 8-byte aligned meaning there is a 4-byte pad > after long_size. This means 32-bit and 64-bit builds see the mask as > being at different offsets. On top of this the structure is in the byte > data[] encoded as: > u16 type > char data[] > This means the mask's struct isn't the required 4 or 8 byte aligned, but > is offset by 2. Consequently the long reads and writes are causing > undefined behavior as the alignment is broken. > > These changes do minor clean up with const, visibility of functions > and using the constant time max function. It then adds 32 and 64-bit > mask encoding variants, packed to match current alignment. Taking the > address of a packed struct leads to unaligned data, so function > arguments are altered to be passed the packed struct. To compact the > mask encoding further and drop the padding, the 4-byte variant is > preferred. Finally a new range encoding is added, that reduces the > size of the common case of a range of CPUs to a single u64. > > On a 72 CPU (hyperthread) machine the original encoding of all CPUs is: > 0x9a98 [0x28]: event: 74 > . > . ... raw event: size 40 bytes > . 0000: 4a 00 00 00 00 00 28 00 01 00 02 00 08 00 00 00 J.....(......... > . 0010: 00 00 ff ff ff ff ff ff ff ff ff 00 00 00 00 00 ................ > . 0020: 00 00 00 00 00 00 00 00 ........ > > 0 0 0x9a98 [0x28]: PERF_RECORD_CPU_MAP > > Using the 4-byte encoding it is: > 0x9a98@pipe [0x20]: event: 74 > . > . ... raw event: size 32 bytes > . 0000: 4a 00 00 00 00 00 20 00 01 00 03 00 04 00 ff ff J..... ......... > . 0010: ff ff ff ff ff ff ff 00 00 00 00 00 00 00 00 00 ................ > > 0 0 0x9a98 [0x20]: PERF_RECORD_CPU_MAP > > Finally, with the range encoding it is: > 0x9ab8@pipe [0x10]: event: 74 > . > . ... raw event: size 16 bytes > . 0000: 4a 00 00 00 00 00 10 00 02 00 00 00 00 00 47 00 J.............G. > > 0 0 0x9ab8 [0x10]: PERF_RECORD_CPU_MAP > > v2. Fixes a bug in the size computation of the update header > introduced by the last patch (Add range data encoding) and caught > by address sanitizer. > > Ian Rogers (6): > perf cpumap: Const map for max > perf cpumap: Synthetic events and const/static > perf cpumap: Compute mask size in constant time > perf cpumap: Fix alignment for masks in event encoding > perf events: Prefer union over variable length array > perf cpumap: Add range data encoding Ping. There was some feedback on this change but nothing to create a v3. Feedback/acked-by/reviewed-by appreciated. Thanks, Ian > tools/lib/perf/cpumap.c | 2 +- > tools/lib/perf/include/perf/cpumap.h | 2 +- > tools/lib/perf/include/perf/event.h | 61 ++++++++- > tools/perf/tests/cpumap.c | 71 ++++++++--- > tools/perf/tests/event_update.c | 14 +-- > tools/perf/util/cpumap.c | 111 +++++++++++++--- > tools/perf/util/cpumap.h | 4 +- > tools/perf/util/event.h | 4 - > tools/perf/util/header.c | 24 ++-- > tools/perf/util/session.c | 35 +++--- > tools/perf/util/synthetic-events.c | 182 +++++++++++++-------------- > tools/perf/util/synthetic-events.h | 2 +- > 12 files changed, 327 insertions(+), 185 deletions(-) > > -- > 2.36.1.476.g0c4daa206d-goog >