From nobody Tue Nov 26 17:30:59 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 A1E7D2141A1 for ; Wed, 16 Oct 2024 19:00:13 +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=1729105216; cv=none; b=sl3vM3BGZPdmRNmZan3gvbP6lLPiBU4X7SFZlt6DGQ67Wz8OhssvTZBHAofmfWoiy/EJRlmaKAf3RPim/lqHGP034GkDqF5GsgllF7KBMzLiEBX8Vd4QTM0OC4axYwvudFZ4lxWHgxOoWdUMyYhKaLZAngHtY9oGzX84XM6cXCQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729105216; c=relaxed/simple; bh=YiUPcFzffWyNLYA+8FWdtxkS29XrLMr0gAQw3As/6sc=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=YEylGs8qHVXavvpLo8f/j4a1OkcuVn5pAXGS5MgkvQwXuYL8W1Xoxm1ScKgjV+apuK0fctch7rlyg+OQcB13d1ZJ6YB8929VY342uJvnNSdkE3AOGHLADP8kpY7VOKcPdKile1EqUqU+ktW7mFhZrY81VdVd9jpzENwiAJYri+o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--bgeffon.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=pFojFKTT; 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--bgeffon.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="pFojFKTT" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e35d1d8c82so4037267b3.3 for ; Wed, 16 Oct 2024 12:00:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729105212; x=1729710012; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=h4jjSM+ORlT3LjodZYnx5ObwICh1BMY0UwPD2hawNIk=; b=pFojFKTTXijq4Cv1novJi9+ajpcR+H8Q1syFh7BcYKD0kpBGcASVYetmSTgWUZwJgl oifsmX/18lQEwRiZkamqbAjCdQrHGDZMHHN3dKzkilXYvtomn+myL1hQm+E6HFstaBLh YEnEWMub59SSFuQifds/hmgHEW73aIvmHouUq4aMWBdmjtYDjem7WQ06qQwwkBjAv3Y4 3z/+QGMqbFf+z3xQeFWHGd93pqHSqr2XzZBpZszuHD4pGo+AJ4CRVe7rnI565qWMFtpw Db2EgAfOcMMQOBcasNZuT7BRxC/fTFa34WcwiG7UVZeBPG45R8DNhbF7bzTyT9etd2tT LpsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729105212; x=1729710012; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=h4jjSM+ORlT3LjodZYnx5ObwICh1BMY0UwPD2hawNIk=; b=YQ/M4pCSBaJlktUtS966ftisl9t1c1fP3N/1WFWKYewykraCo9reTK87rohcK/MQcx v8AMaU6Z0FH6egImPdwgoqW739GOvLL65CK+JYufaCCBlJptJVvI4wtdkoMQV5BnDFqb QbjpqCcpPHgOZ91MTZnx20MOWNtJisALBdAjlVl3HsDtaOBlcaDxd6+c0WBoXw8N8Ci7 aB38OzSqQaairB+TZ//sDiGB+ijwWzOGE1ron+H6sjaIkB1QajpPLWlFNk+kmr7XGG/j pVpSiGBxmB+GDKMfFw5DY3AcYmzKjd4OL9quRxQ1Cl62ncsiCrFz9b5Q995pwzmj8Awa /2Ig== X-Forwarded-Encrypted: i=1; AJvYcCUBtLmOE9msRKEUfFYJ8JAFLBspaSb7kMt8Na51utRTqMsRozL7FYrHhHx0mcyCslQidl9g0ILKCY/GLhg=@vger.kernel.org X-Gm-Message-State: AOJu0Yya6toD849cIFNB0TnhT3TsS1V2m6pFTS4E7kugN8BqA7aJiHVo nsbwI6ApIozLBQn/SZPXbL+roE9fOa27Kh0OUnBfn3ZVWtJc2sd/RnNFb0ld9Sc8f/LQTx4TA0m CFHWQFw== X-Google-Smtp-Source: AGHT+IEOPZW7aXJcAd9af4VdSY0ecDTuw98miWo2+E7cKeDPdGZBkIG1FmVZ2rfbL34eNz+ajcIcTDq5okT5 X-Received: from bjg.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:415]) (user=bgeffon job=sendgmr) by 2002:a05:690c:2b08:b0:6d5:df94:b7ec with SMTP id 00721157ae682-6e3d3f787ddmr550497b3.1.1729105212629; Wed, 16 Oct 2024 12:00:12 -0700 (PDT) Date: Wed, 16 Oct 2024 15:00:09 -0400 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Message-ID: <20241016190009.866615-1-bgeffon@google.com> Subject: [PATCH] perf tools: sched-pipe bench: add (-n) nonblocking benchmark From: Brian Geffon To: Peter Zijlstra , Ingo Molnar Cc: Arnaldo Carvalho de Melo , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Adrian Hunter , Jiri Olsa , Namhyung Kim , Steven Rostedt , Brian Geffon Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The -n mode will benchmark pipes in a non-blocking mode using epoll_wait. This specific mode was added to demonstrate the broken sync nature of epoll: https://lore.kernel.org/lkml/20240426-zupfen-jahrzehnt-5be786bcdf= 04@brauner Signed-off-by: Brian Geffon Reviewed-by: Ian Rogers --- tools/perf/bench/sched-pipe.c | 43 +++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/tools/perf/bench/sched-pipe.c b/tools/perf/bench/sched-pipe.c index 3af6d3c55aba..e2562677df96 100644 --- a/tools/perf/bench/sched-pipe.c +++ b/tools/perf/bench/sched-pipe.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -34,6 +35,8 @@ struct thread_data { int nr; int pipe_read; int pipe_write; + struct epoll_event epoll_ev; + int epoll_fd; bool cgroup_failed; pthread_t pthread; }; @@ -44,6 +47,7 @@ static int loops =3D LOOPS_DEFAULT; /* Use processes by default: */ static bool threaded; =20 +static bool nonblocking; static char *cgrp_names[2]; static struct cgroup *cgrps[2]; =20 @@ -81,6 +85,7 @@ static int parse_two_cgroups(const struct option *opt __m= aybe_unused, } =20 static const struct option options[] =3D { + OPT_BOOLEAN('n', "nonblocking", &nonblocking, "Use non-blocking operation= s"), OPT_INTEGER('l', "loop", &loops, "Specify number of loops"), OPT_BOOLEAN('T', "threaded", &threaded, "Specify threads/process based ta= sk setup"), OPT_CALLBACK('G', "cgroups", NULL, "SEND,RECV", @@ -165,11 +170,25 @@ static void exit_cgroup(int nr) free(cgrp_names[nr]); } =20 +static inline int read_pipe(struct thread_data *td) +{ + int ret, m; +retry: + if (nonblocking) { + ret =3D epoll_wait(td->epoll_fd, &td->epoll_ev, 1, -1); + if (ret < 0) + return ret; + } + ret =3D read(td->pipe_read, &m, sizeof(int)); + if (nonblocking && ret < 0 && errno =3D=3D EWOULDBLOCK) + goto retry; + return ret; +} + static void *worker_thread(void *__tdata) { struct thread_data *td =3D __tdata; - int m =3D 0, i; - int ret; + int i, ret, m =3D 0; =20 ret =3D enter_cgroup(td->nr); if (ret < 0) { @@ -177,16 +196,23 @@ static void *worker_thread(void *__tdata) return NULL; } =20 + if (nonblocking) { + td->epoll_ev.events =3D EPOLLIN; + td->epoll_fd =3D epoll_create(1); + BUG_ON(td->epoll_fd < 0); + BUG_ON(epoll_ctl(td->epoll_fd, EPOLL_CTL_ADD, td->pipe_read, &td->epoll_= ev) < 0); + } + for (i =3D 0; i < loops; i++) { if (!td->nr) { - ret =3D read(td->pipe_read, &m, sizeof(int)); + ret =3D read_pipe(td); BUG_ON(ret !=3D sizeof(int)); ret =3D write(td->pipe_write, &m, sizeof(int)); BUG_ON(ret !=3D sizeof(int)); } else { ret =3D write(td->pipe_write, &m, sizeof(int)); BUG_ON(ret !=3D sizeof(int)); - ret =3D read(td->pipe_read, &m, sizeof(int)); + ret =3D read_pipe(td); BUG_ON(ret !=3D sizeof(int)); } } @@ -209,13 +235,16 @@ int bench_sched_pipe(int argc, const char **argv) * discarding returned value of read(), write() * causes error in building environment for perf */ - int __maybe_unused ret, wait_stat; + int __maybe_unused ret, wait_stat, flags =3D 0; pid_t pid, retpid __maybe_unused; =20 argc =3D parse_options(argc, argv, options, bench_sched_pipe_usage, 0); =20 - BUG_ON(pipe(pipe_1)); - BUG_ON(pipe(pipe_2)); + if (nonblocking) + flags |=3D O_NONBLOCK; + + BUG_ON(pipe2(pipe_1, flags)); + BUG_ON(pipe2(pipe_2, flags)); =20 gettimeofday(&start, NULL); =20 --=20 2.47.0.rc1.288.g06298d1525-goog