From nobody Sun May 19 20:29:58 2024 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (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 7B30E175A5 for ; Thu, 25 Apr 2024 22:34:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714084460; cv=none; b=tye5c2dnpd12sJ++wnUnc0FDpQvsxU/0lYJjKsCRC3QASvLu41dnXZk0WPapIoOl4D+Z+1OsWwGQisvbrDGvkXYBZHnnAGSw+k3S34UDqXexEDJSmI5kY9oTocE62X6qESmel25P5Z0J1XAMn6hOmwBsNMKY95ZqhpVctwdsB3Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714084460; c=relaxed/simple; bh=dphi9qBP63ALc85YmSjwCdzNIVpfkRQLHJHQrbhmr1k=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=lRQw6qYawkahuEryNosd3f4KJTHXWJF09Kr/EWDSb959WKYS/z5wnYDawjPk2O7VRfRvWUv0zsYWBC/XGlzTBtTec3XlIh7UhrPvKjRIw57R0AAQMKQpkttWG+JN6o18r3dMmfOp4UrYlHkH5zfjB+nHlX2XfzCwye0CYL1VU9c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=2amSNHXc; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="2amSNHXc" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dcdc3db67f0so3457295276.1 for ; Thu, 25 Apr 2024 15:34:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714084457; x=1714689257; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=PRyB6ZTPXeEQyqvBeQnDzSQ3aoVG6ArsSOU0946h4+I=; b=2amSNHXcRHIuqrk5p78qfYCdZuvrfmWEnVxzH037tSXvS7iyCUKXnuuJmw8br7kZqS vIQgqLW+oYNsN/v7YmgCkfGJN5C12yNuWyUWHZcVQg/Rdc4A8tJZJkR4w6DBDgcsaVlY vtJJmezZKTKGO4zhcvwLupF0uwW/GHzcMp9yT888fSsfQd9nA7nwJ964WYaRr4drS5HT +8pYrJkbr1jXoah5ZxQFePrlFP20oMgl4KAQtmanYUPXg1jvuMHIXOMBPKM9/osACd7V 5PQnk2ZZFt6E2poZp4qIzv/9MqjO8enI8pVfPniATMI4LOZ4WryceomMy2wTII/gVaKl rhQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714084457; x=1714689257; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=PRyB6ZTPXeEQyqvBeQnDzSQ3aoVG6ArsSOU0946h4+I=; b=tewJWBfJo42Q6T+Lik4/+JTG9oXset3YZObDi8hGtg9c/5tnb+yHWxmMJVxMcGV+GV cBVJh47Mi8y9jelDsxODgDKvo9Mcklf0lCvODLwaDXy3a4DXRSNsVAXvDtAwkFX9v97N BKsggG6GtNIpNblTSADAkbVe0JjQr3G/qyE2ASRCAID7UAEggZQmGVg+4U78kjH/EgpN ozJjJlShUtQeOKZOtngtAXOwE9M7/nTkOt2ws+Q7DcD9YhrNtsQIrbeOEarlQ9tdYm6f szdcMJ6VagxpJdNZRG95M2cg7ToS1nK22+IGwPHo29QaoL0IZQXCc5xOQ0U6aAXU+qFH 6DGA== X-Forwarded-Encrypted: i=1; AJvYcCVAmYe5wjotKIQz7ekCUIFnXPOT+xBMl40ph/a1oEaV5cg/nQ/5Nso3O8ZQ2qcXBzhT3cglTWzRBgvew6FtjxN4C4YsfuRowZmeDxrN X-Gm-Message-State: AOJu0YzLdukg7Q8uLLMu9NvFV8N+enDpzm1b87+fH35LGskoXOvvAVJX My8cBv+4LA8yETbiykLoC/BX5M27E+5eJyfMJEkcria0Tz80nxIZY0wzRYFH1wxhQWZ+6CEpmb7 Yi2Cf4g== X-Google-Smtp-Source: AGHT+IEQ/sIEgXuPsq1khlWSJrM0X0hALhujw4KeoPWU3mHHONJFz2LIsLabZBngG/PF7TMXMHovH8xNLJZ4 X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:8708:517d:aade:8c87]) (user=irogers job=sendgmr) by 2002:a05:6902:c04:b0:dd9:2782:d1c6 with SMTP id fs4-20020a0569020c0400b00dd92782d1c6mr339697ybb.1.1714084457578; Thu, 25 Apr 2024 15:34:17 -0700 (PDT) Date: Thu, 25 Apr 2024 15:34:04 -0700 In-Reply-To: <20240425223406.471120-1-irogers@google.com> Message-Id: <20240425223406.471120-2-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240425223406.471120-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.769.g3c40516874-goog Subject: [RFC PATCH v1 1/3] perf evsel: Don't open tool events From: Ian Rogers To: weilin.wang@intel.com, Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Ze Gao , Leo Yan , Ravi Bangoria , Dmitrii Dolgov <9erthalion6@gmail.com>, Song Liu , James Clark , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Tool events are set up as software dummy events. Don't open them to save some work and a file descriptor. The evsel's fds are initialized to -1, so it suffices to just early return. --- tools/perf/util/evsel.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 3536404e9447..2743d40665ff 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -2005,6 +2005,11 @@ static int evsel__open_cpu(struct evsel *evsel, stru= ct perf_cpu_map *cpus, int pid =3D -1, err, old_errno; enum rlimit_action set_rlimit =3D NO_CHANGE; =20 + if (evsel__is_tool(evsel)) { + /* Tool events are set up as dummy but don't need opening. */ + return 0; + } + err =3D __evsel__prepare_open(evsel, cpus, threads); if (err) return err; --=20 2.44.0.769.g3c40516874-goog From nobody Sun May 19 20:29:58 2024 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (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 EC97E156249 for ; Thu, 25 Apr 2024 22:34:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714084462; cv=none; b=NSlrRmFvwp+Jk5ycEMvXqvDC78ZPczewvaNg1M9WXzzygV2c88SYnPcVbQPzK//+XJ33swHHFwmrLatwe4cTvrnIOn87fv+in4sHu4PaoVrc2BlLJwG0rq6GX2IALIn8Fw9PfW11oh6vjUCWqpJbheiKrN+AjdjFAHNjM3OLdtw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714084462; c=relaxed/simple; bh=I9bPx3CpgQjyYg4yvV6AX9jEdWGmf4GwcXNlAYSkiQ8=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=hOjvDMzc4lzOqkG8bFbzjFr79Zy8G62SjBwSfFEUg4rK4o5rjGYkVY6aNFRAeOUkbn0hujy8Eqixs+z1v5hlqpmF+3hBWVjlVMqeOQfRlixpZ3bRbVE5bTZ31rIpacZUjQqdt1dhKErDlSFKOGTKOs3nMu/UhBJ6SBcPZAoofuM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=A/sDqGfm; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="A/sDqGfm" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dc6b26783b4so2340229276.0 for ; Thu, 25 Apr 2024 15:34:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714084460; x=1714689260; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=iMziqDCWwYpfU4+ULKZj6dbG7cOmBAdk/cZ8+rgWz6E=; b=A/sDqGfmWPt54/X/4DTwR9kdCtrwde957iPGp4sR0EPNr+qv6MEeL64vtns5pBPMS7 pFJMuvMc9ZJvYZA4aHE593QCSHsaaBbh0vK+FbJ6UvOwVU+8wAjm4H4WLCCU42mYXiDz /TABuUheGLDX1WMQIEGoMmkuNQbjKk6HbbwindrCae28hUxoquwWtsvaRAVE7h0mOruB 5k+/XSj2iHwTfEiQ5V4UcjTdndndRIqDXZEvZsUp7nRe10LUBZ+u7yrwppa2qBGx+nz7 xWE34IAg4j+7O+CuPVPJZQzytFa/46MsVSvGFGcZveOPiT3RKX7YoxaQfher6QzrAwPi TDGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714084460; x=1714689260; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=iMziqDCWwYpfU4+ULKZj6dbG7cOmBAdk/cZ8+rgWz6E=; b=ilEoN2z2ra0/SFzjS462DxL3CTLSX13P2+8XU5WK3PCdqBAjjt4An9+RQvlV0ZgKCA EIh0i7/wCaUik/H/5gjFS/TuUSQLjLl6BTRzohxvQb6xggB9l2kT1SIzkyzlT645wIJp Xm8PS03zw6pe0iyd2QZ/LykXAwk39LppaOedyaxFFAlHr1enwW8v97BlOdRBfE+eBCX8 o6WotD4RwVHWfDIprFBb4AhL2SgjelOnJ5ywCkWB4ypi3Ser0j7efSU23L1BTmvsDmwy 7VxgRJhbTXNg67AFPnaZNvONg6lC63HkpiPY5SVe0gPJnHiuaad94iVXoSDIXqtYbDJ6 OHgA== X-Forwarded-Encrypted: i=1; AJvYcCVhxqUXv4z883Cv/k4oYtL+cIyCJRBk+OTqaHVe+nFZg1gjboTS5OwGTDTOMtLesFB/hNuVr9Gi5cEvfZL9b6MsXOaLUIQ7PVQL/qUh X-Gm-Message-State: AOJu0YwggYrW27MFfWVaSMAR/I3hi1pe7mv1KglllXZQzk+qzdokVZGD OuhzceVMXf+J4ptsKCFwBNHqLkqH9z+6Egoc181RB9oZrRbf+NUULxTFiDcLbgECsLVD+axkCA+ Yil09NA== X-Google-Smtp-Source: AGHT+IHtc16sNAH9Y5DvoUb7goP0WugggB/EOiDtg9m48a61YuDx7t/1HnK4DzRMMl4fFIm0pCWoco8lKYJj X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:8708:517d:aade:8c87]) (user=irogers job=sendgmr) by 2002:a05:6902:1028:b0:de5:3003:4b64 with SMTP id x8-20020a056902102800b00de530034b64mr120121ybt.1.1714084459954; Thu, 25 Apr 2024 15:34:19 -0700 (PDT) Date: Thu, 25 Apr 2024 15:34:05 -0700 In-Reply-To: <20240425223406.471120-1-irogers@google.com> Message-Id: <20240425223406.471120-3-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240425223406.471120-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.769.g3c40516874-goog Subject: [RFC PATCH v1 2/3] perf parse-events: Add a retirement latency modifier From: Ian Rogers To: weilin.wang@intel.com, Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Ze Gao , Leo Yan , Ravi Bangoria , Dmitrii Dolgov <9erthalion6@gmail.com>, Song Liu , James Clark , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Retirement latency is a separate sampled count used on newer Intel CPUs. --- tools/perf/util/evsel.h | 1 + tools/perf/util/parse-events.c | 2 ++ tools/perf/util/parse-events.h | 1 + tools/perf/util/parse-events.l | 3 ++- 4 files changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 517cff431de2..e6726587e1bc 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -98,6 +98,7 @@ struct evsel { bool bpf_counter; bool use_config_name; bool skippable; + bool retire_lat; int bpf_fd; struct bpf_object *bpf_obj; struct list_head config_terms; diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 0f308b4db2b9..9c2a76ec8c99 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -1818,6 +1818,8 @@ static int parse_events__modifier_list(struct parse_e= vents_state *parse_state, evsel->weak_group =3D true; if (mod.bpf) evsel->bpf_counter =3D true; + if (mod.retire_lat) + evsel->retire_lat =3D true; } return 0; } diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h index 5695308efab9..eb94d1247dae 100644 --- a/tools/perf/util/parse-events.h +++ b/tools/perf/util/parse-events.h @@ -201,6 +201,7 @@ struct parse_events_modifier { bool hypervisor : 1; /* 'h' */ bool guest : 1; /* 'G' */ bool host : 1; /* 'H' */ + bool retire_lat : 1; /* 'R' */ }; =20 int parse_events__modifier_event(struct parse_events_state *parse_state, v= oid *loc, diff --git a/tools/perf/util/parse-events.l b/tools/perf/util/parse-events.l index 08ea2d845dc3..85015f080240 100644 --- a/tools/perf/util/parse-events.l +++ b/tools/perf/util/parse-events.l @@ -209,6 +209,7 @@ static int modifiers(struct parse_events_state *parse_s= tate, yyscan_t scanner) CASE('W', weak); CASE('e', exclusive); CASE('b', bpf); + CASE('R', retire_lat); default: return PE_ERROR; } @@ -250,7 +251,7 @@ drv_cfg_term [a-zA-Z0-9_\.]+(=3D[a-zA-Z0-9_*?\.:]+)? * If you add a modifier you need to update check_modifier(). * Also, the letters in modifier_event must not be in modifier_bp. */ -modifier_event [ukhpPGHSDIWeb]{1,15} +modifier_event [ukhpPGHSDIWebR]{1,16} modifier_bp [rwx]{1,3} lc_type (L1-dcache|l1-d|l1d|L1-data|L1-icache|l1-i|l1i|L1-instruction|LLC= |L2|dTLB|d-tlb|Data-TLB|iTLB|i-tlb|Instruction-TLB|branch|branches|bpu|btb|= bpc|node) lc_op_result (load|loads|read|store|stores|write|prefetch|prefetches|specu= lative-read|speculative-load|refs|Reference|ops|access|misses|miss) --=20 2.44.0.769.g3c40516874-goog From nobody Sun May 19 20:29:58 2024 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 67429156979 for ; Thu, 25 Apr 2024 22:34:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714084465; cv=none; b=mVXFWo2GI/npKP3hmjUIk7u86+237ZWsz6LCd1ZmEi8QGDjxI3SwkUzdLr95E6EQQgsyQEGYSV+acTY33NCVObvEPeaX5eYLXQqDvMZxyc7bMNIE8JLiOTn+j3xwxKb4ytfj08T64Vek/Puon/ezO5FgCcasw9uwlNp38o91tog= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714084465; c=relaxed/simple; bh=ZSwI+yq5E5BN4AjdvtMRad6FLRDWGqvN6S1bQXrEnHk=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=RsHFJt0jZXUUks2Iz0jqRCRq20Ew+lQCOoOuwztUknTDBvvbwQXEpNEsr+JnEQ2jaoBf2pJOYUcDXm6w69m75D8NfGOmJ/2Y9iYKz6ZbKa1umSmFPk9fr0X7WK7lRQsMjegzai1GUqyen2itJulkNlZ06YZYWvgNA/Z8vEXiT3E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=G2J7S0Ld; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="G2J7S0Ld" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-61b3b02f691so23746287b3.2 for ; Thu, 25 Apr 2024 15:34:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714084462; x=1714689262; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=8pr67K9okSqlKqRnt5D4jF0pSd06W4wTNqiSPTASJPI=; b=G2J7S0LdC/2qf3MOFGuzqlAknAtlTuJBnkoVaPFabuPwTZhEpdceTI+qgKn88HsyAh bKtAFvArxzQ5eqF5ut6hrLohy8itmXQcboELFMtpVZWFtapC930Jsm+04UoMDFP0FxVc ougUP9gGVTmQwdxw4RhsgYjyR+VC6Ty5WWf6VCxNPC4xa5XcGyhTE6UBTdW0wB5Ja+Jo uei/cJCJ+vzgtdvq0uDUhKjhjWf0iFneQpviNwTVC6sHKyfeCqQituIdc9V3kJvQwwIw WK1DRUsFzniFxPTo8PTH3YtJ8NvB/sdkohoNLMH9MQOOkWMM5dOVJYqQHQFMok/JuL2r H8tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714084462; x=1714689262; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=8pr67K9okSqlKqRnt5D4jF0pSd06W4wTNqiSPTASJPI=; b=M5vn+47U06Ynb1Afm5eC6xBYLrzhIbZecINNI6uEIGAlvEYU+u7ZHpqNk2YMdqlD5j NDOeVBR0fcBMVpbLmyrXH5bA1Ks4O+yLtKPM+B07zZ/14X8UfNhXE4BowlObtwmWa3ZQ zrtZIebISEiHrVI/O05qaAVTLoxRUNL0CM/QnMkU9zT2nFCTNzj/vJ+duwGbYiFs6UDp F8h2J5mKSEullu/6SEIZHpil+mn18SrDOPdYl0zzJt4W2jAqqYli8auIKb7j0GuhKmaN yFf3/1mB51ug+lmUW/xQuU2mYeigccUIgtHFcN7xOVMGYF46f1RFP+3jGiT5K1i6f1IN rFkw== X-Forwarded-Encrypted: i=1; AJvYcCXgu7nrDdD/M64d16gHfUDJdknnqY7/euyzO/qXBHVzmpTbE7UhTg1wqXaRALCPUiWE9D4qz4gH/7sb4+PNK6CkhbpOoaI/LiZ4Xb9C X-Gm-Message-State: AOJu0YxhyqfH2wtaGJshpLZeDZezeNjeUIVsIKlmcSTc1kg7ptZq7Yjz EwCJComUG9GqVtFbTupj5an0+MiBhRqS9DYJ+Gfm3y9+yaBUqmAIrMU72qjrURBcoSKBjefew+o eylP/GQ== X-Google-Smtp-Source: AGHT+IFtPTqMyFPlUEA83jO6S8cfsPVfGuW6p7qbvYx4galgmjpo6w0WgOMNmkHgVwvJb46mPDcrvhHnfULi X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:8708:517d:aade:8c87]) (user=irogers job=sendgmr) by 2002:a05:6902:2b0c:b0:de5:78:34d2 with SMTP id fi12-20020a0569022b0c00b00de5007834d2mr115971ybb.6.1714084462481; Thu, 25 Apr 2024 15:34:22 -0700 (PDT) Date: Thu, 25 Apr 2024 15:34:06 -0700 In-Reply-To: <20240425223406.471120-1-irogers@google.com> Message-Id: <20240425223406.471120-4-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240425223406.471120-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.769.g3c40516874-goog Subject: [RFC PATCH v1 3/3] perf evsel: Add retirement latency event support From: Ian Rogers To: weilin.wang@intel.com, Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Ze Gao , Leo Yan , Ravi Bangoria , Dmitrii Dolgov <9erthalion6@gmail.com>, Song Liu , James Clark , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When a retirement latency event is processed it sets a flag on the evsel. This change makes it so that when the flag is set evsel opening, reading and exiting report values from child perf record and perf report processes. Something similar was suggested by Namhyung Kim in: https://lore.kernel.org/lkml/CAM9d7cgdQQn5GYB7t++xuoMdeqPXiEkkcop69+rD06RAn= u9-EQ@mail.gmail.com/ This is trying to add support for retirement latency directly in events rather than through metric changes, as suggested by Weilin Wang in: https://lore.kernel.org/lkml/20240402214436.1409476-1-weilin.wang@intel.com/ --- tools/perf/util/evsel.c | 181 +++++++++++++++++++++++++++++++++++++++- tools/perf/util/evsel.h | 3 + 2 files changed, 181 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 2743d40665ff..3f0b4326bac6 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -56,6 +56,7 @@ #include #include #include +#include =20 #include =20 @@ -491,6 +492,156 @@ struct evsel *evsel__newtp_idx(const char *sys, const= char *name, int idx) } #endif =20 +static int evsel__start_retire_latency_cpu(struct evsel *evsel, struct per= f_cpu_map *cpus, + int cpu_map_idx) +{ + char buf[16]; + int pipefd[2]; + int err, i, event_len; + struct perf_cpu cpu =3D perf_cpu_map__cpu(cpus, cpu_map_idx); + struct child_process *child_record =3D + xyarray__entry(evsel->children, cpu_map_idx, 0); + struct child_process *child_report =3D + xyarray__entry(evsel->children, cpu_map_idx, 1); + char *event =3D strdup(evsel__name(evsel)); + // TODO: the dummy event also won't be used, but there's no option to dis= able. + const char *record_argv[15] =3D { + [0] =3D "perf", + [1] =3D "record", + [2] =3D "--synth=3Dno", + [3] =3D "-W", + [4] =3D "-o", + [5] =3D "-", + [6] =3D "-e", + }; + const char *report_argv[] =3D { + [0] =3D "perf", + [1] =3D "report", + [2] =3D "-i", + [3] =3D "-", + [4] =3D "-q", + [5] =3D "-F", + [6] =3D "weight1", + NULL, + }; + + if (!event) + return -ENOMEM; + + // Remove the R from the modifiers. + event_len =3D strlen(event); + if (event[event_len - 1] =3D=3D 'R' && event[event_len - 2] =3D=3D ':') { + event[strlen(event) - 2] =3D '\0'; + } else if (event[event_len - 1] =3D=3D 'R' && event[event_len - 2] =3D=3D= '/') { + event[strlen(event) - 1] =3D '\0'; + } else { + for (i =3D event_len - 1; i > 0; i--) { + if (event[i] =3D=3D 'R') { + for (int j =3D i + 1; j < event_len; j++) + event[i] =3D event[j]; + event[strlen(event) - 1] =3D '\0'; + break; + } + } + if (i =3D=3D 0) + pr_err("Expected retired latency 'R'\n"); + } + + i =3D 7; + record_argv[i++] =3D event; + if (verbose) { + record_argv[i++] =3D verbose > 1 ? "-vv" : "-v"; + } + if (cpu.cpu >=3D 0) { + record_argv[i++] =3D "-C"; + snprintf(buf, sizeof(buf), "%d", cpu.cpu); + record_argv[i++] =3D buf; + } else { + record_argv[i++] =3D "-a"; + } + record_argv[i++] =3D "sleep"; + // TODO: interval and support for different periods. + record_argv[i++] =3D "0.1"; + + if (pipe(pipefd) < 0) { + free(event); + return -errno; + } + + child_record->argv =3D record_argv; + child_record->pid =3D -1; + child_record->no_stdin =3D 1; + if (verbose) + child_record->err =3D fileno(stderr); + else + child_record->no_stderr =3D 1; + child_record->out =3D pipefd[1]; + err =3D start_command(child_record); + free(event); + if (err) + return err; + + child_report->argv =3D report_argv; + child_report->pid =3D -1; + if (verbose) + child_report->err =3D fileno(stderr); + else + child_report->no_stderr =3D 1; + child_report->in =3D pipefd[0]; + child_report->out =3D -1; + return start_command(child_report); +} + +static int evsel__finish_retire_latency_cpu(struct evsel *evsel, int cpu_m= ap_idx) +{ + struct child_process *child_record =3D + xyarray__entry(evsel->children, cpu_map_idx, 0); + struct child_process *child_report =3D + xyarray__entry(evsel->children, cpu_map_idx, 1); + + finish_command(child_record); + finish_command(child_report); + return 0; +} + +static int evsel__read_retire_latency(struct evsel *evsel, int cpu_map_idx= , int thread) +{ + struct child_process *child_report =3D xyarray__entry(evsel->children, cp= u_map_idx, 1); + struct perf_counts_values *count =3D perf_counts(evsel->counts, cpu_map_i= dx, thread); + char buf[256]; + int err; + + err =3D read(child_report->out, buf, sizeof(buf)); + if (err < 0 || strlen(buf) =3D=3D 0) + return -1; + + count->val =3D atoll(buf); + count->ena =3D 1; + count->run =3D 1; + count->id =3D 0; + count->lost =3D 0; + + err =3D evsel__finish_retire_latency_cpu(evsel, cpu_map_idx); + if (err) + return err; + + /* Restart the counter. */ + return evsel__start_retire_latency_cpu(evsel, evsel->core.cpus, cpu_map_i= dx); +} + +static int evsel__finish_retire_latency(struct evsel *evsel) +{ + int idx; + + perf_cpu_map__for_each_idx(idx, evsel->core.cpus) { + int err =3D evsel__finish_retire_latency_cpu(evsel, idx); + + if (err) + return err; + } + return 0; +} + const char *const evsel__hw_names[PERF_COUNT_HW_MAX] =3D { "cycles", "instructions", @@ -1463,6 +1614,10 @@ static void evsel__free_config_terms(struct evsel *e= vsel) =20 void evsel__exit(struct evsel *evsel) { + if (evsel->children) { + evsel__finish_retire_latency(evsel); + zfree(&evsel->children); + } assert(list_empty(&evsel->core.node)); assert(evsel->evlist =3D=3D NULL); bpf_counter__destroy(evsel); @@ -1602,9 +1757,10 @@ static int evsel__read_group(struct evsel *leader, i= nt cpu_map_idx, int thread) =20 int evsel__read_counter(struct evsel *evsel, int cpu_map_idx, int thread) { - u64 read_format =3D evsel->core.attr.read_format; + if (evsel->retire_lat) + return evsel__read_retire_latency(evsel, cpu_map_idx, thread); =20 - if (read_format & PERF_FORMAT_GROUP) + if (evsel->core.attr.read_format & PERF_FORMAT_GROUP) return evsel__read_group(evsel, cpu_map_idx, thread); =20 return evsel__read_one(evsel, cpu_map_idx, thread); @@ -1819,10 +1975,22 @@ static int __evsel__prepare_open(struct evsel *evse= l, struct perf_cpu_map *cpus, threads =3D empty_thread_map; } =20 - if (evsel->core.fd =3D=3D NULL && + if (!evsel->retire_lat && evsel->core.fd =3D=3D NULL && perf_evsel__alloc_fd(&evsel->core, perf_cpu_map__nr(cpus), nthreads) = < 0) return -ENOMEM; =20 + if (evsel->retire_lat && evsel->children =3D=3D NULL) { + /* + * Use ylen of 2, [0] is the record and [1] is the report + * command. Currently retirement latency doesn't support + * per-thread mode. + */ + evsel->children =3D xyarray__new(perf_cpu_map__nr(cpus), /*ylen=3D*/2, + sizeof(struct child_process)); + if (!evsel->children) + return -ENOMEM; + } + evsel->open_flags =3D PERF_FLAG_FD_CLOEXEC; if (evsel->cgrp) evsel->open_flags |=3D PERF_FLAG_PID_CGROUP; @@ -2033,6 +2201,13 @@ static int evsel__open_cpu(struct evsel *evsel, stru= ct perf_cpu_map *cpus, =20 for (idx =3D start_cpu_map_idx; idx < end_cpu_map_idx; idx++) { =20 + if (evsel->retire_lat) { + err =3D evsel__start_retire_latency_cpu(evsel, cpus, idx); + if (err) + return err; + continue; + } + for (thread =3D 0; thread < nthreads; thread++) { int fd, group_fd; retry_open: diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index e6726587e1bc..ab7c10e7f063 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -171,6 +171,9 @@ struct evsel { =20 /* for missing_features */ struct perf_pmu *pmu; + + /* Used for retire_lat child process. */ + struct xyarray *children; }; =20 struct perf_missing_features { --=20 2.44.0.769.g3c40516874-goog