Skip to content

Commit

Permalink
thermal/core: Precompute the delays from msecs to jiffies
Browse files Browse the repository at this point in the history
The delays are stored in ms units and when the polling function is
called this delay is converted into jiffies at each call.

Instead of doing the conversion again and again, compute the jiffies
at init time and use the value directly when setting the polling.

Cc: Thara Gopinath <[email protected]>
Signed-off-by: Daniel Lezcano <[email protected]>
Reviewed-by: Lukasz Luba <[email protected]>
Reviewed-by: Thara Gopinath <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
  • Loading branch information
dlezcano committed Jan 19, 2021
1 parent 2121496 commit 17d399c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions drivers/thermal/thermal_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1315,6 +1315,9 @@ thermal_zone_device_register(const char *type, int trips, int mask,
tz->passive_delay = passive_delay;
tz->polling_delay = polling_delay;

thermal_set_delay_jiffies(&tz->passive_delay_jiffies, passive_delay);
thermal_set_delay_jiffies(&tz->polling_delay_jiffies, polling_delay);

/* sys I/F */
/* Add nodes that are always present via .groups */
result = thermal_zone_create_device_groups(tz, mask);
Expand Down
1 change: 1 addition & 0 deletions drivers/thermal/thermal_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ int thermal_build_list_of_policies(char *buf);

/* Helpers */
void thermal_zone_set_trips(struct thermal_zone_device *tz);
void thermal_set_delay_jiffies(unsigned long *delay_jiffies, int delay_ms);

/* sysfs I/F */
int thermal_zone_create_device_groups(struct thermal_zone_device *, int);
Expand Down
7 changes: 7 additions & 0 deletions drivers/thermal/thermal_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,13 @@ void thermal_zone_set_trips(struct thermal_zone_device *tz)
mutex_unlock(&tz->lock);
}

void thermal_set_delay_jiffies(unsigned long *delay_jiffies, int delay_ms)
{
*delay_jiffies = msecs_to_jiffies(delay_ms);
if (delay_ms > 1000)
*delay_jiffies = round_jiffies(*delay_jiffies);
}

static void thermal_cdev_set_cur_state(struct thermal_cooling_device *cdev,
int target)
{
Expand Down
7 changes: 7 additions & 0 deletions include/linux/thermal.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,14 @@ struct thermal_cooling_device {
* @trips_disabled; bitmap for disabled trips
* @passive_delay: number of milliseconds to wait between polls when
* performing passive cooling.
* @passive_delay_jiffies: number of jiffies to wait between polls when
* performing passive cooling.
* @polling_delay: number of milliseconds to wait between polls when
* checking whether trip points have been crossed (0 for
* interrupt driven systems)
* @polling_delay_jiffies: number of jiffies to wait between polls when
* checking whether trip points have been crossed (0 for
* interrupt driven systems)
* @temperature: current temperature. This is only for core code,
* drivers should use thermal_zone_get_temp() to get the
* current temperature
Expand Down Expand Up @@ -155,6 +160,8 @@ struct thermal_zone_device {
void *devdata;
int trips;
unsigned long trips_disabled; /* bitmap for disabled trips */
unsigned long passive_delay_jiffies;
unsigned long polling_delay_jiffies;
int passive_delay;
int polling_delay;
int temperature;
Expand Down

0 comments on commit 17d399c

Please sign in to comment.