From nobody Sat Nov 23 01:33:45 2024 Received: from mail-ej1-f48.google.com (mail-ej1-f48.google.com [209.85.218.48]) (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 DEBD515B0EF for ; Thu, 14 Nov 2024 16:07:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731600475; cv=none; b=tk4PG8U3Lu3BgTctqVSXv7421nuFGRStP9E7A4CiiGLDJVELWR3RqBF/D3UoPecVW5i2yMRUhXNTKi1WFGi1SvIZVwjR9/EyNpKr6ETB2TwEmv7nGxB5E7B5m+kIiC7nTThhayDNvpp/Dx+MXnmzJyi6UNaJOZVppcOLtxhcANE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731600475; c=relaxed/simple; bh=bzQ9CRjWdecUHtFTM41DyW8czRtgDd01ddhI7LWZXOw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=sLHHOoZzLiTmpV+DH+D1/ZYrX9htox0GekGomJyfbUTHXvneVlcLdh33FqlkuUZ2B7o0pR5j4C6UB895/oALklhq6X9dnVF2XHaM1NwVE0927e9mCqsn3xUCSrgwtM08ldvf5zsW8rUO4QFs4lREC8/KPgY8Bf7iKb5o8bSkx9E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=SZy6P5GT; arc=none smtp.client-ip=209.85.218.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="SZy6P5GT" Received: by mail-ej1-f48.google.com with SMTP id a640c23a62f3a-a9a0c7abaa6so97722466b.2 for ; Thu, 14 Nov 2024 08:07:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1731600472; x=1732205272; darn=vger.kernel.org; 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=G3cdScFAcgvdlRHopcdKPzeCgYcfuZjBjrzryDpj2HE=; b=SZy6P5GT/OqSZe/QYPRkWaTGry9nck/mdkK/ZNEgJHOI/n8imGVOX277m2jXGR2+b5 mEO3eAs9eCdeQmVEnIianGBo+avAjWOhnnx0DCTnpAUs6MG1+vtFyhbskTjQQcMjsARd PcWbNeQA0XwrQLCvhC9K5oshaBqqFEQnbaGvD42vKsRP1cR3+93xVVBoOs6uGR2LvIWY JT/W2wA7lnXc6aM4Mi3UkXmZISATa2TK4HrsqbOq2Pr4AIID9e+dt0OyiqLl4EIyFh/J PQnS4vUOPwIRVvkbncqxFZATm/r6WLmiKyx5AqJqDW+8QBMCg5sv+IlXGq/+WxHGW8rA kl+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731600472; x=1732205272; 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=G3cdScFAcgvdlRHopcdKPzeCgYcfuZjBjrzryDpj2HE=; b=F2wztIALiXhM9F+2wdrT4bJsPmE0qvtN3s74a/ZvzS8llheChzUC0rcClaE0K1/eYs AJVme/2fr7GCO2E4WUanzI2RZzd7cQtGnyPCCom0aXEKVNrFJfN0BSQctg3UOPvSaqgS q81w4fho0z/l6zc4ia14xfkwacssPOaX1LYqoZh40S4iz3LBTk/A9G1EZlWJAvPFXauB HaO6w1eIm8c7A3GER7Os9ta2FlFfTYq51ZcI9CH1O6QoCDgkY5y/nP/UUPm+5EiQzlRL UquKxehhwEov//m0BQuNHXb8cs9OzkVbW1diQR2WpVTJfibZW4KIYDfDPBJj4eH2o6RI 2GmA== X-Forwarded-Encrypted: i=1; AJvYcCVuzoiqY8K6L8B45wrWiEC3Ch/K6Ks3JVqR1L8dagUGiHINux7wh2EFxC0aSQbpwErT+7sRWwiTFADqDhE=@vger.kernel.org X-Gm-Message-State: AOJu0YwfRUgzOIBpAm4NT72smSYbYDjgV+/0sX5Z4yTR4/b/Newzlzv+ Qe8QxhUFBI5eXBM1oYMf9n5aONt7An6Bv4KeKApWQdHJOYgmyNq0/DCSzlc6tL0= X-Google-Smtp-Source: AGHT+IGHoLs6q08SPM4TqfP2UFLFrJQtplNKocJZiNpyTod0sYUFtC3vT9Nx2DHotVltrf59qYc4fg== X-Received: by 2002:a17:907:60d2:b0:a99:e1a1:473f with SMTP id a640c23a62f3a-aa20cdefc8bmr294267166b.57.1731600472062; Thu, 14 Nov 2024 08:07:52 -0800 (PST) Received: from pop-os.. ([145.224.90.214]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa20e046d76sm77456366b.165.2024.11.14.08.07.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 08:07:51 -0800 (PST) From: James Clark To: linux-perf-users@vger.kernel.org, namhyung@kernel.org, irogers@google.com, thomas.falcon@intel.com Cc: James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Adrian Hunter , "Liang, Kan" , linux-kernel@vger.kernel.org Subject: [PATCH v2 1/2] libperf: evlist: Fix --cpu argument on hybrid platform Date: Thu, 14 Nov 2024 16:04:48 +0000 Message-Id: <20241114160450.295844-2-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241114160450.295844-1-james.clark@linaro.org> References: <20241114160450.295844-1-james.clark@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Since the linked fixes: commit, specifying a CPU on hybrid platforms results in an error because Perf tries to open an extended type event on "any" CPU which isn't valid. Extended type events can only be opened on CPUs that match the type. Before (working): $ perf record --cpu 1 -- true [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 2.385 MB perf.data (7 samples) ] After (not working): $ perf record -C 1 -- true WARNING: A requested CPU in '1' is not supported by PMU 'cpu_atom' (CPUs = 16-27) for event 'cycles:P' Error: The sys_perf_event_open() syscall returned with 22 (Invalid argument) for= event (cpu_atom/cycles:P/). /bin/dmesg | grep -i perf may provide additional information. (Ignore the warning message, that's expected and not particularly relevant to this issue). This is because perf_cpu_map__intersect() of the user specified CPU (1) and one of the PMU's CPUs (16-27) correctly results in an empty (NULL) CPU map. However for the purposes of opening an event, libperf converts empty CPU maps into an any CPU (-1) which the kernel rejects. Fix it by deleting evsels with empty CPU maps in the specific case where user requested CPU maps are evaluated. Fixes: 251aa040244a ("perf parse-events: Wildcard most "numeric" events") Reviewed-by: Ian Rogers Tested-by: Thomas Falcon Signed-off-by: James Clark --- tools/lib/perf/evlist.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/tools/lib/perf/evlist.c b/tools/lib/perf/evlist.c index c6d67fc9e57e..83c43dc13313 100644 --- a/tools/lib/perf/evlist.c +++ b/tools/lib/perf/evlist.c @@ -47,6 +47,20 @@ static void __perf_evlist__propagate_maps(struct perf_ev= list *evlist, */ perf_cpu_map__put(evsel->cpus); evsel->cpus =3D perf_cpu_map__intersect(evlist->user_requested_cpus, evs= el->own_cpus); + + /* + * Empty cpu lists would eventually get opened as "any" so remove + * genuinely empty ones before they're opened in the wrong place. + */ + if (perf_cpu_map__is_empty(evsel->cpus)) { + struct perf_evsel *next =3D perf_evlist__next(evlist, evsel); + + perf_evlist__remove(evlist, evsel); + /* Keep idx contiguous */ + if (next) + list_for_each_entry_from(next, &evlist->entries, node) + next->idx--; + } } else if (!evsel->own_cpus || evlist->has_user_cpus || (!evsel->requires_cpu && perf_cpu_map__has_any_cpu(evlist->user_requeste= d_cpus))) { /* @@ -80,11 +94,11 @@ static void __perf_evlist__propagate_maps(struct perf_e= vlist *evlist, =20 static void perf_evlist__propagate_maps(struct perf_evlist *evlist) { - struct perf_evsel *evsel; + struct perf_evsel *evsel, *n; =20 evlist->needs_map_propagation =3D true; =20 - perf_evlist__for_each_evsel(evlist, evsel) + list_for_each_entry_safe(evsel, n, &evlist->entries, node) __perf_evlist__propagate_maps(evlist, evsel); } =20 --=20 2.34.1 From nobody Sat Nov 23 01:33:45 2024 Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.44]) (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 B8F8D176AAF for ; Thu, 14 Nov 2024 16:07:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731600479; cv=none; b=d91677kZdFV/xeP12dWaezxNbRrptP+aOxyz6la1/MR1KZ88v8jxOSoN0Mct/1rkNbcQ8ng50aqnfKNc6hTAJ6rWhaTtWRCPo5cCsqxE/kZOQfQ8k7L0w/sHIN4BVcJ0xSHJRyxBbXpim6otlN3UFutkre604Kr++7Ui75AlXo4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731600479; c=relaxed/simple; bh=vox/7I9HXy64CSs6t4vNkMQC1vHy0/BtTjz+mYyu0w4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=CTzSChkHhZHSENjTIC+TdDG7cfsUISQPDc4eg6EyJQEIdYnPiLk53u+dqUg0skPqnBY105eslFBW3Jm+ss6zk20ecxqG6v1YAqyaJ2Dyep1618ibmYGd07Iw/oXCSGVjubokbo9PfoIJUwc6dZjiFFKy2FJZP4qpeFguasr1GsQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=zXBqGA9Q; arc=none smtp.client-ip=209.85.218.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="zXBqGA9Q" Received: by mail-ej1-f44.google.com with SMTP id a640c23a62f3a-a9ec267b879so146248266b.2 for ; Thu, 14 Nov 2024 08:07:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1731600476; x=1732205276; darn=vger.kernel.org; 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=YZIDmacdaeoxrMctjHNzYY2IWDwMQUUPmHl/BySCTPM=; b=zXBqGA9QOJLZrUX7PKLi9Zt/3fDXdf+MaXH5ZzAa8X+8GbmUmW9SOzmI6PK5p2Kl/O NOqOw6Cz2DPsIzQKwn9V1Z6G/jGGfkVibxNWv9YSeOQq+4vUCk0thY5GcZLme9OG5ajs go2NMRW+8NCVI5o/3LYSGxSfmBk6TcMD8TjRPGp2R7NEthwj20uhx304n7cpHxa8LBrS DsnD54uH37mDwwtoejq4ejkOEKbqyARmiv26aB/wpgeFN0SI6VYsIx9wdFL7UKHoSZ6D 5XGUd2U4j46PRHXNmtcahI2X/o+L10ySN7h2W97NIQhgZfK8t7zZkltOre9Dq7cypvau GR8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731600476; x=1732205276; 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=YZIDmacdaeoxrMctjHNzYY2IWDwMQUUPmHl/BySCTPM=; b=i9W6nrNcWyfG5F1jEtDLCbRxyges/gspBMzneT/bPBwif5RgCnjnEPwM62XxX3jp6D Ap+zw9XgQl6ZSQx/od3PTEl17mvOBSB/BTqkgU7ieLU4bgQxGq69LEd4AZN5p0N3szj/ bfuUKVoNzPjFHQXnEltzsMVdSRL/eD5CDhDtfC0qvILA6scJF3wEJ0X6bfQhFGPBozZv TsXvHwPr4WZUfl9nQjjiZERonHuBFj8rWH/vq1tufndUorWzG4T6JJBa8Aj7CWhoPRjd o8g8J50ppBGor9KXwnxqOEDkgpWjQU7QT/TS5ientyk06TiIDWePFDKowPcsMN+kxsst sxWw== X-Forwarded-Encrypted: i=1; AJvYcCVvRO1wD6DFmOYgzGHH+6vRnqjVEYMqr7omb5r+sVenshRvi0GMTD0vMbPl+/Pp4ZLTWllwr5ERdPWAdlw=@vger.kernel.org X-Gm-Message-State: AOJu0YxZaeejjhozamsjdRRflJMqxL6B0LUvryqlJqSL1Z2eDmN3tFs5 a7XUEmz6fzcPaP9U44ddkBdJEwbCtwUZnNGsmAB3/gN2WcrZgX8CifB/FHhaA8o= X-Google-Smtp-Source: AGHT+IEf9e1HGnaMlTOrKHVcGTf+ARYIkun1J3c+M5cnt+i+oOvgSy7pGBonSAWnf2OYE1vCdHAj9Q== X-Received: by 2002:a17:907:9302:b0:a9a:3f9d:62f8 with SMTP id a640c23a62f3a-aa1f805d27bmr731019566b.19.1731600475958; Thu, 14 Nov 2024 08:07:55 -0800 (PST) Received: from pop-os.. ([145.224.90.214]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa20e046d76sm77456366b.165.2024.11.14.08.07.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 08:07:54 -0800 (PST) From: James Clark To: linux-perf-users@vger.kernel.org, namhyung@kernel.org, irogers@google.com, thomas.falcon@intel.com Cc: James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Adrian Hunter , "Liang, Kan" , linux-kernel@vger.kernel.org Subject: [PATCH v2 2/2] libperf: evlist: Keep evsel idx contiguous on removal Date: Thu, 14 Nov 2024 16:04:49 +0000 Message-Id: <20241114160450.295844-3-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241114160450.295844-1-james.clark@linaro.org> References: <20241114160450.295844-1-james.clark@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The only two places where evsels are removed end up fixing up the index. Move it into libperf so that it's always done. Signed-off-by: James Clark Reviewed-by: Ian Rogers --- tools/lib/perf/evlist.c | 17 +++++++------ tools/lib/perf/tests/test-evlist.c | 41 ++++++++++++++++++++++++++++++ tools/perf/builtin-record.c | 18 +++---------- 3 files changed, 53 insertions(+), 23 deletions(-) diff --git a/tools/lib/perf/evlist.c b/tools/lib/perf/evlist.c index 83c43dc13313..ffa1a28fb14f 100644 --- a/tools/lib/perf/evlist.c +++ b/tools/lib/perf/evlist.c @@ -52,15 +52,8 @@ static void __perf_evlist__propagate_maps(struct perf_ev= list *evlist, * Empty cpu lists would eventually get opened as "any" so remove * genuinely empty ones before they're opened in the wrong place. */ - if (perf_cpu_map__is_empty(evsel->cpus)) { - struct perf_evsel *next =3D perf_evlist__next(evlist, evsel); - + if (perf_cpu_map__is_empty(evsel->cpus)) perf_evlist__remove(evlist, evsel); - /* Keep idx contiguous */ - if (next) - list_for_each_entry_from(next, &evlist->entries, node) - next->idx--; - } } else if (!evsel->own_cpus || evlist->has_user_cpus || (!evsel->requires_cpu && perf_cpu_map__has_any_cpu(evlist->user_requeste= d_cpus))) { /* @@ -116,8 +109,16 @@ void perf_evlist__add(struct perf_evlist *evlist, void perf_evlist__remove(struct perf_evlist *evlist, struct perf_evsel *evsel) { + struct perf_evsel *next =3D perf_evlist__next(evlist, evsel); + list_del_init(&evsel->node); evlist->nr_entries -=3D 1; + + /* Keep idx contiguous */ + if (!next) + return; + list_for_each_entry_from(next, &evlist->entries, node) + next->idx--; } =20 struct perf_evlist *perf_evlist__new(void) diff --git a/tools/lib/perf/tests/test-evlist.c b/tools/lib/perf/tests/test= -evlist.c index 10f70cb41ff1..06153820f408 100644 --- a/tools/lib/perf/tests/test-evlist.c +++ b/tools/lib/perf/tests/test-evlist.c @@ -571,6 +571,46 @@ static int test_stat_multiplexing(void) return 0; } =20 +static int test_list_remove(void) +{ + struct perf_evlist *evlist; + struct perf_evsel *evsel, *evsel0, *evsel1, *evsel2; + struct perf_event_attr attr =3D {}; + int idx =3D 0; + + evlist =3D perf_evlist__new(); + __T("failed to create evlist", evlist); + + evsel0 =3D perf_evsel__new(&attr); + __T("failed to create evsel", evsel0); + evsel1 =3D perf_evsel__new(&attr); + __T("failed to create evsel", evsel1); + evsel2 =3D perf_evsel__new(&attr); + __T("failed to create evsel", evsel2); + + perf_evlist__add(evlist, evsel0); + perf_evlist__add(evlist, evsel1); + perf_evlist__add(evlist, evsel2); + + idx =3D 0; + perf_evlist__for_each_evsel(evlist, evsel) + __T("idx isn't contiguous", evsel->idx =3D=3D idx++); + + /* Test removing middle */ + perf_evlist__remove(evlist, evsel1); + idx =3D 0; + perf_evlist__for_each_evsel(evlist, evsel) + __T("idx isn't contiguous", evsel->idx =3D=3D idx++); + + /* Test removing end */ + perf_evlist__remove(evlist, evsel2); + idx =3D 0; + perf_evlist__for_each_evsel(evlist, evsel) + __T("idx isn't contiguous", evsel->idx =3D=3D idx++); + + return 0; +} + int test_evlist(int argc, char **argv) { __T_START; @@ -583,6 +623,7 @@ int test_evlist(int argc, char **argv) test_mmap_thread(); test_mmap_cpus(); test_stat_multiplexing(); + test_list_remove(); =20 __T_END; return tests_failed =3D=3D 0 ? 0 : -1; diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 7e99743f7e42..2ebbb0fd0064 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -1359,14 +1359,13 @@ static int record__mmap(struct record *rec) static int record__open(struct record *rec) { char msg[BUFSIZ]; - struct evsel *pos; + struct evsel *pos, *tmp; struct evlist *evlist =3D rec->evlist; struct perf_session *session =3D rec->session; struct record_opts *opts =3D &rec->opts; int rc =3D 0; - bool skipped =3D false; =20 - evlist__for_each_entry(evlist, pos) { + evlist__for_each_entry_safe(evlist, tmp, pos) { try_again: if (evsel__open(pos, pos->core.cpus, pos->core.threads) < 0) { if (evsel__fallback(pos, &opts->target, errno, msg, sizeof(msg))) { @@ -1383,23 +1382,12 @@ static int record__open(struct record *rec) evsel__open_strerror(pos, &opts->target, errno, msg, sizeof(msg)); ui__error("Failure to open event '%s' on PMU '%s' which will be removed= .\n%s\n", evsel__name(pos), evsel__pmu_name(pos), msg); - pos->skippable =3D true; - skipped =3D true; + evlist__remove(evlist, pos); } else { pos->supported =3D true; } } =20 - if (skipped) { - struct evsel *tmp; - int idx =3D 0; - - evlist__for_each_entry_safe(evlist, tmp, pos) { - if (pos->skippable) - evlist__remove(evlist, pos); - pos->core.idx =3D idx++; - } - } if (symbol_conf.kptr_restrict && !evlist__exclude_kernel(evlist)) { pr_warning( "WARNING: Kernel address maps (/proc/{kallsyms,modules}) are restricted,\n" --=20 2.34.1