[PATCH v6 0/5] Hwmon PMUs

Ian Rogers posted 5 patches 1 month ago
There is a newer version of this series
tools/lib/api/io.h                     |   1 +
tools/perf/Documentation/perf-list.txt |  15 +
tools/perf/tests/Build                 |   1 +
tools/perf/tests/builtin-test.c        |   1 +
tools/perf/tests/hwmon_pmu.c           | 243 ++++++++
tools/perf/tests/tests.h               |   1 +
tools/perf/util/Build                  |   1 +
tools/perf/util/evsel.c                |   9 +
tools/perf/util/hwmon_pmu.c            | 821 +++++++++++++++++++++++++
tools/perf/util/hwmon_pmu.h            | 154 +++++
tools/perf/util/pmu.c                  |  20 +
tools/perf/util/pmu.h                  |   2 +
tools/perf/util/pmus.c                 |   9 +
tools/perf/util/pmus.h                 |   3 +
14 files changed, 1281 insertions(+)
create mode 100644 tools/perf/tests/hwmon_pmu.c
create mode 100644 tools/perf/util/hwmon_pmu.c
create mode 100644 tools/perf/util/hwmon_pmu.h
[PATCH v6 0/5] Hwmon PMUs
Posted by Ian Rogers 1 month ago
Following the convention of the tool PMU, create a hwmon PMU that
exposes hwmon data for reading. For example, the following shows
reading the CPU temperature and 2 fan speeds alongside the uncore
frequency:
```
$ perf stat -e temp_cpu,fan1,hwmon_thinkpad/fan2/,tool/num_cpus_online/ -M UNCORE_FREQ -I 1000
     1.001153138              52.00 'C   temp_cpu
     1.001153138              2,588 rpm  fan1
     1.001153138              2,482 rpm  hwmon_thinkpad/fan2/
     1.001153138                  8      tool/num_cpus_online/
     1.001153138      1,077,101,397      UNC_CLOCK.SOCKET                 #     1.08 UNCORE_FREQ
     1.001153138      1,012,773,595      duration_time
...
```

Additional data on the hwmon events is in perf list:
```
$ perf list
...
hwmon:
...
  temp_core_0 OR temp2
       [Temperature in unit coretemp named Core 0. crit=100'C,max=100'C crit_alarm=0'C. Unit:
        hwmon_coretemp]
...
```

v6: Add string.h #include for issue reported by kernel test robot.
v5: Fix asan issue in parse_hwmon_filename caught by a TMA metric.
v4: Drop merged patches 1 to 10. Separate adding the hwmon_pmu from
    the update to perf_pmu to use it. Try to make source of literal
    strings clearer via named #defines. Fix a number of GCC warnings.
v3: Rebase, add Namhyung's acked-by to patches 1 to 10.
v2: Address Namhyung's review feedback. Rebase dropping 4 patches
    applied by Arnaldo, fix build breakage reported by Arnaldo.

Ian Rogers (5):
  tools api io: Ensure line_len_out is always initialized
  perf hwmon_pmu: Add a tool PMU exposing events from hwmon in sysfs
  perf pmu: Add calls enabling the hwmon_pmu
  perf test: Add hwmon "PMU" test
  perf docs: Document tool and hwmon events

 tools/lib/api/io.h                     |   1 +
 tools/perf/Documentation/perf-list.txt |  15 +
 tools/perf/tests/Build                 |   1 +
 tools/perf/tests/builtin-test.c        |   1 +
 tools/perf/tests/hwmon_pmu.c           | 243 ++++++++
 tools/perf/tests/tests.h               |   1 +
 tools/perf/util/Build                  |   1 +
 tools/perf/util/evsel.c                |   9 +
 tools/perf/util/hwmon_pmu.c            | 821 +++++++++++++++++++++++++
 tools/perf/util/hwmon_pmu.h            | 154 +++++
 tools/perf/util/pmu.c                  |  20 +
 tools/perf/util/pmu.h                  |   2 +
 tools/perf/util/pmus.c                 |   9 +
 tools/perf/util/pmus.h                 |   3 +
 14 files changed, 1281 insertions(+)
 create mode 100644 tools/perf/tests/hwmon_pmu.c
 create mode 100644 tools/perf/util/hwmon_pmu.c
 create mode 100644 tools/perf/util/hwmon_pmu.h

-- 
2.47.0.163.g1226f6d8fa-goog
Re: [PATCH v6 0/5] Hwmon PMUs
Posted by Namhyung Kim 1 month ago
Hi Ian,

On Tue, Oct 22, 2024 at 11:06:18AM -0700, Ian Rogers wrote:
> Following the convention of the tool PMU, create a hwmon PMU that
> exposes hwmon data for reading. For example, the following shows
> reading the CPU temperature and 2 fan speeds alongside the uncore
> frequency:
> ```
> $ perf stat -e temp_cpu,fan1,hwmon_thinkpad/fan2/,tool/num_cpus_online/ -M UNCORE_FREQ -I 1000
>      1.001153138              52.00 'C   temp_cpu
>      1.001153138              2,588 rpm  fan1
>      1.001153138              2,482 rpm  hwmon_thinkpad/fan2/
>      1.001153138                  8      tool/num_cpus_online/
>      1.001153138      1,077,101,397      UNC_CLOCK.SOCKET                 #     1.08 UNCORE_FREQ
>      1.001153138      1,012,773,595      duration_time
> ...
> ```
> 
> Additional data on the hwmon events is in perf list:
> ```
> $ perf list
> ...
> hwmon:
> ...
>   temp_core_0 OR temp2
>        [Temperature in unit coretemp named Core 0. crit=100'C,max=100'C crit_alarm=0'C. Unit:
>         hwmon_coretemp]
> ...
> ```
> 
> v6: Add string.h #include for issue reported by kernel test robot.
> v5: Fix asan issue in parse_hwmon_filename caught by a TMA metric.
> v4: Drop merged patches 1 to 10. Separate adding the hwmon_pmu from
>     the update to perf_pmu to use it. Try to make source of literal
>     strings clearer via named #defines. Fix a number of GCC warnings.
> v3: Rebase, add Namhyung's acked-by to patches 1 to 10.
> v2: Address Namhyung's review feedback. Rebase dropping 4 patches
>     applied by Arnaldo, fix build breakage reported by Arnaldo.
> 
> Ian Rogers (5):
>   tools api io: Ensure line_len_out is always initialized
>   perf hwmon_pmu: Add a tool PMU exposing events from hwmon in sysfs
>   perf pmu: Add calls enabling the hwmon_pmu
>   perf test: Add hwmon "PMU" test
>   perf docs: Document tool and hwmon events

I think the patch 2 can be easily splitted into core and other parts
like dealing with aliases and units.  I believe it'd be helpful for
others (like me) to understand how it works.

Please take a look at 'perf/hwmon-pmu' branch in:

  https://git.kernel.org/pub/scm/linux/kernel/git/namhyung/linux-perf.git

Thanks,
Namhyung

> 
>  tools/lib/api/io.h                     |   1 +
>  tools/perf/Documentation/perf-list.txt |  15 +
>  tools/perf/tests/Build                 |   1 +
>  tools/perf/tests/builtin-test.c        |   1 +
>  tools/perf/tests/hwmon_pmu.c           | 243 ++++++++
>  tools/perf/tests/tests.h               |   1 +
>  tools/perf/util/Build                  |   1 +
>  tools/perf/util/evsel.c                |   9 +
>  tools/perf/util/hwmon_pmu.c            | 821 +++++++++++++++++++++++++
>  tools/perf/util/hwmon_pmu.h            | 154 +++++
>  tools/perf/util/pmu.c                  |  20 +
>  tools/perf/util/pmu.h                  |   2 +
>  tools/perf/util/pmus.c                 |   9 +
>  tools/perf/util/pmus.h                 |   3 +
>  14 files changed, 1281 insertions(+)
>  create mode 100644 tools/perf/tests/hwmon_pmu.c
>  create mode 100644 tools/perf/util/hwmon_pmu.c
>  create mode 100644 tools/perf/util/hwmon_pmu.h
> 
> -- 
> 2.47.0.163.g1226f6d8fa-goog
>
Re: [PATCH v6 0/5] Hwmon PMUs
Posted by Ian Rogers 1 month ago
On Wed, Oct 23, 2024 at 8:06 PM Namhyung Kim <namhyung@kernel.org> wrote:
>
> Hi Ian,
>
> On Tue, Oct 22, 2024 at 11:06:18AM -0700, Ian Rogers wrote:
> > Following the convention of the tool PMU, create a hwmon PMU that
> > exposes hwmon data for reading. For example, the following shows
> > reading the CPU temperature and 2 fan speeds alongside the uncore
> > frequency:
> > ```
> > $ perf stat -e temp_cpu,fan1,hwmon_thinkpad/fan2/,tool/num_cpus_online/ -M UNCORE_FREQ -I 1000
> >      1.001153138              52.00 'C   temp_cpu
> >      1.001153138              2,588 rpm  fan1
> >      1.001153138              2,482 rpm  hwmon_thinkpad/fan2/
> >      1.001153138                  8      tool/num_cpus_online/
> >      1.001153138      1,077,101,397      UNC_CLOCK.SOCKET                 #     1.08 UNCORE_FREQ
> >      1.001153138      1,012,773,595      duration_time
> > ...
> > ```
> >
> > Additional data on the hwmon events is in perf list:
> > ```
> > $ perf list
> > ...
> > hwmon:
> > ...
> >   temp_core_0 OR temp2
> >        [Temperature in unit coretemp named Core 0. crit=100'C,max=100'C crit_alarm=0'C. Unit:
> >         hwmon_coretemp]
> > ...
> > ```
> >
> > v6: Add string.h #include for issue reported by kernel test robot.
> > v5: Fix asan issue in parse_hwmon_filename caught by a TMA metric.
> > v4: Drop merged patches 1 to 10. Separate adding the hwmon_pmu from
> >     the update to perf_pmu to use it. Try to make source of literal
> >     strings clearer via named #defines. Fix a number of GCC warnings.
> > v3: Rebase, add Namhyung's acked-by to patches 1 to 10.
> > v2: Address Namhyung's review feedback. Rebase dropping 4 patches
> >     applied by Arnaldo, fix build breakage reported by Arnaldo.
> >
> > Ian Rogers (5):
> >   tools api io: Ensure line_len_out is always initialized
> >   perf hwmon_pmu: Add a tool PMU exposing events from hwmon in sysfs
> >   perf pmu: Add calls enabling the hwmon_pmu
> >   perf test: Add hwmon "PMU" test
> >   perf docs: Document tool and hwmon events
>
> I think the patch 2 can be easily splitted into core and other parts
> like dealing with aliases and units.  I believe it'd be helpful for
> others (like me) to understand how it works.
>
> Please take a look at 'perf/hwmon-pmu' branch in:
>
>   https://git.kernel.org/pub/scm/linux/kernel/git/namhyung/linux-perf.git

Thanks Namhyung but I'm not really seeing this making anything simpler
and I can see significant new bugs. Your new patch:
https://git.kernel.org/pub/scm/linux/kernel/git/namhyung/linux-perf.git/commit/?h=perf/hwmon-pmu&id=85c78b5bf71fb3e67ae815f7b2d044648fa08391
Has taken about 40% out of patch 2, but done so by splitting function
declarations from their definitions, enum declarations from any use,
etc. It also adds in code like:

snprintf(buf, sizeof(buf), "%s_input", evsel->name);

but this would be a strange thing to do. The evsel->name is rewritten
by fallback logic, so cycles may become cycles:u if kernel profiling
is restricted. This is why we have metric-id in the evsel as we cannot
rely on the evsel->name not mutating when looking up events for the
sake of metrics. Using the name as part of a sysfs filename lookup
doesn't make sense to me as now the evsel fallback logic can break a
hwmon event. In the original patch the code was:

snprintf(buf, sizeof(buf), "%s%d_input", hwmon_type_strs[key.type], key.num);

where those two values are constants and key.type and key.num both
values embedded in the config value the evsel fallback logic won't
change. But bringing in the code that does that basically brings in
all of the rest of patch 2.

So the patch is adding a PMU that looks broken, so rather than
simplifying things it just creates a broken intermediate state and
should that be fixed for the benefit of bisects?
It also complicates understanding as the declarations of functions and
enums have kernel-doc, but now the definitions of enums and functions
are split apart. For me, to understand the code I'd want to squash the
patches back together again so I could see a declaration with its
definition.

Thanks,
Ian
Re: [PATCH v6 0/5] Hwmon PMUs
Posted by Namhyung Kim 1 month ago
On Thu, Oct 24, 2024 at 12:07:46AM -0700, Ian Rogers wrote:
> On Wed, Oct 23, 2024 at 8:06 PM Namhyung Kim <namhyung@kernel.org> wrote:
> >
> > Hi Ian,
> >
> > On Tue, Oct 22, 2024 at 11:06:18AM -0700, Ian Rogers wrote:
> > > Following the convention of the tool PMU, create a hwmon PMU that
> > > exposes hwmon data for reading. For example, the following shows
> > > reading the CPU temperature and 2 fan speeds alongside the uncore
> > > frequency:
> > > ```
> > > $ perf stat -e temp_cpu,fan1,hwmon_thinkpad/fan2/,tool/num_cpus_online/ -M UNCORE_FREQ -I 1000
> > >      1.001153138              52.00 'C   temp_cpu
> > >      1.001153138              2,588 rpm  fan1
> > >      1.001153138              2,482 rpm  hwmon_thinkpad/fan2/
> > >      1.001153138                  8      tool/num_cpus_online/
> > >      1.001153138      1,077,101,397      UNC_CLOCK.SOCKET                 #     1.08 UNCORE_FREQ
> > >      1.001153138      1,012,773,595      duration_time
> > > ...
> > > ```
> > >
> > > Additional data on the hwmon events is in perf list:
> > > ```
> > > $ perf list
> > > ...
> > > hwmon:
> > > ...
> > >   temp_core_0 OR temp2
> > >        [Temperature in unit coretemp named Core 0. crit=100'C,max=100'C crit_alarm=0'C. Unit:
> > >         hwmon_coretemp]
> > > ...
> > > ```
> > >
> > > v6: Add string.h #include for issue reported by kernel test robot.
> > > v5: Fix asan issue in parse_hwmon_filename caught by a TMA metric.
> > > v4: Drop merged patches 1 to 10. Separate adding the hwmon_pmu from
> > >     the update to perf_pmu to use it. Try to make source of literal
> > >     strings clearer via named #defines. Fix a number of GCC warnings.
> > > v3: Rebase, add Namhyung's acked-by to patches 1 to 10.
> > > v2: Address Namhyung's review feedback. Rebase dropping 4 patches
> > >     applied by Arnaldo, fix build breakage reported by Arnaldo.
> > >
> > > Ian Rogers (5):
> > >   tools api io: Ensure line_len_out is always initialized
> > >   perf hwmon_pmu: Add a tool PMU exposing events from hwmon in sysfs
> > >   perf pmu: Add calls enabling the hwmon_pmu
> > >   perf test: Add hwmon "PMU" test
> > >   perf docs: Document tool and hwmon events
> >
> > I think the patch 2 can be easily splitted into core and other parts
> > like dealing with aliases and units.  I believe it'd be helpful for
> > others (like me) to understand how it works.
> >
> > Please take a look at 'perf/hwmon-pmu' branch in:
> >
> >   https://git.kernel.org/pub/scm/linux/kernel/git/namhyung/linux-perf.git
> 
> Thanks Namhyung but I'm not really seeing this making anything simpler
> and I can see significant new bugs. Your new patch:
> https://git.kernel.org/pub/scm/linux/kernel/git/namhyung/linux-perf.git/commit/?h=perf/hwmon-pmu&id=85c78b5bf71fb3e67ae815f7b2d044648fa08391
> Has taken about 40% out of patch 2, but done so by splitting function
> declarations from their definitions, enum declarations from any use,

Yeah, it's just because I was lazy and you can split header files too
(and please do so).

> etc. It also adds in code like:
> 
> snprintf(buf, sizeof(buf), "%s_input", evsel->name);
> 
> but this would be a strange thing to do. The evsel->name is rewritten
> by fallback logic, so cycles may become cycles:u if kernel profiling

I know it doesn't work but just want to highlight how it's supposed to
work.  Eventually what we need is a correct file name.  In fact, I think
it'd work if we can pass a correct event name probably like:

  perf stat -e hwmon5/name=fan1/ true

> is restricted. This is why we have metric-id in the evsel as we cannot
> rely on the evsel->name not mutating when looking up events for the
> sake of metrics. Using the name as part of a sysfs filename lookup
> doesn't make sense to me as now the evsel fallback logic can break a
> hwmon event. In the original patch the code was:

The fallback logic is used only if the kernel returns an error.  Thus
it'd be fine as long as it correctly finds the sysfs filename.  But it's
not used in the final code and the change is a simple one-liner.

> 
> snprintf(buf, sizeof(buf), "%s%d_input", hwmon_type_strs[key.type], key.num);
> 
> where those two values are constants and key.type and key.num both
> values embedded in the config value the evsel fallback logic won't
> change. But bringing in the code that does that basically brings in
> all of the rest of patch 2.

Right, that's why I did that way.

> 
> So the patch is adding a PMU that looks broken, so rather than
> simplifying things it just creates a broken intermediate state and
> should that be fixed for the benefit of bisects?

Actually it's not broken since it's not enabled yet. :)


> It also complicates understanding as the declarations of functions and
> enums have kernel-doc, but now the definitions of enums and functions
> are split apart. For me, to understand the code I'd want to squash the
> patches back together again so I could see a declaration with its
> definition.

Yep, please move the declarations to the patch 3.

Thanks,
Namhyung

Re: [PATCH v6 0/5] Hwmon PMUs
Posted by Ian Rogers 1 month ago
On Thu, Oct 24, 2024 at 9:41 AM Namhyung Kim <namhyung@kernel.org> wrote:
>
> On Thu, Oct 24, 2024 at 12:07:46AM -0700, Ian Rogers wrote:
> > On Wed, Oct 23, 2024 at 8:06 PM Namhyung Kim <namhyung@kernel.org> wrote:
> > >
> > > Hi Ian,
> > >
> > > On Tue, Oct 22, 2024 at 11:06:18AM -0700, Ian Rogers wrote:
> > > > Following the convention of the tool PMU, create a hwmon PMU that
> > > > exposes hwmon data for reading. For example, the following shows
> > > > reading the CPU temperature and 2 fan speeds alongside the uncore
> > > > frequency:
> > > > ```
> > > > $ perf stat -e temp_cpu,fan1,hwmon_thinkpad/fan2/,tool/num_cpus_online/ -M UNCORE_FREQ -I 1000
> > > >      1.001153138              52.00 'C   temp_cpu
> > > >      1.001153138              2,588 rpm  fan1
> > > >      1.001153138              2,482 rpm  hwmon_thinkpad/fan2/
> > > >      1.001153138                  8      tool/num_cpus_online/
> > > >      1.001153138      1,077,101,397      UNC_CLOCK.SOCKET                 #     1.08 UNCORE_FREQ
> > > >      1.001153138      1,012,773,595      duration_time
> > > > ...
> > > > ```
> > > >
> > > > Additional data on the hwmon events is in perf list:
> > > > ```
> > > > $ perf list
> > > > ...
> > > > hwmon:
> > > > ...
> > > >   temp_core_0 OR temp2
> > > >        [Temperature in unit coretemp named Core 0. crit=100'C,max=100'C crit_alarm=0'C. Unit:
> > > >         hwmon_coretemp]
> > > > ...
> > > > ```
> > > >
> > > > v6: Add string.h #include for issue reported by kernel test robot.
> > > > v5: Fix asan issue in parse_hwmon_filename caught by a TMA metric.
> > > > v4: Drop merged patches 1 to 10. Separate adding the hwmon_pmu from
> > > >     the update to perf_pmu to use it. Try to make source of literal
> > > >     strings clearer via named #defines. Fix a number of GCC warnings.
> > > > v3: Rebase, add Namhyung's acked-by to patches 1 to 10.
> > > > v2: Address Namhyung's review feedback. Rebase dropping 4 patches
> > > >     applied by Arnaldo, fix build breakage reported by Arnaldo.
> > > >
> > > > Ian Rogers (5):
> > > >   tools api io: Ensure line_len_out is always initialized
> > > >   perf hwmon_pmu: Add a tool PMU exposing events from hwmon in sysfs
> > > >   perf pmu: Add calls enabling the hwmon_pmu
> > > >   perf test: Add hwmon "PMU" test
> > > >   perf docs: Document tool and hwmon events
> > >
> > > I think the patch 2 can be easily splitted into core and other parts
> > > like dealing with aliases and units.  I believe it'd be helpful for
> > > others (like me) to understand how it works.
> > >
> > > Please take a look at 'perf/hwmon-pmu' branch in:
> > >
> > >   https://git.kernel.org/pub/scm/linux/kernel/git/namhyung/linux-perf.git
> >
> > Thanks Namhyung but I'm not really seeing this making anything simpler
> > and I can see significant new bugs. Your new patch:
> > https://git.kernel.org/pub/scm/linux/kernel/git/namhyung/linux-perf.git/commit/?h=perf/hwmon-pmu&id=85c78b5bf71fb3e67ae815f7b2d044648fa08391
> > Has taken about 40% out of patch 2, but done so by splitting function
> > declarations from their definitions, enum declarations from any use,
>
> Yeah, it's just because I was lazy and you can split header files too
> (and please do so).
>
> > etc. It also adds in code like:
> >
> > snprintf(buf, sizeof(buf), "%s_input", evsel->name);
> >
> > but this would be a strange thing to do. The evsel->name is rewritten
> > by fallback logic, so cycles may become cycles:u if kernel profiling
>
> I know it doesn't work but just want to highlight how it's supposed to
> work.  Eventually what we need is a correct file name.  In fact, I think
> it'd work if we can pass a correct event name probably like:
>
>   perf stat -e hwmon5/name=fan1/ true

But this isn't what the term name and evsel's name are for. They are
to allow you to do:
```
$ perf stat -e cycles/name=foobar/ true

Performance counter stats for 'true':

        1,126,942      foobar

      0.001681805 seconds time elapsed

      0.001757000 seconds user
      0.000000000 seconds sys
```
Why would you do this in code, change a fundamental of evsel behavior,
then just to delete it in the next patch?

> > is restricted. This is why we have metric-id in the evsel as we cannot
> > rely on the evsel->name not mutating when looking up events for the
> > sake of metrics. Using the name as part of a sysfs filename lookup
> > doesn't make sense to me as now the evsel fallback logic can break a
> > hwmon event. In the original patch the code was:
>
> The fallback logic is used only if the kernel returns an error.  Thus
> it'd be fine as long as it correctly finds the sysfs filename.  But it's
> not used in the final code and the change is a simple one-liner.

But it's not. It's changing what evsel->name means to be an event
encoding. How does reverse config to name lookup work in this model?
How does the normal use of the name term work?

> >
> > snprintf(buf, sizeof(buf), "%s%d_input", hwmon_type_strs[key.type], key.num);
> >
> > where those two values are constants and key.type and key.num both
> > values embedded in the config value the evsel fallback logic won't
> > change. But bringing in the code that does that basically brings in
> > all of the rest of patch 2.
>
> Right, that's why I did that way.
>
> >
> > So the patch is adding a PMU that looks broken, so rather than
> > simplifying things it just creates a broken intermediate state and
> > should that be fixed for the benefit of bisects?
>
> Actually it's not broken since it's not enabled yet. :)
>
>
> > It also complicates understanding as the declarations of functions and
> > enums have kernel-doc, but now the definitions of enums and functions
> > are split apart. For me, to understand the code I'd want to squash the
> > patches back together again so I could see a declaration with its
> > definition.
>
> Yep, please move the declarations to the patch 3.

So I think moving the enum declarations into one patch is okay. But as
the enum values have no bearing on hardware constants, or something
outside of the code that uses them it smells strange to me. Ultimately
this is going to do little to the lines of code count but damage
readability. I'm not sure why we're doing this given the kernel model
for adding a driver is to add it as a large chunk. For example, here
is adding the intel PT driver:
https://lore.kernel.org/all/1422614392-114498-1-git-send-email-alexander.shishkin@linux.intel.com/T/#u

Thanks,
Ian
Re: [PATCH v6 0/5] Hwmon PMUs
Posted by Namhyung Kim 1 month ago
On Thu, Oct 24, 2024 at 06:33:27PM -0700, Ian Rogers wrote:
> On Thu, Oct 24, 2024 at 9:41 AM Namhyung Kim <namhyung@kernel.org> wrote:
> >
> > On Thu, Oct 24, 2024 at 12:07:46AM -0700, Ian Rogers wrote:
> > > On Wed, Oct 23, 2024 at 8:06 PM Namhyung Kim <namhyung@kernel.org> wrote:
> > > >
> > > > Hi Ian,
> > > >
> > > > On Tue, Oct 22, 2024 at 11:06:18AM -0700, Ian Rogers wrote:
> > > > > Following the convention of the tool PMU, create a hwmon PMU that
> > > > > exposes hwmon data for reading. For example, the following shows
> > > > > reading the CPU temperature and 2 fan speeds alongside the uncore
> > > > > frequency:
> > > > > ```
> > > > > $ perf stat -e temp_cpu,fan1,hwmon_thinkpad/fan2/,tool/num_cpus_online/ -M UNCORE_FREQ -I 1000
> > > > >      1.001153138              52.00 'C   temp_cpu
> > > > >      1.001153138              2,588 rpm  fan1
> > > > >      1.001153138              2,482 rpm  hwmon_thinkpad/fan2/
> > > > >      1.001153138                  8      tool/num_cpus_online/
> > > > >      1.001153138      1,077,101,397      UNC_CLOCK.SOCKET                 #     1.08 UNCORE_FREQ
> > > > >      1.001153138      1,012,773,595      duration_time
> > > > > ...
> > > > > ```
> > > > >
> > > > > Additional data on the hwmon events is in perf list:
> > > > > ```
> > > > > $ perf list
> > > > > ...
> > > > > hwmon:
> > > > > ...
> > > > >   temp_core_0 OR temp2
> > > > >        [Temperature in unit coretemp named Core 0. crit=100'C,max=100'C crit_alarm=0'C. Unit:
> > > > >         hwmon_coretemp]
> > > > > ...
> > > > > ```
> > > > >
> > > > > v6: Add string.h #include for issue reported by kernel test robot.
> > > > > v5: Fix asan issue in parse_hwmon_filename caught by a TMA metric.
> > > > > v4: Drop merged patches 1 to 10. Separate adding the hwmon_pmu from
> > > > >     the update to perf_pmu to use it. Try to make source of literal
> > > > >     strings clearer via named #defines. Fix a number of GCC warnings.
> > > > > v3: Rebase, add Namhyung's acked-by to patches 1 to 10.
> > > > > v2: Address Namhyung's review feedback. Rebase dropping 4 patches
> > > > >     applied by Arnaldo, fix build breakage reported by Arnaldo.
> > > > >
> > > > > Ian Rogers (5):
> > > > >   tools api io: Ensure line_len_out is always initialized
> > > > >   perf hwmon_pmu: Add a tool PMU exposing events from hwmon in sysfs
> > > > >   perf pmu: Add calls enabling the hwmon_pmu
> > > > >   perf test: Add hwmon "PMU" test
> > > > >   perf docs: Document tool and hwmon events
> > > >
> > > > I think the patch 2 can be easily splitted into core and other parts
> > > > like dealing with aliases and units.  I believe it'd be helpful for
> > > > others (like me) to understand how it works.
> > > >
> > > > Please take a look at 'perf/hwmon-pmu' branch in:
> > > >
> > > >   https://git.kernel.org/pub/scm/linux/kernel/git/namhyung/linux-perf.git
> > >
> > > Thanks Namhyung but I'm not really seeing this making anything simpler
> > > and I can see significant new bugs. Your new patch:
> > > https://git.kernel.org/pub/scm/linux/kernel/git/namhyung/linux-perf.git/commit/?h=perf/hwmon-pmu&id=85c78b5bf71fb3e67ae815f7b2d044648fa08391
> > > Has taken about 40% out of patch 2, but done so by splitting function
> > > declarations from their definitions, enum declarations from any use,
> >
> > Yeah, it's just because I was lazy and you can split header files too
> > (and please do so).
> >
> > > etc. It also adds in code like:
> > >
> > > snprintf(buf, sizeof(buf), "%s_input", evsel->name);
> > >
> > > but this would be a strange thing to do. The evsel->name is rewritten
> > > by fallback logic, so cycles may become cycles:u if kernel profiling
> >
> > I know it doesn't work but just want to highlight how it's supposed to
> > work.  Eventually what we need is a correct file name.  In fact, I think
> > it'd work if we can pass a correct event name probably like:
> >
> >   perf stat -e hwmon5/name=fan1/ true
> 
> But this isn't what the term name and evsel's name are for. They are
> to allow you to do:
> ```
> $ perf stat -e cycles/name=foobar/ true
> 
> Performance counter stats for 'true':
> 
>         1,126,942      foobar
> 
>       0.001681805 seconds time elapsed
> 
>       0.001757000 seconds user
>       0.000000000 seconds sys
> ```
> Why would you do this in code, change a fundamental of evsel behavior,
> then just to delete it in the next patch?

Well, I didn't change the actual behavior and it doesn't work yet.
The deletion is just one line, and I think it reveals the intention of
the next patch very well.

> 
> > > is restricted. This is why we have metric-id in the evsel as we cannot
> > > rely on the evsel->name not mutating when looking up events for the
> > > sake of metrics. Using the name as part of a sysfs filename lookup
> > > doesn't make sense to me as now the evsel fallback logic can break a
> > > hwmon event. In the original patch the code was:
> >
> > The fallback logic is used only if the kernel returns an error.  Thus
> > it'd be fine as long as it correctly finds the sysfs filename.  But it's
> > not used in the final code and the change is a simple one-liner.
> 
> But it's not. It's changing what evsel->name means to be an event
> encoding. How does reverse config to name lookup work in this model?
> How does the normal use of the name term work?

It's intermediate code that is not activated yet.  So I think it's about
to say how the code works.  If you really don't like to use evsel->name,
maybe you can put a dummy name with a comment saying it'll be updated in
next patch.

> 
> > >
> > > snprintf(buf, sizeof(buf), "%s%d_input", hwmon_type_strs[key.type], key.num);
> > >
> > > where those two values are constants and key.type and key.num both
> > > values embedded in the config value the evsel fallback logic won't
> > > change. But bringing in the code that does that basically brings in
> > > all of the rest of patch 2.
> >
> > Right, that's why I did that way.
> >
> > >
> > > So the patch is adding a PMU that looks broken, so rather than
> > > simplifying things it just creates a broken intermediate state and
> > > should that be fixed for the benefit of bisects?
> >
> > Actually it's not broken since it's not enabled yet. :)
> >
> >
> > > It also complicates understanding as the declarations of functions and
> > > enums have kernel-doc, but now the definitions of enums and functions
> > > are split apart. For me, to understand the code I'd want to squash the
> > > patches back together again so I could see a declaration with its
> > > definition.
> >
> > Yep, please move the declarations to the patch 3.
> 
> So I think moving the enum declarations into one patch is okay. But as
> the enum values have no bearing on hardware constants, or something
> outside of the code that uses them it smells strange to me. Ultimately
> this is going to do little to the lines of code count but damage
> readability. I'm not sure why we're doing this given the kernel model
> for adding a driver is to add it as a large chunk. For example, here
> is adding the intel PT driver:
> https://lore.kernel.org/all/1422614392-114498-1-git-send-email-alexander.shishkin@linux.intel.com/T/#u

Maybe others can understand a big patch easily, but I'm not.

Thanks,
Namhyung

Re: [PATCH v6 0/5] Hwmon PMUs
Posted by Ian Rogers 1 month ago
On Fri, Oct 25, 2024 at 10:30 AM Namhyung Kim <namhyung@kernel.org> wrote:
>
> On Thu, Oct 24, 2024 at 06:33:27PM -0700, Ian Rogers wrote:
> > On Thu, Oct 24, 2024 at 9:41 AM Namhyung Kim <namhyung@kernel.org> wrote:
> > >
> > > On Thu, Oct 24, 2024 at 12:07:46AM -0700, Ian Rogers wrote:
> > > > On Wed, Oct 23, 2024 at 8:06 PM Namhyung Kim <namhyung@kernel.org> wrote:
> > > > >
> > > > > Hi Ian,
> > > > >
> > > > > On Tue, Oct 22, 2024 at 11:06:18AM -0700, Ian Rogers wrote:
> > > > > > Following the convention of the tool PMU, create a hwmon PMU that
> > > > > > exposes hwmon data for reading. For example, the following shows
> > > > > > reading the CPU temperature and 2 fan speeds alongside the uncore
> > > > > > frequency:
> > > > > > ```
> > > > > > $ perf stat -e temp_cpu,fan1,hwmon_thinkpad/fan2/,tool/num_cpus_online/ -M UNCORE_FREQ -I 1000
> > > > > >      1.001153138              52.00 'C   temp_cpu
> > > > > >      1.001153138              2,588 rpm  fan1
> > > > > >      1.001153138              2,482 rpm  hwmon_thinkpad/fan2/
> > > > > >      1.001153138                  8      tool/num_cpus_online/
> > > > > >      1.001153138      1,077,101,397      UNC_CLOCK.SOCKET                 #     1.08 UNCORE_FREQ
> > > > > >      1.001153138      1,012,773,595      duration_time
> > > > > > ...
> > > > > > ```
> > > > > >
> > > > > > Additional data on the hwmon events is in perf list:
> > > > > > ```
> > > > > > $ perf list
> > > > > > ...
> > > > > > hwmon:
> > > > > > ...
> > > > > >   temp_core_0 OR temp2
> > > > > >        [Temperature in unit coretemp named Core 0. crit=100'C,max=100'C crit_alarm=0'C. Unit:
> > > > > >         hwmon_coretemp]
> > > > > > ...
> > > > > > ```
> > > > > >
> > > > > > v6: Add string.h #include for issue reported by kernel test robot.
> > > > > > v5: Fix asan issue in parse_hwmon_filename caught by a TMA metric.
> > > > > > v4: Drop merged patches 1 to 10. Separate adding the hwmon_pmu from
> > > > > >     the update to perf_pmu to use it. Try to make source of literal
> > > > > >     strings clearer via named #defines. Fix a number of GCC warnings.
> > > > > > v3: Rebase, add Namhyung's acked-by to patches 1 to 10.
> > > > > > v2: Address Namhyung's review feedback. Rebase dropping 4 patches
> > > > > >     applied by Arnaldo, fix build breakage reported by Arnaldo.
> > > > > >
> > > > > > Ian Rogers (5):
> > > > > >   tools api io: Ensure line_len_out is always initialized
> > > > > >   perf hwmon_pmu: Add a tool PMU exposing events from hwmon in sysfs
> > > > > >   perf pmu: Add calls enabling the hwmon_pmu
> > > > > >   perf test: Add hwmon "PMU" test
> > > > > >   perf docs: Document tool and hwmon events
> > > > >
> > > > > I think the patch 2 can be easily splitted into core and other parts
> > > > > like dealing with aliases and units.  I believe it'd be helpful for
> > > > > others (like me) to understand how it works.
> > > > >
> > > > > Please take a look at 'perf/hwmon-pmu' branch in:
> > > > >
> > > > >   https://git.kernel.org/pub/scm/linux/kernel/git/namhyung/linux-perf.git
> > > >
> > > > Thanks Namhyung but I'm not really seeing this making anything simpler
> > > > and I can see significant new bugs. Your new patch:
> > > > https://git.kernel.org/pub/scm/linux/kernel/git/namhyung/linux-perf.git/commit/?h=perf/hwmon-pmu&id=85c78b5bf71fb3e67ae815f7b2d044648fa08391
> > > > Has taken about 40% out of patch 2, but done so by splitting function
> > > > declarations from their definitions, enum declarations from any use,
> > >
> > > Yeah, it's just because I was lazy and you can split header files too
> > > (and please do so).
> > >
> > > > etc. It also adds in code like:
> > > >
> > > > snprintf(buf, sizeof(buf), "%s_input", evsel->name);
> > > >
> > > > but this would be a strange thing to do. The evsel->name is rewritten
> > > > by fallback logic, so cycles may become cycles:u if kernel profiling
> > >
> > > I know it doesn't work but just want to highlight how it's supposed to
> > > work.  Eventually what we need is a correct file name.  In fact, I think
> > > it'd work if we can pass a correct event name probably like:
> > >
> > >   perf stat -e hwmon5/name=fan1/ true
> >
> > But this isn't what the term name and evsel's name are for. They are
> > to allow you to do:
> > ```
> > $ perf stat -e cycles/name=foobar/ true
> >
> > Performance counter stats for 'true':
> >
> >         1,126,942      foobar
> >
> >       0.001681805 seconds time elapsed
> >
> >       0.001757000 seconds user
> >       0.000000000 seconds sys
> > ```
> > Why would you do this in code, change a fundamental of evsel behavior,
> > then just to delete it in the next patch?
>
> Well, I didn't change the actual behavior and it doesn't work yet.
> The deletion is just one line, and I think it reveals the intention of
> the next patch very well.
>
> >
> > > > is restricted. This is why we have metric-id in the evsel as we cannot
> > > > rely on the evsel->name not mutating when looking up events for the
> > > > sake of metrics. Using the name as part of a sysfs filename lookup
> > > > doesn't make sense to me as now the evsel fallback logic can break a
> > > > hwmon event. In the original patch the code was:
> > >
> > > The fallback logic is used only if the kernel returns an error.  Thus
> > > it'd be fine as long as it correctly finds the sysfs filename.  But it's
> > > not used in the final code and the change is a simple one-liner.
> >
> > But it's not. It's changing what evsel->name means to be an event
> > encoding. How does reverse config to name lookup work in this model?
> > How does the normal use of the name term work?
>
> It's intermediate code that is not activated yet.  So I think it's about
> to say how the code works.  If you really don't like to use evsel->name,
> maybe you can put a dummy name with a comment saying it'll be updated in
> next patch.
>
> >
> > > >
> > > > snprintf(buf, sizeof(buf), "%s%d_input", hwmon_type_strs[key.type], key.num);
> > > >
> > > > where those two values are constants and key.type and key.num both
> > > > values embedded in the config value the evsel fallback logic won't
> > > > change. But bringing in the code that does that basically brings in
> > > > all of the rest of patch 2.
> > >
> > > Right, that's why I did that way.
> > >
> > > >
> > > > So the patch is adding a PMU that looks broken, so rather than
> > > > simplifying things it just creates a broken intermediate state and
> > > > should that be fixed for the benefit of bisects?
> > >
> > > Actually it's not broken since it's not enabled yet. :)
> > >
> > >
> > > > It also complicates understanding as the declarations of functions and
> > > > enums have kernel-doc, but now the definitions of enums and functions
> > > > are split apart. For me, to understand the code I'd want to squash the
> > > > patches back together again so I could see a declaration with its
> > > > definition.
> > >
> > > Yep, please move the declarations to the patch 3.
> >
> > So I think moving the enum declarations into one patch is okay. But as
> > the enum values have no bearing on hardware constants, or something
> > outside of the code that uses them it smells strange to me. Ultimately
> > this is going to do little to the lines of code count but damage
> > readability. I'm not sure why we're doing this given the kernel model
> > for adding a driver is to add it as a large chunk. For example, here
> > is adding the intel PT driver:
> > https://lore.kernel.org/all/1422614392-114498-1-git-send-email-alexander.shishkin@linux.intel.com/T/#u
>
> Maybe others can understand a big patch easily, but I'm not.

My understanding is that we make small patches so that the codebase is
more bisectable. When there is something new, like a driver or here a
hwmon PMU, the first patch is large and then we switch to the small
patch model. I have seen patches adding constants ahead of them being
used, but not normally as enums. I've already reduced the size of the
patch by moving everything that isn't hwmon PMU out of the patch and
most of that has already landed. Moving enums out of a header file
okay, shouldn't break the build (a compiler may complain about unused
enums) but then I end up copying comments into commit messages and
doing something alien to what is done in the rest of the kernel. Not
defining a function when you declare it, that is in many cases a
compiler error and for good reason. Adding in changes that are what
are or could be compiler errors goes against making things bisectable.

So breaking up this patch is bad as:
1) it doesn't match existing kernel style,
2) it makes the patch harder to understand (declarations split from
definitions, etc.),
3) with new compiler errors/warnings the code will be less bisectable
as we're deliberately doing things we think wrong for the sake of a
lines-of-code size,
4) we increase the number of patches and commit messages, with commit
messages duplicating comments for things like functions or enums being
added,
5) with your patches we create an intermediate PMU with different
conventions than the rest of the code base and with bugs, impacting
bisectability and the ability to understand the code base.

So I'm arguing against doing this as it is contrary to both our normal
objectives and existing style. I have no real way of knowing when I've
cut something up small enough and if we're not building the code then
how do I build/test the intermediate states, I'm just out on a wild
goose chase.

Thanks,
Ian
Re: [PATCH v6 0/5] Hwmon PMUs
Posted by Arnaldo Carvalho de Melo 1 month ago
On Fri, Oct 25, 2024 at 11:26:26AM -0700, Ian Rogers wrote:
> On Fri, Oct 25, 2024 at 10:30 AM Namhyung Kim <namhyung@kernel.org> wrote:
> > On Thu, Oct 24, 2024 at 06:33:27PM -0700, Ian Rogers wrote:
> > > So I think moving the enum declarations into one patch is okay. But as
> > > the enum values have no bearing on hardware constants, or something
> > > outside of the code that uses them it smells strange to me. Ultimately
> > > this is going to do little to the lines of code count but damage
> > > readability. I'm not sure why we're doing this given the kernel model
> > > for adding a driver is to add it as a large chunk. For example, here
> > > is adding the intel PT driver:
> > > https://lore.kernel.org/all/1422614392-114498-1-git-send-email-alexander.shishkin@linux.intel.com/T/#u

> > Maybe others can understand a big patch easily, but I'm not.
 
> My understanding is that we make small patches so that the codebase is
> more bisectable. When there is something new, like a driver or here a

That is super important, having patches being super small and doing just
one thing helps in bisecting problems.

If two things are done in one patch, and one of them causes a problem,
then bisection is a very effective way of finding out what exactly
caused a problem.

But bisection is not the only benefit from breaking down larger patches
into smaller ones.

We want to have more people joining our ranks, doing low level tooling
and kernel work.

Writing new functionality in a series of patches, growing in complexity
is a way to reduce the cognitive load on understantind how something
works.

As much as trying to emulate how the kernel community works is a good
model as that community has been producing a lot of good code in a
frantic, athletic pace, and as much as I can agree with you that adding
a new piece of code will not affect bisectability as its new code, I
think having it broken down in multiple patches benefits revieweing.

Reviewing is something we should do more, but its very taxing.

One would rather try to write as much code as possible, leaving to
others the reviewing part.

But its a balancing act.

Whatever we can do to help reviewers, like taking into account what they
say they would prefer as a way to submit our work, even if it isn't
exactly of our liking, is one such thing.

So if Namhyung says that it would be best for you to try to break down
your patches into smaller ones, like I did say to you in the past, even
taking the trouble to do it myself, in the process introducing problems,
later fixed, I think you should try to do what he says.

He is the maintainer, try to address his comments.

- Arnaldo
Re: [PATCH v6 0/5] Hwmon PMUs
Posted by Ian Rogers 1 month ago
On Fri, Oct 25, 2024 at 2:01 PM Arnaldo Carvalho de Melo
<acme@kernel.org> wrote:
>
> On Fri, Oct 25, 2024 at 11:26:26AM -0700, Ian Rogers wrote:
> > On Fri, Oct 25, 2024 at 10:30 AM Namhyung Kim <namhyung@kernel.org> wrote:
> > > On Thu, Oct 24, 2024 at 06:33:27PM -0700, Ian Rogers wrote:
> > > > So I think moving the enum declarations into one patch is okay. But as
> > > > the enum values have no bearing on hardware constants, or something
> > > > outside of the code that uses them it smells strange to me. Ultimately
> > > > this is going to do little to the lines of code count but damage
> > > > readability. I'm not sure why we're doing this given the kernel model
> > > > for adding a driver is to add it as a large chunk. For example, here
> > > > is adding the intel PT driver:
> > > > https://lore.kernel.org/all/1422614392-114498-1-git-send-email-alexander.shishkin@linux.intel.com/T/#u
>
> > > Maybe others can understand a big patch easily, but I'm not.
>
> > My understanding is that we make small patches so that the codebase is
> > more bisectable. When there is something new, like a driver or here a
>
> That is super important, having patches being super small and doing just
> one thing helps in bisecting problems.
>
> If two things are done in one patch, and one of them causes a problem,
> then bisection is a very effective way of finding out what exactly
> caused a problem.
>
> But bisection is not the only benefit from breaking down larger patches
> into smaller ones.
>
> We want to have more people joining our ranks, doing low level tooling
> and kernel work.
>
> Writing new functionality in a series of patches, growing in complexity
> is a way to reduce the cognitive load on understantind how something
> works.
>
> As much as trying to emulate how the kernel community works is a good
> model as that community has been producing a lot of good code in a
> frantic, athletic pace, and as much as I can agree with you that adding
> a new piece of code will not affect bisectability as its new code, I
> think having it broken down in multiple patches benefits revieweing.

Can you explain how, as asked, can separating the declaration of a
function from its definition aid in reviewing? As a reviewer, I want
to know the scope of a function and its documentation. Placing them in
2 separate patches doesn't benefit my reviewing.

> Reviewing is something we should do more, but its very taxing.
>
> One would rather try to write as much code as possible, leaving to
> others the reviewing part.
>
> But its a balancing act.
>
> Whatever we can do to help reviewers, like taking into account what they
> say they would prefer as a way to submit our work, even if it isn't
> exactly of our liking, is one such thing.
>
> So if Namhyung says that it would be best for you to try to break down
> your patches into smaller ones, like I did say to you in the past, even
> taking the trouble to do it myself, in the process introducing problems,
> later fixed, I think you should try to do what he says.
>
> He is the maintainer, try to address his comments.

I think I've written long emails addressing the comments. Just saying
too big (1) doesn't match how existing drivers are added (although
I've split the code many times so the addition is the smallest it can
be) (2) as I've pointed out makes the code harder to bisect, work with
compilers and understand.

I think there is far too much developer push back going on, it feels
capricious, I'm lucky as I'll just go push into Google's tree. I'm
only persisting here for upstream's benefit and ultimately my benefit
when I pull from upstream. Perfect shouldn't be the enemy of good, but
frequently (more often than not for me) reviewer comments aren't
improving the code they are significantly stalling it:

1) parallel testing
https://lore.kernel.org/lkml/20241025192109.132482-1-irogers@google.com/
1.1) pushed back because it used an #ifdef __linux__ to maintain some
posix library code (a now dropped complaint)
1.2) pushed back for improvements in test numbering, addressed in:
https://lore.kernel.org/lkml/20241025192109.132482-11-irogers@google.com/
not an unreasonable thing to do but feature creep. Hey we'll only take
your work helping us if you also add feature xyz

2) libdw clean up
https://lore.kernel.org/lkml/20241017002520.59124-1-irogers@google.com/
Pushed back as more cross architecture output would make the commit
messages better. Doesn't sound crazily unreasonable until you realize
the function that is being called and needing cross platform testing
is 6 lines long and only applies when you do analysis of x86 perf.data
files on non-x86 platforms. We heavily test the code on x86 and the
chance that cross platform testing will show anything is very small.

On the other hand I can point at unreviewed maintainer code going into
the tree and code where I've pointed out it is broken, from a
fundamental CS perspective, it is also taken into the tree.

RISC-V has been damaged and now in the driver they are trying to
workaround the perf tool. There were already comments to this effect
in ARM breakpoint driver's code.

On Intel we now have TPEBS (which took far far too long to land)
behind a flag which means we've made accurate top-down analysis
require an additional flag on all newer Intel models, something I
pushed against.

So the reviewing is inconsistent, damages the code (a maintainer may
disagree with the reviewer and developers saying otherwise but the
maintainer has to be followed to land) and is constantly stalling
development. Fixing reference counting took years to land because of
endless stalling, any reasonable developer would have just given up.
It is hard to imagine the state the code base would be in without it.

Of the patches I've mentioned how many are code health and how many
are a feature I can say working on is part of my day job? I see a
deliberate lack of understanding of what a developer needs. To say
I've not tried to address comments, I'd say 90% of the noise on
linux-perf-users is me resending patches, mine and others, to address
comments. Here I've made the patches a size that makes sense. I can
move the enums, which feels like a compiler error along the lines of
"static function defined but not used" but beside this, changing
evsel's name meaning to make it part of the event encoding is imo
wrong, having separate patches for a function declaration and then 1
for its definition, can you imagine taking this to its extreme and
what the patches would look like if you did this? In making things
smaller, as has happened already in this series, it is never clear you
will hit a magical maintainer happy threshold. Knowing how to make a
"right" patch is even harder when it is inconsistent with the rest of
Linux development.

Thanks,
Ian
Re: [PATCH v6 0/5] Hwmon PMUs
Posted by Namhyung Kim 1 month ago
Hello Ian,

Thanks for your email explaining the concerns.

On Fri, Oct 25, 2024 at 04:07:47PM -0700, Ian Rogers wrote:
> On Fri, Oct 25, 2024 at 2:01 PM Arnaldo Carvalho de Melo
> <acme@kernel.org> wrote:
> >
> > On Fri, Oct 25, 2024 at 11:26:26AM -0700, Ian Rogers wrote:
> > > On Fri, Oct 25, 2024 at 10:30 AM Namhyung Kim <namhyung@kernel.org> wrote:
> > > > On Thu, Oct 24, 2024 at 06:33:27PM -0700, Ian Rogers wrote:
> > > > > So I think moving the enum declarations into one patch is okay. But as
> > > > > the enum values have no bearing on hardware constants, or something
> > > > > outside of the code that uses them it smells strange to me. Ultimately
> > > > > this is going to do little to the lines of code count but damage
> > > > > readability. I'm not sure why we're doing this given the kernel model
> > > > > for adding a driver is to add it as a large chunk. For example, here
> > > > > is adding the intel PT driver:
> > > > > https://lore.kernel.org/all/1422614392-114498-1-git-send-email-alexander.shishkin@linux.intel.com/T/#u
> >
> > > > Maybe others can understand a big patch easily, but I'm not.
> >
> > > My understanding is that we make small patches so that the codebase is
> > > more bisectable. When there is something new, like a driver or here a
> >
> > That is super important, having patches being super small and doing just
> > one thing helps in bisecting problems.
> >
> > If two things are done in one patch, and one of them causes a problem,
> > then bisection is a very effective way of finding out what exactly
> > caused a problem.
> >
> > But bisection is not the only benefit from breaking down larger patches
> > into smaller ones.
> >
> > We want to have more people joining our ranks, doing low level tooling
> > and kernel work.
> >
> > Writing new functionality in a series of patches, growing in complexity
> > is a way to reduce the cognitive load on understantind how something
> > works.
> >
> > As much as trying to emulate how the kernel community works is a good
> > model as that community has been producing a lot of good code in a
> > frantic, athletic pace, and as much as I can agree with you that adding
> > a new piece of code will not affect bisectability as its new code, I
> > think having it broken down in multiple patches benefits revieweing.
> 
> Can you explain how, as asked, can separating the declaration of a
> function from its definition aid in reviewing? As a reviewer, I want
> to know the scope of a function and its documentation. Placing them in
> 2 separate patches doesn't benefit my reviewing.

No, it's my fault.  Please move the declaration into the same patch.

> 
> > Reviewing is something we should do more, but its very taxing.
> >
> > One would rather try to write as much code as possible, leaving to
> > others the reviewing part.
> >
> > But its a balancing act.
> >
> > Whatever we can do to help reviewers, like taking into account what they
> > say they would prefer as a way to submit our work, even if it isn't
> > exactly of our liking, is one such thing.
> >
> > So if Namhyung says that it would be best for you to try to break down
> > your patches into smaller ones, like I did say to you in the past, even
> > taking the trouble to do it myself, in the process introducing problems,
> > later fixed, I think you should try to do what he says.
> >
> > He is the maintainer, try to address his comments.
> 
> I think I've written long emails addressing the comments. Just saying
> too big (1) doesn't match how existing drivers are added (although
> I've split the code many times so the addition is the smallest it can

I think it's different than drivers which can be separated by a config
option easily and highly hardware dependent.  Or maybe it's just a
maintainers' preference.


> be) (2) as I've pointed out makes the code harder to bisect, work with
> compilers and understand.

I don't agree.  The intention is to help other's understanding of the
code.  Well I agree it will require more effort for the author, but I
believe that having the code more digestible size would benefit in the
long run.

I feel like the whole perf code base is getting bigger, harder to know
all the details.  So I'm asking contributors to do more work to reduce
the burden in some way.

> 
> I think there is far too much developer push back going on, it feels
> capricious, I'm lucky as I'll just go push into Google's tree. I'm
> only persisting here for upstream's benefit and ultimately my benefit
> when I pull from upstream. Perfect shouldn't be the enemy of good, but
> frequently (more often than not for me) reviewer comments aren't
> improving the code they are significantly stalling it:

I'm sorry that you felt that way.  I was trying to improve the code and
keep the code simple and concise.  But it's sometimes hard to draw the
line where it's acceptable.  Probably my previous decisions were bad,
but I tried to be reasonable as much as possible.

> 
> 1) parallel testing
> https://lore.kernel.org/lkml/20241025192109.132482-1-irogers@google.com/
> 1.1) pushed back because it used an #ifdef __linux__ to maintain some
> posix library code (a now dropped complaint)

I don't know we have that in other place.  So I was curious if we care
about other platforms.  Probably we can just delete the unused code, but
as I said, I can live with this.


> 1.2) pushed back for improvements in test numbering, addressed in:
> https://lore.kernel.org/lkml/20241025192109.132482-11-irogers@google.com/
> not an unreasonable thing to do but feature creep. Hey we'll only take
> your work helping us if you also add feature xyz

Well I think you changed the numbering in the parallel testing and I
asked to keep it continuous as of now.

> 
> 2) libdw clean up
> https://lore.kernel.org/lkml/20241017002520.59124-1-irogers@google.com/
> Pushed back as more cross architecture output would make the commit
> messages better. Doesn't sound crazily unreasonable until you realize
> the function that is being called and needing cross platform testing
> is 6 lines long and only applies when you do analysis of x86 perf.data
> files on non-x86 platforms. We heavily test the code on x86 and the
> chance that cross platform testing will show anything is very small.

I think we're fine except for the register naming.  I haven't reviewed
that part yet and I'll do that next week.

> 
> On the other hand I can point at unreviewed maintainer code going into
> the tree and code where I've pointed out it is broken, from a
> fundamental CS perspective, it is also taken into the tree.
> 
> RISC-V has been damaged and now in the driver they are trying to
> workaround the perf tool. There were already comments to this effect
> in ARM breakpoint driver's code.

It's sad we broke some arch.  But it should be easy to fix the tool
than the kernel driver.  Let's find a way to fix the problems in a
better way.  Sorry if I missed some previous discussion.

> 
> On Intel we now have TPEBS (which took far far too long to land)
> behind a flag which means we've made accurate top-down analysis
> require an additional flag on all newer Intel models, something I
> pushed against.

This is a new code that requires complex and non-intuitive operations
like mixing perf record and perf stat together.  I remember some people
doubt about the approach so it may deserve stricter and longer reviews.

Even then, I tried to review quickly and accepted some minor
disasgreements.  It's unfortunate it took too long but it happens.

> 
> So the reviewing is inconsistent, damages the code (a maintainer may
> disagree with the reviewer and developers saying otherwise but the
> maintainer has to be followed to land) and is constantly stalling
> development. Fixing reference counting took years to land because of
> endless stalling, any reasonable developer would have just given up.
> It is hard to imagine the state the code base would be in without it.

Right it works great, thanks for your effort.

But I think any collaborating work needs some kind of burden (or
stalling) for coordination.  If said patches touch a lot of area, there
is a high chance of rebase, more arguments on the interface, etc.

> 
> Of the patches I've mentioned how many are code health and how many
> are a feature I can say working on is part of my day job? I see a
> deliberate lack of understanding of what a developer needs. To say
> I've not tried to address comments, I'd say 90% of the noise on
> linux-perf-users is me resending patches, mine and others, to address

Thanks for your hard work.  Maybe I'm the bottleneck of your
productivity.  But I cannot take patches without review, and reviewing
patches take time.  Having more active reviewers would help.


> comments. Here I've made the patches a size that makes sense. I can
> move the enums, which feels like a compiler error along the lines of
> "static function defined but not used" but beside this, changing
> evsel's name meaning to make it part of the event encoding is imo
> wrong, having separate patches for a function declaration and then 1
> for its definition, can you imagine taking this to its extreme and
> what the patches would look like if you did this? In making things
> smaller, as has happened already in this series, it is never clear you
> will hit a magical maintainer happy threshold. Knowing how to make a
> "right" patch is even harder when it is inconsistent with the rest of
> Linux development.

At least for this case, I don't think moving the declaration would cause
you a lot of trouble.  Please take a look at my updated 'perf/hwmon-pmu'
branch again.

For the magical maintainer threshold, I admit it can be different to
each maintainer.  But I think it's the review process to find a point of
agreement.  I don't know where it is even by myself but we can argue
each other.

Thanks,
Namhyung