• Rafael J. Wysocki's avatar
    thermal: core: Introduce .should_bind() thermal zone callback · aa35e56a
    Rafael J. Wysocki authored
    The current design of the code binding cooling devices to trip points in
    thermal zones is convoluted and hard to follow.
    
    Namely, a driver that registers a thermal zone can provide .bind()
    and .unbind() operations for it, which are required to call either
    thermal_bind_cdev_to_trip() and thermal_unbind_cdev_from_trip(),
    respectively, or thermal_zone_bind_cooling_device() and
    thermal_zone_unbind_cooling_device(), respectively, for every relevant
    trip point and the given cooling device.  Moreover, if .bind() is
    provided and .unbind() is not, the cleanup necessary during the removal
    of a thermal zone or a cooling device may not be carried out.
    
    In other words, the core relies on the thermal zone owners to do the
    right thing, which is error prone and far from obvious, even though all
    of that is not really necessary.  Specifically, if the core could ask
    the thermal zone owner, through a special thermal zone callback, whether
    or not a given cooling device should be bound to a given trip point in
    the given thermal zone, it might as well carry out all of the binding
    and unbinding by itself.  In particular, the unbinding can be done
    automatically without involving the thermal zone owner at all because
    all of the thermal instances associated with a thermal zone or cooling
    device going away must be deleted regardless.
    
    Accordingly, introduce a new thermal zone operation, .should_bind(),
    that can be invoked by the thermal core for a given thermal zone,
    trip point and cooling device combination in order to check whether
    or not the cooling device should be bound to the trip point at hand.
    It takes an additional cooling_spec argument allowing the thermal
    zone owner to specify the highest and lowest cooling states of the
    cooling device and its weight for the given trip point binding.
    
    Make the thermal core use this operation, if present, in the absence of
    .bind() and .unbind().  Note that .should_bind() will be called under
    the thermal zone lock.
    
    No intentional functional impact.
    Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
    Reviewed-by: default avatarZhang Rui <rui.zhang@intel.com>
    Acked-by: default avatarHuisong Li <lihuisong@huawei.com>
    Reviewed-by: default avatarDaniel Lezcano <daniel.lezcano@linaro.org>
    Link: https://patch.msgid.link/9334403.CDJkKcVGEf@rjwysocki.net
    aa35e56a
thermal_core.c 49 KB