From nobody Sat Apr 4 00:07:11 2026 Received: from mail-dl1-f74.google.com (mail-dl1-f74.google.com [74.125.82.74]) (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 81BDF367F21 for ; Sun, 22 Mar 2026 00:58:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774141117; cv=none; b=kXeCb5LLKrciC68W+tahHAAktwZJkQL0PNfPQ6SK1gHefQTz3D0YvlFnk7BEdavdRTru4YNE6vyhQDiSfqSVGmEZZu03viXw9xRsZ2e+bPbL8ov6aBTBfPIO7kY84RWVF1u0QQwyCIj/J/TNgmxf54AL8xmEUq3VQjJCR4raYMM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774141117; c=relaxed/simple; bh=mUhs77h48VhgtyAjhTyDJ3FwTWR5hwo6IbQbkY4le6w=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=D2ocLbxdeyTqHrDqarZbI5qNB0fDTQsrCA+rgeQbPn2tE8GOHDz0Y4XUtOfj6xRf4ciy2QBNJPO3KK6jUwOEn7jGt3GTUSDMzKNbkmvEb3+PU7dKpkyRJSEXleEz5VoEjKERn9bHQLGFbbksSfUiGVJZxoQZ948peoiqoqj/tPk= 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=RqLYrW3W; arc=none smtp.client-ip=74.125.82.74 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="RqLYrW3W" Received: by mail-dl1-f74.google.com with SMTP id a92af1059eb24-128edc72e5bso2038489c88.1 for ; Sat, 21 Mar 2026 17:58:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1774141116; x=1774745916; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=g5v2cdYDygdPGNKQ1eUv8N21CjI6pyt8oIsrmu7TsyQ=; b=RqLYrW3W0npk2e3Ve5rZhkWYdxhV6Siy+RF5KolfIF+n8ceaj4wbhfxfsXzpOYqcZh VHvj+BTK8I0LA21nh4V7S/olWcpfKhaC7p5st5rUo4WkIwkZ5JnZtqcj86K7DIBuuaSF NrhXiaRXYAuJjtcIO5q8tsiOKzQ4B2/NKTF8NJ6TW4SuOZ1Vw5BMTQQFmimhIOPNV6ZH su2Ms9oz0NI+dtnh0ADI6deQh4+N2O9K2oHQbQLbCiglhf4T+WJoXB+Yj+kHx2xtxSK+ Nth05p5kwyz/Pwf370ZpCMIdmeKvG392QiGKKtoW+GoNbyjS4TBx1wQ3Se7Yy3gITrl+ Aapw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774141116; x=1774745916; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=g5v2cdYDygdPGNKQ1eUv8N21CjI6pyt8oIsrmu7TsyQ=; b=dVoGACWS1/HdUJDsbSOcDEG/Tay71UohxQ1xJRMw1hwuIKHrXlcKslzsWOXS1CWwyC UxKGeR8JFbHBejUNw+wwC8JPjfJdh9nyPqGwt+DcUYPph6QBTjIw5S/Zy9gplkjuCsXZ v0ZdtRbaXvZCtw/wpPLV/SI1jIkDa99QsX/7PFOp+M7nCJWIUNiW28aPY/cFjiqSOnk0 Z7en3hcTgRyixSbEk3yX0bH4dv7/LqDd3GOpUZC7BZGXZWA+A5EFIKSKX13WMYXywbT5 mOIYoZWc8h3z51+msbv8UKkHkpLBTyGcW07fhnuhiGzgFGU3vAgb97IynjIehLiehT0X q/VA== X-Forwarded-Encrypted: i=1; AJvYcCWZynYpVY6j1hDD6EbMR0WjbtxJRvHOo1aOwhdf+r8mX/+KW/ePg+mZFawD7PdZcmRaF1M7m07y2qhCcEE=@vger.kernel.org X-Gm-Message-State: AOJu0Yw8Y/H3vJoMdufTzPxtjqVXPgGHZfsH+5iBJnuRJJ77r8RWiaIp QAZdN3GfAuLLhgsZyDcPifQrWtHRyowFO7QCIi6NhWQNN34DGRQcYYd5BRVdKlGBdcB7DQj5JYd MSZ8RSExlOQ== X-Received: from dlea1-n2.prod.google.com ([2002:a05:701b:4201:20b0:127:82fc:dd48]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:327:b0:12a:7181:2f1c with SMTP id a92af1059eb24-12a72682797mr3457147c88.17.1774141115504; Sat, 21 Mar 2026 17:58:35 -0700 (PDT) Date: Sat, 21 Mar 2026 17:58:20 -0700 In-Reply-To: <20260322005823.981079-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260322005823.981079-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.959.g497ff81fa9-goog Message-ID: <20260322005823.981079-2-irogers@google.com> Subject: [PATCH v2 1/4] perf build: Don't check difference of perf and libbpf hashmap From: Ian Rogers To: irogers@google.com, acme@kernel.org, adrian.hunter@intel.com, james.clark@linaro.org, jolsa@kernel.org, mingo@redhat.com, namhyung@kernel.org, peterz@infradead.org Cc: alexander.shishkin@linux.intel.com, alexei.starovoitov@gmail.com, andrii@kernel.org, ast@kernel.org, bpf@vger.kernel.org, daniel@iogearbox.net, eddyz87@gmail.com, haoluo@google.com, john.fastabend@gmail.com, kpsingh@kernel.org, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, martin.lau@linux.dev, memxor@gmail.com, sdf@fomichev.me, song@kernel.org, yonghong.song@linux.dev Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The hashmap code as-is violates the C specification meaning -fno-strict-aliasing is required or fixes sent in: https://lore.kernel.org/lkml/20260321024446.692008-1-irogers@google.com/ We're looking to not build perf with -fno-strict-aliasing: https://lore.kernel.org/lkml/20260320224248.536449-1-irogers@google.com/ There is also the continual problem with hashmap using errptrs rather than errno introducing subtle bugs as shown in commits, d05073adda0f perf trace: Avoid an ERR_PTR in syscall_stats 96f202eab813 perf trace: Fix IS_ERR() vs NULL check bug 9f3c16a430e8 perf expr: Fix return value of ids__new() but there are additional fixes on the mailing list. https://lore.kernel.org/lkml/20250805063209.3678359-1-linmq006@gmail.com/ Let's allow the perf version of hashmap diverge from libbpf's so that we can fix its issues. Signed-off-by: Ian Rogers --- tools/perf/check-headers.sh | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tools/perf/check-headers.sh b/tools/perf/check-headers.sh index da3aca87457f..36b91cf1ccce 100755 --- a/tools/perf/check-headers.sh +++ b/tools/perf/check-headers.sh @@ -215,10 +215,6 @@ do beauty_check "$i" -B done =20 -# check duplicated library files -check_2 tools/perf/util/hashmap.h tools/lib/bpf/hashmap.h -check_2 tools/perf/util/hashmap.c tools/lib/bpf/hashmap.c - # Files with larger differences =20 check_ignore_some_hunks lib/list_sort.c --=20 2.53.0.959.g497ff81fa9-goog From nobody Sat Apr 4 00:07:11 2026 Received: from mail-dl1-f74.google.com (mail-dl1-f74.google.com [74.125.82.74]) (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 BE12E366822 for ; Sun, 22 Mar 2026 00:58:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774141122; cv=none; b=RVsTUX+0+4oO0iGdAwZBYnRqAdLO3bCdqgb2F5v/so5mTCllCrsNn5FX0Jysdg6VB4zFWu1JTmfEgYjRTMZwxqwiTWksXsr1j5hl75YrUaJTumt5HfFFV1h1ORB6J949HYr/hHBC307Tfq3iHUIy54innKpfHtU2wUU018Ekr+A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774141122; c=relaxed/simple; bh=vioz0+MisITw57cAoM3iweOa/+7fcSWUqOqvspGkFWA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=AuOAEOrpXqv5jyR/7nBpjCeg0i1q9hoyGdA1tgOrkHxoJ8IHun/NmaavfUwxn8RL6bLL9LJwou9o6YMXPWjOKfzOOxnbfW3NTAhvoDHRWUqM/LVZe2qjOFtLvdfblWBEvpVPXYLqTCGvWCEh9uUCQTvzjFGvP5e1DzZcjg9971w= 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=Pivmwq2R; arc=none smtp.client-ip=74.125.82.74 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="Pivmwq2R" Received: by mail-dl1-f74.google.com with SMTP id a92af1059eb24-126e8ee6227so1439267c88.0 for ; Sat, 21 Mar 2026 17:58:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1774141118; x=1774745918; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=aKMNKrBvCJ+Y345Biu9LiA1wBlOnTT99L42XYZixZJ4=; b=Pivmwq2RylQzwfIcbwxKNxGz59d4C7VQLIzbtLdjHGc8jCVoVurIhQLnz3p09+7/Gi N3knpzuDVzb56GfrcX4n2guFVgPI4BLUDoiQJBpM+lnZPcMFAFYciyyDVr2FTPfcCNWD SWMq+zFHZYP7pdnOBEOdjjJNlyQ0SVazmDZ3xbbThYWo4DNCV/WK3irZyELEDwGGME40 O3a6hHFHo2BBP1RFh0Ze85zu2zr9sxUUfRvEdUEcA0F9gPG9g15wGPPZLHG+NDx9KnBJ SwlksoXSFvt4nQjrcYIScrjRshPBk/nuQWDVGNKRUiKLQQHxYFyyyvS+JRKfrognvF7V lABA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774141118; x=1774745918; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=aKMNKrBvCJ+Y345Biu9LiA1wBlOnTT99L42XYZixZJ4=; b=KKwX03ZFpk2MJ30iYrjfYF+ZYEDZGJ8q3UrXEkNUPfZ55OTmP+6R6YcwGDo3Tynufn JtYSSXaUfPy6i308lyhmmDXONI0z+nQmir8polNrJIZlJpF0xPw6C3cxn0A6yMDa1P16 L5LJxqDa1OZHCf5qXtHq1Pxp121onZTlfXjYXdHaLKJiRvfwo4BL0eitAoDFTatoxueL Ti9Q+GXaD9RIDagElTzYx8yAAzfB8bFMiCugYUD/5kXXpSW4ouuMOyS8s23HL8VZc3Me vNNrPq1byLlllgFdwtuKhUwL32w1Jg2X9gyj9wzk5OL+vQcGKpoEvHmoh1LTW/0JOyS7 /UzA== X-Forwarded-Encrypted: i=1; AJvYcCVVest/f6QJSHSUM2RiFMB4NTgM5ovl79pg+eFJ5R8vnWSIBPoMdUXgXATiOV56BJYN+jpO+dG0Cu4n4mI=@vger.kernel.org X-Gm-Message-State: AOJu0YyxsWrgOeazdW6ar7sJB6kCAkn6J318M4TTs6JLUDuBjKbjZF+3 Y+kJCoZXXw113inuezIx3/2lb+VPSRD5BtK/1mwqZOJrVL+bPuX4EZuANl6zwOa/FLztGj8b2qt NKWTZlfXncA== X-Received: from dlea6-n2.prod.google.com ([2002:a05:701b:4206:20b0:12a:6959:fb9b]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:61a1:b0:11b:ade6:45a7 with SMTP id a92af1059eb24-12a72671b02mr2672424c88.1.1774141117653; Sat, 21 Mar 2026 17:58:37 -0700 (PDT) Date: Sat, 21 Mar 2026 17:58:21 -0700 In-Reply-To: <20260322005823.981079-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260322005823.981079-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.959.g497ff81fa9-goog Message-ID: <20260322005823.981079-3-irogers@google.com> Subject: [PATCH v2 2/4] perf hashmap: Rename hashmap to perf_hashmap to avoid libbpf conflict From: Ian Rogers To: irogers@google.com, acme@kernel.org, adrian.hunter@intel.com, james.clark@linaro.org, jolsa@kernel.org, mingo@redhat.com, namhyung@kernel.org, peterz@infradead.org Cc: alexander.shishkin@linux.intel.com, alexei.starovoitov@gmail.com, andrii@kernel.org, ast@kernel.org, bpf@vger.kernel.org, daniel@iogearbox.net, eddyz87@gmail.com, haoluo@google.com, john.fastabend@gmail.com, kpsingh@kernel.org, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, martin.lau@linux.dev, memxor@gmail.com, sdf@fomichev.me, song@kernel.org, yonghong.song@linux.dev Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The hashmap implementation in tools/perf/util was copied from libbpf. To avoid symbol conflicts when linking against a version of libbpf that also provides hashmap functions, rename the perf-specific version to include a 'perf_' prefix. Updated: - hashmap_ -> perf_hashmap_ - hashmap__ -> perf_hashmap__ - struct hashmap -> struct perf_hashmap - struct hashmap_entry -> struct perf_hashmap_entry - enum hashmap_insert_strategy -> enum perf_hashmap_insert_strategy - HASHMAP_ADD -> PERF_HASHMAP_ADD (and other strategy enums) Signed-off-by: Ian Rogers --- tools/perf/builtin-ftrace.c | 20 ++-- tools/perf/builtin-trace.c | 30 +++--- tools/perf/tests/expr.c | 68 ++++++------- tools/perf/tests/pmu-events.c | 8 +- tools/perf/ui/browsers/annotate.c | 12 +-- tools/perf/util/Build | 9 -- tools/perf/util/annotate.c | 18 ++-- tools/perf/util/annotate.h | 6 +- tools/perf/util/bpf-trace-summary.c | 30 +++--- tools/perf/util/bpf_lock_contention.c | 14 +-- tools/perf/util/evsel.c | 8 +- tools/perf/util/evsel.h | 4 +- tools/perf/util/expr.c | 64 ++++++------ tools/perf/util/expr.h | 12 +-- tools/perf/util/expr.y | 2 +- tools/perf/util/fncache.c | 10 +- tools/perf/util/ftrace.h | 2 +- tools/perf/util/hashmap.c | 98 +++++++++---------- tools/perf/util/hashmap.h | 134 +++++++++++++------------- tools/perf/util/hwmon_pmu.c | 44 ++++----- tools/perf/util/metricgroup.c | 30 +++--- tools/perf/util/pmu.c | 24 ++--- tools/perf/util/pmu.h | 4 +- tools/perf/util/s390-sample-raw.c | 12 +-- tools/perf/util/stat.c | 8 +- tools/perf/util/threads.c | 24 ++--- tools/perf/util/threads.h | 2 +- 27 files changed, 344 insertions(+), 353 deletions(-) diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c index 6b6eec65f93f..94abfac934f7 100644 --- a/tools/perf/builtin-ftrace.c +++ b/tools/perf/builtin-ftrace.c @@ -1208,7 +1208,7 @@ static int prepare_func_profile(struct perf_ftrace *f= trace) ftrace->graph_tail =3D 1; ftrace->graph_verbose =3D 0; =20 - ftrace->profile_hash =3D hashmap__new(profile_hash, profile_equal, NULL); + ftrace->profile_hash =3D perf_hashmap__new(profile_hash, profile_equal, N= ULL); if (ftrace->profile_hash =3D=3D NULL) return -ENOMEM; =20 @@ -1224,7 +1224,7 @@ static int add_func_duration(struct perf_ftrace *ftra= ce, char *func, double time { struct ftrace_profile_data *prof =3D NULL; =20 - if (!hashmap__find(ftrace->profile_hash, func, &prof)) { + if (!perf_hashmap__find(ftrace->profile_hash, func, &prof)) { char *key =3D strdup(func); =20 if (key =3D=3D NULL) @@ -1237,7 +1237,7 @@ static int add_func_duration(struct perf_ftrace *ftra= ce, char *func, double time } =20 init_stats(&prof->st); - hashmap__add(ftrace->profile_hash, key, prof); + perf_hashmap__add(ftrace->profile_hash, key, prof); } =20 update_stats(&prof->st, time_ns); @@ -1332,8 +1332,8 @@ static enum perf_ftrace_profile_sort_key profile_sort= =3D PFP_SORT_TOTAL; =20 static int cmp_profile_data(const void *a, const void *b) { - const struct hashmap_entry *e1 =3D *(const struct hashmap_entry **)a; - const struct hashmap_entry *e2 =3D *(const struct hashmap_entry **)b; + const struct perf_hashmap_entry *e1 =3D *(const struct perf_hashmap_entry= **)a; + const struct perf_hashmap_entry *e2 =3D *(const struct perf_hashmap_entry= **)b; struct ftrace_profile_data *p1 =3D e1->pvalue; struct ftrace_profile_data *p2 =3D e2->pvalue; double v1, v2; @@ -1369,10 +1369,10 @@ static int cmp_profile_data(const void *a, const vo= id *b) =20 static void print_profile_result(struct perf_ftrace *ftrace) { - struct hashmap_entry *entry, **profile; + struct perf_hashmap_entry *entry, **profile; size_t i, nr, bkt; =20 - nr =3D hashmap__size(ftrace->profile_hash); + nr =3D perf_hashmap__size(ftrace->profile_hash); if (nr =3D=3D 0) return; =20 @@ -1383,7 +1383,7 @@ static void print_profile_result(struct perf_ftrace *= ftrace) } =20 i =3D 0; - hashmap__for_each_entry(ftrace->profile_hash, entry, bkt) + perf_hashmap__for_each_entry(ftrace->profile_hash, entry, bkt) profile[i++] =3D entry; =20 assert(i =3D=3D nr); @@ -1405,12 +1405,12 @@ static void print_profile_result(struct perf_ftrace= *ftrace) =20 free(profile); =20 - hashmap__for_each_entry(ftrace->profile_hash, entry, bkt) { + perf_hashmap__for_each_entry(ftrace->profile_hash, entry, bkt) { free((char *)entry->pkey); free(entry->pvalue); } =20 - hashmap__free(ftrace->profile_hash); + perf_hashmap__free(ftrace->profile_hash); ftrace->profile_hash =3D NULL; } =20 diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index f487fbaa0ad6..88b2fac16457 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -184,7 +184,7 @@ struct trace { * into the key, but this would make the code inconsistent with the * per-thread version. */ - struct hashmap *syscall_stats; + struct perf_hashmap *syscall_stats; double duration_filter; double runtime_ms; unsigned long pfmaj, pfmin; @@ -1549,7 +1549,7 @@ struct thread_trace { struct file *table; } files; =20 - struct hashmap *syscall_stats; + struct perf_hashmap *syscall_stats; }; =20 static size_t syscall_id_hash(long key, void *ctx __maybe_unused) @@ -1562,24 +1562,24 @@ static bool syscall_id_equal(long key1, long key2, = void *ctx __maybe_unused) return key1 =3D=3D key2; } =20 -static struct hashmap *alloc_syscall_stats(void) +static struct perf_hashmap *alloc_syscall_stats(void) { - struct hashmap *result =3D hashmap__new(syscall_id_hash, syscall_id_equal= , NULL); + struct perf_hashmap *result =3D perf_hashmap__new(syscall_id_hash, syscal= l_id_equal, NULL); =20 return IS_ERR(result) ? NULL : result; } =20 -static void delete_syscall_stats(struct hashmap *syscall_stats) +static void delete_syscall_stats(struct perf_hashmap *syscall_stats) { - struct hashmap_entry *pos; + struct perf_hashmap_entry *pos; size_t bkt; =20 if (!syscall_stats) return; =20 - hashmap__for_each_entry(syscall_stats, pos, bkt) + perf_hashmap__for_each_entry(syscall_stats, pos, bkt) zfree(&pos->pvalue); - hashmap__free(syscall_stats); + perf_hashmap__free(syscall_stats); } =20 static struct thread_trace *thread_trace__new(struct trace *trace) @@ -2637,7 +2637,7 @@ static void thread__update_stats(struct thread *threa= d, struct thread_trace *ttr int id, struct perf_sample *sample, long err, struct trace *trace) { - struct hashmap *syscall_stats =3D ttrace->syscall_stats; + struct perf_hashmap *syscall_stats =3D ttrace->syscall_stats; struct syscall_stats *stats =3D NULL; u64 duration =3D 0; =20 @@ -2647,13 +2647,13 @@ static void thread__update_stats(struct thread *thr= ead, struct thread_trace *ttr if (trace->summary_mode =3D=3D SUMMARY__BY_TOTAL) syscall_stats =3D trace->syscall_stats; =20 - if (!hashmap__find(syscall_stats, id, &stats)) { + if (!perf_hashmap__find(syscall_stats, id, &stats)) { stats =3D zalloc(sizeof(*stats)); if (stats =3D=3D NULL) return; =20 init_stats(&stats->stats); - if (hashmap__add(syscall_stats, id, stats) < 0) { + if (perf_hashmap__add(syscall_stats, id, stats) < 0) { free(stats); return; } @@ -4815,10 +4815,10 @@ static int entry_cmp(const void *e1, const void *e2) return entry1->msecs > entry2->msecs ? -1 : 1; } =20 -static struct syscall_entry *syscall__sort_stats(struct hashmap *syscall_s= tats) +static struct syscall_entry *syscall__sort_stats(struct perf_hashmap *sysc= all_stats) { struct syscall_entry *entry; - struct hashmap_entry *pos; + struct perf_hashmap_entry *pos; unsigned bkt, i, nr; =20 nr =3D syscall_stats->sz; @@ -4827,7 +4827,7 @@ static struct syscall_entry *syscall__sort_stats(stru= ct hashmap *syscall_stats) return NULL; =20 i =3D 0; - hashmap__for_each_entry(syscall_stats, pos, bkt) { + perf_hashmap__for_each_entry(syscall_stats, pos, bkt) { struct syscall_stats *ss =3D pos->pvalue; struct stats *st =3D &ss->stats; =20 @@ -4843,7 +4843,7 @@ static struct syscall_entry *syscall__sort_stats(stru= ct hashmap *syscall_stats) } =20 static size_t syscall__dump_stats(struct trace *trace, int e_machine, FILE= *fp, - struct hashmap *syscall_stats) + struct perf_hashmap *syscall_stats) { size_t printed =3D 0; int lines =3D 0; diff --git a/tools/perf/tests/expr.c b/tools/perf/tests/expr.c index 726cf8d4da28..78493a0ca925 100644 --- a/tools/perf/tests/expr.c +++ b/tools/perf/tests/expr.c @@ -15,7 +15,7 @@ =20 static int test_ids_union(void) { - struct hashmap *ids1, *ids2; + struct perf_hashmap *ids1, *ids2; =20 /* Empty union. */ ids1 =3D ids__new(); @@ -24,7 +24,7 @@ static int test_ids_union(void) TEST_ASSERT_VAL("ids__new", ids2); =20 ids1 =3D ids__union(ids1, ids2); - TEST_ASSERT_EQUAL("union", (int)hashmap__size(ids1), 0); + TEST_ASSERT_EQUAL("union", (int)perf_hashmap__size(ids1), 0); =20 /* Union {foo, bar} against {}. */ ids2 =3D ids__new(); @@ -34,7 +34,7 @@ static int test_ids_union(void) TEST_ASSERT_EQUAL("ids__insert", ids__insert(ids1, strdup("bar")), 0); =20 ids1 =3D ids__union(ids1, ids2); - TEST_ASSERT_EQUAL("union", (int)hashmap__size(ids1), 2); + TEST_ASSERT_EQUAL("union", (int)perf_hashmap__size(ids1), 2); =20 /* Union {foo, bar} against {foo}. */ ids2 =3D ids__new(); @@ -42,7 +42,7 @@ static int test_ids_union(void) TEST_ASSERT_EQUAL("ids__insert", ids__insert(ids2, strdup("foo")), 0); =20 ids1 =3D ids__union(ids1, ids2); - TEST_ASSERT_EQUAL("union", (int)hashmap__size(ids1), 2); + TEST_ASSERT_EQUAL("union", (int)perf_hashmap__size(ids1), 2); =20 /* Union {foo, bar} against {bar,baz}. */ ids2 =3D ids__new(); @@ -51,7 +51,7 @@ static int test_ids_union(void) TEST_ASSERT_EQUAL("ids__insert", ids__insert(ids2, strdup("baz")), 0); =20 ids1 =3D ids__union(ids1, ids2); - TEST_ASSERT_EQUAL("union", (int)hashmap__size(ids1), 3); + TEST_ASSERT_EQUAL("union", (int)perf_hashmap__size(ids1), 3); =20 ids__free(ids1); =20 @@ -134,27 +134,27 @@ static int test__expr(struct test_suite *t __maybe_un= used, int subtest __maybe_u TEST_ASSERT_VAL("find ids", expr__find_ids("FOO + BAR + BAZ + BOZO", "FOO", ctx) =3D=3D 0); - TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) =3D=3D 3); - TEST_ASSERT_VAL("find ids", hashmap__find(ctx->ids, "BAR", &val_ptr)); - TEST_ASSERT_VAL("find ids", hashmap__find(ctx->ids, "BAZ", &val_ptr)); - TEST_ASSERT_VAL("find ids", hashmap__find(ctx->ids, "BOZO", &val_ptr)); + TEST_ASSERT_VAL("find ids", perf_hashmap__size(ctx->ids) =3D=3D 3); + TEST_ASSERT_VAL("find ids", perf_hashmap__find(ctx->ids, "BAR", &val_ptr)= ); + TEST_ASSERT_VAL("find ids", perf_hashmap__find(ctx->ids, "BAZ", &val_ptr)= ); + TEST_ASSERT_VAL("find ids", perf_hashmap__find(ctx->ids, "BOZO", &val_ptr= )); =20 expr__ctx_clear(ctx); ctx->sctx.runtime =3D 3; TEST_ASSERT_VAL("find ids", expr__find_ids("EVENT1\\,param\\=3D?@ + EVENT2\\,param\\=3D?@", NULL, ctx) =3D=3D 0); - TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) =3D=3D 2); - TEST_ASSERT_VAL("find ids", hashmap__find(ctx->ids, "EVENT1,param=3D3@", = &val_ptr)); - TEST_ASSERT_VAL("find ids", hashmap__find(ctx->ids, "EVENT2,param=3D3@", = &val_ptr)); + TEST_ASSERT_VAL("find ids", perf_hashmap__size(ctx->ids) =3D=3D 2); + TEST_ASSERT_VAL("find ids", perf_hashmap__find(ctx->ids, "EVENT1,param=3D= 3@", &val_ptr)); + TEST_ASSERT_VAL("find ids", perf_hashmap__find(ctx->ids, "EVENT2,param=3D= 3@", &val_ptr)); =20 expr__ctx_clear(ctx); TEST_ASSERT_VAL("find ids", expr__find_ids("dash\\-event1 - dash\\-event2", NULL, ctx) =3D=3D 0); - TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) =3D=3D 2); - TEST_ASSERT_VAL("find ids", hashmap__find(ctx->ids, "dash-event1", &val_p= tr)); - TEST_ASSERT_VAL("find ids", hashmap__find(ctx->ids, "dash-event2", &val_p= tr)); + TEST_ASSERT_VAL("find ids", perf_hashmap__size(ctx->ids) =3D=3D 2); + TEST_ASSERT_VAL("find ids", perf_hashmap__find(ctx->ids, "dash-event1", &= val_ptr)); + TEST_ASSERT_VAL("find ids", perf_hashmap__find(ctx->ids, "dash-event2", &= val_ptr)); =20 /* Only EVENT1 or EVENT2 need be measured depending on the value of smt_o= n. */ { @@ -166,8 +166,8 @@ static int test__expr(struct test_suite *t __maybe_unus= ed, int subtest __maybe_u TEST_ASSERT_VAL("find ids", expr__find_ids("EVENT1 if #smt_on else EVENT2", NULL, ctx) =3D=3D 0); - TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) =3D=3D 1); - TEST_ASSERT_VAL("find ids", hashmap__find(ctx->ids, + TEST_ASSERT_VAL("find ids", perf_hashmap__size(ctx->ids) =3D=3D 1); + TEST_ASSERT_VAL("find ids", perf_hashmap__find(ctx->ids, smton ? "EVENT1" : "EVENT2", &val_ptr)); =20 @@ -175,8 +175,8 @@ static int test__expr(struct test_suite *t __maybe_unus= ed, int subtest __maybe_u TEST_ASSERT_VAL("find ids", expr__find_ids("EVENT1 if #core_wide else EVENT2", NULL, ctx) =3D=3D 0); - TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) =3D=3D 1); - TEST_ASSERT_VAL("find ids", hashmap__find(ctx->ids, + TEST_ASSERT_VAL("find ids", perf_hashmap__size(ctx->ids) =3D=3D 1); + TEST_ASSERT_VAL("find ids", perf_hashmap__find(ctx->ids, corewide ? "EVENT1" : "EVENT2", &val_ptr)); =20 @@ -186,47 +186,47 @@ static int test__expr(struct test_suite *t __maybe_un= used, int subtest __maybe_u TEST_ASSERT_VAL("find ids", expr__find_ids("1.0 if EVENT1 > 100.0 else 1.0", NULL, ctx) =3D=3D 0); - TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) =3D=3D 0); + TEST_ASSERT_VAL("find ids", perf_hashmap__size(ctx->ids) =3D=3D 0); =20 /* The expression is a constant 0.0 without needing to evaluate EVENT1. */ expr__ctx_clear(ctx); TEST_ASSERT_VAL("find ids", expr__find_ids("0 & EVENT1 > 0", NULL, ctx) =3D=3D 0); - TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) =3D=3D 0); + TEST_ASSERT_VAL("find ids", perf_hashmap__size(ctx->ids) =3D=3D 0); expr__ctx_clear(ctx); TEST_ASSERT_VAL("find ids", expr__find_ids("EVENT1 > 0 & 0", NULL, ctx) =3D=3D 0); - TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) =3D=3D 0); + TEST_ASSERT_VAL("find ids", perf_hashmap__size(ctx->ids) =3D=3D 0); expr__ctx_clear(ctx); TEST_ASSERT_VAL("find ids", expr__find_ids("1 & EVENT1 > 0", NULL, ctx) =3D=3D 0); - TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) =3D=3D 1); - TEST_ASSERT_VAL("find ids", hashmap__find(ctx->ids, "EVENT1", &val_ptr)); + TEST_ASSERT_VAL("find ids", perf_hashmap__size(ctx->ids) =3D=3D 1); + TEST_ASSERT_VAL("find ids", perf_hashmap__find(ctx->ids, "EVENT1", &val_p= tr)); expr__ctx_clear(ctx); TEST_ASSERT_VAL("find ids", expr__find_ids("EVENT1 > 0 & 1", NULL, ctx) =3D=3D 0); - TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) =3D=3D 1); - TEST_ASSERT_VAL("find ids", hashmap__find(ctx->ids, "EVENT1", &val_ptr)); + TEST_ASSERT_VAL("find ids", perf_hashmap__size(ctx->ids) =3D=3D 1); + TEST_ASSERT_VAL("find ids", perf_hashmap__find(ctx->ids, "EVENT1", &val_p= tr)); =20 /* The expression is a constant 1.0 without needing to evaluate EVENT1. */ expr__ctx_clear(ctx); TEST_ASSERT_VAL("find ids", expr__find_ids("1 | EVENT1 > 0", NULL, ctx) =3D=3D 0); - TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) =3D=3D 0); + TEST_ASSERT_VAL("find ids", perf_hashmap__size(ctx->ids) =3D=3D 0); expr__ctx_clear(ctx); TEST_ASSERT_VAL("find ids", expr__find_ids("EVENT1 > 0 | 1", NULL, ctx) =3D=3D 0); - TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) =3D=3D 0); + TEST_ASSERT_VAL("find ids", perf_hashmap__size(ctx->ids) =3D=3D 0); expr__ctx_clear(ctx); TEST_ASSERT_VAL("find ids", expr__find_ids("0 | EVENT1 > 0", NULL, ctx) =3D=3D 0); - TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) =3D=3D 1); - TEST_ASSERT_VAL("find ids", hashmap__find(ctx->ids, "EVENT1", &val_ptr)); + TEST_ASSERT_VAL("find ids", perf_hashmap__size(ctx->ids) =3D=3D 1); + TEST_ASSERT_VAL("find ids", perf_hashmap__find(ctx->ids, "EVENT1", &val_p= tr)); expr__ctx_clear(ctx); TEST_ASSERT_VAL("find ids", expr__find_ids("EVENT1 > 0 | 0", NULL, ctx) =3D=3D 0); - TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) =3D=3D 1); - TEST_ASSERT_VAL("find ids", hashmap__find(ctx->ids, "EVENT1", &val_ptr)); + TEST_ASSERT_VAL("find ids", perf_hashmap__size(ctx->ids) =3D=3D 1); + TEST_ASSERT_VAL("find ids", perf_hashmap__find(ctx->ids, "EVENT1", &val_p= tr)); =20 /* Test toplogy constants appear well ordered. */ expr__ctx_clear(ctx); @@ -264,8 +264,8 @@ static int test__expr(struct test_suite *t __maybe_unus= ed, int subtest __maybe_u TEST_ASSERT_VAL("source count", expr__find_ids("source_count(EVENT1)", NULL, ctx) =3D=3D 0); - TEST_ASSERT_VAL("source count", hashmap__size(ctx->ids) =3D=3D 1); - TEST_ASSERT_VAL("source count", hashmap__find(ctx->ids, "EVENT1", &val_pt= r)); + TEST_ASSERT_VAL("source count", perf_hashmap__size(ctx->ids) =3D=3D 1); + TEST_ASSERT_VAL("source count", perf_hashmap__find(ctx->ids, "EVENT1", &v= al_ptr)); =20 =20 /* Test no cpuid match */ diff --git a/tools/perf/tests/pmu-events.c b/tools/perf/tests/pmu-events.c index a99716862168..c851e61f6041 100644 --- a/tools/perf/tests/pmu-events.c +++ b/tools/perf/tests/pmu-events.c @@ -929,7 +929,7 @@ static struct test_metric metrics[] =3D { static int metric_parse_fake(const char *metric_name, const char *str) { struct expr_parse_ctx *ctx; - struct hashmap_entry *cur; + struct perf_hashmap_entry *cur; double result; int ret =3D -1; size_t bkt; @@ -954,10 +954,10 @@ static int metric_parse_fake(const char *metric_name,= const char *str) * make them unique. */ i =3D 1; - hashmap__for_each_entry(ctx->ids, cur, bkt) + perf_hashmap__for_each_entry(ctx->ids, cur, bkt) expr__add_id_val(ctx, strdup(cur->pkey), i++); =20 - hashmap__for_each_entry(ctx->ids, cur, bkt) { + perf_hashmap__for_each_entry(ctx->ids, cur, bkt) { if (check_parse_fake(cur->pkey)) { pr_err("check_parse_fake failed\n"); goto out; @@ -971,7 +971,7 @@ static int metric_parse_fake(const char *metric_name, c= onst char *str) * resolve divide by zero issues. */ i =3D 1024; - hashmap__for_each_entry(ctx->ids, cur, bkt) + perf_hashmap__for_each_entry(ctx->ids, cur, bkt) expr__add_id_val(ctx, strdup(cur->pkey), i--); if (expr__parse(&result, ctx, str)) { pr_err("expr__parse failed for %s\n", metric_name); diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/ann= otate.c index ea17e6d29a7e..c61415295dda 100644 --- a/tools/perf/ui/browsers/annotate.c +++ b/tools/perf/ui/browsers/annotate.c @@ -38,7 +38,7 @@ struct annotate_browser { struct hist_entry *he; struct debuginfo *dbg; struct evsel *evsel; - struct hashmap *type_hash; + struct perf_hashmap *type_hash; bool searching_backwards; char search_bf[128]; }; @@ -1117,7 +1117,7 @@ static int annotate_browser__run(struct annotate_brow= ser *browser, if (browser->dbg =3D=3D NULL) browser->dbg =3D dso__debuginfo(map__dso(ms->map)); if (browser->type_hash =3D=3D NULL) { - browser->type_hash =3D hashmap__new(type_hash, type_equal, + browser->type_hash =3D perf_hashmap__new(type_hash, type_equal, /*ctx=3D*/NULL); } annotate_browser__show(browser, title, help); @@ -1219,7 +1219,7 @@ int __hist_entry__tui_annotate(struct hist_entry *he,= struct map_symbol *ms, =20 if (annotate_opts.code_with_type) { browser.dbg =3D dso__debuginfo(dso); - browser.type_hash =3D hashmap__new(type_hash, type_equal, /*ctx=3D*/NULL= ); + browser.type_hash =3D perf_hashmap__new(type_hash, type_equal, /*ctx=3D*= /NULL); } =20 browser.b.width =3D notes->src->widths.max_line_len; @@ -1249,12 +1249,12 @@ int __hist_entry__tui_annotate(struct hist_entry *h= e, struct map_symbol *ms, debuginfo__delete(browser.dbg); =20 if (!IS_ERR_OR_NULL(browser.type_hash)) { - struct hashmap_entry *cur; + struct perf_hashmap_entry *cur; size_t bkt; =20 - hashmap__for_each_entry(browser.type_hash, cur, bkt) + perf_hashmap__for_each_entry(browser.type_hash, cur, bkt) zfree(&cur->pvalue); - hashmap__free(browser.type_hash); + perf_hashmap__free(browser.type_hash); } =20 if (not_annotated && !notes->src->tried_source) diff --git a/tools/perf/util/Build b/tools/perf/util/Build index 70cc91d00804..b8fc4d102c0b 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -197,16 +197,7 @@ perf-util-$(CONFIG_LIBELF) +=3D symbol-elf.o perf-util-$(CONFIG_LIBELF) +=3D probe-file.o perf-util-$(CONFIG_LIBELF) +=3D probe-event.o =20 -ifdef CONFIG_LIBBPF_DYNAMIC - hashmap :=3D 1 -endif -ifndef CONFIG_LIBBPF - hashmap :=3D 1 -endif - -ifdef hashmap perf-util-y +=3D hashmap.o -endif =20 ifndef CONFIG_LIBELF perf-util-y +=3D symbol-minimal.o diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 2e3522905046..d49ae1f4327e 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -112,16 +112,16 @@ static struct annotated_source *annotated_source__new= (void) =20 static __maybe_unused void annotated_source__delete(struct annotated_sourc= e *src) { - struct hashmap_entry *cur; + struct perf_hashmap_entry *cur; size_t bkt; =20 if (src =3D=3D NULL) return; =20 if (src->samples) { - hashmap__for_each_entry(src->samples, cur, bkt) + perf_hashmap__for_each_entry(src->samples, cur, bkt) zfree(&cur->pvalue); - hashmap__free(src->samples); + perf_hashmap__free(src->samples); } zfree(&src->histograms); free(src); @@ -136,7 +136,7 @@ static int annotated_source__alloc_histograms(struct an= notated_source *src, if (src->histograms =3D=3D NULL) return -1; =20 - src->samples =3D hashmap__new(sym_hist_hash, sym_hist_equal, NULL); + src->samples =3D perf_hashmap__new(sym_hist_hash, sym_hist_equal, NULL); if (src->samples =3D=3D NULL) zfree(&src->histograms); =20 @@ -151,7 +151,7 @@ void symbol__annotate_zero_histograms(struct symbol *sy= m) if (notes->src !=3D NULL) { memset(notes->src->histograms, 0, notes->src->nr_histograms * sizeof(*notes->src->histograms)); - hashmap__clear(notes->src->samples); + perf_hashmap__clear(notes->src->samples); } if (notes->branch && notes->branch->cycles_hist) { memset(notes->branch->cycles_hist, 0, @@ -238,12 +238,12 @@ static int __symbol__inc_addr_samples(struct map_symb= ol *ms, } =20 hash_key =3D offset << 16 | evsel->core.idx; - if (!hashmap__find(src->samples, hash_key, &entry)) { + if (!perf_hashmap__find(src->samples, hash_key, &entry)) { entry =3D zalloc(sizeof(*entry)); if (entry =3D=3D NULL) return -ENOMEM; =20 - if (hashmap__add(src->samples, hash_key, entry) < 0) + if (perf_hashmap__add(src->samples, hash_key, entry) < 0) return -ENOMEM; } =20 @@ -1970,7 +1970,7 @@ static int disasm_line__snprint_type_info(struct disa= sm_line *dl, return 1; =20 if (apd->type_hash) { - hashmap__find(apd->type_hash, dl->al.offset, &entry); + perf_hashmap__find(apd->type_hash, dl->al.offset, &entry); if (entry !=3D NULL) { data_type =3D entry->type; offset =3D entry->offset; @@ -1985,7 +1985,7 @@ static int disasm_line__snprint_type_info(struct disa= sm_line *dl, if (entry !=3D NULL) { entry->type =3D data_type; entry->offset =3D offset; - hashmap__add(apd->type_hash, dl->al.offset, entry); + perf_hashmap__add(apd->type_hash, dl->al.offset, entry); } } =20 diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h index 696e36dbf013..b59be2389a65 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h @@ -205,7 +205,7 @@ struct annotation_print_data { const struct arch *arch; struct debuginfo *dbg; /* save data type info keyed by al->offset */ - struct hashmap *type_hash; + struct perf_hashmap *type_hash; /* It'll be set in hist_entry__annotate_printf() */ int addr_fmt_width; }; @@ -300,7 +300,7 @@ struct cyc_hist { struct annotated_source { struct list_head source; struct sym_hist *histograms; - struct hashmap *samples; + struct perf_hashmap *samples; int nr_histograms; int nr_events; int nr_entries; @@ -412,7 +412,7 @@ annotated_source__hist_entry(struct annotated_source *s= rc, const struct evsel *e struct sym_hist_entry *entry; long key =3D offset << 16 | evsel->core.idx; =20 - if (!hashmap__find(src->samples, key, &entry)) + if (!perf_hashmap__find(src->samples, key, &entry)) return NULL; return entry; } diff --git a/tools/perf/util/bpf-trace-summary.c b/tools/perf/util/bpf-trac= e-summary.c index cf6e1e4402d5..2cdafd4b433d 100644 --- a/tools/perf/util/bpf-trace-summary.c +++ b/tools/perf/util/bpf-trace-summary.c @@ -169,19 +169,19 @@ static int print_common_stats(struct syscall_data *da= ta, int max_summary, FILE * return printed; } =20 -static int update_thread_stats(struct hashmap *hash, struct syscall_key *m= ap_key, +static int update_thread_stats(struct perf_hashmap *hash, struct syscall_k= ey *map_key, struct syscall_stats *map_data) { struct syscall_data *data; struct syscall_node *nodes; =20 - if (!hashmap__find(hash, map_key->cpu_or_tid, &data)) { + if (!perf_hashmap__find(hash, map_key->cpu_or_tid, &data)) { data =3D zalloc(sizeof(*data)); if (data =3D=3D NULL) return -ENOMEM; =20 data->key =3D map_key->cpu_or_tid; - if (hashmap__add(hash, data->key, data) < 0) { + if (perf_hashmap__add(hash, data->key, data) < 0) { free(data); return -ENOMEM; } @@ -233,13 +233,13 @@ static int print_thread_stats(struct syscall_data **d= ata, int nr_data, int max_s return printed; } =20 -static int update_total_stats(struct hashmap *hash, struct syscall_key *ma= p_key, +static int update_total_stats(struct perf_hashmap *hash, struct syscall_ke= y *map_key, struct syscall_stats *map_data) { struct syscall_data *data; struct syscall_stats *stat; =20 - if (!hashmap__find(hash, map_key->nr, &data)) { + if (!perf_hashmap__find(hash, map_key->nr, &data)) { data =3D zalloc(sizeof(*data)); if (data =3D=3D NULL) return -ENOMEM; @@ -254,7 +254,7 @@ static int update_total_stats(struct hashmap *hash, str= uct syscall_key *map_key, data->key =3D map_key->nr; data->nodes->syscall_nr =3D data->key; =20 - if (hashmap__add(hash, data->key, data) < 0) { + if (perf_hashmap__add(hash, data->key, data) < 0) { free(data->nodes); free(data); return -ENOMEM; @@ -305,19 +305,19 @@ static int print_total_stats(struct syscall_data **da= ta, int nr_data, int max_su return printed; } =20 -static int update_cgroup_stats(struct hashmap *hash, struct syscall_key *m= ap_key, +static int update_cgroup_stats(struct perf_hashmap *hash, struct syscall_k= ey *map_key, struct syscall_stats *map_data) { struct syscall_data *data; struct syscall_node *nodes; =20 - if (!hashmap__find(hash, map_key->cgroup, &data)) { + if (!perf_hashmap__find(hash, map_key->cgroup, &data)) { data =3D zalloc(sizeof(*data)); if (data =3D=3D NULL) return -ENOMEM; =20 data->key =3D map_key->cgroup; - if (hashmap__add(hash, data->key, data) < 0) { + if (perf_hashmap__add(hash, data->key, data) < 0) { free(data); return -ENOMEM; } @@ -379,14 +379,14 @@ int trace_print_bpf_summary(FILE *fp, int max_summary) struct bpf_map *map =3D skel->maps.syscall_stats_map; struct syscall_key *prev_key, key; struct syscall_data **data =3D NULL; - struct hashmap schash; - struct hashmap_entry *entry; + struct perf_hashmap schash; + struct perf_hashmap_entry *entry; int nr_data =3D 0; int printed =3D 0; int i; size_t bkt; =20 - hashmap__init(&schash, sc_node_hash, sc_node_equal, /*ctx=3D*/NULL); + perf_hashmap__init(&schash, sc_node_hash, sc_node_equal, /*ctx=3D*/NULL); =20 printed =3D fprintf(fp, "\n Summary of events:\n\n"); =20 @@ -414,13 +414,13 @@ int trace_print_bpf_summary(FILE *fp, int max_summary) prev_key =3D &key; } =20 - nr_data =3D hashmap__size(&schash); + nr_data =3D perf_hashmap__size(&schash); data =3D calloc(nr_data, sizeof(*data)); if (data =3D=3D NULL) goto out; =20 i =3D 0; - hashmap__for_each_entry(&schash, entry, bkt) + perf_hashmap__for_each_entry(&schash, entry, bkt) data[i++] =3D entry->pvalue; =20 qsort(data, nr_data, sizeof(*data), datacmp); @@ -446,7 +446,7 @@ int trace_print_bpf_summary(FILE *fp, int max_summary) free(data); =20 out: - hashmap__clear(&schash); + perf_hashmap__clear(&schash); return printed; } =20 diff --git a/tools/perf/util/bpf_lock_contention.c b/tools/perf/util/bpf_lo= ck_contention.c index cbd7435579fe..3efe82915ebb 100644 --- a/tools/perf/util/bpf_lock_contention.c +++ b/tools/perf/util/bpf_lock_contention.c @@ -22,7 +22,7 @@ =20 static struct lock_contention_bpf *skel; static bool has_slab_iter; -static struct hashmap slab_hash; +static struct perf_hashmap slab_hash; =20 static size_t slab_cache_hash(long key, void *ctx __maybe_unused) { @@ -38,7 +38,7 @@ static void check_slab_cache_iter(struct lock_contention = *con) { s32 ret; =20 - hashmap__init(&slab_hash, slab_cache_hash, slab_cache_equal, /*ctx=3D*/NU= LL); + perf_hashmap__init(&slab_hash, slab_cache_hash, slab_cache_equal, /*ctx= =3D*/NULL); =20 con->btf =3D btf__load_vmlinux_btf(); if (con->btf =3D=3D NULL) { @@ -92,20 +92,20 @@ static void run_slab_cache_iter(void) if (bpf_map_lookup_elem(fd, &key, data) < 0) break; =20 - hashmap__add(&slab_hash, data->id, data); + perf_hashmap__add(&slab_hash, data->id, data); prev_key =3D &key; } } =20 static void exit_slab_cache_iter(void) { - struct hashmap_entry *cur; + struct perf_hashmap_entry *cur; unsigned bkt; =20 - hashmap__for_each_entry(&slab_hash, cur, bkt) + perf_hashmap__for_each_entry(&slab_hash, cur, bkt) free(cur->pvalue); =20 - hashmap__clear(&slab_hash); + perf_hashmap__clear(&slab_hash); } =20 static void init_numa_data(struct lock_contention *con) @@ -615,7 +615,7 @@ static const char *lock_contention_get_name(struct lock= _contention *con, } =20 /* look slab_hash for dynamic locks in a slab object */ - if (hashmap__find(&slab_hash, flags & LCB_F_SLAB_ID_MASK, &slab_data)) { + if (perf_hashmap__find(&slab_hash, flags & LCB_F_SLAB_ID_MASK, &slab_dat= a)) { snprintf(name_buf, sizeof(name_buf), "&%s", slab_data->name); return name_buf; } diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 5a294595a677..99a698de28be 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1878,7 +1878,7 @@ void evsel__exit(struct evsel *evsel) zfree(&evsel->unit); zfree(&evsel->metric_id); evsel__zero_per_pkg(evsel); - hashmap__free(evsel->per_pkg_mask); + perf_hashmap__free(evsel->per_pkg_mask); evsel->per_pkg_mask =3D NULL; if (evsel__priv_destructor) evsel__priv_destructor(evsel->priv); @@ -4190,14 +4190,14 @@ int evsel__store_ids(struct evsel *evsel, struct ev= list *evlist) =20 void evsel__zero_per_pkg(struct evsel *evsel) { - struct hashmap_entry *cur; + struct perf_hashmap_entry *cur; size_t bkt; =20 if (evsel->per_pkg_mask) { - hashmap__for_each_entry(evsel->per_pkg_mask, cur, bkt) + perf_hashmap__for_each_entry(evsel->per_pkg_mask, cur, bkt) zfree(&cur->pkey); =20 - hashmap__clear(evsel->per_pkg_mask); + perf_hashmap__clear(evsel->per_pkg_mask); } } =20 diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 339b5c08a33d..ff28d1b4cc19 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -21,7 +21,7 @@ struct perf_stat_evsel; union perf_event; struct bpf_counter_ops; struct target; -struct hashmap; +struct perf_hashmap; struct bperf_leader_bpf; struct bperf_follower_bpf; =20 @@ -126,7 +126,7 @@ struct evsel { bool needs_uniquify; bool fallenback_eacces; bool fallenback_eopnotsupp; - struct hashmap *per_pkg_mask; + struct perf_hashmap *per_pkg_mask; int err; int script_output_type; struct { diff --git a/tools/perf/util/expr.c b/tools/perf/util/expr.c index 465fe2e9bbbe..dc10c335e378 100644 --- a/tools/perf/util/expr.c +++ b/tools/perf/util/expr.c @@ -63,39 +63,39 @@ static bool key_equal(long key1, long key2, void *ctx _= _maybe_unused) return !strcmp((const char *)key1, (const char *)key2); } =20 -struct hashmap *ids__new(void) +struct perf_hashmap *ids__new(void) { - struct hashmap *hash; + struct perf_hashmap *hash; =20 - hash =3D hashmap__new(key_hash, key_equal, NULL); + hash =3D perf_hashmap__new(key_hash, key_equal, NULL); if (IS_ERR(hash)) return NULL; return hash; } =20 -void ids__free(struct hashmap *ids) +void ids__free(struct perf_hashmap *ids) { - struct hashmap_entry *cur; + struct perf_hashmap_entry *cur; size_t bkt; =20 if (ids =3D=3D NULL) return; =20 - hashmap__for_each_entry(ids, cur, bkt) { + perf_hashmap__for_each_entry(ids, cur, bkt) { zfree(&cur->pkey); zfree(&cur->pvalue); } =20 - hashmap__free(ids); + perf_hashmap__free(ids); } =20 -int ids__insert(struct hashmap *ids, const char *id) +int ids__insert(struct perf_hashmap *ids, const char *id) { struct expr_id_data *data_ptr =3D NULL, *old_data =3D NULL; char *old_key =3D NULL; int ret; =20 - ret =3D hashmap__set(ids, id, data_ptr, &old_key, &old_data); + ret =3D perf_hashmap__set(ids, id, data_ptr, &old_key, &old_data); if (ret) free(data_ptr); free(old_key); @@ -103,10 +103,10 @@ int ids__insert(struct hashmap *ids, const char *id) return ret; } =20 -struct hashmap *ids__union(struct hashmap *ids1, struct hashmap *ids2) +struct perf_hashmap *ids__union(struct perf_hashmap *ids1, struct perf_has= hmap *ids2) { size_t bkt; - struct hashmap_entry *cur; + struct perf_hashmap_entry *cur; int ret; struct expr_id_data *old_data =3D NULL; char *old_key =3D NULL; @@ -117,24 +117,24 @@ struct hashmap *ids__union(struct hashmap *ids1, stru= ct hashmap *ids2) if (!ids2) return ids1; =20 - if (hashmap__size(ids1) < hashmap__size(ids2)) { - struct hashmap *tmp =3D ids1; + if (perf_hashmap__size(ids1) < perf_hashmap__size(ids2)) { + struct perf_hashmap *tmp =3D ids1; =20 ids1 =3D ids2; ids2 =3D tmp; } - hashmap__for_each_entry(ids2, cur, bkt) { - ret =3D hashmap__set(ids1, cur->key, cur->value, &old_key, &old_data); + perf_hashmap__for_each_entry(ids2, cur, bkt) { + ret =3D perf_hashmap__set(ids1, cur->key, cur->value, &old_key, &old_dat= a); free(old_key); free(old_data); =20 if (ret) { - hashmap__free(ids1); - hashmap__free(ids2); + perf_hashmap__free(ids1); + perf_hashmap__free(ids2); return NULL; } } - hashmap__free(ids2); + perf_hashmap__free(ids2); return ids1; } =20 @@ -165,7 +165,7 @@ int expr__add_id_val_source_count(struct expr_parse_ctx= *ctx, const char *id, data_ptr->val.source_count =3D source_count; data_ptr->kind =3D EXPR_ID_DATA__VALUE; =20 - ret =3D hashmap__set(ctx->ids, id, data_ptr, &old_key, &old_data); + ret =3D perf_hashmap__set(ctx->ids, id, data_ptr, &old_key, &old_data); if (ret) { free(data_ptr); } else if (old_data) { @@ -204,7 +204,7 @@ int expr__add_ref(struct expr_parse_ctx *ctx, struct me= tric_ref *ref) data_ptr->ref.metric_expr =3D ref->metric_expr; data_ptr->kind =3D EXPR_ID_DATA__REF; =20 - ret =3D hashmap__set(ctx->ids, name, data_ptr, &old_key, &old_data); + ret =3D perf_hashmap__set(ctx->ids, name, data_ptr, &old_key, &old_data); if (ret) free(data_ptr); =20 @@ -221,17 +221,17 @@ int expr__get_id(struct expr_parse_ctx *ctx, const ch= ar *id, { if (!ctx || !id) return -1; - return hashmap__find(ctx->ids, id, data) ? 0 : -1; + return perf_hashmap__find(ctx->ids, id, data) ? 0 : -1; } =20 bool expr__subset_of_ids(struct expr_parse_ctx *haystack, struct expr_parse_ctx *needles) { - struct hashmap_entry *cur; + struct perf_hashmap_entry *cur; size_t bkt; struct expr_id_data *data; =20 - hashmap__for_each_entry(needles->ids, cur, bkt) { + perf_hashmap__for_each_entry(needles->ids, cur, bkt) { if (expr__get_id(haystack, cur->pkey, &data)) return false; } @@ -282,7 +282,7 @@ void expr__del_id(struct expr_parse_ctx *ctx, const cha= r *id) struct expr_id_data *old_val =3D NULL; char *old_key =3D NULL; =20 - hashmap__delete(ctx->ids, id, &old_key, &old_val); + perf_hashmap__delete(ctx->ids, id, &old_key, &old_val); free(old_key); free(old_val); } @@ -295,7 +295,7 @@ struct expr_parse_ctx *expr__ctx_new(void) if (!ctx) return NULL; =20 - ctx->ids =3D hashmap__new(key_hash, key_equal, NULL); + ctx->ids =3D perf_hashmap__new(key_hash, key_equal, NULL); if (IS_ERR(ctx->ids)) { free(ctx); return NULL; @@ -306,30 +306,30 @@ struct expr_parse_ctx *expr__ctx_new(void) =20 void expr__ctx_clear(struct expr_parse_ctx *ctx) { - struct hashmap_entry *cur; + struct perf_hashmap_entry *cur; size_t bkt; =20 - hashmap__for_each_entry(ctx->ids, cur, bkt) { + perf_hashmap__for_each_entry(ctx->ids, cur, bkt) { zfree(&cur->pkey); zfree(&cur->pvalue); } - hashmap__clear(ctx->ids); + perf_hashmap__clear(ctx->ids); } =20 void expr__ctx_free(struct expr_parse_ctx *ctx) { - struct hashmap_entry *cur; + struct perf_hashmap_entry *cur; size_t bkt; =20 if (!ctx) return; =20 zfree(&ctx->sctx.user_requested_cpu_list); - hashmap__for_each_entry(ctx->ids, cur, bkt) { + perf_hashmap__for_each_entry(ctx->ids, cur, bkt) { zfree(&cur->pkey); zfree(&cur->pvalue); } - hashmap__free(ctx->ids); + perf_hashmap__free(ctx->ids); free(ctx); } =20 @@ -421,7 +421,7 @@ double expr__has_event(const struct expr_parse_ctx *ctx= , bool compute_ids, const struct evlist *tmp; double ret; =20 - if (hashmap__find(ctx->ids, id, /*value=3D*/NULL)) + if (perf_hashmap__find(ctx->ids, id, /*value=3D*/NULL)) return 1.0; =20 if (!compute_ids) diff --git a/tools/perf/util/expr.h b/tools/perf/util/expr.h index c0cec29ddc29..4c333af0c5e3 100644 --- a/tools/perf/util/expr.h +++ b/tools/perf/util/expr.h @@ -2,7 +2,7 @@ #ifndef PARSE_CTX_H #define PARSE_CTX_H 1 =20 -struct hashmap; +struct perf_hashmap; struct metric_ref; =20 struct expr_scanner_ctx { @@ -13,20 +13,20 @@ struct expr_scanner_ctx { }; =20 struct expr_parse_ctx { - struct hashmap *ids; + struct perf_hashmap *ids; struct expr_scanner_ctx sctx; }; =20 struct expr_id_data; =20 -struct hashmap *ids__new(void); -void ids__free(struct hashmap *ids); -int ids__insert(struct hashmap *ids, const char *id); +struct perf_hashmap *ids__new(void); +void ids__free(struct perf_hashmap *ids); +int ids__insert(struct perf_hashmap *ids, const char *id); /* * Union two sets of ids (hashmaps) and construct a third, freeing ids1 and * ids2. */ -struct hashmap *ids__union(struct hashmap *ids1, struct hashmap *ids2); +struct perf_hashmap *ids__union(struct perf_hashmap *ids1, struct perf_has= hmap *ids2); =20 struct expr_parse_ctx *expr__ctx_new(void); void expr__ctx_clear(struct expr_parse_ctx *ctx); diff --git a/tools/perf/util/expr.y b/tools/perf/util/expr.y index e364790babb5..75c95e62aeac 100644 --- a/tools/perf/util/expr.y +++ b/tools/perf/util/expr.y @@ -29,7 +29,7 @@ int expr_lex(YYSTYPE * yylval_param , void *yyscanner); * When creating ids, holds the working set of event ids. NULL * implies the set is empty. */ - struct hashmap *ids; + struct perf_hashmap *ids; /* * The metric value. When not creating ids this is the value * read from a counter, a constant or some computed value. When diff --git a/tools/perf/util/fncache.c b/tools/perf/util/fncache.c index bf9559c55c63..9c49a914e784 100644 --- a/tools/perf/util/fncache.c +++ b/tools/perf/util/fncache.c @@ -8,7 +8,7 @@ #include "fncache.h" #include "hashmap.h" =20 -static struct hashmap *fncache; +static struct perf_hashmap *fncache; =20 static size_t fncache__hash(long key, void *ctx __maybe_unused) { @@ -22,10 +22,10 @@ static bool fncache__equal(long key1, long key2, void *= ctx __maybe_unused) =20 static void fncache__init(void) { - fncache =3D hashmap__new(fncache__hash, fncache__equal, /*ctx=3D*/NULL); + fncache =3D perf_hashmap__new(fncache__hash, fncache__equal, /*ctx=3D*/NU= LL); } =20 -static struct hashmap *fncache__get(void) +static struct perf_hashmap *fncache__get(void) { static pthread_once_t fncache_once =3D PTHREAD_ONCE_INIT; =20 @@ -38,7 +38,7 @@ static bool lookup_fncache(const char *name, bool *res) { long val; =20 - if (!hashmap__find(fncache__get(), name, &val)) + if (!perf_hashmap__find(fncache__get(), name, &val)) return false; =20 *res =3D (val !=3D 0); @@ -50,7 +50,7 @@ static void update_fncache(const char *name, bool res) char *old_key =3D NULL, *key =3D strdup(name); =20 if (key) { - hashmap__set(fncache__get(), key, res, &old_key, /*old_value*/NULL); + perf_hashmap__set(fncache__get(), key, res, &old_key, /*old_value*/NULL); free(old_key); } } diff --git a/tools/perf/util/ftrace.h b/tools/perf/util/ftrace.h index 950f2efafad2..46a0b3d94826 100644 --- a/tools/perf/util/ftrace.h +++ b/tools/perf/util/ftrace.h @@ -18,7 +18,7 @@ struct perf_ftrace { struct list_head graph_funcs; struct list_head nograph_funcs; struct list_head event_pair; - struct hashmap *profile_hash; + struct perf_hashmap *profile_hash; unsigned long percpu_buffer_size; bool inherit; bool use_nsec; diff --git a/tools/perf/util/hashmap.c b/tools/perf/util/hashmap.c index 140ee4055676..8c4b1f2af3ed 100644 --- a/tools/perf/util/hashmap.c +++ b/tools/perf/util/hashmap.c @@ -19,24 +19,24 @@ #pragma GCC poison reallocarray =20 /* start with 4 buckets */ -#define HASHMAP_MIN_CAP_BITS 2 +#define PERF_HASHMAP_MIN_CAP_BITS 2 =20 -static void hashmap_add_entry(struct hashmap_entry **pprev, - struct hashmap_entry *entry) +static void perf_hashmap_add_entry(struct perf_hashmap_entry **pprev, + struct perf_hashmap_entry *entry) { entry->next =3D *pprev; *pprev =3D entry; } =20 -static void hashmap_del_entry(struct hashmap_entry **pprev, - struct hashmap_entry *entry) +static void perf_hashmap_del_entry(struct perf_hashmap_entry **pprev, + struct perf_hashmap_entry *entry) { *pprev =3D entry->next; entry->next =3D NULL; } =20 -void hashmap__init(struct hashmap *map, hashmap_hash_fn hash_fn, - hashmap_equal_fn equal_fn, void *ctx) +void perf_hashmap__init(struct perf_hashmap *map, perf_hashmap_hash_fn has= h_fn, + perf_hashmap_equal_fn equal_fn, void *ctx) { map->hash_fn =3D hash_fn; map->equal_fn =3D equal_fn; @@ -48,24 +48,24 @@ void hashmap__init(struct hashmap *map, hashmap_hash_fn= hash_fn, map->sz =3D 0; } =20 -struct hashmap *hashmap__new(hashmap_hash_fn hash_fn, - hashmap_equal_fn equal_fn, +struct perf_hashmap *perf_hashmap__new(perf_hashmap_hash_fn hash_fn, + perf_hashmap_equal_fn equal_fn, void *ctx) { - struct hashmap *map =3D malloc(sizeof(struct hashmap)); + struct perf_hashmap *map =3D malloc(sizeof(struct perf_hashmap)); =20 if (!map) return ERR_PTR(-ENOMEM); - hashmap__init(map, hash_fn, equal_fn, ctx); + perf_hashmap__init(map, hash_fn, equal_fn, ctx); return map; } =20 -void hashmap__clear(struct hashmap *map) +void perf_hashmap__clear(struct perf_hashmap *map) { - struct hashmap_entry *cur, *tmp; + struct perf_hashmap_entry *cur, *tmp; size_t bkt; =20 - hashmap__for_each_entry_safe(map, cur, tmp, bkt) { + perf_hashmap__for_each_entry_safe(map, cur, tmp, bkt) { free(cur); } free(map->buckets); @@ -73,50 +73,50 @@ void hashmap__clear(struct hashmap *map) map->cap =3D map->cap_bits =3D map->sz =3D 0; } =20 -void hashmap__free(struct hashmap *map) +void perf_hashmap__free(struct perf_hashmap *map) { if (IS_ERR_OR_NULL(map)) return; =20 - hashmap__clear(map); + perf_hashmap__clear(map); free(map); } =20 -size_t hashmap__size(const struct hashmap *map) +size_t perf_hashmap__size(const struct perf_hashmap *map) { return map->sz; } =20 -size_t hashmap__capacity(const struct hashmap *map) +size_t perf_hashmap__capacity(const struct perf_hashmap *map) { return map->cap; } =20 -static bool hashmap_needs_to_grow(struct hashmap *map) +static bool perf_hashmap_needs_to_grow(struct perf_hashmap *map) { /* grow if empty or more than 75% filled */ return (map->cap =3D=3D 0) || ((map->sz + 1) * 4 / 3 > map->cap); } =20 -static int hashmap_grow(struct hashmap *map) +static int perf_hashmap_grow(struct perf_hashmap *map) { - struct hashmap_entry **new_buckets; - struct hashmap_entry *cur, *tmp; + struct perf_hashmap_entry **new_buckets; + struct perf_hashmap_entry *cur, *tmp; size_t new_cap_bits, new_cap; size_t h, bkt; =20 new_cap_bits =3D map->cap_bits + 1; - if (new_cap_bits < HASHMAP_MIN_CAP_BITS) - new_cap_bits =3D HASHMAP_MIN_CAP_BITS; + if (new_cap_bits < PERF_HASHMAP_MIN_CAP_BITS) + new_cap_bits =3D PERF_HASHMAP_MIN_CAP_BITS; =20 new_cap =3D 1UL << new_cap_bits; new_buckets =3D calloc(new_cap, sizeof(new_buckets[0])); if (!new_buckets) return -ENOMEM; =20 - hashmap__for_each_entry_safe(map, cur, tmp, bkt) { + perf_hashmap__for_each_entry_safe(map, cur, tmp, bkt) { h =3D hash_bits(map->hash_fn(cur->key, map->ctx), new_cap_bits); - hashmap_add_entry(&new_buckets[h], cur); + perf_hashmap_add_entry(&new_buckets[h], cur); } =20 map->cap =3D new_cap; @@ -127,12 +127,12 @@ static int hashmap_grow(struct hashmap *map) return 0; } =20 -static bool hashmap_find_entry(const struct hashmap *map, +static bool perf_hashmap_find_entry(const struct perf_hashmap *map, const long key, size_t hash, - struct hashmap_entry ***pprev, - struct hashmap_entry **entry) + struct perf_hashmap_entry ***pprev, + struct perf_hashmap_entry **entry) { - struct hashmap_entry *cur, **prev_ptr; + struct perf_hashmap_entry *cur, **prev_ptr; =20 if (!map->buckets) return false; @@ -151,11 +151,11 @@ static bool hashmap_find_entry(const struct hashmap *= map, return false; } =20 -int hashmap_insert(struct hashmap *map, long key, long value, - enum hashmap_insert_strategy strategy, +int perf_hashmap_insert(struct perf_hashmap *map, long key, long value, + enum perf_hashmap_insert_strategy strategy, long *old_key, long *old_value) { - struct hashmap_entry *entry; + struct perf_hashmap_entry *entry; size_t h; int err; =20 @@ -165,51 +165,51 @@ int hashmap_insert(struct hashmap *map, long key, lon= g value, *old_value =3D 0; =20 h =3D hash_bits(map->hash_fn(key, map->ctx), map->cap_bits); - if (strategy !=3D HASHMAP_APPEND && - hashmap_find_entry(map, key, h, NULL, &entry)) { + if (strategy !=3D PERF_HASHMAP_APPEND && + perf_hashmap_find_entry(map, key, h, NULL, &entry)) { if (old_key) *old_key =3D entry->key; if (old_value) *old_value =3D entry->value; =20 - if (strategy =3D=3D HASHMAP_SET || strategy =3D=3D HASHMAP_UPDATE) { + if (strategy =3D=3D PERF_HASHMAP_SET || strategy =3D=3D PERF_HASHMAP_UPD= ATE) { entry->key =3D key; entry->value =3D value; return 0; - } else if (strategy =3D=3D HASHMAP_ADD) { + } else if (strategy =3D=3D PERF_HASHMAP_ADD) { return -EEXIST; } } =20 - if (strategy =3D=3D HASHMAP_UPDATE) + if (strategy =3D=3D PERF_HASHMAP_UPDATE) return -ENOENT; =20 - if (hashmap_needs_to_grow(map)) { - err =3D hashmap_grow(map); + if (perf_hashmap_needs_to_grow(map)) { + err =3D perf_hashmap_grow(map); if (err) return err; h =3D hash_bits(map->hash_fn(key, map->ctx), map->cap_bits); } =20 - entry =3D malloc(sizeof(struct hashmap_entry)); + entry =3D malloc(sizeof(struct perf_hashmap_entry)); if (!entry) return -ENOMEM; =20 entry->key =3D key; entry->value =3D value; - hashmap_add_entry(&map->buckets[h], entry); + perf_hashmap_add_entry(&map->buckets[h], entry); map->sz++; =20 return 0; } =20 -bool hashmap_find(const struct hashmap *map, long key, long *value) +bool perf_hashmap_find(const struct perf_hashmap *map, long key, long *val= ue) { - struct hashmap_entry *entry; + struct perf_hashmap_entry *entry; size_t h; =20 h =3D hash_bits(map->hash_fn(key, map->ctx), map->cap_bits); - if (!hashmap_find_entry(map, key, h, NULL, &entry)) + if (!perf_hashmap_find_entry(map, key, h, NULL, &entry)) return false; =20 if (value) @@ -217,14 +217,14 @@ bool hashmap_find(const struct hashmap *map, long key= , long *value) return true; } =20 -bool hashmap_delete(struct hashmap *map, long key, +bool perf_hashmap_delete(struct perf_hashmap *map, long key, long *old_key, long *old_value) { - struct hashmap_entry **pprev, *entry; + struct perf_hashmap_entry **pprev, *entry; size_t h; =20 h =3D hash_bits(map->hash_fn(key, map->ctx), map->cap_bits); - if (!hashmap_find_entry(map, key, h, &pprev, &entry)) + if (!perf_hashmap_find_entry(map, key, h, &pprev, &entry)) return false; =20 if (old_key) @@ -232,7 +232,7 @@ bool hashmap_delete(struct hashmap *map, long key, if (old_value) *old_value =3D entry->value; =20 - hashmap_del_entry(pprev, entry); + perf_hashmap_del_entry(pprev, entry); free(entry); map->sz--; =20 diff --git a/tools/perf/util/hashmap.h b/tools/perf/util/hashmap.h index 0c4f155e8eb7..310b08c0b669 100644 --- a/tools/perf/util/hashmap.h +++ b/tools/perf/util/hashmap.h @@ -5,8 +5,8 @@ * * Copyright (c) 2019 Facebook */ -#ifndef __LIBBPF_HASHMAP_H -#define __LIBBPF_HASHMAP_H +#ifndef __PERF_UTIL_HASHMAP_H +#define __PERF_UTIL_HASHMAP_H =20 #include #include @@ -40,24 +40,24 @@ static inline size_t str_hash(const char *s) return h; } =20 -typedef size_t (*hashmap_hash_fn)(long key, void *ctx); -typedef bool (*hashmap_equal_fn)(long key1, long key2, void *ctx); +typedef size_t (*perf_hashmap_hash_fn)(long key, void *ctx); +typedef bool (*perf_hashmap_equal_fn)(long key1, long key2, void *ctx); =20 /* * Hashmap interface is polymorphic, keys and values could be either * long-sized integers or pointers, this is achieved as follows: * - interface functions that operate on keys and values are hidden - * behind auxiliary macros, e.g. hashmap_insert <-> hashmap__insert; + * behind auxiliary macros, e.g. perf_hashmap_insert <-> perf_hashmap__i= nsert; * - these auxiliary macros cast the key and value parameters as * long or long *, so the user does not have to specify the casts explic= itly; * - for pointer parameters (e.g. old_key) the size of the pointed - * type is verified by hashmap_cast_ptr using _Static_assert; - * - when iterating using hashmap__for_each_* forms + * type is verified by perf_hashmap_cast_ptr using _Static_assert; + * - when iterating using perf_hashmap__for_each_* forms * hasmap_entry->key should be used for integer keys and * hasmap_entry->pkey should be used for pointer keys, * same goes for values. */ -struct hashmap_entry { +struct perf_hashmap_entry { union { long key; const void *pkey; @@ -66,53 +66,53 @@ struct hashmap_entry { long value; void *pvalue; }; - struct hashmap_entry *next; + struct perf_hashmap_entry *next; }; =20 -struct hashmap { - hashmap_hash_fn hash_fn; - hashmap_equal_fn equal_fn; +struct perf_hashmap { + perf_hashmap_hash_fn hash_fn; + perf_hashmap_equal_fn equal_fn; void *ctx; =20 - struct hashmap_entry **buckets; + struct perf_hashmap_entry **buckets; size_t cap; size_t cap_bits; size_t sz; }; =20 -void hashmap__init(struct hashmap *map, hashmap_hash_fn hash_fn, - hashmap_equal_fn equal_fn, void *ctx); -struct hashmap *hashmap__new(hashmap_hash_fn hash_fn, - hashmap_equal_fn equal_fn, +void perf_hashmap__init(struct perf_hashmap *map, perf_hashmap_hash_fn has= h_fn, + perf_hashmap_equal_fn equal_fn, void *ctx); +struct perf_hashmap *perf_hashmap__new(perf_hashmap_hash_fn hash_fn, + perf_hashmap_equal_fn equal_fn, void *ctx); -void hashmap__clear(struct hashmap *map); -void hashmap__free(struct hashmap *map); +void perf_hashmap__clear(struct perf_hashmap *map); +void perf_hashmap__free(struct perf_hashmap *map); =20 -size_t hashmap__size(const struct hashmap *map); -size_t hashmap__capacity(const struct hashmap *map); +size_t perf_hashmap__size(const struct perf_hashmap *map); +size_t perf_hashmap__capacity(const struct perf_hashmap *map); =20 /* * Hashmap insertion strategy: - * - HASHMAP_ADD - only add key/value if key doesn't exist yet; - * - HASHMAP_SET - add key/value pair if key doesn't exist yet; otherwise, + * - PERF_HASHMAP_ADD - only add key/value if key doesn't exist yet; + * - PERF_HASHMAP_SET - add key/value pair if key doesn't exist yet; other= wise, * update value; - * - HASHMAP_UPDATE - update value, if key already exists; otherwise, do + * - PERF_HASHMAP_UPDATE - update value, if key already exists; otherwise,= do * nothing and return -ENOENT; - * - HASHMAP_APPEND - always add key/value pair, even if key already exist= s. + * - PERF_HASHMAP_APPEND - always add key/value pair, even if key already = exists. * This turns hashmap into a multimap by allowing multiple values to be * associated with the same key. Most useful read API for such hashmap is - * hashmap__for_each_key_entry() iteration. If hashmap__find() is still + * perf_hashmap__for_each_key_entry() iteration. If perf_hashmap__find()= is still * used, it will return last inserted key/value entry (first in a bucket * chain). */ -enum hashmap_insert_strategy { - HASHMAP_ADD, - HASHMAP_SET, - HASHMAP_UPDATE, - HASHMAP_APPEND, +enum perf_hashmap_insert_strategy { + PERF_HASHMAP_ADD, + PERF_HASHMAP_SET, + PERF_HASHMAP_UPDATE, + PERF_HASHMAP_APPEND, }; =20 -#define hashmap_cast_ptr(p) ({ \ +#define perf_hashmap_cast_ptr(p) ({ \ _Static_assert((__builtin_constant_p((p)) ? (p) =3D=3D NULL : 0) || \ sizeof(*(p)) =3D=3D sizeof(long), \ #p " pointee should be a long-sized integer or a pointer"); \ @@ -120,76 +120,76 @@ enum hashmap_insert_strategy { }) =20 /* - * hashmap__insert() adds key/value entry w/ various semantics, depending = on + * perf_hashmap__insert() adds key/value entry w/ various semantics, depen= ding on * provided strategy value. If a given key/value pair replaced already * existing key/value pair, both old key and old value will be returned * through old_key and old_value to allow calling code do proper memory * management. */ -int hashmap_insert(struct hashmap *map, long key, long value, - enum hashmap_insert_strategy strategy, +int perf_hashmap_insert(struct perf_hashmap *map, long key, long value, + enum perf_hashmap_insert_strategy strategy, long *old_key, long *old_value); =20 -#define hashmap__insert(map, key, value, strategy, old_key, old_value) \ - hashmap_insert((map), (long)(key), (long)(value), (strategy), \ - hashmap_cast_ptr(old_key), \ - hashmap_cast_ptr(old_value)) +#define perf_hashmap__insert(map, key, value, strategy, old_key, old_value= ) \ + perf_hashmap_insert((map), (long)(key), (long)(value), (strategy), \ + perf_hashmap_cast_ptr(old_key), \ + perf_hashmap_cast_ptr(old_value)) =20 -#define hashmap__add(map, key, value) \ - hashmap__insert((map), (key), (value), HASHMAP_ADD, NULL, NULL) +#define perf_hashmap__add(map, key, value) \ + perf_hashmap__insert((map), (key), (value), PERF_HASHMAP_ADD, NULL, NULL) =20 -#define hashmap__set(map, key, value, old_key, old_value) \ - hashmap__insert((map), (key), (value), HASHMAP_SET, (old_key), (old_value= )) +#define perf_hashmap__set(map, key, value, old_key, old_value) \ + perf_hashmap__insert((map), (key), (value), PERF_HASHMAP_SET, (old_key), = (old_value)) =20 -#define hashmap__update(map, key, value, old_key, old_value) \ - hashmap__insert((map), (key), (value), HASHMAP_UPDATE, (old_key), (old_va= lue)) +#define perf_hashmap__update(map, key, value, old_key, old_value) \ + perf_hashmap__insert((map), (key), (value), PERF_HASHMAP_UPDATE, (old_key= ), (old_value)) =20 -#define hashmap__append(map, key, value) \ - hashmap__insert((map), (key), (value), HASHMAP_APPEND, NULL, NULL) +#define perf_hashmap__append(map, key, value) \ + perf_hashmap__insert((map), (key), (value), PERF_HASHMAP_APPEND, NULL, NU= LL) =20 -bool hashmap_delete(struct hashmap *map, long key, long *old_key, long *ol= d_value); +bool perf_hashmap_delete(struct perf_hashmap *map, long key, long *old_key= , long *old_value); =20 -#define hashmap__delete(map, key, old_key, old_value) \ - hashmap_delete((map), (long)(key), \ - hashmap_cast_ptr(old_key), \ - hashmap_cast_ptr(old_value)) +#define perf_hashmap__delete(map, key, old_key, old_value) \ + perf_hashmap_delete((map), (long)(key), \ + perf_hashmap_cast_ptr(old_key), \ + perf_hashmap_cast_ptr(old_value)) =20 -bool hashmap_find(const struct hashmap *map, long key, long *value); +bool perf_hashmap_find(const struct perf_hashmap *map, long key, long *val= ue); =20 -#define hashmap__find(map, key, value) \ - hashmap_find((map), (long)(key), hashmap_cast_ptr(value)) +#define perf_hashmap__find(map, key, value) \ + perf_hashmap_find((map), (long)(key), perf_hashmap_cast_ptr(value)) =20 /* - * hashmap__for_each_entry - iterate over all entries in hashmap + * perf_hashmap__for_each_entry - iterate over all entries in hashmap * @map: hashmap to iterate - * @cur: struct hashmap_entry * used as a loop cursor + * @cur: struct perf_hashmap_entry * used as a loop cursor * @bkt: integer used as a bucket loop cursor */ -#define hashmap__for_each_entry(map, cur, bkt) \ +#define perf_hashmap__for_each_entry(map, cur, bkt) \ for (bkt =3D 0; bkt < (map)->cap; bkt++) \ for (cur =3D (map)->buckets[bkt]; cur; cur =3D cur->next) =20 /* - * hashmap__for_each_entry_safe - iterate over all entries in hashmap, safe + * perf_hashmap__for_each_entry_safe - iterate over all entries in hashmap= , safe * against removals * @map: hashmap to iterate - * @cur: struct hashmap_entry * used as a loop cursor - * @tmp: struct hashmap_entry * used as a temporary next cursor storage + * @cur: struct perf_hashmap_entry * used as a loop cursor + * @tmp: struct perf_hashmap_entry * used as a temporary next cursor stora= ge * @bkt: integer used as a bucket loop cursor */ -#define hashmap__for_each_entry_safe(map, cur, tmp, bkt) \ +#define perf_hashmap__for_each_entry_safe(map, cur, tmp, bkt) \ for (bkt =3D 0; bkt < (map)->cap; bkt++) \ for (cur =3D (map)->buckets[bkt]; \ cur && ({tmp =3D cur->next; true; }); \ cur =3D tmp) =20 /* - * hashmap__for_each_key_entry - iterate over entries associated with give= n key + * perf_hashmap__for_each_key_entry - iterate over entries associated with= given key * @map: hashmap to iterate - * @cur: struct hashmap_entry * used as a loop cursor + * @cur: struct perf_hashmap_entry * used as a loop cursor * @key: key to iterate entries for */ -#define hashmap__for_each_key_entry(map, cur, _key) \ +#define perf_hashmap__for_each_key_entry(map, cur, _key) \ for (cur =3D (map)->buckets \ ? (map)->buckets[hash_bits((map)->hash_fn((_key), (map)->ctx), (map= )->cap_bits)] \ : NULL; \ @@ -197,7 +197,7 @@ bool hashmap_find(const struct hashmap *map, long key, = long *value); cur =3D cur->next) \ if ((map)->equal_fn(cur->key, (_key), (map)->ctx)) =20 -#define hashmap__for_each_key_entry_safe(map, cur, tmp, _key) \ +#define perf_hashmap__for_each_key_entry_safe(map, cur, tmp, _key) \ for (cur =3D (map)->buckets \ ? (map)->buckets[hash_bits((map)->hash_fn((_key), (map)->ctx), (map= )->cap_bits)] \ : NULL; \ @@ -205,4 +205,4 @@ bool hashmap_find(const struct hashmap *map, long key, = long *value); cur =3D tmp) \ if ((map)->equal_fn(cur->key, (_key), (map)->ctx)) =20 -#endif /* __LIBBPF_HASHMAP_H */ +#endif /* __PERF_UTIL_HASHMAP_H */ diff --git a/tools/perf/util/hwmon_pmu.c b/tools/perf/util/hwmon_pmu.c index fb3ffa8d32ad..4dc5634aab0f 100644 --- a/tools/perf/util/hwmon_pmu.c +++ b/tools/perf/util/hwmon_pmu.c @@ -103,7 +103,7 @@ static const char *const hwmon_units[HWMON_TYPE_MAX] = =3D { =20 struct hwmon_pmu { struct perf_pmu pmu; - struct hashmap events; + struct perf_hashmap events; char *hwmon_dir; }; =20 @@ -135,12 +135,12 @@ bool evsel__is_hwmon(const struct evsel *evsel) return perf_pmu__is_hwmon(evsel->pmu); } =20 -static size_t hwmon_pmu__event_hashmap_hash(long key, void *ctx __maybe_un= used) +static size_t hwmon_pmu__event_perf_hashmap_hash(long key, void *ctx __may= be_unused) { return ((union hwmon_pmu_event_key)key).type_and_num; } =20 -static bool hwmon_pmu__event_hashmap_equal(long key1, long key2, void *ctx= __maybe_unused) +static bool hwmon_pmu__event_perf_hashmap_equal(long key1, long key2, void= *ctx __maybe_unused) { return ((union hwmon_pmu_event_key)key1).type_and_num =3D=3D ((union hwmon_pmu_event_key)key2).type_and_num; @@ -236,7 +236,7 @@ static void fix_name(char *p) static int hwmon_pmu__read_events(struct hwmon_pmu *pmu) { int err =3D 0; - struct hashmap_entry *cur, *tmp; + struct perf_hashmap_entry *cur, *tmp; size_t bkt; struct io_dirent64 *ent; struct io_dir dir; @@ -267,13 +267,13 @@ static int hwmon_pmu__read_events(struct hwmon_pmu *p= mu) } key.num =3D number; key.type =3D type; - if (!hashmap__find(&pmu->events, key.type_and_num, &value)) { + if (!perf_hashmap__find(&pmu->events, key.type_and_num, &value)) { value =3D zalloc(sizeof(*value)); if (!value) { err =3D -ENOMEM; goto err_out; } - err =3D hashmap__add(&pmu->events, key.type_and_num, value); + err =3D perf_hashmap__add(&pmu->events, key.type_and_num, value); if (err) { free(value); err =3D -ENOMEM; @@ -317,10 +317,10 @@ static int hwmon_pmu__read_events(struct hwmon_pmu *p= mu) close(fd); } } - if (hashmap__size(&pmu->events) =3D=3D 0) + if (perf_hashmap__size(&pmu->events) =3D=3D 0) pr_debug2("hwmon_pmu: %s has no events\n", pmu->pmu.name); =20 - hashmap__for_each_entry_safe((&pmu->events), cur, tmp, bkt) { + perf_hashmap__for_each_entry_safe((&pmu->events), cur, tmp, bkt) { union hwmon_pmu_event_key key =3D { .type_and_num =3D cur->key, }; @@ -329,7 +329,7 @@ static int hwmon_pmu__read_events(struct hwmon_pmu *pmu) if (!test_bit(HWMON_ITEM_INPUT, value->items)) { pr_debug("hwmon_pmu: %s removing event '%s%d' that has no input file\n", pmu->pmu.name, hwmon_type_strs[key.type], key.num); - hashmap__delete(&pmu->events, key.type_and_num, &key, &value); + perf_hashmap__delete(&pmu->events, key.type_and_num, &key, &value); zfree(&value->label); zfree(&value->name); free(value); @@ -383,8 +383,8 @@ struct perf_pmu *hwmon_pmu__new(struct list_head *pmus,= const char *hwmon_dir, } INIT_LIST_HEAD(&hwm->pmu.format); INIT_LIST_HEAD(&hwm->pmu.caps); - hashmap__init(&hwm->events, hwmon_pmu__event_hashmap_hash, - hwmon_pmu__event_hashmap_equal, /*ctx=3D*/NULL); + perf_hashmap__init(&hwm->events, hwmon_pmu__event_perf_hashmap_hash, + hwmon_pmu__event_perf_hashmap_equal, /*ctx=3D*/NULL); =20 list_add_tail(&hwm->pmu.list, pmus); return &hwm->pmu; @@ -393,17 +393,17 @@ struct perf_pmu *hwmon_pmu__new(struct list_head *pmu= s, const char *hwmon_dir, void hwmon_pmu__exit(struct perf_pmu *pmu) { struct hwmon_pmu *hwm =3D container_of(pmu, struct hwmon_pmu, pmu); - struct hashmap_entry *cur, *tmp; + struct perf_hashmap_entry *cur, *tmp; size_t bkt; =20 - hashmap__for_each_entry_safe((&hwm->events), cur, tmp, bkt) { + perf_hashmap__for_each_entry_safe((&hwm->events), cur, tmp, bkt) { struct hwmon_pmu_event_value *value =3D cur->pvalue; =20 zfree(&value->label); zfree(&value->name); free(value); } - hashmap__clear(&hwm->events); + perf_hashmap__clear(&hwm->events); zfree(&hwm->hwmon_dir); } =20 @@ -459,13 +459,13 @@ static size_t hwmon_pmu__describe_items(struct hwmon_= pmu *hwm, char *out_buf, si int hwmon_pmu__for_each_event(struct perf_pmu *pmu, void *state, pmu_event= _callback cb) { struct hwmon_pmu *hwm =3D container_of(pmu, struct hwmon_pmu, pmu); - struct hashmap_entry *cur; + struct perf_hashmap_entry *cur; size_t bkt; =20 if (hwmon_pmu__read_events(hwm)) return false; =20 - hashmap__for_each_entry((&hwm->events), cur, bkt) { + perf_hashmap__for_each_entry((&hwm->events), cur, bkt) { static const char *const hwmon_scale_units[HWMON_TYPE_MAX] =3D { NULL, "0.001V", /* cpu */ @@ -547,7 +547,7 @@ size_t hwmon_pmu__num_events(struct perf_pmu *pmu) struct hwmon_pmu *hwm =3D container_of(pmu, struct hwmon_pmu, pmu); =20 hwmon_pmu__read_events(hwm); - return hashmap__size(&hwm->events); + return perf_hashmap__size(&hwm->events); } =20 bool hwmon_pmu__have_event(struct perf_pmu *pmu, const char *name) @@ -556,7 +556,7 @@ bool hwmon_pmu__have_event(struct perf_pmu *pmu, const = char *name) enum hwmon_type type; int number; union hwmon_pmu_event_key key =3D { .type_and_num =3D 0 }; - struct hashmap_entry *cur; + struct perf_hashmap_entry *cur; size_t bkt; =20 if (!parse_hwmon_filename(name, &type, &number, /*item=3D*/NULL, /*is_ala= rm=3D*/NULL)) @@ -567,12 +567,12 @@ bool hwmon_pmu__have_event(struct perf_pmu *pmu, cons= t char *name) =20 key.type =3D type; key.num =3D number; - if (hashmap_find(&hwm->events, key.type_and_num, /*value=3D*/NULL)) + if (perf_hashmap_find(&hwm->events, key.type_and_num, /*value=3D*/NULL)) return true; if (key.num !=3D -1) return false; /* Item is of form _ which means we should match _