From patchwork Thu Apr 27 23:48:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 88415 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp609573vqo; Thu, 27 Apr 2023 17:21:49 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4Xjg6wr5wpImLIicoWU5MTFc+J8jiyWQQhxF/QHZ/1ON/vT60FJEPFNm4MPQL/8ZLehZ6N X-Received: by 2002:a05:6a00:1950:b0:63d:2911:3683 with SMTP id s16-20020a056a00195000b0063d29113683mr5551507pfk.17.1682641309308; Thu, 27 Apr 2023 17:21:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682641309; cv=none; d=google.com; s=arc-20160816; b=KTFp2bpJ752hzHwQiGiWiZlHt937f23rx6hsJyXEgWS7kX+ordUWCEXdeDU0uc5b5z I7NvSV5lg2sQrJ9cJxX2rwg0egzADSBkxUwJwmSuUZ29xqJgnwY9eQzPLG707eeA4rw+ tMEbn0Net5fCMM8bopT2Q2bMnHZlqzsSRmsyeKCMUbbtYgqtAJxIHGpWwjXu5DhjExvu TIc6BSQ+b+my1hQm+RpXQSsg6B1bJ7+qYiA8Knx3JTH+zPUDJKGm9kXKLon+6a+g3UyY ILqc6nVJ5fWrzRilKnH1h3IacmrUxbOQPIfyYgN5iShY4/i420hpulaMoaG4TovY+TGu cwyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=ZNOWzjzDN8/IL6kFuuC3MOAdiIjEwK+a4rVMlscXpEU=; b=pLkvz4yuALjNYByiXbAEjhPMWdg8wWhiH8RRYu9IrpkHL4wHay8dRDtd/Gm4daE4ge PdWruOO9alraB1be9QP9EGSoHOioCSsp00Dua3yWATAPRpmyBTCcptzZhEgGR4I50uUx hurnCrK8bWaChpPI+jYYl9obVcwQHSfbKC8Nxsf5l28zF7re2aYQSf8jhR+fI/Jhqy9O 2F5G729Ce2mmWluUlVMZlOOBWLC6su7Dv4j/ZheFVmSo+0SYZAfoYLpQ3usp9nsPZ5pl Y1jzPyp5hX2p7JsLx1yJ4SAdDavMs6e6Eg7OTrzxu++urSUufOm4NkJPVuUqrmRWlJPy WO7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=Dy7KxEsS; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i17-20020a056a00005100b0063f1919c66esi17161552pfk.357.2023.04.27.17.21.36; Thu, 27 Apr 2023 17:21:49 -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=@gmail.com header.s=20221208 header.b=Dy7KxEsS; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344449AbjD0Xs6 (ORCPT + 99 others); Thu, 27 Apr 2023 19:48:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344235AbjD0Xsj (ORCPT ); Thu, 27 Apr 2023 19:48:39 -0400 Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 336E61FF5; Thu, 27 Apr 2023 16:48:39 -0700 (PDT) Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-63b7b54642cso6491808b3a.0; Thu, 27 Apr 2023 16:48:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682639318; x=1685231318; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=ZNOWzjzDN8/IL6kFuuC3MOAdiIjEwK+a4rVMlscXpEU=; b=Dy7KxEsSsT4BcpH9K6b7Bs+cMCFyYE7TTBHgYFYjQ+mDHmmEDEU9IOttf5pPaZ1bJ5 z8m5jSGjO573huyo5zG7pA4Q14nWilvb35KzW6HFdRPALYZEnCqpt/YeXb61HwrsWVyR P2LgiH92QNwB5cLsxbzcJb7dQD8oTmqkoSVmjAb4aosfoQP7AvrsHOovgixa6Ui00hRj XhIcXf78a7NBr8mZW4u2pFW35l4UjEkXFuQ1pouT6JzfZmAE0x5QXhWgz38qhLmz2gQN 7LpHDF/hjaBqtaPrnESEriRZzn6gawMAkamuNwHq+V3Xw2zc4xPCxJuRqQBqz8su1rbH u5GQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682639318; x=1685231318; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=ZNOWzjzDN8/IL6kFuuC3MOAdiIjEwK+a4rVMlscXpEU=; b=GgE2b5KOuP2Csv05tVln/FZuO2uh7ayktKswz5m1mD+Ke+JY71/QES+RaJHsF+80JX yG72AbBfbL9JTB0ypbFxLbW9gUvV09jFSHGcmfd9azjYK3AuZO9jsrycP8uWA7k/PCnC lf0k3G5vl2kDZzHvObRNHpgvvOxNU6roLI+m+Hvqyzlc8ObyJEgT3E+pBiH2vMmupVhN dP69X8AWVQ96M4est5v0X8pV8xtDuCcAj5psbS/K7BhG60FzJiVkAQVPvzVEZBMd5nrK or94XVt2ptKAkyxeVeCa2dQ2Xan/CaUSM1m5Easph7FwVJp/n8xaHYaApbj+AEHlqn57 W2Zg== X-Gm-Message-State: AC+VfDzcU6dFE72FM0+hCuyzZveohXWdKn0aztvJvSJyDs7qlrP/qiGr 8GlHmFddqsbAo+dP+H1GtY8= X-Received: by 2002:a05:6a00:24c4:b0:640:f220:d16e with SMTP id d4-20020a056a0024c400b00640f220d16emr5154594pfv.11.1682639318519; Thu, 27 Apr 2023 16:48:38 -0700 (PDT) Received: from moohyul.svl.corp.google.com ([2620:15c:2d4:203:55cd:594d:edb:e780]) by smtp.gmail.com with ESMTPSA id p5-20020a056a000b4500b0062a56e51fd7sm13769425pfo.188.2023.04.27.16.48.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Apr 2023 16:48:38 -0700 (PDT) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ian Rogers , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, bpf@vger.kernel.org, Andrii Nakryiko , Hao Luo , Song Liu , Andrii Nakryiko Subject: [PATCH 2/2] perf lock contention: Rework offset calculation with BPF CO-RE Date: Thu, 27 Apr 2023 16:48:33 -0700 Message-ID: <20230427234833.1576130-2-namhyung@kernel.org> X-Mailer: git-send-email 2.40.1.495.gc816e09b53d-goog In-Reply-To: <20230427234833.1576130-1-namhyung@kernel.org> References: <20230427234833.1576130-1-namhyung@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764377293795545253?= X-GMAIL-MSGID: =?utf-8?q?1764377293795545253?= It seems BPF CO-RE reloc doesn't work well with the pattern that gets the field-offset only. Use offsetof() to make it explicit so that the compiler would generate the correct code. Fixes: 0c1228486bef ("perf lock contention: Support pre-5.14 kernels") Co-developed-by: Andrii Nakryiko Signed-off-by: Namhyung Kim Acked-by: Ian Rogers --- tools/perf/util/bpf_skel/lock_contention.bpf.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tools/perf/util/bpf_skel/lock_contention.bpf.c b/tools/perf/util/bpf_skel/lock_contention.bpf.c index 30c193078bdb..8d3cfbb3cc65 100644 --- a/tools/perf/util/bpf_skel/lock_contention.bpf.c +++ b/tools/perf/util/bpf_skel/lock_contention.bpf.c @@ -429,21 +429,21 @@ struct rq___new { SEC("raw_tp/bpf_test_finish") int BPF_PROG(collect_lock_syms) { - __u64 lock_addr; + __u64 lock_addr, lock_off; __u32 lock_flag; + if (bpf_core_field_exists(struct rq___new, __lock)) + lock_off = offsetof(struct rq___new, __lock); + else + lock_off = offsetof(struct rq___old, lock); + for (int i = 0; i < MAX_CPUS; i++) { struct rq *rq = bpf_per_cpu_ptr(&runqueues, i); - struct rq___new *rq_new = (void *)rq; - struct rq___old *rq_old = (void *)rq; if (rq == NULL) break; - if (bpf_core_field_exists(rq_new->__lock)) - lock_addr = (__u64)&rq_new->__lock; - else - lock_addr = (__u64)&rq_old->lock; + lock_addr = (__u64)(void *)rq + lock_off; lock_flag = LOCK_CLASS_RQLOCK; bpf_map_update_elem(&lock_syms, &lock_addr, &lock_flag, BPF_ANY); }