qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v6 1/9] hw/core/clock: introduce clock objects


From: Damien Hedde
Subject: Re: [PATCH v6 1/9] hw/core/clock: introduce clock objects
Date: Tue, 3 Dec 2019 16:28:16 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.0


On 12/2/19 2:42 PM, Peter Maydell wrote:
> On Wed, 4 Sep 2019 at 13:56, Damien Hedde <address@hidden> wrote:
>>
>> Introduce clock objects: ClockIn and ClockOut.
>>
>> These objects may be used to distribute clocks from an object to several
>> other objects. Each ClockIn object contains the current state of the
>> clock: the frequency; it allows an object to migrate its input clock state
>> independently of other objects.
>>
>> A ClockIn may be connected to a ClockOut so that it receives update,
> 
> "updates" (or "an update")
> 
>> through a callback, whenever the Clockout is updated using the
>> ClockOut's set function.
>>
>> This is based on the original work of Frederic Konrad.
>>
>> +
>> +#define CLOCK_PATH(_clk) (_clk->canonical_path)
> 
> Don't use leading underscores in identifiers, please.

ok

> 
>> +
>> +void clock_init_frequency(ClockIn *clk, uint64_t freq)
>> +{
>> +    assert(clk);
> 
> This sort of assert isn't necessary. Asserts are good
> when they help to make a bug visible sooner and more
> obviously -- when they avoid "something goes wrong
> much later on and further from the site of the actual
> error". In this case, if the assert was not present
> then the code would just segfault on the next line:
> 
>> +
>> +    clk->frequency = freq;
> 
> which is already a very easy bug to diagnose and
> where the offending caller will be in the backtrace.
> 
> If the parameter isn't supposed to be NULL, and the
> method doesn't actually do anything that would
> dereference it, that might be a good candidate to
> assert on.
> 
> The same kind of unnecessary assert is also in some of
> the other functions here (and probably in other patches).

I'll take a look.

> 
>> diff --git a/include/hw/clock.h b/include/hw/clock.h
>> new file mode 100644
>> index 0000000000..fd11202ba4
>> --- /dev/null
>> +++ b/include/hw/clock.h
>> @@ -0,0 +1,124 @@
>> +#ifndef QEMU_HW_CLOCK_H
>> +#define QEMU_HW_CLOCK_H
> 
> All new files need a copyright-and-license comment header (could
> you check the rest of the patchset for this, please?).

Sure.

> 
>> +
> 
>> +/**
>> + * clock_get_frequency:
>> + * @clk: the clk to fetch the clock
>> + *
>> + * @return: the current frequency of @clk in Hz. If @clk is NULL, return 0.
>> + */
>> +static inline uint64_t clock_get_frequency(const ClockIn *clk)
>> +{
>> +    return clk ? clk->frequency : 0;
>> +}
> 
> Is there a use case where we want to support "pass in NULL"
> rather than just making it a programming error for the caller
> to try that ?

No, it's probably a remnant of previous version where input and output
shared some code. I'll remove it.

--
Damien



reply via email to

[Prev in Thread] Current Thread [Next in Thread]