From: Namhyung Kim <namhyung@kernel.org>
To: Ian Rogers <irogers@google.com>, Mingwei Zhang <mizhang@google.com>
Cc: Jim Mattson <jmattson@google.com>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@kernel.org>,
Adrian Hunter <adrian.hunter@intel.com>,
Kan Liang <kan.liang@linux.intel.com>,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
Yang Jihong <yangjihong1@huawei.com>,
Stephane Eranian <eranian@google.com>
Subject: Re: [PATCH v1] perf evlist: Avoid frequency mode for the dummy event
Date: Wed, 11 Oct 2023 09:09:51 -0700 [thread overview]
Message-ID: <CAM9d7ci-G-+FFPsKbMzzSzCr2kS75axYHFDm2=f6TxUk=dM_CA@mail.gmail.com> (raw)
In-Reply-To: <CAL715WJ8w+q_=0_NVZJ=rs0GLs=pYqDiRLcCxxO0gDcGdcvZnw@mail.gmail.com>
Hi Ian,
On Tue, Oct 3, 2023 at 4:20 PM Mingwei Zhang <mizhang@google.com> wrote:
>
> On Tue, Oct 3, 2023 at 3:36 PM Ian Rogers <irogers@google.com> wrote:
> >
> > On Tue, Oct 3, 2023 at 1:08 PM Namhyung Kim <namhyung@kernel.org> wrote:
> > >
> > > Hello,
> > >
> > > On Wed, Sep 20, 2023 at 10:05 PM Mingwei Zhang <mizhang@google.com> wrote:
> > > >
> > > > On Mon, Sep 18, 2023 at 3:43 PM Ian Rogers <irogers@google.com> wrote:
> > > > >
> > > > > On Sat, Sep 16, 2023 at 5:46 PM Mingwei Zhang <mizhang@google.com> wrote:
> > > > > > Thank you very much for the change. I have one quick question about
> > > > > > the PMU unthrottling logic. When I am looking into the function
> > > > > > perf_adjust_freq_unthr_context(), I see the loop with PMU stop and
> > > > > > start in each iteration. Is there a good way to avoid this PMU reset
> > > > > > operation while quickly figuring out the event in frequency mode?
> > > > >
> > > > > Agreed. I think before the pmu_disable could be avoided for this condition:
> > > > > ```
> > > > > if (event->hw.interrupts != MAX_INTERRUPTS &&
> > > > > (!event->attr.freq || !event->attr.sample_freq))
> > > > > continue;
> > > > > ```
> > > > > Fixing up the event stop/start looks harder.
> > > > >
> > > >
> > > > Right, I think putting the check early before pmu_disable() is already
> > > > a great optimization. The only concern I initially had was whether
> > > > event->hw.interrupts can be accessed before we disable the pmu. But
> > > > after checking this field in other locations, I don't see any problem
> > > > at all.
> > >
> > > The event->hw.interrupts would be increased in the NMI handler
> > > so there is a race between the check and the NMI. That's why
> > > I think it checks that after disabling the PMU.
> > >
> > > But I think we can skip non-sampling events for sure. Then it
> > > would be better to set attr.sample_period = 0 rather than attr.freq.
> > >
> > > if (!is_sampling_event(event))
> > > continue;
> > >
> > > perf_pmu_disable(event->pmu);
> > > ...
> > >
> > > Thanks,
> > > Namhyung
> >
> > With the PMU disabled, isn't there still a risk of an interrupt still
> > being in flight? In other words the disable doesn't prevent a race and
> > we'll catch this on the next timer call to
> > perf_adjust_freq_unthr_context. I think we can also improve the code
> > by just disabling a PMU once, we can take advantage of the
> > perf_event_pmu_context and disable that PMU, iterate its events and
> > then re-enable the PMU - i.e. no need for an enable and disable per
> > event. I'll put a patch together.
> >
> > Thanks,
> > Ian
>
> +Jim Mattson
>
> I initially thought this idea was just an alternative, or a more
> professional fix in the perf subsystem. I was wrong...
>
> This would be way better than just skipping frequency events in the
> loop. Since if we just skip by event, we may still suffer from huge
> overhead if the event list contains many sampling events in frequency
> mode. Unfortunately, that is the general case when we do perf record
> -e 'eventlist' (IIUC all events in eventlist are in frequency mode if
> we don't specify period=). So the problem actually remains whenever we
> do perf sampling unless we use something like Intel vtune.
>
> On the other hand, since all of the events are presumably CPU core
> events, with the fix we pay only once for the PMU reset per hrtimer
> regardless of how many events are in frequency mode.
>
> Looking forward to the patch! Please keep us posted if possible.
Any updates?
Thanks,
Namhyung
next prev parent reply other threads:[~2023-10-11 16:10 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-16 4:09 [PATCH v1] perf evlist: Avoid frequency mode for the dummy event Ian Rogers
2023-09-17 0:45 ` Mingwei Zhang
2023-09-18 22:42 ` Ian Rogers
2023-09-21 5:04 ` Mingwei Zhang
2023-10-03 20:07 ` Namhyung Kim
2023-10-03 22:36 ` Ian Rogers
2023-10-03 23:02 ` Namhyung Kim
2023-10-11 16:14 ` Namhyung Kim
2023-10-03 23:19 ` Mingwei Zhang
2023-10-11 16:09 ` Namhyung Kim [this message]
2023-09-18 8:14 ` Adrian Hunter
2023-09-18 21:48 ` Ian Rogers
2023-09-19 5:59 ` Adrian Hunter
2023-09-21 19:26 ` Namhyung Kim
2023-09-22 5:36 ` Adrian Hunter
2023-09-22 15:05 ` Ian Rogers
2023-09-25 3:35 ` Yang Jihong
2023-09-25 17:37 ` Stephane Eranian
2023-09-30 6:06 ` Namhyung Kim
2023-10-30 19:04 ` Mingwei Zhang
2023-10-30 20:01 ` Mingwei Zhang
2023-10-31 5:47 ` Greg KH
-- strict thread matches above, loose matches on Subject: below --
2023-09-16 3:56 Ian Rogers
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='CAM9d7ci-G-+FFPsKbMzzSzCr2kS75axYHFDm2=f6TxUk=dM_CA@mail.gmail.com' \
--to=namhyung@kernel.org \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=eranian@google.com \
--cc=irogers@google.com \
--cc=jmattson@google.com \
--cc=jolsa@kernel.org \
--cc=kan.liang@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=mizhang@google.com \
--cc=peterz@infradead.org \
--cc=yangjihong1@huawei.com \
/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).