From patchwork Sun Jan 8 06:23:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 40482 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1588879wrt; Sat, 7 Jan 2023 22:25:24 -0800 (PST) X-Google-Smtp-Source: AMrXdXu6Yq8z7ZxS1DpwkKBGb9YjcmApj2t0aHLINfOyXPzHMJFEAOrk06LrI35XleTXL2gmsGRo X-Received: by 2002:aa7:cb88:0:b0:499:8849:5fb8 with SMTP id r8-20020aa7cb88000000b0049988495fb8mr886888edt.30.1673159124743; Sat, 07 Jan 2023 22:25:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673159124; cv=none; d=google.com; s=arc-20160816; b=zV6Lo5jI6heKlMRVZIxj20amKBJ43zms/60XOVqbrmDs5i/X5NVy6go27ZYbAP7v+A 6dywkCrEIrSyqWoOWKazOwgryGLv6gqAMCC3gFLpgd6VK6syJsZu2iYIRg9h9HklFS+V 3e7QjnXGYiEiUFojoS5joCh0D61gbx/hZ6N0qgd8gYn5ewHyi/ygAbkkTBxM5SpMVx24 fevWC0vfkGuZG9Gs2bPZseTJV88JczBcJ2JDBMjS1EaQKj7jMMZpjj+CJlw9rZYKkzLl Om+NVr491r5U+GTh2L4p0LbPjpmqIkyHinnsvhgZLgC8I7be69JjYrqbr61A/75kBqbr NM2Q== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=QeoGX28pohH6YTyGGTvoqbUNJvhignnE3xBPpX1iJkM=; b=qweS6xVBE2/SiYX6p/znLl2vfuxr7CdWSXLi50I2j3pOlf7niQQrT9n9no5zMzjlSN 6LrK9UOklJsrtC0C9XPlwl+6rojPGzTtyCnvnt2Xm7ijNVVucnKjyuEhSzlOkrb7dsIA J3yrZ5pQDitiOyUM8khdEuT1eUtxc1WHxx+Jk540dxji2Zrjuqf+BO9NlgWJg/gkkBW5 xVDoL2/+Wc19JILpBMGTymFuYJzr/yxFLxZp/pPiv/RmnJFE4M4sSP84uavRaOrUYRzB kw1eYOajYJU+NUfOIcNzS1jwepL0me00qrsS0vTNzZCVXnhQ4puWez51JI+QaQ/0nXw+ PvoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=oPpOYvzG; 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=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m8-20020a509988000000b0048e8835b929si6845483edb.200.2023.01.07.22.24.55; Sat, 07 Jan 2023 22:25:24 -0800 (PST) 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=@linaro.org header.s=google header.b=oPpOYvzG; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231269AbjAHGYX (ORCPT + 99 others); Sun, 8 Jan 2023 01:24:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229627AbjAHGYS (ORCPT ); Sun, 8 Jan 2023 01:24:18 -0500 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F1181EADF for ; Sat, 7 Jan 2023 22:24:16 -0800 (PST) Received: by mail-pj1-x1029.google.com with SMTP id q64so5638522pjq.4 for ; Sat, 07 Jan 2023 22:24:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=QeoGX28pohH6YTyGGTvoqbUNJvhignnE3xBPpX1iJkM=; b=oPpOYvzGEBhoEz7H0UVS3gcV6apwfYI5SqyEAXBIMM2i0CZVkACiJXbX4PeL0h0kw+ 7ufDhbcnKdFJL8ZA6DdJfaFkzvg8ZHoCoXKL3n0sP4UlUBkggg9o5BJkGso6Idvh1p7P YNmzdHPDRHEgf7Iw1aIQlPlk3vNzAGNFHhHes/m5V0Uu3VYnMDjJSAcQQLAQPqiDqL8n NZj3MbWLlaUSIg8NZCnHnrsUVUJ4S8GMbWhr+IT2NZmJq9UFn0cJ1EH4qZJ2gH+2TMKg yhESY87lPfYMASmA1h0/1Hf3xsvKxzsQSFroPnCa2ndPVgfVV1Y/2xQnBFYgEaR0pA2S vN0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=QeoGX28pohH6YTyGGTvoqbUNJvhignnE3xBPpX1iJkM=; b=tLcrATiIg1uTxqsXzN3zcMfBFq6x8iZIHNlXwwIsnboq3dVg6Vovttm5xXSDgEMvRz aXySbvKt86wyNTlZWoCo3yBt1/JBEfvwvTIycuBKPdWp9x4ysWEgTb4oCCkd4ltR+YpT vDjxNI9xezdu5bZH6ObDXcfERtLkY4wzBKNIsMOEh9xXBpjoHzaGpFNOnaKeUhCxSpxd 3ur4Pnk5z45cCvuXIXCsRtecuFQi3Uz9xMbecev4DG+V2kGsjrSR8h2CDZnymE/WoPlx dXBynH0PkltImGrWwQo2FUH7EAd/AS9gwT32z/2JhF/XuH5K4yTa3W9xg8t8sJ9r3hW+ Cbvw== X-Gm-Message-State: AFqh2kpkrqxhkonkG+N590/rLNOBleoHFA54IlGxUHCzpqUNNi/NdG4l fka5F7CQkAdH/OcFYDQk5cMn8w== X-Received: by 2002:a05:6a20:d38c:b0:af:a276:2f94 with SMTP id iq12-20020a056a20d38c00b000afa2762f94mr77308581pzb.35.1673159055712; Sat, 07 Jan 2023 22:24:15 -0800 (PST) Received: from leoy-huanghe.lan (211-23-48-221.hinet-ip.hinet.net. [211.23.48.221]) by smtp.gmail.com with ESMTPSA id s1-20020a63f041000000b004784cdc196dsm3146510pgj.24.2023.01.07.22.24.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Jan 2023 22:24:15 -0800 (PST) From: Leo Yan To: Arnaldo Carvalho de Melo , Ravi Bangoria , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Vlastimil Babka , Hyeonggon Yoo <42.hyeyoo@gmail.com>, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Leo Yan Subject: [PATCH 1/2] perf kmem: Support legacy tracepoints Date: Sun, 8 Jan 2023 14:23:59 +0800 Message-Id: <20230108062400.250690-1-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham 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?1754434502251497507?= X-GMAIL-MSGID: =?utf-8?q?1754434502251497507?= Commit 11e9734bcb6a ("mm/slab_common: unify NUMA and UMA version of tracepoints") removed tracepoints 'kmalloc_node' and 'kmem_cache_alloc_node', these two tracepoints have disappeared in the latest kernel, but we also need to consider the tool should be backward compatible with old kernels. If detects the tracepoint "kmem:kmalloc_node" is existed on a system, this patch enables the legacy tracepoints, otherwise, it will ignore them for the new kernels. Reported-by: Ravi Bangoria Fixes: 11e9734bcb6a ("mm/slab_common: unify NUMA and UMA version of tracepoints") Signed-off-by: Leo Yan Reviewed-by: James Clark --- tools/perf/builtin-kmem.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c index e20656c431a4..50a3df5dc18a 100644 --- a/tools/perf/builtin-kmem.c +++ b/tools/perf/builtin-kmem.c @@ -1824,6 +1824,19 @@ static int parse_line_opt(const struct option *opt __maybe_unused, return 0; } +static bool slab_legacy_tp_is_exposed(void) +{ + /* + * The tracepoints "kmem:kmalloc_node" and + * "kmem:kmem_cache_alloc_node" have been removed on the latest + * kernel, if the tracepoint "kmem:kmalloc_node" is existed it + * means the tool is running on an old kernel, we need to + * rollback to support these legacy tracepoints. + */ + return IS_ERR(trace_event__tp_format("kmem", "kmalloc_node")) ? + false : true; +} + static int __cmd_record(int argc, const char **argv) { const char * const record_args[] = { @@ -1831,22 +1844,28 @@ static int __cmd_record(int argc, const char **argv) }; const char * const slab_events[] = { "-e", "kmem:kmalloc", - "-e", "kmem:kmalloc_node", "-e", "kmem:kfree", "-e", "kmem:kmem_cache_alloc", - "-e", "kmem:kmem_cache_alloc_node", "-e", "kmem:kmem_cache_free", }; + const char * const slab_legacy_events[] = { + "-e", "kmem:kmalloc_node", + "-e", "kmem:kmem_cache_alloc_node", + }; const char * const page_events[] = { "-e", "kmem:mm_page_alloc", "-e", "kmem:mm_page_free", }; unsigned int rec_argc, i, j; const char **rec_argv; + unsigned int slab_legacy_tp_exposed = slab_legacy_tp_is_exposed(); rec_argc = ARRAY_SIZE(record_args) + argc - 1; - if (kmem_slab) + if (kmem_slab) { rec_argc += ARRAY_SIZE(slab_events); + if (slab_legacy_tp_exposed) + rec_argc += ARRAY_SIZE(slab_legacy_events); + } if (kmem_page) rec_argc += ARRAY_SIZE(page_events) + 1; /* for -g */ @@ -1861,6 +1880,10 @@ static int __cmd_record(int argc, const char **argv) if (kmem_slab) { for (j = 0; j < ARRAY_SIZE(slab_events); j++, i++) rec_argv[i] = strdup(slab_events[j]); + if (slab_legacy_tp_exposed) { + for (j = 0; j < ARRAY_SIZE(slab_legacy_events); j++, i++) + rec_argv[i] = strdup(slab_legacy_events[j]); + } } if (kmem_page) { rec_argv[i++] = strdup("-g"); From patchwork Sun Jan 8 06:24:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 40483 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1590012wrt; Sat, 7 Jan 2023 22:31:05 -0800 (PST) X-Google-Smtp-Source: AMrXdXs7CkE8+08jjmuJA3c5/ODCfSWMZE5J8sIl/o2UdUIWLLVePuK93LvdZKrLIBu5koJ1Jenx X-Received: by 2002:a17:907:d042:b0:7c1:7145:5b3c with SMTP id vb2-20020a170907d04200b007c171455b3cmr46718416ejc.46.1673159464941; Sat, 07 Jan 2023 22:31:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673159464; cv=none; d=google.com; s=arc-20160816; b=hKz/ee6mf04HOLX4vHxdi1JZ8354xSAgrGOQ/kO5plw1Kj6YqCTK6JX3w1mxprZmgx IIMonMYwNr9IrfcUCxp7PTUwgExmU+V7cMbTDbha1Bm6ygX1mTe64ooud9V0cIKdA1fr 3KpGwwkjazYh4zQsBO5BKDucWHyZFTuICvhFsMCbu++LckUc80qZDG3YkIrzeruyZnsM TjE8o0N6HJM6iYwnrc425CIj8HC1Vd+hL5+K0SHN1KzfUEY6O3sBvlpa3Ti2agkoBrxH AXoGnT2ZZYyOPln3ln4FSWF/6vh6MwZccV+zT7bzuczm1MNyW0iF/9IGC49KBQuyAyDW q73A== 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 :dkim-signature; bh=R2N5suS0GnTvzlWBM80TjepEKKn3USjGIlHtbbXe7Gk=; b=a+iOiGejBI97I/R080XeHtyOwotMJ/fwZJvedwLnOpKwl19nqPm1hK4gNIniq1gH9R PEx8heHoow4B/2NG89qybyCaSHUunEf02ZELndkiEMvQ9FwxAD7HJfP7TB7EFkG/9etJ FiSsgh6CMShppMIpFMEWoFJCJea/L9D6twYxkNzvlHYCilFmR+ViW3RPAqBc5sPiy/PU AD301uNGfZrVeuSiYD3Tu8MsJitCnZtEhWdq2k+DFRPi97/YE2cVzb/+5yd42jECGQew LMbWrLRAmJMyr87X4mMRPG1wOqAJEz59W6HxC4/G0wI8fAXCsjFIrHUqaFpkJf8IQUsN 7Q4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=X2VGEwKY; 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=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dt7-20020a170907728700b0083e0ec05041si6502906ejc.541.2023.01.07.22.30.39; Sat, 07 Jan 2023 22:31:04 -0800 (PST) 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=@linaro.org header.s=google header.b=X2VGEwKY; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230435AbjAHGY3 (ORCPT + 99 others); Sun, 8 Jan 2023 01:24:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229482AbjAHGYV (ORCPT ); Sun, 8 Jan 2023 01:24:21 -0500 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C32B1EADD for ; Sat, 7 Jan 2023 22:24:20 -0800 (PST) Received: by mail-pj1-x1029.google.com with SMTP id o1-20020a17090a678100b00219cf69e5f0so9551489pjj.2 for ; Sat, 07 Jan 2023 22:24:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=R2N5suS0GnTvzlWBM80TjepEKKn3USjGIlHtbbXe7Gk=; b=X2VGEwKYZShP9O19V2XqqSk4PNLIVEeSnmbh/ACR/NlfWmKsp3G38aCMqSap1nVK2a FQo1XeubWVQ6TNNHe3InEh2m6rL9B+FeyrtmlSI3jsgHZ/0DFTPFvnYDd9ghed+9jvG/ jbQwcHrz26v91CmbFVV3UHpdfHMh7GNTJUKLpNQ55Yvemk6cVGG6AWriz1wgNvgQPHs3 N5PQS+VCO8/fXwp3Ybf17MBdxtQANLpQrc0j5UEWg2loYiZgZrpyqr9XlYDFzSIJZ4ri gczowKNlErg+tmy5A05BWY9dXmvpa64N/+Tqb6aoWjzTKPdTITvi6Q68KZ7kyvG/QJAT oniw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=R2N5suS0GnTvzlWBM80TjepEKKn3USjGIlHtbbXe7Gk=; b=khgRjNyQT19d6as74gghIOcKNgLBJf6nKJZCuHz6wTak3B08yh9GBJ+LmCMGBUdyZM JV59kO5WeiND6m+0Hvs1oVJTyCr0Jt6M5isQjCB8EUDqKB7gd2Ck5FervNuC/3HZ69gN d+ps8io1ZO+tzD5TivpRDQsEgvGaJ48NAEKpFt0fLr7PvN7yxttP9dgU6Wm1D9+XmezR sfElrGs0caO66ewn1Yjzukf/V4WjmmQkqErCXmqo9ToHZKIOc5Utksvyr96MuTG9OfyI 4YzxvG9nP9kADCpPRu1ncZRLKWaWhhf/jzdDMUYk2HI1xOhdUZScX3lqfKOaW0TbtI6F hcBw== X-Gm-Message-State: AFqh2kqFZZEMKcuyLUrOGVW0EVU4ZslTiZwVN9e1yrRSved+EtPWBnMD IeSB31c83wJ/pGreD/XcW3kHow== X-Received: by 2002:a17:90a:d345:b0:223:f60e:87b5 with SMTP id i5-20020a17090ad34500b00223f60e87b5mr67536167pjx.20.1673159059912; Sat, 07 Jan 2023 22:24:19 -0800 (PST) Received: from leoy-huanghe.lan (211-23-48-221.hinet-ip.hinet.net. [211.23.48.221]) by smtp.gmail.com with ESMTPSA id s1-20020a63f041000000b004784cdc196dsm3146510pgj.24.2023.01.07.22.24.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Jan 2023 22:24:19 -0800 (PST) From: Leo Yan To: Arnaldo Carvalho de Melo , Ravi Bangoria , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Vlastimil Babka , Hyeonggon Yoo <42.hyeyoo@gmail.com>, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Leo Yan Subject: [PATCH 2/2] perf kmem: Support field "node" in evsel__process_alloc_event() Date: Sun, 8 Jan 2023 14:24:00 +0800 Message-Id: <20230108062400.250690-2-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230108062400.250690-1-leo.yan@linaro.org> References: <20230108062400.250690-1-leo.yan@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham 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?1754434859077644102?= X-GMAIL-MSGID: =?utf-8?q?1754434859077644102?= Commit 11e9734bcb6a ("mm/slab_common: unify NUMA and UMA version of tracepoints") adds the field "node" into the tracepoints 'kmalloc' and 'kmem_cache_alloc', so this patch modifies the event process function to support the field "node". If field "node" is existed by checking function evsel__field(), it stats the cross allocation. When the "node" value is NUMA_NO_NODE (-1), it means the memory can be allocated from any memory node, in this case, we don't account it as a cross allocation. After support the field "node" in evsel__process_alloc_event(), evsel__process_alloc_node_event() is duplicate with the previous one, so removes evsel__process_alloc_node_event(). Reported-by: Ravi Bangoria Fixes: 11e9734bcb6a ("mm/slab_common: unify NUMA and UMA version of tracepoints") Signed-off-by: Leo Yan Reviewed-by: James Clark --- tools/perf/builtin-kmem.c | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c index 50a3df5dc18a..8ae0a1535293 100644 --- a/tools/perf/builtin-kmem.c +++ b/tools/perf/builtin-kmem.c @@ -26,6 +26,7 @@ #include "util/string2.h" #include +#include #include #include #include @@ -185,22 +186,33 @@ static int evsel__process_alloc_event(struct evsel *evsel, struct perf_sample *s total_allocated += bytes_alloc; nr_allocs++; - return 0; -} -static int evsel__process_alloc_node_event(struct evsel *evsel, struct perf_sample *sample) -{ - int ret = evsel__process_alloc_event(evsel, sample); + /* + * Commit 11e9734bcb6a ("mm/slab_common: unify NUMA and UMA + * version of tracepoints") adds the field "node" into the + * tracepoints 'kmalloc' and 'kmem_cache_alloc'. + * + * The legacy tracepoints 'kmalloc_node' and 'kmem_cache_alloc_node' + * also contain the field "node". + * + * If the tracepoint contains the field "node" the tool stats the + * cross allocation. + */ + if (evsel__field(evsel, "node")) { + int node1, node2; - if (!ret) { - int node1 = cpu__get_node((struct perf_cpu){.cpu = sample->cpu}), - node2 = evsel__intval(evsel, sample, "node"); + node1 = cpu__get_node((struct perf_cpu){.cpu = sample->cpu}); + node2 = evsel__intval(evsel, sample, "node"); - if (node1 != node2) + /* + * If the field "node" is NUMA_NO_NODE (-1), we don't take it + * as a cross allocation. + */ + if ((node2 != NUMA_NO_NODE) && (node1 != node2)) nr_cross_allocs++; } - return ret; + return 0; } static int ptr_cmp(void *, void *); @@ -1369,8 +1381,8 @@ static int __cmd_kmem(struct perf_session *session) /* slab allocator */ { "kmem:kmalloc", evsel__process_alloc_event, }, { "kmem:kmem_cache_alloc", evsel__process_alloc_event, }, - { "kmem:kmalloc_node", evsel__process_alloc_node_event, }, - { "kmem:kmem_cache_alloc_node", evsel__process_alloc_node_event, }, + { "kmem:kmalloc_node", evsel__process_alloc_event, }, + { "kmem:kmem_cache_alloc_node", evsel__process_alloc_event, }, { "kmem:kfree", evsel__process_free_event, }, { "kmem:kmem_cache_free", evsel__process_free_event, }, /* page allocator */