[PATCH 1/2] Linux: implement getloadavg(3) using sysinfo(2)

Adhemerval Zanella adhemerval.zanella@linaro.org
Fri Aug 20 14:21:55 GMT 2021



On 19/08/2021 18:38, Cristian Rodríguez wrote:
> On Thu, Aug 19, 2021 at 3:17 PM Adhemerval Zanella
> <adhemerval.zanella@linaro.org> wrote:
>>
>>
>>
>> On 06/08/2021 16:17, Cristian Rodríguez wrote:
>>> Signed-off-by: Cristian Rodríguez <crrodriguez@opensuse.org>
>>
>> Look good, some minor comments below.
> 
> First, thanks for looking..
> 
>>> +  struct sysinfo info = {};
>>
>> I think there is no need to clear the struct prior the syscall,
>> I would expect the kernel to fill all the appropriated values
>> (as it seems to be doing on kernel/sys.c).
> 
> 
> Yes, I read the kernel source, I  just decided not to count on the
> kernel doing it.

In this case, clearing the struct does not really improve for the
hypothetical kernel that does not set all the bits because you
won't know if the returned value has meaningful data or not.

> 
> 
>>> +  nelem = CLAMP (nelem, 0, (int)array_length (info.loads));
>>
>> I think there is no need to cast to int here

In this case I think it would be better to make CLAMP a proper
inline function that returns size_t.

> 
> IIRC the compiler complained I was comparing signed and unsigned
> values.. array_length expands to a size_t value.
> 


More information about the Libc-alpha mailing list