Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp279198pxb; Sat, 21 Aug 2021 02:23:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxlM8OEa/qceFZVaoof/+N1BblJFDC0VrI+KTjdPhiHJcXZg5GZI5zWaw825vnODqKq1GDM X-Received: by 2002:a02:3b22:: with SMTP id c34mr6253532jaa.140.1629537811357; Sat, 21 Aug 2021 02:23:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629537811; cv=none; d=google.com; s=arc-20160816; b=gLGFpFieQ6lfMSD/HfVImIQKnLxmG3E8OLstjRbqH265V3amCRsu4c/bHPJsY05i8j FsYYn44DMiDGsMMFTucqHikitl9CD0JhWV3441CsTZvZsqR9kSbIttCv4pE9PJLXGLlV IpGT99I3RTy5C7vBM5MQ9MGt2WvkiR9+enTkPpK1vc6JTQ3tgBCzTHNP1PwCXTAoLbwY US65r+DcXDovjcsM5264fijmHKlsiJiPbYx44N4o7efUC4Q3v9io09+aBLoeOB0J8Mk7 JsIrE8q27fA/tGBZSd5fZL3VHZ4d73uWw+QHMEk5Aqc9wMWTjANcX+dDNkbToAow8tmK zgYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=QInwCOuO2ckUJlld3UzzWnV+R3RPjh8yWuOELi0NyEQ=; b=HYt75TmrXl/ZWGZP6WgtmLFkfzfx7VuRmoqh323vqJpxiJzZ0PSZDvAbAOaPIivj2T pop7XkCh/23502dfFNNy041871SYxJEI+zkqXxWCNtmwmz3H0aCuI9vkRDS33aGBXCUo 5C0v6kJghW/+EAzfDyUcyI6n0OhEmeqLnYJMg40AHDVH/Rhs1jRF05ZEFI1ZVJ3sdKZ4 e4nE/q3UsSLfK2TgM2kzN75VYTS3oHiJHHjmGfIum6OG7EWeMyZddPxTwXZ5t1eJEe5q hlOfgV5yrGQ/fjh/iHPfkqfxMQZc6Jqt/TLQcrNfTv6COU1GqaqixZdq7tK9xW1wQPRq 3/TA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=f+GGTOdm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m18si9721739iow.66.2021.08.21.02.23.20; Sat, 21 Aug 2021 02:23:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=f+GGTOdm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241033AbhHUJW6 (ORCPT + 99 others); Sat, 21 Aug 2021 05:22:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238216AbhHUJWP (ORCPT ); Sat, 21 Aug 2021 05:22:15 -0400 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3ACD8C06114C; Sat, 21 Aug 2021 02:20:26 -0700 (PDT) Received: by mail-ed1-x536.google.com with SMTP id g21so17635262edw.4; Sat, 21 Aug 2021 02:20:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QInwCOuO2ckUJlld3UzzWnV+R3RPjh8yWuOELi0NyEQ=; b=f+GGTOdmQ56JFw+99caC9CxgbqDRllsngG7xH0A54iDf3Iggd+oPiexWzubco4j7Pa YzH4JuoSKdbMx2eLnvZGZTR2RGm9XrHeJuAjhXBJ9gAoGFpacA17ygDKum5PG+q8bzk5 2sygZTXSFlWHO4PyvuUgmcn3OHmYZ7SMi53CwwfXaBvISEpkhelp39rUB90jeHQD0c4y 8UQY/7CjM01f4CBMy08tYuFVmhUe8VmmL7tkGkCMM4ZwEsFb78WOcrCU62Rq6jRF+kxv Cy82xQot62x3/fU65XdjbNg6+Ma1azNJX6PJZEhzMFatzugymXwEjgLJzkikGoi5g3q4 KObg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QInwCOuO2ckUJlld3UzzWnV+R3RPjh8yWuOELi0NyEQ=; b=nWCjaV3JJYdjG0zydvC+jctgeg60sAFMRMsuGdD4C+9zMesAw4A86+nnGMzwQWJqZp zNBvxn0av3LE1UDp17Zd1A1ThUbfJN4xXZjTr1SX6yUWX7v9yBFTUkwoA/n9hvgDWpgJ 1+VERGrVGdc12a9HgAlt2wg952iopNLncGUYiye9MbLhk95t6geSDecTbeIg6XYbCgHh /OGANaz8x+a1CZ5uQRSgio+qs+ZOSBhJciI6ZEYmgYk0wh4utvezN1GF7KbOnla49g66 gklbSz4ysb3ytDvUY+z7iKz1mKdVqMJVpJ5a9EvydkisadhWhvVngNcOxzfNcNidqJ// Wm6g== X-Gm-Message-State: AOAM530AdI7s5A88I9aRL9pBNsiVJMwg8bsfK6EstjosegBxhMYHMvVq i/fWL4y86BQFwB1+RJYT6YY= X-Received: by 2002:a05:6402:10d9:: with SMTP id p25mr26451432edu.51.1629537624769; Sat, 21 Aug 2021 02:20:24 -0700 (PDT) Received: from honeypot.. (mob-176-243-254-204.net.vodafone.it. [176.243.254.204]) by smtp.googlemail.com with ESMTPSA id a25sm4003878ejv.91.2021.08.21.02.20.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Aug 2021 02:20:24 -0700 (PDT) From: Riccardo Mancini To: Arnaldo Carvalho de Melo Cc: Ian Rogers , Namhyung Kim , Peter Zijlstra , Ingo Molnar , Mark Rutland , Jiri Olsa , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Riccardo Mancini Subject: [RFC PATCH v1 29/37] perf evlist: add custom fallback to evlist__open Date: Sat, 21 Aug 2021 11:19:35 +0200 Message-Id: <6109f52f83bbb9d6782969a5e6fc66f5cab7abd8.1629490974.git.rickyman7@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch adds the function evlist__open_custom, which makes it possible to provide a custom fallback mechanism to evsel__open. This function will be used in record__open in the following patch. This could also be used to adapt perf-stat way of opening to the new multithreaded mechanism. Signed-off-by: Riccardo Mancini --- tools/perf/util/evlist.c | 27 +++++++++++++++++++++------ tools/perf/util/evlist.h | 9 +++++++++ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 3472038d719ec7d4..22b9607dcc637a2d 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -1405,15 +1405,20 @@ static int evlist__create_syswide_maps(struct evlist *evlist) return err; } -static int evlist__open_singlethreaded(struct evlist *evlist) +static int evlist__open_singlethreaded(struct evlist *evlist, + struct evlist_open_custom_fallback *cust_fb) { struct evsel *evsel; int err; evlist__for_each_entry(evlist, evsel) { +try_again: err = evsel__open(evsel, evsel->core.cpus, evsel->core.threads); - if (err < 0) + if (err < 0) { + if (cust_fb && cust_fb->func(cust_fb, evlist, evsel, err)) + goto try_again; return err; + } } return 0; @@ -1469,7 +1474,8 @@ static void evlist__open_multithreaded_func(struct work_struct *_work) } } -static int evlist__open_multithreaded(struct evlist *evlist) +static int evlist__open_multithreaded(struct evlist *evlist, + struct evlist_open_custom_fallback *cust_fb) { int cpu, cpuid, cpuidx, thread, err; struct evlist_open_work *works; @@ -1567,6 +1573,9 @@ static int evlist__open_multithreaded(struct evlist *evlist) if (evsel__detect_missing_features(evsel)) goto reprepare; + if (cust_fb && cust_fb->func(cust_fb, evlist, evsel, err)) + goto reprepare; + // no fallback worked, return the error goto out; } @@ -1579,7 +1588,8 @@ static int evlist__open_multithreaded(struct evlist *evlist) return err; } -int evlist__open(struct evlist *evlist) +int evlist__open_custom(struct evlist *evlist, + struct evlist_open_custom_fallback *cust_fb) { int err; @@ -1596,9 +1606,9 @@ int evlist__open(struct evlist *evlist) evlist__update_id_pos(evlist); if (perf_singlethreaded) - err = evlist__open_singlethreaded(evlist); + err = evlist__open_singlethreaded(evlist, cust_fb); else - err = evlist__open_multithreaded(evlist); + err = evlist__open_multithreaded(evlist, cust_fb); if (err) goto out_err; @@ -1610,6 +1620,11 @@ int evlist__open(struct evlist *evlist) return err; } +int evlist__open(struct evlist *evlist) +{ + return evlist__open_custom(evlist, NULL); +} + int evlist__prepare_workload(struct evlist *evlist, struct target *target, const char *argv[], bool pipe_output, void (*exec_error)(int signo, siginfo_t *info, void *ucontext)) { diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h index b0c2da0f9755b2d1..cb753b4c4e70b4ba 100644 --- a/tools/perf/util/evlist.h +++ b/tools/perf/util/evlist.h @@ -161,6 +161,15 @@ void evlist__mmap_consume(struct evlist *evlist, int idx); int evlist__open(struct evlist *evlist); void evlist__close(struct evlist *evlist); +struct evlist_open_custom_fallback; +typedef bool (*evlist_open_custom_fallback_fn)(struct evlist_open_custom_fallback *fallback, + struct evlist *evlist, struct evsel *evsel, int err); +struct evlist_open_custom_fallback { + evlist_open_custom_fallback_fn func; +}; +int evlist__open_custom(struct evlist *evlist, struct evlist_open_custom_fallback *cust_fb); + + struct callchain_param; void evlist__set_id_pos(struct evlist *evlist); -- 2.31.1