From patchwork Fri Aug 16 02:30:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 13765370 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 596DF2BCFF; Fri, 16 Aug 2024 02:30:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723775448; cv=none; b=myz94hzpJaiL+dNwwZRyl0+fIo5LykeK2jc73ilbFhCgznTdNzSj2o+V+XlD5DdT48NqVqEy8VJIAtBjN7p3uboeLAirEy5b+mnV0qEUm39mO7QRQE2FF6HK86VUEb8zgpsZNx4EzKi71fQqTJv2pvGNIGNbQD8KHkEzmu0PqWY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723775448; c=relaxed/simple; bh=6sTPTHmCqB521M+gs5j5T2U6Eqy5Os/J32FMSdEHQwY=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Content-Type; b=Sdo+hcb+rZCAqMwg2cjDRdiahOQ3Ge81d9t/Kn0NELHnZTLOyaGLr9qbKnyUX34bnDFUTwswkktZ72gfNJtcS5v2Pl5pfM9yzIMOOhyBT3d6melKyN7jVM/Ya8zkiOtli+AMAXdYL8bxsCPjnNQWkPM9kD7OAYLsVULMq430dWI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oU/rC2ij; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="oU/rC2ij" Received: by smtp.kernel.org (Postfix) with ESMTPSA id ECAE4C32786; Fri, 16 Aug 2024 02:30:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1723775447; bh=6sTPTHmCqB521M+gs5j5T2U6Eqy5Os/J32FMSdEHQwY=; h=From:To:Cc:Subject:Date:From; b=oU/rC2ijUo3o5kDBnNfb9x2sbpqrjeyYftu5ssZyDQsd/qs10T1QTsQgSP4OMDIXi Raoi0cxKYneLHyjQTzIF1DAyuz4g8xF8ZF07sMa1Z2vIZ27sUcR8o4HTsLgYHwqMvZ CrNWecMxIAF5Qs63jrlWwZ2HWjOdbDIiCIOyv29+K7QqHjC2pFjIBsvF8dn8KqeIHU YjlPoLITG8c3cgXd00zVCaTDIGmZsaUI0VdJTpdyVz9o4Z2y5kAD3CVFXfePvWp5yi dzggA12KOtMehGasaHMSbr2a4LC8z6oRFRQQf1Ewk+0p6ai1AX9MGgV1PO5FuBagpe BE7XQLRwaWq3w== From: "Masami Hiramatsu (Google)" To: Steven Rostedt , Shuah Khan Cc: Masami Hiramatsu , Tom Zanussi , Mathieu Desnoyers , linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v4 0/3] tracing: Support poll on event hist file Date: Fri, 16 Aug 2024 11:30:43 +0900 Message-Id: <172377544331.67914.7474878424159759789.stgit@devnote2> X-Mailer: git-send-email 2.34.1 User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Hi, Here is the v4 patch to support polling on event 'hist' file. The previous version is here; https://lore.kernel.org/all/172359427367.323666.6446548762874507863.stgit@devnote2/ This version uses getopt() in poll test command in [3/3] according to Shuah's comment in the previous thread. Background ---------- There has been interest in allowing user programs to monitor kernel events in real time. Ftrace provides `trace_pipe` interface to wait on events in the ring buffer, but it is needed to wait until filling up a page with events in the ring buffer. We can also peek the `trace` file periodically, but that is inefficient way to monitor a randomely happening event. Overview -------- This patch set allows user to `poll`(or `select`, `epoll`) on event histogram interface. As you know each event has its own `hist` file which shows histograms generated by trigger action. So user can set a new hist trigger on any event you want to monitor, and poll on the `hist` file until it is updated. There are 2 poll events are supported, POLLIN and POLLPRI. POLLIN means that there are any readable update on `hist` file and this event will be flashed only when you call read(). So, this is useful if you want to read the histogram periodically. The other POLLPRI event is for monitoring trace event. Like the POLLIN, this will be returned when the histogram is updated, but you don't need to read() the file and use poll() again. Note that this waits for histogram update (not event arrival), thus you must set a histogram on the event at first. Usage ----- Here is an example usage: ---- TRACEFS=/sys/kernel/tracing EVENT=$TRACEFS/events/sched/sched_process_free # setup histogram trigger and enable event echo "hist:key=comm" >> $EVENT/trigger echo 1 > $EVENT/enable # Wait for update poll pri $EVENT/hist # Event arrived. echo "process free event is comming" tail $TRACEFS/trace ---- The 'poll' command is in the selftest patch. You can take this series also from here; https://git.kernel.org/pub/scm/linux/kernel/git/mhiramat/linux.git/log/?h=topic/event-hist-poll Thank you, --- Masami Hiramatsu (Google) (3): tracing/hist: Add poll(POLLIN) support on hist file tracing/hist: Support POLLPRI event for poll on histogram selftests/tracing: Add hist poll() support test include/linux/trace_events.h | 5 + kernel/trace/trace_events.c | 18 ++++ kernel/trace/trace_events_hist.c | 101 +++++++++++++++++++- tools/testing/selftests/ftrace/Makefile | 2 tools/testing/selftests/ftrace/poll.c | 74 +++++++++++++++ .../ftrace/test.d/trigger/trigger-hist-poll.tc | 74 +++++++++++++++ 6 files changed, 271 insertions(+), 3 deletions(-) create mode 100644 tools/testing/selftests/ftrace/poll.c create mode 100644 tools/testing/selftests/ftrace/test.d/trigger/trigger-hist-poll.tc -- Masami Hiramatsu (Google)