Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp170343lqb; Tue, 28 May 2024 11:56:52 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUpPXgGX0s6WyyS/DD619cdg7EsEazHNE45tPBQwzwPGDF74FaBrcEGkeGX7nq7hNvWh9AzVxm+s1KKme92xfYSjJ0UapzuMZ297JOw3A== X-Google-Smtp-Source: AGHT+IFWev/fXu5+jrZrkP1g5SUTNzyfuLDwoWhEjWbw6wPhqrjNyftJ3gLACdTTesLPQ9HwM7XI X-Received: by 2002:a05:6214:4a07:b0:6ab:9213:f250 with SMTP id 6a1803df08f44-6abcd10fc55mr158646236d6.60.1716922612063; Tue, 28 May 2024 11:56:52 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716922612; cv=pass; d=google.com; s=arc-20160816; b=EcsusK51a2DgpoxhUHrkSXt8xKc+heYVX++pOKgEApTvfAS+8lEv1+W4qetvRqUxL8 TTGh3XECwlGjDM+NPNpyRgG6fBJZwnIA9ysib2o+nVMFb1J6nwOQgKRS739tR4S+/MQy fMm7pbkasHwDLtP1Ib2SMcXxJLXEfMqciqCr7DqTElmg60qWxDpacb9h8ymbypkhPJWb O4asdTZXdzMg+N7PiA29fmSzhGhYObP+C62VHdfhu0EQL4+ncG/JvnbxaqP28sl7F5uw vfjVgjC9f8DSce5CI6843U0F3NFqcH+npHWjj89pOIhsBQyCj8rAcdGIiNNJWrJxuIHv rIIA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence; bh=tV2y+zzHtC8fi/GAxZbta7nCZzttI/+j3Qu6+XzqVmY=; fh=kkuyTixVZR4K/dVgP2rrFl1oURz1038GtROoGiY6oU8=; b=ElDYtrx8LkpryMp0VyDpIJF3mRj15335GxA7bWJLgIZrSX0L0hkfTmcKuGqJNj2//+ RWw7HYR0ITaZnkp+BCsvzCge+feiYVbTGh5KOqGc4jzKEpASKtDVJL1sHxBgk2A4hL8F EnBvxePnY0GvFgNomSNG58r072efNUv1py9atlacZTqyztHTlnE5qyS7Z43u/w4kIhek OzVnxHYlTO8D/igJeG0l68jOBhfP29Ndv7KktnHSkbe57gl8+cdXkfOCJkrcTKN0jUP6 uiRNl47ZZx/9RVsiwj8W9qH+EkoGNOUyAcs/VeqwUIXF1M7kslgLSZT+vKnnlc1QGVFA Shfw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-192889-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-192889-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id 6a1803df08f44-6ac0707d632si110263896d6.149.2024.05.28.11.56.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 11:56:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-192889-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-192889-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-192889-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id C8F481C22F24 for ; Tue, 28 May 2024 18:56:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 767D717165D; Tue, 28 May 2024 18:56:46 +0000 (UTC) Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9EECC39FFB; Tue, 28 May 2024 18:56:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716922606; cv=none; b=umK+E708zGcYMdMwhjJHRx8XBwhaZyUU4mIHGi7G/Nji/L61ukqn2G9o+ODUd8f/OMiNsL+12ivKU1fPO9WBh2dOasEGkEaZETCEm6Y26ZXoOnCqG09Femi6IesX1Sb6KiWZU1seeBAlQ2seO4wtnCvfXbAj1i8vfQmkKD3/Hk4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716922606; c=relaxed/simple; bh=1GkxxU7eiisDXTv7dlI9z9uvQ2yOMGG0iM5hZFEjUKs=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=BdBBLww4DUHXtajWF+XOnowE62C3aogZxLfQuKsrajylUBfLoJ7BxQd13uUrSdyXkqJAcgMEeePErYY5GqFGqgcMyse8/MbRuGhv3Yd6QtWhSMKCQc9TglMK0PPjKqc4NrS+AAR45Ja8l7Gved74EJd/EUkUOce1UNxtvmJWbEo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.215.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pg1-f179.google.com with SMTP id 41be03b00d2f7-68185f92bfdso793896a12.0; Tue, 28 May 2024 11:56:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716922604; x=1717527404; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tV2y+zzHtC8fi/GAxZbta7nCZzttI/+j3Qu6+XzqVmY=; b=Apr3e/BSta3V1tuQKozW1RwIYwbH4niIBhIKwmMd8FOOpi5hkBwvOEdA1GdHqfl081 eNXTblRdpLE7d/mJA+tId+rU2XLnejmEH5aE0+SQXMxWdUUf9ueXWTAHz7pWeUN4MWRx 8F99B/FtA0qUK5EcZ6wPJ0Y12OjTXZYQug+xP3itvaQXRTC+/tsyTR1c0PE7KrRGueAY HKATzqo+E5pOKqocLzc8i1rcVttqdhV2LJQZrQEEoK+7hO8sy04DHkzcWanhodRi7hr6 ynFgDEsv7z/JnjAA+zvIgvBJwYCwexaBHIZASk1xehnO3W8r4PAvgJMZPp67nLp6zaU9 EmvQ== X-Forwarded-Encrypted: i=1; AJvYcCVvEeVL04BCoFXKDHb3yXGawDjU3szlxQ5cCg6hbzUNFMWFCG9oc7jfOSpIFFFuwytl5GIcHuYI9BexfxCvAEAt8wQqAmXKKzhifXirKCAbHsvd4IOZoWa32hQnT5vbiqNIA1oUvsoW3CxfgH02yg== X-Gm-Message-State: AOJu0Yx7esCeSQrdKNZUM9MqxObtI76pzimjJ2PhPeW5V58cAnInn6Nc e2HfQwdt1/5P7QuihW9MhYzC9K8AYGpvuhUh1Mm+EwT1dzA3aHGDSCLGf3HUUZ+/rJfug4IMnfE +lx0b+pDlzIYIqcN2i26IWqdk/pA= X-Received: by 2002:a17:90b:30d6:b0:2c0:bc7:63c3 with SMTP id 98e67ed59e1d1-2c00bc76514mr2606961a91.42.1716922603850; Tue, 28 May 2024 11:56:43 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240527090300.17864-1-yskelg@gmail.com> In-Reply-To: <20240527090300.17864-1-yskelg@gmail.com> From: Namhyung Kim Date: Tue, 28 May 2024 11:56:32 -0700 Message-ID: Subject: Re: [PATCH] perf stat: allocation check when calculating cache instance ID To: yskelg@gmail.com Cc: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , "Liang, Kan" , Gautham Shenoy , K Prateek Nayak , skhan@linuxfoundation.org, Austin Kim , shjy180909@gmail.com, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hello Yunseong, On Mon, May 27, 2024 at 2:06=E2=80=AFAM wrote: > > From: Yunseong Kim > > Adds an allocation check for cpu_map before perf_cpu_map__min() accessing I think perf_cpu_map__min() works well with NULL. Thanks, Namhyung > > Signed-off-by: Yunseong Kim > --- > tools/perf/builtin-stat.c | 24 +++++++++++++----------- > 1 file changed, 13 insertions(+), 11 deletions(-) > > diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c > index 35f79b48e8dc..1f238824abb2 100644 > --- a/tools/perf/builtin-stat.c > +++ b/tools/perf/builtin-stat.c > @@ -1291,20 +1291,22 @@ static struct option stat_options[] =3D { > */ > static int cpu__get_cache_id_from_map(struct perf_cpu cpu, char *map) > { > - int id; > + int id =3D cpu.cpu; > struct perf_cpu_map *cpu_map =3D perf_cpu_map__new(map); > > - /* > - * If the map contains no CPU, consider the current CPU to > - * be the first online CPU in the cache domain else use the > - * first online CPU of the cache domain as the ID. > - */ > - id =3D perf_cpu_map__min(cpu_map).cpu; > - if (id =3D=3D -1) > - id =3D cpu.cpu; > + if (cpu_map) { > + /* > + * If the map contains no CPU, consider the current CPU t= o > + * be the first online CPU in the cache domain else use t= he > + * first online CPU of the cache domain as the ID. > + */ > + id =3D perf_cpu_map__min(cpu_map).cpu; > + if (id =3D=3D -1) > + id =3D cpu.cpu; > > - /* Free the perf_cpu_map used to find the cache ID */ > - perf_cpu_map__put(cpu_map); > + /* Free the perf_cpu_map used to find the cache ID */ > + perf_cpu_map__put(cpu_map); > + } > > return id; > } > -- > 2.34.1 >