RE: [PATCH V5 4/8] perf/x86/intel/uncore: add new data structures for free running counters

From: Liang, Kan
Date: Thu Jan 18 2018 - 12:43:20 EST


> On Mon, Jan 15, 2018 at 10:57:05AM -0800, kan.liang@xxxxxxxxx wrote:
> > From: Kan Liang <Kan.liang@xxxxxxxxx>
> >
> > There are a number of free running counters introduced for uncore, which
> > provide highly valuable information to a wide array of customers.
> > For example, Skylake Server has IIO free running counters to collect
> > Input/Output x BW/Utilization.
> > The precious generic counters could be saved to collect other customer
> > interested data.
> >
> > The free running counter is read-only and always active. Current generic
> > uncore code does not support this kind of counters.
> >
> > Introduce a new index to indicate the free running counters. Only one
> > index is enough for all free running counters. Because the free running
> > countes are always active, and the event and free running counter are
> > always 1:1 mapped. It does not need extra index to indicate the assigned
> > counter.
> >
> > Introduce some rules to encode the event for free running counters.
> > - The event for free running counter has the same event code 0xff as the
> > event for fixed counter.
> > - The umask of the event starts from 0x10. The umask which is less than
> > 0x10 is reserved for the event of fixed counter.
> > - The free running counters can be divided into different types
> > according to the MSR location, bit width or definition. The start
> > point of the umask for different type has 0x10 offset.
> > For example, there are three types of IIO free running counters on
> > Skylake server, IO CLOCKS counters, BANDWIDTH counters and
> UTILIZATION
> > counters.
> > The event code for all free running counters is 0xff.
> > 'ioclk' is the first counter of IO CLOCKS. IO CLOCKS is the first type
> > of free running counters, which umask starts from 0x10.
> > So 'ioclk' is encoded as event=0xff,umask=0x10
> > 'bw_in_port2' is the third counter of BANDWIDTH counters. BANDWIDTH is
> > the second type which umask starts from 0x20.
> > So 'bw_in_port2' is encoded as event=0xff,umask=0x22.
> >
> > Introduce a new data structure to store free running counters related
> > information for each type. It includes the number of counters, bit
> > width, base address, offset between counters and offset between boxes.
> >
> > Introduce several inline helpers to check index for fixed counter and
> > free running counter, validate free running counter event, and retrieve
> > the free running counter information according to box and event.
>
> Sorry, none of this makes any sense, what?
>
> WTH would all free running counters, which presumably count different
> things, have the same event code ?
>
> And whats the hackery with the umask do?
>
> Please rewrite this in comprehensible form and also give rationale for
> the various choices.

I rewrote the encoding part as blow. Does it look better?

------

In the uncore document, there is no event-code assigned to free running counters.
Some events need to be defined to indicate the free running counters.
The events are encoded as event-code + umask-code.

The event-code for all free running counters is 0xff, which is the same as
the fixed counters.
- It has not been decided what code will be used for common events on future platforms.
0xff is the only one which will definitely not be used as any common event-code.
- Free running counters and fixed counters are both dedicated counters.
It makes sense to share the event-code between these two types of counters.
- Even in the existing codes, the fixed counters for core, that have the same event-code,
may count different things. Hence, it should not surprise the users if the free running
counters that share the same event-code also count different things.
Umask will be used to distinguish the counters.

The umask-code is used to distinguish a fixed counter and a free running counter,
and different types of free running counters.
For fixed counters, the umask-code is 0x0X.
X indicates the index of the fixed counter, which starts from 0.
- Compatible with the old event encoding.
- Currently, there is only one fixed counter. There are still 15 reserved spaces for
Extension.
For free running counters, the umask-code uses the rest of the space.
It would bare the format of 0xXY.
X stands for the type of free running counters, which starts from 1.
Y stands for the index of free running counters of same type, which starts from 0.
- The free-running counters do different thing. It can be categorized to several
types, according to the MSR location, bit width and definition.
E.g. there are three types of IIO free running counters on Skylake server to
monitor IO CLOCKS, BANDWIDTH and UTILIZATION on different ports.
It makes it easy to locate the free-running counter of a specific type.
- So far, there are at most 8 counters of each type. There are still 8
reserved spaces for extension.

------

Thanks,
Kan