Re: [RESEND PATCH v17 00/17] Multi Color LED Framework

From: Jacek Anaszewski
Date: Wed Feb 26 2020 - 15:46:01 EST


Hi Greg,

We have here long lasting discussion related to LED multicolor class
sysfs interface design. We went through several iterations and worked
out the solution with individual file per each color sub-LED in the
color directory as shown below:

/sys/class/leds/<led>/colors/<color>_intensity

This is in line with one-value-per-file sysfs rule, that is being
frequently highlighted, and we even had not so long ago a patch
for led cpu trigger solving the problem caused by this rule not
being adhered to.

Now we have the voice below bringing to attention another caveat
from sysfs documentation:

"it is socially acceptable to express an array of values of the same
type"

and proposing the interface in the form of two files:

channel_intensity (file containing array of u32's)
channel_names (usually containing "red green blue")

In order to have this clarified once and for all, could you please
provide us with guidance on whether the fragment from
Documentation/filesystems/sysfs.txt is still in force and we
can benefit from it for LED multicolor framework, or not and then
it should be removed from the doc then?

Best regards,
Jacek Anaszewski

On 2/26/20 1:59 PM, Pavel Machek wrote:
> Hi!
>
>>> The fact that it changes API makes it important to get it right, and
>>> hard/impossible to fix it once it is merged... and I don't think this
>>> is the right interface (sorry).
>>>
>>> In particular, I don't think having directory per channel is a good
>>> idea. It makes atomic updates impossible (minor),
>>
>> It is possible via brightness file, although it will need first writing
>> intensity files, which only will cache colors, and actual write to hw
>> occurs on write to brightness file. This has been discussed dozen of
>> times throughout last year, and you even proposed the formula for
>> calculating per-color-subled brightness basing on global brightness and
>> intensity set for each color.
>
> You are right, it is possible to make updates atomic with right kind
> of latching (which is quite confusing).
>
>>> but will also
>>> increase memory consuption (to a point where led-per-channel might
>>> be cheaper), and will make userspace do 3x ammount of syscalls in the
>>> common case.
>>>
>>> And we can do better; sysfs files with arrays are okay. So I'd like to
>>> see
>>
>> Let's first achieve broader consensus on this statement before we
>> move forward with such design. Sysfs maintainer seems to be the best
>> person to consult at first.
>
> This is actually documented:
>
> Documentation/filesystems/sysfs.txt
>
> <quote>
> Attributes should be ASCII text files, preferably with only one value
> per file. It is noted that it may not be efficient to contain only one
> value per file, so it is socially acceptable to express an array of
> values of the same type.
>
> Mixing types, expressing multiple lines of data, and doing fancy
> formatting of data is heavily frowned upon. Doing these things may get
> you publicly humiliated and your code rewritten without notice.
> </quote>
>
> Best regards,
> Pavel
>