1. 16 Jan, 2024 1 commit
    • Rafael J. Wysocki's avatar
      Merge branches 'thermal-core' and 'thermal-intel' · dd75558b
      Rafael J. Wysocki authored
      Merge additional updates for 6.8-rc1 in the thermal core and in the
      Intel HFI thermal driver:
      
       - Add debugfs-based diagnostics support to the thermal core (Daniel
         Lezcano, Dan Carpenter).
      
       - Fix a power allocator thermal governor issue preventing it from
         resetting cooling devices sometimes (Di Shen).
      
       - Simplify the thermal netlink API and clean up related code (Rafael J.
         Wysocki).
      
       - Make the Intel HFI driver support hibernation and deep suspend
         properly (Ricardo Neri).
      
      * thermal-core:
        thermal/debugfs: Unlock on error path in thermal_debug_tz_trip_up()
        thermal: gov_power_allocator: avoid inability to reset a cdev
        thermal: helpers: Rearrange thermal_cdev_set_cur_state()
        thermal: netlink: Rework notify API for cooling devices
        thermal: core: Use kstrdup_const() during cooling device registration
        thermal/debugfs: Add thermal debugfs information for mitigation episodes
        thermal/debugfs: Add thermal cooling device debugfs information
        thermal: netlink: Pass thermal zone pointer to notify routines
        thermal: netlink: Drop thermal_notify_tz_trip_add/delete()
        thermal: netlink: Pass pointers to thermal_notify_tz_trip_up/down()
        thermal: netlink: Pass pointers to thermal_notify_tz_trip_change()
      
      * thermal-intel:
        thermal: intel: hfi: Add syscore callbacks for system-wide PM
      dd75558b
  2. 12 Jan, 2024 8 commits
    • Dan Carpenter's avatar
      thermal/debugfs: Unlock on error path in thermal_debug_tz_trip_up() · 6dcb3508
      Dan Carpenter authored
      Add a missing mutex_unlock(&thermal_dbg->lock) to this error path.
      
      Fixes: 7ef01f22 ("thermal/debugfs: Add thermal debugfs information for mitigation episodes")
      Signed-off-by: default avatarDan Carpenter <dan.carpenter@linaro.org>
      Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
      6dcb3508
    • Ricardo Neri's avatar
      thermal: intel: hfi: Add syscore callbacks for system-wide PM · 97566d09
      Ricardo Neri authored
      The kernel allocates a memory buffer and provides its location to the
      hardware, which uses it to update the HFI table. This allocation occurs
      during boot and remains constant throughout runtime.
      
      When resuming from hibernation, the restore kernel allocates a second
      memory buffer and reprograms the HFI hardware with the new location as
      part of a normal boot. The location of the second memory buffer may
      differ from the one allocated by the image kernel.
      
      When the restore kernel transfers control to the image kernel, its HFI
      buffer becomes invalid, potentially leading to memory corruption if the
      hardware writes to it (the hardware continues to use the buffer from the
      restore kernel).
      
      It is also possible that the hardware "forgets" the address of the memory
      buffer when resuming from "deep" suspend. Memory corruption may also occur
      in such a scenario.
      
      To prevent the described memory corruption, disable HFI when preparing to
      suspend or hibernate. Enable it when resuming.
      
      Add syscore callbacks to handle the package of the boot CPU (packages of
      non-boot CPUs are handled via CPU offline). Syscore ops always run on the
      boot CPU. Additionally, HFI only needs to be disabled during "deep" suspend
      and hibernation. Syscore ops only run in these cases.
      
      Cc: 6.1+ <stable@vger.kernel.org> # 6.1+
      Signed-off-by: default avatarRicardo Neri <ricardo.neri-calderon@linux.intel.com>
      [ rjw: Comment adjustment, subject and changelog edits ]
      Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
      97566d09
    • Di Shen's avatar
      thermal: gov_power_allocator: avoid inability to reset a cdev · e95fa740
      Di Shen authored
      Commit 0952177f ("thermal/core/power_allocator: Update once
      cooling devices when temp is low") adds an update flag to avoid
      triggering a thermal event when there is no need, and the thermal
      cdev is updated once when the temperature is low.
      
      But when the trips are writable, and switch_on_temp is set to be a
      higher value, the cooling device state may not be reset to 0,
      because last_temperature is smaller than switch_on_temp.
      
      For example:
      First:
      switch_on_temp=70 control_temp=85;
      Then userspace change the trip_temp:
      switch_on_temp=45 control_temp=55 cur_temp=54
      
      Then userspace reset the trip_temp:
      switch_on_temp=70 control_temp=85 cur_temp=57 last_temp=54
      
      At this time, the cooling device state should be reset to 0.
      However, because cur_temp(57) < switch_on_temp(70)
      last_temp(54) < switch_on_temp(70)  ---->  update = false,
      update is false, the cooling device state can not be reset.
      
      Using the observation that tz->passive can also be regarded as the
      temperature status, set the update flag to the tz->passive value.
      
      When the temperature drops below switch_on for the first time, the
      states of cooling devices can be reset once, and tz->passive is updated
      to 0. In the next round, because tz->passive is 0, cdev->state will not
      be updated.
      
      By using the tz->passive value as the "update" flag, the issue above
      can be solved, and the cooling devices can be updated only once when the
      temperature is low.
      
      Fixes: 0952177f ("thermal/core/power_allocator: Update once cooling devices when temp is low")
      Cc: 5.13+ <stable@vger.kernel.org> # 5.13+
      Suggested-by: default avatarWei Wang <wvw@google.com>
      Signed-off-by: default avatarDi Shen <di.shen@unisoc.com>
      Reviewed-by: default avatarLukasz Luba <lukasz.luba@arm.com>
      [ rjw: Subject and changelog edits ]
      Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
      e95fa740
    • Rafael J. Wysocki's avatar
      thermal: helpers: Rearrange thermal_cdev_set_cur_state() · fd881eac
      Rafael J. Wysocki authored
      Change the code layout in thermal_cdev_set_cur_state() so it returns
      early on errors which is more consistent with what happens elsewhere.
      
      No intentional functional impact.
      Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Reviewed-by: default avatarDaniel Lezcano <daniel.lezcano@linaro.org>
      fd881eac
    • Rafael J. Wysocki's avatar
      thermal: netlink: Rework notify API for cooling devices · 11fde939
      Rafael J. Wysocki authored
      In analogy with some previous thermal netlink API changes, redefine
      thermal_notify_cdev_state_update(), thermal_notify_cdev_add() and
      thermal_notify_cdev_delete() to take a const cdev pointer as their
      first argument and let them extract the requisite information from
      there by themselves.
      
      No intentional functional impact.
      Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Reviewed-by: default avatarDaniel Lezcano <daniel.lezcano@linaro.org>
      11fde939
    • Christophe JAILLET's avatar
      thermal: core: Use kstrdup_const() during cooling device registration · 57a427c8
      Christophe JAILLET authored
      Some *thermal_cooling_device_register() calls pass a string literal as
      the 'type' parameter, so kstrdup_const() can be used instead of
      kstrdup() to avoid a memory allocation in such cases.
      Signed-off-by: default avatarChristophe JAILLET <christophe.jaillet@wanadoo.fr>
      [ rjw: Subject and changelog edits ]
      Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
      57a427c8
    • Daniel Lezcano's avatar
      thermal/debugfs: Add thermal debugfs information for mitigation episodes · 7ef01f22
      Daniel Lezcano authored
      The mitigation episodes are recorded. A mitigation episode happens
      when the first trip point is crossed the way up and then the way
      down. During this episode other trip points can be crossed also and
      are accounted for this mitigation episode. The interesting information
      is the average temperature at the trip point, the undershot and the
      overshot. The standard deviation of the mitigated temperature will be
      added later.
      
      The thermal debugfs directory structure tries to stay consistent with
      the sysfs one but in a very simplified way:
      
      thermal/
       `-- thermal_zones
           |-- 0
           |   `-- mitigations
           `-- 1
               `-- mitigations
      
      The content of the mitigations file has the following format:
      
      ,-Mitigation at 349988258us, duration=130136ms
      | trip |     type | temp(°mC) | hyst(°mC) |  duration  |  avg(°mC) |  min(°mC) |  max(°mC) |
      |    0 |  passive |     65000 |      2000 |     130136 |     68227 |     62500 |     75625 |
      |    1 |  passive |     75000 |      2000 |     104209 |     74857 |     71666 |     77500 |
      ,-Mitigation at 272451637us, duration=75000ms
      | trip |     type | temp(°mC) | hyst(°mC) |  duration  |  avg(°mC) |  min(°mC) |  max(°mC) |
      |    0 |  passive |     65000 |      2000 |      75000 |     68561 |     62500 |     75000 |
      |    1 |  passive |     75000 |      2000 |      60714 |     74820 |     70555 |     77500 |
      ,-Mitigation at 238184119us, duration=27316ms
      | trip |     type | temp(°mC) | hyst(°mC) |  duration  |  avg(°mC) |  min(°mC) |  max(°mC) |
      |    0 |  passive |     65000 |      2000 |      27316 |     73377 |     62500 |     75000 |
      |    1 |  passive |     75000 |      2000 |      19468 |     75284 |     69444 |     77500 |
      ,-Mitigation at 39863713us, duration=136196ms
      | trip |     type | temp(°mC) | hyst(°mC) |  duration  |  avg(°mC) |  min(°mC) |  max(°mC) |
      |    0 |  passive |     65000 |      2000 |     136196 |     73922 |     62500 |     75000 |
      |    1 |  passive |     75000 |      2000 |      91721 |     74386 |     69444 |     78125 |
      
      More information for a better understanding of the thermal behavior
      will be added after. The idea is to give detailed statistics
      information about the undershots and overshots, the temperature speed,
      etc... As all the information in a single file is too much, the idea
      would be to create a directory named with the mitigation timestamp
      where all data could be added.
      
      Please note this code is immune against trip ordering but not against
      a trip temperature change while a mitigation is happening. However,
      this situation should be extremely rare, perhaps not happening and we
      might question ourselves if something should be done in the core
      framework for other components first.
      Signed-off-by: default avatarDaniel Lezcano <daniel.lezcano@linaro.org>
      [ rjw: White space fixups, rebase ]
      Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
      7ef01f22
    • Daniel Lezcano's avatar
      thermal/debugfs: Add thermal cooling device debugfs information · 755113d7
      Daniel Lezcano authored
      The thermal framework does not have any debug information except a
      sysfs stat which is a bit controversial. This one allocates big chunks
      of memory for every cooling devices with a high number of states and
      could represent on some systems in production several megabytes of
      memory for just a portion of it. As the sysfs is limited to a page
      size, the output is not exploitable with large data array and gets
      truncated.
      
      The patch provides the same information than sysfs except the
      transitions are dynamically allocated, thus they won't show more
      events than the ones which actually occurred. There is no longer a
      size limitation and it opens the field for more debugging information
      where the debugfs is designed for, not sysfs.
      
      The thermal debugfs directory structure tries to stay consistent with
      the sysfs one but in a very simplified way:
      
      thermal/
       -- cooling_devices
          |-- 0
          |   |-- clear
          |   |-- time_in_state_ms
          |   |-- total_trans
          |   `-- trans_table
          |-- 1
          |   |-- clear
          |   |-- time_in_state_ms
          |   |-- total_trans
          |   `-- trans_table
          |-- 2
          |   |-- clear
          |   |-- time_in_state_ms
          |   |-- total_trans
          |   `-- trans_table
          |-- 3
          |   |-- clear
          |   |-- time_in_state_ms
          |   |-- total_trans
          |   `-- trans_table
          `-- 4
              |-- clear
              |-- time_in_state_ms
              |-- total_trans
              `-- trans_table
      
      The content of the files in the cooling devices directory is the same
      as the sysfs one except for the trans_table which has the following
      format:
      
      Transition	Hits
      1->0      	246
      0->1      	246
      2->1      	632
      1->2      	632
      3->2      	98
      2->3      	98
      Signed-off-by: default avatarDaniel Lezcano <daniel.lezcano@linaro.org>
      [ rjw: White space fixups, rebase ]
      Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
      755113d7
  3. 09 Jan, 2024 4 commits
  4. 05 Jan, 2024 1 commit
    • Rafael J. Wysocki's avatar
      Merge branch 'thermal-intel' · 17e8b764
      Rafael J. Wysocki authored
      Merge changes in thermal control drivers for Intel platforms for
      6.8-rc1:
      
       - Make the Intel HFI thermal driver enable an HFI instance (eg. processor
         package) from its first online CPU and disable it when the last CPU in
         it goes offline (Ricardo Neri).
      
      * thermal-intel:
        thermal: intel: hfi: Disable an HFI instance when all its CPUs go offline
        thermal: intel: hfi: Enable an HFI instance from its first online CPU
        thermal: intel: hfi: Refactor enabling code into helper functions
      17e8b764
  5. 04 Jan, 2024 1 commit
  6. 03 Jan, 2024 3 commits
  7. 02 Jan, 2024 22 commits