linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Song Liu <songliubraving@fb.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Namhyung Kim <namhyung@kernel.org>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Jiri Olsa <jolsa@redhat.com>, Ingo Molnar <mingo@kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Andi Kleen <ak@linux.intel.com>, Ian Rogers <irogers@google.com>,
	Stephane Eranian <eranian@google.com>
Subject: Re: [PATCHSET v2 0/3] perf stat: Enable BPF counters with --for-each-cgroup
Date: Thu, 17 Jun 2021 06:33:28 +0000	[thread overview]
Message-ID: <55A8ECB0-0299-4A07-B285-E9F0D611E822@fb.com> (raw)
In-Reply-To: <20210616223212.GE4272@worktop.programming.kicks-ass.net>



> On Jun 16, 2021, at 3:32 PM, Peter Zijlstra <peterz@infradead.org> wrote:
> 
> On Wed, Jun 16, 2021 at 09:33:42AM -0700, Namhyung Kim wrote:
> 
>>> That seems unfortunate; there's no bpf helper to iterate cgroup
>>> hierarchy?
>> 
>> I couldn't find one..
> 
> Song, is that something that would make sense to have?

I think we can solve this with bpf_get_current_ancestor_cgroup_id and 
a bounded loop. Like:

	/* get diff_reading, which is reading - prev_reading */

	for (i = 0; i < 10 /* at most 10 levels */; i++) {
		__u64 cgroup_id = bpf_get_current_ancestor_cgroup_id(i);
		if (!cgroup_id)
			break;
		/* add diff_reading to cgroup_id */
	}

> 
>>>> * there's no reliable way to trigger running the BPF program
>>> 
>>> You can't attach to the PERF_COUNT_SW_CGROUP_SWITCHES event?
>> 
>> I did it.  But the BPF test run seems not to work with perf_event.
>> So it needs to trigger a cgroup switch manually..
> 
> AFAICT it should be possible to set a bpf prog on a software event.
> perf_event_set_bpf_prog() will take the first branch
> (!perf_event_is_tracing()) and call perf_event_set_bpf_handler().
> 
> That should then result in running the bpf program every time the event
> would generate a sample.
> 
> So if you configure the event to sample on every single event, it should
> then run your program every time.
> 
> This is all from looking at the code, because I really can't operate any
> of that for real. I suspect Song can help out.
> 
> The alternative is to attach a BPF program to the sched_switch
> tracepoint and do the cgroup filter in BPF.

We can create a raw_tp BPF program just for BPF_PROG_TEST_RUN (now also called
BPF_PROG_RUN). The program should be the same as current on_switch program. 
We don't have to attach the program, just use BPF_PROG_RUN to trigger it. 

Would something like this work?

Thanks,
Song 





  reply	other threads:[~2021-06-17  6:33 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-15  1:17 [PATCHSET v2 0/3] perf stat: Enable BPF counters with --for-each-cgroup Namhyung Kim
2021-06-15  1:17 ` [PATCH 1/3] perf tools: Add read_cgroup_id() function Namhyung Kim
2021-06-15  1:17 ` [PATCH 2/3] perf tools: Add cgroup_is_v2() helper Namhyung Kim
2021-06-15  1:17 ` [PATCH 3/3] perf stat: Enable BPF counter with --for-each-cgroup Namhyung Kim
2021-06-16 15:14 ` [PATCHSET v2 0/3] perf stat: Enable BPF counters " Peter Zijlstra
2021-06-16 16:33   ` Namhyung Kim
2021-06-16 22:32     ` Peter Zijlstra
2021-06-17  6:33       ` Song Liu [this message]
2021-06-22  1:43         ` Namhyung Kim

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=55A8ECB0-0299-4A07-B285-E9F0D611E822@fb.com \
    --to=songliubraving@fb.com \
    --cc=acme@kernel.org \
    --cc=ak@linux.intel.com \
    --cc=eranian@google.com \
    --cc=irogers@google.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).