All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexander Monakov <amonakov@ispras.ru>
To: "Suthikulpanit, Suravee" <suravee.suthikulpanit@amd.com>
Cc: David Coe <david.coe@live.co.uk>,
	linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org,
	joro@8bytes.org, will@kernel.org, jsnitsel@redhat.com,
	pmenzel@molgen.mpg.de, Jon.Grimm@amd.com,
	Tj <ml.linux@elloe.vision>,
	Shuah Khan <skhan@linuxfoundation.org>,
	Alex Hung <1917203@bugs.launchpad.net>
Subject: Re: [PATCH 2/2] iommu/amd: Remove performance counter pre-initialization test
Date: Tue, 20 Apr 2021 13:33:35 +0300 (MSK)	[thread overview]
Message-ID: <alpine.LNX.2.20.13.2104201310520.19608@monopod.intra.ispras.ru> (raw)
In-Reply-To: <9d5fa4ff-9666-6475-7f61-2b45cbd83456@amd.com>

[-- Attachment #1: Type: text/plain, Size: 2742 bytes --]

On Tue, 20 Apr 2021, Suthikulpanit, Suravee wrote:

> David / Joerg,
> 
> On 4/10/2021 5:03 PM, David Coe wrote:
> > 
> > The immediately obvious difference is the with the enormous count seen on
> > mem_dte_mis on the older Ryzen 2400G. Will do some RTFM but anyone
> > with comments and insight?
> > 
> > 841,689,151,202,939       amd_iommu_0/mem_dte_mis/              (33.44%)
> > 
> > Otherwise, all seems to running smoothly (especially for a distribution
> > still in β). Bravo and many thanks all!
> 
> The initial hypothesis is that the issue happens only when users specify more
> number of events than
> the available counters, which Perf will time-multiplex the events onto the
> counters.
> 
> Looking at the Perf and AMD IOMMU PMU multiplexing logic, it requires:
>  1. Stop the counter (i.e. set CSOURCE to zero to stop counting)
>  2. Save the counter value of the current event
>  3. Reload the counter value of the new event (previously saved)
>  4. Start the counter (i.e. set CSOURCE to count new events)
> 
> The problem here is that when the driver writes zero to CSOURCE register in
> step 1, this would enable power-gating,
> which prevents access to the counter and result in writing/reading value in
> step 2 and 3.
> 
> I have found a system that reproduced this case (w/ unusually large number of
> count), and debug the issue further.
> As a hack, I have tried skipping step 1, and it seems to eliminate this issue.
> However, this is logically incorrect,
> and might result in inaccurate data depending on the events.
> 
> Here are the options:
> 1. Continue to look for workaround for this issue.
> 2. Find a way to disable event time-multiplexing (e.g. only limit the number
> of counters to 8)
>    if power gating is enabled on the platform.
> 3. Back to the original logic where we had the pre-init check of the counter
> vlues, which is still the safest choice
>    at the moment unless

If the "power-gated" counter only ignores writes, but yields correct values on
reads, you don't need to change its value.

0. When initializing the counter, save its value as 'raw_counter_value'.

When switching:

1. Set CSOURCE to zero (pauses the counter).
2. Read current counter value ('new_value').
3. Add '(new_value - raw_counter_value) & mask' to the current event count;
   where 'mask' is '(1ULL << 48) - 1' to account for overflow correctly.
4. Assign 'raw_counter_value = new_value'.
5. Set CSOURCE to new configuration value.

Modifying the hardware counter value is only needed to get overflow interrupts,
but there's no code to handle them on Linux (since the interrupts are
asynchronous, and given the nature of the events, I don't see how it would be
useful).

Alexander

WARNING: multiple messages have this Message-ID (diff)
From: Alexander Monakov <amonakov@ispras.ru>
To: "Suthikulpanit, Suravee" <suravee.suthikulpanit@amd.com>
Cc: David Coe <david.coe@live.co.uk>,
	pmenzel@molgen.mpg.de, Jon.Grimm@amd.com,
	linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org,
	Shuah Khan <skhan@linuxfoundation.org>,
	Tj <ml.linux@elloe.vision>,
	Alex Hung <1917203@bugs.launchpad.net>,
	will@kernel.org
Subject: Re: [PATCH 2/2] iommu/amd: Remove performance counter pre-initialization test
Date: Tue, 20 Apr 2021 13:33:35 +0300 (MSK)	[thread overview]
Message-ID: <alpine.LNX.2.20.13.2104201310520.19608@monopod.intra.ispras.ru> (raw)
In-Reply-To: <9d5fa4ff-9666-6475-7f61-2b45cbd83456@amd.com>

[-- Attachment #1: Type: text/plain, Size: 2742 bytes --]

On Tue, 20 Apr 2021, Suthikulpanit, Suravee wrote:

> David / Joerg,
> 
> On 4/10/2021 5:03 PM, David Coe wrote:
> > 
> > The immediately obvious difference is the with the enormous count seen on
> > mem_dte_mis on the older Ryzen 2400G. Will do some RTFM but anyone
> > with comments and insight?
> > 
> > 841,689,151,202,939       amd_iommu_0/mem_dte_mis/              (33.44%)
> > 
> > Otherwise, all seems to running smoothly (especially for a distribution
> > still in β). Bravo and many thanks all!
> 
> The initial hypothesis is that the issue happens only when users specify more
> number of events than
> the available counters, which Perf will time-multiplex the events onto the
> counters.
> 
> Looking at the Perf and AMD IOMMU PMU multiplexing logic, it requires:
>  1. Stop the counter (i.e. set CSOURCE to zero to stop counting)
>  2. Save the counter value of the current event
>  3. Reload the counter value of the new event (previously saved)
>  4. Start the counter (i.e. set CSOURCE to count new events)
> 
> The problem here is that when the driver writes zero to CSOURCE register in
> step 1, this would enable power-gating,
> which prevents access to the counter and result in writing/reading value in
> step 2 and 3.
> 
> I have found a system that reproduced this case (w/ unusually large number of
> count), and debug the issue further.
> As a hack, I have tried skipping step 1, and it seems to eliminate this issue.
> However, this is logically incorrect,
> and might result in inaccurate data depending on the events.
> 
> Here are the options:
> 1. Continue to look for workaround for this issue.
> 2. Find a way to disable event time-multiplexing (e.g. only limit the number
> of counters to 8)
>    if power gating is enabled on the platform.
> 3. Back to the original logic where we had the pre-init check of the counter
> vlues, which is still the safest choice
>    at the moment unless

If the "power-gated" counter only ignores writes, but yields correct values on
reads, you don't need to change its value.

0. When initializing the counter, save its value as 'raw_counter_value'.

When switching:

1. Set CSOURCE to zero (pauses the counter).
2. Read current counter value ('new_value').
3. Add '(new_value - raw_counter_value) & mask' to the current event count;
   where 'mask' is '(1ULL << 48) - 1' to account for overflow correctly.
4. Assign 'raw_counter_value = new_value'.
5. Set CSOURCE to new configuration value.

Modifying the hardware counter value is only needed to get overflow interrupts,
but there's no code to handle them on Linux (since the interrupts are
asynchronous, and given the nature of the events, I don't see how it would be
useful).

Alexander

[-- Attachment #2: Type: text/plain, Size: 156 bytes --]

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

  reply	other threads:[~2021-04-20 10:33 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-09  8:58 [PATCH 0/2] iommu/amd: Revert and remove failing PMC test Suravee Suthikulpanit
2021-04-09  8:58 ` Suravee Suthikulpanit
2021-04-09  8:58 ` [PATCH 1/2] Revert "iommu/amd: Fix performance counter initialization" Suravee Suthikulpanit
2021-04-09  8:58   ` Suravee Suthikulpanit
2021-04-09 17:06   ` Shuah Khan
2021-04-09 17:06     ` Shuah Khan
2021-04-13 13:36     ` Suthikulpanit, Suravee
2021-04-13 13:36       ` Suthikulpanit, Suravee
2021-04-09  8:58 ` [PATCH 2/2] iommu/amd: Remove performance counter pre-initialization test Suravee Suthikulpanit
2021-04-09  8:58   ` Suravee Suthikulpanit
2021-04-09 16:37   ` Shuah Khan
2021-04-09 16:37     ` Shuah Khan
2021-04-09 17:10     ` Shuah Khan
2021-04-09 17:10       ` Shuah Khan
2021-04-09 20:00   ` Shuah Khan
2021-04-09 20:00     ` Shuah Khan
2021-04-09 20:19     ` Shuah Khan
2021-04-09 20:19       ` Shuah Khan
2021-04-09 20:11   ` David Coe
2021-04-09 20:11     ` David Coe
2021-04-10  8:17   ` David Coe
2021-04-10  8:17     ` David Coe
2021-04-10 10:03   ` David Coe
2021-04-10 10:03     ` David Coe
2021-04-13 13:51     ` Suthikulpanit, Suravee
2021-04-13 13:51       ` Suthikulpanit, Suravee
2021-04-14 15:33       ` David Coe
2021-04-14 15:33         ` David Coe
2021-04-15  9:28         ` Suthikulpanit, Suravee
2021-04-15  9:28           ` Suthikulpanit, Suravee
2021-04-15 14:39           ` David Coe
2021-04-15 14:39             ` David Coe
2021-04-15 16:20           ` David Coe
2021-04-15 16:20             ` David Coe
2021-04-18 19:16           ` David Coe
2021-04-18 19:16             ` David Coe
2021-04-14 22:18       ` David Coe
2021-04-14 22:18         ` David Coe
2021-04-20  8:38     ` Suthikulpanit, Suravee
2021-04-20  8:38       ` Suthikulpanit, Suravee
2021-04-20 10:33       ` Alexander Monakov [this message]
2021-04-20 10:33         ` Alexander Monakov
2021-04-13  9:38   ` David Coe
2021-04-13  9:38     ` David Coe
2021-04-15 13:41 ` [PATCH 0/2] iommu/amd: Revert and remove failing PMC test Joerg Roedel
2021-04-15 13:41   ` Joerg Roedel

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=alpine.LNX.2.20.13.2104201310520.19608@monopod.intra.ispras.ru \
    --to=amonakov@ispras.ru \
    --cc=1917203@bugs.launchpad.net \
    --cc=Jon.Grimm@amd.com \
    --cc=david.coe@live.co.uk \
    --cc=iommu@lists.linux-foundation.org \
    --cc=joro@8bytes.org \
    --cc=jsnitsel@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ml.linux@elloe.vision \
    --cc=pmenzel@molgen.mpg.de \
    --cc=skhan@linuxfoundation.org \
    --cc=suravee.suthikulpanit@amd.com \
    --cc=will@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.