public inbox for linux-acpi@vger.kernel.org
 help / color / mirror / Atom feed
From: "Wilczynski, Michal" <michal.wilczynski@intel.com>
To: "Rafael J. Wysocki" <rafael@kernel.org>,
	Andy Shevchenko <andriy.shevchenko@intel.com>
Cc: <linux-acpi@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<nvdimm@lists.linux.dev>, <rafael.j.wysocki@intel.com>,
	<lenb@kernel.org>, <dan.j.williams@intel.com>,
	<vishal.l.verma@intel.com>, <ira.weiny@intel.com>
Subject: Re: [PATCH v2 3/6] ACPI: AC: Replace acpi_driver with platform_driver
Date: Mon, 9 Oct 2023 10:40:13 +0200	[thread overview]
Message-ID: <f8ff3c4b-376a-4de0-8674-5789bcbe7aa9@intel.com> (raw)
In-Reply-To: <CAJZ5v0iDhOFDX=k7xsC_=2jjerWmrP+Na-9PFM=YGA0V-hH2xw@mail.gmail.com>


Hi !

Thanks a lot for a review, to both of you ! :-)

On 10/7/2023 12:43 PM, Rafael J. Wysocki wrote:
> On Sat, Oct 7, 2023 at 12:41 PM Rafael J. Wysocki <rafael@kernel.org> wrote:
>> On Sat, Oct 7, 2023 at 9:56 AM Andy Shevchenko
>> <andriy.shevchenko@intel.com> wrote:
>>> On Fri, Oct 06, 2023 at 09:47:57PM +0200, Rafael J. Wysocki wrote:
>>>> On Fri, Oct 6, 2023 at 8:33 PM Michal Wilczynski
>>>> <michal.wilczynski@intel.com> wrote:
>>> ...
>>>
>>>>>  struct acpi_ac {
>>>>>         struct power_supply *charger;
>>>>>         struct power_supply_desc charger_desc;
>>>>> -       struct acpi_device *device;
>>>>> +       struct device *dev;
>>>> I'm not convinced about this change.
>>>>
>>>> If I'm not mistaken, you only use the dev pointer above to get the
>>>> ACPI_COMPANION() of it, but the latter is already found in _probe(),
>>>> so it can be stored in struct acpi_ac for later use and then the dev
>>>> pointer in there will not be necessary any more.
>>>>
>>>> That will save you a bunch of ACPI_HANDLE() evaluations and there's
>>>> nothing wrong with using ac->device->handle.  The patch will then
>>>> become almost trivial AFAICS and if you really need to get from ac to
>>>> the underlying platform device, a pointer to it can be added to struct
>>>> acpi_ac without removing the ACPI device pointer from it.

Yeah we could add platform device without removing acpi device, and
yes that would introduce data duplication, like Andy noticed. And yes,
maybe for this particular driver there is little impact (as struct device is not
really used), but in my opinion we should adhere to some common coding
pattern among all acpi drivers in order for the code to be easier to maintain
and improve readability, also for any newcomer.

>>> The idea behind is to eliminate data duplication.
>> What data duplication exactly do you mean?
>>
>> struct acpi_device *device is replaced with struct device *dev which
>> is the same size.  The latter is then used to obtain a struct
>> acpi_device pointer.  Why is it better to do this than to store the
>> struct acpi_device itself?
> This should be "store the struct acpi_device pointer itself", sorry.

Hi,
So let me explain the reasoning here:

1) I've had a pleasure to work with different drivers in ACPI directory. In my
    opinion the best ones I've seen, were build around the concept of struct
    device (e.g NFIT). It's a struct that's well understood in the kernel, and
    it's easier to understand without having to read any ACPI specific code.
    If I see something like ACPI_HANDLE(dev), I think 'ah-ha -  having a struct
    device I can easily get struct acpi_device - they're connected'. And I think
    using a standardized macro, instead of manually dereferencing pointers is
    also much easier for ACPI newbs reading the code, as it hides a bit complexity
    of getting acpi device from struct device. And to be honest I don't think there would
    be any measurable performance change, as those code paths are far from
    being considered 'hot paths'. So if we can get the code easier to understand
    from a newcomer perspective, why not do it.
   
   
2) I think it would be good to stick to the convention, and introduce some coding
     pattern, for now some drivers store the struct device pointer, and other store
     acpi device pointer . As I'm doing this change acpi device pointer become less
     relevant, as we're using platform device. So to reflect that loss of relevance
     we can choose to adhere to a pattern where we use it less and less, and the
     winning approach would be to use 'struct device' by default everywhere we can
     so maybe eventually we would be able to lose acpi_device altogether at some point,
     as most of the usage is to retrieve acpi handle and execute some AML method.
     So in my understanding acpi device is already obsolete at this point, if we can
     manage to use it less and less, and eventually wipe it out then why not ;-)
   

Thanks again !

Michał



  reply	other threads:[~2023-10-09  8:40 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-06 17:30 [PATCH v2 0/6] Replace acpi_driver with platform_driver Michal Wilczynski
2023-10-06 17:30 ` [PATCH v2 1/6] ACPI: AC: Remove unnecessary checks Michal Wilczynski
2023-10-06 17:30 ` [PATCH v2 2/6] ACPI: AC: Use string_choices API instead of ternary operator Michal Wilczynski
2023-10-06 17:30 ` [PATCH v2 3/6] ACPI: AC: Replace acpi_driver with platform_driver Michal Wilczynski
2023-10-06 17:45   ` Andy Shevchenko
2023-10-06 19:47   ` Rafael J. Wysocki
2023-10-07  7:56     ` Andy Shevchenko
2023-10-07 10:41       ` Rafael J. Wysocki
2023-10-07 10:43         ` Rafael J. Wysocki
2023-10-09  8:40           ` Wilczynski, Michal [this message]
2023-10-09 12:27             ` Rafael J. Wysocki
2023-10-09 13:03               ` Wilczynski, Michal
2023-10-09 17:51                 ` Rafael J. Wysocki
2023-10-06 17:30 ` [PATCH v2 4/6] ACPI: AC: Rename ACPI device from device to adev Michal Wilczynski
2023-10-06 17:30 ` [PATCH v2 5/6] ACPI: NFIT: Replace acpi_driver with platform_driver Michal Wilczynski
2023-10-17  8:51   ` Wilczynski, Michal
2023-10-17 10:55     ` Rafael J. Wysocki
2023-10-17 14:06   ` Rafael J. Wysocki
2023-10-17 18:24   ` Dan Williams
2023-10-18 15:38     ` Wilczynski, Michal
2023-10-06 17:30 ` [PATCH v2 6/6] ACPI: NFIT: Remove redundant call to to_acpi_dev() Michal Wilczynski

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=f8ff3c4b-376a-4de0-8674-5789bcbe7aa9@intel.com \
    --to=michal.wilczynski@intel.com \
    --cc=andriy.shevchenko@intel.com \
    --cc=dan.j.williams@intel.com \
    --cc=ira.weiny@intel.com \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nvdimm@lists.linux.dev \
    --cc=rafael.j.wysocki@intel.com \
    --cc=rafael@kernel.org \
    --cc=vishal.l.verma@intel.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